PluginProbe
WebberZone Top 10 — Popular Posts / 4.5.2
WebberZone Top 10 — Popular Posts v4.5.2
4.5.2 4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 All 118 releases
← All changes | includes/options-api.php +28 -17 4.4.2 → 4.5.2 View file →
@@ -18,9 +18,9 @@
18 18 * @return array Top 10 settings
19 19 */
20 20 function tptn_get_settings() {
21 21
22 - $settings = get_option( 'tptn_settings' );
22 + $settings = get_option( 'tptn_settings', array() );
23 23
24 24 /**
25 25 * Settings array
26 26 *
@@ -36,20 +36,18 @@
36 36 * Get an option
37 37 *
38 38 * Looks to see if the specified setting exists, returns default if not
39 39 *
40 - * @since 2.5.0
40 + * @since 2.5.0
41 41 *
42 - * @param string $key Option to fetch.
43 - * @param mixed $default_value Default option.
42 + * @param string $key Option to fetch.
43 + * @param mixed $default_value Default option.
44 44 * @return mixed
45 45 */
46 46 function tptn_get_option( $key = '', $default_value = null ) {
47 47 global $tptn_settings;
48 48
49 - if ( empty( $tptn_settings ) ) {
50 - $tptn_settings = tptn_get_settings();
51 - }
49 + $tptn_settings = tptn_get_settings();
52 50
53 51 if ( is_null( $default_value ) ) {
54 52 $default_value = tptn_get_default_option( $key );
55 53 }
@@ -106,11 +104,20 @@
106 104 return $remove_option;
107 105 }
108 106
109 107 // First let's grab the current settings.
110 - $options = get_option( 'tptn_settings' );
108 + $options = get_option( 'tptn_settings', array() );
109 + $options = is_array( $options ) ? $options : array();
111 110
112 111 // Let's let devs alter that value coming in.
112 + /**
113 + * Filters a setting value before it is written to the options table.
114 + *
115 + * @since 2.5.0
116 + *
117 + * @param mixed $value The value being saved.
118 + * @param string $key The settings key being updated.
119 + */
113 120 $value = apply_filters( 'tptn_update_option', $value, $key );
114 121
115 122 // Next let's try to update the value.
116 123 $options[ $key ] = $value;
@@ -142,9 +149,10 @@
142 149 return false;
143 150 }
144 151
145 152 // First let's grab the current settings.
146 - $options = get_option( 'tptn_settings' );
153 + $options = get_option( 'tptn_settings', array() );
154 + $options = is_array( $options ) ? $options : array();
147 155
148 156 // Next let's try to update the value.
149 157 if ( isset( $options[ $key ] ) ) {
150 158 unset( $options[ $key ] );
@@ -253,14 +261,15 @@
253 261 * Get the default option for a specific key
254 262 *
255 263 * @since 1.3.0
256 264 *
257 - * @param string $key Key of the option to fetch.
265 + * @param string $key Key of the option to fetch.
258 266 * @return mixed
259 267 */
260 268 function tptn_get_default_option( $key = '' ) {
261 269
262 - $default_settings = tptn_settings_defaults();
270 + /** This filter is documented in includes/options-api.php */
271 + $default_settings = apply_filters( 'tptn_settings_defaults', \WebberZone\Top_Ten\Admin\Settings::get_defaults() );
263 272
264 273 if ( array_key_exists( $key, $default_settings ) ) {
265 274 return $default_settings[ $key ];
266 275 } else {
@@ -309,9 +318,9 @@
309 318 }
310 319
311 320
312 321 /**
313 - * Function to add an action to search for tags using Ajax.
322 + * Handles the AJAX request to search for tags in the Top 10 settings.
314 323 *
315 324 * @since 1.7.0
316 325 *
317 326 * @return void
@@ -344,17 +353,19 @@
344 353 if ( false !== strpos( $s, ',' ) ) {
345 354 $s = explode( ',', $s );
346 355 $s = $s[ count( $s ) - 1 ];
347 356 }
348 - $s = trim( $s );
357 + $s = trim( $s, " \t\n\r\0\x0B" );
349 358
350 - /** This filter has been defined in /wp-admin/includes/ajax-actions.php */
359 + /**
360 + * This filter has been defined in /wp-admin/includes/ajax-actions.php
361 +*/
351 362 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
352 363
353 364 /*
354 - * Require $term_search_min_chars chars for matching (default: 2)
355 - * ensure it's a non-negative, non-zero integer.
356 - */
365 + * Require $term_search_min_chars chars for matching (default: 2)
366 + * ensure it's a non-negative, non-zero integer.
367 + */
357 368 if ( ( 0 === $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) {
358 369 wp_die();
359 370 }
360 371