close

Plugin Directory

Changeset 3463709


Ignore:
Timestamp:
02/17/2026 05:18:44 PM (3 months ago)
Author:
xavivars
Message:

Fix shortcode ajax loader

Location:
xv-random-quotes/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • xv-random-quotes/trunk/changelog.txt

    r3435421 r3463709  
    11== XV Random Quotes ==
     2
     3= 2.6.1 =
     4Fix: Sequential mode now works on shortcodes
     5Fix: LinkPhrase not being required for AJAX shortcodes
     6Improvement: Added `enable_ajax` as an equivalent (in reverse) to `noajax` for shortcodes.
    27
    38= 2.6.0 =
  • xv-random-quotes/trunk/js/quote-refresh.js

    r3429339 r3463709  
    5656        const disableaspect = container.getAttribute('data-disableaspect') === '1';
    5757        const contributor = container.getAttribute('data-contributor') || '';
     58        const currentId = container.getAttribute('data-current-id') || '';
    5859
    5960        // Build query string
     
    6465        if (sequence) {
    6566            params.append('sequence', '1');
     67            // For sequential mode, send current ID to get next quote
     68            if (currentId) {
     69                params.append('current_id', currentId);
     70            }
    6671        }
    6772        if (multi > 1) {
     
    105110                // Get the refresh link wrapper to preserve it
    106111                const refreshWrapper = container.querySelector('.xv-quote-refresh-wrapper');
    107                
     112
    108113                // Update the container content
    109114                // We need to replace everything except the refresh link
    110115                const tempDiv = document.createElement('div');
    111116                tempDiv.innerHTML = data.html;
    112                
     117
    113118                // Clear container except for refresh wrapper
    114119                while (container.firstChild && container.firstChild !== refreshWrapper) {
    115120                    container.removeChild(container.firstChild);
    116121                }
    117                
     122
    118123                // Insert new content before refresh wrapper
    119124                if (refreshWrapper) {
     
    125130                    container.innerHTML = data.html;
    126131                }
    127                
     132
     133                // Update current ID for sequential tracking
     134                if (data.quote_id) {
     135                    container.setAttribute('data-current-id', data.quote_id);
     136                }
     137
     138                // Handle end of sequence
     139                if (data.end_of_sequence && refreshWrapper) {
     140                    const refreshLink = refreshWrapper.querySelector('.xv-quote-refresh');
     141                    if (refreshLink) {
     142                        refreshLink.style.display = 'none';
     143                    }
     144                }
     145
    128146                // Fade in
    129147                container.style.opacity = '1';
  • xv-random-quotes/trunk/readme.txt

    r3435421 r3463709  
    66Tested up to: 6.9
    77Requires PHP: 7.4
    8 Stable tag: 2.6.0
     8Stable tag: 2.6.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • xv-random-quotes/trunk/src/Output/QuoteOutput.php

    r3431360 r3463709  
    118118        // Wrap with AJAX functionality if enabled
    119119        if ( $args['enable_ajax'] ) {
    120             return $this->wrap_with_ajax( $quote_html, $args );
     120            return $this->wrap_with_ajax( $quote_html, $args, $quotes );
    121121        }
    122122
     
    129129     * @param string $quote_html The rendered quote HTML.
    130130     * @param array  $args       Arguments array with AJAX configuration.
     131     * @param array  $quotes     Array of WP_Post quote objects being displayed.
    131132     * @return string HTML wrapped with AJAX functionality.
    132133     */
    133     private function wrap_with_ajax( $quote_html, $args ) {
     134    private function wrap_with_ajax( $quote_html, $args, $quotes = array() ) {
    134135        // Generate or use provided container ID
    135136        $container_id = ! empty( $args['container_id'] ) ? $args['container_id'] : 'xv-quote-container-' . uniqid();
     
    144145        if ( ! empty( $args['contributor'] ) ) {
    145146            $output .= ' data-contributor="' . esc_attr( $args['contributor'] ) . '"';
     147        }
     148
     149        // Add current quote ID(s) for sequential tracking
     150        if ( ! empty( $quotes ) ) {
     151            if ( $args['multi'] > 1 ) {
     152                // For multiple quotes, store comma-separated IDs
     153                $quote_ids = array_map( function( $quote ) {
     154                    return $quote->ID;
     155                }, $quotes );
     156                $output .= ' data-current-id="' . esc_attr( implode( ',', $quote_ids ) ) . '"';
     157            } else {
     158                // For single quote, store just the ID
     159                $output .= ' data-current-id="' . esc_attr( $quotes[0]->ID ) . '"';
     160            }
    146161        }
    147162
  • xv-random-quotes/trunk/src/RestAPI/QuoteEndpoint.php

    r3431360 r3463709  
    8080                'sanitize_callback' => 'sanitize_text_field',
    8181            ),
     82            'current_id'     => array(
     83                'description'       => 'Current quote ID(s) for sequential progression (comma-separated for multi)',
     84                'type'              => 'string',
     85                'default'           => '',
     86                'sanitize_callback' => 'sanitize_text_field',
     87            ),
    8288        );
    8389    }
     
    96102        $disableaspect = $request->get_param( 'disableaspect' );
    97103        $contributor   = $request->get_param( 'contributor' );
     104        $current_id    = $request->get_param( 'current_id' );
    98105
    99106        // Get quotes first (before rendering)
     
    107114            'posts_per_page' => $multi,
    108115        );
    109        
     116
    110117        // Add ordering
    111118        if ( $sequence ) {
    112119            $query_args['orderby'] = 'date';
    113120            $query_args['order'] = 'ASC';
     121
     122            // If current_id is provided, get the next quote(s) after it
     123            if ( ! empty( $current_id ) ) {
     124                // For multi-quote, get the last ID
     125                $current_ids = explode( ',', $current_id );
     126                $last_id = end( $current_ids );
     127
     128                // Get the post to find its date
     129                $current_post = get_post( absint( $last_id ) );
     130                if ( $current_post ) {
     131                    // Query for quotes published after this date
     132                    $query_args['date_query'] = array(
     133                        array(
     134                            'after'     => $current_post->post_date,
     135                            'inclusive' => false,
     136                        ),
     137                    );
     138                }
     139            }
    114140        } else {
    115141            $query_args['orderby'] = 'rand';
    116142        }
    117        
     143
    118144        // Get quotes
    119145        if ( ! empty( $categories_array ) ) {
     
    156182        );
    157183
     184        // Check if we've reached the end of sequence
     185        $end_of_sequence = false;
     186        if ( $sequence && ! empty( $current_id ) ) {
     187            // If we got quotes, check if there are more after these
     188            if ( ! empty( $quotes ) ) {
     189                $last_quote = end( $quotes );
     190                $check_query_args = array(
     191                    'posts_per_page' => 1,
     192                    'fields'         => 'ids',
     193                    'orderby'        => 'date',
     194                    'order'          => 'ASC',
     195                    'date_query'     => array(
     196                        array(
     197                            'after'     => $last_quote->post_date,
     198                            'inclusive' => false,
     199                        ),
     200                    ),
     201                );
     202
     203                // Check for more quotes
     204                if ( ! empty( $categories_array ) ) {
     205                    $more_quotes = $quote_queries->get_quotes_by_categories( $categories_array, $check_query_args );
     206                } else {
     207                    $more_quotes = $quote_queries->get_all_quotes( $check_query_args );
     208                }
     209
     210                $end_of_sequence = empty( $more_quotes );
     211            }
     212        }
     213
     214        $response_data['end_of_sequence'] = $end_of_sequence;
     215
    158216        // Add metadata for single quote
    159217        if ( $multi === 1 && ! empty( $quotes ) && count( $quotes ) > 0 ) {
    160218            $quote = $quotes[0];
    161            
     219
    162220            $response_data['quote_id']      = $quote->ID;
    163221            $response_data['quote_text']    = wp_strip_all_tags( $quote->post_content );
    164222            $response_data['quote_content'] = $quote->post_content;
    165            
     223
    166224            // Get author
    167225            $authors = wp_get_post_terms( $quote->ID, 'quote_author' );
    168             $response_data['author'] = ! empty( $authors ) && ! is_wp_error( $authors ) 
    169                 ? $authors[0]->name 
     226            $response_data['author'] = ! empty( $authors ) && ! is_wp_error( $authors )
     227                ? $authors[0]->name
    170228                : '';
    171            
     229
    172230            // Get source
    173231            $response_data['source'] = get_post_meta( $quote->ID, '_quote_source', true );
    174            
     232
    175233            // Get categories
    176234            $categories_terms = wp_get_post_terms( $quote->ID, 'quote_category' );
  • xv-random-quotes/trunk/src/Shortcodes/ShortcodeHandlers.php

    r3430809 r3463709  
    110110        'widgetid' => '',
    111111        'noajax' => '',
     112        'enable_ajax' => '',
    112113        'multi' => 1,
    113114        'timer' => '',
     
    118119    ));
    119120
    120     // Determine if AJAX is enabled (noajax="" means enabled)
    121     $enable_ajax = empty( $atts['noajax'] ) && ! empty( $atts['linkphrase'] );
     121    // Determine if AJAX is enabled
     122    // Priority order:
     123    // 1. If enable_ajax is explicitly set, use it (true = enable, false = disable)
     124    // 2. Otherwise, use legacy noajax logic (noajax="" or false = enable, noajax="true" = disable)
     125    // 3. Check global AJAX setting (if globally disabled, override to false)
     126    if ( ! empty( $atts['enable_ajax'] ) ) {
     127        // Explicit enable_ajax parameter takes priority
     128        $enable_ajax = filter_var( $atts['enable_ajax'], FILTER_VALIDATE_BOOLEAN );
     129    } else {
     130        // Legacy noajax logic: empty/false = AJAX enabled
     131        $enable_ajax = empty( $atts['noajax'] );
     132    }
     133
     134    // Check global AJAX setting (if disabled globally, override to false)
     135    $global_ajax_disabled = get_option( \XVRandomQuotes\Admin\Settings::OPTION_AJAX, false );
     136    if ( $global_ajax_disabled ) {
     137        $enable_ajax = false;
     138    }
    122139
    123140    // Use QuoteOutput class for complete rendering (including AJAX if enabled)
  • xv-random-quotes/trunk/vendor/composer/installed.php

    r3435421 r3463709  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => 'c5c63fb91808ddbfdfb9ab496437bfe15ad21871',
     6        'reference' => 'ce36e0cf96881317dd73f3a6f9cdd2878096ee62',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => 'c5c63fb91808ddbfdfb9ab496437bfe15ad21871',
     16            'reference' => 'ce36e0cf96881317dd73f3a6f9cdd2878096ee62',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • xv-random-quotes/trunk/xv-random-quotes.php

    r3435421 r3463709  
    55Author: Xavi Ivars
    66Author URI: https://xavi.ivars.me/
    7 Version: 2.6.0
     7Version: 2.6.1
    88Requires at least: 6.0
    99Requires PHP: 7.4
Note: See TracChangeset for help on using the changeset viewer.