Plugin Directory

Changeset 3319010


Ignore:
Timestamp:
06/28/2025 02:31:06 AM (8 months ago)
Author:
neilgee
Message:

Tagging Smoothscroller version 1.1.0 with security patch

Location:
smoothscroller
Files:
10 added
3 edited

Legend:

Unmodified
Added
Removed
  • smoothscroller/tags/1.0.0/readme.txt

    r2405777 r3319010  
    55Tags: smooth, scroll, links, anchor, page, posts
    66Requires at least: 4.0
    7 Tested up to: 5.5
     7Tested up to: 5.8
    88Stable tag: 1.0.0
    99Plugin Name: Smoothscroller
  • smoothscroller/trunk/readme.txt

    r2405777 r3319010  
    55Tags: smooth, scroll, links, anchor, page, posts
    66Requires at least: 4.0
    7 Tested up to: 5.5
    8 Stable tag: 1.0.0
     7Tested up to: 6.8
     8Stable tag: 1.1.0
    99Plugin Name: Smoothscroller
    1010Plugin URI: http://wpbeaches.com
    1111Description: Smoothscroller
    1212Author: Neil Gowran
    13 Version: 1.0.0
     13Version: 1.2.0
    1414Author URI: http://wpbeaches.com/
    1515License: GPL-2.0+
  • smoothscroller/trunk/smoothscroller.php

    r1249929 r3319010  
    1 <?php     namespace ng_smoothscroller;
     1<?php
     2namespace ng_smoothscroller;
    23
    34/*
     
    67Description: Smooth Scroll to internal links in WordPress
    78Author: Neil Gee
    8 Version: 1.0.0
     9Version: 1.1.0
    910Author URI: http://wpbeaches.com
    1011Text Domain: smoothscroller
     
    1617*/
    1718
    18 
    19 // If called direct, refuse
    20   if ( ! defined( 'ABSPATH' ) ) {
    21           die;
    22   }
    23 
    24 /* Assign global variables */
     19if ( ! defined( 'ABSPATH' ) ) {
     20    die;
     21}
    2522
    2623$plugin_url = WP_PLUGIN_URL . '/smoothscroller';
    2724$options = array();
    2825
    29 /**
    30  * Register our text domain.
    31  *
    32  * @since 1.0.0
    33  */
    34 
    3526function load_textdomain() {
    36   load_plugin_textdomain( 'smoothscroller', false, basename( dirname( __FILE__ ) ) . '/languages' );
     27    load_plugin_textdomain( 'smoothscroller', false, basename( dirname( __FILE__ ) ) . '/languages' );
    3728}
    3829add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_textdomain' );
    3930
    40 /**
    41  * Register and Enqueue Scripts and Styles
    42  *
    43  * @since 1.0.0
    44  */
     31function scripts_styles() {
     32    $options = get_option( 'smoothscroller_settings' );
    4533
    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    );
    5139
    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 );
    5544
    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    };
    5850
    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'] ?? '' ) ) );
    6056
    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();
    10162    }
    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 integer
    118 
    119       ),
    120   );
    121 
    122     // Pass PHP variables to jQuery script
    123     wp_localize_script( 'localscroll-init', 'scrollVars', $data );
    124 
    125     wp_enqueue_script( 'localscroll-init' );
    126     }
    127   }
    12863}
    129 
    13064add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\scripts_styles' );
    13165
    132 /**
    133  * Register our option fields
    134  *
    135  * @since 1.0.0
    136  */
     66function plugin_settings(){
     67    register_setting(
     68        'ss_settings-group',
     69        'smoothscroller_settings',
     70        __NAMESPACE__ . '\\smoothscroller_validate_input'
     71    );
    13772
    138 function plugin_settings(){
    139   register_Setting(
    140         'ss_settings-group', //option name
    141         'smoothscroller_settings',// option group setting name and option name
    142         __NAMESPACE__ . '\\smoothscroller_validate_input' //sanitize the inputs
    143   );
     73    add_settings_section(
     74        'ss_smoothscroller_section',
     75        'Smoothscroller Settings',
     76        __NAMESPACE__ . '\\ss_smoothscroller_section_callback',
     77        'smoothscroller'
     78    );
    14479
    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' );
    18785}
    18886add_action('admin_init', __NAMESPACE__ . '\\plugin_settings');
    18987
    190 /**
    191  * Sanitize our inputs
    192  *
    193  * @since 1.0.0
    194  */
    195 
    19688function smoothscroller_validate_input( $input ) {
    197   // Create our array for storing the validated options
    19889    $output = array();
    199      
    200     // Loop through each of the incoming options
    20190    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 );
    215108}
    216109
    217 function ss_smoothscroller_section_callback() {
     110function ss_smoothscroller_section_callback() {}
    218111
     112function 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>';
    219120}
    220121
    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
     122function 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>';
    244127}
    245128
    246 /**
    247  * Register All Pages have scroll option
    248  *
    249  * @since 1.0.0
    250  */
    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 option
    263  *
    264  * @since 1.0.0
    265  */
    266 
    267129function 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}
    281135
    282136function 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>';
    290141}
    291142
    292 /**
    293  * Register Some Posts have scroll option
    294  *
    295  * @since 1.0.0
    296  */
    297 
    298143function 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>';
    306148}
    307149
    308 /**
    309  * Create the plugin option page.
    310  *
    311  * @since 1.0.0
    312  */
    313 
    314150function 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    );
    328158}
    329159add_action( 'admin_menu', __NAMESPACE__ . '\\plugin_page' );
    330160
    331 /**
    332  * Include the plugin option page.
    333  *
    334  * @since 1.0.0
    335  */
    336 
    337161function plugin_options_page() {
    338 
    339162    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'" );
    342164    }
    343 
    344    require( 'inc/options-page-wrapper.php' );
     165    require( 'inc/options-page-wrapper.php' );
    345166}
Note: See TracChangeset for help on using the changeset viewer.