| @@ -6,21 +6,61 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Extensions\Seo; |
| 9 | 9 | |
| 10 | +use Automattic\Jetpack\Modules; | |
| 11 | + | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | + exit( 0 ); | |
| 14 | +} | |
| 15 | + | |
| 10 | 16 | add_action( |
| 11 | 17 | 'jetpack_register_gutenberg_extensions', |
| 12 | 18 | function () { |
| 19 | + if ( is_seo_disabled() ) { | |
| 20 | + return; | |
| 21 | + } | |
| 22 | + | |
| 13 | 23 | \Jetpack_Gutenberg::set_availability_for_plan( 'advanced-seo' ); |
| 14 | - \Jetpack_Gutenberg::set_extension_available( 'jetpack-seo' ); | |
| 15 | 24 | } |
| 16 | 25 | ); |
| 17 | 26 | |
| 27 | +/** | |
| 28 | + * We only want to enable the SEO extension (and display SEO settings) | |
| 29 | + * if the 'jetpack_disable_seo_tools' filter is not set to false. | |
| 30 | + * | |
| 31 | + * This is done on after_setup_theme to ensure that we have access to the hook | |
| 32 | + * that is used by SEO plugins to disable the conflicting output of SEO Tools. | |
| 33 | + */ | |
| 34 | +add_action( | |
| 35 | + 'after_setup_theme', | |
| 36 | + function () { | |
| 37 | + if ( | |
| 38 | + ! is_seo_disabled() | |
| 39 | + /** This filter is already documented in modules/seo-tools/class-jetpack-seo-utils.php */ | |
| 40 | + && ! apply_filters( 'jetpack_disable_seo_tools', false ) | |
| 41 | + ) { | |
| 42 | + \Jetpack_Gutenberg::set_extension_available( 'jetpack-seo' ); | |
| 43 | + } | |
| 44 | + } | |
| 45 | +); | |
| 46 | + | |
| 18 | 47 | add_filter( |
| 19 | 48 | 'jetpack_set_available_extensions', |
| 20 | 49 | function ( $extensions ) { |
| 21 | 50 | return array_merge( |
| 22 | - $extensions, | |
| 51 | + (array) $extensions, | |
| 23 | 52 | array( 'advanced-seo' ) |
| 24 | 53 | ); |
| 25 | 54 | } |
| 26 | 55 | ); |
| 56 | + | |
| 57 | +/** | |
| 58 | + * SEO tools should be hidden from non-admins if the module is not active. | |
| 59 | + * | |
| 60 | + * @since 14.6 | |
| 61 | + * | |
| 62 | + * @return bool | |
| 63 | + */ | |
| 64 | +function is_seo_disabled(): bool { | |
| 65 | + return ! ( new Modules() )->is_active( 'seo-tools' ) && ! current_user_can( 'jetpack_activate_modules' ); | |
| 66 | +} | |