Changeset 1050049
- Timestamp:
- 12/20/2014 06:34:28 AM (11 years ago)
- Location:
- wp-version-in-query-string-modifier/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
wp-version-in-query-string-modifier.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-version-in-query-string-modifier/trunk/readme.txt
r1046678 r1050049 1 1 === WP Version in Query String Modifier === 2 2 Contributors: joesat 3 Tags: query string, remove query string, remove version, version 3 Tags: query string, remove query string, remove version, version, optimization, url, link 4 4 Requires at least: 3.9.3 5 Tested up to: 4. 06 Stable tag: 1.0.0. 55 Tested up to: 4.1 6 Stable tag: 1.0.0.6 7 7 License: GPL2 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 11 11 12 12 == Description == 13 Removes or modifies the version (query string 'ver' parameter) in media resources' url.14 15 13 Depending on your needs, this plugin is useful for: 16 14 … … 58 56 == Changelog == 59 57 58 = 1.0.0.6 = 59 * now really working for multisite install :) 60 60 61 = 1.0.0.5 = 61 62 * yet another update to readme.txt -
wp-version-in-query-string-modifier/trunk/wp-version-in-query-string-modifier.php
r1046678 r1050049 8 8 * option to disable modifying the url without disabling the plugin 9 9 Author: joesat 10 Version: 1.0.0. 510 Version: 1.0.0.6 11 11 Author URI: ttps://wordpress.org/plugins/ 12 12 License: GPL2 … … 19 19 define( 'WPVQSM_TMPL_DIR', dirname(__FILE__) . '/tmpl/' ); 20 20 21 /** plugin constants */ 21 /** plugin name constants */ 22 define( 'WPVQSM_LONG_NAME', 'WP Version in Query String Modifier' ); 22 23 define( '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 */ 32 function 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 */ 46 function wpvqsm_update_options( $options ) { 47 update_option( WPVQSM . 'options', $options ); 48 } 23 49 24 50 /** … … 31 57 */ 32 58 function 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 } 52 73 53 74 /** … … 58 79 */ 59 80 function 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' ); 61 82 } 62 83 … … 80 101 */ 81 102 function 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 } 85 106 86 107 // fetch options 87 $options = get_option( WPVQSM . 'options');108 $options = wpvqsm_get_options(); 88 109 89 110 // template variable … … 102 123 function wpvqsm_update_callback() { 103 124 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(); 107 128 $options['selection'] = $_POST['selection']; 108 update_option( WPVQSM . 'options',$options );129 wpvqsm_update_options( $options ); 109 130 wp_safe_redirect( 'options-general.php?settings-updated=true&page=' . WPVQSM ); 110 131 } … … 118 139 function wpvqsm_ajax_callback() { 119 140 if ( !current_user_can( 'manage_options' ) ) { 120 die( 1 );121 }141 die( 1 ); 142 } 122 143 ob_start (); 123 144 global $wpdb; 124 145 // no use for now but might be useful later 125 //$action = $_POST['action'] ;146 //$action = $_POST['action'] ; 126 147 127 148 // get plugin option and update 128 $options = get_option( WPVQSM . 'options');149 $options = wpvqsm_get_options(); 129 150 ++$options['increment']; 130 update_option( WPVQSM . 'options',$options );151 wpvqsm_update_options( $options ); 131 152 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 ); 133 154 die( 1 ); 134 155 } … … 141 162 */ 142 163 function wpvqsm_activate() { 143 $ default_values = array(164 $wpvqsm_default_values = array( 144 165 'selection' => 'i', 145 166 'increment' => '7', 146 167 ); 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 } 148 181 } 149 182 … … 154 187 * 155 188 */ 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 189 function 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 } 176 202 } 177 203 … … 188 214 add_filter( 'plugin_action_links_' . $plugin, WPVQSM . 'settings_link' ); 189 215 } 216 217 add_filter( 'script_loader_src', WPVQSM. 'modify_version' ); 218 add_filter( 'style_loader_src', WPVQSM. 'modify_version' );
Note: See TracChangeset
for help on using the changeset viewer.