Plugin Directory

Changeset 3213676


Ignore:
Timestamp:
12/27/2024 08:48:27 AM (15 months ago)
Author:
akrocks
Message:

Update to version 2.3.0 from GitHub

Location:
nginx-helper
Files:
2 added
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • nginx-helper/tags/2.3.0/admin/class-fastcgi-purger.php

    r3071366 r3213676  
    9191
    9292        }
    93 
     93       
     94        if( ( is_page() || is_single() ) && $nginx_helper_admin->options['purge_amp_urls'] ) {
     95            $this->purge_amp_version( $url );
     96        }
     97
     98    }
     99   
     100    /**
     101     * Purge AMP version of a URL.
     102     *
     103     * @param string $url_base The base URL to purge.
     104     */
     105    private function purge_amp_version( $url_base ) {
     106        $amp_url = sprintf( '%s/amp/', rtrim( $url_base, '/' ) );
     107       
     108        $this->log( '- Purging AMP URL | ' . $amp_url );
     109       
     110        if ( 'unlink_files' === $this->nginx_helper_admin->options['purge_method'] ) {
     111            $this->delete_cache_file_for( $amp_url );
     112        } else {
     113            $this->do_remote_get( $amp_url );
     114        }
    94115    }
    95116
  • nginx-helper/tags/2.3.0/admin/class-nginx-helper-admin.php

    r3071366 r3213676  
    2121 */
    2222class Nginx_Helper_Admin {
    23 
     23   
    2424    /**
    2525     * The ID of this plugin.
     
    3030     */
    3131    private $plugin_name;
    32 
     32   
    3333    /**
    3434     * The version of this plugin.
     
    3939     */
    4040    private $version;
    41 
     41   
    4242    /**
    4343     * Various settings tabs.
     
    4848     */
    4949    private $settings_tabs;
    50 
     50   
    5151    /**
    5252     * Purge options.
     
    5757     */
    5858    public $options;
    59 
     59   
    6060    /**
    6161     * WP-CLI Command.
     
    6666     */
    6767    const WP_CLI_COMMAND = 'nginx-helper';
    68 
     68   
    6969    /**
    7070     * Initialize the class and set its properties.
     
    7575     */
    7676    public function __construct( $plugin_name, $version ) {
    77 
     77       
    7878        $this->plugin_name = $plugin_name;
    7979        $this->version     = $version;
    80 
     80       
     81        $this->options = $this->nginx_helper_settings();
     82    }
     83   
     84    /**
     85     * Initialize the settings tab.
     86     * Required since i18n is used in the settings tab which can be invoked only after init hook since WordPress 6.7
     87     */
     88    public function initialize_setting_tab() {
     89       
    8190        /**
    8291         * Define settings tabs
     
    95104            )
    96105        );
    97 
    98         $this->options = $this->nginx_helper_settings();
    99 
    100     }
    101 
     106    }
     107   
    102108    /**
    103109     * Register the stylesheets for the admin area.
     
    108114     */
    109115    public function enqueue_styles( $hook ) {
    110 
     116       
    111117        /**
    112118         * This function is provided for demonstration purposes only.
     
    120126         * class.
    121127         */
    122 
     128       
    123129        if ( 'settings_page_nginx' !== $hook ) {
    124130            return;
    125131        }
    126 
     132       
    127133        wp_enqueue_style( $this->plugin_name . '-icons', plugin_dir_url( __FILE__ ) . 'icons/css/nginx-fontello.css', array(), $this->version, 'all' );
    128134        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/nginx-helper-admin.css', array(), $this->version, 'all' );
    129 
    130     }
    131 
     135       
     136    }
     137   
    132138    /**
    133139     * Register the JavaScript for the admin area.
     
    138144     */
    139145    public function enqueue_scripts( $hook ) {
    140 
     146       
    141147        /**
    142148         * This function is provided for demonstration purposes only.
     
    150156         * class.
    151157         */
    152 
     158       
    153159        if ( 'settings_page_nginx' !== $hook ) {
    154160            return;
    155161        }
    156 
     162       
    157163        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/nginx-helper-admin.js', array( 'jquery' ), $this->version, false );
    158 
     164       
    159165        $do_localize = array(
    160166            'purge_confirm_string' => esc_html__( 'Purging entire cache is not recommended. Would you like to continue?', 'nginx-helper' ),
    161167        );
    162168        wp_localize_script( $this->plugin_name, 'nginx_helper', $do_localize );
    163 
    164     }
    165 
     169       
     170    }
     171   
    166172    /**
    167173     * Add admin menu.
     
    170176     */
    171177    public function nginx_helper_admin_menu() {
    172 
     178       
    173179        if ( is_multisite() ) {
    174 
     180           
    175181            add_submenu_page(
    176182                'settings.php',
     
    181187                array( &$this, 'nginx_helper_setting_page' )
    182188            );
    183 
     189           
    184190        } else {
    185 
     191           
    186192            add_submenu_page(
    187193                'options-general.php',
     
    192198                array( &$this, 'nginx_helper_setting_page' )
    193199            );
    194 
    195         }
    196 
    197     }
    198 
     200           
     201        }
     202       
     203    }
     204   
    199205    /**
    200206     * Function to add toolbar purge link.
     
    203209     */
    204210    public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
    205 
     211       
    206212        if ( ! current_user_can( 'manage_options' ) ) {
    207213            return;
    208214        }
    209 
     215       
    210216        if ( is_admin() ) {
    211217            $nginx_helper_urls = 'all';
     
    215221            $link_title        = __( 'Purge Current Page', 'nginx-helper' );
    216222        }
    217 
     223       
    218224        $purge_url = add_query_arg(
    219225            array(
     
    222228            )
    223229        );
    224 
     230       
    225231        $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
    226 
     232       
    227233        $wp_admin_bar->add_menu(
    228234            array(
     
    233239            )
    234240        );
    235 
    236     }
    237 
     241       
     242    }
     243   
    238244    /**
    239245     * Display settings.
     
    246252        include plugin_dir_path( __FILE__ ) . 'partials/nginx-helper-admin-display.php';
    247253    }
    248 
     254   
    249255    /**
    250256     * Default settings.
     
    254260     */
    255261    public function nginx_helper_default_settings() {
    256 
     262       
    257263        return array(
    258264            'enable_purge'                     => 0,
     
    276282            'redis_hostname'                   => '127.0.0.1',
    277283            'redis_port'                       => '6379',
    278             'redis_prefix'                     => 'nginx-cache:',
     284            'redis_prefix'                      => 'nginx-cache:',
     285            'redis_unix_socket'                => '',
     286            'redis_database'                   => 0,
     287            'redis_username'                   => '',
     288            'redis_password'                   => '',
    279289            'purge_url'                        => '',
    280290            'redis_enabled_by_constant'        => 0,
     291            'purge_amp_urls'                   => 1,
     292            'redis_socket_enabled_by_constant' => 0,
     293            'redis_acl_enabled_by_constant'    => 0,
     294            'preload_cache'                    => 0,
     295            'is_cache_preloaded'               => 0
    281296        );
     297       
     298    }
     299   
     300    public function store_default_options() {
     301        $options = get_site_option( 'rt_wp_nginx_helper_options', array() );
     302        $default_settings = $this->nginx_helper_default_settings();
     303       
     304        $removable_default_settings = array(
     305            'redis_port',
     306            'redis_prefix',
     307            'redis_hostname',
     308            'redis_database',
     309            'redis_unix_socket'
     310        );
     311       
     312        // Remove all the keys that are not to be stored by default.
     313        foreach ( $removable_default_settings as $removable_key ) {
     314            unset( $default_settings[ $removable_key ] );
     315        }
     316       
     317        $diffed_options = wp_parse_args( $options, $default_settings );
     318       
     319        add_site_option( 'rt_wp_nginx_helper_options', $diffed_options );
     320    }
    282321
    283     }
    284 
    285322    /**
    286323     * Get settings.
     
    289326     */
    290327    public function nginx_helper_settings() {
    291 
     328       
    292329        $options = get_site_option(
    293330            'rt_wp_nginx_helper_options',
     
    296333                'redis_port'     => '6379',
    297334                'redis_prefix'   => 'nginx-cache:',
     335                'redis_database' => 0,
    298336            )
    299337        );
    300 
     338       
    301339        $data = wp_parse_args(
    302340            $options,
    303341            $this->nginx_helper_default_settings()
    304342        );
    305 
     343       
    306344        $is_redis_enabled = (
    307345            defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) &&
     
    309347            defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' )
    310348        );
     349       
     350        $data['redis_acl_enabled_by_constant']    = defined('RT_WP_NGINX_HELPER_REDIS_USERNAME') && defined('RT_WP_NGINX_HELPER_REDIS_PASSWORD');
     351        $data['redis_socket_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET');
     352        $data['redis_unix_socket']                = $data['redis_socket_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET : $data['redis_unix_socket'];
     353        $data['redis_username']                   = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_USERNAME : $data['redis_username'];
     354        $data['redis_password']                   = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_PASSWORD : $data['redis_password'];
    311355
    312356        if ( ! $is_redis_enabled ) {
     
    314358        }
    315359
    316         $data['redis_enabled_by_constant'] = $is_redis_enabled;
    317         $data['enable_purge']              = $is_redis_enabled;
    318         $data['cache_method']              = 'enable_redis';
    319         $data['redis_hostname']            = RT_WP_NGINX_HELPER_REDIS_HOSTNAME;
    320         $data['redis_port']                = RT_WP_NGINX_HELPER_REDIS_PORT;
    321         $data['redis_prefix']              = RT_WP_NGINX_HELPER_REDIS_PREFIX;
     360        $data['redis_enabled_by_constant']        = $is_redis_enabled;
     361        $data['enable_purge']                     = $is_redis_enabled;
     362        $data['cache_method']                     = 'enable_redis';
     363        $data['redis_hostname']                   = RT_WP_NGINX_HELPER_REDIS_HOSTNAME;
     364        $data['redis_port']                       = RT_WP_NGINX_HELPER_REDIS_PORT;
     365        $data['redis_prefix']                      = RT_WP_NGINX_HELPER_REDIS_PREFIX;
     366        $data['redis_database']                   = defined('RT_WP_NGINX_HELPER_REDIS_DATABASE') ? RT_WP_NGINX_HELPER_REDIS_DATABASE : 0;
    322367
    323368        return $data;
    324 
    325     }
    326 
     369       
     370    }
     371   
    327372    /**
    328373     * Nginx helper setting link function.
     
    333378     */
    334379    public function nginx_helper_settings_link( $links ) {
    335 
     380       
    336381        if ( is_network_admin() ) {
    337382            $setting_page = 'settings.php';
     
    339384            $setting_page = 'options-general.php';
    340385        }
    341 
     386       
    342387        $settings_link = '<a href="' . network_admin_url( $setting_page . '?page=nginx' ) . '">' . __( 'Settings', 'nginx-helper' ) . '</a>';
    343388        array_unshift( $links, $settings_link );
    344 
     389       
    345390        return $links;
    346 
    347     }
    348 
     391       
     392    }
     393   
    349394    /**
    350395     * Check if the nginx log is enabled.
     
    354399     */
    355400    public function is_nginx_log_enabled() {
    356 
     401       
    357402        $options = get_site_option( 'rt_wp_nginx_helper_options', array() );
    358 
     403       
    359404        if ( ! empty( $options['enable_log'] ) && 1 === (int) $options['enable_log'] ) {
    360405            return true;
    361406        }
    362 
     407       
    363408        if ( defined( 'NGINX_HELPER_LOG' ) && true === NGINX_HELPER_LOG ) {
    364409            return true;
    365410        }
    366 
     411       
    367412        return false;
    368413    }
    369 
     414   
    370415    /**
    371416     * Retrieve the asset path.
     
    375420     */
    376421    public function functional_asset_path() {
    377 
     422       
    378423        $log_path = WP_CONTENT_DIR . '/uploads/nginx-helper/';
    379 
     424       
    380425        return apply_filters( 'nginx_asset_path', $log_path );
    381 
    382     }
    383 
     426       
     427    }
     428   
    384429    /**
    385430     * Retrieve the asset url.
     
    389434     */
    390435    public function functional_asset_url() {
    391 
     436       
    392437        $log_url = WP_CONTENT_URL . '/uploads/nginx-helper/';
    393 
     438       
    394439        return apply_filters( 'nginx_asset_url', $log_url );
    395 
    396     }
    397 
     440       
     441    }
     442   
    398443    /**
    399444     * Get latest news.
     
    402447     */
    403448    public function nginx_helper_get_feeds() {
    404 
     449       
    405450        // Get RSS Feed(s).
    406451        require_once ABSPATH . WPINC . '/feed.php';
    407 
     452       
    408453        $maxitems  = 0;
    409454        $rss_items = array();
    410 
     455       
    411456        // Get a SimplePie feed object from the specified feed source.
    412457        $rss = fetch_feed( 'https://rtcamp.com/blog/feed/' );
    413 
     458       
    414459        if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly.
    415 
     460           
    416461            // Figure out how many total items there are, but limit it to 5.
    417462            $maxitems = $rss->get_item_quantity( 5 );
    418463            // Build an array of all the items, starting with element 0 (first element).
    419464            $rss_items = $rss->get_items( 0, $maxitems );
    420 
     465           
    421466        }
    422467        ?>
     
    426471                echo '<li role="listitem">' . esc_html_e( 'No items', 'nginx-helper' ) . '.</li>';
    427472            } else {
    428 
     473               
    429474                // Loop through each feed item and display each item as a hyperlink.
    430475                foreach ( $rss_items as $item ) {
    431476                    ?>
    432                         <li role="listitem">
    433                             <?php
    434                                 printf(
    435                                     '<a href="%s" title="%s">%s</a>',
    436                                     esc_url( $item->get_permalink() ),
    437                                     esc_attr__( 'Posted ', 'nginx-helper' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ),
    438                                     esc_html( $item->get_title() )
    439                                 );
    440                             ?>
    441                         </li>
     477                    <li role="listitem">
     478                        <?php
     479                        printf(
     480                            '<a href="%s" title="%s">%s</a>',
     481                            esc_url( $item->get_permalink() ),
     482                            esc_attr__( 'Posted ', 'nginx-helper' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ),
     483                            esc_html( $item->get_title() )
     484                        );
     485                        ?>
     486                    </li>
    442487                    <?php
    443488                }
     
    447492        <?php
    448493        die();
    449 
    450     }
    451 
     494       
     495    }
     496   
    452497    /**
    453498     * Add time stamps in html.
    454499     */
    455500    public function add_timestamps() {
    456 
     501       
    457502        global $pagenow;
    458 
     503       
    459504        if ( is_admin() || 1 !== (int) $this->options['enable_purge'] || 1 !== (int) $this->options['enable_stamp'] ) {
    460505            return;
    461506        }
    462 
     507       
    463508        if ( ! empty( $pagenow ) && 'wp-login.php' === $pagenow ) {
    464509            return;
    465510        }
    466 
     511       
    467512        foreach ( headers_list() as $header ) {
    468513            list( $key, $value ) = explode( ':', $header, 2 );
     
    475520            }
    476521        }
    477 
     522       
    478523        /**
    479524         * Don't add timestamp if run from ajax, cron or wpcli.
     
    482527            return;
    483528        }
    484 
     529       
    485530        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    486531            return;
    487532        }
    488 
     533       
    489534        if ( defined( 'WP_CLI' ) && WP_CLI ) {
    490535            return;
    491536        }
    492 
     537       
    493538        $timestamps = "\n<!--" .
    494                 'Cached using Nginx-Helper on ' . current_time( 'mysql' ) . '. ' .
    495                 'It took ' . get_num_queries() . ' queries executed in ' . timer_stop() . ' seconds.' .
    496                 "-->\n" .
    497                 '<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->';
    498 
     539            'Cached using Nginx-Helper on ' . current_time( 'mysql' ) . '. ' .
     540            'It took ' . get_num_queries() . ' queries executed in ' . timer_stop() . ' seconds.' .
     541            "-->\n" .
     542            '<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->';
     543       
    499544        echo wp_kses( $timestamps, array() );
    500 
    501     }
    502 
     545       
     546    }
     547   
    503548    /**
    504549     * Get map
     
    509554     */
    510555    public function get_map() {
    511 
     556       
    512557        if ( ! $this->options['enable_map'] ) {
    513558            return;
    514559        }
    515 
     560       
    516561        if ( is_multisite() ) {
    517 
     562           
    518563            global $wpdb;
    519 
     564           
    520565            $rt_all_blogs = $wpdb->get_results(
    521566                $wpdb->prepare(
     
    524569                )
    525570            );
    526 
     571           
    527572            $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
    528 
     573           
    529574            $rt_domain_map_sites = '';
    530 
     575           
    531576            if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->dmtable}'" ) === $wpdb->dmtable ) { // phpcs:ignore
    532577                $rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
    533578            }
    534 
     579           
    535580            $rt_nginx_map       = '';
    536581            $rt_nginx_map_array = array();
    537 
     582           
    538583            if ( $rt_all_blogs ) {
    539 
     584               
    540585                foreach ( $rt_all_blogs as $blog ) {
    541 
     586                   
    542587                    if ( true === SUBDOMAIN_INSTALL ) {
    543588                        $rt_nginx_map_array[ $blog->domain ] = $blog->blog_id;
    544589                    } else {
    545 
     590                       
    546591                        if ( 1 !== $blog->blog_id ) {
    547592                            $rt_nginx_map_array[ $blog->path ] = $blog->blog_id;
     
    550595                }
    551596            }
    552 
     597           
    553598            if ( $rt_domain_map_sites ) {
    554 
     599               
    555600                foreach ( $rt_domain_map_sites as $site ) {
    556601                    $rt_nginx_map_array[ $site->domain ] = $site->blog_id;
    557602                }
    558603            }
    559 
     604           
    560605            foreach ( $rt_nginx_map_array as $domain => $domain_id ) {
    561606                $rt_nginx_map .= "\t" . $domain . "\t" . $domain_id . ";\n";
    562607            }
    563 
     608           
    564609            return $rt_nginx_map;
    565 
    566         }
    567 
    568     }
    569 
     610           
     611        }
     612       
     613    }
     614   
    570615    /**
    571616     * Update map
    572617     */
    573618    public function update_map() {
    574 
     619       
    575620        if ( is_multisite() ) {
    576 
     621           
    577622            $rt_nginx_map = $this->get_map();
    578 
     623           
    579624            $fp = fopen( $this->functional_asset_path() . 'map.conf', 'w+' );
    580625            if ( $fp ) {
     
    583628            }
    584629        }
    585 
    586     }
    587 
     630       
     631    }
     632   
    588633    /**
    589634     * Purge url when post status is changed.
     
    597642     */
    598643    public function set_future_post_option_on_future_status( $new_status, $old_status, $post ) {
    599 
     644       
    600645        global $blog_id, $nginx_purger;
    601 
     646       
    602647        $exclude_post_types = array( 'nav_menu_item' );
    603 
     648       
    604649        if ( in_array( $post->post_type, $exclude_post_types, true ) ) {
    605650            return;
    606651        }
    607 
    608         if ( ! $this->options['enable_purge'] ) {
    609             return;
    610         }
    611 
     652       
     653        if ( ! $this->options['enable_purge'] || $this->is_import_request() ) {
     654            return;
     655        }
     656       
    612657        $purge_status = array( 'publish', 'future' );
    613 
     658       
    614659        if ( in_array( $old_status, $purge_status, true ) || in_array( $new_status, $purge_status, true ) ) {
    615 
     660           
    616661            $nginx_purger->log( 'Purge post on transition post STATUS from ' . $old_status . ' to ' . $new_status );
    617662            $nginx_purger->purge_post( $post->ID );
    618 
    619         }
    620 
     663           
     664        }
     665       
    621666        if (
    622667            'future' === $new_status && $post && 'future' === $post->post_status &&
     
    629674            )
    630675        ) {
    631 
     676           
    632677            $nginx_purger->log( 'Set/update future_posts option ( post id = ' . $post->ID . ' and blog id = ' . $blog_id . ' )' );
    633678            $this->options['future_posts'][ $blog_id ][ $post->ID ] = strtotime( $post->post_date_gmt ) + 60;
    634679            update_site_option( 'rt_wp_nginx_helper_options', $this->options );
    635 
    636         }
    637 
    638     }
    639 
     680           
     681        }
     682       
     683    }
     684   
    640685    /**
    641686     * Unset future post option on delete
     
    647692     */
    648693    public function unset_future_post_option_on_delete( $post_id ) {
    649 
     694       
    650695        global $blog_id, $nginx_purger;
    651 
     696       
    652697        if (
    653698            ! $this->options['enable_purge'] ||
     
    659704            return;
    660705        }
    661 
     706       
    662707        $nginx_purger->log( 'Unset future_posts option ( post id = ' . $post_id . ' and blog id = ' . $blog_id . ' )' );
    663 
     708       
    664709        unset( $this->options['future_posts'][ $blog_id ][ $post_id ] );
    665 
     710       
    666711        if ( ! count( $this->options['future_posts'][ $blog_id ] ) ) {
    667712            unset( $this->options['future_posts'][ $blog_id ] );
    668713        }
    669 
     714       
    670715        update_site_option( 'rt_wp_nginx_helper_options', $this->options );
    671716    }
    672 
     717   
    673718    /**
    674719     * Update map when new blog added in multisite.
     
    679724     */
    680725    public function update_new_blog_options( $blog_id ) {
    681 
     726       
    682727        global $nginx_purger;
    683 
     728       
    684729        $nginx_purger->log( "New site added ( id $blog_id )" );
    685730        $this->update_map();
     
    688733        update_blog_option( $blog_id, 'rt_wp_nginx_helper_options', $helper_options );
    689734        $nginx_purger->log( "Default options updated for the new blog ( id $blog_id )" );
    690 
    691     }
    692 
     735       
     736    }
     737   
    693738    /**
    694739     * Purge all urls.
     
    699744     */
    700745    public function purge_all() {
    701 
     746       
     747        if ( $this->is_import_request() ) {
     748            return;
     749        }
     750       
    702751        global $nginx_purger, $wp;
    703 
     752       
    704753        $method = null;
    705754        if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
    706755            $method = wp_strip_all_tags( $_SERVER['REQUEST_METHOD'] );
    707756        }
    708 
     757       
    709758        $action = '';
    710759        if ( 'POST' === $method ) {
     
    717766            }
    718767        }
    719 
     768       
    720769        if ( empty( $action ) ) {
    721770            return;
    722771        }
    723 
     772       
    724773        if ( ! current_user_can( 'manage_options' ) ) {
    725774            wp_die( 'Sorry, you do not have the necessary privileges to edit these options.' );
    726775        }
    727 
     776       
    728777        if ( 'done' === $action ) {
    729 
     778           
    730779            add_action( 'admin_notices', array( &$this, 'display_notices' ) );
    731780            add_action( 'network_admin_notices', array( &$this, 'display_notices' ) );
    732781            return;
    733 
    734         }
    735 
     782           
     783        }
     784       
    736785        check_admin_referer( 'nginx_helper-purge_all' );
    737 
     786       
    738787        $current_url = user_trailingslashit( home_url( $wp->request ) );
    739 
     788       
    740789        if ( ! is_admin() ) {
    741790            $action       = 'purge_current_page';
     
    744793            $redirect_url = add_query_arg( array( 'nginx_helper_action' => 'done' ) );
    745794        }
    746 
     795       
    747796        switch ( $action ) {
    748797            case 'purge':
     
    753802                break;
    754803        }
    755 
     804       
    756805        if ( 'purge' === $action ) {
    757 
     806           
    758807            /**
    759808             * Fire an action after the entire cache has been purged whatever caching type is used.
     
    762811             */
    763812            do_action( 'rt_nginx_helper_after_purge_all' );
    764 
    765         }
    766 
     813           
     814        }
     815       
    767816        wp_redirect( esc_url_raw( $redirect_url ) );
    768817        exit();
    769 
    770     }
    771 
     818       
     819    }
     820   
    772821    /**
    773822     * Dispay plugin notices.
     
    776825        echo '<div class="updated"><p>' . esc_html__( 'Purge initiated', 'nginx-helper' ) . '</p></div>';
    777826    }
    778 
     827   
     828    /**
     829     * Preloads the cache for the website.
     830     *
     831     * @return void
     832     */
     833    public function preload_cache() {
     834        $is_cache_preloaded    = $this->options['is_cache_preloaded'];
     835        $preload_cache_enabled = $this->options['preload_cache'];
     836       
     837        if ( $preload_cache_enabled && false === boolval( $is_cache_preloaded ) ) {
     838            $this->options['is_cache_preloaded'] = true;
     839           
     840            update_site_option( 'rt_wp_nginx_helper_options', $this->options );
     841            $this->preload_cache_from_sitemap();
     842        }
     843    }
     844   
     845    /**
     846     * This function preloads the cache from sitemap url.
     847     *
     848     * @return void
     849     */
     850    private function preload_cache_from_sitemap() {
     851       
     852        $sitemap_urls = $this->get_index_sitemap_urls();
     853        $all_urls     = array();
     854       
     855        foreach ( $sitemap_urls as $sitemap_url ) {
     856            $urls     = $this->extract_sitemap_urls( $sitemap_url );
     857            $all_urls = array_merge( $all_urls, $urls );
     858        }
     859       
     860        $args = array(
     861            'timeout'   => 1,
     862            'blocking'  => false,
     863            'sslverify' => false,
     864        );
     865       
     866        foreach ( $all_urls as $url ) {
     867            wp_remote_get( esc_url_raw( $url ), $args );
     868        }
     869       
     870    }
     871   
     872    /**
     873     * Fetches all the sitemap urls for the site.
     874     *
     875     * @return array
     876     */
     877    private function get_index_sitemap_urls() {
     878        $sitemaps = wp_sitemaps_get_server()->index->get_sitemap_list();
     879        $urls     = array();
     880        foreach ( $sitemaps as $sitemap ) {
     881            $urls[] = $sitemap['loc'];
     882        }
     883        return $urls;
     884    }
     885   
     886    /**
     887     * Parse sitemap content and extract all URLs.
     888     *
     889     * @param string $sitemap_url The URL of the sitemap.
     890     * @return array|WP_Error An array of URLs or WP_Error on failure.
     891     */
     892    private function extract_sitemap_urls( $sitemap_url ) {
     893        $response = wp_remote_get( $sitemap_url );
     894       
     895        $urls = array();
     896       
     897        if ( is_wp_error( $response ) ) {
     898            return $urls;
     899        }
     900       
     901        $sitemap_content = wp_remote_retrieve_body( $response );
     902       
     903        libxml_use_internal_errors( true );
     904        $xml = simplexml_load_string( $sitemap_content );
     905       
     906        if ( false === $xml ) {
     907            return new WP_Error( 'sitemap_parse_error', esc_html__( 'Failed to parse the sitemap XML', 'nginx-helper' ) );
     908        }
     909       
     910        $urls = array();
     911       
     912        if ( false === $xml ) {
     913            return $urls;
     914        }
     915       
     916        foreach ( $xml->url as $url ) {
     917            $urls[] = (string) $url->loc;
     918        }
     919       
     920        return $urls;
     921    }
     922   
     923    /**
     924    * Determines if the current request is for importing Posts/ WordPress content.
     925    *
     926    * @return bool True if the request is for importing, false otherwise.
     927    */
     928    public function is_import_request() {
     929        $import_query_var   = sanitize_text_field( wp_unslash( $_GET['import'] ?? '' ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is already in the admin dashboard.
     930        $has_import_started = did_action( 'import_start' );
     931       
     932        return ( defined( 'WP_IMPORTING' ) && true === WP_IMPORTING )
     933            || 0 !== $has_import_started
     934            || ! empty( $import_query_var );
     935    }
     936   
     937   
    779938}
  • nginx-helper/tags/2.3.0/admin/class-phpredis-purger.php

    r2222658 r3213676  
    4040
    4141            $this->redis_object = new Redis();
     42           
     43            $redis_acl = array();
     44           
     45            $username = $nginx_helper_admin->options['redis_username'];
     46            $password = $nginx_helper_admin->options['redis_password'];
     47           
     48            if( $username && $password ) {
     49                $redis_acl['auth'] = array( $username, $password );
     50            }
     51           
     52            $hostname = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_hostname'] : $nginx_helper_admin->options['redis_unix_socket'];
     53            $port     = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_port'] : 0;
     54           
    4255            $this->redis_object->connect(
    43                 $nginx_helper_admin->options['redis_hostname'],
    44                 $nginx_helper_admin->options['redis_port'],
    45                 5
     56                $hostname,
     57                $port,
     58                5,
     59                null,
     60                0,
     61                0,
     62                $redis_acl
    4663            );
     64           
     65            if( $nginx_helper_admin->options['redis_database'] !== 0 ) {
     66                $this->redis_object->select($nginx_helper_admin->options['redis_database']);
     67            }
    4768
    4869        } catch ( Exception $e ) {
  • nginx-helper/tags/2.3.0/admin/class-predis-purger.php

    r2222658 r3213676  
    3838
    3939        Predis\Autoloader::register();
    40 
     40       
     41        $predis_args = array();
     42       
     43        $username = $nginx_helper_admin->options['redis_username'];
     44        $password = $nginx_helper_admin->options['redis_password'];
     45       
     46        if( ! empty( $nginx_helper_admin->options['redis_unix_socket'] ) ) {
     47            $predis_args['path'] = $nginx_helper_admin->options['redis_unix_socket'];
     48        } else {
     49            $predis_args['host'] = $nginx_helper_admin->options['redis_hostname'];;
     50            $predis_args['port'] = $nginx_helper_admin->options['redis_port'];
     51        }
     52       
     53        if ( $username && $password ) {
     54            $predis_args['username'] = $username;
     55            $predis_args['password'] = $password;
     56        }
     57       
    4158        // redis server parameter.
    42         $this->redis_object = new Predis\Client(
    43             array(
    44                 'host' => $nginx_helper_admin->options['redis_hostname'],
    45                 'port' => $nginx_helper_admin->options['redis_port'],
    46             )
    47         );
     59        $this->redis_object = new Predis\Client( $predis_args );
    4860
    4961        try {
    5062            $this->redis_object->connect();
     63           
     64            if( 0 !== $nginx_helper_admin->options['redis_database'] ) {
     65                $this->redis_object->select( $nginx_helper_admin->options['redis_database'] );
     66            }
    5167        } catch ( Exception $e ) {
    5268            $this->log( $e->getMessage(), 'ERROR' );
    53         }
     69            return;
     70        }
     71       
    5472
    5573    }
  • nginx-helper/tags/2.3.0/admin/css/nginx-helper-admin.css

    r3023296 r3213676  
    55
    66.clearfix {
    7     *zoom: 1;
     7    zoom: 1;
    88}
    99.clearfix:before,
     
    104104    margin-left: 23px;
    105105}
     106
     107.password-input {
     108    padding-right: 40px;
     109}
     110
     111.password-show-hide-btn {
     112    background-color: transparent;
     113    border: 0;
     114    cursor: pointer;
     115    display: inline-block;
     116}
     117
     118.password-wrapper {
     119    display: flex;
     120}
  • nginx-helper/tags/2.3.0/admin/js/nginx-helper-admin.js

    r2222658 r3213676  
    7676            );
    7777
     78            jQuery('.password-show-hide-btn').on('click', function() {
     79                var passwordInput = $(this).siblings('.password-input');
     80                var icon = $(this).find('.password-input-icon');
     81   
     82                if (passwordInput.attr('type') === 'password') {
     83                    passwordInput.attr('type', 'text');
     84                    icon.removeClass('dashicons-hidden').addClass('dashicons-visibility');
     85                } else {
     86                    passwordInput.attr('type', 'password');
     87                    icon.removeClass('dashicons-visibility').addClass('dashicons-hidden');
     88                }
     89            });
     90
    7891            /**
    7992             * Show OR Hide options on option checkbox
  • nginx-helper/tags/2.3.0/admin/partials/nginx-helper-general-options.php

    r3071366 r3213676  
    2323    'redis_port',
    2424    'redis_prefix',
     25    'redis_database',
     26    'redis_username',
     27    'redis_password',
     28    'redis_unix_socket',
     29    'redis_socket_enabled_by_constant',
     30    'redis_acl_enabled_by_constant',
    2531    'purge_homepage_on_edit',
    2632    'purge_homepage_on_del',
     
    4147    'purge_feeds',
    4248    'smart_http_expire_form_nonce',
     49    'purge_amp_urls',
     50    'preload_cache',
    4351);
    4452
     
    125133                        <input type="checkbox" value="1" id="enable_purge" name="enable_purge" <?php checked( $nginx_helper_settings['enable_purge'], 1 ); ?> />
    126134                        <label for="enable_purge"><?php esc_html_e( 'Enable Purge', 'nginx-helper' ); ?></label>
     135                    </td>
     136                </tr>
     137                <tr valign="top">
     138                    <td>
     139                        <input type="checkbox" value="1" id="preload_cache" name="preload_cache" <?php checked( $nginx_helper_settings['preload_cache'], 1 ); ?> />
     140                        <label for="preload_cache"><?php esc_html_e( 'Preload Cache', 'nginx-helper' ); ?></label>
    127141                    </td>
    128142                </tr>
     
    247261                            <th><label for="redis_hostname"><?php esc_html_e( 'Hostname', 'nginx-helper' ); ?></label></th>
    248262                            <td>
    249                                 <input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     263                                <input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> />
    250264                                <?php
    251265                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     
    255269                                    echo '</p>';
    256270
     271                                }
     272                                ?>
     273                                <?php
     274                                if ( $nginx_helper_settings['redis_unix_socket'] ) {
     275                                    echo '<p class="description">';
     276                                    esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' );
     277                                    echo '</p>';
    257278                                }
    258279                                ?>
     
    262283                            <th><label for="redis_port"><?php esc_html_e( 'Port', 'nginx-helper' ); ?></label></th>
    263284                            <td>
    264                                 <input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     285                                <input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> />
    265286                                <?php
    266287                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     
    270291                                    echo '</p>';
    271292
     293                                }
     294                                ?>
     295                                <?php
     296                                if ( $nginx_helper_settings['redis_unix_socket'] ) {
     297                                   
     298                                    echo '<p class="description">';
     299                                    esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' );
     300                                    echo '</p>';
     301                                   
     302                                }
     303                                ?>
     304                            </td>
     305                        </tr>
     306                        <tr>
     307                            <th><label for="redis_unix_socket"><?php esc_html_e( 'Socket Path', 'nginx-helper' ); ?></label></th>
     308                            <td>
     309                                <input id="redis_unix_socket" class="medium-text" type="text" name="redis_unix_socket" value="<?php echo esc_attr( $nginx_helper_settings['redis_unix_socket'] ); ?>" <?php echo ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     310                                <?php
     311                                if ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) {
     312                                   
     313                                    echo '<p class="description">';
     314                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     315                                    echo '</p>';
     316                                   
    272317                                }
    273318                                ?>
     
    285330                                    echo '</p>';
    286331
     332                                }
     333                                ?>
     334                            </td>
     335                        </tr>
     336                        <tr>
     337                            <th><label for="redis_database"><?php esc_html_e( 'Database', 'nginx-helper' ); ?></label></th>
     338                            <td>
     339                                <input id="redis_database" class="medium-text" type="text" name="redis_database" value="<?php echo esc_attr( $nginx_helper_settings['redis_database'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     340                                <?php
     341                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     342                                   
     343                                    echo '<p class="description">';
     344                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     345                                    echo '</p>';
     346                                   
     347                                }
     348                                ?>
     349                            </td>
     350                        </tr>
     351
     352                        <tr>
     353                            <th><label for="redis_username"><?php esc_html_e( 'Username', 'nginx-helper' ); ?></label></th>
     354                            <td>
     355                                <input id="redis_username" class="medium-text" type="text" name="redis_username" value="<?php echo esc_attr( $nginx_helper_settings['redis_username'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     356                                <?php
     357                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     358                                   
     359                                    echo '<p class="description">';
     360                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     361                                    echo '</p>';
     362                                   
     363                                }
     364                                ?>
     365                            </td>
     366                        </tr>
     367
     368                        <tr>
     369                            <th><label for="redis_password"><?php esc_html_e( 'Password', 'nginx-helper' ); ?></label></th>
     370                            <td>
     371                                <div class="password-wrapper">
     372                                    <input id="redis_password" class="medium-text password-input" type="password" name="redis_password" value="<?php echo esc_attr( $nginx_helper_settings['redis_password'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     373                                    <button type="button" class="password-show-hide-btn"><span class="dashicons dashicons-hidden password-input-icon"></span></button>
     374                                </div>
     375                                <?php
     376                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     377                                    echo '<p class="description">';
     378                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     379                                    echo '</p>';
     380                                   
    287381                                }
    288382                                ?>
     
    542636                                            array( 'strong' => array() )
    543637                                        );
     638                                    ?>
     639                                </label>
     640                                <br />
     641                            </fieldset>
     642                        </td>
     643                    </tr>
     644                </table>
     645                <table class="form-table rtnginx-table">
     646                    <tr valign="top">
     647                        <th scope="row">
     648                            <h4>
     649                <?php esc_html_e( 'Purge AMP URL:', 'nginx-helper' ); ?>
     650                            </h4>
     651                        </th>
     652                        <td>
     653                            <fieldset>
     654                                <legend class="screen-reader-text">
     655                                    <span>
     656                                        &nbsp;
     657                                        <?php
     658                                        esc_html_e( 'purge amp urls', 'nginx-helper' );
     659                                        ?>
     660                                    </span>
     661                                </legend>
     662                                <label for="purge_amp_urls">
     663                                    <input type="checkbox" value="1" id="purge_amp_urls" name="purge_amp_urls" <?php checked( $nginx_helper_settings['purge_amp_urls'], 1 ); ?> />
     664                                    &nbsp;
     665                                    <?php
     666                                    echo wp_kses(
     667                                        __( 'purge <strong>amp urls</strong> along with <strong>posts</strong> & <strong>pages</strong>.', 'nginx-helper' ),
     668                                        array( 'strong' => array() )
     669                                    );
    544670                                    ?>
    545671                                </label>
  • nginx-helper/tags/2.3.0/includes/class-nginx-helper-activator.php

    r1976548 r3213676  
    5858
    5959        wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
     60       
     61        if( method_exists( $nginx_helper_admin, 'store_default_options' ) ) {
     62            $nginx_helper_admin->store_default_options();
     63        }
    6064
    6165    }
  • nginx-helper/tags/2.3.0/includes/class-nginx-helper.php

    r3071366 r3213676  
    7878
    7979        $this->plugin_name = 'nginx-helper';
    80         $this->version     = '2.2.5';
     80        $this->version     = '2.3.0';
    8181        $this->minimum_wp  = '3.0';
    8282
     
    170170
    171171        $nginx_helper_admin = new Nginx_Helper_Admin( $this->get_plugin_name(), $this->get_version() );
    172 
     172        $this->loader->add_action( 'init', $nginx_helper_admin, 'initialize_setting_tab' );
    173173        // Defines global variables.
    174174        if ( ! empty( $nginx_helper_admin->options['cache_method'] ) && 'enable_redis' === $nginx_helper_admin->options['cache_method'] ) {
     
    228228        // expose action to allow other plugins to purge the cache.
    229229        $this->loader->add_action( 'rt_nginx_helper_purge_all', $nginx_purger, 'purge_all' );
     230       
     231        // add action to preload the cache
     232        $this->loader->add_action( 'admin_init', $nginx_helper_admin, 'preload_cache' );
    230233    }
    231234
  • nginx-helper/tags/2.3.0/languages/nginx-helper.po

    r3071366 r3213676  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Nginx Helper 2.2.5\n"
     5"Project-Id-Version: Nginx Helper 2.3.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nginx-helper\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2024-04-15T10:26:40+00:00\n"
     12"POT-Creation-Date: 2024-12-19T06:01:42+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.9.0\n"
     14"X-Generator: WP-CLI 2.11.0\n"
    1515"X-Domain: nginx-helper\n"
    1616
    1717#. Plugin Name of the plugin
    18 #: admin/class-nginx-helper-admin.php:177
    19 #: admin/class-nginx-helper-admin.php:178
    20 #: admin/class-nginx-helper-admin.php:188
    21 #: admin/class-nginx-helper-admin.php:189
     18#: nginx-helper.php
     19#: admin/class-nginx-helper-admin.php:183
     20#: admin/class-nginx-helper-admin.php:184
     21#: admin/class-nginx-helper-admin.php:194
     22#: admin/class-nginx-helper-admin.php:195
    2223msgid "Nginx Helper"
    2324msgstr ""
    2425
    2526#. Plugin URI of the plugin
     27#: nginx-helper.php
    2628msgid "https://rtcamp.com/nginx-helper/"
    2729msgstr ""
    2830
    2931#. Description of the plugin
     32#: nginx-helper.php
    3033msgid "Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things."
    3134msgstr ""
    3235
    3336#. Author of the plugin
     37#: nginx-helper.php
    3438msgid "rtCamp"
    3539msgstr ""
    3640
    3741#. Author URI of the plugin
     42#: nginx-helper.php
    3843msgid "https://rtcamp.com"
    3944msgstr ""
    4045
    41 #: admin/class-nginx-helper-admin.php:88
     46#: admin/class-nginx-helper-admin.php:97
    4247msgid "General"
    4348msgstr ""
    4449
    45 #: admin/class-nginx-helper-admin.php:92
     50#: admin/class-nginx-helper-admin.php:101
    4651msgid "Support"
    4752msgstr ""
    4853
    49 #: admin/class-nginx-helper-admin.php:160
     54#: admin/class-nginx-helper-admin.php:166
    5055msgid "Purging entire cache is not recommended. Would you like to continue?"
    5156msgstr ""
    5257
    53 #: admin/class-nginx-helper-admin.php:212
     58#: admin/class-nginx-helper-admin.php:218
    5459msgid "Purge Cache"
    5560msgstr ""
    5661
    57 #: admin/class-nginx-helper-admin.php:215
     62#: admin/class-nginx-helper-admin.php:221
    5863msgid "Purge Current Page"
    5964msgstr ""
    6065
    61 #: admin/class-nginx-helper-admin.php:342
     66#: admin/class-nginx-helper-admin.php:387
    6267msgid "Settings"
    6368msgstr ""
    6469
    65 #: admin/class-nginx-helper-admin.php:426
     70#: admin/class-nginx-helper-admin.php:471
    6671msgid "No items"
    6772msgstr ""
    6873
    69 #: admin/class-nginx-helper-admin.php:437
     74#: admin/class-nginx-helper-admin.php:482
    7075msgid "Posted "
    7176msgstr ""
    7277
    73 #: admin/class-nginx-helper-admin.php:776
     78#: admin/class-nginx-helper-admin.php:825
    7479msgid "Purge initiated"
     80msgstr ""
     81
     82#: admin/class-nginx-helper-admin.php:907
     83msgid "Failed to parse the sitemap XML"
    7584msgstr ""
    7685
     
    237246msgstr ""
    238247
    239 #: admin/partials/nginx-helper-general-options.php:82
     248#: admin/partials/nginx-helper-general-options.php:90
    240249msgid "Log file size must be a number."
    241250msgstr ""
    242251
    243 #: admin/partials/nginx-helper-general-options.php:92
     252#: admin/partials/nginx-helper-general-options.php:100
    244253msgid "Settings saved."
    245254msgstr ""
    246255
    247 #: admin/partials/nginx-helper-general-options.php:119
     256#: admin/partials/nginx-helper-general-options.php:127
    248257msgid "Purging Options"
    249258msgstr ""
    250259
    251 #: admin/partials/nginx-helper-general-options.php:126
     260#: admin/partials/nginx-helper-general-options.php:134
    252261msgid "Enable Purge"
    253262msgstr ""
    254263
    255 #: admin/partials/nginx-helper-general-options.php:136
     264#: admin/partials/nginx-helper-general-options.php:140
     265msgid "Preload Cache"
     266msgstr ""
     267
     268#: admin/partials/nginx-helper-general-options.php:150
    256269msgid "Caching Method"
    257270msgstr ""
    258271
    259 #: admin/partials/nginx-helper-general-options.php:148
     272#: admin/partials/nginx-helper-general-options.php:162
    260273msgid "nginx Fastcgi cache"
    261274msgstr ""
    262275
    263 #: admin/partials/nginx-helper-general-options.php:150
     276#: admin/partials/nginx-helper-general-options.php:164
    264277msgid "External settings for nginx"
    265278msgstr ""
    266279
    267 #: admin/partials/nginx-helper-general-options.php:151
     280#: admin/partials/nginx-helper-general-options.php:165
    268281msgid "requires external settings for nginx"
    269282msgstr ""
    270283
    271 #: admin/partials/nginx-helper-general-options.php:161
     284#: admin/partials/nginx-helper-general-options.php:175
    272285msgid "Redis cache"
    273286msgstr ""
    274287
    275 #: admin/partials/nginx-helper-general-options.php:171
     288#: admin/partials/nginx-helper-general-options.php:185
    276289msgid "Purge Method"
    277290msgstr ""
    278291
    279 #: admin/partials/nginx-helper-general-options.php:181
    280 #: admin/partials/nginx-helper-general-options.php:361
     292#: admin/partials/nginx-helper-general-options.php:195
     293#: admin/partials/nginx-helper-general-options.php:455
    281294msgid "when a post/page/custom post is published."
    282295msgstr ""
    283296
    284 #: admin/partials/nginx-helper-general-options.php:191
     297#: admin/partials/nginx-helper-general-options.php:205
    285298msgid "Using a GET request to"
    286299msgstr ""
    287300
    288 #: admin/partials/nginx-helper-general-options.php:192
     301#: admin/partials/nginx-helper-general-options.php:206
    289302msgid "(Default option)"
    290303msgstr ""
    291304
    292305#. translators: %s Nginx cache purge module link.
    293 #: admin/partials/nginx-helper-general-options.php:203
     306#: admin/partials/nginx-helper-general-options.php:217
    294307msgid "Uses the %s module."
    295308msgstr ""
    296309
    297 #: admin/partials/nginx-helper-general-options.php:221
     310#: admin/partials/nginx-helper-general-options.php:235
    298311msgid "Delete local server cache files"
    299312msgstr ""
    300313
    301 #: admin/partials/nginx-helper-general-options.php:227
     314#: admin/partials/nginx-helper-general-options.php:241
    302315msgid "Checks for matching cache file in <strong>RT_WP_NGINX_HELPER_CACHE_PATH</strong>. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key \"$scheme$request_method$host$request_uri\")."
    303316msgstr ""
    304317
    305 #: admin/partials/nginx-helper-general-options.php:242
     318#: admin/partials/nginx-helper-general-options.php:256
    306319msgid "Redis Settings"
    307320msgstr ""
    308321
    309 #: admin/partials/nginx-helper-general-options.php:247
     322#: admin/partials/nginx-helper-general-options.php:261
    310323msgid "Hostname"
    311324msgstr ""
    312325
    313 #: admin/partials/nginx-helper-general-options.php:254
    314 #: admin/partials/nginx-helper-general-options.php:269
    315 #: admin/partials/nginx-helper-general-options.php:284
     326#: admin/partials/nginx-helper-general-options.php:268
     327#: admin/partials/nginx-helper-general-options.php:290
     328#: admin/partials/nginx-helper-general-options.php:314
     329#: admin/partials/nginx-helper-general-options.php:329
     330#: admin/partials/nginx-helper-general-options.php:344
     331#: admin/partials/nginx-helper-general-options.php:360
     332#: admin/partials/nginx-helper-general-options.php:378
    316333msgid "Overridden by constant variables."
    317334msgstr ""
    318335
    319 #: admin/partials/nginx-helper-general-options.php:262
     336#: admin/partials/nginx-helper-general-options.php:276
     337#: admin/partials/nginx-helper-general-options.php:299
     338msgid "Overridden by unix socket path."
     339msgstr ""
     340
     341#: admin/partials/nginx-helper-general-options.php:283
    320342msgid "Port"
    321343msgstr ""
    322344
    323 #: admin/partials/nginx-helper-general-options.php:277
     345#: admin/partials/nginx-helper-general-options.php:307
     346msgid "Socket Path"
     347msgstr ""
     348
     349#: admin/partials/nginx-helper-general-options.php:322
    324350msgid "Prefix"
    325351msgstr ""
    326352
    327 #: admin/partials/nginx-helper-general-options.php:297
     353#: admin/partials/nginx-helper-general-options.php:337
     354msgid "Database"
     355msgstr ""
     356
     357#: admin/partials/nginx-helper-general-options.php:353
     358msgid "Username"
     359msgstr ""
     360
     361#: admin/partials/nginx-helper-general-options.php:369
     362msgid "Password"
     363msgstr ""
     364
     365#: admin/partials/nginx-helper-general-options.php:391
    328366msgid "Purging Conditions"
    329367msgstr ""
    330368
    331 #: admin/partials/nginx-helper-general-options.php:302
     369#: admin/partials/nginx-helper-general-options.php:396
    332370msgid "Purge Homepage:"
    333371msgstr ""
    334372
    335 #: admin/partials/nginx-helper-general-options.php:309
     373#: admin/partials/nginx-helper-general-options.php:403
    336374msgid "when a post/page/custom post is modified or added."
    337375msgstr ""
    338376
    339 #: admin/partials/nginx-helper-general-options.php:318
    340 #: admin/partials/nginx-helper-general-options.php:445
     377#: admin/partials/nginx-helper-general-options.php:412
     378#: admin/partials/nginx-helper-general-options.php:539
    341379msgid "when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>."
    342380msgstr ""
    343381
    344 #: admin/partials/nginx-helper-general-options.php:330
     382#: admin/partials/nginx-helper-general-options.php:424
    345383msgid "when an existing post/page/custom post is modified."
    346384msgstr ""
    347385
    348 #: admin/partials/nginx-helper-general-options.php:339
     386#: admin/partials/nginx-helper-general-options.php:433
    349387msgid "when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>"
    350388msgstr ""
    351389
    352 #: admin/partials/nginx-helper-general-options.php:353
     390#: admin/partials/nginx-helper-general-options.php:447
    353391msgid "Purge Post/Page/Custom Post Type:"
    354392msgstr ""
    355393
    356 #: admin/partials/nginx-helper-general-options.php:370
     394#: admin/partials/nginx-helper-general-options.php:464
    357395msgid "when a <strong>post</strong> is <strong>published</strong>."
    358396msgstr ""
    359397
    360 #: admin/partials/nginx-helper-general-options.php:382
    361 #: admin/partials/nginx-helper-general-options.php:479
     398#: admin/partials/nginx-helper-general-options.php:476
     399#: admin/partials/nginx-helper-general-options.php:573
    362400msgid "when a comment is approved/published."
    363401msgstr ""
    364402
    365 #: admin/partials/nginx-helper-general-options.php:391
    366 #: admin/partials/nginx-helper-general-options.php:488
     403#: admin/partials/nginx-helper-general-options.php:485
     404#: admin/partials/nginx-helper-general-options.php:582
    367405msgid "when a <strong>comment</strong> is <strong>approved/published</strong>."
    368406msgstr ""
    369407
    370 #: admin/partials/nginx-helper-general-options.php:403
    371 #: admin/partials/nginx-helper-general-options.php:500
     408#: admin/partials/nginx-helper-general-options.php:497
     409#: admin/partials/nginx-helper-general-options.php:594
    372410msgid "when a comment is unapproved/deleted."
    373411msgstr ""
    374412
    375 #: admin/partials/nginx-helper-general-options.php:412
    376 #: admin/partials/nginx-helper-general-options.php:509
     413#: admin/partials/nginx-helper-general-options.php:506
     414#: admin/partials/nginx-helper-general-options.php:603
    377415msgid "when a <strong>comment</strong> is <strong>unapproved/deleted</strong>."
    378416msgstr ""
    379417
    380 #: admin/partials/nginx-helper-general-options.php:426
     418#: admin/partials/nginx-helper-general-options.php:520
    381419msgid "Purge Archives:"
    382420msgstr ""
    383421
    384 #: admin/partials/nginx-helper-general-options.php:428
     422#: admin/partials/nginx-helper-general-options.php:522
    385423msgid "(date, category, tag, author, custom taxonomies)"
    386424msgstr ""
    387425
    388 #: admin/partials/nginx-helper-general-options.php:436
     426#: admin/partials/nginx-helper-general-options.php:530
    389427msgid "when an post/page/custom post is modified or added"
    390428msgstr ""
    391429
    392 #: admin/partials/nginx-helper-general-options.php:457
     430#: admin/partials/nginx-helper-general-options.php:551
    393431msgid "when an existing post/page/custom post is trashed."
    394432msgstr ""
    395433
    396 #: admin/partials/nginx-helper-general-options.php:466
     434#: admin/partials/nginx-helper-general-options.php:560
    397435msgid "when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>."
    398436msgstr ""
    399437
    400 #: admin/partials/nginx-helper-general-options.php:523
     438#: admin/partials/nginx-helper-general-options.php:617
    401439msgid "Purge Feeds:"
    402440msgstr ""
    403441
    404 #: admin/partials/nginx-helper-general-options.php:532
     442#: admin/partials/nginx-helper-general-options.php:626
    405443msgid "purge feeds"
    406444msgstr ""
    407445
    408 #: admin/partials/nginx-helper-general-options.php:541
     446#: admin/partials/nginx-helper-general-options.php:635
    409447msgid "purge <strong>feeds</strong> along with <strong>posts</strong> & <strong>pages</strong>."
    410448msgstr ""
    411449
    412 #: admin/partials/nginx-helper-general-options.php:554
     450#: admin/partials/nginx-helper-general-options.php:649
     451msgid "Purge AMP URL:"
     452msgstr ""
     453
     454#: admin/partials/nginx-helper-general-options.php:658
     455msgid "purge amp urls"
     456msgstr ""
     457
     458#: admin/partials/nginx-helper-general-options.php:667
     459msgid "purge <strong>amp urls</strong> along with <strong>posts</strong> & <strong>pages</strong>."
     460msgstr ""
     461
     462#: admin/partials/nginx-helper-general-options.php:680
    413463msgid "Custom Purge URL:"
    414464msgstr ""
    415465
    416 #: admin/partials/nginx-helper-general-options.php:560
     466#: admin/partials/nginx-helper-general-options.php:686
    417467msgid "Add one URL per line. URL should not contain domain name."
    418468msgstr ""
    419469
    420 #: admin/partials/nginx-helper-general-options.php:563
     470#: admin/partials/nginx-helper-general-options.php:689
    421471msgid "Eg: To purge http://example.com/sample-page/ add <strong>/sample-page/</strong> in above textarea."
    422472msgstr ""
    423473
    424 #: admin/partials/nginx-helper-general-options.php:567
     474#: admin/partials/nginx-helper-general-options.php:693
    425475msgid "'*' will only work with redis cache server."
    426476msgstr ""
    427477
    428 #: admin/partials/nginx-helper-general-options.php:577
     478#: admin/partials/nginx-helper-general-options.php:703
    429479msgid "Debug Options"
    430480msgstr ""
    431481
    432 #: admin/partials/nginx-helper-general-options.php:587
     482#: admin/partials/nginx-helper-general-options.php:713
    433483msgid "Enable Nginx Map."
    434484msgstr ""
    435485
    436 #: admin/partials/nginx-helper-general-options.php:606
     486#: admin/partials/nginx-helper-general-options.php:732
    437487msgid "Enable Logging"
    438488msgstr ""
    439489
    440 #: admin/partials/nginx-helper-general-options.php:611
     490#: admin/partials/nginx-helper-general-options.php:737
    441491msgid "disable"
    442492msgstr ""
    443493
    444 #: admin/partials/nginx-helper-general-options.php:617
     494#: admin/partials/nginx-helper-general-options.php:743
    445495msgid "enable"
    446496msgstr ""
    447497
    448 #: admin/partials/nginx-helper-general-options.php:624
     498#: admin/partials/nginx-helper-general-options.php:750
    449499msgid "NOTE"
    450500msgstr ""
    451501
    452 #: admin/partials/nginx-helper-general-options.php:625
     502#: admin/partials/nginx-helper-general-options.php:751
    453503msgid "To"
    454504msgstr ""
    455505
    456 #: admin/partials/nginx-helper-general-options.php:627
     506#: admin/partials/nginx-helper-general-options.php:753
    457507msgid "the logging feature, you must define"
    458508msgstr ""
    459509
    460 #: admin/partials/nginx-helper-general-options.php:628
     510#: admin/partials/nginx-helper-general-options.php:754
    461511msgid "as"
    462512msgstr ""
    463513
    464 #: admin/partials/nginx-helper-general-options.php:630
     514#: admin/partials/nginx-helper-general-options.php:756
    465515msgid "in your"
    466516msgstr ""
    467517
    468 #: admin/partials/nginx-helper-general-options.php:641
     518#: admin/partials/nginx-helper-general-options.php:767
    469519msgid "Enable Nginx Timestamp in HTML"
    470520msgstr ""
    471521
    472 #: admin/partials/nginx-helper-general-options.php:655
     522#: admin/partials/nginx-helper-general-options.php:781
    473523msgid "Nginx Map"
    474524msgstr ""
    475525
    476 #: admin/partials/nginx-helper-general-options.php:664
     526#: admin/partials/nginx-helper-general-options.php:790
    477527msgid "Can't write on map file."
    478528msgstr ""
    479529
    480530#. translators: %s file url.
    481 #: admin/partials/nginx-helper-general-options.php:669
    482 #: admin/partials/nginx-helper-general-options.php:741
     531#: admin/partials/nginx-helper-general-options.php:795
     532#: admin/partials/nginx-helper-general-options.php:867
    483533msgid "Check you have write permission on <strong>%s</strong>"
    484534msgstr ""
    485535
    486 #: admin/partials/nginx-helper-general-options.php:686
     536#: admin/partials/nginx-helper-general-options.php:812
    487537msgid "Nginx Map path to include in nginx settings"
    488538msgstr ""
    489539
    490 #: admin/partials/nginx-helper-general-options.php:687
     540#: admin/partials/nginx-helper-general-options.php:813
    491541msgid "(recommended)"
    492542msgstr ""
    493543
    494 #: admin/partials/nginx-helper-general-options.php:700
     544#: admin/partials/nginx-helper-general-options.php:826
    495545msgid "Or,"
    496546msgstr ""
    497547
    498 #: admin/partials/nginx-helper-general-options.php:701
     548#: admin/partials/nginx-helper-general-options.php:827
    499549msgid "Text to manually copy and paste in nginx settings"
    500550msgstr ""
    501551
    502 #: admin/partials/nginx-helper-general-options.php:702
     552#: admin/partials/nginx-helper-general-options.php:828
    503553msgid "(if your network is small and new sites are not added frequently)"
    504554msgstr ""
    505555
    506 #: admin/partials/nginx-helper-general-options.php:720
     556#: admin/partials/nginx-helper-general-options.php:846
    507557msgid "Logging Options"
    508558msgstr ""
    509559
    510 #: admin/partials/nginx-helper-general-options.php:736
     560#: admin/partials/nginx-helper-general-options.php:862
    511561msgid "Can't write on log file."
    512562msgstr ""
    513563
    514 #: admin/partials/nginx-helper-general-options.php:758
     564#: admin/partials/nginx-helper-general-options.php:884
    515565msgid "Logs path"
    516566msgstr ""
    517567
    518 #: admin/partials/nginx-helper-general-options.php:770
     568#: admin/partials/nginx-helper-general-options.php:896
    519569msgid "View Log"
    520570msgstr ""
    521571
    522 #: admin/partials/nginx-helper-general-options.php:775
     572#: admin/partials/nginx-helper-general-options.php:901
    523573msgid "Log"
    524574msgstr ""
    525575
    526 #: admin/partials/nginx-helper-general-options.php:782
     576#: admin/partials/nginx-helper-general-options.php:908
    527577msgid "Log level"
    528578msgstr ""
    529579
    530 #: admin/partials/nginx-helper-general-options.php:787
     580#: admin/partials/nginx-helper-general-options.php:913
    531581msgid "None"
    532582msgstr ""
    533583
    534 #: admin/partials/nginx-helper-general-options.php:788
     584#: admin/partials/nginx-helper-general-options.php:914
    535585msgid "Info"
    536586msgstr ""
    537587
    538 #: admin/partials/nginx-helper-general-options.php:789
     588#: admin/partials/nginx-helper-general-options.php:915
    539589msgid "Warning"
    540590msgstr ""
    541591
    542 #: admin/partials/nginx-helper-general-options.php:790
     592#: admin/partials/nginx-helper-general-options.php:916
    543593msgid "Error"
    544594msgstr ""
    545595
    546 #: admin/partials/nginx-helper-general-options.php:797
     596#: admin/partials/nginx-helper-general-options.php:923
    547597msgid "Max log file size"
    548598msgstr ""
    549599
    550 #: admin/partials/nginx-helper-general-options.php:803
     600#: admin/partials/nginx-helper-general-options.php:929
    551601msgid "Mb"
    552602msgstr ""
    553603
    554 #: admin/partials/nginx-helper-general-options.php:820
     604#: admin/partials/nginx-helper-general-options.php:946
    555605msgid "Save All Changes"
    556606msgstr ""
     
    654704
    655705#. translators: %s is Minimum WP version.
    656 #: includes/class-nginx-helper.php:311
     706#: includes/class-nginx-helper.php:314
    657707msgid "Sorry, Nginx Helper requires WordPress %s or higher"
    658708msgstr ""
  • nginx-helper/tags/2.3.0/nginx-helper.php

    r3071366 r3213676  
    44 * Plugin URI:        https://rtcamp.com/nginx-helper/
    55 * Description:       Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
    6  * Version:           2.2.5
     6 * Version:           2.3.0
    77 * Author:            rtCamp
    88 * Author URI:        https://rtcamp.com
     
    1010 * Domain Path:       /languages
    1111 * Requires at least: 3.0
    12  * Tested up to:      6.4
     12 * Tested up to:      6.7
    1313 *
    1414 * @link              https://rtcamp.com/nginx-helper/
  • nginx-helper/tags/2.3.0/readme.txt

    r3071384 r3213676  
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html
    77Requires at least: 3.0
    8 Tested up to: 6.5
    9 Stable tag: 2.2.5
     8Tested up to: 6.7
     9Stable tag: 2.3.0
    1010
    1111Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
     
    107107```
    108108
     109**Q. Can I override the redis socket path, username, password?**
     110
     111Yes, you can force override the redis socket path, username, password by defining constant in wp-config.php. For example:
     112
     113```php
     114define( 'RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET', '/var/run/redis/redis.sock' );
     115
     116define( 'RT_WP_NGINX_HELPER_REDIS_USERNAME', 'admin' );
     117
     118define( 'RT_WP_NGINX_HELPER_REDIS_PASSWORD', 'admin' );
     119```
     120
    109121= FAQ - Nginx Map =
    110122
     
    117129Most likely yes. A wordpress plugin, if not using explicitly any Apache-only mod, should work on Nginx. Some plugin may need some extra work.
    118130
     131
     132= FAQ - WP-CLI =
     133
     134**Q. How can I update the options using WP-CLI?**
     135
     136```shell
     137wp option patch update rt_wp_nginx_helper_options <option_name> <option_value>
     138```
    119139
    120140= Still need help! =
     
    127147
    128148== Changelog ==
     149
     150= 2.3.0 =
     151
     152* Disable the purge functionality when importing data. [#52](https://github.com/rtCamp/nginx-helper/pull/52) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     153* Added option to preload cache for all Post and Pages. [#47](https://github.com/rtCamp/nginx-helper/pull/47) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     154* Added the capability to purge Amp URL's. [#135](https://github.com/rtCamp/nginx-helper/pull/135) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     155* Add support for adding Username, Password support for Redis. It also includes the support for Unix Socket Path for Redis along with Database selection. [#343](https://github.com/rtCamp/nginx-helper/pull/343),[#350](https://github.com/rtCamp/nginx-helper/pull/350) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     156* Add capability to allow modifying options using WP-CLI. [#307](https://github.com/rtCamp/nginx-helper/pull/307) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     157* Fix the plugin crash issue due to internationalization after upgrading to WordPress Version 6.7. [#364](https://github.com/rtCamp/nginx-helper/pull/364) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     158
    129159
    130160= 2.2.5 =
  • nginx-helper/trunk/admin/class-fastcgi-purger.php

    r3071366 r3213676  
    9191
    9292        }
    93 
     93       
     94        if( ( is_page() || is_single() ) && $nginx_helper_admin->options['purge_amp_urls'] ) {
     95            $this->purge_amp_version( $url );
     96        }
     97
     98    }
     99   
     100    /**
     101     * Purge AMP version of a URL.
     102     *
     103     * @param string $url_base The base URL to purge.
     104     */
     105    private function purge_amp_version( $url_base ) {
     106        $amp_url = sprintf( '%s/amp/', rtrim( $url_base, '/' ) );
     107       
     108        $this->log( '- Purging AMP URL | ' . $amp_url );
     109       
     110        if ( 'unlink_files' === $this->nginx_helper_admin->options['purge_method'] ) {
     111            $this->delete_cache_file_for( $amp_url );
     112        } else {
     113            $this->do_remote_get( $amp_url );
     114        }
    94115    }
    95116
  • nginx-helper/trunk/admin/class-nginx-helper-admin.php

    r3071366 r3213676  
    2121 */
    2222class Nginx_Helper_Admin {
    23 
     23   
    2424    /**
    2525     * The ID of this plugin.
     
    3030     */
    3131    private $plugin_name;
    32 
     32   
    3333    /**
    3434     * The version of this plugin.
     
    3939     */
    4040    private $version;
    41 
     41   
    4242    /**
    4343     * Various settings tabs.
     
    4848     */
    4949    private $settings_tabs;
    50 
     50   
    5151    /**
    5252     * Purge options.
     
    5757     */
    5858    public $options;
    59 
     59   
    6060    /**
    6161     * WP-CLI Command.
     
    6666     */
    6767    const WP_CLI_COMMAND = 'nginx-helper';
    68 
     68   
    6969    /**
    7070     * Initialize the class and set its properties.
     
    7575     */
    7676    public function __construct( $plugin_name, $version ) {
    77 
     77       
    7878        $this->plugin_name = $plugin_name;
    7979        $this->version     = $version;
    80 
     80       
     81        $this->options = $this->nginx_helper_settings();
     82    }
     83   
     84    /**
     85     * Initialize the settings tab.
     86     * Required since i18n is used in the settings tab which can be invoked only after init hook since WordPress 6.7
     87     */
     88    public function initialize_setting_tab() {
     89       
    8190        /**
    8291         * Define settings tabs
     
    95104            )
    96105        );
    97 
    98         $this->options = $this->nginx_helper_settings();
    99 
    100     }
    101 
     106    }
     107   
    102108    /**
    103109     * Register the stylesheets for the admin area.
     
    108114     */
    109115    public function enqueue_styles( $hook ) {
    110 
     116       
    111117        /**
    112118         * This function is provided for demonstration purposes only.
     
    120126         * class.
    121127         */
    122 
     128       
    123129        if ( 'settings_page_nginx' !== $hook ) {
    124130            return;
    125131        }
    126 
     132       
    127133        wp_enqueue_style( $this->plugin_name . '-icons', plugin_dir_url( __FILE__ ) . 'icons/css/nginx-fontello.css', array(), $this->version, 'all' );
    128134        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/nginx-helper-admin.css', array(), $this->version, 'all' );
    129 
    130     }
    131 
     135       
     136    }
     137   
    132138    /**
    133139     * Register the JavaScript for the admin area.
     
    138144     */
    139145    public function enqueue_scripts( $hook ) {
    140 
     146       
    141147        /**
    142148         * This function is provided for demonstration purposes only.
     
    150156         * class.
    151157         */
    152 
     158       
    153159        if ( 'settings_page_nginx' !== $hook ) {
    154160            return;
    155161        }
    156 
     162       
    157163        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/nginx-helper-admin.js', array( 'jquery' ), $this->version, false );
    158 
     164       
    159165        $do_localize = array(
    160166            'purge_confirm_string' => esc_html__( 'Purging entire cache is not recommended. Would you like to continue?', 'nginx-helper' ),
    161167        );
    162168        wp_localize_script( $this->plugin_name, 'nginx_helper', $do_localize );
    163 
    164     }
    165 
     169       
     170    }
     171   
    166172    /**
    167173     * Add admin menu.
     
    170176     */
    171177    public function nginx_helper_admin_menu() {
    172 
     178       
    173179        if ( is_multisite() ) {
    174 
     180           
    175181            add_submenu_page(
    176182                'settings.php',
     
    181187                array( &$this, 'nginx_helper_setting_page' )
    182188            );
    183 
     189           
    184190        } else {
    185 
     191           
    186192            add_submenu_page(
    187193                'options-general.php',
     
    192198                array( &$this, 'nginx_helper_setting_page' )
    193199            );
    194 
    195         }
    196 
    197     }
    198 
     200           
     201        }
     202       
     203    }
     204   
    199205    /**
    200206     * Function to add toolbar purge link.
     
    203209     */
    204210    public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
    205 
     211       
    206212        if ( ! current_user_can( 'manage_options' ) ) {
    207213            return;
    208214        }
    209 
     215       
    210216        if ( is_admin() ) {
    211217            $nginx_helper_urls = 'all';
     
    215221            $link_title        = __( 'Purge Current Page', 'nginx-helper' );
    216222        }
    217 
     223       
    218224        $purge_url = add_query_arg(
    219225            array(
     
    222228            )
    223229        );
    224 
     230       
    225231        $nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
    226 
     232       
    227233        $wp_admin_bar->add_menu(
    228234            array(
     
    233239            )
    234240        );
    235 
    236     }
    237 
     241       
     242    }
     243   
    238244    /**
    239245     * Display settings.
     
    246252        include plugin_dir_path( __FILE__ ) . 'partials/nginx-helper-admin-display.php';
    247253    }
    248 
     254   
    249255    /**
    250256     * Default settings.
     
    254260     */
    255261    public function nginx_helper_default_settings() {
    256 
     262       
    257263        return array(
    258264            'enable_purge'                     => 0,
     
    276282            'redis_hostname'                   => '127.0.0.1',
    277283            'redis_port'                       => '6379',
    278             'redis_prefix'                     => 'nginx-cache:',
     284            'redis_prefix'                      => 'nginx-cache:',
     285            'redis_unix_socket'                => '',
     286            'redis_database'                   => 0,
     287            'redis_username'                   => '',
     288            'redis_password'                   => '',
    279289            'purge_url'                        => '',
    280290            'redis_enabled_by_constant'        => 0,
     291            'purge_amp_urls'                   => 1,
     292            'redis_socket_enabled_by_constant' => 0,
     293            'redis_acl_enabled_by_constant'    => 0,
     294            'preload_cache'                    => 0,
     295            'is_cache_preloaded'               => 0
    281296        );
     297       
     298    }
     299   
     300    public function store_default_options() {
     301        $options = get_site_option( 'rt_wp_nginx_helper_options', array() );
     302        $default_settings = $this->nginx_helper_default_settings();
     303       
     304        $removable_default_settings = array(
     305            'redis_port',
     306            'redis_prefix',
     307            'redis_hostname',
     308            'redis_database',
     309            'redis_unix_socket'
     310        );
     311       
     312        // Remove all the keys that are not to be stored by default.
     313        foreach ( $removable_default_settings as $removable_key ) {
     314            unset( $default_settings[ $removable_key ] );
     315        }
     316       
     317        $diffed_options = wp_parse_args( $options, $default_settings );
     318       
     319        add_site_option( 'rt_wp_nginx_helper_options', $diffed_options );
     320    }
    282321
    283     }
    284 
    285322    /**
    286323     * Get settings.
     
    289326     */
    290327    public function nginx_helper_settings() {
    291 
     328       
    292329        $options = get_site_option(
    293330            'rt_wp_nginx_helper_options',
     
    296333                'redis_port'     => '6379',
    297334                'redis_prefix'   => 'nginx-cache:',
     335                'redis_database' => 0,
    298336            )
    299337        );
    300 
     338       
    301339        $data = wp_parse_args(
    302340            $options,
    303341            $this->nginx_helper_default_settings()
    304342        );
    305 
     343       
    306344        $is_redis_enabled = (
    307345            defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) &&
     
    309347            defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' )
    310348        );
     349       
     350        $data['redis_acl_enabled_by_constant']    = defined('RT_WP_NGINX_HELPER_REDIS_USERNAME') && defined('RT_WP_NGINX_HELPER_REDIS_PASSWORD');
     351        $data['redis_socket_enabled_by_constant'] = defined('RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET');
     352        $data['redis_unix_socket']                = $data['redis_socket_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET : $data['redis_unix_socket'];
     353        $data['redis_username']                   = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_USERNAME : $data['redis_username'];
     354        $data['redis_password']                   = $data['redis_acl_enabled_by_constant'] ? RT_WP_NGINX_HELPER_REDIS_PASSWORD : $data['redis_password'];
    311355
    312356        if ( ! $is_redis_enabled ) {
     
    314358        }
    315359
    316         $data['redis_enabled_by_constant'] = $is_redis_enabled;
    317         $data['enable_purge']              = $is_redis_enabled;
    318         $data['cache_method']              = 'enable_redis';
    319         $data['redis_hostname']            = RT_WP_NGINX_HELPER_REDIS_HOSTNAME;
    320         $data['redis_port']                = RT_WP_NGINX_HELPER_REDIS_PORT;
    321         $data['redis_prefix']              = RT_WP_NGINX_HELPER_REDIS_PREFIX;
     360        $data['redis_enabled_by_constant']        = $is_redis_enabled;
     361        $data['enable_purge']                     = $is_redis_enabled;
     362        $data['cache_method']                     = 'enable_redis';
     363        $data['redis_hostname']                   = RT_WP_NGINX_HELPER_REDIS_HOSTNAME;
     364        $data['redis_port']                       = RT_WP_NGINX_HELPER_REDIS_PORT;
     365        $data['redis_prefix']                      = RT_WP_NGINX_HELPER_REDIS_PREFIX;
     366        $data['redis_database']                   = defined('RT_WP_NGINX_HELPER_REDIS_DATABASE') ? RT_WP_NGINX_HELPER_REDIS_DATABASE : 0;
    322367
    323368        return $data;
    324 
    325     }
    326 
     369       
     370    }
     371   
    327372    /**
    328373     * Nginx helper setting link function.
     
    333378     */
    334379    public function nginx_helper_settings_link( $links ) {
    335 
     380       
    336381        if ( is_network_admin() ) {
    337382            $setting_page = 'settings.php';
     
    339384            $setting_page = 'options-general.php';
    340385        }
    341 
     386       
    342387        $settings_link = '<a href="' . network_admin_url( $setting_page . '?page=nginx' ) . '">' . __( 'Settings', 'nginx-helper' ) . '</a>';
    343388        array_unshift( $links, $settings_link );
    344 
     389       
    345390        return $links;
    346 
    347     }
    348 
     391       
     392    }
     393   
    349394    /**
    350395     * Check if the nginx log is enabled.
     
    354399     */
    355400    public function is_nginx_log_enabled() {
    356 
     401       
    357402        $options = get_site_option( 'rt_wp_nginx_helper_options', array() );
    358 
     403       
    359404        if ( ! empty( $options['enable_log'] ) && 1 === (int) $options['enable_log'] ) {
    360405            return true;
    361406        }
    362 
     407       
    363408        if ( defined( 'NGINX_HELPER_LOG' ) && true === NGINX_HELPER_LOG ) {
    364409            return true;
    365410        }
    366 
     411       
    367412        return false;
    368413    }
    369 
     414   
    370415    /**
    371416     * Retrieve the asset path.
     
    375420     */
    376421    public function functional_asset_path() {
    377 
     422       
    378423        $log_path = WP_CONTENT_DIR . '/uploads/nginx-helper/';
    379 
     424       
    380425        return apply_filters( 'nginx_asset_path', $log_path );
    381 
    382     }
    383 
     426       
     427    }
     428   
    384429    /**
    385430     * Retrieve the asset url.
     
    389434     */
    390435    public function functional_asset_url() {
    391 
     436       
    392437        $log_url = WP_CONTENT_URL . '/uploads/nginx-helper/';
    393 
     438       
    394439        return apply_filters( 'nginx_asset_url', $log_url );
    395 
    396     }
    397 
     440       
     441    }
     442   
    398443    /**
    399444     * Get latest news.
     
    402447     */
    403448    public function nginx_helper_get_feeds() {
    404 
     449       
    405450        // Get RSS Feed(s).
    406451        require_once ABSPATH . WPINC . '/feed.php';
    407 
     452       
    408453        $maxitems  = 0;
    409454        $rss_items = array();
    410 
     455       
    411456        // Get a SimplePie feed object from the specified feed source.
    412457        $rss = fetch_feed( 'https://rtcamp.com/blog/feed/' );
    413 
     458       
    414459        if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly.
    415 
     460           
    416461            // Figure out how many total items there are, but limit it to 5.
    417462            $maxitems = $rss->get_item_quantity( 5 );
    418463            // Build an array of all the items, starting with element 0 (first element).
    419464            $rss_items = $rss->get_items( 0, $maxitems );
    420 
     465           
    421466        }
    422467        ?>
     
    426471                echo '<li role="listitem">' . esc_html_e( 'No items', 'nginx-helper' ) . '.</li>';
    427472            } else {
    428 
     473               
    429474                // Loop through each feed item and display each item as a hyperlink.
    430475                foreach ( $rss_items as $item ) {
    431476                    ?>
    432                         <li role="listitem">
    433                             <?php
    434                                 printf(
    435                                     '<a href="%s" title="%s">%s</a>',
    436                                     esc_url( $item->get_permalink() ),
    437                                     esc_attr__( 'Posted ', 'nginx-helper' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ),
    438                                     esc_html( $item->get_title() )
    439                                 );
    440                             ?>
    441                         </li>
     477                    <li role="listitem">
     478                        <?php
     479                        printf(
     480                            '<a href="%s" title="%s">%s</a>',
     481                            esc_url( $item->get_permalink() ),
     482                            esc_attr__( 'Posted ', 'nginx-helper' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ),
     483                            esc_html( $item->get_title() )
     484                        );
     485                        ?>
     486                    </li>
    442487                    <?php
    443488                }
     
    447492        <?php
    448493        die();
    449 
    450     }
    451 
     494       
     495    }
     496   
    452497    /**
    453498     * Add time stamps in html.
    454499     */
    455500    public function add_timestamps() {
    456 
     501       
    457502        global $pagenow;
    458 
     503       
    459504        if ( is_admin() || 1 !== (int) $this->options['enable_purge'] || 1 !== (int) $this->options['enable_stamp'] ) {
    460505            return;
    461506        }
    462 
     507       
    463508        if ( ! empty( $pagenow ) && 'wp-login.php' === $pagenow ) {
    464509            return;
    465510        }
    466 
     511       
    467512        foreach ( headers_list() as $header ) {
    468513            list( $key, $value ) = explode( ':', $header, 2 );
     
    475520            }
    476521        }
    477 
     522       
    478523        /**
    479524         * Don't add timestamp if run from ajax, cron or wpcli.
     
    482527            return;
    483528        }
    484 
     529       
    485530        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    486531            return;
    487532        }
    488 
     533       
    489534        if ( defined( 'WP_CLI' ) && WP_CLI ) {
    490535            return;
    491536        }
    492 
     537       
    493538        $timestamps = "\n<!--" .
    494                 'Cached using Nginx-Helper on ' . current_time( 'mysql' ) . '. ' .
    495                 'It took ' . get_num_queries() . ' queries executed in ' . timer_stop() . ' seconds.' .
    496                 "-->\n" .
    497                 '<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->';
    498 
     539            'Cached using Nginx-Helper on ' . current_time( 'mysql' ) . '. ' .
     540            'It took ' . get_num_queries() . ' queries executed in ' . timer_stop() . ' seconds.' .
     541            "-->\n" .
     542            '<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->';
     543       
    499544        echo wp_kses( $timestamps, array() );
    500 
    501     }
    502 
     545       
     546    }
     547   
    503548    /**
    504549     * Get map
     
    509554     */
    510555    public function get_map() {
    511 
     556       
    512557        if ( ! $this->options['enable_map'] ) {
    513558            return;
    514559        }
    515 
     560       
    516561        if ( is_multisite() ) {
    517 
     562           
    518563            global $wpdb;
    519 
     564           
    520565            $rt_all_blogs = $wpdb->get_results(
    521566                $wpdb->prepare(
     
    524569                )
    525570            );
    526 
     571           
    527572            $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
    528 
     573           
    529574            $rt_domain_map_sites = '';
    530 
     575           
    531576            if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->dmtable}'" ) === $wpdb->dmtable ) { // phpcs:ignore
    532577                $rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
    533578            }
    534 
     579           
    535580            $rt_nginx_map       = '';
    536581            $rt_nginx_map_array = array();
    537 
     582           
    538583            if ( $rt_all_blogs ) {
    539 
     584               
    540585                foreach ( $rt_all_blogs as $blog ) {
    541 
     586                   
    542587                    if ( true === SUBDOMAIN_INSTALL ) {
    543588                        $rt_nginx_map_array[ $blog->domain ] = $blog->blog_id;
    544589                    } else {
    545 
     590                       
    546591                        if ( 1 !== $blog->blog_id ) {
    547592                            $rt_nginx_map_array[ $blog->path ] = $blog->blog_id;
     
    550595                }
    551596            }
    552 
     597           
    553598            if ( $rt_domain_map_sites ) {
    554 
     599               
    555600                foreach ( $rt_domain_map_sites as $site ) {
    556601                    $rt_nginx_map_array[ $site->domain ] = $site->blog_id;
    557602                }
    558603            }
    559 
     604           
    560605            foreach ( $rt_nginx_map_array as $domain => $domain_id ) {
    561606                $rt_nginx_map .= "\t" . $domain . "\t" . $domain_id . ";\n";
    562607            }
    563 
     608           
    564609            return $rt_nginx_map;
    565 
    566         }
    567 
    568     }
    569 
     610           
     611        }
     612       
     613    }
     614   
    570615    /**
    571616     * Update map
    572617     */
    573618    public function update_map() {
    574 
     619       
    575620        if ( is_multisite() ) {
    576 
     621           
    577622            $rt_nginx_map = $this->get_map();
    578 
     623           
    579624            $fp = fopen( $this->functional_asset_path() . 'map.conf', 'w+' );
    580625            if ( $fp ) {
     
    583628            }
    584629        }
    585 
    586     }
    587 
     630       
     631    }
     632   
    588633    /**
    589634     * Purge url when post status is changed.
     
    597642     */
    598643    public function set_future_post_option_on_future_status( $new_status, $old_status, $post ) {
    599 
     644       
    600645        global $blog_id, $nginx_purger;
    601 
     646       
    602647        $exclude_post_types = array( 'nav_menu_item' );
    603 
     648       
    604649        if ( in_array( $post->post_type, $exclude_post_types, true ) ) {
    605650            return;
    606651        }
    607 
    608         if ( ! $this->options['enable_purge'] ) {
    609             return;
    610         }
    611 
     652       
     653        if ( ! $this->options['enable_purge'] || $this->is_import_request() ) {
     654            return;
     655        }
     656       
    612657        $purge_status = array( 'publish', 'future' );
    613 
     658       
    614659        if ( in_array( $old_status, $purge_status, true ) || in_array( $new_status, $purge_status, true ) ) {
    615 
     660           
    616661            $nginx_purger->log( 'Purge post on transition post STATUS from ' . $old_status . ' to ' . $new_status );
    617662            $nginx_purger->purge_post( $post->ID );
    618 
    619         }
    620 
     663           
     664        }
     665       
    621666        if (
    622667            'future' === $new_status && $post && 'future' === $post->post_status &&
     
    629674            )
    630675        ) {
    631 
     676           
    632677            $nginx_purger->log( 'Set/update future_posts option ( post id = ' . $post->ID . ' and blog id = ' . $blog_id . ' )' );
    633678            $this->options['future_posts'][ $blog_id ][ $post->ID ] = strtotime( $post->post_date_gmt ) + 60;
    634679            update_site_option( 'rt_wp_nginx_helper_options', $this->options );
    635 
    636         }
    637 
    638     }
    639 
     680           
     681        }
     682       
     683    }
     684   
    640685    /**
    641686     * Unset future post option on delete
     
    647692     */
    648693    public function unset_future_post_option_on_delete( $post_id ) {
    649 
     694       
    650695        global $blog_id, $nginx_purger;
    651 
     696       
    652697        if (
    653698            ! $this->options['enable_purge'] ||
     
    659704            return;
    660705        }
    661 
     706       
    662707        $nginx_purger->log( 'Unset future_posts option ( post id = ' . $post_id . ' and blog id = ' . $blog_id . ' )' );
    663 
     708       
    664709        unset( $this->options['future_posts'][ $blog_id ][ $post_id ] );
    665 
     710       
    666711        if ( ! count( $this->options['future_posts'][ $blog_id ] ) ) {
    667712            unset( $this->options['future_posts'][ $blog_id ] );
    668713        }
    669 
     714       
    670715        update_site_option( 'rt_wp_nginx_helper_options', $this->options );
    671716    }
    672 
     717   
    673718    /**
    674719     * Update map when new blog added in multisite.
     
    679724     */
    680725    public function update_new_blog_options( $blog_id ) {
    681 
     726       
    682727        global $nginx_purger;
    683 
     728       
    684729        $nginx_purger->log( "New site added ( id $blog_id )" );
    685730        $this->update_map();
     
    688733        update_blog_option( $blog_id, 'rt_wp_nginx_helper_options', $helper_options );
    689734        $nginx_purger->log( "Default options updated for the new blog ( id $blog_id )" );
    690 
    691     }
    692 
     735       
     736    }
     737   
    693738    /**
    694739     * Purge all urls.
     
    699744     */
    700745    public function purge_all() {
    701 
     746       
     747        if ( $this->is_import_request() ) {
     748            return;
     749        }
     750       
    702751        global $nginx_purger, $wp;
    703 
     752       
    704753        $method = null;
    705754        if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
    706755            $method = wp_strip_all_tags( $_SERVER['REQUEST_METHOD'] );
    707756        }
    708 
     757       
    709758        $action = '';
    710759        if ( 'POST' === $method ) {
     
    717766            }
    718767        }
    719 
     768       
    720769        if ( empty( $action ) ) {
    721770            return;
    722771        }
    723 
     772       
    724773        if ( ! current_user_can( 'manage_options' ) ) {
    725774            wp_die( 'Sorry, you do not have the necessary privileges to edit these options.' );
    726775        }
    727 
     776       
    728777        if ( 'done' === $action ) {
    729 
     778           
    730779            add_action( 'admin_notices', array( &$this, 'display_notices' ) );
    731780            add_action( 'network_admin_notices', array( &$this, 'display_notices' ) );
    732781            return;
    733 
    734         }
    735 
     782           
     783        }
     784       
    736785        check_admin_referer( 'nginx_helper-purge_all' );
    737 
     786       
    738787        $current_url = user_trailingslashit( home_url( $wp->request ) );
    739 
     788       
    740789        if ( ! is_admin() ) {
    741790            $action       = 'purge_current_page';
     
    744793            $redirect_url = add_query_arg( array( 'nginx_helper_action' => 'done' ) );
    745794        }
    746 
     795       
    747796        switch ( $action ) {
    748797            case 'purge':
     
    753802                break;
    754803        }
    755 
     804       
    756805        if ( 'purge' === $action ) {
    757 
     806           
    758807            /**
    759808             * Fire an action after the entire cache has been purged whatever caching type is used.
     
    762811             */
    763812            do_action( 'rt_nginx_helper_after_purge_all' );
    764 
    765         }
    766 
     813           
     814        }
     815       
    767816        wp_redirect( esc_url_raw( $redirect_url ) );
    768817        exit();
    769 
    770     }
    771 
     818       
     819    }
     820   
    772821    /**
    773822     * Dispay plugin notices.
     
    776825        echo '<div class="updated"><p>' . esc_html__( 'Purge initiated', 'nginx-helper' ) . '</p></div>';
    777826    }
    778 
     827   
     828    /**
     829     * Preloads the cache for the website.
     830     *
     831     * @return void
     832     */
     833    public function preload_cache() {
     834        $is_cache_preloaded    = $this->options['is_cache_preloaded'];
     835        $preload_cache_enabled = $this->options['preload_cache'];
     836       
     837        if ( $preload_cache_enabled && false === boolval( $is_cache_preloaded ) ) {
     838            $this->options['is_cache_preloaded'] = true;
     839           
     840            update_site_option( 'rt_wp_nginx_helper_options', $this->options );
     841            $this->preload_cache_from_sitemap();
     842        }
     843    }
     844   
     845    /**
     846     * This function preloads the cache from sitemap url.
     847     *
     848     * @return void
     849     */
     850    private function preload_cache_from_sitemap() {
     851       
     852        $sitemap_urls = $this->get_index_sitemap_urls();
     853        $all_urls     = array();
     854       
     855        foreach ( $sitemap_urls as $sitemap_url ) {
     856            $urls     = $this->extract_sitemap_urls( $sitemap_url );
     857            $all_urls = array_merge( $all_urls, $urls );
     858        }
     859       
     860        $args = array(
     861            'timeout'   => 1,
     862            'blocking'  => false,
     863            'sslverify' => false,
     864        );
     865       
     866        foreach ( $all_urls as $url ) {
     867            wp_remote_get( esc_url_raw( $url ), $args );
     868        }
     869       
     870    }
     871   
     872    /**
     873     * Fetches all the sitemap urls for the site.
     874     *
     875     * @return array
     876     */
     877    private function get_index_sitemap_urls() {
     878        $sitemaps = wp_sitemaps_get_server()->index->get_sitemap_list();
     879        $urls     = array();
     880        foreach ( $sitemaps as $sitemap ) {
     881            $urls[] = $sitemap['loc'];
     882        }
     883        return $urls;
     884    }
     885   
     886    /**
     887     * Parse sitemap content and extract all URLs.
     888     *
     889     * @param string $sitemap_url The URL of the sitemap.
     890     * @return array|WP_Error An array of URLs or WP_Error on failure.
     891     */
     892    private function extract_sitemap_urls( $sitemap_url ) {
     893        $response = wp_remote_get( $sitemap_url );
     894       
     895        $urls = array();
     896       
     897        if ( is_wp_error( $response ) ) {
     898            return $urls;
     899        }
     900       
     901        $sitemap_content = wp_remote_retrieve_body( $response );
     902       
     903        libxml_use_internal_errors( true );
     904        $xml = simplexml_load_string( $sitemap_content );
     905       
     906        if ( false === $xml ) {
     907            return new WP_Error( 'sitemap_parse_error', esc_html__( 'Failed to parse the sitemap XML', 'nginx-helper' ) );
     908        }
     909       
     910        $urls = array();
     911       
     912        if ( false === $xml ) {
     913            return $urls;
     914        }
     915       
     916        foreach ( $xml->url as $url ) {
     917            $urls[] = (string) $url->loc;
     918        }
     919       
     920        return $urls;
     921    }
     922   
     923    /**
     924    * Determines if the current request is for importing Posts/ WordPress content.
     925    *
     926    * @return bool True if the request is for importing, false otherwise.
     927    */
     928    public function is_import_request() {
     929        $import_query_var   = sanitize_text_field( wp_unslash( $_GET['import'] ?? '' ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is already in the admin dashboard.
     930        $has_import_started = did_action( 'import_start' );
     931       
     932        return ( defined( 'WP_IMPORTING' ) && true === WP_IMPORTING )
     933            || 0 !== $has_import_started
     934            || ! empty( $import_query_var );
     935    }
     936   
     937   
    779938}
  • nginx-helper/trunk/admin/class-phpredis-purger.php

    r2222658 r3213676  
    4040
    4141            $this->redis_object = new Redis();
     42           
     43            $redis_acl = array();
     44           
     45            $username = $nginx_helper_admin->options['redis_username'];
     46            $password = $nginx_helper_admin->options['redis_password'];
     47           
     48            if( $username && $password ) {
     49                $redis_acl['auth'] = array( $username, $password );
     50            }
     51           
     52            $hostname = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_hostname'] : $nginx_helper_admin->options['redis_unix_socket'];
     53            $port     = empty( $nginx_helper_admin->options['redis_unix_socket'] ) ? $nginx_helper_admin->options['redis_port'] : 0;
     54           
    4255            $this->redis_object->connect(
    43                 $nginx_helper_admin->options['redis_hostname'],
    44                 $nginx_helper_admin->options['redis_port'],
    45                 5
     56                $hostname,
     57                $port,
     58                5,
     59                null,
     60                0,
     61                0,
     62                $redis_acl
    4663            );
     64           
     65            if( $nginx_helper_admin->options['redis_database'] !== 0 ) {
     66                $this->redis_object->select($nginx_helper_admin->options['redis_database']);
     67            }
    4768
    4869        } catch ( Exception $e ) {
  • nginx-helper/trunk/admin/class-predis-purger.php

    r2222658 r3213676  
    3838
    3939        Predis\Autoloader::register();
    40 
     40       
     41        $predis_args = array();
     42       
     43        $username = $nginx_helper_admin->options['redis_username'];
     44        $password = $nginx_helper_admin->options['redis_password'];
     45       
     46        if( ! empty( $nginx_helper_admin->options['redis_unix_socket'] ) ) {
     47            $predis_args['path'] = $nginx_helper_admin->options['redis_unix_socket'];
     48        } else {
     49            $predis_args['host'] = $nginx_helper_admin->options['redis_hostname'];;
     50            $predis_args['port'] = $nginx_helper_admin->options['redis_port'];
     51        }
     52       
     53        if ( $username && $password ) {
     54            $predis_args['username'] = $username;
     55            $predis_args['password'] = $password;
     56        }
     57       
    4158        // redis server parameter.
    42         $this->redis_object = new Predis\Client(
    43             array(
    44                 'host' => $nginx_helper_admin->options['redis_hostname'],
    45                 'port' => $nginx_helper_admin->options['redis_port'],
    46             )
    47         );
     59        $this->redis_object = new Predis\Client( $predis_args );
    4860
    4961        try {
    5062            $this->redis_object->connect();
     63           
     64            if( 0 !== $nginx_helper_admin->options['redis_database'] ) {
     65                $this->redis_object->select( $nginx_helper_admin->options['redis_database'] );
     66            }
    5167        } catch ( Exception $e ) {
    5268            $this->log( $e->getMessage(), 'ERROR' );
    53         }
     69            return;
     70        }
     71       
    5472
    5573    }
  • nginx-helper/trunk/admin/css/nginx-helper-admin.css

    r3023296 r3213676  
    55
    66.clearfix {
    7     *zoom: 1;
     7    zoom: 1;
    88}
    99.clearfix:before,
     
    104104    margin-left: 23px;
    105105}
     106
     107.password-input {
     108    padding-right: 40px;
     109}
     110
     111.password-show-hide-btn {
     112    background-color: transparent;
     113    border: 0;
     114    cursor: pointer;
     115    display: inline-block;
     116}
     117
     118.password-wrapper {
     119    display: flex;
     120}
  • nginx-helper/trunk/admin/js/nginx-helper-admin.js

    r2222658 r3213676  
    7676            );
    7777
     78            jQuery('.password-show-hide-btn').on('click', function() {
     79                var passwordInput = $(this).siblings('.password-input');
     80                var icon = $(this).find('.password-input-icon');
     81   
     82                if (passwordInput.attr('type') === 'password') {
     83                    passwordInput.attr('type', 'text');
     84                    icon.removeClass('dashicons-hidden').addClass('dashicons-visibility');
     85                } else {
     86                    passwordInput.attr('type', 'password');
     87                    icon.removeClass('dashicons-visibility').addClass('dashicons-hidden');
     88                }
     89            });
     90
    7891            /**
    7992             * Show OR Hide options on option checkbox
  • nginx-helper/trunk/admin/partials/nginx-helper-general-options.php

    r3071366 r3213676  
    2323    'redis_port',
    2424    'redis_prefix',
     25    'redis_database',
     26    'redis_username',
     27    'redis_password',
     28    'redis_unix_socket',
     29    'redis_socket_enabled_by_constant',
     30    'redis_acl_enabled_by_constant',
    2531    'purge_homepage_on_edit',
    2632    'purge_homepage_on_del',
     
    4147    'purge_feeds',
    4248    'smart_http_expire_form_nonce',
     49    'purge_amp_urls',
     50    'preload_cache',
    4351);
    4452
     
    125133                        <input type="checkbox" value="1" id="enable_purge" name="enable_purge" <?php checked( $nginx_helper_settings['enable_purge'], 1 ); ?> />
    126134                        <label for="enable_purge"><?php esc_html_e( 'Enable Purge', 'nginx-helper' ); ?></label>
     135                    </td>
     136                </tr>
     137                <tr valign="top">
     138                    <td>
     139                        <input type="checkbox" value="1" id="preload_cache" name="preload_cache" <?php checked( $nginx_helper_settings['preload_cache'], 1 ); ?> />
     140                        <label for="preload_cache"><?php esc_html_e( 'Preload Cache', 'nginx-helper' ); ?></label>
    127141                    </td>
    128142                </tr>
     
    247261                            <th><label for="redis_hostname"><?php esc_html_e( 'Hostname', 'nginx-helper' ); ?></label></th>
    248262                            <td>
    249                                 <input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     263                                <input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> />
    250264                                <?php
    251265                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     
    255269                                    echo '</p>';
    256270
     271                                }
     272                                ?>
     273                                <?php
     274                                if ( $nginx_helper_settings['redis_unix_socket'] ) {
     275                                    echo '<p class="description">';
     276                                    esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' );
     277                                    echo '</p>';
    257278                                }
    258279                                ?>
     
    262283                            <th><label for="redis_port"><?php esc_html_e( 'Port', 'nginx-helper' ); ?></label></th>
    263284                            <td>
    264                                 <input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     285                                <input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] || $nginx_helper_settings['redis_unix_socket'] ) ? 'readonly="readonly"' : ''; ?> />
    265286                                <?php
    266287                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     
    270291                                    echo '</p>';
    271292
     293                                }
     294                                ?>
     295                                <?php
     296                                if ( $nginx_helper_settings['redis_unix_socket'] ) {
     297                                   
     298                                    echo '<p class="description">';
     299                                    esc_html_e( 'Overridden by unix socket path.', 'nginx-helper' );
     300                                    echo '</p>';
     301                                   
     302                                }
     303                                ?>
     304                            </td>
     305                        </tr>
     306                        <tr>
     307                            <th><label for="redis_unix_socket"><?php esc_html_e( 'Socket Path', 'nginx-helper' ); ?></label></th>
     308                            <td>
     309                                <input id="redis_unix_socket" class="medium-text" type="text" name="redis_unix_socket" value="<?php echo esc_attr( $nginx_helper_settings['redis_unix_socket'] ); ?>" <?php echo ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     310                                <?php
     311                                if ( $nginx_helper_settings['redis_socket_enabled_by_constant'] ) {
     312                                   
     313                                    echo '<p class="description">';
     314                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     315                                    echo '</p>';
     316                                   
    272317                                }
    273318                                ?>
     
    285330                                    echo '</p>';
    286331
     332                                }
     333                                ?>
     334                            </td>
     335                        </tr>
     336                        <tr>
     337                            <th><label for="redis_database"><?php esc_html_e( 'Database', 'nginx-helper' ); ?></label></th>
     338                            <td>
     339                                <input id="redis_database" class="medium-text" type="text" name="redis_database" value="<?php echo esc_attr( $nginx_helper_settings['redis_database'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     340                                <?php
     341                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     342                                   
     343                                    echo '<p class="description">';
     344                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     345                                    echo '</p>';
     346                                   
     347                                }
     348                                ?>
     349                            </td>
     350                        </tr>
     351
     352                        <tr>
     353                            <th><label for="redis_username"><?php esc_html_e( 'Username', 'nginx-helper' ); ?></label></th>
     354                            <td>
     355                                <input id="redis_username" class="medium-text" type="text" name="redis_username" value="<?php echo esc_attr( $nginx_helper_settings['redis_username'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     356                                <?php
     357                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     358                                   
     359                                    echo '<p class="description">';
     360                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     361                                    echo '</p>';
     362                                   
     363                                }
     364                                ?>
     365                            </td>
     366                        </tr>
     367
     368                        <tr>
     369                            <th><label for="redis_password"><?php esc_html_e( 'Password', 'nginx-helper' ); ?></label></th>
     370                            <td>
     371                                <div class="password-wrapper">
     372                                    <input id="redis_password" class="medium-text password-input" type="password" name="redis_password" value="<?php echo esc_attr( $nginx_helper_settings['redis_password'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
     373                                    <button type="button" class="password-show-hide-btn"><span class="dashicons dashicons-hidden password-input-icon"></span></button>
     374                                </div>
     375                                <?php
     376                                if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
     377                                    echo '<p class="description">';
     378                                    esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
     379                                    echo '</p>';
     380                                   
    287381                                }
    288382                                ?>
     
    542636                                            array( 'strong' => array() )
    543637                                        );
     638                                    ?>
     639                                </label>
     640                                <br />
     641                            </fieldset>
     642                        </td>
     643                    </tr>
     644                </table>
     645                <table class="form-table rtnginx-table">
     646                    <tr valign="top">
     647                        <th scope="row">
     648                            <h4>
     649                <?php esc_html_e( 'Purge AMP URL:', 'nginx-helper' ); ?>
     650                            </h4>
     651                        </th>
     652                        <td>
     653                            <fieldset>
     654                                <legend class="screen-reader-text">
     655                                    <span>
     656                                        &nbsp;
     657                                        <?php
     658                                        esc_html_e( 'purge amp urls', 'nginx-helper' );
     659                                        ?>
     660                                    </span>
     661                                </legend>
     662                                <label for="purge_amp_urls">
     663                                    <input type="checkbox" value="1" id="purge_amp_urls" name="purge_amp_urls" <?php checked( $nginx_helper_settings['purge_amp_urls'], 1 ); ?> />
     664                                    &nbsp;
     665                                    <?php
     666                                    echo wp_kses(
     667                                        __( 'purge <strong>amp urls</strong> along with <strong>posts</strong> & <strong>pages</strong>.', 'nginx-helper' ),
     668                                        array( 'strong' => array() )
     669                                    );
    544670                                    ?>
    545671                                </label>
  • nginx-helper/trunk/includes/class-nginx-helper-activator.php

    r1976548 r3213676  
    5858
    5959        wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
     60       
     61        if( method_exists( $nginx_helper_admin, 'store_default_options' ) ) {
     62            $nginx_helper_admin->store_default_options();
     63        }
    6064
    6165    }
  • nginx-helper/trunk/includes/class-nginx-helper.php

    r3071366 r3213676  
    7878
    7979        $this->plugin_name = 'nginx-helper';
    80         $this->version     = '2.2.5';
     80        $this->version     = '2.3.0';
    8181        $this->minimum_wp  = '3.0';
    8282
     
    170170
    171171        $nginx_helper_admin = new Nginx_Helper_Admin( $this->get_plugin_name(), $this->get_version() );
    172 
     172        $this->loader->add_action( 'init', $nginx_helper_admin, 'initialize_setting_tab' );
    173173        // Defines global variables.
    174174        if ( ! empty( $nginx_helper_admin->options['cache_method'] ) && 'enable_redis' === $nginx_helper_admin->options['cache_method'] ) {
     
    228228        // expose action to allow other plugins to purge the cache.
    229229        $this->loader->add_action( 'rt_nginx_helper_purge_all', $nginx_purger, 'purge_all' );
     230       
     231        // add action to preload the cache
     232        $this->loader->add_action( 'admin_init', $nginx_helper_admin, 'preload_cache' );
    230233    }
    231234
  • nginx-helper/trunk/languages/nginx-helper.po

    r3071366 r3213676  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Nginx Helper 2.2.5\n"
     5"Project-Id-Version: Nginx Helper 2.3.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nginx-helper\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2024-04-15T10:26:40+00:00\n"
     12"POT-Creation-Date: 2024-12-19T06:01:42+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.9.0\n"
     14"X-Generator: WP-CLI 2.11.0\n"
    1515"X-Domain: nginx-helper\n"
    1616
    1717#. Plugin Name of the plugin
    18 #: admin/class-nginx-helper-admin.php:177
    19 #: admin/class-nginx-helper-admin.php:178
    20 #: admin/class-nginx-helper-admin.php:188
    21 #: admin/class-nginx-helper-admin.php:189
     18#: nginx-helper.php
     19#: admin/class-nginx-helper-admin.php:183
     20#: admin/class-nginx-helper-admin.php:184
     21#: admin/class-nginx-helper-admin.php:194
     22#: admin/class-nginx-helper-admin.php:195
    2223msgid "Nginx Helper"
    2324msgstr ""
    2425
    2526#. Plugin URI of the plugin
     27#: nginx-helper.php
    2628msgid "https://rtcamp.com/nginx-helper/"
    2729msgstr ""
    2830
    2931#. Description of the plugin
     32#: nginx-helper.php
    3033msgid "Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things."
    3134msgstr ""
    3235
    3336#. Author of the plugin
     37#: nginx-helper.php
    3438msgid "rtCamp"
    3539msgstr ""
    3640
    3741#. Author URI of the plugin
     42#: nginx-helper.php
    3843msgid "https://rtcamp.com"
    3944msgstr ""
    4045
    41 #: admin/class-nginx-helper-admin.php:88
     46#: admin/class-nginx-helper-admin.php:97
    4247msgid "General"
    4348msgstr ""
    4449
    45 #: admin/class-nginx-helper-admin.php:92
     50#: admin/class-nginx-helper-admin.php:101
    4651msgid "Support"
    4752msgstr ""
    4853
    49 #: admin/class-nginx-helper-admin.php:160
     54#: admin/class-nginx-helper-admin.php:166
    5055msgid "Purging entire cache is not recommended. Would you like to continue?"
    5156msgstr ""
    5257
    53 #: admin/class-nginx-helper-admin.php:212
     58#: admin/class-nginx-helper-admin.php:218
    5459msgid "Purge Cache"
    5560msgstr ""
    5661
    57 #: admin/class-nginx-helper-admin.php:215
     62#: admin/class-nginx-helper-admin.php:221
    5863msgid "Purge Current Page"
    5964msgstr ""
    6065
    61 #: admin/class-nginx-helper-admin.php:342
     66#: admin/class-nginx-helper-admin.php:387
    6267msgid "Settings"
    6368msgstr ""
    6469
    65 #: admin/class-nginx-helper-admin.php:426
     70#: admin/class-nginx-helper-admin.php:471
    6671msgid "No items"
    6772msgstr ""
    6873
    69 #: admin/class-nginx-helper-admin.php:437
     74#: admin/class-nginx-helper-admin.php:482
    7075msgid "Posted "
    7176msgstr ""
    7277
    73 #: admin/class-nginx-helper-admin.php:776
     78#: admin/class-nginx-helper-admin.php:825
    7479msgid "Purge initiated"
     80msgstr ""
     81
     82#: admin/class-nginx-helper-admin.php:907
     83msgid "Failed to parse the sitemap XML"
    7584msgstr ""
    7685
     
    237246msgstr ""
    238247
    239 #: admin/partials/nginx-helper-general-options.php:82
     248#: admin/partials/nginx-helper-general-options.php:90
    240249msgid "Log file size must be a number."
    241250msgstr ""
    242251
    243 #: admin/partials/nginx-helper-general-options.php:92
     252#: admin/partials/nginx-helper-general-options.php:100
    244253msgid "Settings saved."
    245254msgstr ""
    246255
    247 #: admin/partials/nginx-helper-general-options.php:119
     256#: admin/partials/nginx-helper-general-options.php:127
    248257msgid "Purging Options"
    249258msgstr ""
    250259
    251 #: admin/partials/nginx-helper-general-options.php:126
     260#: admin/partials/nginx-helper-general-options.php:134
    252261msgid "Enable Purge"
    253262msgstr ""
    254263
    255 #: admin/partials/nginx-helper-general-options.php:136
     264#: admin/partials/nginx-helper-general-options.php:140
     265msgid "Preload Cache"
     266msgstr ""
     267
     268#: admin/partials/nginx-helper-general-options.php:150
    256269msgid "Caching Method"
    257270msgstr ""
    258271
    259 #: admin/partials/nginx-helper-general-options.php:148
     272#: admin/partials/nginx-helper-general-options.php:162
    260273msgid "nginx Fastcgi cache"
    261274msgstr ""
    262275
    263 #: admin/partials/nginx-helper-general-options.php:150
     276#: admin/partials/nginx-helper-general-options.php:164
    264277msgid "External settings for nginx"
    265278msgstr ""
    266279
    267 #: admin/partials/nginx-helper-general-options.php:151
     280#: admin/partials/nginx-helper-general-options.php:165
    268281msgid "requires external settings for nginx"
    269282msgstr ""
    270283
    271 #: admin/partials/nginx-helper-general-options.php:161
     284#: admin/partials/nginx-helper-general-options.php:175
    272285msgid "Redis cache"
    273286msgstr ""
    274287
    275 #: admin/partials/nginx-helper-general-options.php:171
     288#: admin/partials/nginx-helper-general-options.php:185
    276289msgid "Purge Method"
    277290msgstr ""
    278291
    279 #: admin/partials/nginx-helper-general-options.php:181
    280 #: admin/partials/nginx-helper-general-options.php:361
     292#: admin/partials/nginx-helper-general-options.php:195
     293#: admin/partials/nginx-helper-general-options.php:455
    281294msgid "when a post/page/custom post is published."
    282295msgstr ""
    283296
    284 #: admin/partials/nginx-helper-general-options.php:191
     297#: admin/partials/nginx-helper-general-options.php:205
    285298msgid "Using a GET request to"
    286299msgstr ""
    287300
    288 #: admin/partials/nginx-helper-general-options.php:192
     301#: admin/partials/nginx-helper-general-options.php:206
    289302msgid "(Default option)"
    290303msgstr ""
    291304
    292305#. translators: %s Nginx cache purge module link.
    293 #: admin/partials/nginx-helper-general-options.php:203
     306#: admin/partials/nginx-helper-general-options.php:217
    294307msgid "Uses the %s module."
    295308msgstr ""
    296309
    297 #: admin/partials/nginx-helper-general-options.php:221
     310#: admin/partials/nginx-helper-general-options.php:235
    298311msgid "Delete local server cache files"
    299312msgstr ""
    300313
    301 #: admin/partials/nginx-helper-general-options.php:227
     314#: admin/partials/nginx-helper-general-options.php:241
    302315msgid "Checks for matching cache file in <strong>RT_WP_NGINX_HELPER_CACHE_PATH</strong>. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key \"$scheme$request_method$host$request_uri\")."
    303316msgstr ""
    304317
    305 #: admin/partials/nginx-helper-general-options.php:242
     318#: admin/partials/nginx-helper-general-options.php:256
    306319msgid "Redis Settings"
    307320msgstr ""
    308321
    309 #: admin/partials/nginx-helper-general-options.php:247
     322#: admin/partials/nginx-helper-general-options.php:261
    310323msgid "Hostname"
    311324msgstr ""
    312325
    313 #: admin/partials/nginx-helper-general-options.php:254
    314 #: admin/partials/nginx-helper-general-options.php:269
    315 #: admin/partials/nginx-helper-general-options.php:284
     326#: admin/partials/nginx-helper-general-options.php:268
     327#: admin/partials/nginx-helper-general-options.php:290
     328#: admin/partials/nginx-helper-general-options.php:314
     329#: admin/partials/nginx-helper-general-options.php:329
     330#: admin/partials/nginx-helper-general-options.php:344
     331#: admin/partials/nginx-helper-general-options.php:360
     332#: admin/partials/nginx-helper-general-options.php:378
    316333msgid "Overridden by constant variables."
    317334msgstr ""
    318335
    319 #: admin/partials/nginx-helper-general-options.php:262
     336#: admin/partials/nginx-helper-general-options.php:276
     337#: admin/partials/nginx-helper-general-options.php:299
     338msgid "Overridden by unix socket path."
     339msgstr ""
     340
     341#: admin/partials/nginx-helper-general-options.php:283
    320342msgid "Port"
    321343msgstr ""
    322344
    323 #: admin/partials/nginx-helper-general-options.php:277
     345#: admin/partials/nginx-helper-general-options.php:307
     346msgid "Socket Path"
     347msgstr ""
     348
     349#: admin/partials/nginx-helper-general-options.php:322
    324350msgid "Prefix"
    325351msgstr ""
    326352
    327 #: admin/partials/nginx-helper-general-options.php:297
     353#: admin/partials/nginx-helper-general-options.php:337
     354msgid "Database"
     355msgstr ""
     356
     357#: admin/partials/nginx-helper-general-options.php:353
     358msgid "Username"
     359msgstr ""
     360
     361#: admin/partials/nginx-helper-general-options.php:369
     362msgid "Password"
     363msgstr ""
     364
     365#: admin/partials/nginx-helper-general-options.php:391
    328366msgid "Purging Conditions"
    329367msgstr ""
    330368
    331 #: admin/partials/nginx-helper-general-options.php:302
     369#: admin/partials/nginx-helper-general-options.php:396
    332370msgid "Purge Homepage:"
    333371msgstr ""
    334372
    335 #: admin/partials/nginx-helper-general-options.php:309
     373#: admin/partials/nginx-helper-general-options.php:403
    336374msgid "when a post/page/custom post is modified or added."
    337375msgstr ""
    338376
    339 #: admin/partials/nginx-helper-general-options.php:318
    340 #: admin/partials/nginx-helper-general-options.php:445
     377#: admin/partials/nginx-helper-general-options.php:412
     378#: admin/partials/nginx-helper-general-options.php:539
    341379msgid "when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>."
    342380msgstr ""
    343381
    344 #: admin/partials/nginx-helper-general-options.php:330
     382#: admin/partials/nginx-helper-general-options.php:424
    345383msgid "when an existing post/page/custom post is modified."
    346384msgstr ""
    347385
    348 #: admin/partials/nginx-helper-general-options.php:339
     386#: admin/partials/nginx-helper-general-options.php:433
    349387msgid "when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>"
    350388msgstr ""
    351389
    352 #: admin/partials/nginx-helper-general-options.php:353
     390#: admin/partials/nginx-helper-general-options.php:447
    353391msgid "Purge Post/Page/Custom Post Type:"
    354392msgstr ""
    355393
    356 #: admin/partials/nginx-helper-general-options.php:370
     394#: admin/partials/nginx-helper-general-options.php:464
    357395msgid "when a <strong>post</strong> is <strong>published</strong>."
    358396msgstr ""
    359397
    360 #: admin/partials/nginx-helper-general-options.php:382
    361 #: admin/partials/nginx-helper-general-options.php:479
     398#: admin/partials/nginx-helper-general-options.php:476
     399#: admin/partials/nginx-helper-general-options.php:573
    362400msgid "when a comment is approved/published."
    363401msgstr ""
    364402
    365 #: admin/partials/nginx-helper-general-options.php:391
    366 #: admin/partials/nginx-helper-general-options.php:488
     403#: admin/partials/nginx-helper-general-options.php:485
     404#: admin/partials/nginx-helper-general-options.php:582
    367405msgid "when a <strong>comment</strong> is <strong>approved/published</strong>."
    368406msgstr ""
    369407
    370 #: admin/partials/nginx-helper-general-options.php:403
    371 #: admin/partials/nginx-helper-general-options.php:500
     408#: admin/partials/nginx-helper-general-options.php:497
     409#: admin/partials/nginx-helper-general-options.php:594
    372410msgid "when a comment is unapproved/deleted."
    373411msgstr ""
    374412
    375 #: admin/partials/nginx-helper-general-options.php:412
    376 #: admin/partials/nginx-helper-general-options.php:509
     413#: admin/partials/nginx-helper-general-options.php:506
     414#: admin/partials/nginx-helper-general-options.php:603
    377415msgid "when a <strong>comment</strong> is <strong>unapproved/deleted</strong>."
    378416msgstr ""
    379417
    380 #: admin/partials/nginx-helper-general-options.php:426
     418#: admin/partials/nginx-helper-general-options.php:520
    381419msgid "Purge Archives:"
    382420msgstr ""
    383421
    384 #: admin/partials/nginx-helper-general-options.php:428
     422#: admin/partials/nginx-helper-general-options.php:522
    385423msgid "(date, category, tag, author, custom taxonomies)"
    386424msgstr ""
    387425
    388 #: admin/partials/nginx-helper-general-options.php:436
     426#: admin/partials/nginx-helper-general-options.php:530
    389427msgid "when an post/page/custom post is modified or added"
    390428msgstr ""
    391429
    392 #: admin/partials/nginx-helper-general-options.php:457
     430#: admin/partials/nginx-helper-general-options.php:551
    393431msgid "when an existing post/page/custom post is trashed."
    394432msgstr ""
    395433
    396 #: admin/partials/nginx-helper-general-options.php:466
     434#: admin/partials/nginx-helper-general-options.php:560
    397435msgid "when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>."
    398436msgstr ""
    399437
    400 #: admin/partials/nginx-helper-general-options.php:523
     438#: admin/partials/nginx-helper-general-options.php:617
    401439msgid "Purge Feeds:"
    402440msgstr ""
    403441
    404 #: admin/partials/nginx-helper-general-options.php:532
     442#: admin/partials/nginx-helper-general-options.php:626
    405443msgid "purge feeds"
    406444msgstr ""
    407445
    408 #: admin/partials/nginx-helper-general-options.php:541
     446#: admin/partials/nginx-helper-general-options.php:635
    409447msgid "purge <strong>feeds</strong> along with <strong>posts</strong> & <strong>pages</strong>."
    410448msgstr ""
    411449
    412 #: admin/partials/nginx-helper-general-options.php:554
     450#: admin/partials/nginx-helper-general-options.php:649
     451msgid "Purge AMP URL:"
     452msgstr ""
     453
     454#: admin/partials/nginx-helper-general-options.php:658
     455msgid "purge amp urls"
     456msgstr ""
     457
     458#: admin/partials/nginx-helper-general-options.php:667
     459msgid "purge <strong>amp urls</strong> along with <strong>posts</strong> & <strong>pages</strong>."
     460msgstr ""
     461
     462#: admin/partials/nginx-helper-general-options.php:680
    413463msgid "Custom Purge URL:"
    414464msgstr ""
    415465
    416 #: admin/partials/nginx-helper-general-options.php:560
     466#: admin/partials/nginx-helper-general-options.php:686
    417467msgid "Add one URL per line. URL should not contain domain name."
    418468msgstr ""
    419469
    420 #: admin/partials/nginx-helper-general-options.php:563
     470#: admin/partials/nginx-helper-general-options.php:689
    421471msgid "Eg: To purge http://example.com/sample-page/ add <strong>/sample-page/</strong> in above textarea."
    422472msgstr ""
    423473
    424 #: admin/partials/nginx-helper-general-options.php:567
     474#: admin/partials/nginx-helper-general-options.php:693
    425475msgid "'*' will only work with redis cache server."
    426476msgstr ""
    427477
    428 #: admin/partials/nginx-helper-general-options.php:577
     478#: admin/partials/nginx-helper-general-options.php:703
    429479msgid "Debug Options"
    430480msgstr ""
    431481
    432 #: admin/partials/nginx-helper-general-options.php:587
     482#: admin/partials/nginx-helper-general-options.php:713
    433483msgid "Enable Nginx Map."
    434484msgstr ""
    435485
    436 #: admin/partials/nginx-helper-general-options.php:606
     486#: admin/partials/nginx-helper-general-options.php:732
    437487msgid "Enable Logging"
    438488msgstr ""
    439489
    440 #: admin/partials/nginx-helper-general-options.php:611
     490#: admin/partials/nginx-helper-general-options.php:737
    441491msgid "disable"
    442492msgstr ""
    443493
    444 #: admin/partials/nginx-helper-general-options.php:617
     494#: admin/partials/nginx-helper-general-options.php:743
    445495msgid "enable"
    446496msgstr ""
    447497
    448 #: admin/partials/nginx-helper-general-options.php:624
     498#: admin/partials/nginx-helper-general-options.php:750
    449499msgid "NOTE"
    450500msgstr ""
    451501
    452 #: admin/partials/nginx-helper-general-options.php:625
     502#: admin/partials/nginx-helper-general-options.php:751
    453503msgid "To"
    454504msgstr ""
    455505
    456 #: admin/partials/nginx-helper-general-options.php:627
     506#: admin/partials/nginx-helper-general-options.php:753
    457507msgid "the logging feature, you must define"
    458508msgstr ""
    459509
    460 #: admin/partials/nginx-helper-general-options.php:628
     510#: admin/partials/nginx-helper-general-options.php:754
    461511msgid "as"
    462512msgstr ""
    463513
    464 #: admin/partials/nginx-helper-general-options.php:630
     514#: admin/partials/nginx-helper-general-options.php:756
    465515msgid "in your"
    466516msgstr ""
    467517
    468 #: admin/partials/nginx-helper-general-options.php:641
     518#: admin/partials/nginx-helper-general-options.php:767
    469519msgid "Enable Nginx Timestamp in HTML"
    470520msgstr ""
    471521
    472 #: admin/partials/nginx-helper-general-options.php:655
     522#: admin/partials/nginx-helper-general-options.php:781
    473523msgid "Nginx Map"
    474524msgstr ""
    475525
    476 #: admin/partials/nginx-helper-general-options.php:664
     526#: admin/partials/nginx-helper-general-options.php:790
    477527msgid "Can't write on map file."
    478528msgstr ""
    479529
    480530#. translators: %s file url.
    481 #: admin/partials/nginx-helper-general-options.php:669
    482 #: admin/partials/nginx-helper-general-options.php:741
     531#: admin/partials/nginx-helper-general-options.php:795
     532#: admin/partials/nginx-helper-general-options.php:867
    483533msgid "Check you have write permission on <strong>%s</strong>"
    484534msgstr ""
    485535
    486 #: admin/partials/nginx-helper-general-options.php:686
     536#: admin/partials/nginx-helper-general-options.php:812
    487537msgid "Nginx Map path to include in nginx settings"
    488538msgstr ""
    489539
    490 #: admin/partials/nginx-helper-general-options.php:687
     540#: admin/partials/nginx-helper-general-options.php:813
    491541msgid "(recommended)"
    492542msgstr ""
    493543
    494 #: admin/partials/nginx-helper-general-options.php:700
     544#: admin/partials/nginx-helper-general-options.php:826
    495545msgid "Or,"
    496546msgstr ""
    497547
    498 #: admin/partials/nginx-helper-general-options.php:701
     548#: admin/partials/nginx-helper-general-options.php:827
    499549msgid "Text to manually copy and paste in nginx settings"
    500550msgstr ""
    501551
    502 #: admin/partials/nginx-helper-general-options.php:702
     552#: admin/partials/nginx-helper-general-options.php:828
    503553msgid "(if your network is small and new sites are not added frequently)"
    504554msgstr ""
    505555
    506 #: admin/partials/nginx-helper-general-options.php:720
     556#: admin/partials/nginx-helper-general-options.php:846
    507557msgid "Logging Options"
    508558msgstr ""
    509559
    510 #: admin/partials/nginx-helper-general-options.php:736
     560#: admin/partials/nginx-helper-general-options.php:862
    511561msgid "Can't write on log file."
    512562msgstr ""
    513563
    514 #: admin/partials/nginx-helper-general-options.php:758
     564#: admin/partials/nginx-helper-general-options.php:884
    515565msgid "Logs path"
    516566msgstr ""
    517567
    518 #: admin/partials/nginx-helper-general-options.php:770
     568#: admin/partials/nginx-helper-general-options.php:896
    519569msgid "View Log"
    520570msgstr ""
    521571
    522 #: admin/partials/nginx-helper-general-options.php:775
     572#: admin/partials/nginx-helper-general-options.php:901
    523573msgid "Log"
    524574msgstr ""
    525575
    526 #: admin/partials/nginx-helper-general-options.php:782
     576#: admin/partials/nginx-helper-general-options.php:908
    527577msgid "Log level"
    528578msgstr ""
    529579
    530 #: admin/partials/nginx-helper-general-options.php:787
     580#: admin/partials/nginx-helper-general-options.php:913
    531581msgid "None"
    532582msgstr ""
    533583
    534 #: admin/partials/nginx-helper-general-options.php:788
     584#: admin/partials/nginx-helper-general-options.php:914
    535585msgid "Info"
    536586msgstr ""
    537587
    538 #: admin/partials/nginx-helper-general-options.php:789
     588#: admin/partials/nginx-helper-general-options.php:915
    539589msgid "Warning"
    540590msgstr ""
    541591
    542 #: admin/partials/nginx-helper-general-options.php:790
     592#: admin/partials/nginx-helper-general-options.php:916
    543593msgid "Error"
    544594msgstr ""
    545595
    546 #: admin/partials/nginx-helper-general-options.php:797
     596#: admin/partials/nginx-helper-general-options.php:923
    547597msgid "Max log file size"
    548598msgstr ""
    549599
    550 #: admin/partials/nginx-helper-general-options.php:803
     600#: admin/partials/nginx-helper-general-options.php:929
    551601msgid "Mb"
    552602msgstr ""
    553603
    554 #: admin/partials/nginx-helper-general-options.php:820
     604#: admin/partials/nginx-helper-general-options.php:946
    555605msgid "Save All Changes"
    556606msgstr ""
     
    654704
    655705#. translators: %s is Minimum WP version.
    656 #: includes/class-nginx-helper.php:311
     706#: includes/class-nginx-helper.php:314
    657707msgid "Sorry, Nginx Helper requires WordPress %s or higher"
    658708msgstr ""
  • nginx-helper/trunk/nginx-helper.php

    r3071366 r3213676  
    44 * Plugin URI:        https://rtcamp.com/nginx-helper/
    55 * Description:       Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
    6  * Version:           2.2.5
     6 * Version:           2.3.0
    77 * Author:            rtCamp
    88 * Author URI:        https://rtcamp.com
     
    1010 * Domain Path:       /languages
    1111 * Requires at least: 3.0
    12  * Tested up to:      6.4
     12 * Tested up to:      6.7
    1313 *
    1414 * @link              https://rtcamp.com/nginx-helper/
  • nginx-helper/trunk/readme.txt

    r3071384 r3213676  
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html
    77Requires at least: 3.0
    8 Tested up to: 6.5
    9 Stable tag: 2.2.5
     8Tested up to: 6.7
     9Stable tag: 2.3.0
    1010
    1111Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
     
    107107```
    108108
     109**Q. Can I override the redis socket path, username, password?**
     110
     111Yes, you can force override the redis socket path, username, password by defining constant in wp-config.php. For example:
     112
     113```php
     114define( 'RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET', '/var/run/redis/redis.sock' );
     115
     116define( 'RT_WP_NGINX_HELPER_REDIS_USERNAME', 'admin' );
     117
     118define( 'RT_WP_NGINX_HELPER_REDIS_PASSWORD', 'admin' );
     119```
     120
    109121= FAQ - Nginx Map =
    110122
     
    117129Most likely yes. A wordpress plugin, if not using explicitly any Apache-only mod, should work on Nginx. Some plugin may need some extra work.
    118130
     131
     132= FAQ - WP-CLI =
     133
     134**Q. How can I update the options using WP-CLI?**
     135
     136```shell
     137wp option patch update rt_wp_nginx_helper_options <option_name> <option_value>
     138```
    119139
    120140= Still need help! =
     
    127147
    128148== Changelog ==
     149
     150= 2.3.0 =
     151
     152* Disable the purge functionality when importing data. [#52](https://github.com/rtCamp/nginx-helper/pull/52) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     153* Added option to preload cache for all Post and Pages. [#47](https://github.com/rtCamp/nginx-helper/pull/47) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     154* Added the capability to purge Amp URL's. [#135](https://github.com/rtCamp/nginx-helper/pull/135) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     155* Add support for adding Username, Password support for Redis. It also includes the support for Unix Socket Path for Redis along with Database selection. [#343](https://github.com/rtCamp/nginx-helper/pull/343),[#350](https://github.com/rtCamp/nginx-helper/pull/350) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     156* Add capability to allow modifying options using WP-CLI. [#307](https://github.com/rtCamp/nginx-helper/pull/307) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     157* Fix the plugin crash issue due to internationalization after upgrading to WordPress Version 6.7. [#364](https://github.com/rtCamp/nginx-helper/pull/364) - by [Vedant Gandhi](https://github.com/Vedant-Gandhi)
     158
    129159
    130160= 2.2.5 =
Note: See TracChangeset for help on using the changeset viewer.