css
5 years ago
js
5 years ago
class-atomic-additional-css-manager.php
3 years ago
class-css-customizer-nudge.php
5 years ago
class-css-nudge-customize-control.php
5 years ago
class-wpcom-additional-css-manager.php
3 years ago
class-css-customizer-nudge.php
132 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CSS_Customizer_Nudge file. |
| 4 | * CSS Nudge implementation for Atomic and WPCOM. |
| 5 | * |
| 6 | * @package Jetpack |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\Dashboard_Customizations; |
| 10 | |
| 11 | /** |
| 12 | * Class WPCOM_CSS_Customizer |
| 13 | * |
| 14 | * @package Automattic\Jetpack\Dashboard_Customizations |
| 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 | \wp_enqueue_script( |
| 56 | 'additional-css-js', |
| 57 | plugins_url( 'js/additional-css.js', __FILE__ ), |
| 58 | array(), |
| 59 | JETPACK__VERSION, |
| 60 | true |
| 61 | ); |
| 62 | \wp_enqueue_style( |
| 63 | 'additional-css', |
| 64 | plugins_url( 'css/additional-css.css', __FILE__ ), |
| 65 | array(), |
| 66 | JETPACK__VERSION |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Register the CSS nudge in the Customizer. |
| 72 | * |
| 73 | * @param \WP_Customize_Manager $wp_customize The customize manager. |
| 74 | */ |
| 75 | public function customize_register_nudge( \WP_Customize_Manager $wp_customize ) { |
| 76 | // Show a nudge in place of the normal CSS section. |
| 77 | \add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts_nudge' ) ); |
| 78 | |
| 79 | $wp_customize->add_setting( |
| 80 | $this->control_name . '[dummy_setting]', |
| 81 | array( |
| 82 | 'type' => $this->control_name . '_dummy_setting', |
| 83 | 'default' => '', |
| 84 | 'transport' => 'refresh', |
| 85 | ) |
| 86 | ); |
| 87 | |
| 88 | $wp_customize->add_section( $this->create_css_nudge_section( $wp_customize ) ); |
| 89 | |
| 90 | $wp_customize->add_control( $this->create_css_nudge_control( $wp_customize ) ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Create a nudge control object. |
| 95 | * |
| 96 | * @param \WP_Customize_Manager $wp_customize The Core Customize Manager. |
| 97 | * |
| 98 | * @return CSS_Nudge_Customize_Control |
| 99 | */ |
| 100 | public function create_css_nudge_control( \WP_Customize_Manager $wp_customize ) { |
| 101 | return new CSS_Nudge_Customize_Control( |
| 102 | $wp_customize, |
| 103 | $this->control_name . '_control', |
| 104 | array( |
| 105 | 'cta_url' => $this->cta_url, |
| 106 | 'nudge_copy' => $this->nudge_copy, |
| 107 | 'label' => __( 'Custom CSS', 'jetpack' ), |
| 108 | 'section' => $this->control_name, |
| 109 | 'settings' => $this->control_name . '[dummy_setting]', |
| 110 | ) |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Create the nudge section. |
| 116 | * |
| 117 | * @param \WP_Customize_Manager $wp_customize The core Customize Manager. |
| 118 | * |
| 119 | * @return \WP_Customize_Section |
| 120 | */ |
| 121 | public function create_css_nudge_section( \WP_Customize_Manager $wp_customize ) { |
| 122 | return new \WP_Customize_Section( |
| 123 | $wp_customize, |
| 124 | $this->control_name, |
| 125 | array( |
| 126 | 'title' => __( 'Additional CSS', 'jetpack' ), |
| 127 | 'priority' => 200, |
| 128 | ) |
| 129 | ); |
| 130 | } |
| 131 | } |
| 132 |