Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
43 / 43 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CSS_Customizer_Nudge | |
100.00% |
43 / 43 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| customize_controls_enqueue_scripts_nudge | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| customize_register_nudge | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| create_css_nudge_control | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| create_css_nudge_section | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * CSS_Customizer_Nudge file. |
| 4 | * CSS Nudge implementation for Atomic and WPCOM. |
| 5 | * |
| 6 | * @package automattic/jetpack-masterbar |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\Masterbar; |
| 10 | |
| 11 | use Automattic\Jetpack\Assets; |
| 12 | |
| 13 | /** |
| 14 | * Class WPCOM_CSS_Customizer |
| 15 | */ |
| 16 | class CSS_Customizer_Nudge { |
| 17 | /** |
| 18 | * Call to Action URL. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | private $cta_url; |
| 23 | |
| 24 | /** |
| 25 | * The nudge message. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | private $nudge_copy; |
| 30 | |
| 31 | /** |
| 32 | * The name of the control in Customizer. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | private $control_name; |
| 37 | |
| 38 | /** |
| 39 | * CSS_Customizer_Nudge constructor. |
| 40 | * |
| 41 | * @param string $cta_url The URL to the plans. |
| 42 | * @param string $nudge_copy The nudge text. |
| 43 | * @param string $control_name The slug prefix of the nudge. |
| 44 | */ |
| 45 | public function __construct( $cta_url, $nudge_copy, $control_name = 'custom_css' ) { |
| 46 | $this->cta_url = $cta_url; |
| 47 | $this->nudge_copy = $nudge_copy; |
| 48 | $this->control_name = $control_name; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Register the assets required for the CSS nudge page from the Customizer. |
| 53 | */ |
| 54 | public function customize_controls_enqueue_scripts_nudge() { |
| 55 | $assets_base_path = '../../../dist/nudges/additional-css/'; |
| 56 | |
| 57 | Assets::register_script( |
| 58 | 'additional-css-js', |
| 59 | $assets_base_path . 'additional-css.js', |
| 60 | __FILE__, |
| 61 | array( |
| 62 | 'enqueue' => true, |
| 63 | 'css_path' => $assets_base_path . 'additional-css.css', |
| 64 | ) |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Register the CSS nudge in the Customizer. |
| 70 | * |
| 71 | * @param \WP_Customize_Manager $wp_customize The customize manager. |
| 72 | */ |
| 73 | public function customize_register_nudge( \WP_Customize_Manager $wp_customize ) { |
| 74 | // Show a nudge in place of the normal CSS section. |
| 75 | \add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts_nudge' ) ); |
| 76 | |
| 77 | $wp_customize->add_setting( |
| 78 | $this->control_name . '[dummy_setting]', |
| 79 | array( |
| 80 | 'type' => $this->control_name . '_dummy_setting', |
| 81 | 'default' => '', |
| 82 | 'transport' => 'refresh', |
| 83 | ) |
| 84 | ); |
| 85 | |
| 86 | $wp_customize->add_section( $this->create_css_nudge_section( $wp_customize ) ); |
| 87 | |
| 88 | $wp_customize->add_control( $this->create_css_nudge_control( $wp_customize ) ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Create a nudge control object. |
| 93 | * |
| 94 | * @param \WP_Customize_Manager $wp_customize The Core Customize Manager. |
| 95 | * |
| 96 | * @return CSS_Nudge_Customize_Control |
| 97 | */ |
| 98 | public function create_css_nudge_control( \WP_Customize_Manager $wp_customize ) { |
| 99 | return new CSS_Nudge_Customize_Control( |
| 100 | $wp_customize, |
| 101 | $this->control_name . '_control', |
| 102 | array( |
| 103 | 'cta_url' => $this->cta_url, |
| 104 | 'nudge_copy' => $this->nudge_copy, |
| 105 | 'label' => __( 'Custom CSS', 'jetpack-masterbar' ), |
| 106 | 'section' => $this->control_name, |
| 107 | 'settings' => $this->control_name . '[dummy_setting]', |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Create the nudge section. |
| 114 | * |
| 115 | * @param \WP_Customize_Manager $wp_customize The core Customize Manager. |
| 116 | * |
| 117 | * @return \WP_Customize_Section |
| 118 | */ |
| 119 | public function create_css_nudge_section( \WP_Customize_Manager $wp_customize ) { |
| 120 | return new \WP_Customize_Section( |
| 121 | $wp_customize, |
| 122 | $this->control_name, |
| 123 | array( |
| 124 | 'title' => __( 'Additional CSS', 'jetpack-masterbar' ), |
| 125 | 'priority' => 200, |
| 126 | ) |
| 127 | ); |
| 128 | } |
| 129 | } |