PluginProbe
Polylang / 2.5
Polylang v2.5
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 +17 -101 3.02.5 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 *
@@ -121,15 +47,15 @@
121 47 ),
122 48 'deactivate' => sprintf(
123 49 '<a title="%s" href="%s">%s</a>',
124 50 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' ) ),
51 + wp_nonce_url( '?page=mlang&amp;tab=modules&amp;pll_action=deactivate&amp;noheader=true&amp;module=' . $this->module, 'pll_deactivate' ),
126 52 esc_html__( 'Deactivate', 'polylang' )
127 53 ),
128 54 'activate' => sprintf(
129 55 '<a title="%s" href="%s">%s</a>',
130 56 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' ) ),
57 + wp_nonce_url( '?page=mlang&amp;tab=modules&amp;pll_action=activate&amp;noheader=true&amp;module=' . $this->module, 'pll_activate' ),
132 58 esc_html__( 'Activate', 'polylang' )
133 59 ),
134 60 'activated' => esc_html__( 'Activated', 'polylang' ),
135 61 'deactivated' => esc_html__( 'Deactivated', 'polylang' ),
@@ -135,10 +61,10 @@
135 61 'deactivated' => esc_html__( 'Deactivated', 'polylang' ),
136 62 );
137 63
138 64 $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' ) ),
65 + 'cancel' => sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', esc_html__( 'Cancel' ) ),
66 + 'save' => sprintf( '<button type="button" class="button button-primary save">%s</button>', esc_html__( 'Save Changes' ) ),
141 67 );
142 68
143 69 // Ajax action to save options
144 70 add_action( 'wp_ajax_pll_save_options', array( $this, 'save_options' ) );
@@ -158,10 +84,8 @@
158 84 /**
159 85 * Activates the module
160 86 *
161 87 * @since 1.8
162 - *
163 - * @return void
164 88 */
165 89 public function activate() {
166 90 if ( ! empty( $this->active_option ) ) {
167 91 $this->options[ $this->active_option ] = true;
@@ -172,10 +96,8 @@
172 96 /**
173 97 * Deactivates the module
174 98 *
175 99 * @since 1.8
176 - *
177 - * @return void
178 100 */
179 101 public function deactivate() {
180 102 if ( ! empty( $this->active_option ) ) {
181 103 $this->options[ $this->active_option ] = false;
@@ -186,10 +108,8 @@
186 108 /**
187 109 * Protected method to display a configuration form
188 110 *
189 111 * @since 1.8
190 - *
191 - * @return void
192 112 */
193 113 protected function form() {
194 114 // Child classes can provide a form
195 115 }
@@ -219,9 +139,9 @@
219 139 *
220 140 * @param array $options Raw options
221 141 * @return array Options
222 142 */
223 - protected function update( $options ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
143 + protected function update( $options ) {
224 144 return array(); // It's responsibility of the child class to decide what is saved
225 145 }
226 146
227 147 /**
@@ -227,10 +147,8 @@
227 147 /**
228 148 * Ajax method to save the options
229 149 *
230 150 * @since 1.8
231 - *
232 - * @return void
233 151 */
234 152 public function save_options() {
235 153 check_ajax_referer( 'pll_options', '_pll_nonce' );
236 154 if ( ! current_user_can( 'manage_options' ) ) {
@@ -236,9 +154,9 @@
236 154 if ( ! current_user_can( 'manage_options' ) ) {
237 155 wp_die( -1 );
238 156 }
239 157
240 - if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] ) {
158 + if ( $this->module == $_POST['module'] ) {
241 159 // It's up to the child class to decide which options are saved, whether there are errors or not
242 160 $post = array_diff_key( $_POST, array_flip( array( 'action', 'module', 'pll_ajax_backend', '_pll_nonce' ) ) );
243 161 $options = $this->update( $post );
244 162 $this->options = array_merge( $this->options, $options );
@@ -254,9 +172,9 @@
254 172 ob_start();
255 173
256 174 if ( ! get_settings_errors() ) {
257 175 // Send update message
258 - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' );
176 + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
259 177 settings_errors();
260 178 $x = new WP_Ajax_Response( array( 'what' => 'success', 'data' => ob_get_clean() ) );
261 179 $x->send();
262 180 } else {
@@ -268,17 +186,15 @@
268 186 }
269 187 }
270 188
271 189 /**
272 - * Get the row actions.
190 + * Get the row actions
273 191 *
274 192 * @since 1.8
275 193 *
276 - * @return string[]
194 + * @return array
277 195 */
278 196 protected function get_actions() {
279 - $actions = array();
280 -
281 197 if ( $this->is_active() && $this->get_form() ) {
282 198 $actions[] = 'configure';
283 199 }
284 200
@@ -293,13 +209,13 @@
293 209 return $actions;
294 210 }
295 211
296 212 /**
297 - * Get the actions links.
213 + * Get the actions links
298 214 *
299 215 * @since 1.8
300 216 *
301 - * @return string[] Action links.
217 + * @return array
302 218 */
303 219 public function get_action_links() {
304 220 return array_intersect_key( $this->action_links, array_flip( $this->get_actions() ) );
305 221 }
@@ -313,9 +229,9 @@
313 229 */
314 230 protected function default_upgrade_message() {
315 231 return sprintf(
316 232 '%s <a href="%s">%s</a>',
317 - __( 'To enable this feature, you need Polylang Pro.', 'polylang' ),
233 + __( 'You need Polylang Pro to enable this feature.', 'polylang' ),
318 234 'https://polylang.pro',
319 235 __( 'Upgrade now.', 'polylang' )
320 236 );
321 237 }
@@ -331,13 +247,13 @@
331 247 return '';
332 248 }
333 249
334 250 /**
335 - * Get the buttons.
251 + * Get the buttons
336 252 *
337 253 * @since 1.9
338 254 *
339 - * @return string[] An array of html fragment for the buttons.
255 + * @return array
340 256 */
341 257 public function get_buttons() {
342 258 return $this->buttons;
343 259 }