Q2W3 Fixed Widget - Version 4.0.4

Version Description

  • Added option "Auto fix widget id". It is on by default. If the plugin is working with this option switched off - leave it in off position!
Download this release

Release Info

Developer Max Bond
Plugin Icon 128x128 Q2W3 Fixed Widget
Version 4.0.4
Comparing to
See all releases

Code changes from version 4.0.3 to 4.0.4

Files changed (2) hide show
  1. q2w3-fixed-widget.php +98 -88
  2. readme.txt +4 -1
q2w3-fixed-widget.php CHANGED
@@ -4,41 +4,19 @@ Plugin Name: Q2W3 Fixed Widget
4
  Plugin URI: http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/
5
  Description: Fixes positioning of the selected widgets, when the page is scrolled down.
6
  Author: Max Bond
7
- Version: 4.0.3
8
  Author URI: http://www.q2w3.ru/
9
  */
10
 
11
- // Hooks
12
-
13
- if ( is_admin() ) {
14
-
15
- add_action('in_widget_form', array( 'q2w3_fixed_widget', 'add_option' ), 10, 3);
16
-
17
- add_filter('widget_update_callback', array( 'q2w3_fixed_widget', 'update_option' ), 10, 3);
18
-
19
- add_action('admin_init', array( 'q2w3_fixed_widget', 'register_settings' ));
20
-
21
- add_action('admin_menu', array( 'q2w3_fixed_widget', 'admin_init' ));
22
-
23
- } else {
24
-
25
- add_action('wp_enqueue_scripts', array( 'q2w3_fixed_widget', 'init' ));
26
-
27
- add_filter('register_sidebar', array( 'q2w3_fixed_widget', 'register_sidebar_filter' ));
28
-
29
- add_action('wp_footer', array( 'q2w3_fixed_widget', 'action' ), 1);
30
-
31
- }
32
 
33
  if ( class_exists('q2w3_fixed_widget', false) ) return; // if class is allready loaded return control to the main script
34
 
35
- // Plugin class
36
-
37
- class q2w3_fixed_widget {
38
 
39
  const ID = 'q2w3_fixed_widget';
40
 
41
- const VERSION = '4.0.3';
42
 
43
  protected static $sidebars_widgets;
44
 
@@ -52,15 +30,35 @@ class q2w3_fixed_widget {
52
 
53
  if ( $options['logged_in_req'] && !is_user_logged_in() ) return;
54
 
55
- add_filter('widget_display_callback', array( 'q2w3_fixed_widget', 'check' ), $options['widget_display_callback_priority'], 3);
 
 
56
 
57
- wp_enqueue_script('q2w3-fixed-widget', plugin_dir_url( __FILE__ ) . 'js/q2w3-fixed-widget.min.js', array('jquery'), self::VERSION);
58
-
59
- self::check_custom_ids();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  }
62
 
63
- public static function check($instance, $widget, $args){
64
 
65
  if ( isset($instance['q2w3_fixed_widget']) && $instance['q2w3_fixed_widget'] ) {
66
 
@@ -72,7 +70,7 @@ class q2w3_fixed_widget {
72
 
73
  }
74
 
75
- protected static function check_custom_ids() {
76
 
77
  $options = self::load_options();
78
 
@@ -118,7 +116,7 @@ class q2w3_fixed_widget {
118
 
119
  }
120
 
121
- public static function action() {
122
 
123
  $options = self::load_options();
124
 
@@ -164,7 +162,7 @@ class q2w3_fixed_widget {
164
 
165
  }
166
 
167
- public static function add_option($widget, $return, $instance) {
168
 
169
  echo '<p>'.PHP_EOL;
170
 
@@ -176,7 +174,7 @@ class q2w3_fixed_widget {
176
 
177
  }
178
 
179
- public static function update_option($instance, $new_instance, $old_instance){
180
 
181
  if ( isset($new_instance['q2w3_fixed_widget']) && $new_instance['q2w3_fixed_widget'] ) {
182
 
@@ -206,9 +204,7 @@ class q2w3_fixed_widget {
206
 
207
  }
208
 
209
- public static function admin_init() {
210
-
211
- self::load_language();
212
 
213
  add_submenu_page( 'themes.php', __('Fixed Widget Options', 'q2w3_fixed_widget'), __('Fixed Widget Options', 'q2w3_fixed_widget'), 'activate_plugins', 'q2w3_fixed_widget', array( __CLASS__, 'settings_page' ) );
214
 
@@ -224,16 +220,14 @@ class q2w3_fixed_widget {
224
 
225
  $d['screen-max-width'] = 0;
226
 
 
 
227
  $d['window-load-enabled'] = false;
228
 
229
  $d['logged_in_req'] = false;
230
 
231
  $d['widget_display_callback_priority'] = 30;
232
 
233
- $d['disable-phone'] = false;
234
-
235
- $d['disable-tablet'] = false;
236
-
237
  return $d;
238
 
239
  }
@@ -264,6 +258,12 @@ class q2w3_fixed_widget {
264
 
265
  $input['custom-ids'] = trim(wp_strip_all_tags($input['custom-ids']));
266
 
 
 
 
 
 
 
267
  return $input;
268
 
269
  }
@@ -294,6 +294,8 @@ class q2w3_fixed_widget {
294
 
295
  echo '<p><span >'. __('Custom HTML IDs (each one on a new line):', 'q2w3_fixed_widget') .'</span><br/><textarea name="'. self::ID .'[custom-ids]" style="width: 320px; height: 120px;">'. $options['custom-ids'] .'</textarea>'.PHP_EOL;
296
 
 
 
297
  echo '<p><span style="display: inline-block; width: 220px;">'. __('Use jQuery(window).load() hook:', 'q2w3_fixed_widget') .'</span><input type="checkbox" name="'. self::ID .'[window-load-enabled]" value="yes" '. checked('yes', $options['window-load-enabled'], false) .' /> '. __('Use this option only if you have problems with <a href="http://wordpress.org/support/topic/doesnt-work-with-infinte-scroll-for-widget-scripts" target="_blank">other scroll oriented javascript code</a>', 'q2w3_fixed_widget') .'</p>'.PHP_EOL;
298
 
299
  echo '<p><span style="display: inline-block; width: 220px;">'. __('Enable plugin for logged in users only:', 'q2w3_fixed_widget') .'</span><input type="checkbox" name="'. self::ID .'[logged_in_req]" value="yes" '. checked('yes', $options['logged_in_req'], false) .' /></p>'.PHP_EOL;
@@ -312,62 +314,70 @@ class q2w3_fixed_widget {
312
 
313
  }
314
 
315
- public static function register_sidebar_filter($sidebar) {
316
 
317
  global $wp_registered_sidebars;
318
 
319
- if ( strpos($sidebar['before_widget'], 'id="%1$s"') !== false || strpos($sidebar['before_widget'], 'id=\'%1$s\'') !== false ) return;
320
 
321
- if ( $sidebar['before_widget'] == '' || $sidebar['before_widget'] == ' ' ) {
322
-
323
- $wp_registered_sidebars[$sidebar['id']]['before_widget'] = '<div id="%1$s">';
324
-
325
- $wp_registered_sidebars[$sidebar['id']]['after_widget'] = '</div>';
326
-
327
- } elseif ( strpos($sidebar['before_widget'], 'id=') === false ) {
328
-
329
- $tag_end_pos = strpos($sidebar['before_widget'], '>');
330
-
331
- if ( $tag_end_pos !== false ) {
332
-
333
- $wp_registered_sidebars[$sidebar['id']]['before_widget'] = substr_replace($sidebar['before_widget'], ' id="%1$s"', $tag_end_pos, 0);
334
-
335
- }
336
-
337
- } else {
338
-
339
- $str_array = explode(' ', $sidebar['before_widget']);
340
 
341
- if ( is_array($str_array) ) {
342
-
343
- foreach ( $str_array as $str_part_id => $str_part ) {
344
 
345
- if ( strpos($str_part, 'id="') !== false ) {
346
-
347
- $p1 = strpos($str_part, 'id="');
348
-
349
- $p2 = strpos($str_part, '"', $p1 + 4);
350
-
351
- $str_array[$str_part_id] = substr_replace($str_part, 'id="%1$s"', $p1, $p2 + 1);
352
-
353
- } elseif ( strpos($str_part, 'id=\'') !== false ) {
354
 
355
- $p1 = strpos($str_part, 'id=\'');
356
 
357
- $p2 = strpos($str_part, "'", $p1 + 4);
 
 
 
 
 
 
358
 
359
- $str_array[$str_part_id] = substr_replace($str_part, 'id=\'%1$s\'', $p1, $p2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
 
361
  }
362
-
363
- }
364
-
365
- $wp_registered_sidebars[$sidebar['id']]['before_widget'] = implode(' ', $str_array);
366
-
367
- }
368
-
369
- }
370
 
371
- }
372
 
373
- }
4
  Plugin URI: http://www.q2w3.ru/q2w3-fixed-widget-wordpress-plugin/
5
  Description: Fixes positioning of the selected widgets, when the page is scrolled down.
6
  Author: Max Bond
7
+ Version: 4.0.4
8
  Author URI: http://www.q2w3.ru/
9
  */
10
 
11
+ add_action('init', array( 'q2w3_fixed_widget', 'init' )); // Main Hook
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  if ( class_exists('q2w3_fixed_widget', false) ) return; // if class is allready loaded return control to the main script
14
 
15
+ class q2w3_fixed_widget { // Plugin class
 
 
16
 
17
  const ID = 'q2w3_fixed_widget';
18
 
19
+ const VERSION = '4.0.4';
20
 
21
  protected static $sidebars_widgets;
22
 
30
 
31
  if ( $options['logged_in_req'] && !is_user_logged_in() ) return;
32
 
33
+ if ( is_admin() ) {
34
+
35
+ self::load_language();
36
 
37
+ add_action('in_widget_form', array( __CLASS__, 'add_widget_option' ), 10, 3);
38
+
39
+ add_filter('widget_update_callback', array( __CLASS__, 'update_widget_option' ), 10, 3);
40
+
41
+ add_action('admin_init', array( __CLASS__, 'register_settings' ));
42
+
43
+ add_action('admin_menu', array( __CLASS__, 'admin_menu' ));
44
+
45
+ } else {
46
+
47
+ if ( $options['fix-widget-id'] ) self::registered_sidebars_filter(); //add_action('wp_loaded', array( __CLASS__, 'registered_sidebars_filter' )); //
48
+
49
+ add_filter('widget_display_callback', array( __CLASS__, 'is_widget_fixed' ), $options['widget_display_callback_priority'], 3);
50
+
51
+ add_action('wp_loaded', array( __CLASS__, 'custom_ids' ));
52
+
53
+ add_action('wp_footer', array( __CLASS__, 'action_script' ), 1);
54
+
55
+ wp_enqueue_script('q2w3-fixed-widget', plugin_dir_url( __FILE__ ) . 'js/q2w3-fixed-widget.min.js', array('jquery'), self::VERSION);
56
+
57
+ }
58
 
59
  }
60
 
61
+ public static function is_widget_fixed($instance, $widget, $args){
62
 
63
  if ( isset($instance['q2w3_fixed_widget']) && $instance['q2w3_fixed_widget'] ) {
64
 
70
 
71
  }
72
 
73
+ public static function custom_ids() {
74
 
75
  $options = self::load_options();
76
 
116
 
117
  }
118
 
119
+ public static function action_script() {
120
 
121
  $options = self::load_options();
122
 
162
 
163
  }
164
 
165
+ public static function add_widget_option($widget, $return, $instance) {
166
 
167
  echo '<p>'.PHP_EOL;
168
 
174
 
175
  }
176
 
177
+ public static function update_widget_option($instance, $new_instance, $old_instance){
178
 
179
  if ( isset($new_instance['q2w3_fixed_widget']) && $new_instance['q2w3_fixed_widget'] ) {
180
 
204
 
205
  }
206
 
207
+ public static function admin_menu() {
 
 
208
 
209
  add_submenu_page( 'themes.php', __('Fixed Widget Options', 'q2w3_fixed_widget'), __('Fixed Widget Options', 'q2w3_fixed_widget'), 'activate_plugins', 'q2w3_fixed_widget', array( __CLASS__, 'settings_page' ) );
210
 
220
 
221
  $d['screen-max-width'] = 0;
222
 
223
+ $d['fix-widget-id'] = 'yes';
224
+
225
  $d['window-load-enabled'] = false;
226
 
227
  $d['logged_in_req'] = false;
228
 
229
  $d['widget_display_callback_priority'] = 30;
230
 
 
 
 
 
231
  return $d;
232
 
233
  }
258
 
259
  $input['custom-ids'] = trim(wp_strip_all_tags($input['custom-ids']));
260
 
261
+ if ( !isset($input['fix-widget-id']) ) $input['fix-widget-id'] = false;
262
+
263
+ if ( !isset($input['window-load-enabled']) ) $input['window-load-enabled'] = false;
264
+
265
+ if ( !isset($input['logged_in_req']) ) $input['logged_in_req'] = false;
266
+
267
  return $input;
268
 
269
  }
294
 
295
  echo '<p><span >'. __('Custom HTML IDs (each one on a new line):', 'q2w3_fixed_widget') .'</span><br/><textarea name="'. self::ID .'[custom-ids]" style="width: 320px; height: 120px;">'. $options['custom-ids'] .'</textarea>'.PHP_EOL;
296
 
297
+ echo '<p><span style="display: inline-block; width: 220px;">'. __('Auto fix widget id:', 'q2w3_fixed_widget') .'</span><input type="checkbox" name="'. self::ID .'[fix-widget-id]" value="yes" '. checked('yes', $options['fix-widget-id'], false) .' /> </p>'.PHP_EOL;
298
+
299
  echo '<p><span style="display: inline-block; width: 220px;">'. __('Use jQuery(window).load() hook:', 'q2w3_fixed_widget') .'</span><input type="checkbox" name="'. self::ID .'[window-load-enabled]" value="yes" '. checked('yes', $options['window-load-enabled'], false) .' /> '. __('Use this option only if you have problems with <a href="http://wordpress.org/support/topic/doesnt-work-with-infinte-scroll-for-widget-scripts" target="_blank">other scroll oriented javascript code</a>', 'q2w3_fixed_widget') .'</p>'.PHP_EOL;
300
 
301
  echo '<p><span style="display: inline-block; width: 220px;">'. __('Enable plugin for logged in users only:', 'q2w3_fixed_widget') .'</span><input type="checkbox" name="'. self::ID .'[logged_in_req]" value="yes" '. checked('yes', $options['logged_in_req'], false) .' /></p>'.PHP_EOL;
314
 
315
  }
316
 
317
+ public static function registered_sidebars_filter() {
318
 
319
  global $wp_registered_sidebars;
320
 
321
+ if ( !is_array($wp_registered_sidebars) ) return;
322
 
323
+ foreach ( $wp_registered_sidebars as $id => $sidebar ) {
324
+
325
+ if ( strpos($sidebar['before_widget'], 'id="%1$s"') === false && strpos($sidebar['before_widget'], 'id=\'%1$s\'') === false ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
+ if ( $sidebar['before_widget'] == '' || $sidebar['before_widget'] == ' ' ) {
 
 
328
 
329
+ $wp_registered_sidebars[$id]['before_widget'] = '<div id="%1$s">';
330
+
331
+ $wp_registered_sidebars[$id]['after_widget'] = '</div>';
332
+
333
+ } elseif ( strpos($sidebar['before_widget'], 'id=') === false ) {
334
+
335
+ $tag_end_pos = strpos($sidebar['before_widget'], '>');
336
+
337
+ if ( $tag_end_pos !== false ) {
338
 
339
+ $wp_registered_sidebars[$id]['before_widget'] = substr_replace($sidebar['before_widget'], ' id="%1$s"', $tag_end_pos, 0);
340
 
341
+ }
342
+
343
+ } else {
344
+
345
+ $str_array = explode(' ', $sidebar['before_widget']);
346
+
347
+ if ( is_array($str_array) ) {
348
 
349
+ foreach ( $str_array as $str_part_id => $str_part ) {
350
+
351
+ if ( strpos($str_part, 'id="') !== false ) {
352
+
353
+ $p1 = strpos($str_part, 'id="');
354
+
355
+ $p2 = strpos($str_part, '"', $p1 + 4);
356
+
357
+ $str_array[$str_part_id] = substr_replace($str_part, 'id="%1$s"', $p1, $p2 + 1);
358
+
359
+ } elseif ( strpos($str_part, 'id=\'') !== false ) {
360
+
361
+ $p1 = strpos($str_part, 'id=\'');
362
+
363
+ $p2 = strpos($str_part, "'", $p1 + 4);
364
+
365
+ $str_array[$str_part_id] = substr_replace($str_part, 'id=\'%1$s\'', $p1, $p2);
366
+
367
+ }
368
+
369
+ }
370
+
371
+ $wp_registered_sidebars[$id]['before_widget'] = implode(' ', $str_array);
372
 
373
  }
374
+
375
+ }
376
+
377
+ } // if id is wrong
378
+
379
+ } // foreach
 
 
380
 
381
+ } // registered_sidebars_filter()
382
 
383
+ } // q2w3_fixed_widget class
readme.txt CHANGED
@@ -92,6 +92,9 @@ Send me email from this page: [http://www.q2w3.ru/contacts/](http://www.q2w3.ru/
92
 
93
  == Changelog ==
94
 
 
 
 
95
  = 4.0.3 =
96
  * Optimized code to resolve [plugin crash after 4.0.1 update](http://wordpress.org/support/topic/the-plugin-crash-after-401-update) problem
97
  * Minified javascript code
@@ -117,7 +120,7 @@ Send me email from this page: [http://www.q2w3.ru/contacts/](http://www.q2w3.ru/
117
  * Now user can disable plugin, when browser window width is less then specified value (check plugin options).
118
 
119
  = 2.2.4 =
120
- * This version is jQuery 1.9 compatible
121
 
122
  = 2.2.3 =
123
  * Little internal improvments
92
 
93
  == Changelog ==
94
 
95
+ = 4.0.4 =
96
+ * Added option "Auto fix widget id". It is on by default. If the plugin is working with this option switched off - leave it in off position!
97
+
98
  = 4.0.3 =
99
  * Optimized code to resolve [plugin crash after 4.0.1 update](http://wordpress.org/support/topic/the-plugin-crash-after-401-update) problem
100
  * Minified javascript code
120
  * Now user can disable plugin, when browser window width is less then specified value (check plugin options).
121
 
122
  = 2.2.4 =
123
+ * This version compatible with jQuery 1.9 and 1.10
124
 
125
  = 2.2.3 =
126
  * Little internal improvments