350555a8 by Jeff Balicki

cache

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent d83d5b28
Showing 105 changed files with 3463 additions and 0 deletions
1 # Not loaded by default eslint, but we use tools/js-tools/load-eslint-ignore.js in .eslintrc to pull it in.
2
3 # @todo: Files below ignored as part of Automattic/jetpack/pull/25449
4 # They can be removed here as lint errors are addressed.
5 /inc/delete-cache-button.js
6 /inc/preload-notification.js
1 module.exports = {
2 extends: [ require.resolve( 'jetpack-js-tools/eslintrc/base' ) ],
3 rules: {
4 // Enforce use of the correct textdomain.
5 '@wordpress/i18n-text-domain': [
6 'error',
7 {
8 allowedTextDomain: 'wp-super-cache',
9 },
10 ],
11 },
12 };
1 # super-cache
2
3 A very fast caching engine for WordPress that produces static html files.
4
5 ## How to install super-cache
6
7 ### Installation From Git Repo
8
9 ## Contribute
10
11 ## Get Help
12
13 Support is handled via the .org support forums.
14
15 ## Security
16
17 Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).
18
19 ## License
20
21 super-cache is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)
1 # Security Policy
2
3 Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
4
5 ## Supported Versions
6
7 Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions.
8
9 ## Reporting a Vulnerability
10
11 [Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure.
12
13 **For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
14
15 Our most critical targets are:
16
17 * Jetpack and the Jetpack composer packages (all within this repo)
18 * Jetpack.com -- the primary marketing site.
19 * cloud.jetpack.com -- a management site.
20 * wordpress.com -- the shared management site for both Jetpack and WordPress.com sites.
21
22 For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
23
24 _Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
25
26 ## Guidelines
27
28 We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
29
30 * Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
31 * Pen-testing Production:
32 * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
33 * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
34 * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
35 * To be eligible for a bounty, all of these guidelines must be followed.
36 * Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
37
38 We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.
1 <?php
2 // WP SUPER CACHE 1.2
3 function wpcache_broken_message() {
4 global $wp_cache_config_file;
5 if ( isset( $wp_cache_config_file ) == false ) {
6 return '';
7 }
8
9 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
10 $xmlrpc_request = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;
11 $rest_request = defined( 'REST_REQUEST' ) && REST_REQUEST;
12 $robots_request = strpos( $_SERVER['REQUEST_URI'], 'robots.txt' ) != false;
13
14 $skip_output = ( $doing_ajax || $xmlrpc_request || $rest_request || $robots_request );
15 if ( false == strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) && ! $skip_output ) {
16 echo '<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->';
17 }
18 }
19
20 if ( false == defined( 'WPCACHEHOME' ) ) {
21 define( 'ADVANCEDCACHEPROBLEM', 1 );
22 } elseif ( ! include_once WPCACHEHOME . 'wp-cache-phase1.php' ) {
23 if ( ! @is_file( WPCACHEHOME . 'wp-cache-phase1.php' ) ) {
24 define( 'ADVANCEDCACHEPROBLEM', 1 );
25 }
26 }
27 if ( defined( 'ADVANCEDCACHEPROBLEM' ) ) {
28 register_shutdown_function( 'wpcache_broken_message' );
29 }
30
1 <svg width="513" height="400" viewBox="0 0 513 400" fill="none" xmlns="http://www.w3.org/2000/svg">
2 <g filter="url(#filter0_f_2285_9948)">
3 <path opacity="0.7" d="M505.462 -126.766C530.541 -119.966 549.288 -98.8259 572.421 -86.2516C600.401 -71.0427 638.717 -72.4006 656.759 -44.5276C674.393 -17.2838 665.913 20.8197 663.238 54.0552C660.751 84.9436 650.487 113.365 641.675 142.841C632.059 175.007 630.926 212.795 608.725 236.396C586.471 260.054 552.462 263.253 522.033 270.029C492.682 276.566 463.078 280.134 433.434 275.432C402.994 270.605 372.263 262.269 347.494 242.349C322.667 222.382 304.977 193.366 292.881 162.392C281.191 132.458 280.938 99.6507 279.082 67.1702C277.181 33.9036 268.485 -1.53342 281.799 -31.5256C295.088 -61.4623 324.768 -77.8611 350.985 -94.8026C374.635 -110.085 400.357 -119.998 427.357 -125.585C453.264 -130.946 479.871 -133.705 505.462 -126.766Z" fill="#F5E6B3"/>
4 <path opacity="0.7" d="M274.015 156.173C295.086 169.132 307.167 193.384 321.975 214.247C336.016 234.031 352.197 252.418 359.227 276.233C366.356 300.379 368.273 326.743 362.435 351.298C356.74 375.254 340.991 394.185 326.63 413.345C312.893 431.674 295.965 445.599 279.86 461.47C259.756 481.283 245.911 513.006 219.385 519.036C193.402 524.943 169.073 503.68 144.71 492.194C120.547 480.803 90.952 475.33 76.2142 451.541C61.3709 427.582 68.762 395.334 66.8348 366.495C65.2206 342.34 64.3226 318.928 65.737 294.759C67.2819 268.358 62.3709 239.32 75.5755 217.13C88.7931 194.918 115.438 188.59 136.618 175.644C157.993 162.579 177.206 143.602 201.505 140.158C226.271 136.649 252.261 142.795 274.015 156.173Z" fill="#CED9F2"/>
5 <path d="M549.377 206.234C594.702 223.625 610.9 283.303 639.95 325.028C666.696 363.443 704.795 395.077 713.74 442.307C722.685 489.54 697.844 534.7 688.591 581.863C678.121 635.231 687.426 696.612 655.585 738.726C623.071 781.732 567.997 793.298 518.428 806.93C467.16 821.029 413.471 836.097 362.916 819.213C311.973 802.2 266.336 763.635 239.174 713.667C213.549 666.525 223.51 608.177 218.559 553.647C214.133 504.904 202.281 457.338 211.548 409.411C221.467 358.118 235.699 302.891 273.35 270.285C310.684 237.954 363.969 247.851 410.604 237.03C457.576 226.13 504.076 188.853 549.377 206.234Z" fill="#069E08" fill-opacity="0.11"/>
6 </g>
7 <defs>
8 <filter id="filter0_f_2285_9948" x="-19.4263" y="-215.362" width="819.537" height="1126.51" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
9 <feFlood flood-opacity="0" result="BackgroundImageFix"/>
10 <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
11 <feGaussianBlur stdDeviation="42.2297" result="effect1_foregroundBlur_2285_9948"/>
12 </filter>
13 </defs>
14 </svg>
...\ No newline at end of file ...\ No newline at end of file
1 <svg class="jitm-jp-logo" viewBox="0 0 176 32" xmlns="http://www.w3.org/2000/svg">
2 <path d="M16 32C24.8365 32 32 24.8362 32 15.9994C32 7.16259 24.8365 0 16 0C7.16351 0 0 7.16377 0 16.0006C0 24.8374 7.16351 32 16 32Z" fill="#069E08"/>
3 <path d="m16.794 13.313v15.511l8-15.511h-8z" fill="#fff"/>
4 <path d="m15.176 18.657v-15.482l-7.9692 15.482h7.9692z" fill="#fff"/>
5 <path d="m41.711 27.015c-0.4629-0.7159-0.8936-1.4307-1.3254-2.1152 2.2813-1.4004 3.0517-2.5196 3.0517-4.636v-12.227h-2.6821v-2.3325h5.7039v13.938c0 3.547-1.0169 5.5378-4.7481 7.3729z"/>
6 <path d="m65.603 18.677c0 1.1819 0.8326 1.3063 1.3876 1.3063 0.5551 0 1.3566-0.1871 1.9727-0.3731v2.178c-0.8637 0.2801-1.7573 0.4974-2.9907 0.4974-1.4798 0-3.206-0.5602-3.206-3.174v-6.4095h-1.5719v-2.2093h1.5719v-3.2657h2.8364v3.2669h3.5756v2.2093h-3.5756v5.9737z"/>
7 <path d="m71.523 28.104v-17.641h2.7132v1.0576c1.079-0.8402 2.2813-1.369 3.7611-1.369 2.5588 0 4.5937 1.8049 4.5937 5.6935 0 3.8585-2.2191 6.4095-5.8881 6.4095-0.8936 0-1.603-0.1243-2.3435-0.2801v6.098h-2.8364v0.0314zm5.7338-15.587c-0.8326 0-1.8805 0.4045-2.8675 1.2761v6.0051c0.6161 0.1243 1.2645 0.2173 2.127 0.2173 2.0038 0 3.145-1.2761 3.145-3.9515 0-2.458-0.8326-3.547-2.4045-3.547z"/>
8 <path d="m93.748 22.007h-2.651v-1.2761h-0.0622c-0.9247 0.716-2.066 1.4935-3.7611 1.4935-1.4798 0-3.0828-1.089-3.0828-3.2983 0-2.9555 2.4966-3.5157 4.254-3.7644l2.4966-0.3416v-0.3417c0-1.5562-0.6161-2.0536-2.066-2.0536-0.7094 0-2.3734 0.2173-3.73 0.7775l-0.2464-2.3023c1.2334-0.4358 2.9285-0.7461 4.3473-0.7461 2.7741 0 4.5626 1.1204 4.5626 4.4489v7.4042h-0.061zm-2.8364-5.382-2.3435 0.373c-0.7094 0.093-1.4487 0.5288-1.4487 1.5864 0 0.9332 0.524 1.462 1.2944 1.462 0.8326 0 1.7262-0.4974 2.4966-1.0576v-2.3638h0.0012z"/>
9 <path d="m105.46 21.633c-1.171 0.4044-2.219 0.6531-3.546 0.6531-4.2537 0-5.95-2.458-5.95-6.0352 0-3.7643 2.3435-6.098 6.135-6.098 1.417 0 2.281 0.2487 3.237 0.5602v2.4266c-0.833-0.3115-2.035-0.6531-3.206-0.6531-1.727 0-3.2064 0.9332-3.2064 3.6085 0 2.9555 1.4794 3.8585 3.3604 3.8585 0.894 0 1.88-0.1871 3.206-0.7159v2.3953h-0.03z"/>
10 <path d="m110.83 15.442c0.246-0.2801 0.432-0.5602 4.008-4.9474h3.698l-4.624 5.4762 5.055 6.0666h-3.699l-4.408-5.4762v5.4762h-2.835v-16.333h2.836v9.7379h-0.031z"/>
11 <path d="m59.066 21.632c-1.4798 0.4672-2.7443 0.6531-4.2241 0.6531-3.6378 0-5.888-1.8351-5.888-6.1294 0-3.1425 1.9116-6.005 5.5794-6.005 3.6379 0 4.9023 2.551 4.9023 4.9776 0 0.8089-0.0622 1.2447-0.0921 1.7107h-7.3367c0.0622 2.5197 1.4798 3.1112 3.6067 3.1112 1.1712 0 2.2191-0.2801 3.4226-0.7159v2.3953h0.0299v0.0024zm-2.5888-6.6896c0-1.4005-0.4629-2.6138-1.9726-2.6138-1.4176 0-2.2813 1.0262-2.4667 2.6138h4.4393z"/>
12 <path d="m131.97 10.894c0 0.6585-0.146 1.2617-0.439 1.8106-0.293 0.549-0.777 1.0038-1.452 1.3679v0.0454c0.375 0.1284 0.718 0.2933 1.03 0.4936 0.311 0.2003 0.577 0.4383 0.799 0.7149 0.22 0.2767 0.394 0.5888 0.518 0.9363 0.124 0.3486 0.185 0.7382 0.185 1.1687 0 0.3708-0.058 0.7681-0.174 1.192-0.117 0.4238-0.321 0.8344-0.614 1.2317s-0.683 0.7626-1.17 1.0946c-0.487 0.3331-1.103 0.5976-1.846 0.7946-0.188 0.0454-0.392 0.0874-0.614 0.1251-0.221 0.0376-0.467 0.0697-0.737 0.0962-0.27 0.0266-0.571 0.0454-0.9 0.0565-0.331 0.0111-0.702 0.0166-1.114 0.0166h-4.378v-15.184h5.234c1.117 0 2.018 0.114 2.701 0.34087 0.51 0.16601 0.953 0.38403 1.328 0.65297 0.375 0.26893 0.685 0.56774 0.929 0.89644 0.243 0.3287 0.423 0.67731 0.54 1.0436 0.116 0.36628 0.174 0.73598 0.174 1.1056zm-5.661 2.2135c0.749 0 1.309-0.0753 1.677-0.2269 0.413-0.1738 0.707-0.4139 0.883-0.7205 0.176-0.3065 0.265-0.6529 0.265-1.0381 0-0.4006-0.101-0.7581-0.304-1.0724-0.203-0.31431-0.548-0.54672-1.035-0.69834-0.203-0.06087-0.439-0.10403-0.709-0.13059s-0.604-0.03984-1.002-0.03984h-2.262v3.9267h2.487zm-2.487 2.3263v4.2786h1.801c0.479 0 0.892-0.0133 1.238-0.0399 0.344-0.0265 0.641-0.0697 0.889-0.1306 0.383-0.083 0.701-0.1948 0.957-0.3353 0.255-0.1395 0.461-0.2988 0.619-0.477 0.158-0.1771 0.27-0.3741 0.338-0.5899s0.101-0.4438 0.101-0.6861c0-0.4239-0.116-0.7947-0.349-1.1123s-0.596-0.5556-1.092-0.7149c-0.217-0.0687-0.473-0.1174-0.765-0.1472-0.293-0.0299-0.667-0.0454-1.125-0.0454h-2.612z" fill="#646970"/>
13 <path d="m145.21 16.368c0 0.8697-0.13 1.6634-0.391 2.3813-0.261 0.7178-0.635 1.3318-1.121 1.8432-0.487 0.5113-1.075 0.9065-1.765 1.1845-0.689 0.2791-1.459 0.4175-2.31 0.4175-0.873 0-1.657-0.1396-2.351-0.4175-0.694-0.278-1.281-0.6732-1.764-1.1845-0.484-0.5114-0.854-1.1254-1.109-1.8432-0.257-0.7168-0.386-1.5116-0.386-2.3813s0.13-1.6634 0.391-2.3813c0.261-0.7167 0.635-1.3319 1.121-1.8432 0.487-0.5113 1.076-0.9065 1.765-1.1845 0.689-0.2791 1.46-0.4175 2.31-0.4175 0.874 0 1.657 0.1396 2.351 0.4175 0.694 0.2791 1.282 0.6732 1.765 1.1845s0.852 1.1254 1.108 1.8432c0.257 0.7179 0.386 1.5116 0.386 2.3813zm-2.816 0c0-0.5872-0.07-1.1064-0.207-1.5574-0.138-0.4499-0.33-0.8284-0.575-1.1331-0.246-0.3048-0.541-0.5337-0.886-0.6866-0.345-0.153-0.721-0.2289-1.127-0.2289-0.399 0-0.768 0.0759-1.108 0.2289-0.341 0.1529-0.635 0.3818-0.879 0.6866-0.246 0.3059-0.438 0.6832-0.575 1.1331-0.138 0.4499-0.208 0.9691-0.208 1.5574 0 0.5872 0.07 1.1063 0.208 1.5574 0.137 0.4499 0.331 0.8261 0.58 1.1275 0.249 0.3015 0.544 0.5303 0.885 0.6866s0.714 0.2345 1.121 0.2345c0.406 0 0.778-0.0782 1.115-0.2345 0.338-0.1563 0.628-0.3851 0.874-0.6866 0.245-0.3014 0.437-0.6776 0.575-1.1275 0.137-0.4511 0.207-0.9702 0.207-1.5574z" fill="#646970"/>
14 <path d="m157.45 16.368c0 0.8697-0.126 1.6634-0.379 2.3813-0.253 0.7178-0.615 1.3318-1.086 1.8432-0.471 0.5113-1.042 0.9065-1.71 1.1845-0.667 0.2791-1.413 0.4175-2.238 0.4175-0.846 0-1.605-0.1396-2.277-0.4175-0.672-0.278-1.241-0.6732-1.709-1.1845-0.468-0.5114-0.827-1.1254-1.074-1.8432-0.249-0.7168-0.374-1.5116-0.374-2.3813s0.126-1.6634 0.379-2.3813c0.252-0.7167 0.615-1.3319 1.086-1.8432s1.041-0.9065 1.709-1.1845c0.668-0.2791 1.414-0.4175 2.239-0.4175 0.846 0 1.605 0.1396 2.277 0.4175 0.672 0.2791 1.241 0.6732 1.709 1.1845s0.826 1.1254 1.074 1.8432c0.249 0.7179 0.374 1.5116 0.374 2.3813zm-2.729 0c0-0.5872-0.068-1.1064-0.201-1.5574-0.134-0.4499-0.319-0.8284-0.557-1.1331-0.238-0.3048-0.524-0.5337-0.858-0.6866-0.335-0.153-0.699-0.2289-1.092-0.2289-0.386 0-0.744 0.0759-1.074 0.2289-0.33 0.1529-0.614 0.3818-0.851 0.6866-0.238 0.3059-0.424 0.6832-0.557 1.1331-0.134 0.4499-0.201 0.9691-0.201 1.5574 0 0.5872 0.067 1.1063 0.201 1.5574 0.133 0.4499 0.321 0.8261 0.562 1.1275 0.241 0.3015 0.527 0.5303 0.857 0.6866s0.692 0.2345 1.086 0.2345c0.393 0 0.754-0.0782 1.081-0.2345s0.608-0.3851 0.846-0.6866c0.238-0.3014 0.423-0.6776 0.557-1.1275 0.135-0.4511 0.201-0.9702 0.201-1.5574z" fill="#646970"/>
15 <path d="m164.24 18.692c0-0.2367-0.067-0.4309-0.199-0.5839-0.133-0.1529-0.309-0.2802-0.529-0.384-0.219-0.1027-0.471-0.192-0.756-0.269-0.283-0.0759-0.581-0.1529-0.892-0.2288-0.394-0.1072-0.772-0.2311-1.136-0.3718-0.364-0.1406-0.684-0.3259-0.96-0.5548-0.277-0.2288-0.497-0.5168-0.66-0.864-0.163-0.3471-0.245-0.7724-0.245-1.2759 0-0.6184 0.11-1.1542 0.33-1.6086 0.219-0.4543 0.517-0.8294 0.892-1.1274 0.375-0.2981 0.81-0.5191 1.307-0.6642s1.021-0.2177 1.574-0.2177c0.674 0 1.307 0.0558 1.898 0.1663s1.125 0.2534 1.603 0.4287v2.2102c-0.251-0.0837-0.514-0.1618-0.791-0.2344-0.277-0.0725-0.557-0.135-0.841-0.1886s-0.567-0.0971-0.847-0.1318c-0.28-0.0346-0.545-0.0513-0.796-0.0513-0.318 0-0.587 0.0301-0.807 0.0915-0.219 0.0614-0.398 0.1429-0.534 0.2456-0.137 0.1027-0.235 0.221-0.296 0.355s-0.091 0.2724-0.091 0.4175c0 0.2523 0.066 0.4577 0.198 0.6184 0.133 0.1608 0.316 0.2903 0.551 0.3896 0.235 0.0994 0.481 0.1808 0.74 0.2467 0.257 0.0648 0.507 0.1284 0.75 0.1887 0.379 0.0915 0.757 0.202 1.136 0.3315s0.72 0.3114 1.023 0.5436c0.303 0.2333 0.551 0.5347 0.745 0.9042 0.193 0.3706 0.29 0.8417 0.29 1.4133 0 0.6262-0.118 1.1709-0.353 1.6364s-0.563 0.8529-0.983 1.1621-0.925 0.5381-1.512 0.6865c-0.588 0.1485-1.233 0.2233-1.938 0.2233-0.697 0-1.324-0.0558-1.881-0.1663-0.556-0.1106-1.017-0.2501-1.381-0.4175v-2.1857c0.591 0.221 1.136 0.3717 1.637 0.4521 0.5 0.0803 0.967 0.1205 1.398 0.1205 0.334 0 0.644-0.0245 0.932-0.0748 0.289-0.0491 0.536-0.1272 0.745-0.2344s0.374-0.2422 0.495-0.4063c0.124-0.1641 0.184-0.3617 0.184-0.5905z" fill="#646970"/>
16 <path d="m176 21.896c-0.302 0.0916-0.661 0.1641-1.079 0.2177-0.417 0.0536-0.808 0.0804-1.169 0.0804-0.92 0-1.671-0.1507-2.256-0.4521-0.584-0.3014-0.996-0.7344-1.237-1.2992-0.173-0.4041-0.26-0.9532-0.26-1.6486v-5.745h-2.046v-2.2323h2.046v-3.1008h2.678v3.1019h3.165v2.2323h-3.165v5.3912c0 0.4275 0.064 0.7445 0.192 0.9498 0.226 0.3516 0.674 0.5269 1.345 0.5269 0.308 0 0.616-0.0246 0.921-0.0748 0.305-0.0491 0.593-0.1128 0.864-0.1887v2.2413h1e-3z" fill="#646970"/>
17 </svg>
1 {
2 "name": "automattic/wp-super-cache",
3 "description": "A very fast caching engine for WordPress that produces static html files.",
4 "type": "wordpress-plugin",
5 "license": "GPL-2.0-or-later",
6 "require": {
7 "automattic/jetpack-device-detection": "^1.4.24"
8 },
9 "require-dev": {
10 "yoast/phpunit-polyfills": "1.0.4",
11 "automattic/jetpack-changelogger": "^3.3.2"
12 },
13 "autoload": {
14 "classmap": [
15 "src/"
16 ]
17 },
18 "scripts": {
19 "phpunit": [
20 "./vendor/phpunit/phpunit/phpunit --colors=always"
21 ],
22 "test-php": [
23 "@composer phpunit"
24 ],
25 "test-e2e": [
26 "cd tests/e2e && pnpm i && pnpm env:up && pnpm test:run"
27 ],
28 "build-production": "echo 'Add your build step to composer.json, please!'",
29 "build-development": "echo 'Add your build step to composer.json, please!'"
30 },
31 "repositories": [],
32 "minimum-stability": "dev",
33 "prefer-stable": true,
34 "extra": {
35 "autorelease": true,
36 "autotagger": true,
37 "changelogger": {
38 "link-template": "https://github.com/Automattic/wp-super-cache/compare/v${old}...v${new}"
39 },
40 "mirror-repo": "Automattic/wp-super-cache",
41 "release-branch-prefix": "super-cache",
42 "wp-plugin-slug": "wp-super-cache",
43 "wp-svn-autopublish": true
44 },
45 "config": {
46 "autoloader-suffix": "6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ1_9_4"
47 }
48 }
1 ( function ( $ ) {
2 $( document ).ready( function () {
3 $( '#wp-admin-bar-delete-cache' ).on( 'click', function () {
4 $( '#wp-admin-bar-delete-cache' ).fadeOut( 'slow' );
5 $.ajax( {
6 type: 'post',
7 dataType: 'json',
8 url: wpsc_ajax.ajax_url,
9 data: {
10 // wp ajax action
11 action: 'ajax-delete-cache',
12
13 path: wpsc_ajax.path,
14 admin: wpsc_ajax.admin,
15
16 // send the nonce along with the request
17 nonce: wpsc_ajax.nonce,
18 },
19 success: function ( msg ) {
20 wpsc_ajax.admin == 1 && console.log( 'Deleted entire cache' );
21 wpsc_ajax.admin == 0 && console.log( 'Deleted cache for this page and reloading' );
22 window.location.reload();
23 },
24 complete: function ( msg ) {
25 $( '#wp-admin-bar-delete-cache' ).fadeIn( 'slow' );
26 },
27 } );
28 return false;
29 } );
30 } );
31 } )( jQuery );
1 <?php
2 if ( defined( 'WPSCDISABLEDELETEBUTTON' ) ) {
3 return;
4 }
5
6 /**
7 * Adds "Delete Cache" button in WP Toolbar.
8 */
9 function wpsc_admin_bar_render( $wp_admin_bar ) {
10
11 if ( ! function_exists( 'current_user_can' ) || ! is_user_logged_in() ) {
12 return false;
13 }
14
15 $path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
16 if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) {
17
18 $site_regex = preg_quote( $path_to_home, '`' );
19 $req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] );
20 $path = preg_replace( '`^' . $site_regex . '`', '', $req_uri );
21
22 $wp_admin_bar->add_menu( array(
23 'parent' => '',
24 'id' => 'delete-cache',
25 'title' => __( 'Delete Cache', 'wp-super-cache' ),
26 'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
27 'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache-' . $path . '_0', 'nonce' )
28 ) );
29 }
30
31 if ( is_admin() && ( wpsupercache_site_admin() || current_user_can( 'delete_others_posts' ) ) ) {
32 $wp_admin_bar->add_menu( array(
33 'parent' => '',
34 'id' => 'delete-cache',
35 'title' => __( 'Delete Cache', 'wp-super-cache' ),
36 'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
37 'href' => wp_nonce_url( admin_url( 'index.php?admin=1&action=delcachepage&path=' . rawurlencode( trailingslashit( $path_to_home ) ) ), 'delete-cache-' . trailingslashit( $path_to_home ) . '_1', 'nonce' )
38 ) );
39 }
40 }
41 add_action( 'admin_bar_menu', 'wpsc_admin_bar_render', 99 );
42
43 function wpsc_delete_cache_scripts() {
44 if ( ! is_user_logged_in() ) {
45 return;
46 }
47
48 if (
49 is_plugin_active( 'amp/amp.php' ) ||
50 ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() )
51 ) {
52 wp_cache_debug( 'AMP detected. Not loading Delete Cache button JavaScript.' );
53 return;
54 }
55
56 $path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
57
58 wp_enqueue_script( 'delete-cache-button', plugins_url( '/delete-cache-button.js', __FILE__ ), array('jquery'), '1.0', 1 );
59
60 if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can( 'delete_others_posts' ) ) {
61 $site_regex = preg_quote( $path_to_home, '`' );
62 $req_uri = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] );
63 $path_to_home = preg_replace( '`^' . $site_regex . '`', '', $req_uri );
64 $admin = 0;
65 } else {
66 $admin = 1;
67 }
68
69 if ( $path_to_home === '' ) {
70 $path_to_home = '/';
71 }
72
73 $nonce = wp_create_nonce( 'delete-cache-' . $path_to_home . '_' . $admin );
74 wp_localize_script( 'delete-cache-button', 'wpsc_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'path' => $path_to_home, 'admin' => $admin, 'nonce' => $nonce ) );
75 }
76 add_action( 'wp_ajax_ajax-delete-cache', 'wpsc_admin_bar_delete_cache_ajax' );
77 add_action( 'admin_enqueue_scripts', 'wpsc_delete_cache_scripts' );
78
79 /**
80 * Delete cache for a specific page.
81 */
82 function wpsc_admin_bar_delete_cache_ajax() {
83 // response output
84 header( "Content-Type: application/json" );
85 if ( ! wpsc_delete_cache_directory() ) {
86 if ( defined( 'WPSCDELETEERROR' ) ) {
87 return json_decode( constant( 'WPSCDELETEERROR' ) );
88 } else {
89 return json_decode( false );
90 }
91 }
92 }
93
94 function wpsc_admin_bar_delete_cache() {
95 $referer = wp_get_referer();
96
97 if ( ! isset( $_GET['admin'] ) ) {
98 $_GET['admin'] = 0;
99 }
100
101 foreach( array( 'path', 'nonce', 'admin' ) as $part ) {
102 if ( isset( $_GET[ $part ] ) ) {
103 $_POST[ $part ] = $_GET[ $part ];
104 }
105 }
106 wpsc_delete_cache_directory();
107
108 $req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
109 $valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
110
111 if (
112 $valid_nonce
113 && $referer
114 && $req_path
115 && (
116 false !== stripos( $referer, $req_path )
117 || 0 === stripos( $referer, wp_login_url() )
118 )
119 ) {
120 /**
121 * Hook into the cache deletion process after a successful cache deletion from the admin bar button.
122 *
123 * @since 1.9
124 *
125 * @param string $req_path Path of the page where the cache flush was requested.
126 * @param string $referer Referer URL.
127 */
128 do_action( 'wpsc_after_delete_cache_admin_bar', $req_path, $referer );
129
130 if ( $_POST['admin'] ) {
131 wp_safe_redirect( $referer );
132 } else {
133 wp_safe_redirect( esc_url_raw( home_url( $req_path ) ) );
134 }
135 exit;
136 } else {
137 die( "Oops. Problem with nonce. Please delete cached page from settings page." );
138 }
139 }
140
141 if ( 'delcachepage' === filter_input( INPUT_GET, 'action' ) ) {
142 add_action( 'admin_init', 'wpsc_admin_bar_delete_cache' );
143 }
144
145 function wpsc_delete_cache_directory() {
146 if ( ! current_user_can( 'delete_others_posts' ) ) {
147 return false;
148 }
149
150 $req_path = isset( $_POST['path'] ) ? sanitize_text_field( stripslashes( $_POST['path'] ) ) : '';
151 $valid_nonce = ( $req_path && isset( $_POST['nonce'] ) ) ? wp_verify_nonce( $_POST['nonce'], 'delete-cache-' . $_POST['path'] . '_' . $_POST['admin'] ) : false;
152
153 if ( ! $valid_nonce ) {
154 wp_cache_debug( 'wpsc_delete_cache_directory: nonce was not valid' );
155 return false;
156 }
157
158 $path = $valid_nonce ? realpath( trailingslashit( get_supercache_dir() . str_replace( '..', '', preg_replace( '/:.*$/', '', $req_path ) ) ) ) : false;
159
160 if ( $path ) {
161 if ( isset( $_POST['admin'] ) && (int) $_POST['admin'] === 1 ) {
162 global $file_prefix;
163 wp_cache_debug( 'Cleaning cache for this site.' );
164 wp_cache_clean_cache( $file_prefix );
165 return;
166 }
167 $path = trailingslashit( $path );
168 $supercachepath = realpath( get_supercache_dir() );
169
170 if ( false === wp_cache_confirm_delete( $path ) || 0 !== strpos( $path, $supercachepath ) ) {
171 wp_cache_debug( 'Could not delete directory: ' . $path );
172 define( 'WPSCDELETEERROR', 'Could not delete directory' );
173 return false;
174 }
175
176 wp_cache_debug( 'Deleting cache files in directory: ' . $path );
177 wpsc_delete_files( $path );
178 return;
179 } else {
180 wp_cache_debug( 'wpsc_delete_cache_directory: Could not delete directory. It does not exist: ' . esc_attr( $_POST['path'] ) );
181 }
182 }
1 jQuery( document ).ready( function () {
2 load_preload_status();
3 setInterval( function () {
4 load_preload_status();
5 }, 1000 );
6 } );
7
8 /**
9 *
10 */
11 function load_preload_status() {
12 jQuery.get( {
13 url: wpsc_preload_ajax.preload_permalink_url + '?' + Math.random(),
14 success: function ( response ) {
15 jQuery( '#preload_status' ).text( response );
16 },
17 } );
18 }
1 <?php
2
3 function wpsc_preload_notification_scripts() {
4 global $cache_path;
5 if (
6 isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' &&
7 isset( $_GET['tab'] ) && $_GET['tab'] === 'preload' &&
8 @file_exists( $cache_path . 'preload_permalink.txt' )
9 ) {
10 wp_enqueue_script( 'preload-notification', plugins_url( '/preload-notification.js', __FILE__ ), array('jquery'), '1.0', 1 );
11 wp_localize_script( 'preload-notification', 'wpsc_preload_ajax', array( 'preload_permalink_url' => home_url( str_replace( $_SERVER['DOCUMENT_ROOT'], '', $cache_path ) . '/preload_permalink.txt' ) ) );
12 }
13 }
14 add_action( 'admin_enqueue_scripts', 'wpsc_preload_notification_scripts' );
1 jQuery( document ).ready( () => {
2 // Don't run on versions of WordPress too old for the block editor and the translation methods it brings.
3 // All the install / activate options are plain links with meaningful destinations anyway.
4 if ( ! window.wp || ! window.wp.i18n ) {
5 return;
6 }
7
8 const { __, sprintf } = window.wp.i18n;
9 const ajaxurl = window.ajaxurl;
10 const wpscAdmin = window.wpscAdmin;
11
12 const link = jQuery( '.wpsc-install-action-button' );
13 const label = link.find( 'label' );
14 const spinner = link.find( '.spinner' );
15
16 // Dismiss Boost banner.
17 jQuery( '.wpsc-boost-dismiss' ).on( 'click', function () {
18 jQuery( '.wpsc-boost-banner' ).fadeOut( 'slow' );
19
20 jQuery.post( ajaxurl, {
21 action: 'wpsc-hide-boost-banner',
22 nonce: wpscAdmin.boostDismissNonce,
23 } );
24 } );
25
26 // One-click install for Boost.
27 jQuery( '#wpsc-install-boost-button' ).on( 'click', event => {
28 event.preventDefault();
29 showBoostBannerBusy( __( 'Installing…', 'wp-super-cache' ) );
30
31 jQuery
32 .post( ajaxurl, {
33 action: 'wpsc_install_plugin',
34 _ajax_nonce: wpscAdmin.boostInstallNonce,
35 slug: 'jetpack-boost',
36 } )
37 .done( response => {
38 if ( response.success ) {
39 activateBoost();
40 } else {
41 showBoostBannerError( response.data );
42 }
43 } )
44 .fail( response => {
45 showBoostBannerError(
46 sprintf(
47 /* translators: %d is an HTTP error code */
48 __( 'Failed to install Jetpack Boost: HTTP %d error received', 'wp-super-cache' ),
49 response.status
50 )
51 );
52 } );
53 } );
54
55 // Handle activate button click.
56 jQuery( '#wpsc-activate-boost-button' ).on( 'click', event => {
57 event.preventDefault();
58 activateBoost();
59 } );
60
61 // Helper function to show Boost Banner work in progress.
62 const showBoostBannerBusy = action => {
63 link.attr( 'disabled', true );
64 label.text( action );
65 spinner.addClass( 'is-active' ).show();
66 };
67
68 // Helper function to reset Boost Banner button.
69 const resetBoostBannerButton = () => {
70 link.attr( 'disabled', false );
71 jQuery( '#wpsc-activate-boost-button' )
72 .find( 'label' )
73 .text( __( 'Activate Jetpack Boost', 'wp-super-cache' ) );
74 jQuery( '#wpsc-install-boost-button' )
75 .find( 'label' )
76 .text( __( 'Install Jetpack Boost', 'wp-super-cache' ) );
77 spinner.removeClass( 'is-active' ).hide();
78 };
79
80 // Helper function to show an error.
81 const showBoostBannerError = err => {
82 resetBoostBannerButton();
83
84 jQuery( '#wpsc-boost-banner-error' )
85 .text(
86 err || __( 'An error occurred while trying to activate Jetpack Boost', 'wp-super-cache' )
87 )
88 .show();
89 };
90
91 // Activate Jetpack Boost.
92 const activateBoost = () => {
93 showBoostBannerBusy( __( 'Activating…', 'wp-super-cache' ) );
94
95 jQuery
96 .post( ajaxurl, {
97 action: 'wpsc_activate_boost',
98 _ajax_nonce: wpscAdmin.boostActivateNonce,
99 } )
100 .done( response => {
101 if ( response.success ) {
102 label.text( 'Success! Sending you to Jetpack Boost...' );
103 spinner.hide();
104 window.location.href = 'admin.php?page=jetpack-boost';
105 } else {
106 showBoostBannerError( response.data );
107 }
108 } )
109 .fail( response => {
110 showBoostBannerError(
111 sprintf(
112 /* translators: %d is an HTTP error code */
113 __( 'Failed to activate Jetpack Boost: HTTP %d error received', 'wp-super-cache' ),
114 response.status
115 )
116 );
117 } );
118 };
119 } );
This diff could not be displayed because it is too large.
1 {
2 "private": true,
3 "name": "@automattic/jetpack-super-cache",
4 "version": "1.9.4",
5 "description": "A very fast caching engine for WordPress that produces static html files.",
6 "homepage": "https://jetpack.com",
7 "bugs": {
8 "url": "https://github.com/Automattic/jetpack/labels/[Plugin] Super Cache"
9 },
10 "repository": {
11 "type": "git",
12 "url": "https://github.com/Automattic/jetpack.git",
13 "directory": "projects/plugins/super-cache"
14 },
15 "license": "GPL-2.0-or-later",
16 "author": "Automattic",
17 "scripts": {
18 "build": "echo 'Not implemented.'",
19 "build-js": "echo 'Not implemented.'",
20 "build-production": "echo 'Not implemented.'",
21 "build-production-js": "echo 'Not implemented.'",
22 "clean": "true"
23 },
24 "devDependencies": {}
25 }
1 <?php
2 extract( wpsc_update_debug_settings() ); // $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_super_cache_comments, $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug, $wp_cache_debug_username
3 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
4
5 echo '<a name="debug"></a>';
6 echo '<fieldset class="options">';
7 echo '<p>' . __( 'Fix problems with the plugin by debugging it here. It will log to a file in your cache directory.', 'wp-super-cache' ) . '</p>';
8 if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
9 extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
10 }
11
12 $log_file_link = "<a href='" . home_url( str_replace( $_SERVER['DOCUMENT_ROOT'], '', "{$cache_path}view_{$wp_cache_debug_log}?wp-admin=1&wp-json=1&filter=" ) ) . "'>$wp_cache_debug_log</a>";
13
14 if ( $wp_super_cache_debug == 1 ) {
15 echo "<p>" . sprintf( __( 'Currently logging to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
16 } else {
17 echo "<p>" . sprintf( __( 'Last Logged to: %s', 'wp-super-cache' ), $log_file_link ) . "</p>";
18 }
19 echo "<p>" . sprintf( __( 'Username/Password: %s', 'wp-super-cache' ), $wp_cache_debug_username ) . "</p>";
20
21 echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
22 wp_nonce_field('wp-cache');
23 echo "<input type='hidden' name='wpsc_delete_log' value='1' />";
24 submit_button( __( 'Delete', 'wp-super-cache' ), 'delete', 'wpsc_delete_log_form', false );
25 echo "</form>";
26
27 echo '<form name="wpsc_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
28 if ( ! isset( $wp_super_cache_debug ) || $wp_super_cache_debug == 0 ) {
29 $debug_status_message = __( 'Enable Logging', 'wp-super-cache' );
30 $not_status = 1;
31 } else {
32 $debug_status_message = __( 'Disable Logging', 'wp-super-cache' );
33 $not_status = 0;
34 }
35 echo "<input type='hidden' name='wp_super_cache_debug' value='" . $not_status . "' />";
36 wp_nonce_field('wp-cache');
37 submit_button( $debug_status_message, 'primary', 'wpsc_log_status', true );
38 echo "</form>";
39
40 echo '<form name="wp_cache_debug" action="' . esc_url_raw( add_query_arg( 'tab', 'debug', $admin_url ) ) . '" method="post">';
41 echo "<input type='hidden' name='wp_cache_debug' value='1' /><br />";
42 echo "<table class='form-table'>";
43 echo "<tr><th>" . __( 'IP Address', 'wp-super-cache' ) . "</th><td> <input type='text' size='20' name='wp_cache_debug_ip' value='{$wp_cache_debug_ip}' /> " . sprintf( __( '(only log requests from this IP address. Your IP is %s)', 'wp-super-cache' ), $_SERVER[ 'REMOTE_ADDR' ] ) . "</td></tr>";
44 echo "<tr><th valign='top'>" . __( 'Cache Status Messages', 'wp-super-cache' ) . "</th><td><input type='checkbox' name='wp_super_cache_comments' value='1' " . checked( 1, $wp_super_cache_comments, false ) . " /> " . __( 'enabled', 'wp-super-cache' ) . "<br />";
45 echo __( 'Display comments at the end of every page like this:', 'wp-super-cache' ) . "<br />";
46 echo "<pre>&lt;!-- Dynamic page generated in 0.450 seconds. -->
47 &lt;!-- Cached page generated by WP-Super-Cache on " . date( "Y-m-d H:i:s", time() ) . " -->
48 &lt;!-- super cache --></pre></td></tr>";
49 echo "</table>\n";
50 if ( isset( $wp_super_cache_advanced_debug ) ) {
51 echo "<h5>" . __( 'Advanced', 'wp-super-cache' ) . "</h5><p>" . __( 'In very rare cases two problems may arise on some blogs:<ol><li> The front page may start downloading as a zip file.</li><li> The wrong page is occasionally cached as the front page if your blog uses a static front page and the permalink structure is <em>/%category%/%postname%/</em>.</li></ol>', 'wp-super-cache' ) . '</p>';
52 echo "<p>" . __( 'I&#8217;m 99% certain that they aren&#8217;t bugs in WP Super Cache and they only happen in very rare cases but you can run a simple check once every 5 minutes to verify that your site is ok if you&#8217;re worried. You will be emailed if there is a problem.', 'wp-super-cache' ) . "</p>";
53 echo "<table class='form-table'>";
54 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_check' value='1' " . checked( 1, $wp_super_cache_front_page_check, false ) . " /> " . __( 'Check front page every 5 minutes.', 'wp-super-cache' ) . "</td></tr>";
55 echo "<tr><td valign='top'>" . __( 'Front page text', 'wp-super-cache' ) . "</td><td> <input type='text' size='30' name='wp_super_cache_front_page_text' value='{$wp_super_cache_front_page_text}' /> (" . __( 'Text to search for on your front page. If this text is missing, the cache will be cleared. Leave blank to disable.', 'wp-super-cache' ) . ")</td></tr>";
56 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_clear' value='1' " . checked( 1, $wp_super_cache_front_page_clear, false ) . " /> " . __( 'Clear cache on error.', 'wp-super-cache' ) . "</td></tr>";
57 echo "<tr><td valign='top' colspan='2'><input type='checkbox' name='wp_super_cache_front_page_notification' value='1' " . checked( 1, $wp_super_cache_front_page_notification, false ) . " /> " . __( 'Email the blog admin when checks are made. (useful for testing)', 'wp-super-cache' ) . "</td></tr>";
58
59 echo "</table>\n";
60 }
61 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save Settings', 'wp-super-cache' ) . '" /></div>';
62 wp_nonce_field('wp-cache');
63 echo "</form>\n";
64 echo '</fieldset>';
1 <a name='lockdown'></a>
2 <fieldset class="options">
3 <h4><?php _e( 'Lock Down:', 'wp-super-cache' ); ?> <?php echo $wp_lock_down == '0' ? '<span style="color:red">' . __( 'Disabled', 'wp-super-cache' ) . '</span>' : '<span style="color:green">' . __( 'Enabled', 'wp-super-cache' ) . '</span>'; ?></h4>
4 <p><?php _e( 'Prepare your server for an expected spike in traffic by enabling the lock down. When this is enabled, new comments on a post will not refresh the cached static files.', 'wp-super-cache' ); ?></p>
5 <p><?php _e( 'Developers: Make your plugin lock down compatible by checking the "WPLOCKDOWN" constant. The following code will make sure your plugin respects the WPLOCKDOWN setting.', 'wp-super-cache' ); ?>
6 <blockquote><code>if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) ) {
7 &nbsp;&nbsp;&nbsp;&nbsp;echo "<?php _e( 'Sorry. My blog is locked down. Updates will appear shortly', 'wp-super-cache' ); ?>";
8 }</code></blockquote>
9 <?php
10 if( $wp_lock_down == '1' ) {
11 ?><p><?php _e( 'WordPress is locked down. Super Cache static files will not be deleted when new comments are made.', 'wp-super-cache' ); ?></p><?php
12 } else {
13 ?><p><?php _e( 'WordPress is not locked down. New comments will refresh Super Cache static files as normal.', 'wp-super-cache' ); ?></p><?php
14 }
15 $new_lockdown = $wp_lock_down == '1' ? '0' : '1';
16 $new_lockdown_desc = $wp_lock_down == '1' ? __( 'Disable', 'wp-super-cache' ) : __( 'Enable', 'wp-super-cache' );
17 echo '<form name="wp_lock_down" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#lockdown' ) . '" method="post">';
18 echo "<input type='hidden' name='wp_lock_down' value='{$new_lockdown}' />";
19 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr( $new_lockdown_desc . ' ' . __( 'Lock Down', 'wp-super-cache' ) ) . '" /></div>';
20 wp_nonce_field( 'wp-cache' );
21 echo '</form>';
22
23 ?></fieldset><?php
24 if( $cache_enabled == true && $super_cache_enabled == true ) {
25 ?><a name='direct'></a>
26 <fieldset class="options">
27 <h4><?php _e( 'Directly Cached Files', 'wp-super-cache' ); ?></h4><?php
28
29 $cached_direct_pages = wpsc_update_direct_pages();
30
31 $readonly = '';
32 if( !is_writeable_ACLSafe( ABSPATH ) ) {
33 $readonly = 'READONLY';
34 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( 'You must make %s writable to enable this feature. As this is a security risk, please make it read-only after your page is generated.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
35 } else {
36 $abspath_stat = stat(ABSPATH . '/');
37 $abspath_mode = decoct( $abspath_stat[ 'mode' ] & 0777 );
38 if ( substr( $abspath_mode, -2 ) == '77' ) {
39 ?><p style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><strong><?php _e( 'Warning!', 'wp-super-cache' ); ?></strong> <?php printf( __( '%s is writable. Please make it readonly after your page is generated as this is a security risk.', 'wp-super-cache' ), ABSPATH ); ?></p><?php
40 }
41 }
42 echo '<form name="direct_page" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#direct' ) . '" method="post">';
43 if( is_array( $cached_direct_pages ) ) {
44 $out = '';
45 foreach( $cached_direct_pages as $page ) {
46 if( $page == '' )
47 continue;
48 $generated = '';
49 if( is_file( ABSPATH . $page . '/index.html' ) )
50 $generated = '<input class="button-secondary" type="Submit" name="deletepage" value="' . $page . '">';
51 $out .= "<tr><td><input type='text' $readonly name='direct_pages[]' size='30' value='$page' /></td><td>$generated</td></tr>";
52 }
53 if( $out != '' ) {
54 ?><table><tr><th><?php _e( 'Existing direct page', 'wp-super-cache' ); ?></th><th><?php _e( 'Delete cached file', 'wp-super-cache' ); ?></th></tr><?php
55 echo "$out</table>";
56 }
57 }
58
59 if ( 'READONLY' !== $readonly ) {
60 echo esc_html__( 'Add direct page:', 'wp-super-cache' ) . '<input type="text" name="new_direct_page" size="30" value="" />';
61 }
62 echo '<p>' . sprintf(
63 esc_html__( 'Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.', 'wp-super-cache' ),
64 esc_attr( ABSPATH )
65 ) . '</p>';
66 if ( 'READONLY' !== $readonly ) {
67 echo '<p>' . sprintf( __( 'For example: to cache <em>%1$sabout/</em>, you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ),
68 esc_attr( trailingslashit( get_option( 'home' ) ) )
69 ) . '</p>';
70 echo '<p>' . esc_html__( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . '</p>';
71
72 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . ' value="' . esc_attr__( 'Update Direct Pages', 'wp-super-cache' ) . '" /></div>';
73 }
74 wp_nonce_field( 'wp-cache' );
75 echo '</form>';
76 ?>
77 </fieldset>
78 <?php
79 } // if $super_cache_enabled
1 <?php
2 echo '<a name="preload"></a>';
3 if ( ! $cache_enabled || ! $super_cache_enabled || true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
4 echo '<div class="notice notice-warning"><p>' . __( 'Preloading of cache disabled. Please make sure simple or expert mode is enabled or talk to your host administrator.', 'wp-super-cache' ) . '</p></div>';
5 return;
6 }
7
8 $count = wpsc_post_count();
9 if ( $count > 1000 ) {
10 $min_refresh_interval = 720;
11 } else {
12 $min_refresh_interval = 30;
13 }
14
15 echo '<p>' . __( 'This will cache every published post and page on your site. It will create supercache static files so unknown visitors (including bots) will hit a cached page. This will probably help your Google ranking as they are using speed as a metric when judging websites now.', 'wp-super-cache' ) . '</p>';
16 echo '<p>' . __( 'Preloading creates lots of files however. Caching is done from the newest post to the oldest so please consider only caching the newest if you have lots (10,000+) of posts. This is especially important on shared hosting.', 'wp-super-cache' ) . '</p>';
17 echo '<p>' . __( 'In &#8217;Preload Mode&#8217; regular garbage collection will be disabled so that old cache files are not deleted. This is a recommended setting when the cache is preloaded.', 'wp-super-cache' ) . '</p>';
18 echo '<form name="cache_filler" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
19 echo '<input type="hidden" name="action" value="preload" />';
20 echo '<input type="hidden" name="page" value="wpsupercache" />';
21 echo '<p>' . sprintf( __( 'Refresh preloaded cache files every %s minutes. (0 to disable, minimum %d minutes.)', 'wp-super-cache' ), "<input type='text' size=4 name='wp_cache_preload_interval' value='" . (int) $wp_cache_preload_interval . "' />", $min_refresh_interval ) . '</p>';
22 if ( $count > 100 ) {
23 $step = (int)( $count / 10 );
24
25 $select = "<select name='wp_cache_preload_posts' size=1>";
26 $select .= "<option value='all' ";
27 if ( ! isset( $wp_cache_preload_posts ) || $wp_cache_preload_posts == 'all' ) {
28 $checked = 'selectect=1 ';
29 $best = 'all';
30 } else {
31 $checked = ' ';
32 $best = $wp_cache_preload_posts;
33 }
34 $select .= "{$checked}>" . __( 'all', 'wp-super-cache' ) . "</option>";
35
36 for( $c = $step; $c < $count; $c += $step ) {
37 $checked = ' ';
38 if ( $best == $c )
39 $checked = 'selected=1 ';
40 $select .= "<option value='$c'{$checked}>$c</option>";
41 }
42 $checked = ' ';
43 if ( $best == $count )
44 $checked = 'selected=1 ';
45 $select .= "<option value='$count'{$checked}>$count</option>";
46 $select .= "</select>";
47 echo '<p>' . sprintf( __( 'Preload %s posts.', 'wp-super-cache' ), $select ) . '</p>';
48 } else {
49 echo '<input type="hidden" name="wp_cache_preload_posts" value="' . $count . '" />';
50 }
51
52 echo '<input type="checkbox" name="wp_cache_preload_on" value="1" ';
53 echo $wp_cache_preload_on == 1 ? 'checked=1' : '';
54 echo ' /> ' . __( 'Preload mode (garbage collection disabled. Recommended.)', 'wp-super-cache' ) . '<br />';
55 echo '<input type="checkbox" name="wp_cache_preload_taxonomies" value="1" ';
56 echo $wp_cache_preload_taxonomies == 1 ? 'checked=1' : '';
57 echo ' /> ' . __( 'Preload tags, categories and other taxonomies.', 'wp-super-cache' ) . '<br />';
58 echo __( 'Send me status emails when files are refreshed.', 'wp-super-cache' ) . '<br />';
59 if ( !isset( $wp_cache_preload_email_volume ) )
60 $wp_cache_preload_email_volume = 'none';
61 echo '<select type="select" name="wp_cache_preload_email_volume">';
62 echo '<option value="none" '. selected( 'none', $wp_cache_preload_email_volume ) . '>'. __( 'No Emails', 'wp-super-cache' ) . '</option>';
63 echo '<option value="many" '. selected( 'many', $wp_cache_preload_email_volume ) . '>'. __( 'Many emails, 2 emails per 100 posts.', 'wp-super-cache' ) . '</option>';
64 echo '<option value="medium" '. selected( 'medium', $wp_cache_preload_email_volume ) . '>'. __( 'Medium, 1 email per 100 posts.', 'wp-super-cache' ) . '</option>';
65 echo '<option value="less" '. selected( 'less', $wp_cache_preload_email_volume ) . '>'. __( 'Less emails, 1 at the start and 1 at the end of preloading all posts.', 'wp-super-cache' ) . '</option>';
66 echo "</select>";
67
68 if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
69 $currently_preloading = true;
70 }
71 echo '<div class="submit"><input class="button-primary" type="submit" name="preload" value="' . __( 'Save Settings', 'wp-super-cache' ) . '" />';
72 echo '</div>';
73 wp_nonce_field( 'wp-cache' );
74 echo '</form>';
75 echo '<form name="do_preload" action="' . esc_url_raw( add_query_arg( 'tab', 'preload', $admin_url ) ) . '" method="POST">';
76 echo '<input type="hidden" name="action" value="preload" />';
77 echo '<input type="hidden" name="page" value="wpsupercache" />';
78 echo '<div class="submit">';
79 if ( false == $currently_preloading ) {
80 echo '<input class="button-primary" type="submit" name="preload_now" value="' . __( 'Preload Cache Now', 'wp-super-cache' ) . '" />';
81 } else {
82 echo '<input class="button-primary" type="submit" name="preload_off" value="' . __( 'Cancel Cache Preload', 'wp-super-cache' ) . '" />';
83 }
84 echo '</div>';
85 wp_nonce_field( 'wp-cache' );
86 echo '</form>';
1 <?php
2 echo '<a name="useragents"></a><fieldset class="options"><h4>' . __( 'Rejected User Agents', 'wp-super-cache' ) . '</h4>';
3 echo "<p>" . __( 'Strings in the HTTP &#8217;User Agent&#8217; header that prevent WP-Cache from caching bot, spiders, and crawlers&#8217; requests. Note that super cached files are still sent to these agents if they already exists.', 'wp-super-cache' ) . "</p>\n";
4 echo '<form name="wp_edit_rejected_user_agent" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#useragents' ) . '" method="post">';
5 echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 50%; font-size: 12px;" class="code">';
6 foreach( $cache_rejected_user_agent as $ua ) {
7 echo esc_html( $ua ) . "\n";
8 }
9 echo '</textarea> ';
10 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save UA Strings', 'wp-super-cache' ) . '" /></div>';
11 wp_nonce_field('wp-cache');
12 echo '</form>';
13 echo "</fieldset>\n";
14
1 <?php
2 echo '<fieldset class="options"><h4>' . __( 'Fix Configuration', 'wp-super-cache' ) . '</h4>';
3 echo '<form name="wp_restore" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#top' ) . '" method="post">';
4 echo '<input type="hidden" name="wp_restore_config" />';
5 echo '<div class="submit"><input class="button-secondary" type="submit" ' . SUBMITDISABLED . 'id="deletepost" value="' . __( 'Restore Default Configuration', 'wp-super-cache' ) . '" /></div>';
6 wp_nonce_field('wp-cache');
7 echo "</form>\n";
8 echo '</fieldset>';
1 <?php
2 echo '<a name="trackingparameters"></a><fieldset class="options"><h4>' . __( 'Tracking Parameters', 'wp-super-cache' ) . '</h4>';
3 echo '<form name="edit_tracking_parameters" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#trackingparameters' ) . '" method="post">';
4 echo "<p>" . __( 'Tracking parameters to ignore when caching. Visitors from Facebook, Twitter and elsewhere to your website will go to a URL with tracking parameters added. This setting allows the plugin to ignore those parameters and show an already cached page. Any actual tracking by Google Analytics or other Javascript based code should still work as the URL of the page is not modified.', 'wp-super-cache' ) . "</p>\n";
5 echo '<textarea name="tracking_parameters" cols="20" rows="10" style="width: 50%; font-size: 12px;" class="code">';
6 foreach ( $wpsc_tracking_parameters as $parameter) {
7 echo esc_html( $parameter ) . "\n";
8 }
9 echo '</textarea> ';
10 echo "<p><label><input type='checkbox' name='wpsc_ignore_tracking_parameters' value='1' " . checked( 1, $wpsc_ignore_tracking_parameters, false ) . " /> " . __( 'Enable', 'wp-super-cache' ) . "</label></p>";
11 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Save', 'wp-super-cache' ) . '" /></div>';
12 wp_nonce_field('wp-cache');
13 echo "</form>\n";
1 <?php
2
3 function awaitingmoderation_action( $buffer ) {
4 $buffer = str_replace( __( 'Your comment is awaiting moderation.', 'wp-super-cache' ), '', $buffer );
5 return $buffer;
6 }
7
8 function awaitingmoderation_actions() {
9 global $cache_awaitingmoderation;
10 if ( '1' === $cache_awaitingmoderation ) {
11 add_filter( 'wpsupercache_buffer', 'awaitingmoderation_action' );
12 }
13 }
14 add_cacheaction( 'add_cacheaction', 'awaitingmoderation_actions' );
15
16 // Your comment is awaiting moderation.
17 function wp_supercache_awaitingmoderation_admin() {
18 global $cache_awaitingmoderation, $wp_cache_config_file, $valid_nonce;
19
20 $cache_awaitingmoderation = '' === $cache_awaitingmoderation ? '0' : $cache_awaitingmoderation;
21
22 if ( isset( $_POST['cache_awaitingmoderation'] ) && $valid_nonce ) {
23 $cache_awaitingmoderation = (int) $_POST['cache_awaitingmoderation'];
24 wp_cache_replace_line( '^ *\$cache_awaitingmoderation', "\$cache_awaitingmoderation = '$cache_awaitingmoderation';", $wp_cache_config_file );
25 $changed = true;
26 } else {
27 $changed = false;
28 }
29 $id = 'awaitingmoderation-section';
30 ?>
31 <fieldset id="<?php echo $id; ?>" class="options">
32 <h4><?php _e( 'Awaiting Moderation', 'wp-super-cache' ); ?></h4>
33 <form name="wp_manager" action="" method="post">
34 <label><input type="radio" name="cache_awaitingmoderation" value="1" <?php if ( $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
35 <label><input type="radio" name="cache_awaitingmoderation" value="0" <?php if ( ! $cache_awaitingmoderation ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
36 <p><?php _e( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ); ?></p>
37 <?php
38 if ( $changed ) {
39 if ( $cache_awaitingmoderation ) {
40 $status = __( 'enabled', 'wp-super-cache' );
41 } else {
42 $status = __( 'disabled', 'wp-super-cache' );
43 }
44 echo '<p><strong>' . sprintf( __( 'Awaiting Moderation is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
45 }
46 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
47 wp_nonce_field( 'wp-cache' );
48 ?>
49 </form>
50 </fieldset>
51 <?php
52 }
53 add_cacheaction( 'cache_admin_page', 'wp_supercache_awaitingmoderation_admin' );
54
55 function wpsc_awaiting_moderation_list( $list ) {
56 $list['awaitingmoderation'] = array(
57 'key' => 'awaitingmoderation',
58 'url' => '',
59 'title' => __( 'Awaiting Moderation', 'wp-super-cache' ),
60 'desc' => __( 'Enables or disables plugin to Remove the text "Your comment is awaiting moderation." when someone leaves a moderated comment.', 'wp-super-cache' ),
61 );
62 return $list;
63 }
64 add_cacheaction( 'wpsc_filter_list', 'wpsc_awaiting_moderation_list' );
1 <?php
2
3 function wp_supercache_badbehaviour( $file ) {
4 global $cache_badbehaviour;
5
6 if ( 1 !== $cache_badbehaviour ) {
7 return $file;
8 }
9 wp_supercache_badbehaviour_include();
10 return $file;
11 }
12 add_cacheaction( 'wp_cache_served_cache_file', 'wp_supercache_badbehaviour' );
13
14 function wp_supercache_badbehaviour_include() {
15 $bbfile = get_bb_file_loc();
16 if ( ! $bbfile ) {
17 require_once $bbfile;
18 }
19 }
20
21 function get_bb_file_loc() {
22 global $cache_badbehaviour_file;
23 if ( $cache_badbehaviour_file ) {
24 return $cache_badbehaviour_file;
25 }
26
27 if ( file_exists( WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php' ) ) {
28 $bbfile = WP_CONTENT_DIR . '/plugins/bad-behavior/bad-behavior-generic.php';
29 } elseif ( file_exists( WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php' ) ) {
30 $bbfile = WP_CONTENT_DIR . '/plugins/Bad-Behavior/bad-behavior-generic.php';
31 } else {
32 $bbfile = false;
33 }
34 return $bbfile;
35 }
36
37 function wp_supercache_badbehaviour_admin() {
38 global $cache_badbehaviour, $wp_cache_config_file, $valid_nonce;
39
40 $cache_badbehaviour = '' === $cache_badbehaviour ? 0 : $cache_badbehaviour;
41 if ( 'no' === $cache_badbehaviour ) {
42 $cache_badbehaviour = 0;
43 }
44
45 $err = false;
46
47 if ( isset( $_POST['cache_badbehaviour'] ) && $valid_nonce ) {
48 $bbfile = get_bb_file_loc();
49 if ( ! $bbfile ) {
50 $_POST['cache_badbehaviour'] = 0;
51 $err = __( 'Bad Behaviour not found. Please check your install.', 'wp-super-cache' );
52 }
53 if ( $cache_badbehaviour === (int) $_POST['cache_badbehaviour'] ) {
54 $changed = false;
55 } else {
56 $changed = true;
57 }
58 $cache_badbehaviour = (int) $_POST['cache_badbehaviour'];
59 wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = 0;", $wp_cache_config_file );
60 wp_cache_replace_line( '^ *\$cache_badbehaviour', "\$cache_badbehaviour = $cache_badbehaviour;", $wp_cache_config_file );
61 wp_cache_replace_line( '^ *\$cache_badbehaviour_file', "\$cache_badbehaviour_file = '$bbfile';", $wp_cache_config_file );
62 $changed = true;
63 }
64 $id = 'badbehavior-section';
65 ?>
66 <fieldset id="<?php echo $id; ?>" class="options">
67 <h4><?php _e( 'Bad Behavior', 'wp-super-cache' ); ?></h4>
68 <form name="wp_manager" action="" method="post">
69 <label><input type="radio" name="cache_badbehaviour" value="1" <?php if ( $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
70 <label><input type="radio" name="cache_badbehaviour" value="0" <?php if ( ! $cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
71 <p><?php _e( '', 'wp-super-cache' ); ?></p><?php
72 echo '<p>' . sprintf( __( '(Only WPCache caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
73 if ( isset( $changed ) && $changed ) {
74 if ( $cache_badbehaviour ) {
75 $status = __( 'enabled', 'wp-super-cache' );
76 } else {
77 $status = __( 'disable', 'wp-super-cache' );
78 }
79 echo '<p><strong>' . sprintf( __( 'Bad Behavior support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
80 }
81 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
82 wp_nonce_field( 'wp-cache' );
83 ?>
84 </form>
85 </fieldset>
86 <?php
87 if ( $err ) {
88 echo '<p><strong>' . __( 'Warning!', 'wp-super-cache' ) . "</strong> $err</p>";
89 }
90 }
91 add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
92
93 function wpsc_badbehaviour_list( $list ) {
94 $list['badbehaviour'] = array(
95 'key' => 'badbehaviour',
96 'url' => 'http://www.bad-behavior.ioerror.us/',
97 'title' => __( 'Bad Behavior', 'wp-super-cache' ),
98 'desc' => sprintf( __( 'Support for Bad Behavior. (Only WPCache caching supported, disabled compression and requires Bad Behavior in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ),
99 );
100 return $list;
101 }
102 add_cacheaction( 'wpsc_filter_list', 'wpsc_badbehaviour_list' );
1 <?php
2
3 function domain_mapping_gc_cache( $function, $directory ) {
4 global $cache_path;
5
6 if ( ! function_exists( 'domain_mapping_warning' ) ) {
7 return;
8 }
9
10 $siteurl = domain_mapping_siteurl( false );
11 if ( ! $siteurl ) {
12 return;
13 }
14
15 $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
16
17 if ( 'homepage' === $directory ) {
18 $directory = '';
19 }
20
21 switch ( $function ) {
22 case 'rebuild':
23 wpsc_rebuild_files( $cache_path . 'supercache/' . $sitedir . $directory );
24 break;
25 case 'prune':
26 wpsc_delete_files( $cache_path . 'supercache/' . $sitedir . $directory );
27 break;
28 }
29 }
30
31 function domain_mapping_supercachedir( $dir ) {
32 global $cache_path;
33
34 if ( ! function_exists( 'domain_mapping_warning' ) ) {
35 return $dir;
36 }
37
38 $siteurl = domain_mapping_siteurl( false );
39 if ( ! $siteurl ) {
40 return $dir;
41 }
42
43 $sitedir = trailingslashit( preg_replace( '`^(https?:)?//`', '', $siteurl ) );
44
45 return trailingslashit( $cache_path . 'supercache/' . $sitedir );
46 }
47
48 function domain_mapping_actions() {
49 global $cache_domain_mapping;
50
51 $cache_domain_mapping = (int) $cache_domain_mapping;
52 if ( 1 !== $cache_domain_mapping ) {
53 return;
54 }
55
56 add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
57 add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
58 }
59 add_cacheaction( 'add_cacheaction', 'domain_mapping_actions' );
60
61 function wp_supercache_domain_mapping_admin() {
62 global $cache_domain_mapping, $wp_cache_config_file, $valid_nonce;
63
64 $requested_state = isset( $_POST['cache_domain_mapping'] ) ? (int) $_POST['cache_domain_mapping'] : null;
65 $cache_domain_mapping = (int) $cache_domain_mapping;
66
67 $changed = false;
68 if ( null !== $requested_state && $valid_nonce ) {
69 $cache_domain_mapping = $requested_state;
70
71 wp_cache_replace_line( '^\s*\$cache_domain_mapping\s*=', '$cache_domain_mapping = ' . intval( $cache_domain_mapping ) . ';', $wp_cache_config_file );
72 $changed = true;
73 }
74
75 $id = 'domain_mapping-section';
76 ?>
77 <fieldset id="<?php echo esc_attr( $id ); ?>" class="options">
78
79 <h4><?php esc_html_e( 'Domain Mapping', 'wp-super-cache' ); ?></h4>
80
81 <form name="wp_manager" action="" method="post">
82 <label><input type="radio" name="cache_domain_mapping" value="1" <?php checked( $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Enabled', 'wp-super-cache' ); ?></label>
83 <label><input type="radio" name="cache_domain_mapping" value="0" <?php checked( ! $cache_domain_mapping ); ?>/> <?php esc_html_e( 'Disabled', 'wp-super-cache' ); ?></label>
84 <?php
85 echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
86
87 if ( $changed ) {
88 echo '<p><strong>' . sprintf(
89 esc_html__( 'Domain Mapping support is now %s', 'wp-super-cache' ),
90 esc_html( $cache_domain_mapping ? __( 'enabled', 'wp-super-cache' ) : __( 'disabled', 'wp-super-cache' ) )
91 ) . '</strong></p>';
92 }
93
94 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . ' type="submit" value="' . esc_html__( 'Update', 'wp-super-cache' ) . '" /></div>';
95 wp_nonce_field( 'wp-cache' );
96 ?>
97 </form>
98
99 </fieldset>
100 <?php
101 }
102 add_cacheaction( 'cache_admin_page', 'wp_supercache_domain_mapping_admin' );
103
104 function wp_supercache_domain_mapping_notice() {
105 global $cache_enabled;
106
107 if ( $cache_enabled ) {
108 echo '<div class="error"><p><strong>' . esc_html__( 'Domain Mapping plugin detected! Please go to the Supercache plugins page and enable the domain mapping helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
109 }
110 }
111 function wp_supercache_domain_mapping_exists() {
112 global $cache_domain_mapping;
113
114 $cache_domain_mapping = (int) $cache_domain_mapping;
115 if ( 1 === $cache_domain_mapping ) {
116 return;
117 }
118
119 if ( is_admin() && function_exists( 'domain_mapping_warning' ) ) {
120 add_action( 'admin_notices', 'wp_supercache_domain_mapping_notice' );
121 }
122 }
123
124 if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
125 add_cacheaction( 'add_cacheaction', 'wp_supercache_domain_mapping_exists' );
126 }
127
128 function wpsc_domain_mapping_list( $list ) {
129 $list['domain_mapping'] = array(
130 'key' => 'domain_mapping',
131 'url' => 'https://wordpress.org/plugins/wordpress-mu-domain-mapping/',
132 'title' => esc_html__( 'Domain Mapping', 'wp-super-cache' ),
133 'desc' => esc_html__( 'Provides support for Domain Mapping plugin to map multiple domains to a blog.', 'wp-super-cache' ),
134 );
135 return $list;
136 }
137 add_cacheaction( 'wpsc_filter_list', 'wpsc_domain_mapping_list' );
1 <?php
2
3 /*
4 * On the Advanced Settings page enable "Enable dynamic caching" and clear
5 * the cache.
6 *
7 * Plugin authors: NEVER define the template tag for your users. Make them
8 * choose one so it will be unique to their site.
9 *
10 * There are two examples in this file. Both use template tags that must be
11 * kept secret.
12 *
13 * GLOSSARY:
14 *
15 * Dynamic content: the text or widget you want to show visitors to your site
16 * that changes every time it's viewed.
17 * Placeholder/template tag: the string of random characters placed in your
18 * theme file or printed in an action where the dynamic content will go.
19 * Output buffer (ob): any text that is printed by PHP to be sent to the browser
20 * but captured by PHP for further manipulation.
21 * OB Callback function: A function that is called when the output buffer is
22 * filled with a html page. The contents of the page are passed to the function
23 * for processing.
24 *
25 * **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
26 * You should probably add 'deny from all' to the .htaccess in the cache directory
27 * so visitors can't directly load any cached html files and discover the secret
28 * tag. Or you can move the cache directory out of the web path and set the
29 * cache location to that new directory on the advanced settings page.
30 *
31 */
32
33 /*
34 * EXAMPLE 1
35 * http://ocaoimh.ie/2013/10/21/shiny-new-dynamic-content-wp-super-cache/
36 * Replace a string in your theme with the dynamic content.
37 *
38 * dynamic_cache_test_init()
39 * This function is the first one to be called. This function hooks
40 * dynamic_cache_test_template() to the WordPress action, wp_footer.
41 * This script is loaded before WordPress is and the add_action()
42 * function isn't defined at this time.
43 * This init function hooks onto the cache action "add_cacheaction"
44 * that fires after WordPress (and add_action) is loaded.
45 *
46 *
47 * dynamic_cache_test_template_tag()
48 * This function hooks on to wp_footer and displays the secret template
49 * tag that will be replaced by our dynamic content on each page view.
50 *
51 *
52 * dynamic_cache_test_filter()
53 * This function hooks on to the filter through which all the cached data
54 * sent to visitors is sent.
55 * In this simple example the template tag is replaced by a html comment
56 * containing the text "Hello world at " and the current server time.
57 * If you want to use the output of a WordPress plugin or command you
58 * must enable "late init" on the settings page. Each time you reload
59 * the cached page this time will change. View the page source to examine
60 * this text.
61 *
62 * Chronology of a request:
63 * 1. dynamic_cache_test_init() hooks dynamic_cache_test_template_tag() on
64 * to the wp_footer action. dynamic_cache_test_filter() is hooked on to
65 * the wpsc_cachedata filter.
66 * 2. An output buffer is created by WP Super Cache.
67 * 3. Most of the page is generated by WordPress.
68 * 4. The wp_footer action fires and the TAG is printed to the page.
69 * 5. Processing continues and the page is created.
70 * 6. The output buffer finishes. A WP Super Cache callback function runs
71 * and saves the output buffer to a cache file. The wpsc_cachedata
72 * filter is called.
73 * 7. The function dynamic_cache_test_filter() runs and replaces the TAG in
74 * the buffer with the "Hello world" string.
75 * 8. The output buffer is pushed to the browser to be displayed.
76 */
77 define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag.
78 if ( '' !== DYNAMIC_CACHE_TEST_TAG ) {
79 function dynamic_cache_test_safety( $safety ) {
80 return 1;
81 }
82 add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
83
84 function dynamic_cache_test_filter( $cachedata ) {
85 return str_replace( DYNAMIC_CACHE_TEST_TAG, '<!-- Hello world at ' . date( 'H:i:s' ) . ' -->', $cachedata );
86 }
87 add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
88
89 function dynamic_cache_test_template_tag() {
90 echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag.
91 }
92
93 function dynamic_cache_test_init() {
94 add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
95 }
96 add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
97 }
98
99 /*
100 * EXAMPLE 2
101 *
102 * This is going to be complicated. Hang on!
103 *
104 * When the cache file for a new page is generated the plugin uses an output
105 * buffer to capture the page. A callback function processes the buffer and
106 * writes to the cache file. The placeholder tag for any dynamic content has
107 * to be written to that cache file but also, it has to be replaced with
108 * dynamic content before the page is shown to the user.
109 * More on output buffers here: http://php.net/ob_start
110 *
111 * Unfortunately an extra output buffer is often required when capturing dynamic
112 * content such as sidebar widgets. Due to a quirk of the way PHP works it's
113 * not possible to have an output buffer run in an output buffer callback. That
114 * dynamic content has to be generated before the callback function is reached.
115 * The following error occurs when an output buffer is created in the
116 * callback function of another output buffer:
117 * "PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in..."
118 *
119 * In this example the function add_action() isn't available when this file is
120 * loaded so dynamic_output_buffer_init() is hooked on to the "add_cacheaction"
121 * cacheaction. That function then hooks dynamic_output_buffer_test() on to the
122 * familiar wp_footer action.
123 *
124 * The first time dynamic_output_buffer_test() runs it generates the dynamic
125 * content and captures it with ob_start() in the DYNAMIC_OB_TEXT constant.
126 *
127 * When the main WP Super Cache output buffer is ready the callback is called.
128 * This fires the wpsc_cachedata_safety filter. If the DYNAMIC_OB_TEXT constant
129 * is set, which means dynamic content is ready, then it returns 1, a signal
130 * that everything is ok.
131 * Finally, the wpsc_cachedata filter is run. The function
132 * dynamic_output_buffer_test() is hooked on to it. Since DYNAMIC_OB_TEXT is
133 * set it replaces the placeholder text with that constant.
134 * The resulting html is then sent to the browser.
135 *
136 * Already cached pages call the safety filter, and then the wpsc_cachedata
137 * filter so any hooked function must be ready to generate dynamic content. The
138 * very last line of dynamic_output_buffer_test() replaces the placeholder tag
139 * with the dynamic content in the cache file.
140 *
141 * Use an output buffer to capture dynamic content while the page is generated
142 * and insert into the right place:
143 * Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
144 * your theme where the dynamic content should be.
145 *
146 * dynamic_output_buffer_test() is a function that uses the wpsc_cachedata
147 * filter to add a small message and the current server time to every web
148 * page. The time increments on every reload.
149 *
150 */
151
152 define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag.
153
154 if ( '' !== DYNAMIC_OUTPUT_BUFFER_TAG ) {
155 function dynamic_output_buffer_test( $cachedata = 0 ) {
156 if ( defined( 'DYNAMIC_OB_TEXT' ) ) {
157 return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
158 }
159
160 ob_start();
161 // call the sidebar function, do something dynamic
162 echo '<p>This is a test. The current time on the server is: ' . date( 'H:i:s' ) . '</p>';
163 $text = ob_get_contents();
164 ob_end_clean();
165
166 if ( 0 === $cachedata ) { // called directly from the theme so store the output.
167 define( 'DYNAMIC_OB_TEXT', $text );
168 } else { // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php.
169 return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
170 }
171 }
172 add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
173
174 function dynamic_output_buffer_init() {
175 add_action( 'wp_footer', 'dynamic_output_buffer_test' );
176 }
177 add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
178
179 function dynamic_output_buffer_test_safety( $safety ) {
180 if ( defined( 'DYNAMIC_OB_TEXT' ) ) {// this is set when you call dynamic_output_buffer_test() from the theme.
181 return 1; // ready to replace tag with dynamic content.
182 } else {
183 return 0; // tag cannot be replaced.
184 }
185 }
186 add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
187 }
1 <?php
2
3 if ( ! class_exists( 'Automattic\Jetpack\Device_Detection' ) ) {
4 // Manually load Device_Detection before autoload is initialized.
5 if ( defined( 'WPCACHEHOME' ) ) {
6 if ( file_exists( WPCACHEHOME . '/vendor/automattic/jetpack-device-detection/src/class-device-detection.php' ) ) {
7 require_once WPCACHEHOME . '/vendor/automattic/jetpack-device-detection/src/class-device-detection.php';
8 }
9 }
10 }
11
12 function wp_super_cache_jetpack_admin() {
13 global $cache_jetpack, $wp_cache_config_file, $valid_nonce;
14
15 $cache_jetpack = '' === $cache_jetpack ? '0' : $cache_jetpack;
16
17 if ( isset( $_POST['cache_jetpack'] ) && $valid_nonce ) {
18 if ( $cache_jetpack === (int) $_POST['cache_jetpack'] ) {
19 $changed = false;
20 } else {
21 $changed = true;
22 }
23 $cache_jetpack = (int) $_POST['cache_jetpack'];
24 wp_cache_replace_line( '^ *\$cache_jetpack', "\$cache_jetpack = '$cache_jetpack';", $wp_cache_config_file );
25 if ( $changed && $cache_jetpack ) {
26 wp_cache_replace_line( '^ *\$wp_cache_mobile_enabled', '$wp_cache_mobile_enabled = 1;', $wp_cache_config_file );
27 wp_cache_replace_line( '^ *\$wp_cache_mod_rewrite', '$wp_cache_mod_rewrite = 0;', $wp_cache_config_file );
28 wp_cache_replace_line( '^ *\$super_cache_enabled', '$super_cache_enabled = 1;', $wp_cache_config_file );
29 }
30 }
31 $id = 'jetpack-section';
32 ?>
33 <fieldset id="<?php echo $id; ?>" class="options">
34 <h4><?php _e( 'Jetpack Mobile Theme', 'wp-super-cache' ); ?></h4>
35 <?php
36 if ( false === file_exists( dirname( WPCACHEHOME ) . '/jetpack/class.jetpack-user-agent.php' ) ) {
37 echo '<strong>' . sprintf( __( 'Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors.', 'wp-super-cache' ), dirname( WPCACHEHOME ) ) . '</strong>';
38 } else {
39 ?>
40 <form name="wp_manager" action="" method="post">
41 <label><input type="radio" name="cache_jetpack" value="1" <?php if ( $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
42 <label><input type="radio" name="cache_jetpack" value="0" <?php if ( ! $cache_jetpack ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
43 <?php
44 echo '<p>' . __( 'Provides support for the <a href="https://wordpress.org/plugins/jetpack/">Jetpack</a> mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ) . '</p>';
45 if ( isset( $changed ) && $changed ) {
46 if ( $cache_jetpack ) {
47 $status = __( 'enabled', 'wp-super-cache' );
48 } else {
49 $status = __( 'disabled', 'wp-super-cache' );
50 }
51 echo '<p><strong>' . sprintf( __( 'Jetpack Mobile Theme support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
52 }
53 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
54 wp_nonce_field( 'wp-cache' );
55 ?>
56 </form>
57 <?php } ?>
58 </fieldset>
59 <?php
60 }
61 add_cacheaction( 'cache_admin_page', 'wp_super_cache_jetpack_admin' );
62
63 function wp_super_cache_jetpack_cookie_check( $cache_key ) {
64 if ( isset ( $_COOKIE['akm_mobile'] ) ) {
65 if ( $_COOKIE['akm_mobile'] == 'true' ) {
66 return 'mobile';
67 } elseif ( $_COOKIE['akm_mobile'] == 'false' ) {
68 return 'normal';
69 }
70 }
71
72 if ( ! class_exists( 'Automattic\Jetpack\Device_Detection' ) ) {
73 return 'normal';
74 }
75
76 if ( \Automattic\Jetpack\Device_Detection::is_phone() ) {
77 return 'mobile';
78 } else {
79 return 'normal';
80 }
81 }
82
83 if ( isset( $cache_jetpack ) && '1' === $cache_jetpack ) {
84 add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_jetpack_cookie_check' );
85 }
86
87 function wpsc_cache_jetpack_list( $list ) {
88 $list['jetpack'] = array(
89 'key' => 'jetpack',
90 'url' => 'https://wordpress.org/plugins/jetpack/',
91 'title' => __( 'Jetpack Mobile Theme', 'wp-super-cache' ),
92 'desc' => __( 'Provides support for the Jetpack mobile theme and plugin. PHP caching mode and mobile support will be enabled too.', 'wp-super-cache' ),
93 );
94 return $list;
95 }
96 add_cacheaction( 'wpsc_filter_list', 'wpsc_cache_jetpack_list' );
1 <?php
2
3 if ( is_multisite() ) {
4 add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
5 }
6
7 function wp_super_cache_multisite_init() {
8 add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
9 add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 );
10 add_action( 'init', 'wp_super_cache_override_on_flag', 9 );
11 }
12
13 function wp_super_cache_blogs_col( $col ) {
14 $col['wp_super_cache'] = __( 'Cached', 'wp-super-cache' );
15 return $col;
16 }
17
18 function wp_super_cache_blogs_field( $name, $blog_id ) {
19 if ( 'wp_super_cache' !== $name ) {
20 return false;
21 }
22
23 $blog_id = (int) $blog_id;
24
25 if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] )
26 && $blog_id === filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT )
27 && wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id )
28 ) {
29 if ( 'disable_cache' === filter_input( INPUT_GET, 'action' ) ) {
30 add_blog_option( $blog_id, 'wp_super_cache_disabled', 1 );
31 } elseif ( 'enable_cache' === filter_input( INPUT_GET, 'action' ) ) {
32 delete_blog_option( $blog_id, 'wp_super_cache_disabled' );
33 }
34 }
35
36 if ( 1 === (int) get_blog_option( $blog_id, 'wp_super_cache_disabled' ) ) {
37 echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Enable', 'wp-super-cache' ) . '</a>';
38 } else {
39 echo '<a href="' . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . '">' . __( 'Disable', 'wp-super-cache' ) . '</a>';
40 }
41 }
42
43 function wp_super_cache_multisite_notice() {
44 if ( 'wpsupercache' === filter_input( INPUT_GET, 'page' ) ) {
45 echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
46 }
47 }
48
49 function wp_super_cache_override_on_flag() {
50 global $cache_enabled, $super_cache_enabled;
51 if ( true !== $cache_enabled ) {
52 return false;
53 }
54
55 if ( 1 === (int) get_option( 'wp_super_cache_disabled' ) ) {
56 $cache_enabled = false;
57 $super_cache_enabled = false;
58 define( 'DONOTCACHEPAGE', 1 );
59 define( 'SUBMITDISABLED', 'disabled style="color: #aaa" ' );
60 if ( is_admin() ) {
61 add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
62 }
63 }
64 }
1 <?php
2
3 function wp_super_cache_wptouch_admin() {
4 global $cache_wptouch, $wp_cache_config_file, $valid_nonce;
5
6 $cache_wptouch = '' === $cache_wptouch ? '0' : $cache_wptouch;
7
8 if ( isset( $_POST['cache_wptouch'] ) && $valid_nonce ) {
9 if ( $cache_wptouch === (int) $_POST['cache_wptouch'] ) {
10 $changed = false;
11 } else {
12 $changed = true;
13 }
14 $cache_wptouch = (int) $_POST['cache_wptouch'];
15 wp_cache_replace_line( '^ *\$cache_wptouch', "\$cache_wptouch = '$cache_wptouch';", $wp_cache_config_file );
16 }
17 $id = 'wptouch-section';
18 ?>
19 <fieldset id="<?php echo $id; ?>" class="options">
20 <h4><?php _e( 'WPTouch', 'wp-super-cache' ); ?></h4>
21 <form name="wp_manager" action="" method="post">
22 <label><input type="radio" name="cache_wptouch" value="1" <?php if ( $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
23 <label><input type="radio" name="cache_wptouch" value="0" <?php if ( ! $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
24 <?php
25 echo '<p>' . __( 'Provides support for <a href="https://wordpress.org/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
26 if ( isset( $changed ) && $changed ) {
27 if ( $cache_wptouch ) {
28 $status = __( 'enabled', 'wp-super-cache' );
29 } else {
30 $status = __( 'disabled', 'wp-super-cache' );
31 }
32 echo '<p><strong>' . sprintf( __( 'WPTouch support is now %s', 'wp-super-cache' ), $status ) . '</strong></p>';
33 }
34 echo '<div class="submit"><input class="button-primary" ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
35 wp_nonce_field( 'wp-cache' );
36 ?>
37 </form>
38 </fieldset>
39 <?php
40 }
41 add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' );
42
43 function wp_super_cache_wptouch_notice() {
44 global $cache_enabled;
45 if ( $cache_enabled ) {
46 echo '<div class="error"><p><strong>' . __( 'WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
47 }
48 }
49 function wp_super_cache_wptouch_exists() {
50 global $cache_wptouch;
51 if ( '1' === $cache_wptouch ) {
52 return false;
53 }
54
55 if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) ) {
56 add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
57 }
58 }
59
60 if ( isset( $_GET['page'] ) && 'wpsupercache' === $_GET['page'] ) {
61 add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
62 }
63
64 // disable mobile checking if.
65 function wp_super_cache_maybe_disable_wptouch( $t ) {
66 global $cache_wptouch, $wptouch_exclude_ua;
67 if ( '1' !== $cache_wptouch ) {
68 return false;
69 }
70
71 if ( ( isset( $_COOKIE['wptouch_switch_toggle'] ) && 'normal' === $_COOKIE['wptouch_switch_toggle'] ) ||
72 ( isset( $_COOKIE['wptouch-pro-view'] ) && 'desktop' === $_COOKIE['wptouch-pro-view'] ) ) {
73 return true;
74 }
75
76 $ua = explode( ',', $wptouch_exclude_ua );
77 foreach ( $ua as $agent ) {
78 if ( preg_match( "#$agent#i", $_SERVER['HTTP_HOST'] ) ) {
79 return true; // disable mobile ua check if matches the exclude list in wptouch.
80 }
81 }
82
83 return false;
84 }
85
86 add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
87
88 function wp_super_cache_wptouch_browsers( $browsers ) {
89 global $wptouch_exclude_ua, $wp_cache_config_file;
90
91 if ( false === function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false === function_exists( 'bnc_wptouch_get_user_agents' ) ) {
92 return $browsers;
93 }
94
95 $browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too.
96 if ( $browsers !== $wptouch_exclude_ua ) {
97 wp_cache_replace_line( '^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file );
98 $wptouch_exclude_ua = $browsers;
99 }
100
101 return bnc_wptouch_get_user_agents();
102 }
103
104 function wp_super_cache_wptouch_prefixes( $prefixes ) {
105 return array(); // wptouch doesn't support UA prefixes.
106 }
107
108 function wp_super_cache_wptouch_cookie_check( $cache_key ) {
109 if ( false === isset( $_COOKIE['wptouch_switch_toggle'] ) ) {
110 return $cache_key;
111 }
112 if ( 'normal' === $_COOKIE['wptouch_switch_toggle'] || 'mobile' === $_COOKIE['wptouch_switch_toggle'] ) {
113 return $_COOKIE['wptouch_switch_toggle'];
114 }
115
116 if ( isset( $_COOKIE['wptouch-pro-view'] ) ) {
117 if ( 'desktop' === $_COOKIE['wptouch-pro-view'] ) {
118 return 'normal';
119 } else {
120 return $_COOKIE['wptouch-pro-view'];
121 }
122 }
123
124 return $cache_key;
125 }
126
127 if ( isset( $cache_wptouch ) && '1' === $cache_wptouch ) {
128 add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
129 add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
130 add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
131 }
132
133 function wpsc_wptouch_list( $list ) {
134 $list['wptouch'] = array(
135 'key' => 'wptouch',
136 'url' => 'https://wordpress.org/plugins/wptouch/',
137 'title' => __( 'WPTouch', 'wp-super-cache' ),
138 'desc' => __( 'Provides support for WPTouch mobile theme and plugin.', 'wp-super-cache' ),
139 );
140 return $list;
141 }
142 add_cacheaction( 'wpsc_filter_list', 'wpsc_wptouch_list' );
1 <?php
2
3 class WP_Super_Cache_Rest_Delete_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $params = $request->get_json_params();
13
14 if ( isset( $params['id'] ) && is_numeric( $params['id'] ) ) {
15 wpsc_delete_post_cache( $params['id'] );
16
17 } elseif ( !empty( $params['expired'] ) ) {
18 global $file_prefix;
19 wp_cache_clean_expired( $file_prefix );
20
21 } elseif ( isset( $params['url'] ) ) {
22 global $cache_path;
23
24 $directory = $cache_path . 'supercache/' . $params[ 'url' ];
25 wpsc_delete_files( $directory );
26 prune_super_cache( $directory . '/page', true );
27
28 } else {
29 global $file_prefix;
30 wp_cache_clean_cache( $file_prefix, !empty( $params['all'] ) );
31 }
32
33 return rest_ensure_response( array( 'Cache Cleared' => true ) );
34 }
35 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $valid_nonce;
13
14 $valid_nonce = true;
15 $_GET[ 'listfiles' ] = 1;
16 $sizes = wpsc_generate_sizes_array();
17 $supercachedir = get_supercache_dir();
18 $list = wpsc_dirsize( $supercachedir, $sizes );
19 $return_list = array();
20
21 foreach( $list as $type => $file_list ) {
22 foreach ( $file_list as $state => $value ) {
23 if ( is_array( $value ) ) {
24 foreach( $value as $filenames ) {
25 foreach( $filenames as $filename => $t ) {
26 if ( $type == 'wpcache' ) {
27 $filename = dirname( $filename );
28 }
29 if ( false == isset( $return_list[ $type ][ $state ] ) || false == in_array( $filename, $return_list[ $type ][ $state ] ) )
30 $return_list[ $type ][ $state ][] = $filename;
31 }
32 }
33 }
34 }
35
36 if ( isset ( $return_list[ $type ] ) ) {
37 $list[ $type ] = $return_list[ $type ];
38 }
39
40 unset( $return_list[ $type ] );
41 }
42
43 return rest_ensure_response( $list );
44 }
45 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Plugins extends WP_REST_Controller {
4
5 /**
6 * GET a list of plugins through the /plugins/ endpoint
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12
13 $list = wpsc_get_plugin_list();
14 return rest_ensure_response( $list );
15 }
16 }
1 <?php
2
3 require_once __DIR__ . '/class.wp-super-cache-settings-map.php';
4
5 class WP_Super_Cache_Rest_Get_Settings extends WP_REST_Controller {
6
7 /**
8 * Get the settings.
9 *
10 * @param WP_REST_Request $request Full data about the request.
11 * @return WP_Error|WP_REST_Response
12 */
13 public function callback( $request ) {
14 $settings = array();
15
16 global $wp_cache_config_file;
17
18 if ( defined( 'WPLOCKDOWN' ) ) {
19 $config_file = file_get_contents( $wp_cache_config_file );
20 if ( false === strpos( $config_file, "defined( 'WPLOCKDOWN' )" ) ) {
21 wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', " . $this->get_is_lock_down_enabled() . " );", $wp_cache_config_file );
22 }
23 }
24
25 if ( function_exists( "opcache_invalidate" ) ) {
26 @opcache_invalidate( $wp_cache_config_file );
27 }
28 include( $wp_cache_config_file );
29
30 foreach ( WP_Super_Cache_Settings_Map::$map as $name => $map ) {
31 if ( isset ( $map['get'] ) ) {
32 $get_method = $map['get'];
33
34 if ( method_exists( $this, $get_method ) ) {
35 $settings[ $name ] = $this->$get_method();
36
37 } elseif ( function_exists( $get_method ) ) {
38 $settings[ $name ] = $get_method();
39 }
40
41 } else if ( isset ( $map['option'] ) ) {
42 $settings[ $name ] = get_option( $map['option'] );
43
44 } elseif ( isset( $map['global'] ) ) {
45 if ( false == isset( $GLOBALS[ $map[ 'global' ] ] ) ) {
46 $settings[ $name ] = false;
47 } else {
48 $settings[ $name ] = $GLOBALS[ $map[ 'global' ] ];
49 }
50 }
51 }
52
53 return $this->prepare_item_for_response( $settings, $request );
54 }
55
56 /**
57 * @return string
58 */
59 public function get_ossdl_off_blog_url() {
60 $url = get_option( 'ossdl_off_blog_url' );
61 if ( ! $url )
62 $url = apply_filters( 'ossdl_off_blog_url', untrailingslashit( get_option( 'siteurl' ) ) );
63 return $url;
64 }
65
66 /**
67 * @return string
68 */
69 public function get_cache_path_url() {
70 global $cache_path;
71
72 return site_url( str_replace( ABSPATH, '', "{$cache_path}" ) );
73 }
74
75 /**
76 * @return string
77 */
78 public function get_cache_type() {
79 global $wp_cache_config_file;
80 if ( function_exists( "opcache_invalidate" ) ) {
81 @opcache_invalidate( $wp_cache_config_file );
82 }
83 include( $wp_cache_config_file );
84
85 if ( $wp_cache_mod_rewrite == 1 ) {
86 return 'mod_rewrite';
87 } else {
88 return 'PHP';
89 }
90 }
91
92 /**
93 * Prepare the item for the REST response
94 *
95 * @param mixed $item WordPress representation of the item.
96 * @param WP_REST_Request $request Request object.
97 * @return mixed
98 */
99 public function prepare_item_for_response( $item, $request ) {
100 $settings = array();
101
102 $integers = array( 'cache_max_time', 'preload_interval' );
103 $string_arrays = array( 'cache_stats', 'cache_acceptable_files', 'cache_rejected_uri', 'cache_rejected_user_agent',
104 'cache_direct_pages' );
105 foreach( $item as $key => $value ) {
106 if ( is_array( $value ) && false == in_array( $key, $string_arrays ) ) {
107 array_walk( $value, array( $this, 'make_array_bool' ) );
108
109 } elseif ( ( $value === 0 || $value === 1 ) && false == in_array( $key, $integers ) ) {
110 $value = (bool)$value;
111 }
112
113 $settings[ $key ] = $value;
114 }
115
116 $strings_to_bool = array( 'ossdl_https', 'refresh_current_only_on_comments' );
117 foreach( $strings_to_bool as $key ) {
118 if ( isset( $settings[ $key ] ) ) {
119 $settings[ $key ] = (bool)$settings[ $key ];
120 }
121 }
122
123 return rest_ensure_response( $settings );
124 }
125
126 /**
127 * @param mixed $value
128 * @param string $key
129 */
130 public function make_array_bool( &$value, $key ) {
131 if ( $value == 0 || $value == 1 ) {
132 $value = (bool) $value;
133 }
134 }
135
136 /**
137 * @return bool
138 */
139 protected function get_is_submit_enabled() {
140 global $wp_cache_config_file;
141 return is_writeable_ACLSafe( $wp_cache_config_file );
142 }
143
144 /**
145 * @return bool
146 */
147 protected function get_is_preload_enabled() {
148 return false === defined( 'DISABLESUPERCACHEPRELOADING' );
149 }
150
151 /**
152 * @return false|int
153 */
154 protected function get_next_gc() {
155 return wp_next_scheduled( 'wp_cache_gc' );
156 }
157
158 /**
159 * @return int
160 */
161 protected function get_is_preload_active() {
162 if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
163 return true;
164 } else {
165 return false;
166 }
167 }
168
169 /**
170 * @return int
171 */
172 protected function get_minimum_preload_interval() {
173 global $wpdb;
174 $count = $this->get_post_count();
175 if ( $count > 1000 ) {
176 $min_refresh_interval = 720;
177 } else {
178 $min_refresh_interval = 30;
179 }
180
181 return $min_refresh_interval;
182 }
183
184 /**
185 * @return int
186 */
187 protected function get_is_lock_down_enabled() {
188 if ( defined( 'WPLOCKDOWN' ) ) {
189 return constant( 'WPLOCKDOWN' ) ? 1 : 0;
190 }
191
192 return 0;
193 }
194
195 /**
196 * @return int
197 */
198 protected function get_post_count() {
199 return wpsc_post_count();
200 }
201
202 /**
203 * @return string
204 */
205 protected function get_default_cache_path() {
206 return WP_CONTENT_DIR . '/wp-cache/';
207 }
208 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Stats extends WP_REST_Controller {
4
5 /**
6 * Get the cache stats for the site.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $valid_nonce;
13 $_GET[ 'listfiles' ] = 1;
14 $valid_nonce = true;
15
16 return rest_ensure_response( wp_cache_regenerate_cache_file_stats() );
17 }
18 }
1 <?php
2
3 class WP_Super_Cache_Rest_Get_Status extends WP_REST_Controller {
4
5 /**
6 * Get any status that might be visible.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $status = array();
13
14 include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
15 include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
16 $this->add_rewrite_status( $status );
17 $this->add_cache_disabled_status( $status );
18 $this->add_compression_status( $status );
19 $this->add_php_mod_rewrite_status( $status );
20 $this->add_preload_status( $status );
21
22 if ( empty( $status ) ) {
23 return rest_ensure_response( new stdclass() );
24 } else {
25 return rest_ensure_response( $status );
26 }
27 }
28
29 /**
30 * @param array $status
31 */
32 protected function add_preload_status( & $status ) {
33 global $wp_cache_config_file;
34
35 include( $wp_cache_config_file );
36
37 if ( false == $cache_enabled ) {
38 $status[ 'preload_disabled_cache_off' ] = true;
39 }
40 if ( false == $super_cache_enabled ) {
41 $status[ 'preload_disabled_supercache_off' ] = true;
42 }
43 if ( true === defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
44 $status[ 'preload_disabled_by_admin' ] = true;
45 }
46 }
47
48 /**
49 * @param array $status
50 */
51 protected function add_php_mod_rewrite_status( & $status ) {
52 global $wp_cache_config_file;
53
54 include( $wp_cache_config_file );
55
56 if ( $cache_enabled && !$wp_cache_mod_rewrite ) {
57 $scrules = trim( implode( "\n", extract_from_markers( trailingslashit( get_home_path() ) . '.htaccess', 'WPSuperCache' ) ) );
58 if ( $scrules != '' ) {
59 $status[ 'php_mod_rewrite' ] = true;
60 }
61 }
62 }
63
64 /**
65 * @param array $status
66 */
67 protected function add_cache_disabled_status( & $status ) {
68 global $wp_cache_config_file;
69
70 if ( ! is_writeable_ACLSafe( $wp_cache_config_file ) ) {
71 $status['cache_disabled'] = true;
72 }
73 }
74
75 /**
76 * @param array $status
77 */
78 protected function add_compression_status( & $status ) {
79 if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
80 $status['compression_disabled_by_admin'] = true;
81 } elseif ( false == function_exists( 'gzencode' ) ) {
82 $status['compression_disabled_no_gzencode'] = true;
83 }
84 }
85
86 /**
87 * @param array $status
88 */
89 protected function add_rewrite_status( & $status ) {
90 global $home_path, $wp_cache_config_file;
91
92 include( $wp_cache_config_file );
93
94 // Return if the rewrite caching is disabled.
95 if ( ! $cache_enabled || ! $super_cache_enabled || ! $wp_cache_mod_rewrite ) {
96 return;
97 }
98
99 $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
100 extract( wpsc_get_htaccess_info() );
101
102 if ( $scrules != $rules ) {
103 $status[ 'mod_rewrite_rules' ] = true;
104 }
105 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true );
106 if ( $wp_cache_mod_rewrite && false == apply_filters( 'got_rewrite', $got_rewrite ) ) {
107 $status[ 'mod_rewrite_missing' ] = true;
108 }
109
110 if ( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
111 $status[ 'htaccess_ro' ] = true;
112 }
113 }
114 }
1 <?php
2
3 class WP_Super_Cache_Rest_Preload extends WP_REST_Controller {
4
5 /**
6 * Update the cache settings.
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $parameters = $request->get_json_params();
13
14 if ( defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
15 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: preload disabled by admin' );
16 return rest_ensure_response( array( 'error' => 'preload disabled by admin' ) );
17 }
18
19 if ( isset( $parameters[ 'enable' ] ) ) {
20 if ( $parameters[ 'enable' ] == true ) {
21 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: enable' );
22 wpsc_enable_preload();
23 return( rest_ensure_response( array( 'enabled' => true ) ) );
24 } else {
25 wp_cache_debug( 'WP_Super_Cache_Rest_Preload: cancel' );
26 wpsc_cancel_preload();
27 return( rest_ensure_response( array( 'enabled' => false ) ) );
28 }
29 }
30 }
31 }
1 <?php
2
3 class WP_Super_Cache_Rest_Test_Cache extends WP_REST_Controller {
4
5 /**
6 * Get a collection of items
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 global $cache_path;
13
14 $url = trailingslashit( get_bloginfo( 'url' ) );
15
16 $response = array( 'status' => 'UNKNOWN' );
17 $has_errors = false;
18
19 $attempts = array( 'prime', 'first', 'second' );
20
21 $c = 0;
22 foreach ( $attempts as $attempt_name ) {
23 $attempt = array();
24 $page[ $c ] = wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
25
26 if ( ! is_wp_error( $page[ $c ] ) ) {
27 $fp = fopen( $cache_path . $c . ".html", "w" );
28 fwrite( $fp, $page[ $c ][ 'body' ] );
29 fclose( $fp );
30 }
31
32 if ( is_wp_error( $page[ $c ] ) ) {
33 $has_errors = true;
34 $attempt['status'] = false;
35 $attempt['errors'] = $this->format_error( $page[ $c ] );
36
37 } elseif ( $page[ $c ]['response']['code'] != 200 ) {
38 $has_errors = true;
39 $attempt['status'] = false;
40 $attempt['errors'] = array( $page[ $c ]['response']['message'] );
41
42 // Don't run this step on prime cache.
43 } elseif ( 0 !== $c && 0 === preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ $c ]['body'], $matches2 ) ) {
44 $has_errors = true;
45 $attempt['status'] = false;
46 $attempt['errors'] = array( __( 'Timestamps not found', 'wp-super-cache' ) );
47
48 } else {
49 $attempt['status'] = true;
50 }
51
52
53 $response[ 'attempts' ][ $attempt_name ] = $attempt;
54 ++$c;
55 }
56
57 if (
58 false == $has_errors &&
59 preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 1 ][ 'body' ], $matches1 ) &&
60 preg_match( '/(Cached page generated by WP-Super-Cache on) ([0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*)/', $page[ 2 ][ 'body' ], $matches2 ) &&
61 $matches1[2] == $matches2[2]
62 ) {
63 $response[ 'status' ] = true;
64 } else {
65 $response[ 'status' ] = false;
66 $response[ 'error' ] = array( __( 'Timestamps do not match', 'wp-super-cache' ) );
67 }
68
69 $error = '';
70 if ( $response[ 'status' ] == false ) {
71 if ( isset( $response[ 'error' ] ) ) {
72 $error = $response[ 'error' ];
73 } else {
74 foreach( $response[ 'attempts' ] as $attempt ) {
75 $error .= $attempt[ 'errors' ] . "\n";
76 }
77 }
78 return new WP_Error( 'test_error', $error, array( 'status' => 500 ) );
79 }
80 return rest_ensure_response( $response );
81 }
82
83 /**
84 * @param WP_Error $error
85 * @return array
86 */
87 protected function format_error( WP_Error $error ) {
88 $messages = array();
89 foreach ( $error->get_error_codes() as $code ) {
90 foreach ( $error->get_error_messages( $code ) as $err ) {
91 $messages[] = $err;
92 }
93 }
94
95 return $messages;
96 }
97 }
1 <?php
2
3 class WP_Super_Cache_Rest_Update_Plugins extends WP_REST_Controller {
4
5 /**
6 * Toggle plugins on/off through the /plugins/ endpoint
7 *
8 * @param WP_REST_Request $request Full data about the request.
9 * @return WP_Error|WP_REST_Response
10 */
11 public function callback( $request ) {
12 $parameters = $request->get_json_params();
13
14 global $valid_nonce;
15 $valid_nonce = true;
16
17 wpsc_update_plugin_list( $parameters );
18 $list = wpsc_get_plugin_list();
19
20 return rest_ensure_response( $list );
21 }
22 }
1 <?php
2
3 class WP_Super_Cache_Settings_Map {
4 /**
5 * A map describing how settings transform from their external names
6 * into internal methods and globals.
7 *
8 * Key definitions:
9 *
10 * - get: A getter method or function that will be called to return the var
11 * - set: A setter method or function that will be called to set the var
12 * - option: An option name that will be used to get or set the var
13 * - global: A name of a global that can GET
14 *
15 * @var array
16 */
17 public static $map = array(
18 'is_submit_enabled' => array(
19 'get' => 'get_is_submit_enabled',
20 'set' => '',
21 ),
22 'is_preload_enabled' => array(
23 'get' => 'get_is_preload_enabled',
24 'set' => '',
25 ),
26 'cache_lock_down' => array(
27 'get' => 'get_is_lock_down_enabled',
28 'set' => 'set_lock_down',
29 ),
30 'cache_next_gc' => array(
31 'get' => 'get_next_gc',
32 'set' => '',
33 ),
34 'cache_gc_email_me' => array(
35 'global' => 'cache_gc_email_me',
36 'set' => 'set_time_setting',
37 ),
38 'cache_path_url' => array(
39 'get' => 'get_cache_path_url',
40 ),
41 'cache_type' => array(
42 'get' => 'get_cache_type',
43 'set' => 'set_super_cache_enabled',
44 ),
45 'is_preloading' => array(
46 'get' => 'wpsc_is_preloading',
47 'set' => '',
48 ),
49 'post_count' => array(
50 'get' => 'get_post_count',
51 'set' => '',
52 ),
53 'is_cache_enabled' => array(
54 'global' => 'cache_enabled',
55 'set' => 'set_cache_enabled',
56 ),
57 'is_super_cache_enabled' => array(
58 'global' => 'super_cache_enabled',
59 'set' => 'set_super_cache_enabled',
60 ),
61 'is_mobile_enabled' => array(
62 'global' => 'wp_cache_mobile_enabled',
63 ),
64 'is_mfunc_enabled' => array(
65 'global' => 'wp_cache_mfunc_enabled',
66 ),
67 'cache_list' => array(
68 'global' => 'wp_supercache_cache_list',
69 ),
70 'clear_cache_on_post_edit' => array(
71 'global' => 'wp_cache_clear_on_post_edit',
72 ),
73 'wpsc_save_headers' => array(
74 'global' => 'wpsc_save_headers',
75 ),
76 'cache_rebuild' => array(
77 'global' => 'cache_rebuild_files',
78 ),
79 'dont_cache_logged_in' => array(
80 'global' => 'wp_cache_not_logged_in',
81 ),
82 'make_known_anon' => array(
83 'global' => 'wp_cache_make_known_anon',
84 ),
85 'cache_path' => array(
86 'global' => 'cache_path',
87 'set' => 'set_wp_cache_location',
88 ),
89 'default_cache_path' => array(
90 'get' => 'get_default_cache_path',
91 ),
92 'use_object_cache' => array(
93 'global' => 'wp_cache_object_cache',
94 ),
95 'refresh_current_only_on_comments' => array(
96 'global' => 'wp_cache_refresh_single_only',
97 ),
98 'cache_compression' => array(
99 'global' => 'cache_compression',
100 'set' => 'set_cache_compression',
101 ),
102 'cache_mod_rewrite' => array(
103 'global' => 'wp_cache_mod_rewrite',
104 ),
105 'use_304_headers' => array(
106 'global' => 'wp_supercache_304',
107 ),
108 'cache_late_init' => array(
109 'global' => 'wp_super_cache_late_init',
110 ),
111 'front_page_checks' => array(
112 'global' => 'wp_cache_front_page_checks',
113 ),
114 'cache_page_secret' => array(
115 'global' => 'cache_page_secret',
116 ),
117 'disable_utf8' => array(
118 'global' => 'wp_cache_disable_utf8',
119 ),
120 'no_cache_for_get' => array(
121 'global' => 'wp_cache_no_cache_for_get',
122 ),
123 'cache_schedule_type' => array(
124 'global' => 'cache_schedule_type',
125 'set' => 'set_time_setting',
126 ),
127 'cache_scheduled_time' => array(
128 'global' => 'cache_scheduled_time',
129 'set' => 'set_time_setting',
130 ),
131 'cache_max_time' => array(
132 'global' => 'cache_max_time',
133 'set' => 'set_time_setting',
134 ),
135 'cache_time_interval' => array(
136 'global' => 'cache_time_interval',
137 'set' => 'set_time_setting',
138 ),
139 'shutdown_garbage_collector' => array(
140 'global' => 'wp_cache_shutdown_gc',
141 ),
142 'pages' => array(
143 'global' => 'wp_cache_pages',
144 ),
145 'minimum_preload_interval' => array(
146 'get' => 'get_minimum_preload_interval',
147 ),
148 'preload_interval' => array(
149 'global' => 'wp_cache_preload_interval',
150 'set' => 'set_preload_setting',
151 ),
152 'preload_posts' => array(
153 'global' => 'wp_cache_preload_posts',
154 'set' => 'set_preload_setting',
155 ),
156 'preload_on' => array(
157 'global' => 'wp_cache_preload_on',
158 'set' => 'set_preload_setting',
159 ),
160 'preload_active' => array(
161 'get' => 'get_is_preload_active',
162 ),
163 'preload_taxonomies' => array(
164 'global' => 'wp_cache_preload_taxonomies',
165 'set' => 'set_preload_setting',
166 ),
167 'preload_email_me' => array(
168 'global' => 'wp_cache_preload_email_me',
169 'set' => 'set_preload_setting',
170 ),
171 'preload_email_volume' => array(
172 'global' => 'wp_cache_preload_email_volume',
173 'set' => 'set_preload_setting',
174 ),
175 'cache_mobile_browsers' => array(
176 'global' => 'wp_cache_mobile_browsers',
177 ),
178 'cache_mobile_prefixes' => array(
179 'global' => 'wp_cache_mobile_prefixes',
180 ),
181 'cache_disable_locking' => array(
182 'global' => 'wp_cache_mutex_disabled',
183 ),
184 'cache_hello_world' => array(
185 'global' => 'wp_cache_hello_world',
186 ),
187 'cache_schedule_interval' => array(
188 'global' => 'cache_schedule_interval',
189 'set' => 'set_time_setting',
190 ),
191 'cache_acceptable_files' => array(
192 'global' => 'cache_acceptable_files',
193 ),
194 'cache_rejected_uri' => array(
195 'global' => 'cache_rejected_uri',
196 ),
197 'cache_rejected_user_agent' => array(
198 'global' => 'cache_rejected_user_agent',
199 ),
200 'cache_direct_pages' => array(
201 'global' => 'cached_direct_pages',
202 'set' => 'set_cache_direct_pages',
203 ),
204 'new_direct_page' => array(
205 'set' => 'new_direct_page',
206 ),
207 'ossdl_cname' => array(
208 'option' => 'ossdl_cname',
209 'set' => 'set_ossdl_cname',
210 ),
211 'ossdl_https' => array(
212 'option' => 'ossdl_https',
213 'set' => 'set_ossdl_https',
214 ),
215 'ossdl_off_cdn_url' => array(
216 'option' => 'ossdl_off_cdn_url',
217 'set' => 'set_ossdl_off_cdn_url',
218 ),
219 'ossdl_off_blog_url' => array(
220 'option' => 'ossdl_off_blog_url',
221 'set' => 'set_ossdl_off_blog_url',
222 ),
223 'ossdl_off_exclude' => array(
224 'option' => 'ossdl_off_exclude',
225 'set' => 'set_ossdl_off_exclude',
226 ),
227 'ossdl_off_include_dirs' => array(
228 'option' => 'ossdl_off_include_dirs',
229 'set' => 'set_ossdl_off_include_dirs',
230 ),
231 'ossdlcdn' => array(
232 'global' => 'ossdlcdn',
233 'set' => 'set_ossdlcdn',
234 ),
235 'wp_super_cache_debug' => array(
236 'global' => 'wp_super_cache_debug',
237 ),
238 'wp_cache_debug_username' => array(
239 'get' => 'wpsc_debug_username',
240 ),
241 'wp_cache_debug_log' => array(
242 'global' => 'wp_cache_debug_log',
243 ),
244 'wp_cache_debug_ip' => array(
245 'global' => 'wp_cache_debug_ip',
246 ),
247 'wp_super_cache_comments' => array(
248 'global' => 'wp_super_cache_comments',
249 ),
250 'wp_super_cache_front_page_check' => array(
251 'global' => 'wp_super_cache_front_page_check',
252 ),
253 'wp_super_cache_front_page_clear' => array(
254 'global' => 'wp_super_cache_front_page_clear',
255 ),
256 'wp_super_cache_front_page_text' => array(
257 'global' => 'wp_super_cache_front_page_text',
258 ),
259 'wp_super_cache_front_page_notification' => array(
260 'global' => 'wp_super_cache_front_page_notification',
261 ),
262 );
263 }
1 <?php
2
3 require_once( __DIR__ . '/class.wp-super-cache-rest-get-settings.php' );
4 require_once( __DIR__ . '/class.wp-super-cache-rest-update-settings.php' );
5 require_once( __DIR__ . '/class.wp-super-cache-rest-get-stats.php' );
6 require_once( __DIR__ . '/class.wp-super-cache-rest-get-cache.php' );
7 require_once( __DIR__ . '/class.wp-super-cache-rest-get-status.php' );
8 require_once( __DIR__ . '/class.wp-super-cache-rest-test-cache.php' );
9 require_once( __DIR__ . '/class.wp-super-cache-rest-delete-cache.php' );
10 require_once( __DIR__ . '/class.wp-super-cache-rest-preload.php' );
11 require_once( __DIR__ . '/class.wp-super-cache-rest-get-plugins.php' );
12 require_once( __DIR__. '/class.wp-super-cache-rest-update-plugins.php' );
13
14 class WP_Super_Cache_Router {
15
16 /**
17 * Register the routes for the objects of the controller.
18 *
19 * GET /wp-super-cache/v1/settings
20 * POST /wp-super-cache/v1/settings
21 * GET /wp-super-cache/v1/stats
22 * GET /wp-super-cache/v1/cache
23 * POST /wp-super-cache/v1/cache
24 */
25 public static function register_routes() {
26 $version = '1';
27 $namespace = 'wp-super-cache/v' . $version;
28
29 $get_settings = new WP_Super_Cache_Rest_Get_Settings();
30 $update_settings = new WP_Super_Cache_Rest_Update_Settings();
31 $get_stats = new WP_Super_Cache_Rest_Get_Stats();
32 $get_cache = new WP_Super_Cache_Rest_Get_Cache();
33 $test_cache = new WP_Super_Cache_Rest_Test_Cache();
34 $delete_cache = new WP_Super_Cache_Rest_Delete_Cache();
35 $preload_cache = new WP_Super_Cache_Rest_Preload();
36 $get_status = new WP_Super_Cache_Rest_Get_Status();
37 $get_plugins = new WP_Super_Cache_Rest_Get_Plugins();
38 $update_plugins = new WP_Super_Cache_Rest_Update_Plugins();
39
40 register_rest_route( $namespace, '/settings', array(
41 array(
42 'methods' => WP_REST_Server::READABLE,
43 'callback' => array( $get_settings, 'callback' ),
44 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
45 'args' => array(),
46 ),
47 array(
48 'methods' => WP_REST_Server::CREATABLE,
49 'callback' => array( $update_settings, 'callback' ),
50 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
51 'args' => array(),
52 ),
53 ) );
54
55 register_rest_route( $namespace, '/status', array(
56 'methods' => WP_REST_Server::READABLE,
57 'callback' => array( $get_status, 'callback' ),
58 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
59 ) );
60
61 register_rest_route( $namespace, '/stats', array(
62 'methods' => WP_REST_Server::READABLE,
63 'callback' => array( $get_stats, 'callback' ),
64 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
65 ) );
66
67 register_rest_route( $namespace, '/cache', array(
68 array(
69 'methods' => WP_REST_Server::READABLE,
70 'callback' => array( $get_cache, 'callback' ),
71 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
72 'args' => array(),
73 ),
74 array(
75 'methods' => WP_REST_Server::CREATABLE,
76 'callback' => array( $delete_cache, 'callback' ),
77 'permission_callback' => __CLASS__ . '::delete_item_permissions_check',
78 'args' => array(),
79 ),
80 ) );
81
82 register_rest_route( $namespace, '/preload', array(
83 'methods' => WP_REST_Server::CREATABLE,
84 'callback' => array( $preload_cache, 'callback' ),
85 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
86 ) );
87
88 register_rest_route( $namespace, '/cache/test', array(
89 'methods' => WP_REST_Server::CREATABLE,
90 'callback' => array( $test_cache, 'callback' ),
91 'permission_callback' => __CLASS__ . '::create_item_permissions_check',
92 ) );
93
94 register_rest_route( $namespace, '/plugins', array(
95 array(
96 'methods' => WP_REST_Server::READABLE,
97 'callback' => array( $get_plugins, 'callback' ),
98 'permission_callback' => __CLASS__ . '::get_item_permissions_check',
99 'args' => array(),
100 ),
101 array(
102 'methods' => WP_REST_Server::CREATABLE,
103 'callback' => array( $update_plugins, 'callback' ),
104 'permission_callback' => __CLASS__ . '::update_item_permissions_check',
105 'args' => array(),
106 ),
107 ) );
108 }
109
110 /**
111 * Check if a given request has access to get items
112 *
113 * @param WP_REST_Request $request Full data about the request.
114 * @return WP_Error|bool
115 */
116 public static function get_items_permissions_check( $request ) {
117 return wpsupercache_site_admin();
118 }
119
120 /**
121 * Check if a given request has access to get a specific item
122 *
123 * @param WP_REST_Request $request Full data about the request.
124 * @return WP_Error|bool
125 */
126 public static function get_item_permissions_check( $request ) {
127 return self::get_items_permissions_check( $request );
128 }
129
130 /**
131 * Check if a given request has access to create items
132 *
133 * @param WP_REST_Request $request Full data about the request.
134 * @return WP_Error|bool
135 */
136 public static function create_item_permissions_check( $request ) {
137 return self::get_items_permissions_check( $request );
138 }
139
140 /**
141 * Check if a given request has access to update a specific item
142 *
143 * @param WP_REST_Request $request Full data about the request.
144 * @return WP_Error|bool
145 */
146 public static function update_item_permissions_check( $request ) {
147 return self::create_item_permissions_check( $request );
148 }
149
150 /**
151 * Check if a given request has access to update a specific item
152 *
153 * @param WP_REST_Request $request Full data about the request.
154 * @return WP_Error|bool
155 */
156 public static function delete_item_permissions_check( $request ) {
157 return self::update_item_permissions_check( $request );
158 }
159
160 }
161
162 function wpsc_load_rest_api() {
163 $wpsupercache_route = new WP_Super_Cache_Router();
164 $wpsupercache_route->register_routes();
165 };
166
167 add_action( 'rest_api_init', 'wpsc_load_rest_api' );
1 <?php
2 /**
3 * Put your classes in this `src` folder!
4 *
5 * @package automattic/PACKAGE-NAME
6 */
7
8 // Start your code here!
1 <?php
2
3 // autoload.php @generated by Composer
4
5 if (PHP_VERSION_ID < 50600) {
6 if (!headers_sent()) {
7 header('HTTP/1.1 500 Internal Server Error');
8 }
9 $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
10 if (!ini_get('display_errors')) {
11 if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
12 fwrite(STDERR, $err);
13 } elseif (!headers_sent()) {
14 echo $err;
15 }
16 }
17 trigger_error(
18 $err,
19 E_USER_ERROR
20 );
21 }
22
23 require_once __DIR__ . '/composer/autoload_real.php';
24
25 return ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cache1_9_4::getLoader();
1 # Changelog
2
3 All notable changes to this project will be documented in this file.
4
5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
8 ## [1.4.24] - 2023-02-20
9 ### Changed
10 - Minor internal updates.
11
12 ## [1.4.23] - 2023-01-11
13 ### Changed
14 - Updated package dependencies.
15
16 ## [1.4.22] - 2022-12-02
17 ### Changed
18 - Updated package dependencies. [#27688]
19
20 ## [1.4.21] - 2022-11-22
21 ### Added
22 - Add a guard in `functions.php` against being loaded twice from different copies of the package. [#27475]
23
24 ### Changed
25 - Updated package dependencies. [#27043]
26
27 ## [1.4.20] - 2022-11-07
28 ### Fixed
29 - Ensure that User_Agent is loaded in environments without autoload enabled. (e.g.: WordPress.com and Super Cache) [#27223]
30
31 ## [1.4.19] - 2022-10-25
32 ### Changed
33 - Update `wp_unslash` wrapper to possibly run on wpcom before WordPress is loaded. [#26971]
34
35 ## [1.4.18] - 2022-07-26
36 ### Changed
37 - Updated package dependencies. [#25158]
38
39 ## [1.4.17] - 2022-06-21
40 ### Changed
41 - Renaming master to trunk.
42
43 ## [1.4.16] - 2022-04-26
44 ### Changed
45 - Updated package dependencies.
46
47 ## [1.4.15] - 2022-04-19
48 ### Changed
49 - PHPCS: Fix `WordPress.Security.ValidatedSanitizedInput`
50
51 ## [1.4.14] - 2022-03-29
52 ### Changed
53 - Microperformance: Use === null instead of is_null
54
55 ## [1.4.13] - 2022-02-09
56 ### Fixed
57 - Fixed some new PHPCS warnings.
58
59 ## [1.4.12] - 2022-01-25
60 ### Changed
61 - Updated package dependencies.
62
63 ## [1.4.11] - 2022-01-04
64 ### Changed
65 - Switch to pcov for code coverage.
66 - Updated package dependencies
67
68 ## [1.4.10] - 2021-12-14
69 ### Changed
70 - Updated package dependencies.
71
72 ## [1.4.9] - 2021-11-16
73 ### Fixed
74 - Verify $_SERVER['HTTP_USER_AGENT'] exists before use.
75
76 ## [1.4.8] - 2021-11-02
77 ### Changed
78 - Set `convertDeprecationsToExceptions` true in PHPUnit config.
79 - Update PHPUnit configs to include just what needs coverage rather than include everything then try to exclude stuff that doesn't.
80
81 ## [1.4.7] - 2021-10-19
82 ### Deprecated
83 - General: remove numerous long-deprecated functions.
84
85 ## [1.4.6] - 2021-10-13
86 ### Changed
87 - Updated package dependencies.
88
89 ## [1.4.5] - 2021-10-12
90 ### Changed
91 - Updated package dependencies
92
93 ## [1.4.4] - 2021-09-28
94 ### Changed
95 - Updated package dependencies.
96
97 ## [1.4.3] - 2021-08-31
98 ### Changed
99 - Run composer update on test-php command instead of phpunit.
100 - Tests: update PHPUnit polyfills dependency (yoast/phpunit-polyfills).
101 - Updated versions in annotations.
102
103 ## [1.4.2] - 2021-05-25
104 ### Changed
105 - Updated package dependencies.
106
107 ## [1.4.1] - 2021-04-27
108 ### Changed
109 - Updated package dependencies.
110
111 ## [1.4.0] - 2021-03-30
112 ### Added
113 - Added Opera Desktop detection
114 - Composer alias for dev-master, to improve dependencies
115
116 ### Changed
117 - Update package dependencies.
118
119 ### Fixed
120 - Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in.
121
122 ## [1.3.2] - 2021-02-05
123
124 - CI: Make tests more generic
125
126 ## [1.3.1] - 2021-01-19
127
128 - Add mirror-repo information to all current composer packages
129 - Monorepo: Reorganize all projects
130
131 ## [1.3.0] - 2020-12-09
132
133 - Codesniffer: Update mediawiki/mediawiki-codesniffer dependency
134 - Pin dependencies
135 - Packages: Update for PHP 8 testing
136
137 ## [1.2.1] - 2020-11-10
138
139 - Improve PHP 8 compatibility
140 - Updated PHPCS: Packages and Debugger
141
142 ## [1.2.0] - 2020-10-19
143
144 - Replaced intval() with (int) as part of issue #17432.
145
146 ## [1.1.0] - 2020-08-13
147
148 - CI: Try collect js coverage
149
150 ## 1.0.0 - 2020-06-25
151
152 - Moving jetpack_is_mobile into a package
153
154 [1.4.24]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.23...v1.4.24
155 [1.4.23]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.22...v1.4.23
156 [1.4.22]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.21...v1.4.22
157 [1.4.21]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.20...v1.4.21
158 [1.4.20]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.19...v1.4.20
159 [1.4.19]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.18...v1.4.19
160 [1.4.18]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.17...v1.4.18
161 [1.4.17]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.16...v1.4.17
162 [1.4.16]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.15...v1.4.16
163 [1.4.15]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.14...v1.4.15
164 [1.4.14]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.13...v1.4.14
165 [1.4.13]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.12...v1.4.13
166 [1.4.12]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.11...v1.4.12
167 [1.4.11]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.10...v1.4.11
168 [1.4.10]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.9...v1.4.10
169 [1.4.9]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.8...v1.4.9
170 [1.4.8]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.7...v1.4.8
171 [1.4.7]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.6...v1.4.7
172 [1.4.6]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.5...v1.4.6
173 [1.4.5]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.4...v1.4.5
174 [1.4.4]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.3...v1.4.4
175 [1.4.3]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.2...v1.4.3
176 [1.4.2]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.1...v1.4.2
177 [1.4.1]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.0...v1.4.1
178 [1.4.0]: https://github.com/Automattic/jetpack-device-detection/compare/v1.3.2...v1.4.0
179 [1.3.2]: https://github.com/Automattic/jetpack-device-detection/compare/v1.3.1...v1.3.2
180 [1.3.1]: https://github.com/Automattic/jetpack-device-detection/compare/v1.3.0...v1.3.1
181 [1.3.0]: https://github.com/Automattic/jetpack-device-detection/compare/v1.2.1...v1.3.0
182 [1.2.1]: https://github.com/Automattic/jetpack-device-detection/compare/v1.2.0...v1.2.1
183 [1.2.0]: https://github.com/Automattic/jetpack-device-detection/compare/v1.1.0...v1.2.0
184 [1.1.0]: https://github.com/Automattic/jetpack-device-detection/compare/v1.0.0...v1.1.0
1 # Jetpack Device Detection
2
3 A method to detect device types, originates from `jetpack_is_mobile`.
4
5
6
7 ### Usage
8
9 Retrieve device information.
10
11 ```php
12 use Automattic\Jetpack\Device_Detection;
13
14 $device_info = Device_Detection::get_info();
15
16 /**
17 * array(
18 * 'is_phone' => (bool) Whether the current device is a mobile phone.
19 * 'is_smartphone' => (bool) Whether the current device is a smartphone.
20 * 'is_tablet' => (bool) Whether the current device is a tablet device.
21 * 'is_handheld' => (bool) Whether the current device is a handheld device.
22 * 'is_desktop' => (bool) Whether the current device is a laptop / desktop device.
23 * 'platform' => (string) Detected platform.
24 * 'is_phone_matched_ua' => (string) Matched UA.
25 * );
26 */
27 ```
28
29 Detect any mobile phone.
30
31 ```php
32 use Automattic\Jetpack\Device_Detection;
33
34 $is_phone = Device_Detection::is_phone();
35 ```
36
37 Detect a smartphone.
38
39 ```php
40 use Automattic\Jetpack\Device_Detection;
41
42 $is_smartphone = Device_Detection::is_smartphone();
43 ```
44
45 Detect a dumbphone.
46
47 ```php
48 use Automattic\Jetpack\Device_Detection;
49
50 $is_dumbphone = Device_Detection::is_phone() && ! Device_Detection::is_smartphone();
51 ```
52
53 Detect a tablet.
54
55 ```php
56 use Automattic\Jetpack\Device_Detection;
57
58 $is_tablet = Device_Detection::is_tablet();
59 ```
60
61 Detect a desktop device.
62
63 ```php
64 use Automattic\Jetpack\Device_Detection;
65
66 $is_desktop = Device_Detection::is_desktop();
67 ```
68
69 Detect any handheld device.
70
71 ```php
72 use Automattic\Jetpack\Device_Detection;
73
74 $is_handheld = Device_Detection::is_handheld();
75 ```
1 # Security Policy
2
3 Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
4
5 ## Supported Versions
6
7 Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions.
8
9 ## Reporting a Vulnerability
10
11 [Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure.
12
13 **For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
14
15 Our most critical targets are:
16
17 * Jetpack and the Jetpack composer packages (all within this repo)
18 * Jetpack.com -- the primary marketing site.
19 * cloud.jetpack.com -- a management site.
20 * wordpress.com -- the shared management site for both Jetpack and WordPress.com sites.
21
22 For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
23
24 _Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
25
26 ## Guidelines
27
28 We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
29
30 * Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
31 * Pen-testing Production:
32 * Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
33 * If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
34 * **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
35 * To be eligible for a bounty, all of these guidelines must be followed.
36 * Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
37
38 We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.
1 {
2 "name": "automattic/jetpack-device-detection",
3 "description": "A way to detect device types based on User-Agent header.",
4 "type": "jetpack-library",
5 "license": "GPL-2.0-or-later",
6 "require": {},
7 "require-dev": {
8 "yoast/phpunit-polyfills": "1.0.4",
9 "automattic/jetpack-changelogger": "^3.3.2"
10 },
11 "autoload": {
12 "classmap": [
13 "src/"
14 ]
15 },
16 "scripts": {
17 "phpunit": [
18 "./vendor/phpunit/phpunit/phpunit --colors=always"
19 ],
20 "test-php": [
21 "@composer phpunit"
22 ]
23 },
24 "minimum-stability": "dev",
25 "prefer-stable": true,
26 "extra": {
27 "autotagger": true,
28 "mirror-repo": "Automattic/jetpack-device-detection",
29 "changelogger": {
30 "link-template": "https://github.com/Automattic/jetpack-device-detection/compare/v${old}...v${new}"
31 },
32 "branch-alias": {
33 "dev-trunk": "1.4.x-dev"
34 }
35 }
36 }
1 <?php
2 /**
3 * Device detection for Jetpack.
4 *
5 * @package automattic/jetpack-device-detection
6 */
7
8 namespace Automattic\Jetpack;
9
10 require_once __DIR__ . '/functions.php';
11 require_once __DIR__ . '/class-user-agent-info.php';
12
13 use Automattic\Jetpack\Device_Detection\User_Agent_Info;
14 use function Automattic\Jetpack\Device_Detection\wp_unslash;
15
16 /**
17 * Class Device_Detection
18 *
19 * Determine if the current User Agent matches the passed $kind.
20 */
21 class Device_Detection {
22
23 /**
24 * Returns information about the current device accessing the page.
25 *
26 * @param string $ua (Optional) User-Agent string.
27 *
28 * @return array Device information.
29 *
30 * array(
31 * 'is_phone' => (bool) Whether the current device is a mobile phone.
32 * 'is_smartphone' => (bool) Whether the current device is a smartphone.
33 * 'is_tablet' => (bool) Whether the current device is a tablet device.
34 * 'is_handheld' => (bool) Whether the current device is a handheld device.
35 * 'is_desktop' => (bool) Whether the current device is a laptop / desktop device.
36 * 'platform' => (string) Detected platform.
37 * 'is_phone_matched_ua' => (string) Matched UA.
38 * );
39 */
40 public static function get_info( $ua = '' ) {
41 $ua_info = new User_Agent_Info( $ua );
42
43 $info = array(
44 'is_phone' => self::is_mobile( 'any', false, $ua_info ),
45 'is_phone_matched_ua' => self::is_mobile( 'any', true, $ua_info ),
46 'is_smartphone' => self::is_mobile( 'smart', false, $ua_info ),
47 'is_tablet' => $ua_info->is_tablet(),
48 'platform' => $ua_info->get_platform(),
49 );
50
51 $info['is_handheld'] = $info['is_phone'] || $info['is_tablet'];
52 $info['is_desktop'] = ! $info['is_handheld'];
53
54 if ( function_exists( 'apply_filters' ) ) {
55 /**
56 * Filter the value of Device_Detection::get_info.
57 *
58 * @since 1.0.0
59 *
60 * @param array $info Array of device information.
61 * @param string $ua User agent string passed to Device_Detection::get_info.
62 * @param User_Agent_Info $ua_info Instance of Automattic\Jetpack\Device_Detection\User_Agent_Info.
63 */
64 $info = apply_filters( 'jetpack_device_detection_get_info', $info, $ua, $ua_info );
65 }
66 return $info;
67 }
68
69 /**
70 * Detects phone devices.
71 *
72 * @param string $ua User-Agent string.
73 *
74 * @return bool
75 */
76 public static function is_phone( $ua = '' ) {
77 $device_info = self::get_info( $ua );
78 return true === $device_info['is_phone'];
79 }
80
81 /**
82 * Detects smartphone devices.
83 *
84 * @param string $ua User-Agent string.
85 *
86 * @return bool
87 */
88 public static function is_smartphone( $ua = '' ) {
89 $device_info = self::get_info( $ua );
90 return true === $device_info['is_smartphone'];
91 }
92
93 /**
94 * Detects tablet devices.
95 *
96 * @param string $ua User-Agent string.
97 *
98 * @return bool
99 */
100 public static function is_tablet( $ua = '' ) {
101 $device_info = self::get_info( $ua );
102 return true === $device_info['is_tablet'];
103 }
104
105 /**
106 * Detects desktop devices.
107 *
108 * @param string $ua User-Agent string.
109 *
110 * @return bool
111 */
112 public static function is_desktop( $ua = '' ) {
113 $device_info = self::get_info( $ua );
114 return true === $device_info['is_desktop'];
115 }
116
117 /**
118 * Detects handheld (i.e. phone + tablet) devices.
119 *
120 * @param string $ua User-Agent string.
121 *
122 * @return bool
123 */
124 public static function is_handheld( $ua = '' ) {
125 $device_info = self::get_info( $ua );
126 return true === $device_info['is_handheld'];
127 }
128
129 /**
130 * Determine if the current User Agent matches the passed $kind.
131 *
132 * @param string $kind Category of mobile device to check for. Either: any, dumb, smart.
133 * @param bool $return_matched_agent Boolean indicating if the UA should be returned.
134 * @param User_Agent_Info $ua_info Boolean indicating if the UA should be returned.
135 *
136 * @return bool|string Boolean indicating if current UA matches $kind. If `$return_matched_agent` is true, returns the UA string.
137 */
138 private static function is_mobile( $kind, $return_matched_agent, $ua_info ) {
139 $kinds = array(
140 'smart' => false,
141 'dumb' => false,
142 'any' => false,
143 );
144 $first_run = true;
145 $matched_agent = '';
146
147 // If an invalid kind is passed in, reset it to default.
148 if ( ! isset( $kinds[ $kind ] ) ) {
149 $kind = 'any';
150 }
151
152 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
153 return false;
154 }
155
156 $agent = strtolower( filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) );
157 if ( strpos( $agent, 'ipad' ) ) {
158 return false;
159 }
160
161 // Remove Samsung Galaxy tablets (SCH-I800) from being mobile devices.
162 if ( strpos( $agent, 'sch-i800' ) ) {
163 return false;
164 }
165
166 if ( $ua_info->is_android_tablet() && false === $ua_info->is_kindle_touch() ) {
167 return false;
168 }
169
170 if ( $ua_info->is_blackberry_tablet() ) {
171 return false;
172 }
173
174 if ( $first_run ) {
175 $first_run = false;
176
177 // checks for iPhoneTier devices & RichCSS devices.
178 if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) {
179 $kinds['smart'] = true;
180 $matched_agent = $ua_info->matched_agent;
181 }
182
183 if ( ! $kinds['smart'] ) {
184 // if smart, we are not dumb so no need to check.
185 $dumb_agents = $ua_info->dumb_agents;
186
187 foreach ( $dumb_agents as $dumb_agent ) {
188 if ( false !== strpos( $agent, $dumb_agent ) ) {
189 $kinds['dumb'] = true;
190 $matched_agent = $dumb_agent;
191
192 break;
193 }
194 }
195
196 if ( ! $kinds['dumb'] ) {
197 if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
198 $kinds['dumb'] = true;
199 $matched_agent = 'http_x_wap_profile';
200 } elseif ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is doing the validating.
201 $kinds['dumb'] = true;
202 $matched_agent = 'vnd.wap.xhtml+xml';
203 }
204 }
205 }
206
207 if ( $kinds['dumb'] || $kinds['smart'] ) {
208 $kinds['any'] = true;
209 }
210 }
211
212 $value = $kinds[ $kind ];
213
214 if ( $return_matched_agent ) {
215 $value = $matched_agent;
216 }
217 return $value;
218 }
219 }
1 <?php
2 /**
3 * Utility functions for device detection.
4 *
5 * @package automattic/jetpack-device-detection
6 */
7
8 namespace Automattic\Jetpack\Device_Detection;
9
10 // Check if the function is already defined, in case someone bypassed the autoloader or something
11 // to get the two classes from different copies of the package.
12 if ( ! function_exists( __NAMESPACE__ . '\\wp_unslash' ) ) {
13
14 /**
15 * A wrapper for WordPress's `wp_unslash()`.
16 *
17 * Even though PHP itself dropped the option to add slashes to superglobals a decade ago,
18 * WordPress still does it through some misguided extreme backwards compatibility. 🙄
19 *
20 * If WordPress's function exists, assume it needs to be called.
21 * Else if on WordPress.com, do a simplified version because we're running really early.
22 * Else, assume it's not needed.
23 *
24 * @param string $value String of data to unslash.
25 * @return string Possibly unslashed $value.
26 */
27 function wp_unslash( $value ) {
28 if ( function_exists( '\\wp_unslash' ) ) {
29 return \wp_unslash( $value );
30 } elseif ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
31 return stripslashes( $value );
32 } else {
33 return $value;
34 }
35 }
36 }
1
2 Copyright (c) Nils Adermann, Jordi Boggiano
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is furnished
9 to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21
1 <?php
2
3 // autoload_classmap.php @generated by Composer
4
5 $vendorDir = dirname(__DIR__);
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 'Automattic\\Jetpack\\Device_Detection' => $vendorDir . '/automattic/jetpack-device-detection/src/class-device-detection.php',
10 'Automattic\\Jetpack\\Device_Detection\\User_Agent_Info' => $vendorDir . '/automattic/jetpack-device-detection/src/class-user-agent-info.php',
11 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
12 );
1 <?php
2
3 // autoload_namespaces.php @generated by Composer
4
5 $vendorDir = dirname(__DIR__);
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 );
1 <?php
2
3 // autoload_psr4.php @generated by Composer
4
5 $vendorDir = dirname(__DIR__);
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 );
1 <?php
2
3 // autoload_real.php @generated by Composer
4
5 class ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cache1_9_4
6 {
7 private static $loader;
8
9 public static function loadClassLoader($class)
10 {
11 if ('Composer\Autoload\ClassLoader' === $class) {
12 require __DIR__ . '/ClassLoader.php';
13 }
14 }
15
16 /**
17 * @return \Composer\Autoload\ClassLoader
18 */
19 public static function getLoader()
20 {
21 if (null !== self::$loader) {
22 return self::$loader;
23 }
24
25 spl_autoload_register(array('ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ1_9_4', 'loadClassLoader'), true, true);
26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27 spl_autoload_unregister(array('ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ1_9_4', 'loadClassLoader'));
28
29 require __DIR__ . '/autoload_static.php';
30 call_user_func(\Composer\Autoload\ComposerStaticInit6fe342bc02f0b440f7b3c8d8ade42286_super_cache1_9_4::getInitializer($loader));
31
32 $loader->setClassMapAuthoritative(true);
33 $loader->register(true);
34
35 return $loader;
36 }
37 }
1 <?php
2
3 // autoload_static.php @generated by Composer
4
5 namespace Composer\Autoload;
6
7 class ComposerStaticInit6fe342bc02f0b440f7b3c8d8ade42286_super_cache1_9_4
8 {
9 public static $classMap = array (
10 'Automattic\\Jetpack\\Device_Detection' => __DIR__ . '/..' . '/automattic/jetpack-device-detection/src/class-device-detection.php',
11 'Automattic\\Jetpack\\Device_Detection\\User_Agent_Info' => __DIR__ . '/..' . '/automattic/jetpack-device-detection/src/class-user-agent-info.php',
12 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
13 );
14
15 public static function getInitializer(ClassLoader $loader)
16 {
17 return \Closure::bind(function () use ($loader) {
18 $loader->classMap = ComposerStaticInit6fe342bc02f0b440f7b3c8d8ade42286_super_cache1_9_4::$classMap;
19
20 }, null, ClassLoader::class);
21 }
22 }
1 {
2 "packages": [
3 {
4 "name": "automattic/jetpack-device-detection",
5 "version": "v1.4.24",
6 "version_normalized": "1.4.24.0",
7 "source": {
8 "type": "git",
9 "url": "https://github.com/Automattic/jetpack-device-detection.git",
10 "reference": "9931222d1865eaf7efd26c9e88518e632593f7e2"
11 },
12 "dist": {
13 "type": "zip",
14 "url": "https://api.github.com/repos/Automattic/jetpack-device-detection/zipball/9931222d1865eaf7efd26c9e88518e632593f7e2",
15 "reference": "9931222d1865eaf7efd26c9e88518e632593f7e2",
16 "shasum": ""
17 },
18 "require-dev": {
19 "automattic/jetpack-changelogger": "^3.3.2",
20 "yoast/phpunit-polyfills": "1.0.4"
21 },
22 "time": "2023-02-20T19:47:12+00:00",
23 "type": "jetpack-library",
24 "extra": {
25 "autotagger": true,
26 "mirror-repo": "Automattic/jetpack-device-detection",
27 "changelogger": {
28 "link-template": "https://github.com/Automattic/jetpack-device-detection/compare/v${old}...v${new}"
29 },
30 "branch-alias": {
31 "dev-trunk": "1.4.x-dev"
32 }
33 },
34 "installation-source": "dist",
35 "autoload": {
36 "classmap": [
37 "src/"
38 ]
39 },
40 "notification-url": "https://packagist.org/downloads/",
41 "license": [
42 "GPL-2.0-or-later"
43 ],
44 "description": "A way to detect device types based on User-Agent header.",
45 "support": {
46 "source": "https://github.com/Automattic/jetpack-device-detection/tree/v1.4.24"
47 },
48 "install-path": "../automattic/jetpack-device-detection"
49 }
50 ],
51 "dev": false,
52 "dev-package-names": []
53 }
1 <?php return array(
2 'root' => array(
3 'name' => 'automattic/wp-super-cache',
4 'pretty_version' => 'dev-trunk',
5 'version' => 'dev-trunk',
6 'reference' => NULL,
7 'type' => 'wordpress-plugin',
8 'install_path' => __DIR__ . '/../../',
9 'aliases' => array(),
10 'dev' => false,
11 ),
12 'versions' => array(
13 'automattic/jetpack-device-detection' => array(
14 'pretty_version' => 'v1.4.24',
15 'version' => '1.4.24.0',
16 'reference' => '9931222d1865eaf7efd26c9e88518e632593f7e2',
17 'type' => 'jetpack-library',
18 'install_path' => __DIR__ . '/../automattic/jetpack-device-detection',
19 'aliases' => array(),
20 'dev_requirement' => false,
21 ),
22 'automattic/wp-super-cache' => array(
23 'pretty_version' => 'dev-trunk',
24 'version' => 'dev-trunk',
25 'reference' => NULL,
26 'type' => 'wordpress-plugin',
27 'install_path' => __DIR__ . '/../../',
28 'aliases' => array(),
29 'dev_requirement' => false,
30 ),
31 ),
32 );
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.