Q2W3 Fixed Widget - Version 5.1

Version Description

  • New options load method!
  • Tested with WordPress 4.9
Download this release

Release Info

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

Code changes from version 5.0.4 to 5.1

Files changed (2) hide show
  1. q2w3-fixed-widget.php +89 -9
  2. readme.txt +6 -2
q2w3-fixed-widget.php CHANGED
@@ -5,7 +5,7 @@ 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
  Text Domain: q2w3-fixed-widget
7
  Author: Max Bond
8
- Version: 5.0.4
9
  Author URI: http://www.q2w3.ru/
10
  */
11
 
@@ -17,7 +17,7 @@ class q2w3_fixed_widget { // Plugin class
17
 
18
  const ID = 'q2w3_fixed_widget';
19
 
20
- const VERSION = '5.0.4';
21
 
22
  protected static $sidebars_widgets;
23
 
@@ -50,11 +50,11 @@ class q2w3_fixed_widget { // Plugin class
50
 
51
  if ( $options['fix-widget-id'] ) self::registered_sidebars_filter();
52
 
53
- add_filter('widget_display_callback', array( __CLASS__, 'is_widget_fixed' ), $options['widget_display_callback_priority'], 3);
54
 
55
  add_action('wp_loaded', array( __CLASS__, 'custom_ids' ));
56
 
57
- add_action('wp_footer', array( __CLASS__, 'js_settings' ));
58
 
59
  add_action('wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ));
60
 
@@ -64,17 +64,85 @@ class q2w3_fixed_widget { // Plugin class
64
 
65
  public static function enqueue_scripts() {
66
 
 
 
67
  wp_enqueue_script('jquery');
68
 
69
  wp_enqueue_script(self::ID, plugin_dir_url( __FILE__ ) . 'js/q2w3-fixed-widget.min.js', array('jquery'), self::VERSION, true);
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
 
 
 
72
 
73
- public static function is_widget_fixed($instance, $widget, $args){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  if ( isset($instance['q2w3_fixed_widget']) && $instance['q2w3_fixed_widget'] ) {
76
 
77
- self::$fixed_widgets[$args['id']][$widget->id] = "'". $widget->id ."'";
 
 
78
 
79
  echo '<!-- fixed widget -->';
80
 
@@ -96,7 +164,9 @@ class q2w3_fixed_widget { // Plugin class
96
 
97
  $id = trim($id);
98
 
99
- if ( $id ) self::$fixed_widgets[self::get_widget_sidebar($id)][$id] = "'". $id ."'";
 
 
100
 
101
  }
102
 
@@ -130,7 +200,7 @@ class q2w3_fixed_widget { // Plugin class
130
 
131
  }
132
 
133
- public static function js_settings() {
134
 
135
  $options = self::load_options();
136
 
@@ -314,6 +384,8 @@ class q2w3_fixed_widget { // Plugin class
314
 
315
  add_meta_box(self::ID.'-custom-ids', __('Custom IDs', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_custom_ids_box' ), $screen, 'normal');
316
 
 
 
317
  add_meta_box(self::ID.'-help', __('Help for users', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_help_box' ), $screen, 'side');
318
 
319
  add_meta_box(self::ID.'-donate', __('Help for developer', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_donate_box' ), $screen, 'side');
@@ -398,7 +470,15 @@ class q2w3_fixed_widget { // Plugin class
398
 
399
  echo '<p><span style="display: inline-block; width: 280px;">'. __('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) .' /> '. __('Enable this option only if you have problems with other scroll oriented javascript code', 'q2w3-fixed-widget') .'</p>'.PHP_EOL;
400
 
401
- echo '<p><span style="display: inline-block; width: 280px;">'. __('widget_display_callback hook priority:', 'q2w3-fixed-widget') .'</span><select name="'. self::ID .'[widget_display_callback_priority]"><option value="1" '. selected('1', $options['widget_display_callback_priority'], false) .'>1</option><option value="10" '. selected('10', $options['widget_display_callback_priority'], false) .'>10</option><option value="20" '. selected('20', $options['widget_display_callback_priority'], false) .'>20</option><option value="30" '. selected('30', $options['widget_display_callback_priority'], false) .'>30</option><option value="50" '. selected('50', $options['widget_display_callback_priority'], false) .'>50</option><option value="100" '. selected('100', $options['widget_display_callback_priority'], false) .'>100</option></select></p>'.PHP_EOL;
 
 
 
 
 
 
 
 
402
 
403
  }
404
 
5
  Description: Fixes positioning of the selected widgets, when the page is scrolled down.
6
  Text Domain: q2w3-fixed-widget
7
  Author: Max Bond
8
+ Version: 5.1
9
  Author URI: http://www.q2w3.ru/
10
  */
11
 
17
 
18
  const ID = 'q2w3_fixed_widget';
19
 
20
+ const VERSION = '5.1';
21
 
22
  protected static $sidebars_widgets;
23
 
50
 
51
  if ( $options['fix-widget-id'] ) self::registered_sidebars_filter();
52
 
53
+ //add_filter('widget_display_callback', array( __CLASS__, 'is_widget_fixed' ), $options['widget_display_callback_priority'], 3);
54
 
55
  add_action('wp_loaded', array( __CLASS__, 'custom_ids' ));
56
 
57
+ //add_action('wp_footer', array( __CLASS__, 'js_settings' ));
58
 
59
  add_action('wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ));
60
 
64
 
65
  public static function enqueue_scripts() {
66
 
67
+ self::fixed_wigets();
68
+
69
  wp_enqueue_script('jquery');
70
 
71
  wp_enqueue_script(self::ID, plugin_dir_url( __FILE__ ) . 'js/q2w3-fixed-widget.min.js', array('jquery'), self::VERSION, true);
72
 
73
+ $options = self::load_options();
74
+
75
+ if ( is_array(self::$fixed_widgets) && !empty(self::$fixed_widgets) ) {
76
+
77
+ if ( isset($options['window-load-enabled']) && $options['window-load-enabled'] == 'yes' ) $window_load_hook = true; else $window_load_hook = false;
78
+
79
+ if ( isset($options['width-inherit']) && $options['width-inherit'] ) $width_inherit = true; else $width_inherit = false;
80
+
81
+ if ( isset($options['disable-mo-api']) && $options['disable-mo-api'] ) $disable_mo_api = true; else $disable_mo_api = false;
82
+
83
+ if ( $options['refresh-interval'] > 0 ) $refresh_interval = $options['refresh-interval']; else $refresh_interval = 0;
84
+
85
+ $i = 0;
86
+ $sidebar_options = array();
87
+
88
+ foreach ( self::$fixed_widgets as $sidebar => $widgets ) {
89
+
90
+ $sidebar_options[ $i ] = array(
91
+ 'sidebar' => $sidebar,
92
+ 'margin_top' => $options['margin-top'],
93
+ 'stop_id' => $options['stop-id'],
94
+ 'screen_max_width' => $options['screen-max-width'],
95
+ 'screen_max_height' => $options['screen-max-height'],
96
+ 'width_inherit' => $width_inherit,
97
+ 'refresh_interval' => $refresh_interval,
98
+ 'window_load_hook' => $window_load_hook,
99
+ 'disable_mo_api' => $disable_mo_api,
100
+ 'widgets' => array_values( $widgets )
101
+ );
102
+
103
+ $i++;
104
+
105
+ }
106
+
107
+ wp_localize_script( self::ID, 'q2w3_sidebar_options', $sidebar_options );
108
+
109
+ }
110
+
111
  }
112
+
113
+
114
+ public static function fixed_wigets() {
115
 
116
+ $sidebars = wp_get_sidebars_widgets();
117
+
118
+ if ( $sidebars && is_array($sidebars) ) foreach ( $sidebars as $sidebar_id => $sidebar_widgets ) {
119
+
120
+ if ( ! (stristr($sidebar_id, 'orphaned_widgets') !== false || $sidebar_id == 'wp_inactive_widgets') ) {
121
+
122
+ if ( $sidebar_widgets && is_array($sidebar_widgets) ) foreach ( $sidebar_widgets as $widget ) {
123
+
124
+ list($widget_type, $widget_id) = explode('-', $widget);
125
+
126
+ $widget_options = get_option('widget_' . $widget_type);
127
+
128
+ if ( isset($widget_options[$widget_id]['q2w3_fixed_widget']) && $widget_options[$widget_id]['q2w3_fixed_widget']) self::$fixed_widgets[$sidebar_id][$widget] = $widget;
129
+
130
+ }
131
+
132
+ }
133
+
134
+ }
135
+
136
+ }
137
+
138
+
139
+ public static function is_widget_fixed($instance, $widget, $args) { // deprecated
140
 
141
  if ( isset($instance['q2w3_fixed_widget']) && $instance['q2w3_fixed_widget'] ) {
142
 
143
+ //self::$fixed_widgets[$args['id']][$widget->id] = "'". $widget->id ."'";
144
+
145
+ self::$fixed_widgets[$args['id']][$widget->id] = $widget->id;
146
 
147
  echo '<!-- fixed widget -->';
148
 
164
 
165
  $id = trim($id);
166
 
167
+ //if ( $id ) self::$fixed_widgets[self::get_widget_sidebar($id)][$id] = "'". $id ."'";
168
+
169
+ if ( $id ) self::$fixed_widgets[self::get_widget_sidebar($id)][$id] = $id;
170
 
171
  }
172
 
200
 
201
  }
202
 
203
+ public static function js_settings() { // deprecated
204
 
205
  $options = self::load_options();
206
 
384
 
385
  add_meta_box(self::ID.'-custom-ids', __('Custom IDs', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_custom_ids_box' ), $screen, 'normal');
386
 
387
+ add_meta_box(self::ID.'-recommend', __('Recommended plugins', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_recommend_box' ), $screen, 'side', 'high');
388
+
389
  add_meta_box(self::ID.'-help', __('Help for users', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_help_box' ), $screen, 'side');
390
 
391
  add_meta_box(self::ID.'-donate', __('Help for developer', 'q2w3-fixed-widget'), array( __CLASS__, 'settings_page_donate_box' ), $screen, 'side');
470
 
471
  echo '<p><span style="display: inline-block; width: 280px;">'. __('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) .' /> '. __('Enable this option only if you have problems with other scroll oriented javascript code', 'q2w3-fixed-widget') .'</p>'.PHP_EOL;
472
 
473
+ //echo '<p><span style="display: inline-block; width: 280px;">'. __('widget_display_callback hook priority:', 'q2w3-fixed-widget') .'</span><select name="'. self::ID .'[widget_display_callback_priority]"><option value="1" '. selected('1', $options['widget_display_callback_priority'], false) .'>1</option><option value="10" '. selected('10', $options['widget_display_callback_priority'], false) .'>10</option><option value="20" '. selected('20', $options['widget_display_callback_priority'], false) .'>20</option><option value="30" '. selected('30', $options['widget_display_callback_priority'], false) .'>30</option><option value="50" '. selected('50', $options['widget_display_callback_priority'], false) .'>50</option><option value="100" '. selected('100', $options['widget_display_callback_priority'], false) .'>100</option></select></p>'.PHP_EOL;
474
+
475
+ }
476
+
477
+ public static function settings_page_recommend_box($options) {
478
+
479
+ echo '<ul><li><a href="https://wordpress.org/plugins/advanced-ads/" target="_blank"><b>Advanced Ads</b></a> - best Ad manager. Works perfect with Q2W3!</li>'.PHP_EOL;
480
+
481
+ echo '<li><a href="https://wordpress.org/plugins/autoptimize/" target="_blank"><b>Autoptimize</b></a> - best minificator and site optimizator. Fully compatible with Q2W3!</li></ul>'.PHP_EOL;
482
 
483
  }
484
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Max Bond
3
  Tags: sidebar, widget, scroll, scrolling, fixed, fixed widget, floating, floating widget, sticky, sticky widget, russian, q2w3
4
  Requires at least: 4.0
5
- Tested up to: 4.6
6
- Stable tag: 5.0.4
7
 
8
  Fixes positioning of the selected widgets, when the page is scrolled down.
9
 
@@ -82,6 +82,10 @@ Other Q2W3 plugins:
82
 
83
  == Changelog ==
84
 
 
 
 
 
85
  = 5.0.4 =
86
  * Compatibility patch for Better Wordpress Minify plugin.
87
 
2
  Contributors: Max Bond
3
  Tags: sidebar, widget, scroll, scrolling, fixed, fixed widget, floating, floating widget, sticky, sticky widget, russian, q2w3
4
  Requires at least: 4.0
5
+ Tested up to: 4.9.3
6
+ Stable tag: 5.1
7
 
8
  Fixes positioning of the selected widgets, when the page is scrolled down.
9
 
82
 
83
  == Changelog ==
84
 
85
+ = 5.1 =
86
+ * New options load method!
87
+ * Tested with WordPress 4.9
88
+
89
  = 5.0.4 =
90
  * Compatibility patch for Better Wordpress Minify plugin.
91