PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / jetpack_vendor / automattic / jetpack-masterbar / src / nudges / additional-css / class-css-customizer-nudge.php

class-css-customizer-nudge.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-masterbar/src/nudges/additional-css/class-css-customizer-nudge.php

130 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
130