diff --git a/.gitattributes b/.gitattributes index 5b2151f790..3361aa2e40 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,8 +1,12 @@ # PHPUnit files .travis.yml export-ignore bin export-ignore +tests/bootstrap.php export-ignore +tests/test-sample.php export-ignore +tests/inc export-ignore phpunit.xml export-ignore -tests export-ignore README.md export-ignore .gitattributes export-ignore .gitignore export-ignore +phpcs.xml export-ignore +.tx export-ignore diff --git a/.gitignore b/.gitignore index 2ccbe4656c..a4c544a106 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules/ +getpomakemo.sh diff --git a/.tx/config b/.tx/config new file mode 100644 index 0000000000..40d39c4ada --- /dev/null +++ b/.tx/config @@ -0,0 +1,8 @@ +[main] +host = https://www.transifex.com + +[wp-rocket.rocket] +file_filter = languages/rocket-.po +source_file = languages/rocket.pot +source_lang = en +type = PO diff --git a/contributors.txt b/contributors.txt index f4164755c3..3f7ee795c4 100644 --- a/contributors.txt +++ b/contributors.txt @@ -3,4 +3,7 @@ This file contains a list of people who have made large contributions to WP Rock Developers: Jonathan Buttigieg Julio Potier - Remy Perona \ No newline at end of file + Remy Perona + +UX: + Caspar Hübinger diff --git a/inc/3rd-party/3rd-party.php b/inc/3rd-party/3rd-party.php index e1ab321e3e..3c2df4136b 100644 --- a/inc/3rd-party/3rd-party.php +++ b/inc/3rd-party/3rd-party.php @@ -1,5 +1,5 @@ 'sitemap_preload', - 'type' => 'checkbox', - 'label' => __('All in One SEO XML sitemap', 'rocket' ), - 'label_for' => 'all_in_one_seo_xml_sitemap', - 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'All in One SEO Pack' ), - 'default' => 0, - ); - $options[] = array( - 'parent' => 'sitemap_preload', - 'type' => 'helper_description', - 'name' => 'all_in_one_seo_xml_sitemap_desc', - 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'All in One SEO Pack' ) - ); - return $options; - } - } -endif; \ No newline at end of file + /** + * Add All in One SEO Sitemap sub-option on WP Rocket settings page + * + * @since 2.8 + * @author Remy Perona + * + * @param Array $options Array of WP Rocket options. + * @return Array Updated array of WP Rocket options + */ + function rocket_sitemap_preload_all_in_one_seo_option( $options ) { + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'checkbox', + 'label' => __( 'All in One SEO XML sitemap', 'rocket' ), + 'label_for' => 'all_in_one_seo_xml_sitemap', + 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'All in One SEO Pack' ), + 'default' => 0, + ); + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'helper_description', + 'name' => 'all_in_one_seo_xml_sitemap_desc', + 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'All in One SEO Pack' ), + ); + return $options; + } + add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_all_in_one_seo_option' ); + } +endif; diff --git a/inc/3rd-party/autoptimize.php b/inc/3rd-party/autoptimize.php index 1e80af3d52..cc3538cb30 100644 --- a/inc/3rd-party/autoptimize.php +++ b/inc/3rd-party/autoptimize.php @@ -1,15 +1,13 @@ domainflush(); + // Preload cache. + run_rocket_preload_cache( 'cache-preload' ); + } } -} + add_action( 'init', 'rocket_clear_cache_after_savvii' ); -/** - * Don't display the Varnish options tab for Savvii users - * - * @since 2.7 - */ -add_filter( 'rocket_display_varnish_options_tab', '__return_false' ); + /** + * Call the cache server to purge the cache with Savvii hosting. + * + * @since 2.6.5 + */ + function rocket_clean_savvii() { + $plugin = new \Savvii\CacheFlusherPlugin(); -endif; \ No newline at end of file + if ( method_exists( $plugin, 'domainflush' ) ) { + $plugin->domainflush(); + } + } + add_action( 'after_rocket_clean_domain', 'rocket_clean_savvii' ); +endif; diff --git a/inc/3rd-party/hosting/varnish.php b/inc/3rd-party/hosting/varnish.php index cf1c4816e3..a7182e0a3d 100644 --- a/inc/3rd-party/hosting/varnish.php +++ b/inc/3rd-party/hosting/varnish.php @@ -1,47 +1,54 @@ -pagination_base ) . '?vregex'; - - rocket_varnish_http_purge( $home_url ); - rocket_varnish_http_purge( $home_pagination_url ); -} + /** + * Purge a specific page + * + * @since 2.6.8 + * + * @param string $url The url to purge. + */ + function rocket_varnish_clean_file( $url ) { + rocket_varnish_http_purge( trailingslashit( $url ) . '?vregex' ); + } + add_action( 'before_rocket_clean_file', 'rocket_varnish_clean_file' ); + + /** + * Purge the homepage and its pagination + * + * @since 2.6.8 + * + * @param string $root The path of home cache file. + * @param string $lang The current lang to purge. + */ + function rocket_varnish_clean_home( $root, $lang ) { + $home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) ); + $home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ) . '?vregex'; -endif; \ No newline at end of file + rocket_varnish_http_purge( $home_url ); + rocket_varnish_http_purge( $home_pagination_url ); + } + add_action( 'before_rocket_clean_home', 'rocket_varnish_clean_home', 10, 2 ); +endif; diff --git a/inc/3rd-party/hosting/wp-serveur.php b/inc/3rd-party/hosting/wp-serveur.php index 2e820ae046..5988276322 100644 --- a/inc/3rd-party/hosting/wp-serveur.php +++ b/inc/3rd-party/hosting/wp-serveur.php @@ -1,33 +1,34 @@ -get_cdn_domain( $domains, home_url(), $is_ssl ); - + + $wpengine = WpeCommon::instance(); + $cdn_domain = $wpengine->get_cdn_domain( $domains, home_url(), $is_ssl ); + if ( ! empty( $cdn_domain ) ) { $cdn_domain = $native_schema . '://' . $cdn_domain; - set_transient( 'rocket_wpengine_cdn', $cdn_domain, DAY_IN_SECONDS ); } - } - - return $cdn_domain; -} - -/** - * Always keep WP_CACHE constant to true - * - * @since 2.8.6 - */ -add_filter( 'set_rocket_wp_cache_define', '__return_true' ); + return $cdn_domain; + } endif; diff --git a/inc/3rd-party/i18n/polylang.php b/inc/3rd-party/i18n/polylang.php index 187dfae544..a0a07f6b67 100644 --- a/inc/3rd-party/i18n/polylang.php +++ b/inc/3rd-party/i18n/polylang.php @@ -1,20 +1,18 @@ -options['force_lang'] ) { - rocket_clean_cache_dir(); - } -} - -endif; \ No newline at end of file + if ( isset( $pll ) && 0 === $pll->options['force_lang'] ) { + rocket_clean_cache_dir(); + } + } + add_action( 'after_rocket_clean_domain', 'rocket_force_clean_domain_on_polylang' ); +endif; diff --git a/inc/3rd-party/i18n/wpml.php b/inc/3rd-party/i18n/wpml.php index 37cfd76a1a..39d8acf64b 100644 --- a/inc/3rd-party/i18n/wpml.php +++ b/inc/3rd-party/i18n/wpml.php @@ -1,20 +1,18 @@ - 'sitemap_preload', - 'type' => 'checkbox', - 'label' => __('Jetpack XML Sitemaps', 'rocket' ), + if ( is_array( $jetpack_active_modules ) && in_array( 'sitemaps', $jetpack_active_modules, true ) && function_exists( 'jetpack_sitemap_uri' ) ) { + /** + * Add Jetpack option to WP Rocket options + * + * @since 2.8 + * @author Remy Perona + * + * @param Array $options WP Rocket options array. + * @return Array Updated WP Rocket options array + */ + function rocket_add_jetpack_sitemap_option( $options ) { + $options['jetpack_xml_sitemap'] = 0; + + return $options; + } + add_filter( 'rocket_first_install_options', 'rocket_add_jetpack_sitemap_option' ); + + /** + * Sanitize jetpack option value + * + * @since 2.8 + * @author Remy Perona + * + * @param Array $inputs Array of inputs values. + * @return Array Array of inputs values + */ + function rocket_jetpack_sitemap_option_sanitize( $inputs ) { + $inputs['jetpack_xml_sitemap'] = ! empty( $inputs['jetpack_xml_sitemap'] ) ? 1 : 0; + + return $inputs; + } + add_filter( 'rocket_inputs_sanitize', 'rocket_jetpack_sitemap_option_sanitize' ); + + /** + * Add Jetpack sitemap to preload list + * + * @since 2.8 + * @author Remy Perona + * + * @param Array $sitemaps Array of sitemaps to preload. + * @return Array Updated Array of sitemaps to preload + */ + function rocket_add_jetpack_sitemap( $sitemaps ) { + if ( get_rocket_option( 'jetpack_xml_sitemap', false ) ) { + $sitemaps['jetpack'] = jetpack_sitemap_uri(); + } + + return $sitemaps; + } + add_filter( 'rocket_sitemap_preload_list', 'rocket_add_jetpack_sitemap' ); + + /** + * Add Jetpack sub-option to WP Rocket settings page + * + * @since 2.8 + * @author Remy Perona + * + * @param Array $options WP Rocket options array. + * @return Array Updated WP Rocket options array + */ + function rocket_sitemap_preload_jetpack_option( $options ) { + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'checkbox', + 'label' => __( 'Jetpack XML Sitemaps', 'rocket' ), 'label_for' => 'jetpack_xml_sitemap', 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'Jetpack' ), 'default' => 0, - ); - $options[] = array( - 'parent' => 'sitemap_preload', - 'type' => 'helper_description', - 'name' => 'jetpack_xml_sitemap_desc', - 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Jetpack' ) - ); - - return $options; - } - } + ); + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'helper_description', + 'name' => 'jetpack_xml_sitemap_desc', + 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Jetpack' ), + ); + + return $options; + } + add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_jetpack_option' ); + } endif; diff --git a/inc/3rd-party/kk-star-ratings.php b/inc/3rd-party/kk-star-ratings.php index dd122b3d43..17dfc9d4d6 100644 --- a/inc/3rd-party/kk-star-ratings.php +++ b/inc/3rd-party/kk-star-ratings.php @@ -1,16 +1,16 @@ - $slug ) { + + foreach ( $sfml_slugs as $key => $slug ) { $sfml_slugs[ $key ] = $slug . '?'; } - + return array_merge( $urls, $sfml_slugs ); } -add_action( 'activate_sf-move-login/sf-move-login.php', 'rocket_activate_sfml', 11 ); /** * Add SFML custom urls to caching exclusion when activating the plugin * @@ -53,16 +52,16 @@ function rocket_add_sfml_exclude_pages( $urls ) { function rocket_activate_sfml() { if ( defined( 'SFML_VERSION' ) ) { add_filter( 'rocket_cache_reject_uri', 'rocket_add_sfml_exclude_pages' ); - - // Update the WP Rocket rules on the .htaccess - flush_rocket_htaccess(); - - // Regenerate the config file - rocket_generate_config_file(); - } + + // Update the WP Rocket rules on the .htaccess. + flush_rocket_htaccess(); + + // Regenerate the config file. + rocket_generate_config_file(); + } } +add_action( 'activate_sf-move-login/sf-move-login.php', 'rocket_activate_sfml', 11 ); -add_action( 'deactivate_sf-move-login/sf-move-login.php', 'rocket_deactivate_sfml', 11 ); /** * Remove SFML custom urls from caching exclusion when deactivating the plugin * @@ -71,11 +70,12 @@ function rocket_activate_sfml() { function rocket_deactivate_sfml() { if ( defined( 'SFML_VERSION' ) ) { remove_filter( 'rocket_cache_reject_uri', 'rocket_add_sfml_exclude_pages' ); - - // Update the WP Rocket rules on the .htaccess - flush_rocket_htaccess(); - - // Regenerate the config file - rocket_generate_config_file(); - } + + // Update the WP Rocket rules on the .htaccess. + flush_rocket_htaccess(); + + // Regenerate the config file. + rocket_generate_config_file(); + } } +add_action( 'deactivate_sf-move-login/sf-move-login.php', 'rocket_deactivate_sfml', 11 ); diff --git a/inc/3rd-party/security/secupress.php b/inc/3rd-party/security/secupress.php index edd0bd60ae..62acd54db5 100644 --- a/inc/3rd-party/security/secupress.php +++ b/inc/3rd-party/security/secupress.php @@ -1,11 +1,17 @@ -get( 'Name' ) ) : - /** - * Excludes Divi's Salvatorre script from JS minification - * - * Exclude it to prevent an error after minification/concatenation - * - * @since 2.9 - * @author Remy Perona - * - * @param Array $excluded_js An array of JS paths to be excluded - * @return Array the updated array of paths - */ - add_filter( 'rocket_exclude_js', 'rocket_exclude_js_divi' ); - function rocket_exclude_js_divi( $excluded_js ) { - if ( defined( 'ET_BUILDER_URI' ) ) { - $excluded_js[] = str_replace( home_url(), '', ET_BUILDER_URI ) . '/scripts/salvattore.min.js'; - } + /** + * Excludes Divi's Salvatorre script from JS minification + * + * Exclude it to prevent an error after minification/concatenation + * + * @since 2.9 + * @author Remy Perona + * + * @param Array $excluded_js An array of JS paths to be excluded. + * @return Array the updated array of paths + */ + function rocket_exclude_js_divi( $excluded_js ) { + if ( defined( 'ET_BUILDER_URI' ) ) { + $excluded_js[] = str_replace( home_url(), '', ET_BUILDER_URI ) . '/scripts/salvattore.min.js'; + } - return $excluded_js; - } -endif; \ No newline at end of file + return $excluded_js; + } + add_filter( 'rocket_exclude_js', 'rocket_exclude_js_divi' ); +endif; diff --git a/inc/3rd-party/weepie-cookie-allow.php b/inc/3rd-party/weepie-cookie-allow.php index 11b992a56b..479d6f665d 100644 --- a/inc/3rd-party/weepie-cookie-allow.php +++ b/inc/3rd-party/weepie-cookie-allow.php @@ -1,5 +1,5 @@ query_vars['print'] ) ) { - add_filter( 'do_rocket_lazyload', '__return_false' ); + if ( isset( $wp_query->query_vars['print'] ) ) { + add_filter( 'do_rocket_lazyload', '__return_false' ); + } } -} - -endif; \ No newline at end of file + add_action( 'wp', 'rocket_deactivate_lazyload_on_print_pages' ); +endif; diff --git a/inc/3rd-party/wp-rest-api.php b/inc/3rd-party/wp-rest-api.php index 7d89ccd5c4..cd74b03edb 100644 --- a/inc/3rd-party/wp-rest-api.php +++ b/inc/3rd-party/wp-rest-api.php @@ -1,25 +1,33 @@ is_pro() ) { return $url; } - + $cdn_domain = get_option( 'wr2x_cdn_domain' ); if ( ! empty( $cdn_domain ) ) { return $url; } - + return get_rocket_cdn_url( $url, array( 'all', 'images' ) ); } + add_filter( 'wr2x_img_retina_url', 'rocket_cdn_on_images_from_wp_retina_x2' ); + add_filter( 'wr2x_img_url', 'rocket_cdn_on_images_from_wp_retina_x2' ); endif; diff --git a/inc/3rd-party/yoast-seo.php b/inc/3rd-party/yoast-seo.php index 8d75328e3e..ec1a69b6d0 100644 --- a/inc/3rd-party/yoast-seo.php +++ b/inc/3rd-party/yoast-seo.php @@ -1,8 +1,8 @@ 'sitemap_preload', - 'type' => 'checkbox', - 'label' => __('Yoast SEO XML sitemap', 'rocket' ), - 'label_for' => 'yoast_xml_sitemap', - 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'Yoast SEO' ), - 'default' => 0, - ); - $options[] = array( - 'parent' => 'sitemap_preload', - 'type' => 'helper_description', - 'name' => 'yoast_xml_sitemap_desc', - 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Yoast SEO' ) - ); - return $options; - } - } -endif; \ No newline at end of file + if ( true === $yoast_seo_xml['enablexmlsitemap'] ) { + /** + * Add Yoast SEO sitemap option to WP Rocket default options + * + * @since 2.8 + * @author Remy Perona + * + * @param array $options WP Rocket options array. + * @return array Updated WP Rocket options array + */ + function rocket_add_yoast_seo_sitemap_option( $options ) { + $options['yoast_xml_sitemap'] = 0; + + return $options; + } + add_filter( 'rocket_first_install_options', 'rocket_add_yoast_seo_sitemap_option' ); + + /** + * Sanitize Yoast SEO sitemap option value + * + * @since 2.8 + * @author Remy Perona + * + * @param array $inputs WP Rocket inputs array. + * @return array Sanitized WP Rocket inputs array + */ + function rocket_yoast_seo_sitemap_option_sanitize( $inputs ) { + $inputs['yoast_xml_sitemap'] = ! empty( $inputs['yoast_xml_sitemap'] ) ? 1 : 0; + + return $inputs; + } + add_filter( 'rocket_inputs_sanitize', 'rocket_yoast_seo_sitemap_option_sanitize' ); + + /** + * Add Yoast SEO sitemap URL to the sitemaps to preload + * + * @since 2.8 + * @author Remy Perona + * + * @param array $sitemaps Sitemaps to preload. + * @return array Updated Sitemaps to preload + */ + function rocket_add_yoast_seo_sitemap( $sitemaps ) { + if ( get_rocket_option( 'yoast_xml_sitemap', false ) ) { + $sitemaps[] = WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ); + } + + return $sitemaps; + } + add_filter( 'rocket_sitemap_preload_list', 'rocket_add_yoast_seo_sitemap' ); + + /** + * Add Yoast SEO option to WP Rocket settings + * + * @since 2.8 + * @author Remy Perona + * + * @param array $options WP Rocket settings array. + * @return array Updated WP Rocket settings array + */ + function rocket_sitemap_preload_yoast_seo_option( $options ) { + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'checkbox', + 'label' => __( 'Yoast SEO XML sitemap', 'rocket' ), + 'label_for' => 'yoast_xml_sitemap', + 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'Yoast SEO' ), + 'default' => 0, + ); + $options[] = array( + 'parent' => 'sitemap_preload', + 'type' => 'helper_description', + 'name' => 'yoast_xml_sitemap_desc', + 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Yoast SEO' ), + ); + return $options; + } + add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_yoast_seo_option' ); + } +endif; diff --git a/inc/admin/admin.php b/inc/admin/admin.php index f32dd9abff..ed17d4c8ab 100644 --- a/inc/admin/admin.php +++ b/inc/admin/admin.php @@ -2,40 +2,45 @@ defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' ); /** - * Link to the configuration page of the plugin + * Link to the configuration page of the plugin, support & documentation * * @since 1.0 + * + * @param array $actions Array of links to display. + * @return array Updated array of links */ -add_filter( 'plugin_action_links_' . plugin_basename( WP_ROCKET_FILE ), '__rocket_settings_action_links' ); -function __rocket_settings_action_links( $actions ) { +function rocket_settings_action_links( $actions ) { if ( ! rocket_is_white_label() ) { array_unshift( $actions, sprintf( '%s', 'http://wp-rocket.me/support/', __( 'Support', 'rocket' ) ) ); array_unshift( $actions, sprintf( '%s', get_rocket_documentation_url(), __( 'Docs', 'rocket' ) ) ); + + array_unshift( $actions, sprintf( '%s', get_rocket_faq_url(), __( 'FAQ', 'rocket' ) ) ); } array_unshift( $actions, sprintf( '%s', admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ), __( 'Settings' ) ) ); - return $actions; + return $actions; } +add_filter( 'plugin_action_links_' . plugin_basename( WP_ROCKET_FILE ), 'rocket_settings_action_links' ); /** * Add a link "Renew your licence" when ou can't do it automatically (expired licence but new version available) * * @since 2.2 * + * @param array $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI. + * @param string $plugin_file Path to the plugin file, relative to the plugins directory. + * @return array Updated meta content if license is expired */ -add_action( 'plugin_row_meta', '__rocket_plugin_row_meta', 10, 3 ); -function __rocket_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data ) { - if ( 'wp-rocket/wp-rocket.php' == $plugin_file ) { +function rocket_plugin_row_meta( $plugin_meta, $plugin_file ) { + if ( 'wp-rocket/wp-rocket.php' === $plugin_file ) { $update_plugins = get_site_transient( 'update_plugins' ); - if ( $update_plugins != false && isset( $update_plugins->response[ $plugin_file ] ) && empty( $update_plugins->response[ $plugin_file ]->package ) ) { + if ( false !== $update_plugins && isset( $update_plugins->response[ $plugin_file ] ) && empty( $update_plugins->response[ $plugin_file ]->package ) ) { - $link = ' ' . - 'Renew your licence of WP Rocket to receive access to automatic upgrades and support. ' . - 'Purchase now.'; + $link = ' Renew your licence of WP Rocket to receive access to automatic upgrades and support. Purchase now.'; $plugin_meta = array_merge( (array) $link, $plugin_meta ); } @@ -43,58 +48,68 @@ function __rocket_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data ) { return $plugin_meta; } +add_action( 'plugin_row_meta', 'rocket_plugin_row_meta', 10, 2 ); /** * Add a link "Purge this cache" in the post edit area * * @since 1.0 - * @todo manage all CPTs + * + * @param array $actions An array of row action links. + * @param object $post The post object. + * @return array Updated array of row action links */ -add_filter( 'page_row_actions', '__rocket_post_row_actions', 10, 2 ); -add_filter( 'post_row_actions', '__rocket_post_row_actions', 10, 2 ); -function __rocket_post_row_actions( $actions, $post ) { +function rocket_post_row_actions( $actions, $post ) { /** This filter is documented in inc/admin-bar.php */ if ( current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) { $url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=post-' . $post->ID ), 'purge_cache_post-' . $post->ID ); $actions['rocket_purge'] = sprintf( '%s', $url, __( 'Clear this cache', 'rocket' ) ); } - return $actions; + return $actions; } +add_filter( 'page_row_actions', 'rocket_post_row_actions', 10, 2 ); +add_filter( 'post_row_actions', 'rocket_post_row_actions', 10, 2 ); /** * Add a link "Purge this cache" in the taxonomy edit area * * @since 1.0 - * @todo manage all CPTs + * + * @param array $actions An array of row action links. + * @param object $term The term object. + * @return array Updated array of row action links */ -add_filter( 'tag_row_actions', '__rocket_tag_row_actions', 10, 2 ); -function __rocket_tag_row_actions( $actions, $term ) { +function rocket_tag_row_actions( $actions, $term ) { global $taxnow; - + /** This filter is documented in inc/admin-bar.php */ if ( current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) { - $url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=term-' . $term->term_id . '&taxonomy=' . $taxnow ), 'purge_cache_term-' . $term->term_id ); + $url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=term-' . $term->term_id . '&taxonomy=' . $taxnow ), 'purge_cache_term-' . $term->term_id ); $actions['rocket_purge'] = sprintf( '%s', $url, __( 'Clear this cache', 'rocket' ) ); } - - return $actions; + + return $actions; } +add_filter( 'tag_row_actions', 'rocket_tag_row_actions', 10, 2 ); /** * Add a link "Purge this cache" in the user edit area * * @since 2.6.12 + * @param array $actions An array of row action links. + * @param object $user The user object. + * @return array Updated array of row action links */ -add_filter( 'user_row_actions', '__rocket_user_row_actions', 10, 2 ); -function __rocket_user_row_actions( $actions, $user ) { +function rocket_user_row_actions( $actions, $user ) { /** This filter is documented in inc/admin-bar.php */ if ( current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) && get_rocket_option( 'cache_logged_user', false ) ) { $url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=user-' . $user->ID ), 'purge_cache_user-' . $user->ID ); $actions['rocket_purge'] = sprintf( '%s', $url, __( 'Clear this cache', 'rocket' ) ); } - - return $actions; + + return $actions; } +add_filter( 'user_row_actions', 'rocket_user_row_actions', 10, 2 ); /** * Manage the dismissed boxes @@ -102,9 +117,9 @@ function __rocket_user_row_actions( $actions, $user ) { * @since 2.4 Add a delete_transient on function name (box name) * @since 1.3.0 $args can replace $_GET when called internaly * @since 1.1.10 + * + * @param array $args An array of query args. */ -add_action( 'wp_ajax_rocket_ignore', 'rocket_dismiss_boxes' ); -add_action( 'admin_post_rocket_ignore', 'rocket_dismiss_boxes' ); function rocket_dismiss_boxes( $args ) { $args = empty( $args ) ? $_GET : $args; @@ -121,7 +136,7 @@ function rocket_dismiss_boxes( $args ) { if ( '__rocket_imagify_notice' === $args['box'] ) { update_option( 'wp_rocket_dismiss_imagify_notice', 0 ); } - + global $current_user; $actual = get_user_meta( $current_user->ID, 'rocket_boxes', true ); $actual = array_merge( (array) $actual, array( $args['box'] ) ); @@ -130,7 +145,7 @@ function rocket_dismiss_boxes( $args ) { update_user_meta( $current_user->ID, 'rocket_boxes', $actual ); delete_transient( $args['box'] ); - if ( 'admin-post.php' == $GLOBALS['pagenow'] ){ + if ( 'admin-post.php' === $GLOBALS['pagenow'] ) { if ( defined( 'DOING_AJAX' ) ) { wp_send_json( array( 'error' => 0 ) ); } else { @@ -140,27 +155,30 @@ function rocket_dismiss_boxes( $args ) { } } } +add_action( 'wp_ajax_rocket_ignore', 'rocket_dismiss_boxes' ); +add_action( 'admin_post_rocket_ignore', 'rocket_dismiss_boxes' ); /** * Renew the plugin modification warning on plugin de/activation * * @since 1.3.0 + * + * @param string $plugin plugin name. */ -add_action( 'activated_plugin', 'rocket_dismiss_plugin_box' ); -add_action( 'deactivated_plugin', 'rocket_dismiss_plugin_box' ); function rocket_dismiss_plugin_box( $plugin ) { - if ( $plugin != plugin_basename( WP_ROCKET_FILE ) ) { + if ( plugin_basename( WP_ROCKET_FILE ) !== $plugin ) { rocket_renew_box( 'rocket_warning_plugin_modification' ); } } +add_action( 'activated_plugin', 'rocket_dismiss_plugin_box' ); +add_action( 'deactivated_plugin', 'rocket_dismiss_plugin_box' ); /** * Display a prevention message when enabling or disabling a plugin can be in conflict with WP Rocket * * @since 1.3.0 */ -add_action( 'admin_post_deactivate_plugin', '__rocket_deactivate_plugin' ); -function __rocket_deactivate_plugin() { +function rocket_deactivate_plugin() { if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'deactivate_plugin' ) ) { wp_nonce_ays( '' ); } @@ -170,31 +188,33 @@ function __rocket_deactivate_plugin() { wp_safe_redirect( wp_get_referer() ); die(); } +add_action( 'admin_post_deactivate_plugin', 'rocket_deactivate_plugin' ); /** * Reset White Label values to WP Rocket default values * * @since 2.1 */ -add_action( 'admin_post_rocket_resetwl', '__rocket_reset_white_label_values_action' ); -function __rocket_reset_white_label_values_action() { +function rocket_reset_white_label_values_action() { if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'rocket_resetwl' ) ) { rocket_reset_white_label_values( true ); } wp_safe_redirect( add_query_arg( 'page', 'wprocket', remove_query_arg( 'page', wp_get_referer() ) ) ); die(); } +add_action( 'admin_post_rocket_resetwl', 'rocket_reset_white_label_values_action' ); /** * White Label the plugin, if you need to * * @since 2.1 * + * @param array $plugins An array of plugins installed. + * @return array Updated array of plugins installed */ -add_filter( 'all_plugins', '__rocket_white_label' ); -function __rocket_white_label( $plugins ) { +function rocket_white_label( $plugins ) { $white_label_description = get_rocket_option( 'wl_description' ); - // We change the plugin's header + // We change the plugin's header. $plugins['wp-rocket/wp-rocket.php'] = array( 'Name' => get_rocket_option( 'wl_plugin_name' ), 'PluginURI' => get_rocket_option( 'wl_plugin_URI' ), @@ -206,49 +226,48 @@ function __rocket_white_label( $plugins ) { 'DomainPath' => isset( $plugins['wp-rocket/wp-rocket.php']['DomainPath'] ) ? $plugins['wp-rocket/wp-rocket.php']['DomainPath'] : '', ); - // if white label, remove our names from contributors + // if white label, remove our names from contributors. if ( rocket_is_white_label() ) { remove_filter( 'plugin_row_meta', 'rocket_plugin_row_meta', 10, 2 ); } return $plugins; } +add_filter( 'all_plugins', 'rocket_white_label' ); /** * When you're doing an update, the constant does not contain yet your option or any value, reset and redirect! * * @since 2.1 */ -add_action( 'admin_init', '__rocket_check_no_empty_name', 11 ); -function __rocket_check_no_empty_name() { +function rocket_check_no_empty_name() { $wl_plugin_name = trim( get_rocket_option( 'wl_plugin_name' ) ); - + if ( empty( $wl_plugin_name ) ) { rocket_reset_white_label_values( false ); wp_safe_redirect( $_SERVER['REQUEST_URI'] ); die(); } } +add_action( 'admin_init', 'rocket_check_no_empty_name', 11 ); /** * This function will force the direct download of the plugin's options, compressed. * * @since 2.2 */ -add_action( 'admin_post_rocket_export', '__rocket_do_options_export' ); -function __rocket_do_options_export() { +function rocket_do_options_export() { if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_export' ) ) { wp_nonce_ays( '' ); } - $filename_prefix = rocket_is_white_label() ? sanitize_title( get_rocket_option( 'wl_plugin_name' ) ) : 'wp-rocket'; + $filename_prefix = rocket_is_white_label() ? sanitize_title( get_rocket_option( 'wl_plugin_name' ) ) : 'wp-rocket'; - $filename = sprintf( '%s-settings-%s-%s.txt', $filename_prefix, date( 'Y-m-d' ), uniqid() ); + $filename = sprintf( '%s-settings-%s-%s.json', $filename_prefix, date( 'Y-m-d' ), uniqid() ); $gz = 'gz' . strrev( 'etalfed' ); - $options = $gz//; - ( serialize( get_option( WP_ROCKET_SLUG ) ), 1 ); // do not use get_rocket_option() here + $options = wp_json_encode( get_option( WP_ROCKET_SLUG ) ); // do not use get_rocket_option() here. nocache_headers(); - @header( 'Content-Type: text/plain' ); + @header( 'Content-Type: application/json' ); @header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); @header( 'Content-Transfer-Encoding: binary' ); @header( 'Content-Length: ' . strlen( $options ) ); @@ -256,14 +275,14 @@ function __rocket_do_options_export() { echo $options; exit(); } +add_action( 'admin_post_rocket_export', 'rocket_do_options_export' ); /** * Do the rollback * * @since 2.4 */ -add_action( 'admin_post_rocket_rollback', '__rocket_rollback' ); -function __rocket_rollback() { +function rocket_rollback() { if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_rollback' ) ) { wp_nonce_ays( '' ); } @@ -278,7 +297,7 @@ function __rocket_rollback() { 'slug' => $plugin_folder, 'new_version' => $version, 'url' => 'https://wp-rocket.me', - 'package' => $url + 'package' => $url, ); $temp_object = (object) $temp_array; @@ -288,7 +307,7 @@ function __rocket_rollback() { $c_key = get_rocket_option( 'consumer_key' ); $transient = get_transient( 'rocket_warning_rollback' ); - if ( false == $transient ) { + if ( false === $transient ) { require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); $title = sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ); $plugin = 'wp-rocket/wp-rocket.php'; @@ -302,40 +321,47 @@ function __rocket_rollback() { wp_die( '', sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ), array( 'response' => 200 ) ); } } +add_action( 'admin_post_rocket_rollback', 'rocket_rollback' ); -/* - * Create cache folders if not exists. - * Regenerate the advanced-cache.php file if an issue is detected. - * Define WP_CACHE to true if it's not defined yet. - * - * @since 2.6.5 Check config files issues - * @since 2.6 Check WP_CACHE & advanced-cache.php issues - * @since 2.5.5 - */ if ( ! defined( 'DOING_AJAX' ) && ! defined( 'DOING_AUTOSAVE' ) ) { - add_action( 'admin_init', 'rocket_init_cache_dir' ); - add_action( 'admin_init', '__rocket_maybe_generate_advanced_cache_file' ); - add_action( 'admin_init', '__rocket_maybe_generate_config_files' ); - add_action( 'admin_init', '__rocket_maybe_set_wp_cache_define' ); + add_action( 'admin_init', 'rocket_init_cache_dir' ); + add_action( 'admin_init', 'rocket_maybe_generate_advanced_cache_file' ); + add_action( 'admin_init', 'rocket_maybe_generate_config_files' ); + add_action( 'admin_init', 'rocket_maybe_set_wp_cache_define' ); } -function __rocket_maybe_generate_advanced_cache_file() { +/** + * Regenerate the advanced-cache.php file if an issue is detected. + * + * @since 2.6 + */ +function rocket_maybe_generate_advanced_cache_file() { if ( ! defined( 'WP_ROCKET_ADVANCED_CACHE' ) || ( defined( 'WP_ROCKET_ADVANCED_CACHE_PROBLEM' ) && WP_ROCKET_ADVANCED_CACHE_PROBLEM ) ) { rocket_generate_advanced_cache_file(); } } -function __rocket_maybe_generate_config_files() { - list( $host, $path ) = get_rocket_parse_url( home_url() ); +/** + * Regenerate config file if an issue is detected. + * + * @since 2.6.5 + */ +function rocket_maybe_generate_config_files() { + list( $host, $path ) = get_rocket_parse_url( home_url() ); $path = ( ! empty( $path ) ) ? str_replace( '/', '.', untrailingslashit( $path ) ) : ''; - - if( ! file_exists( WP_ROCKET_CONFIG_PATH . strtolower( $host ) . $path . '.php' ) ) { + + if ( ! file_exists( WP_ROCKET_CONFIG_PATH . strtolower( $host ) . $path . '.php' ) ) { rocket_generate_config_file(); } } -function __rocket_maybe_set_wp_cache_define() { - if( defined( 'WP_CACHE' ) && ! WP_CACHE ) { +/** + * Define WP_CACHE to true if it's not defined yet. + * + * @since 2.6 + */ +function rocket_maybe_set_wp_cache_define() { + if ( defined( 'WP_CACHE' ) && ! WP_CACHE ) { set_rocket_wp_cache_define( true ); } } @@ -346,14 +372,14 @@ function __rocket_maybe_set_wp_cache_define() { * @since 2.8 * @author Remy Perona */ -add_action( 'admin_post_rocket_optimize_database', '__rocket_optimize_database' ); -function __rocket_optimize_database() { - if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_optimize_database' ) ) { - wp_nonce_ays( '' ); - } +function rocket_optimize_database() { + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_optimize_database' ) ) { + wp_nonce_ays( '' ); + } - do_rocket_database_optimization(); + do_rocket_database_optimization(); - wp_redirect( wp_get_referer() ); - die(); -} \ No newline at end of file + wp_redirect( wp_get_referer() ); + die(); +} +add_action( 'admin_post_rocket_optimize_database', 'rocket_optimize_database' ); diff --git a/inc/admin/ajax.php b/inc/admin/ajax.php index 8d8096ac6a..2cb5034159 100644 --- a/inc/admin/ajax.php +++ b/inc/admin/ajax.php @@ -1,15 +1,14 @@ WP_ROCKET_VERSION, 'wp_rocket_options' => get_option( WP_ROCKET_SLUG ), 'support_summary' => $_POST['summary'], - 'support_description' => $_POST['description'] - ) + 'support_description' => $_POST['description'], + ), ), ) ); if ( ! is_wp_error( $response ) ) { - wp_send_json( wp_remote_retrieve_body( $response ) ); - } else { + wp_send_json( wp_remote_retrieve_body( $response ) ); + } else { wp_send_json( array( 'msg' => 'BAD_SERVER' ) ); - } + } } +add_action( 'wp_ajax_rocket_new_ticket_support', 'wp_ajax_rocket_new_ticket_support' ); /** * Documentation suggestions based on the summary input from the new ticket support form. * * @since 2.6 */ -add_action( 'wp_ajax_rocket_helpscout_live_search', '__wp_ajax_rocket_helpscout_live_search' ); -function __wp_ajax_rocket_helpscout_live_search() { +function wp_ajax_rocket_helpscout_live_search() { if ( current_user_can( apply_filters( 'rocket_capability', 'manage_options' ) ) ) { - $response = wp_remote_post( + $query = filter_input( INPUT_POST, 'query' ); + $response = wp_remote_post( WP_ROCKET_WEB_MAIN . 'tools/wp-rocket/helpscout/livesearch.php', array( 'timeout' => 10, - 'body' => array( - 'query' => esc_html( wp_strip_all_tags( $_POST['query'] , true ) ), - 'lang' => get_locale() + 'body' => array( + 'query' => esc_html( wp_strip_all_tags( $query, true ) ), + 'lang' => get_locale(), ), ) ); - + if ( ! is_wp_error( $response ) ) { wp_send_json( wp_remote_retrieve_body( $response ) ); } } -} \ No newline at end of file +} +add_action( 'wp_ajax_rocket_helpscout_live_search', 'wp_ajax_rocket_helpscout_live_search' ); diff --git a/inc/admin/class-repeater-field.php b/inc/admin/class-repeater-field.php index 215ab3cbc8..27cd924e21 100644 --- a/inc/admin/class-repeater-field.php +++ b/inc/admin/class-repeater-field.php @@ -1,11 +1,10 @@ option = $args['name']; - $this->label_screen = ! empty($args['label_screen']) ? esc_html($args['label_screen']) : false; - $this->placeholder = ! empty( $args['placeholder'] ) ? 'placeholder="'. $args['placeholder'].'" ' : ''; - $this->is_drag_n_drop = ! empty($args['repeater_drag_n_drop']) ? true : false; - $this->label_add_field = ! empty($args['repeater_label_add_field']) ? $args['repeater_label_add_field'] : false; + $this->label_screen = ! empty( $args['label_screen'] ) ? esc_html( $args['label_screen'] ) : false; + $this->placeholder = ! empty( $args['placeholder'] ) ? 'placeholder="' . $args['placeholder'] . '" ' : ''; + $this->is_drag_n_drop = ! empty( $args['repeater_drag_n_drop'] ) ? true : false; + $this->label_add_field = ! empty( $args['repeater_label_add_field'] ) ? $args['repeater_label_add_field'] : false; add_filter( 'rocket_repeater_field_classes', array( $this, 'add_drag_n_drop_classes' ) ); add_action( 'before_rocket_repeater_field', array( $this, 'add_drag_n_drop_support' ) ); @@ -91,7 +90,7 @@ public function add_drag_n_drop_support() { * @since 2.2 * @access public * - * @param string $classes All classes in rocket_repeater_field_classes filter + * @param string $classes All classes in rocket_repeater_field_classes filter. */ public function add_drag_n_drop_classes( $classes ) { @@ -108,8 +107,8 @@ public function add_drag_n_drop_classes( $classes ) { */ private function the_label_screen() { - if( $this->label_screen ) { - echo '' . $this->label_screen. ''; + if ( $this->label_screen ) { + echo '' . $this->label_screen . ''; } } @@ -120,11 +119,12 @@ private function the_label_screen() { * @since 2.2 * @access private * - * @param string $key The key of the field - * @param string $value The value of the field - * @param bool $remove_button If true, remove button is display + * @param string $key The key of the field. + * @param string $value The value of the field. + * @param bool $remove_button If true, remove button is display. */ - private function the_field( $key = null, $value = '', $remove_button = true ) { ?> + private function the_field( $key = null, $value = '', $remove_button = true ) { + ?>

@@ -135,14 +135,14 @@ private function the_field( $key = null, $value = '', $remove_button = true ) { * * @since 2.2 * @param string $option The option name - */ + */ do_action( 'before_rocket_repeater_field', $this->option ); ?> placeholder; ?> class="option; ?> regular-text" name="wp_rocket_settings[option; ?>][]" value="" /> - + @@ -153,7 +153,7 @@ private function the_field( $key = null, $value = '', $remove_button = true ) { * * @since 2.2 * @param string $option The option name - */ + */ do_action( 'after_rocket_repeater_field', $this->option ); ?> @@ -168,9 +168,9 @@ private function the_field( $key = null, $value = '', $remove_button = true ) { * * @since 2.2 * @access public - * */ - public function render() { ?> + public function render() { + ?>

@@ -182,13 +182,13 @@ public function render() { ?> $_option = get_rocket_option( $this->option ); - if( $_option ) { + if ( $_option ) { - foreach( $_option as $key => $value ) { + foreach ( $_option as $key => $value ) { $this->the_field( $key, $value, true ); } - // If no values yet, use this template inside + // If no values yet, use this template inside. } else { $this->the_field( 0, '', false ); } @@ -196,7 +196,7 @@ public function render() { ?> - +
the_field(); ?> @@ -209,4 +209,4 @@ public function render() { ?> } -} \ No newline at end of file +} diff --git a/inc/admin/compat/cf-options-5.4.php b/inc/admin/compat/cf-options-5.4.php index a412814822..33edb2e3f4 100644 --- a/inc/admin/compat/cf-options-5.4.php +++ b/inc/admin/compat/cf-options-5.4.php @@ -2,12 +2,14 @@ $cf_instance = get_rocket_cloudflare_api_instance(); if ( ! is_wp_error( $cf_instance ) ) { - try { - $zone_instance = new CloudFlare\Zone( $cf_instance ); - $zone = $zone_instance->zones( $newvalue['cloudflare_domain'] ); + try { + $zone_instance = new CloudFlare\Zone( $cf_instance ); + $zone = $zone_instance->zones( $newvalue['cloudflare_domain'] ); - if ( isset( $zone->result[0]->id ) ) { - $newvalue['cloudflare_zone_id'] = $zone->result[0]->id; - } - } catch ( Exception $e ) {} -} \ No newline at end of file + if ( isset( $zone->result[0]->id ) ) { + $newvalue['cloudflare_zone_id'] = $zone->result[0]->id; + } + } catch ( Exception $e ) { + return false; + } +} diff --git a/inc/admin/compat/cf-upgrader-5.4.php b/inc/admin/compat/cf-upgrader-5.4.php index 6ed6f35d91..33f1a02680 100644 --- a/inc/admin/compat/cf-upgrader-5.4.php +++ b/inc/admin/compat/cf-upgrader-5.4.php @@ -2,13 +2,15 @@ $cf_instance = get_rocket_cloudflare_api_instance(); if ( ! is_wp_error( $cf_instance ) ) { - try { - $zone_instance = new CloudFlare\Zone( $cf_instance ); - $zone = $zone_instance->zones( $options['cloudflare_domain'] ); + try { + $zone_instance = new CloudFlare\Zone( $cf_instance ); + $zone = $zone_instance->zones( $options['cloudflare_domain'] ); - if ( isset( $zone->result[0]->id ) ) { - $options['cloudflare_zone_id'] = $zone->result[0]->id; - update_option( WP_ROCKET_SLUG, $options ); - } - } catch ( Exception $e ) {} -} \ No newline at end of file + if ( isset( $zone->result[0]->id ) ) { + $options['cloudflare_zone_id'] = $zone->result[0]->id; + update_option( WP_ROCKET_SLUG, $options ); + } + } catch ( Exception $e ) { + return false; + } +} diff --git a/inc/admin/faq.inc.php b/inc/admin/faq.inc.php index b304605eda..4578c49fcc 100644 --- a/inc/admin/faq.inc.php +++ b/inc/admin/faq.inc.php @@ -19,4 +19,4 @@
  • Reports from PageSpeed and YSlow tell me that the content is not gziped and/or did not expire, what should I do?', 'rocket' ); ?>

  • What should I do if WP Rocket distorts my website display?', 'rocket' ); ?>

  • How to exclude a particular page from caching?', 'rocket' ); ?>

  • - \ No newline at end of file + diff --git a/inc/admin/options.php b/inc/admin/options.php index 75d07f89f7..f6517bd381 100644 --- a/inc/admin/options.php +++ b/inc/admin/options.php @@ -5,48 +5,58 @@ * Fix the capability for our capacity filter hook * * @since 2.6 + * + * @param string $capability Capacity to access WP Rocket options. + * @return string Updated capacity */ -add_filter( 'option_page_capability_wp_rocket', 'rocket_correct_capability_for_options_page' ); function rocket_correct_capability_for_options_page( $capability ) { + /** This filter is documented in inc/admin-bar.php */ return apply_filters( 'rocket_capacity', 'manage_options' ); } +add_filter( 'option_page_capability_wp_rocket', 'rocket_correct_capability_for_options_page' ); /** * Add submenu in menu "Settings" * * @since 1.0 */ -add_action( 'admin_menu', 'rocket_admin_menu' ); function rocket_admin_menu() { - // do not use WP_ROCKET_PLUGIN_NAME here because if the WL has just been activated, the constant is not correct yet + // do not use WP_ROCKET_PLUGIN_NAME here because if the WL has just been activated, the constant is not correct yet. $wl_plugin_name = get_rocket_option( 'wl_plugin_name', WP_ROCKET_PLUGIN_NAME ); - // same with WP_ROCKET_PLUGIN_SLUG + // same with WP_ROCKET_PLUGIN_SLUG. $wl_plugin_slug = sanitize_key( $wl_plugin_name ); add_options_page( $wl_plugin_name, $wl_plugin_name, apply_filters( 'rocket_capacity', 'manage_options' ), $wl_plugin_slug, 'rocket_display_options' ); } +add_action( 'admin_menu', 'rocket_admin_menu' ); /** * Used to display fields on settings form * * @since 1.0 + * + * @param array $args An array of arguments to populate the settings fields. */ function rocket_field( $args ) { - if( ! is_array( reset( $args ) ) ) { + if ( ! is_array( reset( $args ) ) ) { $args = array( $args ); } $full = $args; foreach ( $full as $args ) { - if ( isset( $args['display'] ) && !$args['display'] ) { + if ( ! is_array( $args ) ) { + continue; + } + + if ( isset( $args['display'] ) && ! $args['display'] ) { continue; } $args['label_for'] = isset( $args['label_for'] ) ? $args['label_for'] : ''; $args['name'] = isset( $args['name'] ) ? $args['name'] : $args['label_for']; - $parent = isset( $args['parent'] ) ? 'data-parent="' . sanitize_html_class( $args['parent' ] ). '"' : null; - $placeholder = isset( $args['placeholder'] ) ? 'placeholder="'. $args['placeholder'].'" ' : ''; + $parent = isset( $args['parent'] ) ? 'data-parent="' . sanitize_html_class( $args['parent'] ) . '"' : null; + $placeholder = isset( $args['placeholder'] ) ? 'placeholder="' . $args['placeholder'] . '" ' : ''; $class = isset( $args['class'] ) ? sanitize_html_class( $args['class'] ) : sanitize_html_class( $args['name'] ); $class .= ( $parent ) ? ' has-parent' : null; $label = isset( $args['label'] ) ? $args['label'] : ''; @@ -55,24 +65,28 @@ function rocket_field( $args ) { $cols = isset( $args['cols'] ) ? (int) $args['cols'] : 50; $rows = isset( $args['rows'] ) ? (int) $args['rows'] : 5; - if( ! isset( $args['fieldset'] ) || 'start' == $args['fieldset'] ){ - echo '
    '; + if ( ! isset( $args['fieldset'] ) || 'start' === $args['fieldset'] ) { + printf( '
    ', + sanitize_html_class( $args['name'] ), + sanitize_html_class( $args['type'] ), + isset( $args['parent'] ) ? 'fieldparent-' . sanitize_html_class( $args['parent'] ) : '' + ); } - switch( $args['type'] ) { + switch ( $args['type'] ) { case 'number' : case 'email' : case 'text' : $value = get_rocket_option( $args['name'] ); - if ( $value === false ) { + if ( false === $value ) { $value = $default; } $value = esc_attr( $value ); - $number_options = $args['type']=='number' ? ' min="0" class="small-text"' : ''; - $autocomplete = in_array( $args['name'], array( 'consumer_key', 'consumer_email' ) ) ? ' autocomplete="off"' : ''; - $disabled = ( 'consumer_key' == $args['name'] && defined( 'WP_ROCKET_KEY' ) ) || ( 'consumer_email' == $args['name'] && defined( 'WP_ROCKET_EMAIL' ) ) ? ' disabled="disabled"' : $readonly; + $number_options = 'number' === $args['type'] ? ' min="0" class="small-text"' : ''; + $autocomplete = in_array( $args['name'], array( 'consumer_key', 'consumer_email' ), true ) ? ' autocomplete="off"' : ''; + $disabled = ( 'consumer_key' === $args['name'] && defined( 'WP_ROCKET_KEY' ) ) || ( 'consumer_email' === $args['name'] && defined( 'WP_ROCKET_EMAIL' ) ) ? ' disabled="disabled"' : $readonly; ?> @@ -81,54 +95,54 @@ function rocket_field( $args ) { - + -