PluginProbe ʕ •ᴥ•ʔ
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) / 1.8.7
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) v1.8.7
2.9.1 2.9.0 2.8.9 2.8.8 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 2.0 2.0.1 2.0.3 2.0.4 2.0.5 2.0.6 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7
mystickymenu / mystickymenu.php
mystickymenu Last commit date
js 9 years ago languages 11 years ago mystickymenu.php 9 years ago readme.txt 9 years ago
mystickymenu.php
487 lines
1 <?php
2 /*
3 Plugin Name: myStickymenu
4 Plugin URI: http://wordpress.transformnews.com/plugins/mystickymenu-simple-sticky-fixed-on-top-menu-implementation-for-twentythirteen-menu-269
5 Description: Simple sticky (fixed on top) menu implementation for default Twentythirteen navigation menu. For other themes, after install go to Settings / myStickymenu and change Sticky Class to .your_navbar_class or #your_navbar_id.
6 Version: 1.8.7
7 Author: m.r.d.a
8 Author URI: http://wordpress.transformnews.com/
9 Text Domain: mystickymenu
10 Domain Path: /languages
11 License: GPLv2 or later
12 */
13
14 defined('ABSPATH') or die("Cannot access pages directly.");
15
16 class MyStickyMenuBackend
17 {
18
19 private $options;
20
21 public function __construct()
22 {
23 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
24 add_action( 'admin_init', array( $this, 'mysticky_load_transl') );
25 add_action( 'admin_init', array( $this, 'page_init' ) );
26 add_action( 'admin_init', array( $this, 'mysticky_default_options' ) );
27 add_action( 'admin_enqueue_scripts', array( $this, 'mysticky_enqueue_color_picker' ) );
28 }
29
30 public function mysticky_load_transl()
31 {
32 load_plugin_textdomain('mystickymenu', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
33 }
34
35 public function add_plugin_page()
36 {
37 // This page will be under "Settings"
38 add_options_page(
39 'Settings Admin',
40 'myStickymenu',
41 'manage_options',
42 'my-stickymenu-settings',
43 array( $this, 'create_admin_page' )
44 );
45 }
46
47 public function create_admin_page()
48 {
49 // Set class property
50 $this->options = get_option( 'mysticky_option_name');
51 ?>
52 <div class="wrap">
53 <?php screen_icon(); ?>
54 <h2><?php _e('myStickymenu Settings', 'mystickymenu'); ?></h2>
55 <form method="post" action="options.php">
56 <?php
57 settings_fields( 'mysticky_option_group' );
58 do_settings_sections( 'my-stickymenu-settings' );
59 submit_button();
60 ?>
61 </form>
62 </div>
63 <?php
64 }
65
66 public function page_init()
67 {
68 global $id, $title, $callback, $page;
69 register_setting(
70 'mysticky_option_group',
71 'mysticky_option_name',
72 array( $this, 'sanitize' )
73 );
74
75 add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() );
76
77 add_settings_section(
78 'setting_section_id',
79 __("myStickymenu Options", 'mystickymenu'),
80 array( $this, 'print_section_info' ),
81 'my-stickymenu-settings'
82 );
83 add_settings_field(
84 'mysticky_class_selector',
85 __("Sticky Class", 'mystickymenu'),
86 array( $this, 'mysticky_class_selector_callback' ),
87 'my-stickymenu-settings',
88 'setting_section_id'
89 );
90 add_settings_field(
91 'myfixed_zindex',
92 __("Sticky z-index", 'mystickymenu'),
93 array( $this, 'myfixed_zindex_callback' ),
94 'my-stickymenu-settings',
95 'setting_section_id'
96 );
97 add_settings_field(
98 'myfixed_bgcolor',
99 __("Sticky Background Color", 'mystickymenu'),
100 array( $this, 'myfixed_bgcolor_callback' ),
101 'my-stickymenu-settings',
102 'setting_section_id'
103 );
104 add_settings_field(
105 'myfixed_opacity',
106 __("Sticky Opacity", 'mystickymenu'),
107 array( $this, 'myfixed_opacity_callback' ),
108 'my-stickymenu-settings',
109 'setting_section_id'
110 );
111 add_settings_field(
112 'myfixed_transition_time',
113 __("Sticky Transition Time", 'mystickymenu'),
114 array( $this, 'myfixed_transition_time_callback' ),
115 'my-stickymenu-settings',
116 'setting_section_id'
117 );
118 add_settings_field(
119 'myfixed_disable_small_screen',
120 __("Disable at Small Screen Sizes", 'mystickymenu'),
121 array( $this, 'myfixed_disable_small_screen_callback' ),
122 'my-stickymenu-settings',
123 'setting_section_id'
124 );
125 add_settings_field(
126 'mysticky_active_on_height',
127 __("Make visible on Scroll", 'mystickymenu'),
128 array( $this, 'mysticky_active_on_height_callback' ),
129 'my-stickymenu-settings',
130 'setting_section_id'
131 );
132 add_settings_field(
133 'mysticky_active_on_height_home',
134 __("Make visible on Scroll at homepage", 'mystickymenu'),
135 array( $this, 'mysticky_active_on_height_home_callback' ),
136 'my-stickymenu-settings',
137 'setting_section_id'
138 );
139 add_settings_field(
140 'myfixed_fade',
141 __("Fade or slide effect", 'mystickymenu'),
142 array( $this, 'myfixed_fade_callback' ),
143 'my-stickymenu-settings',
144 'setting_section_id'
145 );
146 add_settings_field(
147 'myfixed_cssstyle',
148 __(".myfixed css class", 'mystickymenu'),
149 array( $this, 'myfixed_cssstyle_callback' ),
150 'my-stickymenu-settings',
151 'setting_section_id'
152 );
153 add_settings_field(
154 'disable_css',
155 __("Disable CSS style", 'mystickymenu'),
156 array( $this, 'disable_css_callback' ),
157 'my-stickymenu-settings',
158 'setting_section_id'
159 );
160 }
161 /**
162 * Sanitize each setting field as needed
163 *
164 * @param array $input Contains all settings fields as array keys
165 */
166 public function sanitize( $input )
167 {
168 $new_input = array();
169 if( isset( $input['mysticky_class_selector'] ) )
170 $new_input['mysticky_class_selector'] = sanitize_text_field( $input['mysticky_class_selector'] );
171
172 if( isset( $input['myfixed_zindex'] ) )
173 $new_input['myfixed_zindex'] = absint( $input['myfixed_zindex'] );
174
175 if( isset( $input['myfixed_bgcolor'] ) )
176 $new_input['myfixed_bgcolor'] = sanitize_text_field( $input['myfixed_bgcolor'] );
177
178 if( isset( $input['myfixed_opacity'] ) )
179 $new_input['myfixed_opacity'] = absint( $input['myfixed_opacity'] );
180
181 if( isset( $input['myfixed_transition_time'] ) )
182 $new_input['myfixed_transition_time'] = sanitize_text_field( $input['myfixed_transition_time'] );
183
184 if( isset( $input['myfixed_disable_small_screen'] ) )
185 $new_input['myfixed_disable_small_screen'] = absint( $input['myfixed_disable_small_screen'] );
186
187 if( isset( $input['mysticky_active_on_height'] ) )
188 $new_input['mysticky_active_on_height'] = absint( $input['mysticky_active_on_height'] );
189
190 if( isset( $input['mysticky_active_on_height_home'] ) )
191 $new_input['mysticky_active_on_height_home'] = absint( $input['mysticky_active_on_height_home'] );
192
193 if( isset( $input['myfixed_fade'] ) )
194 $new_input['myfixed_fade'] = sanitize_text_field( $input['myfixed_fade'] );
195
196 if( isset( $input['myfixed_cssstyle'] ) )
197 $new_input['myfixed_cssstyle'] = sanitize_text_field( $input['myfixed_cssstyle'] );
198
199 if( isset( $input['disable_css'] ) )
200 $new_input['disable_css'] = sanitize_text_field( $input['disable_css'] );
201
202 return $new_input;
203 }
204
205 public function mysticky_default_options() {
206
207 global $options;
208 $default = array(
209
210 'mysticky_class_selector' => '.navbar',
211 'myfixed_zindex' => '1000',
212 'myfixed_bgcolor' => '#FAFAFA',
213 'myfixed_opacity' => '90',
214 'myfixed_transition_time' => '0.3',
215 'myfixed_disable_small_screen' => '359',
216 'mysticky_active_on_height' => '320',
217 'mysticky_active_on_height_home' => '320',
218 'myfixed_fade' => false,
219 'myfixed_cssstyle' => '.myfixed { margin:0 auto!important; float:none!important; border:0px!important; background:none!important; max-width:100%!important; }'
220 );
221
222 if ( get_option('mysticky_option_name') == false ) {
223 update_option( 'mysticky_option_name', $default );
224 }
225 }
226
227 public function mysticky_enqueue_color_picker( )
228 {
229 wp_enqueue_style( 'wp-color-picker' );
230 wp_enqueue_script( 'my-script-handle', plugins_url('js/iris-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
231 }
232
233 public function print_section_info()
234 {
235 echo __("Add nice modern sticky menu or header to any theme. Defaults works for Twenty Thirteen theme. <br />For other themes change 'Sticky Class' to div class desired to be sticky (div id can be used too).", 'mystickymenu');
236 }
237
238 public function mysticky_class_selector_callback()
239 {
240 printf(
241 '<p class="description"><input type="text" size="8" id="mysticky_class_selector" name="mysticky_option_name[mysticky_class_selector]" value="%s" /> ',
242 isset( $this->options['mysticky_class_selector'] ) ? esc_attr( $this->options['mysticky_class_selector']) : ''
243 );
244 echo __("menu or header div class or id.", 'mystickymenu');
245 echo '</p>';
246 }
247
248 public function myfixed_zindex_callback()
249 {
250 printf(
251 '<p class="description"><input type="number" min="0" max="2147483647" step="1" id="myfixed_zindex" name="mysticky_option_name[myfixed_zindex]" value="%s" /></p>',
252 isset( $this->options['myfixed_zindex'] ) ? esc_attr( $this->options['myfixed_zindex']) : ''
253 );
254 }
255
256 public function myfixed_bgcolor_callback()
257 {
258 printf(
259 '<p class="description"><input type="text" id="myfixed_bgcolor" name="mysticky_option_name[myfixed_bgcolor]" class="my-color-field" value="%s" /></p> ' ,
260 isset( $this->options['myfixed_bgcolor'] ) ? esc_attr( $this->options['myfixed_bgcolor']) : ''
261 );
262 }
263
264 public function myfixed_opacity_callback()
265 {
266 printf(
267 '<p class="description"><input type="number" class="small-text" min="0" step="1" max="100" id="myfixed_opacity" name="mysticky_option_name[myfixed_opacity]" value="%s" /> ',
268 isset( $this->options['myfixed_opacity'] ) ? esc_attr( $this->options['myfixed_opacity']) : ''
269 );
270 echo __("numbers 1-100.", 'mystickymenu');
271 echo '</p>';
272 }
273
274 public function myfixed_transition_time_callback()
275 {
276 printf(
277 '<p class="description"><input type="number" class="small-text" min="0" step="0.1" id="myfixed_transition_time" name="mysticky_option_name[myfixed_transition_time]" value="%s" /> ',
278 isset( $this->options['myfixed_transition_time'] ) ? esc_attr( $this->options['myfixed_transition_time']) : ''
279 );
280 echo __("in seconds.", 'mystickymenu');
281 echo '</p>';
282 }
283
284 public function myfixed_disable_small_screen_callback()
285 {
286 printf(
287 '<p class="description">'
288 );
289 echo __("less than", 'mystickymenu');
290 printf(
291 ' <input type="number" class="small-text" min="0" step="1" id="myfixed_disable_small_screen" name="mysticky_option_name[myfixed_disable_small_screen]" value="%s" />',
292 isset( $this->options['myfixed_disable_small_screen'] ) ? esc_attr( $this->options['myfixed_disable_small_screen']) : ''
293 );
294 echo __("px width, 0 to disable.", 'mystickymenu');
295 echo '</p>';
296 }
297
298 public function mysticky_active_on_height_callback()
299 {
300 printf(
301 '<p class="description">'
302 );
303 echo __("after", 'mystickymenu');
304 printf(
305 ' <input type="number" class="small-text" min="0" step="1" id="mysticky_active_on_height" name="mysticky_option_name[mysticky_active_on_height]" value="%s" />',
306 isset( $this->options['mysticky_active_on_height'] ) ? esc_attr( $this->options['mysticky_active_on_height']) : ''
307 );
308 echo __("px.", 'mystickymenu');
309 echo '</p>';
310 }
311
312 public function mysticky_active_on_height_home_callback()
313 {
314 printf(
315 '<p class="description">'
316 );
317 echo __("after", 'mystickymenu');
318 printf(
319 ' <input type="number" class="small-text" min="0" step="1" id="mysticky_active_on_height_home" name="mysticky_option_name[mysticky_active_on_height_home]" value="%s" />',
320 isset( $this->options['mysticky_active_on_height_home'] ) ? esc_attr( $this->options['mysticky_active_on_height_home']) : ''
321 );
322 echo __("px.", 'mystickymenu');
323 echo '</p>';
324 }
325
326 public function myfixed_fade_callback()
327 {
328 printf(
329 '<p class="description"><input id="%1$s" name="mysticky_option_name[myfixed_fade]" type="checkbox" %2$s /> ',
330 'myfixed_fade',
331 checked( isset( $this->options['myfixed_fade'] ), true, false )
332 );
333 echo __("Checked is slide, unchecked is fade.", 'mystickymenu');
334 echo '</p>';
335 }
336
337 public function myfixed_cssstyle_callback()
338 {
339 printf(
340 '<p class="description">'
341 );
342 echo __("Add/Edit .myfixed css class to change sticky menu style. Leave it blank for default style.", 'mystickymenu');
343 echo '</p>';
344 printf(
345 '<textarea type="text" rows="4" cols="60" id="myfixed_cssstyle" name="mysticky_option_name[myfixed_cssstyle]">%s</textarea> <br />',
346 isset( $this->options['myfixed_cssstyle'] ) ? esc_attr( $this->options['myfixed_cssstyle']) : ''
347 );
348 echo '<p class="description">';
349 echo __("Default style: ", 'mystickymenu');
350 echo '.myfixed { margin:0 auto!important; float:none!important; border:0px!important; background:none!important; max-width:100%!important; }<br /><br />';
351 echo __("If you want to change sticky hover color first add default style and than: ", 'mystickymenu');
352 echo '.myfixed li a:hover {color:#000; background-color: #ccc;}<br />';
353 echo __("More examples <a href='http://wordpress.transformnews.com/tutorials/mystickymenu-extended-style-functionality-using-myfixed-sticky-class-403'>here</a>.", 'mystickymenu');
354 echo'</p>';
355 }
356
357 public function disable_css_callback()
358 {
359 printf(
360 '<p class="description"><input id="%1$s" name="mysticky_option_name[disable_css]" type="checkbox" %2$s /> ',
361 'disable_css',
362 checked( isset( $this->options['disable_css'] ), true, false )
363 );
364 echo __("Use this option if you plan to include CSS Style manually", 'mystickymenu');
365 echo '</p>';
366 }
367
368 }
369
370
371
372 class MyStickyMenuFrontend
373 {
374
375 public function __construct()
376 {
377 add_action( 'wp_head', array( $this, 'mysticky_build_stylesheet_content' ) );
378 add_action( 'wp_enqueue_scripts', array( $this, 'mystickymenu_script' ) );
379
380 }
381
382 public function mysticky_build_stylesheet_content()
383 {
384
385 $mysticky_options = get_option( 'mysticky_option_name' );
386
387 if (isset($mysticky_options['disable_css']))
388 {
389 //do nothing
390 } else {
391 $mysticky_options['disable_css'] = false;
392 };
393
394 if ($mysticky_options ['disable_css'] == false )
395 {
396
397 echo
398 '<style type="text/css">';
399 if ( is_user_logged_in() ) {
400 echo '#wpadminbar { position: absolute !important; top: 0px !important;}';
401 }
402 if ( $mysticky_options['myfixed_cssstyle'] == "" ) {
403 echo '.myfixed{margin:0 auto!important; float:none!important; border:0px!important; background:none!important; max-width:100%!important;}';
404 }
405 echo esc_attr ( $mysticky_options ['myfixed_cssstyle'] );
406 echo '#mysticky-nav { width:100%!important; position: static;';
407
408 if (isset($mysticky_options['myfixed_fade']))
409 {
410 echo 'top: -100px;';
411 }
412 echo '}';
413
414
415 if ($mysticky_options ['myfixed_opacity'] == 100 ){
416
417 echo '.wrapfixed { position: fixed!important; top:0px!important; left: 0px!important; margin-top:0px!important; z-index: '. $mysticky_options ['myfixed_zindex'] .'; -webkit-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; -moz-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; -o-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; background-color: ' . $mysticky_options ['myfixed_bgcolor'] . '!important;}';
418
419 }
420
421 if ($mysticky_options ['myfixed_opacity'] < 100 ){
422
423 echo '.wrapfixed { position: fixed!important; top:0px!important; left: 0px!important; margin-top:0px!important; z-index: '. $mysticky_options ['myfixed_zindex'] .'; -webkit-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; -moz-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; -o-transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; transition: ' . $mysticky_options ['myfixed_transition_time'] . 's; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=' . $mysticky_options ['myfixed_opacity'] . ')"; filter: alpha(opacity=' . $mysticky_options ['myfixed_opacity'] . '); opacity:.' . $mysticky_options ['myfixed_opacity'] . '; background-color: ' . $mysticky_options ['myfixed_bgcolor'] . '!important;}';
424
425 }
426
427 if ($mysticky_options ['myfixed_disable_small_screen'] > 0 ){
428
429 echo '@media (max-width: ' . $mysticky_options ['myfixed_disable_small_screen'] . 'px) {.wrapfixed {position: static!important;} }';
430
431 }
432 echo '</style>';
433 }
434 }
435
436 // add_action('wp_head', 'mysticky_build_stylesheet_content');
437
438 public function mystickymenu_script() {
439
440 $mysticky_options = get_option( 'mysticky_option_name' );
441
442 // needed for update 1.7 => 1.8 ... will be removed in the future ()
443 if (isset($mysticky_options['mysticky_active_on_height_home'])){
444 //do nothing
445 } else {
446 $mysticky_options['mysticky_active_on_height_home'] = $mysticky_options['mysticky_active_on_height'];
447 };
448
449 if ($mysticky_options['mysticky_active_on_height_home'] == 0 ){
450 $mysticky_options['mysticky_active_on_height_home'] = $mysticky_options['mysticky_active_on_height'];
451 };
452
453
454 if ( is_front_page() && is_home() ) {
455
456 $mysticky_options['mysticky_active_on_height'] = $mysticky_options['mysticky_active_on_height_home'];
457
458 } elseif ( is_front_page()){
459
460 $mysticky_options['mysticky_active_on_height'] = $mysticky_options['mysticky_active_on_height_home'];
461
462 }
463
464 wp_register_script('mystickymenu', plugins_url( 'js/mystickymenu.min.js', __FILE__ ), array('jquery'),'1.8.7', true);
465 wp_enqueue_script( 'mystickymenu' );
466
467 $mysticky_translation_array = array(
468 'mysticky_string' => $mysticky_options['mysticky_class_selector'] ,
469 'mysticky_active_on_height_string' => $mysticky_options['mysticky_active_on_height'],
470 'mysticky_disable_at_width_string' => $mysticky_options['myfixed_disable_small_screen']
471 );
472
473 wp_localize_script( 'mystickymenu', 'mysticky_name', $mysticky_translation_array );
474 }
475
476 //add_action( 'wp_enqueue_scripts', 'mystickymenu_script' );
477 }
478
479 if( is_admin() ) {
480
481 new MyStickyMenuBackend();
482
483 } else {
484
485 new MyStickyMenuFrontend();
486 }
487 ?>