1 | <?php |
||
13 | class Jetpack_Related_Posts_Customize { |
||
14 | |||
15 | /** |
||
16 | * Key for panel, section and prefix for options. Same option name than in Options > Reading. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | var $prefix = 'jetpack_relatedposts'; |
||
|
|||
21 | |||
22 | /** |
||
23 | * @var string Control to focus when customizer loads. |
||
24 | */ |
||
25 | var $focus = ''; |
||
26 | |||
27 | /** |
||
28 | * Class initialization. |
||
29 | * |
||
30 | * @since 4.4.0 |
||
31 | */ |
||
32 | function __construct() { |
||
33 | add_action( 'customize_register', array( $this, 'customize_register' ) ); |
||
34 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'customize_controls_enqueue_scripts' ) ); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Initialize Customizer controls. |
||
39 | * |
||
40 | * @since 4.4.0 |
||
41 | * |
||
42 | * @param WP_Customize_Manager $wp_customize Customizer instance. |
||
43 | */ |
||
44 | function customize_register( $wp_customize ) { |
||
45 | |||
46 | $wp_customize->add_section( $this->prefix, |
||
47 | array( |
||
48 | 'title' => esc_html__( 'Related Posts', 'jetpack' ), |
||
49 | 'description' => '', |
||
50 | 'capability' => 'edit_theme_options', |
||
51 | 'priority' => 200, |
||
52 | ) |
||
53 | ); |
||
54 | |||
55 | $selective_options = array(); |
||
56 | |||
57 | foreach ( $this->get_options( $wp_customize ) as $key => $field ) { |
||
58 | $control_id = "$this->prefix[$key]"; |
||
59 | $selective_options[] = $control_id; |
||
60 | $wp_customize->add_setting( $control_id, |
||
61 | array( |
||
62 | 'default' => isset( $field['default'] ) ? $field['default'] : '', |
||
63 | 'type' => isset( $field['setting_type'] ) ? $field['setting_type'] : 'option', |
||
64 | 'capability' => isset( $field['capability'] ) ? $field['capability'] : 'edit_theme_options', |
||
65 | 'transport' => isset( $field['transport'] ) ? $field['transport'] : 'postMessage', |
||
66 | ) |
||
67 | ); |
||
68 | $control_settings = array( |
||
69 | 'label' => isset( $field['label'] ) ? $field['label'] : '', |
||
70 | 'description' => isset( $field['description'] ) ? $field['description'] : '', |
||
71 | 'settings' => $control_id, |
||
72 | 'type' => isset( $field['control_type'] ) ? $field['control_type'] : 'text', |
||
73 | 'section' => $this->prefix, |
||
74 | 'priority' => 10, |
||
75 | 'active_callback' => isset( $field['active_callback'] ) ? $field['active_callback'] : __CLASS__ . '::is_single', |
||
76 | ); |
||
77 | switch ( $field['control_type'] ) { |
||
78 | case 'text': |
||
79 | case 'checkbox': |
||
80 | default: |
||
81 | $wp_customize->add_control( new WP_Customize_Control( $wp_customize, $control_id, $control_settings ) ); |
||
82 | break; |
||
83 | case 'select': |
||
84 | if ( isset( $field['choices'] ) ) { |
||
85 | $control_settings['choices'] = $field['choices']; |
||
86 | $wp_customize->add_control( new WP_Customize_Control( $wp_customize, $control_id, $control_settings ) ); |
||
87 | } |
||
88 | break; |
||
89 | case 'message': |
||
90 | $wp_customize->add_control( new Jetpack_Message_Control( $wp_customize, $control_id, $control_settings ) ); |
||
91 | break; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | // If selective refresh is available, implement it. |
||
96 | if ( isset( $wp_customize->selective_refresh ) ) { |
||
97 | $wp_customize->selective_refresh->add_partial( "$this->prefix", array( |
||
98 | 'selector' => '.jp-relatedposts', |
||
99 | 'settings' => $selective_options, |
||
100 | 'render_callback' => __CLASS__ . '::render_callback', |
||
101 | 'container_inclusive' => false, |
||
102 | ) ); |
||
103 | } |
||
104 | |||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Callback that outputs the headline based on user choice. |
||
109 | * |
||
110 | * @since 4.4.0 |
||
111 | */ |
||
112 | public static function render_callback() { |
||
115 | |||
116 | /** |
||
117 | * Check that we're in a single post view. |
||
118 | * |
||
119 | * @since 4.4.0 |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public static function is_single() { |
||
126 | |||
127 | /** |
||
128 | * Check that we're not in a single post view. |
||
129 | * |
||
130 | * @since 4.4.0 |
||
131 | * |
||
132 | * @return bool |
||
133 | */ |
||
134 | public static function is_not_single() { |
||
137 | |||
138 | /** |
||
139 | * Return list of options to modify. |
||
140 | * |
||
141 | * @since 4.4.0 |
||
142 | * |
||
143 | * @param object $wp_customize Instance of WP Customizer |
||
144 | * |
||
145 | * @return mixed|void |
||
146 | */ |
||
147 | function get_options( $wp_customize ) { |
||
231 | |||
232 | /** |
||
233 | * Enqueue assets for Customizer controls. |
||
234 | * |
||
235 | * @since 4.4.0 |
||
236 | */ |
||
237 | function customize_controls_enqueue_scripts() { |
||
240 | |||
241 | } // class end |
||
242 | |||
261 | new Jetpack_Related_Posts_Customize; |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.