Plugin Directory

Changeset 3280737


Ignore:
Timestamp:
04/24/2025 09:34:20 AM (11 months ago)
Author:
dexerto
Message:

Update to version 1.3.0 from GitHub

Location:
on-demand-revalidation
Files:
62 added
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • on-demand-revalidation/tags/1.3.0/on-demand-revalidation.php

    r3225736 r3280737  
    77 * GitHub Plugin URI:   https://github.com/dexerto/on-demand-revalidation
    88 * Description:         Next.js On-Demand Revalidation on the post update, revalidate specific paths, tags on the post update.
    9  * Version:             1.2.5
     9 * Version:             1.3.0
    1010 * Author:              Dexerto
    1111 * Author URI:          https://dexerto.com
     
    1313 * License:             GPL-3
    1414 * License URI:         https://www.gnu.org/licenses/gpl-3.0.html
    15  * 
     15 *
    1616 * @package OnDemandRevalidation
    1717 */
     
    5555                    self::$instance->revalidation();
    5656                    self::$instance->plugin_links();
     57                    self::$instance->load_textdomain();
    5758
    5859                    \OnDemandRevalidation\Helpers::prevent_wrong_api_url();
     
    122123            // Plugin version.
    123124            if ( ! defined( 'ON_DEMAND_REVALIDATION_VERSION' ) ) {
    124                 define( 'ON_DEMAND_REVALIDATION_VERSION', get_plugin_data( __FILE__ )['Version'] );
     125                $plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ) );
     126                define( 'ON_DEMAND_REVALIDATION_VERSION', $plugin_data['Version'] );
    125127            }
    126128
     
    226228            );
    227229        }
     230
     231        /**
     232         * Load plugin text domain.
     233         *
     234         * @since 1.3.0
     235         */
     236        private function load_textdomain(): void {
     237            add_action(
     238                'init',
     239                function () {
     240                    load_plugin_textdomain( 'on-demand-revalidation', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     241                }
     242            );
     243        }
    228244    }
    229245
  • on-demand-revalidation/tags/1.3.0/readme.txt

    r3225736 r3280737  
    22Contributors: bebjakub
    33Tags: nextjs, ssg, revalidation, on-demand
    4 Requires at least: 4.7
    5 Tested up to: 6.7.1
    6 Stable tag: 1.2.5
     4Requires at least: 6.0.0
     5Tested up to: 6.7.2
     6Stable tag: 1.3.0
    77Requires PHP: 8.0
    88License: GPL-3
     
    1111=== Description ===
    1212
    13 Next.js On-Demand Revalidation for Wordpress on the post update, revalidate specific paths and tags on the post update.
     13Next.js On-Demand Revalidation for Wordpress on post updates, revalidate specific paths and tags on post updates.
    1414
    1515Feel free to create a PR to [plugin Github repo](https://github.com/Dexerto/on-demand-revalidation).
     
    2525
    2626== Changelog ==
     27= 1.3.0 =
     28- feat: Add ability to provide custom paths and tags per post type from @MuhammedAO
     29- fix: prevent locales from being loaded too early @humet
    2730= 1.2.5 =
    2831- feat: prevent revalidate functions from running more than once within a single save_post request from @MuhammedAO
  • on-demand-revalidation/tags/1.3.0/src/Admin/Settings.php

    r3073849 r3280737  
    6969     */
    7070    public function register_settings() {
     71        $tag_desc = 'One tag per row.<br/><br/><i>Available current placeholders:</i><br/><code>%slug%</code> <code>%author_nicename%</code> <code>%author_username%</code> <code>%category%</code> <code>%post_tag%</code><code>%database_id%</code> <code>%id%</code> <code>%custom_taxonomy%</code><br/><br/><i>Note:</i> Replace <code>%custom_taxonomy%</code> with your custom taxonomy name.';
    7172
    7273        $this->settings_api->register_section(
     
    7475            array(
    7576                'title' => __( 'General', 'on-demand-revalidation' ),
    76             ) 
     77            )
    7778        );
    7879
     
    9091                    'type'  => 'password',
    9192                ),
    92             )
    93         );
    94 
    95         $this->settings_api->register_section(
    96             'on_demand_revalidation_post_update_settings',
    97             array(
    98                 'title' => __( 'On post update', 'on-demand-revalidation' ),
    99                 'desc'  => __( 'On post update is current page revalidated automatically.', 'on-demand-revalidation' ),
    100             )
    101         );
    102 
    103         $this->settings_api->register_fields(
    104             'on_demand_revalidation_post_update_settings',
    105             array(
    106                 array(
    107                     'name'    => 'revalidate_homepage',
    108                     'desc'    => __( 'Revalidate Homepage on post update', 'on-demand-revalidation' ),
    109                     'type'    => 'checkbox',
    110                     'default' => 'on',
    111                 ),
     93
    11294                array(
    11395                    'name' => 'disable_cron',
    11496                    'desc' => __( "<b>Disable scheduled revalidation.</b> Revalidation triggered immediately without using WP-Cron. It'll slow down post update.", 'on-demand-revalidation' ),
    11597                    'type' => 'checkbox',
    116                 ),
    117                 array(
    118                     'name'        => 'revalidate_paths',
    119                     'label'       => __( 'Additional paths to revalidate on Post update', 'on-demand-revalidation' ),
    120                     'desc'        => 'One path per row.',
    121                     'placeholder' => '/category/%category%',
    122                     'type'        => 'textarea',
    123                 ),
    124            
    125                 array(
    126                     'name'        => 'revalidate_tags',
    127                     'label'       => __( 'Tags to revalidate on Post update', 'on-demand-revalidation' ),
    128                     'desc'        => 'One tag per row.<br/><br/><i>Available current Post placeholders:</i><br/><code>%slug%</code> <code>%author_nicename%</code> <code>%author_username%</code> <code>%category%</code> <code>%post_tag%</code><code>%database_id%</code> <code>%id%</code> <code>%custom_taxonomy%</code><br/><br/><i>Note:</i> Replace <code>%custom_taxonomy%</code> with your custom taxonomy name.',
    129                     'placeholder' => '%databaseid%',
    130                     'type'        => 'textarea',
    13198                ),
    13299
     
    137104                    'type'  => 'html',
    138105                ),
    139             )
    140         );
     106            )
     107        );
     108
     109        $this->settings_api->register_section(
     110            'on_demand_revalidation_post_update_settings',
     111            array(
     112                'title' => __( 'All Settings', 'on-demand-revalidation' ),
     113                'desc'  => __( 'Revalidation settings for all post types.', 'on-demand-revalidation' ),
     114            )
     115        );
     116
     117        $this->settings_api->register_fields(
     118            'on_demand_revalidation_post_update_settings',
     119            array(
     120                array(
     121                    'name'    => 'revalidate_homepage',
     122                    'desc'    => __( 'Revalidate homepage on all post updates', 'on-demand-revalidation' ),
     123                    'type'    => 'checkbox',
     124                    'default' => 'on',
     125                ),
     126
     127                array(
     128                    'name'        => 'revalidate_paths',
     129                    'label'       => __( 'Paths to revalidate on all updates', 'on-demand-revalidation' ),
     130                    'desc'        => 'One path per row.',
     131                    'placeholder' => '/category/%category%',
     132                    'type'        => 'textarea',
     133                ),
     134
     135                array(
     136                    'name'        => 'revalidate_tags',
     137                    'label'       => __( 'Tags to revalidate on all updates', 'on-demand-revalidation' ),
     138                    'desc'        => $tag_desc,
     139                    'placeholder' => '%databaseid%',
     140                    'type'        => 'textarea',
     141                ),
     142
     143
     144            )
     145        );
     146
     147        $post_types = get_post_types( array( 'public' => true ), 'objects' );
     148        foreach ( $post_types as $post_type_obj ) {
     149
     150            if ( 'attachment' === $post_type_obj->name ) {
     151                continue;
     152            }
     153            $section_id = 'on_demand_revalidation_' . $post_type_obj->name . '_settings';
     154            $this->settings_api->register_section(
     155                $section_id,
     156                array(
     157                    // translators: %s: plural name of the post type, e.g. "Posts" or "Books".
     158                    'title' => sprintf( __( '%s Settings', 'on-demand-revalidation', ), $post_type_obj->labels->name ),
     159                    // translators: %s: singular name of the post type, e.g. "Post" or "Book".
     160                    'desc'  => sprintf( __( 'Revalidation settings specific to %s posts.', 'on-demand-revalidation', ), $post_type_obj->labels->singular_name ),
     161                )
     162            );
     163            $this->settings_api->register_fields(
     164                $section_id,
     165                array(
     166                    array(
     167                        'name'    => 'revalidate_enabled_' . $post_type_obj->name,
     168                        // translators: %s: singular post type name, used in the checkbox label.
     169                        'desc'    => sprintf( __( 'Enable revalidation for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     170                        'type'    => 'checkbox',
     171                        'default' => 'on',
     172                    ),
     173                    array(
     174                        'name'    => 'revalidate_homepage_' . $post_type_obj->name,
     175                        // translators: %s: singular post type name, used in the textarea label.
     176                        'desc'    => sprintf( __( 'Revalidate Homepage on all updates for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     177                        'type'    => 'checkbox',
     178                        'default' => 'on',
     179                    ),
     180                    array(
     181                        'name'        => 'revalidate_paths_' . $post_type_obj->name,
     182                        // translators: %s: singular post type name, used in the textarea label.
     183                        'label'       => sprintf( __( 'Additional paths for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     184                        'desc'        => __( 'One path per row. Leave empty if not applicable.', 'on-demand-revalidation' ),
     185                        'placeholder' => '/custom/path/$placeholder%/',
     186                        'type'        => 'textarea',
     187                    ),
     188                    array(
     189                        'name'        => 'revalidate_tags_' . $post_type_obj->name,
     190                        // translators: %s: singular post type name, used in the textarea label.
     191                        'label'       => sprintf( __( 'Tags for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     192                        'desc'        => $tag_desc,
     193                        'placeholder' => '%slug%',
     194                        'type'        => 'textarea',
     195                    ),
     196                )
     197            );
     198        }
    141199    }
    142200
  • on-demand-revalidation/tags/1.3.0/src/Revalidation.php

    r3225736 r3280737  
    4444            return;
    4545        }
    46        
     46
    4747        $old_permalink = get_permalink( $post_ID );
    4848        update_post_meta( $post_ID, '_old_permalink', $old_permalink );
     
    6666    public static function handle_save_post( $post_id, $post ) {
    6767        $excluded_statuses = array( 'auto-draft', 'inherit', 'draft', 'trash' );
    68        
     68
    6969        if ( isset( $post->post_status ) && in_array( $post->post_status, $excluded_statuses, true ) ) {
    7070            return;
    7171        }
    72        
     72
    7373        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    7474            return;
    7575        }
    76    
     76
    7777        if ( false !== wp_is_post_revision( $post_id ) ) {
    7878            return;
    7979        }
    8080
    81         if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    82             return;
    83         }
    84        
    8581        self::revalidate_post( $post );
    8682    }
     
    9995            self::revalidate_post( $post );
    10096        }
    101     }   
     97    }
    10298
    10399    /**
     
    129125        }
    130126
     127        $post_type = $post->post_type;
     128
     129        // Check if revalidation is enabled for this post type.
     130        $individual_toggle = Settings::get( 'revalidate_enabled_' . $post_type, 'on', 'on_demand_revalidation_' . $post_type . '_settings' );
     131        if ( 'on' !== $individual_toggle ) {
     132            return (object) array(
     133                'success' => false,
     134                // translators: %s: post type slug, e.g. "post" or "page".
     135                'message' => sprintf( __( 'Revalidation is disabled for %s.', 'on-demand-revalidation' ), $post_type ),
     136            );
     137        }
     138
    131139        $paths = array();
    132140
    133         if ( Settings::get( 'revalidate_homepage', 'on', 'on_demand_revalidation_post_update_settings' ) === 'on' ) {
     141        $individual_homepage = Settings::get( 'revalidate_homepage_' . $post_type, null, 'on_demand_revalidation_' . $post_type . '_settings' );
     142
     143        if ( null === $individual_homepage ) {
     144            // no per‑type override, use global.
     145            $home_enabled = (
     146                Settings::get(
     147                    'revalidate_homepage',
     148                    'on',
     149                    'on_demand_revalidation_post_update_settings'
     150                ) === 'on'
     151            );
     152        } else {
     153            // use per‑type setting.
     154            $home_enabled = ( 'on' === $individual_homepage );
     155        }
     156
     157        if ( $home_enabled ) {
    134158            $paths[] = '/';
    135159        }
     160
    136161
    137162        $post_permalink  = get_permalink( $post );
     
    148173        if ( ! empty( $old_permalink ) ) {
    149174            $parse_old_permalink = wp_parse_url( $old_permalink );
    150        
     175
    151176            if ( isset( $parse_old_permalink['path'] ) && '/' !== $parse_old_permalink['path'] ) {
    152177                $old_page_path = substr( $parse_old_permalink['path'], -1 ) === '/' ? substr( $parse_old_permalink['path'], 0, -1 ) : $parse_old_permalink['path'];
     
    158183
    159184        $revalidate_paths = trim( Settings::get( 'revalidate_paths', '', 'on_demand_revalidation_post_update_settings' ) );
    160        
     185
    161186        if ( ! empty( $revalidate_paths ) ) {
    162187            $revalidate_paths = preg_split( '/\r\n|\n|\r/', $revalidate_paths );
     
    181206        }
    182207
     208        // per‑post‑type additional paths.
     209        $post_type_raw_paths = Settings::get( 'revalidate_paths_' . $post_type, '', 'on_demand_revalidation_' . $post_type . '_settings' );
     210        if ( ! empty( $post_type_raw_paths ) ) {
     211            $post_type_defined_paths = preg_split( '/\r\n|\n|\r/', $post_type_raw_paths );
     212            $post_type_defined_paths = Helpers::rewrite_placeholders( $post_type_defined_paths, $post );
     213            foreach ( $post_type_defined_paths as $path ) {
     214                if ( str_starts_with( $path, '/' ) ) {
     215                    $paths[] = $path;
     216                }
     217            }
     218        }
     219
    183220        $paths = apply_filters( 'on_demand_revalidation_paths', $paths, $post );
    184         $tags  = apply_filters( 'on_demand_revalidation_tags', $tags, $post );
     221
     222
     223
     224            // per‑post‑type additional tags.
     225        $post_type_raw_tags = Settings::get( 'revalidate_tags_' . $post_type, '', 'on_demand_revalidation_' . $post_type . '_settings' );
     226        if ( ! empty( $post_type_raw_tags ) ) {
     227            $post_type_defined_tags = preg_split( '/\r\n|\n|\r/', $post_type_raw_tags );
     228            $post_type_defined_tags = Helpers::rewrite_placeholders( $post_type_defined_tags, $post );
     229            $tags                   = array_merge( $tags, $post_type_defined_tags );
     230        }
     231
     232        $tags = apply_filters( 'on_demand_revalidation_tags', $tags, $post );
    185233
    186234        $data = array(
    187235            'postId' => $post->ID,
    188236        );
    189    
     237
    190238        if ( ! empty( $paths ) ) {
    191239            $data['paths'] = $paths;
    192240        }
    193    
     241
    194242        if ( ! empty( $tags ) ) {
    195243            $data['tags'] = $tags;
     
    219267
    220268        if ( ! is_array( $response_data ) || ! isset( $response_data['revalidated'] ) ) {
    221             return new WP_Error( 
    222                 'revalidate_error', 
    223                 'Invalid response from revalidation endpoint', 
    224                 array( 'status' => 403 ) 
     269            return new WP_Error(
     270                'revalidate_error',
     271                'Invalid response from revalidation endpoint',
     272                array( 'status' => 403 )
    225273            );
    226274        }
  • on-demand-revalidation/tags/1.3.0/vendor/autoload.php

    r3073815 r3280737  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676::getLoader();
     25return ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53::getLoader();
  • on-demand-revalidation/tags/1.3.0/vendor/composer/InstalledVersions.php

    r3225736 r3280737  
    3232     */
    3333    private static $installed;
     34
     35    /**
     36     * @var bool
     37     */
     38    private static $installedIsLocalDir;
    3439
    3540    /**
     
    310315        self::$installed = $data;
    311316        self::$installedByVendor = array();
     317
     318        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     319        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     320        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     321        // all installed packages for example
     322        self::$installedIsLocalDir = false;
    312323    }
    313324
     
    326337
    327338        if (self::$canGetVendors) {
     339            $selfDir = strtr(__DIR__, '\\', '/');
    328340            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     341                $vendorDir = strtr($vendorDir, '\\', '/');
    329342                if (isset(self::$installedByVendor[$vendorDir])) {
    330343                    $installed[] = self::$installedByVendor[$vendorDir];
     
    334347                    self::$installedByVendor[$vendorDir] = $required;
    335348                    $installed[] = $required;
    336                     if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
     349                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
    337350                        self::$installed = $required;
    338                         $copiedLocalDir = true;
     351                        self::$installedIsLocalDir = true;
    339352                    }
     353                }
     354                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     355                    $copiedLocalDir = true;
    340356                }
    341357            }
  • on-demand-revalidation/tags/1.3.0/vendor/composer/autoload_real.php

    r3073815 r3280737  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676
     5class ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676', 'loadClassLoader'), true, true);
     25        require __DIR__ . '/platform_check.php';
     26
     27        spl_autoload_register(array('ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53', 'loadClassLoader'), true, true);
    2628        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53', 'loadClassLoader'));
    2830
    2931        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInit34bda8da618ea87a4aa4928738826a53::getInitializer($loader));
    3133
    3234        $loader->register(true);
  • on-demand-revalidation/tags/1.3.0/vendor/composer/autoload_static.php

    r3073815 r3280737  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitabe7fdb289c442ae5244023b8c11b676
     7class ComposerStaticInit34bda8da618ea87a4aa4928738826a53
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • on-demand-revalidation/tags/1.3.0/vendor/composer/installed.php

    r3225736 r3280737  
    11<?php return array(
    22    'root' => array(
    3         'name' => 'gdidentity/on-demand-revalidation',
    4         'pretty_version' => '1.2.5',
    5         'version' => '1.2.5.0',
    6         'reference' => null,
     3        'name' => 'dexerto/on-demand-revalidation',
     4        'pretty_version' => '1.3.0',
     5        'version' => '1.3.0.0',
     6        'reference' => 'f807a12333d6e0b83df7b801038e56859eae8a0b',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1111    ),
    1212    'versions' => array(
    13         'gdidentity/on-demand-revalidation' => array(
    14             'pretty_version' => '1.2.5',
    15             'version' => '1.2.5.0',
    16             'reference' => null,
     13        'dexerto/on-demand-revalidation' => array(
     14            'pretty_version' => '1.3.0',
     15            'version' => '1.3.0.0',
     16            'reference' => 'f807a12333d6e0b83df7b801038e56859eae8a0b',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • on-demand-revalidation/trunk/on-demand-revalidation.php

    r3225736 r3280737  
    77 * GitHub Plugin URI:   https://github.com/dexerto/on-demand-revalidation
    88 * Description:         Next.js On-Demand Revalidation on the post update, revalidate specific paths, tags on the post update.
    9  * Version:             1.2.5
     9 * Version:             1.3.0
    1010 * Author:              Dexerto
    1111 * Author URI:          https://dexerto.com
     
    1313 * License:             GPL-3
    1414 * License URI:         https://www.gnu.org/licenses/gpl-3.0.html
    15  * 
     15 *
    1616 * @package OnDemandRevalidation
    1717 */
     
    5555                    self::$instance->revalidation();
    5656                    self::$instance->plugin_links();
     57                    self::$instance->load_textdomain();
    5758
    5859                    \OnDemandRevalidation\Helpers::prevent_wrong_api_url();
     
    122123            // Plugin version.
    123124            if ( ! defined( 'ON_DEMAND_REVALIDATION_VERSION' ) ) {
    124                 define( 'ON_DEMAND_REVALIDATION_VERSION', get_plugin_data( __FILE__ )['Version'] );
     125                $plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ) );
     126                define( 'ON_DEMAND_REVALIDATION_VERSION', $plugin_data['Version'] );
    125127            }
    126128
     
    226228            );
    227229        }
     230
     231        /**
     232         * Load plugin text domain.
     233         *
     234         * @since 1.3.0
     235         */
     236        private function load_textdomain(): void {
     237            add_action(
     238                'init',
     239                function () {
     240                    load_plugin_textdomain( 'on-demand-revalidation', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     241                }
     242            );
     243        }
    228244    }
    229245
  • on-demand-revalidation/trunk/readme.txt

    r3225736 r3280737  
    22Contributors: bebjakub
    33Tags: nextjs, ssg, revalidation, on-demand
    4 Requires at least: 4.7
    5 Tested up to: 6.7.1
    6 Stable tag: 1.2.5
     4Requires at least: 6.0.0
     5Tested up to: 6.7.2
     6Stable tag: 1.3.0
    77Requires PHP: 8.0
    88License: GPL-3
     
    1111=== Description ===
    1212
    13 Next.js On-Demand Revalidation for Wordpress on the post update, revalidate specific paths and tags on the post update.
     13Next.js On-Demand Revalidation for Wordpress on post updates, revalidate specific paths and tags on post updates.
    1414
    1515Feel free to create a PR to [plugin Github repo](https://github.com/Dexerto/on-demand-revalidation).
     
    2525
    2626== Changelog ==
     27= 1.3.0 =
     28- feat: Add ability to provide custom paths and tags per post type from @MuhammedAO
     29- fix: prevent locales from being loaded too early @humet
    2730= 1.2.5 =
    2831- feat: prevent revalidate functions from running more than once within a single save_post request from @MuhammedAO
  • on-demand-revalidation/trunk/src/Admin/Settings.php

    r3073849 r3280737  
    6969     */
    7070    public function register_settings() {
     71        $tag_desc = 'One tag per row.<br/><br/><i>Available current placeholders:</i><br/><code>%slug%</code> <code>%author_nicename%</code> <code>%author_username%</code> <code>%category%</code> <code>%post_tag%</code><code>%database_id%</code> <code>%id%</code> <code>%custom_taxonomy%</code><br/><br/><i>Note:</i> Replace <code>%custom_taxonomy%</code> with your custom taxonomy name.';
    7172
    7273        $this->settings_api->register_section(
     
    7475            array(
    7576                'title' => __( 'General', 'on-demand-revalidation' ),
    76             ) 
     77            )
    7778        );
    7879
     
    9091                    'type'  => 'password',
    9192                ),
    92             )
    93         );
    94 
    95         $this->settings_api->register_section(
    96             'on_demand_revalidation_post_update_settings',
    97             array(
    98                 'title' => __( 'On post update', 'on-demand-revalidation' ),
    99                 'desc'  => __( 'On post update is current page revalidated automatically.', 'on-demand-revalidation' ),
    100             )
    101         );
    102 
    103         $this->settings_api->register_fields(
    104             'on_demand_revalidation_post_update_settings',
    105             array(
    106                 array(
    107                     'name'    => 'revalidate_homepage',
    108                     'desc'    => __( 'Revalidate Homepage on post update', 'on-demand-revalidation' ),
    109                     'type'    => 'checkbox',
    110                     'default' => 'on',
    111                 ),
     93
    11294                array(
    11395                    'name' => 'disable_cron',
    11496                    'desc' => __( "<b>Disable scheduled revalidation.</b> Revalidation triggered immediately without using WP-Cron. It'll slow down post update.", 'on-demand-revalidation' ),
    11597                    'type' => 'checkbox',
    116                 ),
    117                 array(
    118                     'name'        => 'revalidate_paths',
    119                     'label'       => __( 'Additional paths to revalidate on Post update', 'on-demand-revalidation' ),
    120                     'desc'        => 'One path per row.',
    121                     'placeholder' => '/category/%category%',
    122                     'type'        => 'textarea',
    123                 ),
    124            
    125                 array(
    126                     'name'        => 'revalidate_tags',
    127                     'label'       => __( 'Tags to revalidate on Post update', 'on-demand-revalidation' ),
    128                     'desc'        => 'One tag per row.<br/><br/><i>Available current Post placeholders:</i><br/><code>%slug%</code> <code>%author_nicename%</code> <code>%author_username%</code> <code>%category%</code> <code>%post_tag%</code><code>%database_id%</code> <code>%id%</code> <code>%custom_taxonomy%</code><br/><br/><i>Note:</i> Replace <code>%custom_taxonomy%</code> with your custom taxonomy name.',
    129                     'placeholder' => '%databaseid%',
    130                     'type'        => 'textarea',
    13198                ),
    13299
     
    137104                    'type'  => 'html',
    138105                ),
    139             )
    140         );
     106            )
     107        );
     108
     109        $this->settings_api->register_section(
     110            'on_demand_revalidation_post_update_settings',
     111            array(
     112                'title' => __( 'All Settings', 'on-demand-revalidation' ),
     113                'desc'  => __( 'Revalidation settings for all post types.', 'on-demand-revalidation' ),
     114            )
     115        );
     116
     117        $this->settings_api->register_fields(
     118            'on_demand_revalidation_post_update_settings',
     119            array(
     120                array(
     121                    'name'    => 'revalidate_homepage',
     122                    'desc'    => __( 'Revalidate homepage on all post updates', 'on-demand-revalidation' ),
     123                    'type'    => 'checkbox',
     124                    'default' => 'on',
     125                ),
     126
     127                array(
     128                    'name'        => 'revalidate_paths',
     129                    'label'       => __( 'Paths to revalidate on all updates', 'on-demand-revalidation' ),
     130                    'desc'        => 'One path per row.',
     131                    'placeholder' => '/category/%category%',
     132                    'type'        => 'textarea',
     133                ),
     134
     135                array(
     136                    'name'        => 'revalidate_tags',
     137                    'label'       => __( 'Tags to revalidate on all updates', 'on-demand-revalidation' ),
     138                    'desc'        => $tag_desc,
     139                    'placeholder' => '%databaseid%',
     140                    'type'        => 'textarea',
     141                ),
     142
     143
     144            )
     145        );
     146
     147        $post_types = get_post_types( array( 'public' => true ), 'objects' );
     148        foreach ( $post_types as $post_type_obj ) {
     149
     150            if ( 'attachment' === $post_type_obj->name ) {
     151                continue;
     152            }
     153            $section_id = 'on_demand_revalidation_' . $post_type_obj->name . '_settings';
     154            $this->settings_api->register_section(
     155                $section_id,
     156                array(
     157                    // translators: %s: plural name of the post type, e.g. "Posts" or "Books".
     158                    'title' => sprintf( __( '%s Settings', 'on-demand-revalidation', ), $post_type_obj->labels->name ),
     159                    // translators: %s: singular name of the post type, e.g. "Post" or "Book".
     160                    'desc'  => sprintf( __( 'Revalidation settings specific to %s posts.', 'on-demand-revalidation', ), $post_type_obj->labels->singular_name ),
     161                )
     162            );
     163            $this->settings_api->register_fields(
     164                $section_id,
     165                array(
     166                    array(
     167                        'name'    => 'revalidate_enabled_' . $post_type_obj->name,
     168                        // translators: %s: singular post type name, used in the checkbox label.
     169                        'desc'    => sprintf( __( 'Enable revalidation for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     170                        'type'    => 'checkbox',
     171                        'default' => 'on',
     172                    ),
     173                    array(
     174                        'name'    => 'revalidate_homepage_' . $post_type_obj->name,
     175                        // translators: %s: singular post type name, used in the textarea label.
     176                        'desc'    => sprintf( __( 'Revalidate Homepage on all updates for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     177                        'type'    => 'checkbox',
     178                        'default' => 'on',
     179                    ),
     180                    array(
     181                        'name'        => 'revalidate_paths_' . $post_type_obj->name,
     182                        // translators: %s: singular post type name, used in the textarea label.
     183                        'label'       => sprintf( __( 'Additional paths for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     184                        'desc'        => __( 'One path per row. Leave empty if not applicable.', 'on-demand-revalidation' ),
     185                        'placeholder' => '/custom/path/$placeholder%/',
     186                        'type'        => 'textarea',
     187                    ),
     188                    array(
     189                        'name'        => 'revalidate_tags_' . $post_type_obj->name,
     190                        // translators: %s: singular post type name, used in the textarea label.
     191                        'label'       => sprintf( __( 'Tags for %s', 'on-demand-revalidation' ), $post_type_obj->labels->singular_name ),
     192                        'desc'        => $tag_desc,
     193                        'placeholder' => '%slug%',
     194                        'type'        => 'textarea',
     195                    ),
     196                )
     197            );
     198        }
    141199    }
    142200
  • on-demand-revalidation/trunk/src/Revalidation.php

    r3225736 r3280737  
    4444            return;
    4545        }
    46        
     46
    4747        $old_permalink = get_permalink( $post_ID );
    4848        update_post_meta( $post_ID, '_old_permalink', $old_permalink );
     
    6666    public static function handle_save_post( $post_id, $post ) {
    6767        $excluded_statuses = array( 'auto-draft', 'inherit', 'draft', 'trash' );
    68        
     68
    6969        if ( isset( $post->post_status ) && in_array( $post->post_status, $excluded_statuses, true ) ) {
    7070            return;
    7171        }
    72        
     72
    7373        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
    7474            return;
    7575        }
    76    
     76
    7777        if ( false !== wp_is_post_revision( $post_id ) ) {
    7878            return;
    7979        }
    8080
    81         if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
    82             return;
    83         }
    84        
    8581        self::revalidate_post( $post );
    8682    }
     
    9995            self::revalidate_post( $post );
    10096        }
    101     }   
     97    }
    10298
    10399    /**
     
    129125        }
    130126
     127        $post_type = $post->post_type;
     128
     129        // Check if revalidation is enabled for this post type.
     130        $individual_toggle = Settings::get( 'revalidate_enabled_' . $post_type, 'on', 'on_demand_revalidation_' . $post_type . '_settings' );
     131        if ( 'on' !== $individual_toggle ) {
     132            return (object) array(
     133                'success' => false,
     134                // translators: %s: post type slug, e.g. "post" or "page".
     135                'message' => sprintf( __( 'Revalidation is disabled for %s.', 'on-demand-revalidation' ), $post_type ),
     136            );
     137        }
     138
    131139        $paths = array();
    132140
    133         if ( Settings::get( 'revalidate_homepage', 'on', 'on_demand_revalidation_post_update_settings' ) === 'on' ) {
     141        $individual_homepage = Settings::get( 'revalidate_homepage_' . $post_type, null, 'on_demand_revalidation_' . $post_type . '_settings' );
     142
     143        if ( null === $individual_homepage ) {
     144            // no per‑type override, use global.
     145            $home_enabled = (
     146                Settings::get(
     147                    'revalidate_homepage',
     148                    'on',
     149                    'on_demand_revalidation_post_update_settings'
     150                ) === 'on'
     151            );
     152        } else {
     153            // use per‑type setting.
     154            $home_enabled = ( 'on' === $individual_homepage );
     155        }
     156
     157        if ( $home_enabled ) {
    134158            $paths[] = '/';
    135159        }
     160
    136161
    137162        $post_permalink  = get_permalink( $post );
     
    148173        if ( ! empty( $old_permalink ) ) {
    149174            $parse_old_permalink = wp_parse_url( $old_permalink );
    150        
     175
    151176            if ( isset( $parse_old_permalink['path'] ) && '/' !== $parse_old_permalink['path'] ) {
    152177                $old_page_path = substr( $parse_old_permalink['path'], -1 ) === '/' ? substr( $parse_old_permalink['path'], 0, -1 ) : $parse_old_permalink['path'];
     
    158183
    159184        $revalidate_paths = trim( Settings::get( 'revalidate_paths', '', 'on_demand_revalidation_post_update_settings' ) );
    160        
     185
    161186        if ( ! empty( $revalidate_paths ) ) {
    162187            $revalidate_paths = preg_split( '/\r\n|\n|\r/', $revalidate_paths );
     
    181206        }
    182207
     208        // per‑post‑type additional paths.
     209        $post_type_raw_paths = Settings::get( 'revalidate_paths_' . $post_type, '', 'on_demand_revalidation_' . $post_type . '_settings' );
     210        if ( ! empty( $post_type_raw_paths ) ) {
     211            $post_type_defined_paths = preg_split( '/\r\n|\n|\r/', $post_type_raw_paths );
     212            $post_type_defined_paths = Helpers::rewrite_placeholders( $post_type_defined_paths, $post );
     213            foreach ( $post_type_defined_paths as $path ) {
     214                if ( str_starts_with( $path, '/' ) ) {
     215                    $paths[] = $path;
     216                }
     217            }
     218        }
     219
    183220        $paths = apply_filters( 'on_demand_revalidation_paths', $paths, $post );
    184         $tags  = apply_filters( 'on_demand_revalidation_tags', $tags, $post );
     221
     222
     223
     224            // per‑post‑type additional tags.
     225        $post_type_raw_tags = Settings::get( 'revalidate_tags_' . $post_type, '', 'on_demand_revalidation_' . $post_type . '_settings' );
     226        if ( ! empty( $post_type_raw_tags ) ) {
     227            $post_type_defined_tags = preg_split( '/\r\n|\n|\r/', $post_type_raw_tags );
     228            $post_type_defined_tags = Helpers::rewrite_placeholders( $post_type_defined_tags, $post );
     229            $tags                   = array_merge( $tags, $post_type_defined_tags );
     230        }
     231
     232        $tags = apply_filters( 'on_demand_revalidation_tags', $tags, $post );
    185233
    186234        $data = array(
    187235            'postId' => $post->ID,
    188236        );
    189    
     237
    190238        if ( ! empty( $paths ) ) {
    191239            $data['paths'] = $paths;
    192240        }
    193    
     241
    194242        if ( ! empty( $tags ) ) {
    195243            $data['tags'] = $tags;
     
    219267
    220268        if ( ! is_array( $response_data ) || ! isset( $response_data['revalidated'] ) ) {
    221             return new WP_Error( 
    222                 'revalidate_error', 
    223                 'Invalid response from revalidation endpoint', 
    224                 array( 'status' => 403 ) 
     269            return new WP_Error(
     270                'revalidate_error',
     271                'Invalid response from revalidation endpoint',
     272                array( 'status' => 403 )
    225273            );
    226274        }
  • on-demand-revalidation/trunk/vendor/autoload.php

    r3073815 r3280737  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676::getLoader();
     25return ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53::getLoader();
  • on-demand-revalidation/trunk/vendor/composer/InstalledVersions.php

    r3225736 r3280737  
    3232     */
    3333    private static $installed;
     34
     35    /**
     36     * @var bool
     37     */
     38    private static $installedIsLocalDir;
    3439
    3540    /**
     
    310315        self::$installed = $data;
    311316        self::$installedByVendor = array();
     317
     318        // when using reload, we disable the duplicate protection to ensure that self::$installed data is
     319        // always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
     320        // so we have to assume it does not, and that may result in duplicate data being returned when listing
     321        // all installed packages for example
     322        self::$installedIsLocalDir = false;
    312323    }
    313324
     
    326337
    327338        if (self::$canGetVendors) {
     339            $selfDir = strtr(__DIR__, '\\', '/');
    328340            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
     341                $vendorDir = strtr($vendorDir, '\\', '/');
    329342                if (isset(self::$installedByVendor[$vendorDir])) {
    330343                    $installed[] = self::$installedByVendor[$vendorDir];
     
    334347                    self::$installedByVendor[$vendorDir] = $required;
    335348                    $installed[] = $required;
    336                     if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
     349                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
    337350                        self::$installed = $required;
    338                         $copiedLocalDir = true;
     351                        self::$installedIsLocalDir = true;
    339352                    }
     353                }
     354                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
     355                    $copiedLocalDir = true;
    340356                }
    341357            }
  • on-demand-revalidation/trunk/vendor/composer/autoload_real.php

    r3073815 r3280737  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676
     5class ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676', 'loadClassLoader'), true, true);
     25        require __DIR__ . '/platform_check.php';
     26
     27        spl_autoload_register(array('ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53', 'loadClassLoader'), true, true);
    2628        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitabe7fdb289c442ae5244023b8c11b676', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInit34bda8da618ea87a4aa4928738826a53', 'loadClassLoader'));
    2830
    2931        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInit34bda8da618ea87a4aa4928738826a53::getInitializer($loader));
    3133
    3234        $loader->register(true);
  • on-demand-revalidation/trunk/vendor/composer/autoload_static.php

    r3073815 r3280737  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitabe7fdb289c442ae5244023b8c11b676
     7class ComposerStaticInit34bda8da618ea87a4aa4928738826a53
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticInitabe7fdb289c442ae5244023b8c11b676::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInit34bda8da618ea87a4aa4928738826a53::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • on-demand-revalidation/trunk/vendor/composer/installed.php

    r3225736 r3280737  
    11<?php return array(
    22    'root' => array(
    3         'name' => 'gdidentity/on-demand-revalidation',
    4         'pretty_version' => '1.2.5',
    5         'version' => '1.2.5.0',
    6         'reference' => null,
     3        'name' => 'dexerto/on-demand-revalidation',
     4        'pretty_version' => '1.3.0',
     5        'version' => '1.3.0.0',
     6        'reference' => 'f807a12333d6e0b83df7b801038e56859eae8a0b',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1111    ),
    1212    'versions' => array(
    13         'gdidentity/on-demand-revalidation' => array(
    14             'pretty_version' => '1.2.5',
    15             'version' => '1.2.5.0',
    16             'reference' => null,
     13        'dexerto/on-demand-revalidation' => array(
     14            'pretty_version' => '1.3.0',
     15            'version' => '1.3.0.0',
     16            'reference' => 'f807a12333d6e0b83df7b801038e56859eae8a0b',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.