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