PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | settings/settings-module.php +30 -113 3.02.3.6 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Base class for all settings
8 5 *
@@ -8,85 +5,14 @@
8 5 *
9 6 * @since 1.8
10 7 */
11 8 class PLL_Settings_Module {
12 - /**
13 - * Stores the plugin options.
14 - *
15 - * @var array
16 - */
9 + public $active_option, $configure;
10 + public $module, $title, $description;
17 11 public $options;
12 + protected $action_links, $buttons, $form = false;
18 13
19 14 /**
20 - * @var PLL_Model
21 - */
22 - public $model;
23 -
24 - /**
25 - * Instance of a child class of PLL_Links_Model.
26 - *
27 - * @var PLL_Links_Model
28 - */
29 - public $links_model;
30 -
31 - /**
32 - * Stores if the module is active.
33 - *
34 - * @var bool
35 - */
36 - public $active_option;
37 -
38 - /**
39 - * Stores the display order priority.
40 - *
41 - * @var int
42 - */
43 - public $priority = 100;
44 -
45 - /**
46 - * Stores the module name.
47 - * It must be unique.
48 - *
49 - * @var string
50 - */
51 - public $module;
52 -
53 - /**
54 - * Stores the module title.
55 - *
56 - * @var string
57 - */
58 - public $title;
59 -
60 - /**
61 - * Stores the module description.
62 - *
63 - * @var string
64 - */
65 - public $description;
66 -
67 - /**
68 - * Stores the settings actions.
69 - *
70 - * @var array
71 - */
72 - protected $action_links;
73 -
74 - /**
75 - * Stores html fragment for the buttons.
76 - *
77 - * @var array
78 - */
79 - protected $buttons;
80 -
81 - /**
82 - * Stores html form when provided by a child class.
83 - *
84 - * @var bool|string
85 - */
86 - protected $form = false;
87 -
88 - /**
89 15 * Constructor
90 16 *
91 17 * @since 1.8
92 18 *
@@ -97,16 +23,13 @@
97 23 $this->options = &$polylang->options;
98 24 $this->model = &$polylang->model;
99 25 $this->links_model = &$polylang->links_model;
100 26
101 - $args = wp_parse_args(
102 - $args,
103 - array(
104 - 'title' => '',
105 - 'description' => '',
106 - 'active_option' => false,
107 - )
108 - );
27 + $args = wp_parse_args( $args, array(
28 + 'title' => '',
29 + 'description' => '',
30 + 'active_option' => false,
31 + ) );
109 32
110 33 foreach ( $args as $prop => $value ) {
111 34 $this->$prop = $value;
112 35 }
@@ -112,33 +35,37 @@
112 35 }
113 36
114 37 // All possible action links, even if not always a link ;-)
115 38 $this->action_links = array(
116 - 'configure' => sprintf(
39 + 'configure' => sprintf(
117 40 '<a title="%s" href="%s">%s</a>',
118 41 esc_attr__( 'Configure this module', 'polylang' ),
119 42 '#',
120 43 esc_html__( 'Settings', 'polylang' )
121 44 ),
122 - 'deactivate' => sprintf(
45 +
46 + 'deactivate' => sprintf(
123 47 '<a title="%s" href="%s">%s</a>',
124 48 esc_attr__( 'Deactivate this module', 'polylang' ),
125 - esc_url( wp_nonce_url( '?page=mlang&tab=modules&pll_action=deactivate&noheader=true&module=' . $this->module, 'pll_deactivate' ) ),
49 + wp_nonce_url( '?page=mlang&amp;tab=modules&amp;pll_action=deactivate&amp;noheader=true&amp;module=' . $this->module, 'pll_deactivate' ),
126 50 esc_html__( 'Deactivate', 'polylang' )
127 51 ),
128 - 'activate' => sprintf(
52 +
53 + 'activate' => sprintf(
129 54 '<a title="%s" href="%s">%s</a>',
130 55 esc_attr__( 'Activate this module', 'polylang' ),
131 - esc_url( wp_nonce_url( '?page=mlang&tab=modules&pll_action=activate&noheader=true&module=' . $this->module, 'pll_activate' ) ),
56 + wp_nonce_url( '?page=mlang&amp;tab=modules&amp;pll_action=activate&amp;noheader=true&amp;module=' . $this->module, 'pll_activate' ),
132 57 esc_html__( 'Activate', 'polylang' )
133 58 ),
134 - 'activated' => esc_html__( 'Activated', 'polylang' ),
59 +
60 + 'activated' => esc_html__( 'Activated', 'polylang' ),
61 +
135 62 'deactivated' => esc_html__( 'Deactivated', 'polylang' ),
136 63 );
137 64
138 65 $this->buttons = array(
139 - 'cancel' => sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', esc_html__( 'Cancel', 'polylang' ) ),
140 - 'save' => sprintf( '<button type="button" class="button button-primary save">%s</button>', esc_html__( 'Save Changes', 'polylang' ) ),
66 + 'cancel' => sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', esc_html__( 'Cancel' ) ),
67 + 'save' => sprintf( '<button type="button" class="button button-primary save">%s</button>', esc_html__( 'Save Changes' ) ),
141 68 );
142 69
143 70 // Ajax action to save options
144 71 add_action( 'wp_ajax_pll_save_options', array( $this, 'save_options' ) );
@@ -158,10 +85,8 @@
158 85 /**
159 86 * Activates the module
160 87 *
161 88 * @since 1.8
162 - *
163 - * @return void
164 89 */
165 90 public function activate() {
166 91 if ( ! empty( $this->active_option ) ) {
167 92 $this->options[ $this->active_option ] = true;
@@ -172,10 +97,8 @@
172 97 /**
173 98 * Deactivates the module
174 99 *
175 100 * @since 1.8
176 - *
177 - * @return void
178 101 */
179 102 public function deactivate() {
180 103 if ( ! empty( $this->active_option ) ) {
181 104 $this->options[ $this->active_option ] = false;
@@ -186,10 +109,8 @@
186 109 /**
187 110 * Protected method to display a configuration form
188 111 *
189 112 * @since 1.8
190 - *
191 - * @return void
192 113 */
193 114 protected function form() {
194 115 // Child classes can provide a form
195 116 }
@@ -219,9 +140,9 @@
219 140 *
220 141 * @param array $options Raw options
221 142 * @return array Options
222 143 */
223 - protected function update( $options ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
144 + protected function update( $options ) {
224 145 return array(); // It's responsibility of the child class to decide what is saved
225 146 }
226 147
227 148 /**
@@ -227,10 +148,8 @@
227 148 /**
228 149 * Ajax method to save the options
229 150 *
230 151 * @since 1.8
231 - *
232 - * @return void
233 152 */
234 153 public function save_options() {
235 154 check_ajax_referer( 'pll_options', '_pll_nonce' );
236 155 if ( ! current_user_can( 'manage_options' ) ) {
@@ -236,9 +155,9 @@
236 155 if ( ! current_user_can( 'manage_options' ) ) {
237 156 wp_die( -1 );
238 157 }
239 158
240 - if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] ) {
159 + if ( $this->module == $_POST['module'] ) {
241 160 // It's up to the child class to decide which options are saved, whether there are errors or not
242 161 $post = array_diff_key( $_POST, array_flip( array( 'action', 'module', 'pll_ajax_backend', '_pll_nonce' ) ) );
243 162 $options = $this->update( $post );
244 163 $this->options = array_merge( $this->options, $options );
@@ -254,9 +173,9 @@
254 173 ob_start();
255 174
256 175 if ( ! get_settings_errors() ) {
257 176 // Send update message
258 - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' );
177 + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
259 178 settings_errors();
260 179 $x = new WP_Ajax_Response( array( 'what' => 'success', 'data' => ob_get_clean() ) );
261 180 $x->send();
262 181 } else {
@@ -268,17 +187,15 @@
268 187 }
269 188 }
270 189
271 190 /**
272 - * Get the row actions.
191 + * Get the row actions
273 192 *
274 193 * @since 1.8
275 194 *
276 - * @return string[]
195 + * @return array
277 196 */
278 197 protected function get_actions() {
279 - $actions = array();
280 -
281 198 if ( $this->is_active() && $this->get_form() ) {
282 199 $actions[] = 'configure';
283 200 }
284 201
@@ -293,13 +210,13 @@
293 210 return $actions;
294 211 }
295 212
296 213 /**
297 - * Get the actions links.
214 + * Get the actions links
298 215 *
299 216 * @since 1.8
300 217 *
301 - * @return string[] Action links.
218 + * @return array
302 219 */
303 220 public function get_action_links() {
304 221 return array_intersect_key( $this->action_links, array_flip( $this->get_actions() ) );
305 222 }
@@ -313,9 +230,9 @@
313 230 */
314 231 protected function default_upgrade_message() {
315 232 return sprintf(
316 233 '%s <a href="%s">%s</a>',
317 - __( 'To enable this feature, you need Polylang Pro.', 'polylang' ),
234 + __( 'You need Polylang Pro to enable this feature.', 'polylang' ),
318 235 'https://polylang.pro',
319 236 __( 'Upgrade now.', 'polylang' )
320 237 );
321 238 }
@@ -331,13 +248,13 @@
331 248 return '';
332 249 }
333 250
334 251 /**
335 - * Get the buttons.
252 + * Get the buttons
336 253 *
337 254 * @since 1.9
338 255 *
339 - * @return string[] An array of html fragment for the buttons.
256 + * @return array
340 257 */
341 258 public function get_buttons() {
342 259 return $this->buttons;
343 260 }