Changeset 3319010
- Timestamp:
- 06/28/2025 02:31:06 AM (8 months ago)
- Location:
- smoothscroller
- Files:
-
- 10 added
- 3 edited
-
tags/1.0.0/readme.txt (modified) (1 diff)
-
tags/1.1.0 (added)
-
tags/1.1.0/inc (added)
-
tags/1.1.0/inc/options-page-wrapper.php (added)
-
tags/1.1.0/index.php (added)
-
tags/1.1.0/js (added)
-
tags/1.1.0/js/localscroll-init.js (added)
-
tags/1.1.0/languages (added)
-
tags/1.1.0/languages/smoothscroller.pot (added)
-
tags/1.1.0/readme.txt (added)
-
tags/1.1.0/smoothscroller.php (added)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/smoothscroller.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smoothscroller/tags/1.0.0/readme.txt
r2405777 r3319010 5 5 Tags: smooth, scroll, links, anchor, page, posts 6 6 Requires at least: 4.0 7 Tested up to: 5. 57 Tested up to: 5.8 8 8 Stable tag: 1.0.0 9 9 Plugin Name: Smoothscroller -
smoothscroller/trunk/readme.txt
r2405777 r3319010 5 5 Tags: smooth, scroll, links, anchor, page, posts 6 6 Requires at least: 4.0 7 Tested up to: 5.58 Stable tag: 1. 0.07 Tested up to: 6.8 8 Stable tag: 1.1.0 9 9 Plugin Name: Smoothscroller 10 10 Plugin URI: http://wpbeaches.com 11 11 Description: Smoothscroller 12 12 Author: Neil Gowran 13 Version: 1. 0.013 Version: 1.2.0 14 14 Author URI: http://wpbeaches.com/ 15 15 License: GPL-2.0+ -
smoothscroller/trunk/smoothscroller.php
r1249929 r3319010 1 <?php namespace ng_smoothscroller; 1 <?php 2 namespace ng_smoothscroller; 2 3 3 4 /* … … 6 7 Description: Smooth Scroll to internal links in WordPress 7 8 Author: Neil Gee 8 Version: 1. 0.09 Version: 1.1.0 9 10 Author URI: http://wpbeaches.com 10 11 Text Domain: smoothscroller … … 16 17 */ 17 18 18 19 // If called direct, refuse 20 if ( ! defined( 'ABSPATH' ) ) { 21 die; 22 } 23 24 /* Assign global variables */ 19 if ( ! defined( 'ABSPATH' ) ) { 20 die; 21 } 25 22 26 23 $plugin_url = WP_PLUGIN_URL . '/smoothscroller'; 27 24 $options = array(); 28 25 29 /**30 * Register our text domain.31 *32 * @since 1.0.033 */34 35 26 function load_textdomain() { 36 load_plugin_textdomain( 'smoothscroller', false, basename( dirname( __FILE__ ) ) . '/languages' );27 load_plugin_textdomain( 'smoothscroller', false, basename( dirname( __FILE__ ) ) . '/languages' ); 37 28 } 38 29 add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_textdomain' ); 39 30 40 /** 41 * Register and Enqueue Scripts and Styles 42 * 43 * @since 1.0.0 44 */ 31 function scripts_styles() { 32 $options = get_option( 'smoothscroller_settings' ); 45 33 46 //Script-tac-ulous -> All the Scripts and Styles Registered and Enqueued 47 function scripts_styles() { 48 $options = get_option( 'smoothscroller_settings' );49 //if( !isset( $options['ss_all_pages'] ) ) $options['ss_all_pages'] = 0; 50 if( isset($options['ss_all_pages'] )) {34 $data = array( 35 'ss_smooth' => array( 36 'ss_smoothscroll_speed' => isset($options['ss_speed_duration']) ? (int)$options['ss_speed_duration'] : 200, 37 ), 38 ); 51 39 52 wp_register_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.1/jquery.scrollTo.min.js', array( 'jquery' ), '2.1.1', true ); 53 wp_register_script( 'localscroll', '//cdn.jsdelivr.net/jquery.localscroll/1.4.0/jquery.localScroll.min.js', array( 'scrollto' ), '1.4.0', true ); 54 wp_register_script( 'localscroll-init', plugins_url( '/js/localscroll-init.js', __FILE__ ), array( 'localscroll' ), '1', true ); 40 $enqueue_scripts = function () use ($data) { 41 wp_register_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.1/jquery.scrollTo.min.js', array( 'jquery' ), '2.1.1', true ); 42 wp_register_script( 'localscroll', '//cdn.jsdelivr.net/jquery.localscroll/1.4.0/jquery.localScroll.min.js', array( 'scrollto' ), '1.4.0', true ); 43 wp_register_script( 'localscroll-init', plugins_url( '/js/localscroll-init.js', __FILE__ ), array( 'localscroll' ), '1', true ); 55 44 56 wp_enqueue_script( 'scrollto' ); 57 wp_enqueue_script( 'localscroll' ); 45 wp_enqueue_script( 'scrollto' ); 46 wp_enqueue_script( 'localscroll' ); 47 wp_localize_script( 'localscroll-init', 'scrollVars', $data ); 48 wp_enqueue_script( 'localscroll-init' ); 49 }; 58 50 59 $data = array ( 51 if ( isset( $options['ss_all_pages'] ) ) { 52 $enqueue_scripts(); 53 } elseif ( isset( $options['ss_some_pages'] ) || isset( $options['ss_some_posts'] ) ) { 54 $page_ids = array_filter( array_map( 'absint', explode( ',', $options['ss_some_pages'] ?? '' ) ) ); 55 $post_ids = array_filter( array_map( 'absint', explode( ',', $options['ss_some_posts'] ?? '' ) ) ); 60 56 61 'ss_smooth' => array( 62 63 'ss_smoothscroll_speed' => (int)$options['ss_speed_duration'], // this is an integer 64 65 ), 66 ); 67 68 // Pass PHP variables to jQuery script 69 wp_localize_script( 'localscroll-init', 'scrollVars', $data ); 70 71 wp_enqueue_script( 'localscroll-init' ); 72 } 73 74 75 elseif( !isset($options['ss_all_pages'] )) { 76 $page_ids = explode( ',', $options['ss_some_pages'] ); 77 $post_ids = explode( ',', $options['ss_some_posts'] ); 78 79 if( is_page( $page_ids ) || is_single( $post_ids ) ) { 80 wp_register_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.0/jquery.scrollTo.min.js', array( 'jquery' ), '2.1.0', true ); 81 wp_register_script( 'localscroll', '//cdn.jsdelivr.net/jquery.localscroll/1.4.0/jquery.localScroll.min.js', array( 'scrollto' ), '1.4.0', true ); 82 wp_register_script( 'localscroll-init', plugins_url( '/js/localscroll-init.js', __FILE__ ), array( 'localscroll' ), '1', true ); 83 84 wp_enqueue_script( 'scrollto' ); 85 wp_enqueue_script( 'localscroll' ); 86 87 $data = array ( 88 89 'ss_smooth' => array( 90 91 'ss_smoothscroll_speed' => (int)$options['ss_speed_duration'], // this is an integer 92 93 ), 94 95 ); 96 97 // Pass PHP variables to jQuery script 98 wp_localize_script( 'localscroll-init', 'scrollVars', $data ); 99 100 wp_enqueue_script( 'localscroll-init' ); 57 if ( is_page( $page_ids ) || is_single( $post_ids ) ) { 58 $enqueue_scripts(); 59 } 60 } elseif ( isset( $options['ss_front_page'] ) && ( is_home() || is_front_page() ) ) { 61 $enqueue_scripts(); 101 62 } 102 }103 //endif;104 if( isset($options['ss_front_page'] )) {105 if( is_home() || is_front_page() ) {106 wp_register_script( 'scrollto', '//cdn.jsdelivr.net/jquery.scrollto/2.1.0/jquery.scrollTo.min.js', array( 'jquery' ), '2.1.0', true );107 wp_register_script( 'localscroll', '//cdn.jsdelivr.net/jquery.localscroll/1.4.0/jquery.localScroll.min.js', array( 'scrollto' ), '1.4.0', true );108 wp_register_script( 'localscroll-init', plugins_url( '/js/localscroll-init.js', __FILE__ ), array( 'localscroll' ), '1', true );109 110 wp_enqueue_script( 'scrollto' );111 wp_enqueue_script( 'localscroll' );112 113 $data = array (114 115 'ss_smooth' => array(116 117 'ss_smoothscroll_speed' => (int)$options['ss_speed_duration'], // this is an integer118 119 ),120 );121 122 // Pass PHP variables to jQuery script123 wp_localize_script( 'localscroll-init', 'scrollVars', $data );124 125 wp_enqueue_script( 'localscroll-init' );126 }127 }128 63 } 129 130 64 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\scripts_styles' ); 131 65 132 /** 133 * Register our option fields 134 * 135 * @since 1.0.0 136 */ 66 function plugin_settings(){ 67 register_setting( 68 'ss_settings-group', 69 'smoothscroller_settings', 70 __NAMESPACE__ . '\\smoothscroller_validate_input' 71 ); 137 72 138 function plugin_settings(){ 139 register_Setting(140 ' ss_settings-group', //option name141 'smoothscroller_settings',// option group setting name and option name142 __NAMESPACE__ . '\\smoothscroller_validate_input' //sanitize the inputs143 );73 add_settings_section( 74 'ss_smoothscroller_section', 75 'Smoothscroller Settings', 76 __NAMESPACE__ . '\\ss_smoothscroller_section_callback', 77 'smoothscroller' 78 ); 144 79 145 add_settings_section( 146 'ss_smoothscroller_section', //declare the section id 147 'Smoothscroller Settings', //page title 148 __NAMESPACE__ . '\\ss_smoothscroller_section_callback', //callback function below 149 'smoothscroller' //page that it appears on 150 151 ); 152 add_settings_field( 153 'ss_all_pages', //unique id of field 154 'Apply to all Posts/Pages', //title 155 __NAMESPACE__ . '\\ss_all_pages_callback', //callback function below 156 'smoothscroller', //page that it appears on 157 'ss_smoothscroller_section' //settings section declared in add_settings_section 158 ); 159 add_settings_field( 160 'ss_front_page', //unique id of field 161 'Apply to Front/Home Page', //title 162 __NAMESPACE__ . '\\ss_front_page_callback', //callback function below 163 'smoothscroller', //page that it appears on 164 'ss_smoothscroller_section' //settings section declared in add_settings_section 165 ); 166 add_settings_field( 167 'ss_some_pages', //unique id of field 168 'Apply to some Pages', //title 169 __NAMESPACE__ . '\\ss_some_pages_callback', //callback function below 170 'smoothscroller', //page that it appears on 171 'ss_smoothscroller_section' //settings section declared in add_settings_section 172 ); 173 add_settings_field( 174 'ss_some_posts', //unique id of field 175 'Apply to some Posts', //title 176 __NAMESPACE__ . '\\ss_some_posts_callback', //callback function below 177 'smoothscroller', //page that it appears on 178 'ss_smoothscroller_section' //settings section declared in add_settings_section 179 ); 180 add_settings_field( 181 'ss_speed_duration', //unique id of field 182 'Speed of Scroll', //title 183 __NAMESPACE__ . '\\ss_smoothscroller_speed_callback', //callback function below 184 'smoothscroller', //page that it appears on 185 'ss_smoothscroller_section' //settings section declared in add_settings_section 186 ); 80 add_settings_field( 'ss_all_pages', 'Apply to all Posts/Pages', __NAMESPACE__ . '\\ss_all_pages_callback', 'smoothscroller', 'ss_smoothscroller_section' ); 81 add_settings_field( 'ss_front_page', 'Apply to Front/Home Page', __NAMESPACE__ . '\\ss_front_page_callback', 'smoothscroller', 'ss_smoothscroller_section' ); 82 add_settings_field( 'ss_some_pages', 'Apply to some Pages', __NAMESPACE__ . '\\ss_some_pages_callback', 'smoothscroller', 'ss_smoothscroller_section' ); 83 add_settings_field( 'ss_some_posts', 'Apply to some Posts', __NAMESPACE__ . '\\ss_some_posts_callback', 'smoothscroller', 'ss_smoothscroller_section' ); 84 add_settings_field( 'ss_speed_duration', 'Speed of Scroll', __NAMESPACE__ . '\\ss_smoothscroller_speed_callback', 'smoothscroller', 'ss_smoothscroller_section' ); 187 85 } 188 86 add_action('admin_init', __NAMESPACE__ . '\\plugin_settings'); 189 87 190 /**191 * Sanitize our inputs192 *193 * @since 1.0.0194 */195 196 88 function smoothscroller_validate_input( $input ) { 197 // Create our array for storing the validated options198 89 $output = array(); 199 200 // Loop through each of the incoming options201 90 foreach( $input as $key => $value ) { 202 203 // Check to see if the current option has a value. If so, process it. 204 if( isset( $input[$key] ) ) { 205 206 // Strip all HTML and PHP tags and properly handle quoted strings 207 $output[$key] = strip_tags( stripslashes( $input[ $key ] ) ); 208 209 } // end if 210 211 } // end foreach 212 213 // Return the array processing any additional functions filtered by this action 214 return apply_filters( 'smoothscroller_validate_input' , $output, $input ); 91 switch ( $key ) { 92 case 'ss_all_pages': 93 case 'ss_front_page': 94 $output[ $key ] = absint( $value ); 95 break; 96 case 'ss_some_pages': 97 case 'ss_some_posts': 98 $ids = array_filter( array_map( 'absint', explode( ',', $value ) ) ); 99 $output[ $key ] = implode( ',', $ids ); 100 break; 101 case 'ss_speed_duration': 102 $allowed = [200, 400, 600, 800, 1000, 2000]; 103 $output[$key] = in_array((int)$value, $allowed, true) ? (int)$value : 200; 104 break; 105 } 106 } 107 return apply_filters( 'smoothscroller_validate_input', $output, $input ); 215 108 } 216 109 217 function ss_smoothscroller_section_callback() { 110 function ss_smoothscroller_section_callback() {} 218 111 112 function ss_smoothscroller_speed_callback() { 113 $options = get_option( 'smoothscroller_settings' ); 114 $current = isset( $options['ss_speed_duration'] ) ? (int)$options['ss_speed_duration'] : 200; 115 echo '<select name="smoothscroller_settings[ss_speed_duration]" id="ss_speed_duration">'; 116 foreach ([200, 400, 600, 800, 1000, 2000] as $val) { 117 printf('<option value="%d" %s>%d</option>', $val, selected($current, $val, false), $val); 118 } 119 echo '</select><label for="ss_speed_duration">' . esc_html__('Speed of scroll (Lower numbers are faster)', 'smoothscroller') . '</label>'; 219 120 } 220 121 221 /** 222 * Register our Speed Duration callback 223 * 224 * @since 1.0.0 225 */ 226 227 function ss_smoothscroller_speed_callback(){ 228 $options = get_option( 'smoothscroller_settings' ); 229 230 if( !isset( $options['ss_speed_duration'] ) ) $options['ss_speed_duration'] = 200; 231 232 ?> 233 234 <select name="smoothscroller_settings[ss_speed_duration]" id="ss_speed_duration"> 235 <option value="200" <?php selected($options['ss_speed_duration'], '200'); ?>>200</option> 236 <option value="400" <?php selected($options['ss_speed_duration'], '400'); ?>>400</option> 237 <option value="600" <?php selected($options['ss_speed_duration'], '600'); ?>>600</option> 238 <option value="800" <?php selected($options['ss_speed_duration'], '800'); ?>>800</option> 239 <option value="1000" <?php selected($options['ss_speed_duration'], '1000'); ?>>1000</option> 240 <option value="2000" <?php selected($options['ss_speed_duration'], '2000'); ?>>2000</option> 241 </select> 242 <label for="ss_speed_duration"><?php esc_attr_e( 'Speed of scroll (Lower numbers are faster)', 'smoothscroller' ); ?></label> 243 <?php 122 function ss_all_pages_callback() { 123 $options = get_option( 'smoothscroller_settings' ); 124 $checked = isset($options['ss_all_pages']) ? (int)$options['ss_all_pages'] : 0; 125 echo '<input type="checkbox" id="ss_all_pages" name="smoothscroller_settings[ss_all_pages]" value="1"' . checked( 1, $checked, false ) . '/>'; 126 echo '<label for="ss_all_pages">' . esc_html__('Check to enable Smoothscroller on all posts/pages','smoothscroller') . '</label>'; 244 127 } 245 128 246 /**247 * Register All Pages have scroll option248 *249 * @since 1.0.0250 */251 252 function ss_all_pages_callback() {253 $options = get_option( 'smoothscroller_settings' );254 255 if( !isset( $options['ss_all_pages'] ) ) $options['ss_all_pages'] = 0;256 257 echo'<input type="checkbox" id="ss_all_pages" name="smoothscroller_settings[ss_all_pages]" value="1"' . checked( 1, $options['ss_all_pages'], false ) . '/>';258 echo'<label for="ss_all_pages">' . esc_attr_e( 'Check to enable Smoothscroller on all posts/pages','smoothscroller') . '</label>';259 }260 261 /**262 * Register Front Page has scroll option263 *264 * @since 1.0.0265 */266 267 129 function ss_front_page_callback() { 268 $options = get_option( 'smoothscroller_settings' ); 269 270 if( !isset( $options['ss_front_page'] ) ) $options['ss_front_page'] = 0; 271 272 echo'<input type="checkbox" id="ss_front_page" name="smoothscroller_settings[ss_front_page]" value="1"' . checked( 1, $options['ss_front_page'], false ) . '/>'; 273 echo'<label for="ss_front_page">' . esc_attr_e( 'Check to enable Smoothscroller on Home/Front page','smoothscroller') . '</label>'; 274 } 275 276 /** 277 * Register Some Pages have scroll option 278 * 279 * @since 1.0.0 280 */ 130 $options = get_option( 'smoothscroller_settings' ); 131 $checked = isset($options['ss_front_page']) ? (int)$options['ss_front_page'] : 0; 132 echo '<input type="checkbox" id="ss_front_page" name="smoothscroller_settings[ss_front_page]" value="1"' . checked( 1, $checked, false ) . '/>'; 133 echo '<label for="ss_front_page">' . esc_html__('Check to enable Smoothscroller on Home/Front page','smoothscroller') . '</label>'; 134 } 281 135 282 136 function ss_some_pages_callback() { 283 $options = get_option( 'smoothscroller_settings' ); 284 285 if( !isset( $options['ss_some_pages'] ) ) $options['ss_some_pages'] = ''; 286 287 288 echo '<input type="text" id="ss_some_pages" name="smoothscroller_settings[ss_some_pages]" value="' . sanitize_text_field($options['ss_some_pages']) . '" placeholder="add page IDs comma separated">'; 289 echo '<label for="ss_some_pages">' . esc_attr_e( 'Comma Separate the ID values','smoothscroller') . '</label>'; 137 $options = get_option( 'smoothscroller_settings' ); 138 $val = esc_attr( $options['ss_some_pages'] ?? '' ); 139 echo '<input type="text" id="ss_some_pages" name="smoothscroller_settings[ss_some_pages]" value="' . $val . '" placeholder="add page IDs comma separated">'; 140 echo '<label for="ss_some_pages">' . esc_html__('Comma Separate the ID values','smoothscroller') . '</label>'; 290 141 } 291 142 292 /**293 * Register Some Posts have scroll option294 *295 * @since 1.0.0296 */297 298 143 function ss_some_posts_callback() { 299 $options = get_option( 'smoothscroller_settings' ); 300 301 if( !isset( $options['ss_some_posts'] ) ) $options['ss_some_posts'] = ''; 302 303 304 echo '<input type="text" id="ss_some_posts" name="smoothscroller_settings[ss_some_posts]" value="' . sanitize_text_field($options['ss_some_posts']) . '" placeholder="add post IDs comma separated">'; 305 echo '<label for="ss_some_posts">' . esc_attr_e( ' Comma Separate the ID values','smoothscroller') . '</label>'; 144 $options = get_option( 'smoothscroller_settings' ); 145 $val = esc_attr( $options['ss_some_posts'] ?? '' ); 146 echo '<input type="text" id="ss_some_posts" name="smoothscroller_settings[ss_some_posts]" value="' . $val . '" placeholder="add post IDs comma separated">'; 147 echo '<label for="ss_some_posts">' . esc_html__('Comma Separate the ID values','smoothscroller') . '</label>'; 306 148 } 307 149 308 /**309 * Create the plugin option page.310 *311 * @since 1.0.0312 */313 314 150 function plugin_page() { 315 316 /* 317 * Use the add options_page function 318 * add_options_page( $page_title, $menu_title, $capability, $menu-slug, $function ) 319 */ 320 321 add_options_page( 322 __( 'Smoothscroller Options Plugin','smoothscroller' ), //$page_title 323 __( 'Smoothscroller', 'smoothscroller' ), //$menu_title 324 'manage_options', //$capability 325 'smoothscroller', //$menu-slug 326 __NAMESPACE__ . '\\plugin_options_page' //$function 327 ); 151 add_options_page( 152 __( 'Smoothscroller Options Plugin','smoothscroller' ), 153 __( 'Smoothscroller', 'smoothscroller' ), 154 'manage_options', 155 'smoothscroller', 156 __NAMESPACE__ . '\\plugin_options_page' 157 ); 328 158 } 329 159 add_action( 'admin_menu', __NAMESPACE__ . '\\plugin_page' ); 330 160 331 /**332 * Include the plugin option page.333 *334 * @since 1.0.0335 */336 337 161 function plugin_options_page() { 338 339 162 if( !current_user_can( 'manage_options' ) ) { 340 341 wp_die( "Hall and Oates 'Say No Go'" ); 163 wp_die( "Hall and Oates 'Say No Go'" ); 342 164 } 343 344 require( 'inc/options-page-wrapper.php' ); 165 require( 'inc/options-page-wrapper.php' ); 345 166 }
Note: See TracChangeset
for help on using the changeset viewer.