From 052156c05d3e3f46a95e2770789f679ae8387e3d Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 10:22:39 -0600 Subject: [PATCH 1/7] adds a quick check if Yoast Premium is active this can be used by a bunch of things to enable/disable features --- inc/namespace.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/inc/namespace.php b/inc/namespace.php index 8a161f0..5d83bef 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -71,6 +71,15 @@ function load_redirects() { require_once Altis\ROOT_DIR . '/vendor/humanmade/hm-redirects/hm-redirects.php'; } +/** + * Checks if Yoast SEO Premium is installed. + * + * @return bool + */ +function is_yoast_premium() : bool { + return class_exists( 'WPSEO_Premium' ); +} + /** * Load Yoast SEO. */ From a55a7c908d0fde6f42ac4c0bce8e10574e8cafba Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 10:23:07 -0600 Subject: [PATCH 2/7] bail early if yoast premium is active premium overrides free version. --- inc/namespace.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/namespace.php b/inc/namespace.php index 5d83bef..5b0ea22 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -84,7 +84,9 @@ function is_yoast_premium() : bool { * Load Yoast SEO. */ function load_wpseo() { - $wpseo_file = Altis\ROOT_DIR . '/vendor/yoast/wordpress-seo/wp-seo.php'; + if ( is_yoast_premium() ) { + return; + } // Define a fake WP SEO Premium File value if we don't have WP SEO Premium installed. This hides some of the upsell UI. if ( ! class_exists( 'WPSEO_Premium' ) ) { From d6eeb832cb49eb99e25f3a624fbabec6c5f92e2b Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 10:23:47 -0600 Subject: [PATCH 3/7] we don't actually need to spoof yoast premium in fact it leads to problems with labelling & makes things appear that Premium is active when it's actually not --- inc/namespace.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index 5b0ea22..c264905 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -88,14 +88,7 @@ function load_wpseo() { return; } - // Define a fake WP SEO Premium File value if we don't have WP SEO Premium installed. This hides some of the upsell UI. - if ( ! class_exists( 'WPSEO_Premium' ) ) { - if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { - define( 'WPSEO_PREMIUM_FILE', $wpseo_file ); - define( 'WPSEO_PREMIUM_VERSION', Altis\get_version() ); - } - require_once $wpseo_file; - } + require_once Altis\ROOT_DIR . '/vendor/yoast/wordpress-seo/wp-seo.php'; } /** From 68c8627293b32b4b58bfebde99365ae16e852f29 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 11:08:23 -0600 Subject: [PATCH 4/7] hide the social tab if Yoast Premium is not active prevents the social tab from displaying in the yoast metabox if Yoast Premium is inactive --- inc/namespace.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inc/namespace.php b/inc/namespace.php index c264905..d7424d8 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -50,6 +50,7 @@ function bootstrap( Module $module ) { // CSS overrides. add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\enqueue_yoast_css_overrides', 11 ); add_action( 'wpseo_configuration_wizard_head', __NAMESPACE__ . '\\override_wizard_styles' ); + add_action( 'admin_head', __NAMESPACE__ . '\\hide_yoast_premium_social_previews' ); } /** @@ -252,3 +253,26 @@ function override_wizard_styles() { wp_register_style( 'altis-seo', plugin_dir_url( dirname( __FILE__ ) ) . 'assets/global-styles.css', [], '2021-06-04-5' ); wp_print_styles( 'altis-seo' ); } + +/** + * Hide the social previews if Yoast Premium is not active. + */ +function hide_yoast_premium_social_previews() { + $screen = get_current_screen(); + + // Bail early if Yoast Premium is active or if we aren't on a post edit screen. + if ( is_yoast_premium() || $screen->base !== 'post' ) { + return; + } + + /** + * Hide the Social tab in the Yoast Metabox. + * The Google preview is in the basic SEO tab and social previews + * are only available for Yoast SEO Premium. + */ + $styles .= '.wpseo-metabox-menu .yoast-aria-tabs li:last-of-type { + display:none; + }'; + + echo ""; +} \ No newline at end of file From 61db5f98b63b443391dc7155db14b3b1614b1338 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 11:09:12 -0600 Subject: [PATCH 5/7] Hide the sidebar panels for social previews if Premium isn't active --- inc/namespace.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/inc/namespace.php b/inc/namespace.php index d7424d8..5004c6c 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -265,6 +265,16 @@ function hide_yoast_premium_social_previews() { return; } + /** + * This targets the 6th and 7th components panel in the Yoast + * sidebar, which corresponds to the Facebook and Twitter social + * preview buttons. If Yoast ever adds more panels to this sidebar, + * this will need to be updated. + */ + $styles = 'div.components-panel div:nth-child(6n) div.yoast.components-panel__body, div.components-panel div:nth-child(7n) div.yoast.components-panel__body { + display: none; + }'; + /** * Hide the Social tab in the Yoast Metabox. * The Google preview is in the basic SEO tab and social previews @@ -275,4 +285,4 @@ function hide_yoast_premium_social_previews() { }'; echo ""; -} \ No newline at end of file +} From 1d4bbf7fe813c400309c1d47f179d218131861dc Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 11:19:44 -0600 Subject: [PATCH 6/7] ignore phpcs rule about escaping output we're hard-coding what's going into the echo here with no possibility of outside insertions. --- inc/namespace.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/namespace.php b/inc/namespace.php index 5004c6c..b9b03c8 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -284,5 +284,5 @@ function hide_yoast_premium_social_previews() { display:none; }'; - echo ""; + echo ""; // phpcs:ignore HM.Security.EscapeOutput.OutputNotEscaped } From 74e6370038cb74fb9bad6b02899b279873fdd957 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 21 Jun 2021 13:08:23 -0600 Subject: [PATCH 7/7] add a line break to try to retrigger the linter --- inc/namespace.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/inc/namespace.php b/inc/namespace.php index b9b03c8..73fc972 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -41,6 +41,15 @@ function bootstrap( Module $module ) { // Remove Yoast SEO dashboard widget. add_action( 'admin_init', __NAMESPACE__ . '\\remove_yoast_dashboard_widget' ); + // Remove the Yoast Premium submenu page. + add_action( 'admin_init', __NAMESPACE__ . '\\remove_yoast_submenu_page' ); + + // Remove Helpscout. + add_filter( 'wpseo_helpscout_show_beacon', '__return_false' ); + + // Hide the HUGE SEO ISSUE warning and disable admin bar menu. + add_filter( 'pre_option_wpseo', __NAMESPACE__ . '\\override_yoast_seo_options' ); + // Read config/robots.txt file into robots.txt route handled by WP. add_filter( 'robots_txt', __NAMESPACE__ . '\\robots_txt', 10 ); @@ -103,6 +112,13 @@ function remove_yoast_dashboard_widget() { wp_dequeue_style( 'wp-dashboard' ); } +/** + * Remove the Premium submenu. + */ +function remove_yoast_submenu_page() { + remove_submenu_page( 'wpseo_dashboard', 'wpseo_licenses' ); +} + /** * Load the SEO metadata plugin. * @@ -193,6 +209,27 @@ function metadata_img_as_tachyon( array $meta, array $img_settings = [] ) : arra return $meta; } +/** + * Override the Yoast SEO options. + * + * Disables the Search Engines Discouraged warning on non-production environments and the admin bar menu. + * + * @param mixed $options The option to retrieve. + * + * @return array The updated WPSEO options. + */ +function override_yoast_seo_options( $options ) : ?array { + $options['enable_admin_bar_menu'] = false; + + if ( Altis\get_environment_type() === 'production' ) { + return $options; + } + + $options['ignore_search_engines_discouraged_notice'] = true; + + return $options; +} + /** * Add robots.txt content if file is present. * @@ -277,6 +314,7 @@ function hide_yoast_premium_social_previews() { /** * Hide the Social tab in the Yoast Metabox. + * * The Google preview is in the basic SEO tab and social previews * are only available for Yoast SEO Premium. */