Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\Seo\is_seo_tools_disabled
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * Block Editor - SEO feature.
4 *
5 * @package automattic/jetpack
6 */
7
8namespace Automattic\Jetpack\Extensions\Seo;
9
10use Automattic\Jetpack\Modules;
11use Automattic\Jetpack\SEO\Initializer;
12
13if ( ! defined( 'ABSPATH' ) ) {
14    exit( 0 );
15}
16
17add_action(
18    'jetpack_register_gutenberg_extensions',
19    function () {
20        if ( is_seo_tools_disabled() ) {
21            return;
22        }
23
24        \Jetpack_Gutenberg::set_extension_available( 'advanced-seo' );
25    }
26);
27
28/**
29 * We only want to enable the SEO extension (and display SEO settings)
30 * if the 'jetpack_disable_seo_tools' filter is not set to false.
31 *
32 * This is done on after_setup_theme to ensure that we have access to the hook
33 * that is used by SEO plugins to disable the conflicting output of SEO Tools.
34 */
35add_action(
36    'after_setup_theme',
37    function () {
38        if (
39            ! is_seo_tools_disabled()
40            /** This filter is documented in projects/packages/seo/src/class-seo-tools.php */
41            && ! apply_filters( 'jetpack_disable_seo_tools', false )
42        ) {
43            \Jetpack_Gutenberg::set_extension_available( 'jetpack-seo' );
44        }
45    }
46);
47
48add_filter(
49    'jetpack_set_available_extensions',
50    function ( $extensions ) {
51        return array_merge(
52            (array) $extensions,
53            array( 'advanced-seo' )
54        );
55    }
56);
57
58/**
59 * SEO tools should be hidden from non-admins if the module is not active.
60 *
61 * @since 14.6
62 *
63 * @return bool
64 */
65function is_seo_tools_disabled(): bool {
66    // Hidden from everyone while the SEO switch holds SEO Tools off.
67    if ( method_exists( Initializer::class, 'get_paused_modules' ) && in_array( 'seo-tools', Initializer::get_paused_modules(), true ) ) {
68        return true;
69    }
70
71    return ! ( new Modules() )->is_active( 'seo-tools' ) && ! current_user_can( 'jetpack_activate_modules' );
72}