bootstrap.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Bootstrap file for the nudges. |
| 4 | * |
| 5 | * @package Jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Dashboard_Customizations; |
| 9 | |
| 10 | use Automattic\Jetpack\Status; |
| 11 | use Automattic\Jetpack\Status\Host; |
| 12 | |
| 13 | /** |
| 14 | * The WP_Customize_Control core class is loaded only on customize_register. |
| 15 | * |
| 16 | * @param \WP_Customize_Manager $customize_manager Core customize manager. |
| 17 | */ |
| 18 | function register_css_nudge_control( \WP_Customize_Manager $customize_manager ) { |
| 19 | require_once __DIR__ . '/additional-css/class-css-nudge-customize-control.php'; |
| 20 | require_once __DIR__ . '/additional-css/class-css-customizer-nudge.php'; |
| 21 | |
| 22 | $domain = ( new Status() )->get_site_suffix(); |
| 23 | |
| 24 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 25 | require_once __DIR__ . '/additional-css/class-wpcom-additional-css-manager.php'; |
| 26 | $manager = new WPCOM_Additional_CSS_Manager( $domain ); |
| 27 | } elseif ( ( new Host() )->is_woa_site() ) { |
| 28 | require_once __DIR__ . '/additional-css/class-atomic-additional-css-manager.php'; |
| 29 | $manager = new Atomic_Additional_CSS_Manager( $domain ); |
| 30 | } |
| 31 | |
| 32 | if ( ! isset( $manager ) ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | $manager->register_nudge( $customize_manager ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Load the bootstrap on init action. |
| 41 | * |
| 42 | * We need to load on init because otherwise the filter will not be set to true in WPCOM (since the add_filter is set on init). |
| 43 | */ |
| 44 | function load_bootstrap_on_init() { |
| 45 | |
| 46 | /** |
| 47 | * Disable Additional CSS section from Customizer in WPCOM and Atomic and replace it with a nudge. |
| 48 | * |
| 49 | * @module masterbar |
| 50 | * |
| 51 | * @since 9.9.0 |
| 52 | * |
| 53 | * @param bool |
| 54 | */ |
| 55 | if ( \apply_filters( 'jetpack_customize_enable_additional_css_nudge', false ) ) { |
| 56 | \add_action( 'customize_register', __NAMESPACE__ . '\register_css_nudge_control' ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | add_action( 'init', __NAMESPACE__ . '\load_bootstrap_on_init' ); |
| 61 |