PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
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 +56 -54 2.7.22.0.3 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * Base class for all settings
4 + * base class for all settings
5 5 *
6 6 * @since 1.8
7 7 */
8 8 class PLL_Settings_Module {
@@ -8,17 +8,17 @@
8 8 class PLL_Settings_Module {
9 9 public $active_option, $configure;
10 10 public $module, $title, $description;
11 11 public $options;
12 - protected $action_links, $buttons, $form = false;
12 + protected $action_links, $buttons;
13 13
14 14 /**
15 - * Constructor
15 + * constructor
16 16 *
17 17 * @since 1.8
18 18 *
19 - * @param object $polylang Polylang object
20 - * @param array $args
19 + * @param object $polylang polylang object
20 + * @param array $args
21 21 */
22 22 public function __construct( &$polylang, $args ) {
23 23 $this->options = &$polylang->options;
24 24 $this->model = &$polylang->model;
@@ -23,56 +23,57 @@
23 23 $this->options = &$polylang->options;
24 24 $this->model = &$polylang->model;
25 25 $this->links_model = &$polylang->links_model;
26 26
27 - $args = wp_parse_args(
28 - $args,
29 - array(
30 - 'title' => '',
31 - 'description' => '',
32 - 'active_option' => false,
33 - )
34 - );
27 + $args = wp_parse_args( $args, array(
28 + 'title' => '',
29 + 'description' => '',
30 + 'active_option' => false,
31 + ) );
35 32
36 33 foreach ( $args as $prop => $value ) {
37 34 $this->$prop = $value;
38 35 }
39 36
40 - // All possible action links, even if not always a link ;-)
37 + // all possible action links, even if not always a link ;- )
41 38 $this->action_links = array(
42 - 'configure' => sprintf(
39 + 'configure' => sprintf(
43 40 '<a title="%s" href="%s">%s</a>',
44 41 esc_attr__( 'Configure this module', 'polylang' ),
45 42 '#',
46 43 esc_html__( 'Settings', 'polylang' )
47 44 ),
48 - 'deactivate' => sprintf(
45 +
46 + 'deactivate' => sprintf(
49 47 '<a title="%s" href="%s">%s</a>',
50 48 esc_attr__( 'Deactivate this module', 'polylang' ),
51 - 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' ),
52 50 esc_html__( 'Deactivate', 'polylang' )
53 51 ),
54 - 'activate' => sprintf(
52 +
53 + 'activate' => sprintf(
55 54 '<a title="%s" href="%s">%s</a>',
56 55 esc_attr__( 'Activate this module', 'polylang' ),
57 - 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' ),
58 57 esc_html__( 'Activate', 'polylang' )
59 58 ),
60 - 'activated' => esc_html__( 'Activated', 'polylang' ),
59 +
60 + 'activated' => esc_html__( 'Activated', 'polylang' ),
61 +
61 62 'deactivated' => esc_html__( 'Deactivated', 'polylang' ),
62 63 );
63 64
64 65 $this->buttons = array(
65 - 'cancel' => sprintf( '<button type="button" class="button button-secondary cancel">%s</button>', esc_html__( 'Cancel', 'polylang' ) ),
66 - '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' ) ),
67 68 );
68 69
69 - // Ajax action to save options
70 + // ajax action to save options
70 71 add_action( 'wp_ajax_pll_save_options', array( $this, 'save_options' ) );
71 72 }
72 73
73 74 /**
74 - * Tells if the module is active
75 + * tells if the module is active
75 76 *
76 77 * @since 1.8
77 78 *
78 79 * @return bool
@@ -81,9 +82,9 @@
81 82 return empty( $this->active_option ) || ! empty( $this->options[ $this->active_option ] );
82 83 }
83 84
84 85 /**
85 - * Activates the module
86 + * activates the module
86 87 *
87 88 * @since 1.8
88 89 */
89 90 public function activate() {
@@ -93,9 +94,9 @@
93 94 }
94 95 }
95 96
96 97 /**
97 - * Deactivates the module
98 + * deactivates the module
98 99 *
99 100 * @since 1.8
100 101 */
101 102 public function deactivate() {
@@ -105,18 +106,19 @@
105 106 }
106 107 }
107 108
108 109 /**
109 - * Protected method to display a configuration form
110 + * protected method to display a configuration form
110 111 *
111 112 * @since 1.8
113 + *
112 114 */
113 115 protected function form() {
114 - // Child classes can provide a form
116 + // child classes can provide a form
115 117 }
116 118
117 119 /**
118 - * Public method returning the form if any
120 + * public method returning the form if any
119 121 *
120 122 * @since 1.8
121 123 *
122 124 * @return string
@@ -121,32 +123,34 @@
121 123 *
122 124 * @return string
123 125 */
124 126 public function get_form() {
125 - // Read the form only once
126 - if ( false === $this->form ) {
127 + static $form = false;
128 +
129 + // read the form only once
130 + if ( false === $form ) {
127 131 ob_start();
128 132 $this->form();
129 - $this->form = ob_get_clean();
133 + $form = ob_get_clean();
130 134 }
131 135
132 - return $this->form;
136 + return $form;
133 137 }
134 138
135 139 /**
136 - * Allows child classes to validate their options before saving
140 + * allows child classes to validate their options before saving
137 141 *
138 142 * @since 1.8
139 143 *
140 - * @param array $options Raw options
141 - * @return array Options
144 + * @param array $options raw options
145 + * @param array options
142 146 */
143 147 protected function update( $options ) {
144 - return array(); // It's responsibility of the child class to decide what is saved
148 + return array(); // it's responsibility of the child class to decide what is saved
145 149 }
146 150
147 151 /**
148 - * Ajax method to save the options
152 + * ajax method to save the options
149 153 *
150 154 * @since 1.8
151 155 */
152 156 public function save_options() {
@@ -154,32 +158,32 @@
154 158 if ( ! current_user_can( 'manage_options' ) ) {
155 159 wp_die( -1 );
156 160 }
157 161
158 - if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] ) {
159 - // It's up to the child class to decide which options are saved, whether there are errors or not
162 + if ( $this->module == $_POST['module'] ) {
163 + // it's up to the child class to decide which options are saved, whether there are errors or not
160 164 $post = array_diff_key( $_POST, array_flip( array( 'action', 'module', 'pll_ajax_backend', '_pll_nonce' ) ) );
161 165 $options = $this->update( $post );
162 166 $this->options = array_merge( $this->options, $options );
163 167 update_option( 'polylang', $this->options );
164 168
165 - // Refresh language cache in case home urls have been modified
169 + // refresh language cache in case home urls have been modified
166 170 $this->model->clean_languages_cache();
167 171
168 - // Refresh rewrite rules in case rewrite, hide_default, post types or taxonomies options have been modified
169 - // Don't use flush_rewrite_rules as we don't have the right links model and permastruct
172 + // refresh rewrite rules in case rewrite, hide_default, post types or taxonomies options have been modified
173 + // don't use flush_rewrite_rules as we don't have the right links model and permastruct
170 174 delete_option( 'rewrite_rules' );
171 175
172 176 ob_start();
173 177
174 178 if ( ! get_settings_errors() ) {
175 - // Send update message
176 - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' );
179 + // send update message
180 + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' );
177 181 settings_errors();
178 182 $x = new WP_Ajax_Response( array( 'what' => 'success', 'data' => ob_get_clean() ) );
179 183 $x->send();
180 184 } else {
181 - // Send error messages
185 + // send error messages
182 186 settings_errors();
183 187 $x = new WP_Ajax_Response( array( 'what' => 'error', 'data' => ob_get_clean() ) );
184 188 $x->send();
185 189 }
@@ -186,9 +190,9 @@
186 190 }
187 191 }
188 192
189 193 /**
190 - * Get the row actions
194 + * get the row actions
191 195 *
192 196 * @since 1.8
193 197 *
194 198 * @return array
@@ -193,10 +197,8 @@
193 197 *
194 198 * @return array
195 199 */
196 200 protected function get_actions() {
197 - $actions = array();
198 -
199 201 if ( $this->is_active() && $this->get_form() ) {
200 202 $actions[] = 'configure';
201 203 }
202 204
@@ -211,9 +213,9 @@
211 213 return $actions;
212 214 }
213 215
214 216 /**
215 - * Get the actions links
217 + * get the actions links
216 218 *
217 219 * @since 1.8
218 220 *
219 221 * @return array
@@ -222,9 +224,9 @@
222 224 return array_intersect_key( $this->action_links, array_flip( $this->get_actions() ) );
223 225 }
224 226
225 227 /**
226 - * Default upgrade message ( to Pro version )
228 + * default upgrade message ( to pro version )
227 229 *
228 230 * @since 1.9
229 231 *
230 232 * @return string
@@ -231,9 +233,9 @@
231 233 */
232 234 protected function default_upgrade_message() {
233 235 return sprintf(
234 236 '%s <a href="%s">%s</a>',
235 - __( 'To enable this feature, you need Polylang Pro.', 'polylang' ),
237 + __( 'You need Polylang Pro to enable this feature.', 'polylang' ),
236 238 'https://polylang.pro',
237 239 __( 'Upgrade now.', 'polylang' )
238 240 );
239 241 }
@@ -238,9 +240,9 @@
238 240 );
239 241 }
240 242
241 243 /**
242 - * Allows child classes to display an upgrade message
244 + * allows child classes to display an upgrade message
243 245 *
244 246 * @since 1.9
245 247 *
246 248 * @return string
@@ -249,9 +251,9 @@
249 251 return '';
250 252 }
251 253
252 254 /**
253 - * Get the buttons
255 + * get the buttons
254 256 *
255 257 * @since 1.9
256 258 *
257 259 * @return array