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