Plugin Directory

Changeset 1050049


Ignore:
Timestamp:
12/20/2014 06:34:28 AM (11 years ago)
Author:
joesat
Message:

1.0.0.6

  • now really working for multisite install :)
Location:
wp-version-in-query-string-modifier/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-version-in-query-string-modifier/trunk/readme.txt

    r1046678 r1050049  
    11=== WP Version in Query String Modifier ===
    22Contributors: joesat
    3 Tags: query string, remove query string, remove version, version
     3Tags: query string, remove query string, remove version, version, optimization, url, link
    44Requires at least: 3.9.3
    5 Tested up to: 4.0
    6 Stable tag: 1.0.0.5
     5Tested up to: 4.1
     6Stable tag: 1.0.0.6
    77License: GPL2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1111
    1212== Description ==
    13 Removes or modifies the version (query string 'ver' parameter) in media resources' url.
    14 
    1513Depending on your needs, this plugin is useful for:
    1614
     
    5856== Changelog ==
    5957
     58= 1.0.0.6 =
     59* now really working for multisite install :)
     60
    6061= 1.0.0.5 =
    6162* yet another update to readme.txt
  • wp-version-in-query-string-modifier/trunk/wp-version-in-query-string-modifier.php

    r1046678 r1050049  
    88* option to disable modifying the url without disabling the plugin
    99Author: joesat
    10 Version: 1.0.0.5
     10Version: 1.0.0.6
    1111Author URI: ttps://wordpress.org/plugins/
    1212License: GPL2
     
    1919define( 'WPVQSM_TMPL_DIR', dirname(__FILE__) . '/tmpl/' );
    2020
    21 /** plugin constants */
     21/** plugin name constants */
     22define( 'WPVQSM_LONG_NAME', 'WP Version in Query String Modifier' );
    2223define( 'WPVQSM_SHORT_NAME', 'WP Version Modifier' );
     24
     25/**
     26 * fetch plugin options from DB   
     27 *
     28 * @since 1.6
     29 *
     30 * @return array            array list of plugin options, or return default values when not found       
     31 */
     32function wpvqsm_get_options() {
     33    $wpvqsm_default_values = array(
     34        'selection' => 'i',
     35        'increment' => '7',
     36    );
     37    return get_option( WPVQSM . 'options', $wpvqsm_default_values );
     38}
     39
     40/**
     41 * update plugin option
     42 *
     43 * @since 1.6
     44 *
     45 */
     46function wpvqsm_update_options( $options ) {
     47    update_option( WPVQSM . 'options', $options );
     48}
    2349
    2450/**
     
    3157 */
    3258function wpvqsm_modify_version( $src ) {
    33     $options = get_option( WPVQSM . 'options' );
    34     // override the ver param with our new value
    35     $src = add_query_arg('ver', str_pad( $options['increment'], 3, '0', STR_PAD_LEFT ) , $src);
    36     return $src;
    37 }
    38 
    39 /**
    40  * Removes query string from uri using WP utility remove_query_arg
    41  *
    42  * @since 1.0
    43  *
    44  * @param string $src       the target uri to format
    45  * @return string           Formatted uri without the ver query string parameter
    46  */
    47 function wpvqsm_remove_version( $src ) {
    48     $src = remove_query_arg('ver', $src);
    49     return $src;
    50 }
    51 
     59    $options = wpvqsm_get_options();
     60    if ('i' === $options['selection']) {
     61        // override the ver param with our new value
     62        return add_query_arg('ver', str_pad( $options['increment'], 3, '0', STR_PAD_LEFT ) , $src);
     63    }
     64    else if ('r' === $options['selection']) {
     65        // remove ver in the query string
     66        $src = remove_query_arg('ver', $src);
     67        return $src;
     68    }
     69    else {
     70        // do nothing
     71    }
     72}
    5273
    5374/**
     
    5879 */
    5980function wpvqsm_menu() {
    60     add_options_page( WPVQSM_SHORT_NAME . ' Options', WPVQSM_SHORT_NAME, 'manage_options', WPVQSM, WPVQSM . 'options' );
     81    add_options_page( WPVQSM_SHORT_NAME . ' Options', WPVQSM_SHORT_NAME, 'manage_options', WPVQSM, WPVQSM . 'options' );
    6182}
    6283
     
    80101 */
    81102function wpvqsm_options() {
    82     if ( !current_user_can( 'manage_options' ) )  {
    83         wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    84     }
     103    if ( !current_user_can( 'manage_options' ) )  {
     104        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
     105    }
    85106   
    86107    // fetch options
    87     $options = get_option( WPVQSM . 'options' );
     108    $options = wpvqsm_get_options();
    88109   
    89110    // template variable
     
    102123function wpvqsm_update_callback() {
    103124    if ( !current_user_can( 'manage_options' ) )  {
    104         wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    105     }
    106     $options = get_option( WPVQSM . 'options' );
     125        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
     126    }
     127    $options = wpvqsm_get_options();
    107128    $options['selection'] = $_POST['selection'];
    108     update_option( WPVQSM . 'options', $options );
     129    wpvqsm_update_options( $options );
    109130    wp_safe_redirect( 'options-general.php?settings-updated=true&page=' . WPVQSM );
    110131}
     
    118139function wpvqsm_ajax_callback() {
    119140    if ( !current_user_can( 'manage_options' ) )  {
    120         die( 1 );
    121     }
     141        die( 1 );
     142    }
    122143    ob_start ();
    123144    global $wpdb;
    124145    // no use for now but might be useful later
    125     //$action = $_POST['action'] ;   
     146    //$action = $_POST['action'] ;   
    126147   
    127148    // get plugin option and update
    128     $options = get_option( WPVQSM . 'options' );
     149    $options = wpvqsm_get_options();
    129150    ++$options['increment'];
    130     update_option( WPVQSM . 'options', $options );
     151    wpvqsm_update_options( $options );
    131152    ob_end_clean ();
    132     echo str_pad( $options['increment'], 3, '0', STR_PAD_LEFT );
     153    echo str_pad( $options['increment'], 3, '0', STR_PAD_LEFT );
    133154    die( 1 );
    134155}
     
    141162 */
    142163function wpvqsm_activate() {
    143     $default_values = array(
     164    $wpvqsm_default_values = array(
    144165        'selection' => 'i',
    145166        'increment' => '7',
    146167    );
    147     update_option( WPVQSM . 'options', $default_values );
     168
     169    if ( !is_multisite() ) {
     170        add_option( WPVQSM . 'options', $wpvqsm_default_values );
     171    }
     172    else {
     173        global $wpdb;
     174        $blog_ids = $wpdb->get_col( 'SELECT blog_id FROM ' . $wpdb->blogs );
     175        foreach ($blog_ids as $blog_id) {
     176            switch_to_blog($blog_id);
     177            add_option( WPVQSM . 'options', $wpvqsm_default_values );
     178        }
     179        restore_current_blog(); 
     180    }
    148181}
    149182
     
    154187 *
    155188 */
    156 function wpvqsm_deactivate() {
    157     delete_option( WPVQSM . 'options' );
    158 }
    159 
    160 $options = get_option( WPVQSM . 'options' );
    161 
    162 // add callback function filter to js and css loaders
    163 // depending on chosen option
    164 if ('i' === $options['selection']) {
    165     // modify version to option index
    166     add_filter( 'script_loader_src', WPVQSM. 'modify_version' );
    167     add_filter( 'style_loader_src', WPVQSM. 'modify_version' );
    168 }
    169 else if ('r' === $options['selection']) {
    170     // remove version
    171     add_filter( 'script_loader_src', WPVQSM. 'remove_version' );
    172     add_filter( 'style_loader_src', WPVQSM. 'remove_version' );
    173 }
    174 else {
    175     // do nothing, as if plugin is disabled
     189function wpvqsm_deactivate() {   
     190    if ( !is_multisite() ) {
     191        delete_option( WPVQSM . 'options' );
     192    }
     193    else {
     194        global $wpdb;
     195        $blog_ids = $wpdb->get_col( 'SELECT blog_id FROM ' . $wpdb->blogs );
     196        foreach ($blog_ids as $blog_id) {
     197            switch_to_blog($blog_id);
     198            delete_option( WPVQSM . 'options' );
     199        }
     200        restore_current_blog(); 
     201    }
    176202}
    177203
     
    188214    add_filter( 'plugin_action_links_' . $plugin, WPVQSM . 'settings_link' );
    189215}
     216
     217add_filter( 'script_loader_src', WPVQSM. 'modify_version' );
     218add_filter( 'style_loader_src', WPVQSM. 'modify_version' );   
Note: See TracChangeset for help on using the changeset viewer.