| 1 |
<?php |
| 2 |
/** |
| 3 |
* Block Editor - SEO feature. |
| 4 |
* |
| 5 |
* @package automattic/jetpack |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Extensions\Seo; |
| 9 |
|
| 10 |
use Automattic\Jetpack\Modules; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit( 0 ); |
| 14 |
} |
| 15 |
|
| 16 |
add_action( |
| 17 |
'jetpack_register_gutenberg_extensions', |
| 18 |
function () { |
| 19 |
if ( is_seo_disabled() ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
\Jetpack_Gutenberg::set_availability_for_plan( 'advanced-seo' ); |
| 24 |
} |
| 25 |
); |
| 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 |
|
| 47 |
add_filter( |
| 48 |
'jetpack_set_available_extensions', |
| 49 |
function ( $extensions ) { |
| 50 |
return array_merge( |
| 51 |
(array) $extensions, |
| 52 |
array( 'advanced-seo' ) |
| 53 |
); |
| 54 |
} |
| 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 |
} |
| 67 |
|