Changeset 3494018
- Timestamp:
- 03/29/2026 09:03:11 PM (8 weeks ago)
- Location:
- xv-random-quotes/trunk
- Files:
-
- 13 edited
-
changelog.txt (modified) (1 diff)
-
js/quote-refresh.js (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
src/Admin/OverviewPage.php (modified) (1 diff)
-
src/Admin/Settings.php (modified) (4 diffs)
-
src/Blocks/RandomQuote/block.json (modified) (1 diff)
-
src/Blocks/RandomQuote/index.tsx (modified) (3 diffs)
-
src/Blocks/RandomQuote/render.php (modified) (2 diffs)
-
src/Output/QuoteOutput.php (modified) (5 diffs)
-
src/Shortcodes/ShortcodeHandlers.php (modified) (3 diffs)
-
src/generated/random-quote-block.asset.php (modified) (1 diff)
-
src/generated/random-quote-block.js (modified) (1 diff)
-
xv-random-quotes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
xv-random-quotes/trunk/changelog.txt
r3494013 r3494018 1 1 == XV Random Quotes == 2 3 = 2.9.0 = 4 New feature: Cache bypass mode — AJAX-enabled quotes can now fetch a fresh quote on every page load, bypassing full-page caches like WP Rocket 5 New feature: Global "Bypass Page Cache" setting in AJAX Settings 6 New feature: Per-block "Bypass page cache" toggle in the Random Quote block editor 7 New feature: cache_bypass shortcode attribute for [stray-random] 8 Fix: AJAX refresh no longer sends a WP nonce header, preventing failures on pages cached longer than 12-24 hours 9 Fix: Admin card padding overridden to restore proper spacing when other plugins (e.g. Subscribe to Comments Reloaded) zero out .card padding 2 10 3 11 = 2.8.0 = -
xv-random-quotes/trunk/js/quote-refresh.js
r3463709 r3494018 32 32 // Set up auto-refresh timers 33 33 const containers = document.querySelectorAll('.xv-quote-container[data-timer]'); 34 34 35 35 containers.forEach(function(container) { 36 36 const timer = parseInt(container.getAttribute('data-timer'), 10); 37 37 38 38 if (timer > 0) { 39 39 setInterval(function() { … … 41 41 }, timer * 1000); // Convert seconds to milliseconds 42 42 } 43 }); 44 45 // Load-on-init: fetch a fresh quote immediately for cache-bypass containers 46 const initContainers = document.querySelectorAll('.xv-quote-container[data-load-on-init="1"]'); 47 48 initContainers.forEach(function(container) { 49 refreshQuote(container); 43 50 }); 44 51 } … … 95 102 method: 'GET', 96 103 headers: { 97 'Content-Type': 'application/json', 98 'X-WP-Nonce': xvQuoteRefresh.restNonce 99 }, 100 credentials: 'same-origin' 104 'Content-Type': 'application/json' 105 } 101 106 }) 102 107 .then(function(response) { -
xv-random-quotes/trunk/readme.txt
r3494013 r3494018 6 6 Tested up to: 6.9 7 7 Requires PHP: 7.4 8 Stable tag: 2. 8.08 Stable tag: 2.9.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
xv-random-quotes/trunk/src/Admin/OverviewPage.php
r3435038 r3494018 231 231 max-width: 100%; 232 232 margin-bottom: 20px; 233 padding: 16px 20px 20px !important; 233 234 } 234 235 .wrap .card h3 { -
xv-random-quotes/trunk/src/Admin/Settings.php
r3494013 r3494018 52 52 // AJAX Settings 53 53 const OPTION_AJAX = 'xv_quotes_ajax'; 54 const OPTION_CACHE_BYPASS = 'xv_quotes_cache_bypass'; 54 55 const OPTION_LOADER = 'xv_quotes_loader'; 55 56 const OPTION_BEFORE_LOADER = 'xv_quotes_before_loader'; … … 196 197 register_setting( 197 198 self::SETTINGS_GROUP, 199 self::OPTION_CACHE_BYPASS, 200 array( 201 'type' => 'string', 202 'default' => '0', 203 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), 204 ) 205 ); 206 207 register_setting( 208 self::SETTINGS_GROUP, 198 209 self::OPTION_LOADER, 199 210 array( … … 523 534 'option_name' => self::OPTION_AJAX, 524 535 'description' => __( 'Check to disable AJAX dynamic loading entirely. When unchecked, AJAX can still be disabled from widgets, shortcodes, or template tags.', 'xv-random-quotes' ), 536 ) 537 ); 538 539 add_settings_field( 540 self::OPTION_CACHE_BYPASS, 541 __( 'Bypass Page Cache Globally', 'xv-random-quotes' ), 542 array( $this, 'render_checkbox_field' ), 543 self::PAGE_SLUG, 544 'xv_quotes_ajax', 545 array( 546 'label_for' => self::OPTION_CACHE_BYPASS, 547 'option_name' => self::OPTION_CACHE_BYPASS, 548 'description' => __( 'When enabled, all AJAX-enabled quotes will fetch a fresh quote on every page load, bypassing full-page caches like WP Rocket. Requires AJAX to be enabled on each quote block or shortcode.', 'xv-random-quotes' ), 525 549 ) 526 550 ); … … 798 822 max-width: 100%; 799 823 margin-bottom: 20px; 824 padding: 16px 20px 20px !important; 800 825 } 801 826 .xv-quotes-settings .card h2 { -
xv-random-quotes/trunk/src/Blocks/RandomQuote/block.json
r3463747 r3494018 37 37 "type": "number", 38 38 "default": 0 39 }, 40 "cacheBypass": { 41 "type": "boolean", 42 "default": false 39 43 } 40 44 }, -
xv-random-quotes/trunk/src/Blocks/RandomQuote/index.tsx
r3463747 r3494018 16 16 enableAjax: boolean; 17 17 timer: number; 18 cacheBypass: boolean; 18 19 } 19 20 … … 60 61 /> 61 62 {attributes.enableAjax && ( 63 <> 62 64 <RangeControl 63 65 label={__('Auto-refresh timer (seconds)', 'xv-random-quotes')} … … 68 70 help={__('0 = no auto-refresh', 'xv-random-quotes')} 69 71 /> 72 <ToggleControl 73 label={__('Bypass page cache', 'xv-random-quotes')} 74 checked={attributes.cacheBypass} 75 onChange={(value) => setAttributes({ cacheBypass: value })} 76 help={__('Fetch a fresh quote on every page load, even when the page is cached', 'xv-random-quotes')} 77 /> 78 </> 70 79 )} 71 80 </BlockEditor> -
xv-random-quotes/trunk/src/Blocks/RandomQuote/render.php
r3430809 r3494018 22 22 $enableAjax = $attributes['enableAjax'] ?? false; 23 23 $timer = $attributes['timer'] ?? 0; 24 $cacheBypass = $attributes['cacheBypass'] ?? false; 24 25 25 26 // Use QuoteOutput class for complete rendering (including AJAX if enabled) … … 33 34 'disableaspect' => $disableaspect, 34 35 'enable_ajax' => $enableAjax, 36 'cache_bypass' => $cacheBypass, 35 37 'timer' => $timer, 36 38 ) -
xv-random-quotes/trunk/src/Output/QuoteOutput.php
r3463709 r3494018 82 82 'contributor' => '', 83 83 'enable_ajax' => false, 84 'cache_bypass' => false, 84 85 'link_phrase' => '', 85 86 'timer' => 0, … … 118 119 // Wrap with AJAX functionality if enabled 119 120 if ( $args['enable_ajax'] ) { 120 return $this->wrap_with_ajax( $quote_html, $args, $quotes ); 121 // Apply global cache bypass setting if not already enabled per-instance 122 $cache_bypass = $args['cache_bypass']; 123 if ( ! $cache_bypass && get_option( Settings::OPTION_CACHE_BYPASS, false ) === '1' ) { 124 $cache_bypass = true; 125 } 126 return $this->wrap_with_ajax( $quote_html, $args, $quotes, $cache_bypass ); 121 127 } 122 128 … … 127 133 * Wrap quote HTML with AJAX container and refresh link 128 134 * 129 * @param string $quote_html The rendered quote HTML. 130 * @param array $args Arguments array with AJAX configuration. 131 * @param array $quotes Array of WP_Post quote objects being displayed. 135 * @param string $quote_html The rendered quote HTML. 136 * @param array $args Arguments array with AJAX configuration. 137 * @param array $quotes Array of WP_Post quote objects being displayed. 138 * @param bool $cache_bypass When true, renders an empty container so JS fetches a fresh quote on every page load. 132 139 * @return string HTML wrapped with AJAX functionality. 133 140 */ 134 private function wrap_with_ajax( $quote_html, $args, $quotes = array() ) {141 private function wrap_with_ajax( $quote_html, $args, $quotes = array(), $cache_bypass = false ) { 135 142 // Generate or use provided container ID 136 143 $container_id = ! empty( $args['container_id'] ) ? $args['container_id'] : 'xv-quote-container-' . uniqid(); … … 164 171 $output .= ' data-timer="' . esc_attr( absint( $args['timer'] ) ) . '"'; 165 172 173 if ( $cache_bypass ) { 174 $output .= ' data-load-on-init="1"'; 175 } 176 166 177 $output .= '>'; 167 $output .= $quote_html; 178 179 if ( ! $cache_bypass ) { 180 $output .= $quote_html; 181 } 168 182 169 183 // Add refresh link (only if not auto-refresh only) … … 211 225 'xvQuoteRefresh', 212 226 array( 213 'restUrl' => esc_url_raw( rest_url( 'xv-random-quotes/v1/quote/random' ) ), 214 'restNonce' => wp_create_nonce( 'wp_rest' ), 227 'restUrl' => esc_url_raw( rest_url( 'xv-random-quotes/v1/quote/random' ) ), 215 228 ) 216 229 ); -
xv-random-quotes/trunk/src/Shortcodes/ShortcodeHandlers.php
r3463709 r3494018 111 111 'noajax' => '', 112 112 'enable_ajax' => '', 113 'cache_bypass' => '', 113 114 'multi' => 1, 114 115 'timer' => '', … … 138 139 } 139 140 141 $cache_bypass = ! empty( $atts['cache_bypass'] ) ? filter_var( $atts['cache_bypass'], FILTER_VALIDATE_BOOLEAN ) : false; 142 140 143 // Use QuoteOutput class for complete rendering (including AJAX if enabled) 141 144 $quote_output = new QuoteOutput(); … … 149 152 'contributor' => $atts['user'], 150 153 'enable_ajax' => $enable_ajax, 154 'cache_bypass' => $cache_bypass, 151 155 'link_phrase' => $atts['linkphrase'], 152 156 'timer' => ! empty( $atts['timer'] ) ? absint( $atts['timer'] ) : 0, -
xv-random-quotes/trunk/src/generated/random-quote-block.asset.php
r3463747 r3494018 1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => ' 53d7bb16db4cdfcfcaec');1 <?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n', 'wp-server-side-render'), 'version' => '0486856f86ec2cf71c23'); -
xv-random-quotes/trunk/src/generated/random-quote-block.js
r3463747 r3494018 1 (()=>{"use strict";var e={n:o=>{var n=o&&o.__esModule?()=>o.default:()=>o;return e.d(n,{a:n}),n},d:(o,n)=>{for(var t in n)e.o(n,t)&&!e.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:n[t]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,n=window.wp.components,t=window.wp.i18n,a=window.wp.blockEditor,r=window.wp.serverSideRender;var s=e.n(r);const l=window.ReactJSXRuntime,d=({blockName:e,attributes:o,children:r,renderCondition:d=!0,placeholderMessage:i=null})=>{const u=(0,a.useBlockProps)();return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(a.InspectorControls,{children:(0,l.jsx)(n.PanelBody,{title:(0,t.__)("Quote Settings","xv-random-quotes"),children:r})}),(0,l.jsx)("div",{...u,children:d?(0,l.jsx)(s(),{block:e,attributes:o}):i&&(0,l.jsx)("p",{children:i})})]})},i=({value:e,onChange:o})=>(0,l.jsx)(n.TextControl,{label:(0,t.__)("Categories (comma-separated slugs)","xv-random-quotes"),value:e,onChange:o,help:(0,t.__)("Leave empty for all categories","xv-random-quotes")}),u=({checked:e,onChange:o})=>(0,l.jsx)(n.ToggleControl,{label:(0,t.__)("Disable styling","xv-random-quotes"),checked:e,onChange:o,help:(0,t.__)("Remove default HTML wrappers","xv-random-quotes")});(0,o.registerBlockType)("xv-random-quotes/random-quote",{edit:e=>{const{attributes:o,setAttributes:a}=e;return(0,l.jsxs)(d,{blockName:"xv-random-quotes/random-quote",attributes:o,children:[(0,l.jsx)(i,{value:o.categories,onChange:e=>a({categories:e})}),(0,l.jsx)(n.RangeControl,{label:(0,t.__)("Number of quotes","xv-random-quotes"),value:o.multi,onChange:e=>a({multi:e||1}),min:1,max:10,help:(0,t.__)("How many quotes to display","xv-random-quotes")}),(0,l.jsx)(n.ToggleControl,{label:(0,t.__)("Sequential order","xv-random-quotes"),checked:o.sequence,onChange:e=>a({sequence:e}),help:(0,t.__)("Show quotes in order instead of random","xv-random-quotes")}),(0,l.jsx)(u,{checked:o.disableaspect,onChange:e=>a({disableaspect:e})}),(0,l.jsx)(n.ToggleControl,{label:(0,t.__)("Enable AJAX refresh","xv-random-quotes"),checked:o.enableAjax,onChange:e=>a({enableAjax:e})}),o.enableAjax&&(0,l.jsx)(n.RangeControl,{label:(0,t.__)("Auto-refresh timer (seconds)","xv-random-quotes"),value:o.timer,onChange:e=>a({timer:e}),min:0,max:300,help:(0,t.__)("0 = no auto-refresh","xv-random-quotes")})]})},save:()=>null})})();1 (()=>{"use strict";var e={n:o=>{var n=o&&o.__esModule?()=>o.default:()=>o;return e.d(n,{a:n}),n},d:(o,n)=>{for(var a in n)e.o(n,a)&&!e.o(o,a)&&Object.defineProperty(o,a,{enumerable:!0,get:n[a]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,n=window.wp.components,a=window.wp.i18n,t=window.wp.blockEditor,s=window.wp.serverSideRender;var r=e.n(s);const l=window.ReactJSXRuntime,d=({blockName:e,attributes:o,children:s,renderCondition:d=!0,placeholderMessage:c=null})=>{const u=(0,t.useBlockProps)();return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(t.InspectorControls,{children:(0,l.jsx)(n.PanelBody,{title:(0,a.__)("Quote Settings","xv-random-quotes"),children:s})}),(0,l.jsx)("div",{...u,children:d?(0,l.jsx)(r(),{block:e,attributes:o}):c&&(0,l.jsx)("p",{children:c})})]})},c=({value:e,onChange:o})=>(0,l.jsx)(n.TextControl,{label:(0,a.__)("Categories (comma-separated slugs)","xv-random-quotes"),value:e,onChange:o,help:(0,a.__)("Leave empty for all categories","xv-random-quotes")}),u=({checked:e,onChange:o})=>(0,l.jsx)(n.ToggleControl,{label:(0,a.__)("Disable styling","xv-random-quotes"),checked:e,onChange:o,help:(0,a.__)("Remove default HTML wrappers","xv-random-quotes")});(0,o.registerBlockType)("xv-random-quotes/random-quote",{edit:e=>{const{attributes:o,setAttributes:t}=e;return(0,l.jsxs)(d,{blockName:"xv-random-quotes/random-quote",attributes:o,children:[(0,l.jsx)(c,{value:o.categories,onChange:e=>t({categories:e})}),(0,l.jsx)(n.RangeControl,{label:(0,a.__)("Number of quotes","xv-random-quotes"),value:o.multi,onChange:e=>t({multi:e||1}),min:1,max:10,help:(0,a.__)("How many quotes to display","xv-random-quotes")}),(0,l.jsx)(n.ToggleControl,{label:(0,a.__)("Sequential order","xv-random-quotes"),checked:o.sequence,onChange:e=>t({sequence:e}),help:(0,a.__)("Show quotes in order instead of random","xv-random-quotes")}),(0,l.jsx)(u,{checked:o.disableaspect,onChange:e=>t({disableaspect:e})}),(0,l.jsx)(n.ToggleControl,{label:(0,a.__)("Enable AJAX refresh","xv-random-quotes"),checked:o.enableAjax,onChange:e=>t({enableAjax:e})}),o.enableAjax&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.RangeControl,{label:(0,a.__)("Auto-refresh timer (seconds)","xv-random-quotes"),value:o.timer,onChange:e=>t({timer:e}),min:0,max:300,help:(0,a.__)("0 = no auto-refresh","xv-random-quotes")}),(0,l.jsx)(n.ToggleControl,{label:(0,a.__)("Bypass page cache","xv-random-quotes"),checked:o.cacheBypass,onChange:e=>t({cacheBypass:e}),help:(0,a.__)("Fetch a fresh quote on every page load, even when the page is cached","xv-random-quotes")})]})]})},save:()=>null})})(); -
xv-random-quotes/trunk/xv-random-quotes.php
r3494013 r3494018 5 5 Author: Xavi Ivars 6 6 Author URI: https://xavi.ivars.me/ 7 Version: 2. 8.07 Version: 2.9.0 8 8 Requires at least: 6.0 9 9 Requires PHP: 7.4
Note: See TracChangeset
for help on using the changeset viewer.