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