PluginProbe ʕ •ᴥ•ʔ
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) / 1.5
My Sticky Bar – Floating Notification Bar & Sticky Header (formerly myStickymenu) v1.5
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 12 years ago mystickymenu.php 12 years ago readme.txt 12 years ago screenshot-1.png 12 years ago screenshot-2.png 12 years ago
mystickymenu.php
384 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.5
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 add_settings_field(
139 'myfixed_cssstyle',
140 '.myfixed css class',
141 array( $this, 'myfixed_cssstyle_callback' ),
142 'my-stickymenu-settings',
143 'setting_section_id'
144
145 );
146 add_settings_field(
147 'myfixed_fade',
148 'Fade or slide effect',
149 array( $this, 'myfixed_fade_callback' ),
150 'my-stickymenu-settings',
151 'setting_section_id'
152 );
153 }
154
155 /**
156 * Sanitize each setting field as needed
157 *
158 * @param array $input Contains all settings fields as array keys
159 */
160 public function sanitize( $input )
161 {
162 $new_input = array();
163 if( isset( $input['mysticky_class_selector'] ) )
164 $new_input['mysticky_class_selector'] = sanitize_text_field( $input['mysticky_class_selector'] );
165
166 if( isset( $input['myfixed_zindex'] ) )
167 $new_input['myfixed_zindex'] = absint( $input['myfixed_zindex'] );
168
169 if( isset( $input['myfixed_bgcolor'] ) )
170 $new_input['myfixed_bgcolor'] = sanitize_text_field( $input['myfixed_bgcolor'] );
171
172 if( isset( $input['myfixed_opacity'] ) )
173 $new_input['myfixed_opacity'] = sanitize_text_field( $input['myfixed_opacity'] );
174
175 if( isset( $input['myfixed_transition_time'] ) )
176 $new_input['myfixed_transition_time'] = sanitize_text_field( $input['myfixed_transition_time'] );
177
178 if( isset( $input['myfixed_disable_small_screen'] ) )
179 $new_input['myfixed_disable_small_screen'] = absint( $input['myfixed_disable_small_screen'] );
180
181 if( isset( $input['myfixed_cssstyle'] ) )
182 //$new_input['myfixed_cssstyle'] = esc_textarea( $input['myfixed_cssstyle'] );
183 $new_input['myfixed_cssstyle'] = sanitize_text_field( $input['myfixed_cssstyle'] );
184
185 if( isset( $input['myfixed_fade'] ) )
186 $new_input['myfixed_fade'] = sanitize_text_field( $input['myfixed_fade'] );
187
188
189 return $new_input;
190 }
191
192 /**
193 * Load Defaults
194 */
195 public function mysticky_default_options() {
196
197 global $options;
198
199
200
201
202 if ( get_option('mysticky_option_name') == false ) {
203
204 $default = array(
205
206 'mysticky_class_selector' => '.navbar',
207 'myfixed_zindex' => '1000000',
208 'myfixed_bgcolor' => '#F39A30',
209 'myfixed_opacity' => '95',
210 'myfixed_transition_time' => '0.3',
211 'myfixed_cssstyle' => '.myfixed {margin: 0 auto!important; float:none!important; border:0px!important; background:none!important;}',
212 'myfixed_disable_small_screen' => '359',
213 'myfixed_fade' => 'on'
214 );
215
216 update_option( 'mysticky_option_name', $default );
217 }
218 }
219 /**
220 * Print the Section text
221 */
222
223 public function print_section_info()
224 {
225 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).';
226 }
227 /**
228 * Get the settings option array and print one of its values
229 */
230
231 public function mysticky_class_selector_callback()
232 {
233 printf(
234 '<p class="description"><input type="text" id="mysticky_class_selector" name="mysticky_option_name[mysticky_class_selector]" value="%s" /> menu or header div class or id.</p>',
235 isset( $this->options['mysticky_class_selector'] ) ? esc_attr( $this->options['mysticky_class_selector']) : ''
236 );
237 }
238
239 public function myfixed_zindex_callback()
240 {
241 printf(
242 '<p class="description"><input type="text" id="myfixed_zindex" name="mysticky_option_name[myfixed_zindex]" value="%s" /> sticky z-index.</p>',
243 isset( $this->options['myfixed_zindex'] ) ? esc_attr( $this->options['myfixed_zindex']) : ''
244 );
245 }
246
247 public function myfixed_bgcolor_callback()
248 {
249 printf(
250 '<p class="description"><input type="text" id="myfixed_bgcolor" name="mysticky_option_name[myfixed_bgcolor]" value="%s" /> full width background color.</p>' ,
251 isset( $this->options['myfixed_bgcolor'] ) ? esc_attr( $this->options['myfixed_bgcolor']) : ''
252 );
253 }
254
255 public function myfixed_opacity_callback()
256 {
257 printf(
258 '<p class="description"><input type="text" id="myfixed_opacity" name="mysticky_option_name[myfixed_opacity]" value="%s" /> numbers 1-100.</p>',
259 isset( $this->options['myfixed_opacity'] ) ? esc_attr( $this->options['myfixed_opacity']) : ''
260 );
261 }
262
263 public function myfixed_transition_time_callback()
264 {
265 printf(
266 '<p class="description"><input type="text" id="myfixed_transition_time" name="mysticky_option_name[myfixed_transition_time]" value="%s" /> in seconds.</p>',
267 isset( $this->options['myfixed_transition_time'] ) ? esc_attr( $this->options['myfixed_transition_time']) : ''
268 );
269 }
270
271 public function myfixed_disable_small_screen_callback()
272 {
273 printf(
274 '<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, 0 to disable.</p>',
275 isset( $this->options['myfixed_disable_small_screen'] ) ? esc_attr( $this->options['myfixed_disable_small_screen']) : ''
276 );
277 }
278
279 public function myfixed_cssstyle_callback()
280
281 {
282 printf(
283 '
284 <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 /><p class="description">Default style: .myfixed {margin: 0 auto!important; float:none!important; border:0px!important; background:none!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>
285 ' ,
286 isset( $this->options['myfixed_cssstyle'] ) ? esc_attr( $this->options['myfixed_cssstyle']) : ''
287 );
288 }
289
290 public function myfixed_fade_callback()
291 {
292 printf(
293 '<p class="description"><input id="%1$s" name="mysticky_option_name[myfixed_fade]" type="checkbox" %2$s /> Checked is fade, unchecked is slide.</p>',
294 'myfixed_fade',
295 checked( isset( $this->options['myfixed_fade'] ), true, false )
296 );
297 }
298
299 }
300
301 if( is_admin() )
302 $my_settings_page = new MyStickyMenuPage();
303
304 // end plugin admin settings
305
306
307 // Remove default option for more link that jumps at the midle of page and its covered by menu
308
309 function mysticky_remove_more_jump_link($link) {
310 $offset = strpos($link, '#more-');
311 if ($offset) {
312 $end = strpos($link, '"',$offset);
313 }
314 if ($end) {
315 $link = substr_replace($link, '', $offset, $end-$offset);
316 }
317 return $link;
318 }
319 add_filter('the_content_more_link', 'mysticky_remove_more_jump_link');
320
321 // Create style from options
322
323 function mysticky_build_stylesheet_content() {
324
325 $mysticky_options = get_option( 'mysticky_option_name' );
326
327 echo
328 '<style type="text/css">';
329 if ( is_user_logged_in() ) {
330 echo '#wpadminbar { position: absolute !important; top: 0px !important;}';
331 }
332
333 if ( $mysticky_options['myfixed_cssstyle'] == "" ) {
334
335 echo '.myfixed { margin:0 auto!important; float:none!important; border:0px!important; background:none!important; max-width:100%!important; }';
336
337 }
338
339 echo
340 $mysticky_options ['myfixed_cssstyle'] ;
341
342 echo
343 '
344 #mysticky-nav { width:100%!important; position: static;';
345 if (!isset($mysticky_options['myfixed_fade'])){
346 echo
347 'top: -100px;';
348 }
349 echo
350 '}';
351 echo
352 '.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; }
353 ';
354
355
356
357 if ($mysticky_options ['myfixed_disable_small_screen'] > 0 ){
358 echo
359 '@media (max-width: ' . $mysticky_options ['myfixed_disable_small_screen'] . 'px) {.wrapfixed {position: static!important;}}
360 ';
361 }
362 echo
363 '</style>
364 ';
365 }
366 add_action('wp_head', 'mysticky_build_stylesheet_content');
367
368
369 function mystickymenu_script() {
370
371 $mysticky_options = get_option( 'mysticky_option_name' );
372
373 // Register scripts
374 wp_register_script('mystickymenu', WP_PLUGIN_URL. '/mystickymenu/mystickymenu.js', false,'1.0.0', true);
375 wp_enqueue_script( 'mystickymenu' );
376
377 // Localize mystickymenu.js script with myStickymenu options
378 $mysticky_translation_array = array( 'mysticky_string' => $mysticky_options['mysticky_class_selector'] );
379
380 wp_localize_script( 'mystickymenu', 'mysticky_name', $mysticky_translation_array );
381 }
382
383 add_action( 'wp_enqueue_scripts', 'mystickymenu_script' );
384 ?>