Changeset 1440619
- Timestamp:
- 06/21/2016 04:38:59 AM (10 years ago)
- Location:
- protect-version-controlled-updates
- Files:
-
- 4 added
- 16 edited
- 1 copied
-
assets/screenshot-1.png (added)
-
assets/screenshot-2.png (added)
-
assets/screenshot-3.png (added)
-
assets/screenshot-4.png (added)
-
tags/1.1.0 (copied) (copied from protect-version-controlled-updates/trunk)
-
tags/1.1.0/assets/js/pvcu.js (modified) (1 diff)
-
tags/1.1.0/pvcu-activation.php (modified) (1 diff)
-
tags/1.1.0/pvcu-general.php (modified) (4 diffs)
-
tags/1.1.0/pvcu-main.php (modified) (1 diff)
-
tags/1.1.0/pvcu-modal-output.php (modified) (2 diffs)
-
tags/1.1.0/pvcu-options-page.php (modified) (7 diffs)
-
tags/1.1.0/pvcu-scripts.php (modified) (1 diff)
-
tags/1.1.0/readme.txt (modified) (3 diffs)
-
trunk/assets/js/pvcu.js (modified) (1 diff)
-
trunk/pvcu-activation.php (modified) (1 diff)
-
trunk/pvcu-general.php (modified) (4 diffs)
-
trunk/pvcu-main.php (modified) (1 diff)
-
trunk/pvcu-modal-output.php (modified) (2 diffs)
-
trunk/pvcu-options-page.php (modified) (7 diffs)
-
trunk/pvcu-scripts.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
protect-version-controlled-updates/tags/1.1.0/assets/js/pvcu.js
r1429558 r1440619 3 3 $( 'a.update-link' ).addClass( 'update-link-disabled' ).removeClass( 'update-link' ); 4 4 5 // Intercept the update link on the plugins page (plugins.php) 5 6 $( 'a.update-link-disabled' ).click( function( e ) { 6 7 e.preventDefault(); 7 8 var updateLink = $(this).attr( 'href' ); 8 console.log( updateLink ); 9 $( '#pvcuModal' ).modal(); 10 $( '#pvcuModal #update' ).attr( 'href', updateLink ); 9 $( '#pvcuModal-plugins' ).modal(); 10 $( '#pvcuModal-plugins #update' ).click( function ( e2 ) { 11 window.location=updateLink; 12 return false; 13 }); 11 14 }); 15 16 // Intercept the bulk update form on the plugins page (plugins.php) 17 // If #pvcuModal-plugins hasn't been injected, that means protection is not enabled, so do nothing. 18 if( $( '#pvcuModal-plugins' ).length ) { 19 console.log( 'running' ); 20 $( 'form#bulk-action-form' ).submit( function( e, submit ) { 21 var bulkActionOption = $( this ).find( 'select' ).val(); 22 if( bulkActionOption == 'update-selected' ) { 23 if( ! submit ) { 24 e.preventDefault(); 25 $( '#pvcuModal-plugins' ).modal(); 26 } 27 28 } 29 }); 30 31 $( '#pvcuModal-plugins #update' ).click( function() { 32 $( 'form#bulk-action-form' ).trigger( 'submit', [true] ); 33 }); 34 } 35 36 // Intercept the update link on the Theme Details page (themes.php) 37 // TBD 38 39 // Intercept the core update submit button on update-core.php. 40 // Uncomment when able to stop core updates. 41 // If #pvcuModal-core hasn't been injected, that means protection is not enabled, so do nothing. 42 // if( $( '#pvcuModal-core' ).length ) { 43 // $( 'form[name="upgrade"]' ).submit( function( e, submit ) { 44 // if( ! submit ) { 45 // e.preventDefault(); 46 // $( '#pvcuModal-core' ).modal(); 47 // } 48 // }); 49 50 // $( '#pvcuModal-core #update' ).click( function() { 51 // $( 'form[name="upgrade"]' ).trigger( 'submit', [true] ); 52 // }); 53 // } 54 55 // Intercept the plugins update submit button on update-core.php 56 // If #pvcuModal-plugins hasn't been injected, that means protection is not enabled, so do nothing. 57 if( $( '#pvcuModal-plugins' ).length ) { 58 $( 'form[name="upgrade-plugins"]' ).submit( function( e, submit ) { 59 if( ! submit ) { 60 e.preventDefault(); 61 $( '#pvcuModal-plugins' ).modal(); 62 } 63 }); 64 65 $( '#pvcuModal-plugins #update' ).click( function() { 66 $( 'form[name="upgrade-plugins"]' ).trigger( 'submit', [true] ); 67 }); 68 } 69 70 // Intercept the themes update submit button on update-core.php 71 // If #pvcuModal-themes hasn't been injected, that means protection is not enabled, so do nothing. 72 if( $( '#pvcuModal-themes' ).length ) { 73 $( 'form[name="upgrade-themes"]' ).submit( function( e, submit ) { 74 if( ! submit ) { 75 e.preventDefault(); 76 $( '#pvcuModal-themes' ).modal(); 77 } 78 }); 79 80 $( '#pvcuModal-themes #update' ).click( function() { 81 $( 'form[name="upgrade-themes"]' ).trigger( 'submit', [true] ); 82 }); 83 } 84 12 85 })( jQuery ); -
protect-version-controlled-updates/tags/1.1.0/pvcu-activation.php
r1429558 r1440619 1 1 <?php 2 2 3 /* 4 * This function uses the output of pvcu_find_version_control() 5 * to set options in the options table upon plugin activation. 6 * 7 * @uses pvcu_find_version_control To find what components have VC'ed folders 8 * 9 * @param void 10 * @return void 11 */ 12 3 13 function pvcu_activation() { 4 // Find out if there's a .git folder somewhere14 // Find out if there's a .git or .svn folder somewhere 5 15 $vc_files_found = pvcu_find_version_control(); 16 add_option( 'pvcu_return', $vc_files_found ); 6 17 7 18 // Create an array of option values 8 19 $pvcu_options_array = array(); 9 20 10 $pvcu_options_array[ 'pvcu_enabled' ] = $vc_files_found; 11 $pvcu_options_array[ 'pvcu_warn_or_block' ] = 'warn'; 12 $pvcu_options_array[ 'pvcu_modal_title' ] = ''; 13 $pvcu_options_array[ 'pvcu_modal_content' ] = ''; 21 if( $vc_files_found[ 'plugins' ] === true ) { 22 $pvcu_options_array[ 'pvcu_plugins_action' ] = 'warn'; 23 } else { 24 $pvcu_options_array[ 'pvcu_plugins_action' ] = 'none'; 25 } 26 27 if( $vc_files_found[ 'themes' ] === true ) { 28 $pvcu_options_array[ 'pvcu_themes_action' ] = 'warn'; 29 } else { 30 $pvcu_options_array[ 'pvcu_themes_action' ] = 'none'; 31 } 32 33 // Uncomment when able to stop core updates. 34 35 // if( $vc_files_found[ 'core' ] === true ) { 36 // $pvcu_options_array[ 'pvcu_core_action' ] = 'warn'; 37 // } else { 38 // $pvcu_options_array[ 'pvcu_core_action' ] = 'none'; 39 // } 40 41 $pvcu_options_array[ 'pvcu_modal_title' ] = 'Update Warning'; 42 $pvcu_options_array[ 'pvcu_modal_content' ] = 'Are you sure you want to update this item? Please check with your web development company before doing so.'; 14 43 15 44 add_option( 'pvcu_settings', $pvcu_options_array, '', FALSE ); -
protect-version-controlled-updates/tags/1.1.0/pvcu-general.php
r1429558 r1440619 4 4 * This function will be part of the activation process. 5 5 * It looks through the file system at specific likely 6 * points, looking for .git folders or files. If present,6 * points, looking for .git or .svn folders or files. If present, 7 7 * it returns true so that the protection is turned on 8 8 * automatically. 9 9 * 10 * @todo Search for SVN-related files as well. 10 * @uses pvcu_is_version_controlled() Tests for the existence of 11 * .git or .svn folders. 12 * 13 * @param void 14 * @return array An array of the things to protect by default, 15 * based off of existence of .git or .svn folders. 16 * 11 17 */ 12 18 13 19 function pvcu_find_version_control() { 14 $vc_files_found = false; 15 $folders_to_check = array(); 20 $vc_controlled_paths = array(); 21 $plugins_dir_path = ''; 22 $themes_dir_path = ''; 23 $current_theme_path = ''; 24 $parent_theme_path = ''; 16 25 17 26 // Clear the built-in PHP file caching 18 27 clearstatcache(); 19 28 20 /* 21 * Get an array of server paths to check. There are a 22 * plethora of functions to get *URL's*, but very few that 23 * get server paths. As a result, some of these are a 24 * little convoluted. 29 // Set the defaults for the $vc_controlled_paths array 30 $vc_controlled_paths[ 'plugins' ] = false; 31 $vc_controlled_paths[ 'themes' ] = false; 32 // Uncomment when able to stop core updates. 33 // $vc_controlled_paths[ 'core' ] = false; 34 35 36 /* 37 * Check numerous server paths for .git or .svn folders. 38 * There are a plethora of functions to get *URL's*, but 39 * fewer that get server paths. As a result, some of 40 * these are a little convoluted. 41 * 42 * For these paths, we're going to set the appropriate flag 43 * in $vc_controlled_paths - choices are 'plugins', 44 * 'themes', and 'core' - depending on the path. 25 45 */ 26 46 27 47 /* 28 48 * Sometimes the whole site is version-controlled, so look 29 * in the root. 49 * in the root. If true, set all three flags. 30 50 */ 31 51 … … 33 53 include_once( ABSPATH . 'wp-admin/includes/file.php' ); 34 54 35 $folders_to_check[ 'root' ] = get_home_path(); 36 37 /* 38 * Sometimes only the wp-content folder is VC'ed 55 if( pvcu_is_version_controlled( get_home_path() ) ) { 56 $vc_controlled_paths[ 'plugins' ] = true; 57 $vc_controlled_paths[ 'themes' ] = true; 58 // Uncomment when able to stop core updates. 59 // $vc_controlled_paths[ 'core' ] = true; 60 }; 61 62 /* 63 * Sometimes only the wp-content folder is VC'ed. If so, set 64 * 'plugins' and 'themes' flag. 39 65 * 40 * @todo Using WP constants is frowned upon, find a 41 * better way. 42 */ 43 $folders_to_check[ 'wp_content' ] = WP_CONTENT_DIR; 66 * @todo Using WP constants is frowned upon, find a better way. 67 */ 68 69 if( pvcu_is_version_controlled( WP_CONTENT_DIR ) ) { 70 $vc_controlled_paths[ 'plugins' ] = true; 71 $vc_controlled_paths[ 'themes' ] = true; 72 }; 44 73 45 74 // Sometimes it's only the plugins or themes folders … … 47 76 /* 48 77 * Find the parent directory of this plugin to determine 49 * the path to the plugins directory. 50 * 51 * @todo: Make this MU friendly. 52 */ 53 54 $folders_to_check[ 'plugins' ] = dirname( plugin_dir_path( __FILE__ ) ); 55 56 // Find the parent directory of the stylesheet path 57 $folders_to_check[ 'all_themes' ] = dirname( get_stylesheet_directory() ); 78 * the path to the plugins directory. If this returns 79 * true, set 'plugins' flag. 80 */ 81 82 $plugins_dir_path = dirname( dirname( plugin_dir_path( __FILE__ ) ) ); 83 if( pvcu_is_version_controlled( $plugins_dir_path ) ) { 84 $vc_controlled_paths[ 'plugins' ] = true; 85 }; 86 87 /* 88 * If $plugins_dir_path isn't equal to WP_PLUGIN_DIR, 89 * that means that this plugin is in the mu-plugins 90 * directory. The test above checked the mu-plugins 91 * folder already, so let's check WP_PLUGIN_DIR, and 92 * set the 'plugins' flag if true. 93 * 94 * @todo Using WP constants is frowned upon, find a better way. 95 */ 96 97 if( pvcu_is_version_controlled( WP_PLUGIN_DIR ) ) { 98 $vc_controlled_paths[ 'plugins' ] = true; 99 }; 100 101 /* 102 * Find the parent directory of the stylesheet path to 103 * determine the path to the themes directory. If this 104 * returns true, set 'themes' flag. 105 */ 106 107 $themes_dir_path = dirname( get_stylesheet_directory() ); 108 109 if( pvcu_is_version_controlled( $themes_dir_path ) ) { 110 $vc_controlled_paths[ 'themes' ] = true; 111 }; 58 112 59 113 // And (very rarely) it's just the theme that's VC'ed. 60 114 61 // Find the stylesheet path 62 $folders_to_check[ 'current_theme' ] = get_stylesheet_directory(); 63 64 // If this is a child theme, find the parent's directory 65 if( get_stylesheet_directory() != get_template_directory() ) { 66 $folders_to_check[ 'parent_theme' ] = get_template_directory(); 115 /* 116 * Find the stylesheet paths. If the theme is VC'ed, there's 117 * probably a parent and child theme. I can't see why the 118 * parent would be VC'ed but not the child, but let's check 119 * both just to be safe. Set the 'themes' flag if either 120 * is true. 121 */ 122 123 $current_theme_path = get_stylesheet_directory(); 124 $parent_theme_path = get_template_directory(); 125 126 if( pvcu_is_version_controlled( $current_theme_path ) || pvcu_is_version_controlled( $parent_theme_path ) ) { 127 $vc_controlled_paths[ 'themes' ] = true; 67 128 } 68 129 69 130 // Didn't I warn you that some of those were convoluted? 70 131 71 /* 72 * For each of the paths in our array, check to see if 73 * there's a .git folder in that path. 74 */ 75 76 foreach( $folders_to_check as $folder ) { 77 if( file_exists( $folder . '/.git' ) ) { 78 $vc_files_found = true; 79 } 132 return $vc_controlled_paths; 133 134 } 135 136 function pvcu_is_version_controlled( $path ) { 137 138 /* 139 * Check the path, see if there's a VC-ed folder in that path, and set 140 * the appropriate flag if there is. 141 * 142 * @param string $path The path to check for a VC folder 143 * @return bool Whether there's a VC folder in $path. 144 */ 145 146 $vc_files_found = false; 147 148 if( file_exists( $path . '/.git' ) || file_exists( $path . '/.svn' ) ) { 149 $vc_files_found = true; 80 150 } 81 151 … … 87 157 * be loaded on a page. 88 158 * 159 * @uses pvcu_get_current_screen() Gets the base of the current screen. 160 * @uses pvcu_get_current_screen_relevant_option Gets the relevant option 161 * based on current base. 162 * 163 * 89 164 * @param void 90 * @return bool Whether this page is one of the types of pages 91 * being protected. 92 */ 93 94 function pvcu_protect_this_page() { 95 // Bail if protection is disabled from the options screen 96 $pvcu_settings = get_option( 'pvcu_settings' ); 165 * @return bool Should this page have scripts and modals loaded on it? 166 */ 167 168 function pvcu_load_assets() { 169 $full_options = ''; 170 $current_screen = ''; 171 $protected_screens = array(); 172 $current_screen_settings = ''; 173 $current_screen_option = array(); 174 $load_assets = ''; 175 176 // Get the current screen base 177 $current_screen = pvcu_get_current_screen(); 97 178 98 if( $pvcu_settings[ 'pvcu_enabled' ] !== '1' ) { 99 return false; 100 } 101 179 $protected_screens = array( 'plugins', 'plugin-install', 'themes', 'update-core', ); 180 181 // Add or unset protected screens from the array if desired. 182 $protected_screens = apply_filters( 'pvcu_protected_screens', $protected_screens ); 183 184 /* 185 * Check to see if the current screen is one of the ones which should be protected. 186 * If so, grab the option setting which corresponds to this type of page. If it's 187 * set to 'none,' return false, but otherwise, return true. 188 */ 189 if( in_array( $current_screen, $protected_screens ) ) { 190 $load_assets = false; 191 $full_options = get_option( 'pvcu_settings' ); 192 $current_screen_option_name = pvcu_get_current_screen_relevant_option( $current_screen ); 193 194 foreach( $current_screen_option_name as $single_option ) { 195 if( $single_option != 'none' ) { 196 $load_assets = true; 197 } 198 } 199 return $load_assets; 200 } else { 201 return false; // This page isn't protected, don't load scripts or modal. 202 } 203 } 204 205 /* 206 * Gets the current screen base. 207 * 208 * @param void 209 * @return string The base of the current screen 210 */ 211 212 function pvcu_get_current_screen() { 102 213 $current_screen_object = new stdClass(); 103 214 $current_screen = ''; 104 $protected_screens = array(); 105 215 216 // Get the base of the screen we're looking at. 106 217 $current_screen_object = get_current_screen(); 107 218 $current_screen = $current_screen_object->base; 108 $protected_screens = array( 'plugins', 'plugin-install' ); 109 $protected_screens = apply_filters( 'pvcu_protected_screens', $protected_screens ); 110 111 if( in_array( $current_screen, $protected_screens ) ) { 112 return true; 219 220 return $current_screen; 221 } 222 223 /* 224 * Given the base of a screen, this will return the name of the relevant 225 * PVCU option. Note that this doesn't return the *value* of the option, 226 * just the key name to check in the option. 227 * 228 * @param string Current screen base 229 * @return mixed Array (one $key=>$value pair) with the relevant setting 230 * from the pvcu_settings option array, array (three pairs) 231 * of all options if we're on the 'update-core' page, or 232 * null if the base doesn't have a corresponding option value. 233 */ 234 235 function pvcu_get_current_screen_relevant_option( $base ) { 236 $screen_to_option_name = array(); 237 $option_name = ''; 238 239 /* 240 * For the 'update-core' page, we need to return an array 241 * of all three choices, since all three can be on the 242 * page. 243 */ 244 245 $screen_to_option_name = array( 246 'plugins' => array( 'plugins' => 'pvcu_plugins_action' ), 247 'plugin-install' => array( 'plugins' => 'pvcu_plugins_action' ), 248 'themes' => array( 'themes' => 'pvcu_themes_action' ), 249 'update-core' => array( 250 'plugins' => 'pvcu_plugins_action', 251 'themes' => 'pvcu_themes_action', 252 // Uncomment when able to stop core updates. 253 // 'core' => 'pvcu_core_action', 254 ), 255 ); 256 257 /* 258 * Here's a chance to modify the array, in case new screens were added 259 * to the protected screens array using the pvcu_protected_screens 260 * filter. 261 */ 262 263 $screen_to_option_name = apply_filters( 'pvcu_screen_to_option_name', $screen_to_option_name ); 264 265 // Find the value of $base in this array 266 if( isset( $screen_to_option_name[ $base ] ) ) { 267 return $screen_to_option_name[ $base ]; 113 268 } else { 114 return false;115 } 116 } 269 return null; 270 } 271 } -
protect-version-controlled-updates/tags/1.1.0/pvcu-main.php
r1429558 r1440619 4 4 Plugin URI: https://wordpress.org/plugins/protect-version-controlled-updates/ 5 5 Description: This plugin is for version-controlled websites. Depending on the settings, users attempting to update plugins will either get a popup asking for confirmation or will be totally prevented from updating. 6 Version: 1. 0.06 Version: 1.1.0 7 7 Author: Shiny 9 Web Design 8 8 Author URI: http://www.shiny9web.com -
protect-version-controlled-updates/tags/1.1.0/pvcu-modal-output.php
r1429558 r1440619 1 1 <?php 2 2 3 // The modal popup 3 /* 4 * Generates the modal popup. 5 * 6 * @uses get_option Gets the value of the plugin option 7 * @uses pvcu_get_current_screen Gets the base for the current screen 8 * @uses pvcu_get_current_screen_relevant_option Gets the key for the needed value for this screen 9 * 10 * @param void 11 * @return string HTML for the popup. 12 */ 4 13 5 14 function pvcu_modal_output() { 6 $pvcu_settings = ''; 7 $pvcu_update_action = ''; 8 $pvcu_modal_title = ''; 9 $pvcu_modal_content = ''; 15 $full_settings = ''; 16 $current_screen = ''; 17 $current_screen_key = ''; 18 $current_screen_action = ''; 19 $modal_title = ''; 20 $modal_content = ''; 10 21 11 $pvcu_settings = get_option( 'pvcu_settings' ); 22 $full_settings = get_option( 'pvcu_settings' ); 23 $current_screen = pvcu_get_current_screen(); 24 $current_screen_option = pvcu_get_current_screen_relevant_option( $current_screen ); 25 $modal_title = $full_settings[ 'pvcu_modal_title' ]; 26 $modal_content = $full_settings[ 'pvcu_modal_content' ]; 12 27 13 $pvcu_update_action = $pvcu_settings[ 'pvcu_warn_or_block' ]; 14 $pvcu_modal_title = $pvcu_settings[ 'pvcu_modal_title' ]; 15 $pvcu_modal_content = $pvcu_settings[ 'pvcu_modal_content' ]; 28 ob_start(); 29 foreach( $current_screen_option as $key => $value ) { 30 $option_value = $full_settings[ $value ]; 31 32 // Don't generate a modal if the option is set to 'none' 33 if( $option_value == 'none' ) { 34 continue; 35 } 36 37 ?> 38 <div id="pvcuModal-<?php echo $key; ?>" class="modal hide fade" tabindex="-1" > 39 <div class="modal-header"> 40 <h3><?php echo $modal_title; ?></h3> 41 </div> 42 <div class="modal-body"> 43 <?php echo apply_filters( 'the_content', $modal_content ); ?> 44 </div> 45 <div class="modal-footer"> 46 <button id="dismiss" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 47 <?php if( $option_value != 'block' ) { ?> 48 <button id="update" class="btn btn-primary" data-confirm="true" aria-hidden="false" >Update</button> 49 <?php } ?> 50 </div> 51 </div> 52 <?php 53 } // End foreach 54 $output = ob_get_clean(); 55 apply_filters( 'pvcu_output', $output ); 16 56 17 ob_start(); ?> 18 <div id="pvcuModal" class="modal hide fade" tabindex="-1" > 19 <div class="modal-header"> 20 <h3><?php echo $pvcu_modal_title; ?></h3> 21 </div> 22 <div class="modal-body"> 23 <?php echo apply_filters( 'the_content', $pvcu_modal_content ); ?> 24 </div> 25 <div class="modal-footer"> 26 <button id="dismiss" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 27 <?php if( $pvcu_update_action != 'block' ) { ?> 28 <a id="update" class="btn btn-primary" data-confirm="true" aria-hidden="false" >Update</a> 29 <?php } ?> 30 </div> 31 </div> 32 <?php 33 $pvcu_output = ob_get_clean(); 34 apply_filters( 'pvcu_output', $pvcu_output ); 57 return $output; 58 } 35 59 36 return $pvcu_output; 37 } 60 /* 61 * Inject the modal HTML into the admin page. 62 * 63 * @uses pvcu_load_assets Determines if the modal should be 64 * injected into this page. 65 * 66 * @param void 67 * @return string Echoes the HTML 68 */ 38 69 39 70 function pvcu_modal_action() { 40 71 /* 41 72 * We only want the modal injected on pages we've 42 * designated, and only if the option is turned on 43 * through the options page. 73 * designated. 44 74 */ 45 75 46 if( ! pvcu_ protect_this_page() ) {76 if( ! pvcu_load_assets() ) { 47 77 return; 48 78 }; … … 51 81 } 52 82 53 add_action( 'admin_ print_footer_scripts', 'pvcu_modal_action' );83 add_action( 'admin_head', 'pvcu_modal_action' ); -
protect-version-controlled-updates/tags/1.1.0/pvcu-options-page.php
r1429558 r1440619 24 24 25 25 add_settings_section( 26 'pvcu_pluginPage_section', 27 '', 28 // __( 'General Settings', 'pvcu' ), 29 'pvcu_settings_section_callback', 26 'pvcu_plugin_action_settings', 27 'Action Settings', 28 'pvcu_plugin_action_callback', 30 29 'pluginPage' 31 30 ); 32 31 33 32 add_settings_field( 34 'pvcu_ enabled',35 __( ' Manually enable/disable protection', 'pvcu' ),36 'pvcu_ enabled_render',33 'pvcu_plugins_action', 34 __( 'Plugins Action', 'pvcu' ), 35 'pvcu_plugins_action_render', 37 36 'pluginPage', 38 'pvcu_plugin Page_section'37 'pvcu_plugin_action_settings' 39 38 ); 40 39 41 40 add_settings_field( 42 'pvcu_ warn_or_block',43 __( ' Warn before updating, or block entirely', 'pvcu' ),44 'pvcu_ warn_or_block_render',41 'pvcu_themes_action', 42 __( 'Themes Action', 'pvcu' ), 43 'pvcu_themes_action_render', 45 44 'pluginPage', 46 'pvcu_pluginPage_section' 45 'pvcu_plugin_action_settings' 46 ); 47 48 // Uncomment when able to stop core updates. 49 50 // add_settings_field( 51 // 'pvcu_core_action', 52 // __( 'Core Action', 'pvcu' ), 53 // 'pvcu_core_action_render', 54 // 'pluginPage', 55 // 'pvcu_plugin_action_settings' 56 // ); 57 58 add_settings_section( 59 'pvcu_plugin_modal_settings', 60 'Modal Settings', 61 'pvcu_plugin_modal_callback', 62 'pluginPage' 47 63 ); 48 64 … … 52 68 'pvcu_modal_title_render', 53 69 'pluginPage', 54 'pvcu_plugin Page_section'70 'pvcu_plugin_modal_settings' 55 71 ); 56 72 … … 60 76 'pvcu_modal_content_render', 61 77 'pluginPage', 62 'pvcu_plugin Page_section'78 'pvcu_plugin_modal_settings' 63 79 ); 64 80 } … … 66 82 add_action( 'admin_init', 'pvcu_settings_init' ); 67 83 68 function pvcu_enabled_render() { 84 function pvcu_plugin_action_callback() { 85 echo __( '<p>For the two locations below, you can choose to have <em>no</em> protection, <em>warn</em> the user before a plugin update (with a modal window which the user must agree to before the update triggers), or <em>block</em> updates entirely.</p>', 'pvcu' ); 86 } 87 88 function pvcu_plugins_action_render() { 69 89 $options = get_option( 'pvcu_settings' ); ?> 70 <label for='pvcu_settings[pvcu_enabled]'>This plugin scans your WordPress installation looking for Git folders. You can use this checkbox to turn the protection off.<br />You can also use this checkbox to force protection, in case the plugin did not detect your version-controlled settings.</label><br /> 71 <input type='checkbox' name='pvcu_settings[pvcu_enabled]' <?php checked( $options['pvcu_enabled'], 1 ); ?> value='1'> 90 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'none' ); ?> value='none'>None<br /> 91 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'warn' ); ?> value='warn'>Warn<br /> 92 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'block' ); ?> value='block'>Block 72 93 <?php 73 94 } 74 95 75 function pvcu_ warn_or_block_render() {96 function pvcu_themes_action_render() { 76 97 $options = get_option( 'pvcu_settings' ); ?> 77 < label for='pvcu_settings[pvcu_warn_or_block]'>You can choose to <em>warn</em> the user before a plugin update, using a modal window which the user must agree to before the update triggers. You can also choose to <em>block</em> updates entirely.</label><br />78 <input type='radio' name='pvcu_settings[pvcu_ warn_or_block]' <?php checked( $options['pvcu_warn_or_block'], 'warn' ); ?> value='warn'>Warn<br />79 <input type='radio' name='pvcu_settings[pvcu_ warn_or_block]' <?php checked( $options['pvcu_warn_or_block'], 'block' ); ?> value='block'>Block98 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'none' ); ?> value='none'>None<br /> 99 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'warn' ); ?> value='warn'>Warn<br /> 100 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'block' ); ?> value='block'>Block 80 101 <?php 102 } 103 104 function pvcu_core_action_render() { 105 $options = get_option( 'pvcu_settings' ); ?> 106 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'none' ); ?> value='none'>None<br /> 107 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'warn' ); ?> value='warn'>Warn<br /> 108 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'block' ); ?> value='block'>Block 109 <?php 110 } 111 112 function pvcu_plugin_modal_callback() { 113 echo __( '<p>You can set options below for the modal window the user will see for any sectio marked <em>warn</em> or <em>block</em> above.' ); 81 114 } 82 115 … … 84 117 $options = get_option( 'pvcu_settings' ); ?> 85 118 <label>What title do you want to display on the modal window?</label><br /> 86 <input type='text' name='pvcu_settings[pvcu_modal_title]' value='<?php echo $options[ 'pvcu_modal_title']; ?>'>119 <input type='text' name='pvcu_settings[pvcu_modal_title]' value='<?php echo $options[ 'pvcu_modal_title' ]; ?>'> 87 120 <?php 88 121 } … … 91 124 $options = get_option( 'pvcu_settings' ); ?> 92 125 <label>What message do you want to display on the modal window?</label><br /> 93 <textarea cols='40' rows='5' name='pvcu_settings[pvcu_modal_content]'><?php echo $options[ 'pvcu_modal_content']; ?></textarea>126 <textarea cols='40' rows='5' name='pvcu_settings[pvcu_modal_content]'><?php echo $options[ 'pvcu_modal_content' ]; ?></textarea> 94 127 <?php 95 }96 97 function pvcu_settings_section_callback() {98 echo __( 'You can control the settings for the Protect Version Controlled Updates plugin below.', 'pvcu' );99 128 } 100 129 … … 102 131 <form action='options.php' method='post'> 103 132 <h1>Protect Version Controlled Updates</h1> 133 <p>You can control the settings for the Protect Version Controlled Updates plugin below.</p> 104 134 105 135 <?php -
protect-version-controlled-updates/tags/1.1.0/pvcu-scripts.php
r1429558 r1440619 3 3 // Enqueue bootstrap, JS, and CSS, only on the plugin page 4 4 5 function pvcu_add_scripts( $hook ) { 6 if( ! pvcu_protect_this_page() ) { 5 function pvcu_add_scripts() { 6 7 if( ! pvcu_load_assets() ) { 7 8 return; 8 9 } 9 10 10 wp_enqueue_script( 'bootstrap-js', plugin_dir_url( __FILE__ ) . 'assets/bootstrap/js/bootstrap.min.js' );11 wp_enqueue_script( 'pvcu-js', plugin_dir_url( __FILE__ ) . 'assets/js/pvcu.js', array( 'jquery', 'updates' ), '', TRUE);11 wp_enqueue_script( 'bootstrap-js', plugin_dir_url( __FILE__ ) . 'assets/bootstrap/js/bootstrap.min.js', '', '', true ); 12 wp_enqueue_script( 'pvcu-js', plugin_dir_url( __FILE__ ) . 'assets/js/pvcu.js', array( 'jquery', 'updates' ), '', true ); 12 13 wp_enqueue_style( 'pvcu-css', plugin_dir_url( __FILE__ ) . 'assets/css/pvcu.css' ); 13 14 } -
protect-version-controlled-updates/tags/1.1.0/readme.txt
r1429558 r1440619 4 4 Requires at least: 4.2 5 5 Tested up to: 4.5.2 6 Stable tag: 1. 0.06 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 31 31 == Frequently Asked Questions == 32 32 33 = Does this auto-detect if I have a Git version-controllled server? =33 = Does this auto-detect if I have a Git or SVN version-controllled server? = 34 34 35 This plugin looks in all the normal spots for .git folders - the root, the wp-content folder, the plugins folder, the themes folder, and even in the current theme and the parent theme (if applicable).35 This plugin looks in all the normal spots for .git and/or .svn folders - the root, the wp-content folder, the plugins folder, the themes folder, and even in the current theme and the parent theme (if applicable). 36 36 37 37 = If it doesn't autodetect my installation, what then? = … … 39 39 You can manually turn on the protection from the options screen. 40 40 41 = What about Subversion? =42 43 The plugin doesn't currently autodetect Subversion repos. You can manually turn on the protection for Subversion version-controlled servers.44 45 41 = Can I turn the protection off? = 46 42 47 From the same options page, you can uncheck the box to allow updates on your site.43 You can turn protection off individually for either plugins or themes. 48 44 49 = Does this protect themes or core? = 45 = Which pages are protected? = 46 47 The plugins page (plugins.php), the plugin install page (plugin-install.php), and the general updates page (update-core.php). Future versions will protect the themes page (themes.php). 48 49 = I can still update my theme from the Themes page, even with protection. What gives? = 50 51 That's a known issue. Future versions will protect theme updates from the Themes screen. 52 53 = Does this protect plugin or theme deletion? = 50 54 51 55 Not at this time, but that's planned for a future version. 52 56 57 = Does this protect core? = 58 59 Not at this time, but that's planned for a future version. 60 61 == Screenshots == 62 63 1. The modal title and description are user-changable. Note that both the plugins and themes are set to "warn." 64 2. The actual modal. Note that there's a cancel button and an update button. 65 3. Setting both plugins and themes to "block." 66 4. The actual modal, now with only a cancel button. 67 53 68 == Changelog == 69 70 = 1.1 = 71 * Extensive refactoring of functions to allow for separate choices for plugins, themes, and core (upcoming release). 72 * Removed the checkbox to disable protection. 73 * Merged the protection disabling into the radio button choices for plugins and for themes. 74 * Updated JS to intercept form submissions for updates. 54 75 55 76 = 1.0 = -
protect-version-controlled-updates/trunk/assets/js/pvcu.js
r1429558 r1440619 3 3 $( 'a.update-link' ).addClass( 'update-link-disabled' ).removeClass( 'update-link' ); 4 4 5 // Intercept the update link on the plugins page (plugins.php) 5 6 $( 'a.update-link-disabled' ).click( function( e ) { 6 7 e.preventDefault(); 7 8 var updateLink = $(this).attr( 'href' ); 8 console.log( updateLink ); 9 $( '#pvcuModal' ).modal(); 10 $( '#pvcuModal #update' ).attr( 'href', updateLink ); 9 $( '#pvcuModal-plugins' ).modal(); 10 $( '#pvcuModal-plugins #update' ).click( function ( e2 ) { 11 window.location=updateLink; 12 return false; 13 }); 11 14 }); 15 16 // Intercept the bulk update form on the plugins page (plugins.php) 17 // If #pvcuModal-plugins hasn't been injected, that means protection is not enabled, so do nothing. 18 if( $( '#pvcuModal-plugins' ).length ) { 19 console.log( 'running' ); 20 $( 'form#bulk-action-form' ).submit( function( e, submit ) { 21 var bulkActionOption = $( this ).find( 'select' ).val(); 22 if( bulkActionOption == 'update-selected' ) { 23 if( ! submit ) { 24 e.preventDefault(); 25 $( '#pvcuModal-plugins' ).modal(); 26 } 27 28 } 29 }); 30 31 $( '#pvcuModal-plugins #update' ).click( function() { 32 $( 'form#bulk-action-form' ).trigger( 'submit', [true] ); 33 }); 34 } 35 36 // Intercept the update link on the Theme Details page (themes.php) 37 // TBD 38 39 // Intercept the core update submit button on update-core.php. 40 // Uncomment when able to stop core updates. 41 // If #pvcuModal-core hasn't been injected, that means protection is not enabled, so do nothing. 42 // if( $( '#pvcuModal-core' ).length ) { 43 // $( 'form[name="upgrade"]' ).submit( function( e, submit ) { 44 // if( ! submit ) { 45 // e.preventDefault(); 46 // $( '#pvcuModal-core' ).modal(); 47 // } 48 // }); 49 50 // $( '#pvcuModal-core #update' ).click( function() { 51 // $( 'form[name="upgrade"]' ).trigger( 'submit', [true] ); 52 // }); 53 // } 54 55 // Intercept the plugins update submit button on update-core.php 56 // If #pvcuModal-plugins hasn't been injected, that means protection is not enabled, so do nothing. 57 if( $( '#pvcuModal-plugins' ).length ) { 58 $( 'form[name="upgrade-plugins"]' ).submit( function( e, submit ) { 59 if( ! submit ) { 60 e.preventDefault(); 61 $( '#pvcuModal-plugins' ).modal(); 62 } 63 }); 64 65 $( '#pvcuModal-plugins #update' ).click( function() { 66 $( 'form[name="upgrade-plugins"]' ).trigger( 'submit', [true] ); 67 }); 68 } 69 70 // Intercept the themes update submit button on update-core.php 71 // If #pvcuModal-themes hasn't been injected, that means protection is not enabled, so do nothing. 72 if( $( '#pvcuModal-themes' ).length ) { 73 $( 'form[name="upgrade-themes"]' ).submit( function( e, submit ) { 74 if( ! submit ) { 75 e.preventDefault(); 76 $( '#pvcuModal-themes' ).modal(); 77 } 78 }); 79 80 $( '#pvcuModal-themes #update' ).click( function() { 81 $( 'form[name="upgrade-themes"]' ).trigger( 'submit', [true] ); 82 }); 83 } 84 12 85 })( jQuery ); -
protect-version-controlled-updates/trunk/pvcu-activation.php
r1429558 r1440619 1 1 <?php 2 2 3 /* 4 * This function uses the output of pvcu_find_version_control() 5 * to set options in the options table upon plugin activation. 6 * 7 * @uses pvcu_find_version_control To find what components have VC'ed folders 8 * 9 * @param void 10 * @return void 11 */ 12 3 13 function pvcu_activation() { 4 // Find out if there's a .git folder somewhere14 // Find out if there's a .git or .svn folder somewhere 5 15 $vc_files_found = pvcu_find_version_control(); 16 add_option( 'pvcu_return', $vc_files_found ); 6 17 7 18 // Create an array of option values 8 19 $pvcu_options_array = array(); 9 20 10 $pvcu_options_array[ 'pvcu_enabled' ] = $vc_files_found; 11 $pvcu_options_array[ 'pvcu_warn_or_block' ] = 'warn'; 12 $pvcu_options_array[ 'pvcu_modal_title' ] = ''; 13 $pvcu_options_array[ 'pvcu_modal_content' ] = ''; 21 if( $vc_files_found[ 'plugins' ] === true ) { 22 $pvcu_options_array[ 'pvcu_plugins_action' ] = 'warn'; 23 } else { 24 $pvcu_options_array[ 'pvcu_plugins_action' ] = 'none'; 25 } 26 27 if( $vc_files_found[ 'themes' ] === true ) { 28 $pvcu_options_array[ 'pvcu_themes_action' ] = 'warn'; 29 } else { 30 $pvcu_options_array[ 'pvcu_themes_action' ] = 'none'; 31 } 32 33 // Uncomment when able to stop core updates. 34 35 // if( $vc_files_found[ 'core' ] === true ) { 36 // $pvcu_options_array[ 'pvcu_core_action' ] = 'warn'; 37 // } else { 38 // $pvcu_options_array[ 'pvcu_core_action' ] = 'none'; 39 // } 40 41 $pvcu_options_array[ 'pvcu_modal_title' ] = 'Update Warning'; 42 $pvcu_options_array[ 'pvcu_modal_content' ] = 'Are you sure you want to update this item? Please check with your web development company before doing so.'; 14 43 15 44 add_option( 'pvcu_settings', $pvcu_options_array, '', FALSE ); -
protect-version-controlled-updates/trunk/pvcu-general.php
r1429558 r1440619 4 4 * This function will be part of the activation process. 5 5 * It looks through the file system at specific likely 6 * points, looking for .git folders or files. If present,6 * points, looking for .git or .svn folders or files. If present, 7 7 * it returns true so that the protection is turned on 8 8 * automatically. 9 9 * 10 * @todo Search for SVN-related files as well. 10 * @uses pvcu_is_version_controlled() Tests for the existence of 11 * .git or .svn folders. 12 * 13 * @param void 14 * @return array An array of the things to protect by default, 15 * based off of existence of .git or .svn folders. 16 * 11 17 */ 12 18 13 19 function pvcu_find_version_control() { 14 $vc_files_found = false; 15 $folders_to_check = array(); 20 $vc_controlled_paths = array(); 21 $plugins_dir_path = ''; 22 $themes_dir_path = ''; 23 $current_theme_path = ''; 24 $parent_theme_path = ''; 16 25 17 26 // Clear the built-in PHP file caching 18 27 clearstatcache(); 19 28 20 /* 21 * Get an array of server paths to check. There are a 22 * plethora of functions to get *URL's*, but very few that 23 * get server paths. As a result, some of these are a 24 * little convoluted. 29 // Set the defaults for the $vc_controlled_paths array 30 $vc_controlled_paths[ 'plugins' ] = false; 31 $vc_controlled_paths[ 'themes' ] = false; 32 // Uncomment when able to stop core updates. 33 // $vc_controlled_paths[ 'core' ] = false; 34 35 36 /* 37 * Check numerous server paths for .git or .svn folders. 38 * There are a plethora of functions to get *URL's*, but 39 * fewer that get server paths. As a result, some of 40 * these are a little convoluted. 41 * 42 * For these paths, we're going to set the appropriate flag 43 * in $vc_controlled_paths - choices are 'plugins', 44 * 'themes', and 'core' - depending on the path. 25 45 */ 26 46 27 47 /* 28 48 * Sometimes the whole site is version-controlled, so look 29 * in the root. 49 * in the root. If true, set all three flags. 30 50 */ 31 51 … … 33 53 include_once( ABSPATH . 'wp-admin/includes/file.php' ); 34 54 35 $folders_to_check[ 'root' ] = get_home_path(); 36 37 /* 38 * Sometimes only the wp-content folder is VC'ed 55 if( pvcu_is_version_controlled( get_home_path() ) ) { 56 $vc_controlled_paths[ 'plugins' ] = true; 57 $vc_controlled_paths[ 'themes' ] = true; 58 // Uncomment when able to stop core updates. 59 // $vc_controlled_paths[ 'core' ] = true; 60 }; 61 62 /* 63 * Sometimes only the wp-content folder is VC'ed. If so, set 64 * 'plugins' and 'themes' flag. 39 65 * 40 * @todo Using WP constants is frowned upon, find a 41 * better way. 42 */ 43 $folders_to_check[ 'wp_content' ] = WP_CONTENT_DIR; 66 * @todo Using WP constants is frowned upon, find a better way. 67 */ 68 69 if( pvcu_is_version_controlled( WP_CONTENT_DIR ) ) { 70 $vc_controlled_paths[ 'plugins' ] = true; 71 $vc_controlled_paths[ 'themes' ] = true; 72 }; 44 73 45 74 // Sometimes it's only the plugins or themes folders … … 47 76 /* 48 77 * Find the parent directory of this plugin to determine 49 * the path to the plugins directory. 50 * 51 * @todo: Make this MU friendly. 52 */ 53 54 $folders_to_check[ 'plugins' ] = dirname( plugin_dir_path( __FILE__ ) ); 55 56 // Find the parent directory of the stylesheet path 57 $folders_to_check[ 'all_themes' ] = dirname( get_stylesheet_directory() ); 78 * the path to the plugins directory. If this returns 79 * true, set 'plugins' flag. 80 */ 81 82 $plugins_dir_path = dirname( dirname( plugin_dir_path( __FILE__ ) ) ); 83 if( pvcu_is_version_controlled( $plugins_dir_path ) ) { 84 $vc_controlled_paths[ 'plugins' ] = true; 85 }; 86 87 /* 88 * If $plugins_dir_path isn't equal to WP_PLUGIN_DIR, 89 * that means that this plugin is in the mu-plugins 90 * directory. The test above checked the mu-plugins 91 * folder already, so let's check WP_PLUGIN_DIR, and 92 * set the 'plugins' flag if true. 93 * 94 * @todo Using WP constants is frowned upon, find a better way. 95 */ 96 97 if( pvcu_is_version_controlled( WP_PLUGIN_DIR ) ) { 98 $vc_controlled_paths[ 'plugins' ] = true; 99 }; 100 101 /* 102 * Find the parent directory of the stylesheet path to 103 * determine the path to the themes directory. If this 104 * returns true, set 'themes' flag. 105 */ 106 107 $themes_dir_path = dirname( get_stylesheet_directory() ); 108 109 if( pvcu_is_version_controlled( $themes_dir_path ) ) { 110 $vc_controlled_paths[ 'themes' ] = true; 111 }; 58 112 59 113 // And (very rarely) it's just the theme that's VC'ed. 60 114 61 // Find the stylesheet path 62 $folders_to_check[ 'current_theme' ] = get_stylesheet_directory(); 63 64 // If this is a child theme, find the parent's directory 65 if( get_stylesheet_directory() != get_template_directory() ) { 66 $folders_to_check[ 'parent_theme' ] = get_template_directory(); 115 /* 116 * Find the stylesheet paths. If the theme is VC'ed, there's 117 * probably a parent and child theme. I can't see why the 118 * parent would be VC'ed but not the child, but let's check 119 * both just to be safe. Set the 'themes' flag if either 120 * is true. 121 */ 122 123 $current_theme_path = get_stylesheet_directory(); 124 $parent_theme_path = get_template_directory(); 125 126 if( pvcu_is_version_controlled( $current_theme_path ) || pvcu_is_version_controlled( $parent_theme_path ) ) { 127 $vc_controlled_paths[ 'themes' ] = true; 67 128 } 68 129 69 130 // Didn't I warn you that some of those were convoluted? 70 131 71 /* 72 * For each of the paths in our array, check to see if 73 * there's a .git folder in that path. 74 */ 75 76 foreach( $folders_to_check as $folder ) { 77 if( file_exists( $folder . '/.git' ) ) { 78 $vc_files_found = true; 79 } 132 return $vc_controlled_paths; 133 134 } 135 136 function pvcu_is_version_controlled( $path ) { 137 138 /* 139 * Check the path, see if there's a VC-ed folder in that path, and set 140 * the appropriate flag if there is. 141 * 142 * @param string $path The path to check for a VC folder 143 * @return bool Whether there's a VC folder in $path. 144 */ 145 146 $vc_files_found = false; 147 148 if( file_exists( $path . '/.git' ) || file_exists( $path . '/.svn' ) ) { 149 $vc_files_found = true; 80 150 } 81 151 … … 87 157 * be loaded on a page. 88 158 * 159 * @uses pvcu_get_current_screen() Gets the base of the current screen. 160 * @uses pvcu_get_current_screen_relevant_option Gets the relevant option 161 * based on current base. 162 * 163 * 89 164 * @param void 90 * @return bool Whether this page is one of the types of pages 91 * being protected. 92 */ 93 94 function pvcu_protect_this_page() { 95 // Bail if protection is disabled from the options screen 96 $pvcu_settings = get_option( 'pvcu_settings' ); 165 * @return bool Should this page have scripts and modals loaded on it? 166 */ 167 168 function pvcu_load_assets() { 169 $full_options = ''; 170 $current_screen = ''; 171 $protected_screens = array(); 172 $current_screen_settings = ''; 173 $current_screen_option = array(); 174 $load_assets = ''; 175 176 // Get the current screen base 177 $current_screen = pvcu_get_current_screen(); 97 178 98 if( $pvcu_settings[ 'pvcu_enabled' ] !== '1' ) { 99 return false; 100 } 101 179 $protected_screens = array( 'plugins', 'plugin-install', 'themes', 'update-core', ); 180 181 // Add or unset protected screens from the array if desired. 182 $protected_screens = apply_filters( 'pvcu_protected_screens', $protected_screens ); 183 184 /* 185 * Check to see if the current screen is one of the ones which should be protected. 186 * If so, grab the option setting which corresponds to this type of page. If it's 187 * set to 'none,' return false, but otherwise, return true. 188 */ 189 if( in_array( $current_screen, $protected_screens ) ) { 190 $load_assets = false; 191 $full_options = get_option( 'pvcu_settings' ); 192 $current_screen_option_name = pvcu_get_current_screen_relevant_option( $current_screen ); 193 194 foreach( $current_screen_option_name as $single_option ) { 195 if( $single_option != 'none' ) { 196 $load_assets = true; 197 } 198 } 199 return $load_assets; 200 } else { 201 return false; // This page isn't protected, don't load scripts or modal. 202 } 203 } 204 205 /* 206 * Gets the current screen base. 207 * 208 * @param void 209 * @return string The base of the current screen 210 */ 211 212 function pvcu_get_current_screen() { 102 213 $current_screen_object = new stdClass(); 103 214 $current_screen = ''; 104 $protected_screens = array(); 105 215 216 // Get the base of the screen we're looking at. 106 217 $current_screen_object = get_current_screen(); 107 218 $current_screen = $current_screen_object->base; 108 $protected_screens = array( 'plugins', 'plugin-install' ); 109 $protected_screens = apply_filters( 'pvcu_protected_screens', $protected_screens ); 110 111 if( in_array( $current_screen, $protected_screens ) ) { 112 return true; 219 220 return $current_screen; 221 } 222 223 /* 224 * Given the base of a screen, this will return the name of the relevant 225 * PVCU option. Note that this doesn't return the *value* of the option, 226 * just the key name to check in the option. 227 * 228 * @param string Current screen base 229 * @return mixed Array (one $key=>$value pair) with the relevant setting 230 * from the pvcu_settings option array, array (three pairs) 231 * of all options if we're on the 'update-core' page, or 232 * null if the base doesn't have a corresponding option value. 233 */ 234 235 function pvcu_get_current_screen_relevant_option( $base ) { 236 $screen_to_option_name = array(); 237 $option_name = ''; 238 239 /* 240 * For the 'update-core' page, we need to return an array 241 * of all three choices, since all three can be on the 242 * page. 243 */ 244 245 $screen_to_option_name = array( 246 'plugins' => array( 'plugins' => 'pvcu_plugins_action' ), 247 'plugin-install' => array( 'plugins' => 'pvcu_plugins_action' ), 248 'themes' => array( 'themes' => 'pvcu_themes_action' ), 249 'update-core' => array( 250 'plugins' => 'pvcu_plugins_action', 251 'themes' => 'pvcu_themes_action', 252 // Uncomment when able to stop core updates. 253 // 'core' => 'pvcu_core_action', 254 ), 255 ); 256 257 /* 258 * Here's a chance to modify the array, in case new screens were added 259 * to the protected screens array using the pvcu_protected_screens 260 * filter. 261 */ 262 263 $screen_to_option_name = apply_filters( 'pvcu_screen_to_option_name', $screen_to_option_name ); 264 265 // Find the value of $base in this array 266 if( isset( $screen_to_option_name[ $base ] ) ) { 267 return $screen_to_option_name[ $base ]; 113 268 } else { 114 return false;115 } 116 } 269 return null; 270 } 271 } -
protect-version-controlled-updates/trunk/pvcu-main.php
r1429558 r1440619 4 4 Plugin URI: https://wordpress.org/plugins/protect-version-controlled-updates/ 5 5 Description: This plugin is for version-controlled websites. Depending on the settings, users attempting to update plugins will either get a popup asking for confirmation or will be totally prevented from updating. 6 Version: 1. 0.06 Version: 1.1.0 7 7 Author: Shiny 9 Web Design 8 8 Author URI: http://www.shiny9web.com -
protect-version-controlled-updates/trunk/pvcu-modal-output.php
r1429558 r1440619 1 1 <?php 2 2 3 // The modal popup 3 /* 4 * Generates the modal popup. 5 * 6 * @uses get_option Gets the value of the plugin option 7 * @uses pvcu_get_current_screen Gets the base for the current screen 8 * @uses pvcu_get_current_screen_relevant_option Gets the key for the needed value for this screen 9 * 10 * @param void 11 * @return string HTML for the popup. 12 */ 4 13 5 14 function pvcu_modal_output() { 6 $pvcu_settings = ''; 7 $pvcu_update_action = ''; 8 $pvcu_modal_title = ''; 9 $pvcu_modal_content = ''; 15 $full_settings = ''; 16 $current_screen = ''; 17 $current_screen_key = ''; 18 $current_screen_action = ''; 19 $modal_title = ''; 20 $modal_content = ''; 10 21 11 $pvcu_settings = get_option( 'pvcu_settings' ); 22 $full_settings = get_option( 'pvcu_settings' ); 23 $current_screen = pvcu_get_current_screen(); 24 $current_screen_option = pvcu_get_current_screen_relevant_option( $current_screen ); 25 $modal_title = $full_settings[ 'pvcu_modal_title' ]; 26 $modal_content = $full_settings[ 'pvcu_modal_content' ]; 12 27 13 $pvcu_update_action = $pvcu_settings[ 'pvcu_warn_or_block' ]; 14 $pvcu_modal_title = $pvcu_settings[ 'pvcu_modal_title' ]; 15 $pvcu_modal_content = $pvcu_settings[ 'pvcu_modal_content' ]; 28 ob_start(); 29 foreach( $current_screen_option as $key => $value ) { 30 $option_value = $full_settings[ $value ]; 31 32 // Don't generate a modal if the option is set to 'none' 33 if( $option_value == 'none' ) { 34 continue; 35 } 36 37 ?> 38 <div id="pvcuModal-<?php echo $key; ?>" class="modal hide fade" tabindex="-1" > 39 <div class="modal-header"> 40 <h3><?php echo $modal_title; ?></h3> 41 </div> 42 <div class="modal-body"> 43 <?php echo apply_filters( 'the_content', $modal_content ); ?> 44 </div> 45 <div class="modal-footer"> 46 <button id="dismiss" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 47 <?php if( $option_value != 'block' ) { ?> 48 <button id="update" class="btn btn-primary" data-confirm="true" aria-hidden="false" >Update</button> 49 <?php } ?> 50 </div> 51 </div> 52 <?php 53 } // End foreach 54 $output = ob_get_clean(); 55 apply_filters( 'pvcu_output', $output ); 16 56 17 ob_start(); ?> 18 <div id="pvcuModal" class="modal hide fade" tabindex="-1" > 19 <div class="modal-header"> 20 <h3><?php echo $pvcu_modal_title; ?></h3> 21 </div> 22 <div class="modal-body"> 23 <?php echo apply_filters( 'the_content', $pvcu_modal_content ); ?> 24 </div> 25 <div class="modal-footer"> 26 <button id="dismiss" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button> 27 <?php if( $pvcu_update_action != 'block' ) { ?> 28 <a id="update" class="btn btn-primary" data-confirm="true" aria-hidden="false" >Update</a> 29 <?php } ?> 30 </div> 31 </div> 32 <?php 33 $pvcu_output = ob_get_clean(); 34 apply_filters( 'pvcu_output', $pvcu_output ); 57 return $output; 58 } 35 59 36 return $pvcu_output; 37 } 60 /* 61 * Inject the modal HTML into the admin page. 62 * 63 * @uses pvcu_load_assets Determines if the modal should be 64 * injected into this page. 65 * 66 * @param void 67 * @return string Echoes the HTML 68 */ 38 69 39 70 function pvcu_modal_action() { 40 71 /* 41 72 * We only want the modal injected on pages we've 42 * designated, and only if the option is turned on 43 * through the options page. 73 * designated. 44 74 */ 45 75 46 if( ! pvcu_ protect_this_page() ) {76 if( ! pvcu_load_assets() ) { 47 77 return; 48 78 }; … … 51 81 } 52 82 53 add_action( 'admin_ print_footer_scripts', 'pvcu_modal_action' );83 add_action( 'admin_head', 'pvcu_modal_action' ); -
protect-version-controlled-updates/trunk/pvcu-options-page.php
r1429558 r1440619 24 24 25 25 add_settings_section( 26 'pvcu_pluginPage_section', 27 '', 28 // __( 'General Settings', 'pvcu' ), 29 'pvcu_settings_section_callback', 26 'pvcu_plugin_action_settings', 27 'Action Settings', 28 'pvcu_plugin_action_callback', 30 29 'pluginPage' 31 30 ); 32 31 33 32 add_settings_field( 34 'pvcu_ enabled',35 __( ' Manually enable/disable protection', 'pvcu' ),36 'pvcu_ enabled_render',33 'pvcu_plugins_action', 34 __( 'Plugins Action', 'pvcu' ), 35 'pvcu_plugins_action_render', 37 36 'pluginPage', 38 'pvcu_plugin Page_section'37 'pvcu_plugin_action_settings' 39 38 ); 40 39 41 40 add_settings_field( 42 'pvcu_ warn_or_block',43 __( ' Warn before updating, or block entirely', 'pvcu' ),44 'pvcu_ warn_or_block_render',41 'pvcu_themes_action', 42 __( 'Themes Action', 'pvcu' ), 43 'pvcu_themes_action_render', 45 44 'pluginPage', 46 'pvcu_pluginPage_section' 45 'pvcu_plugin_action_settings' 46 ); 47 48 // Uncomment when able to stop core updates. 49 50 // add_settings_field( 51 // 'pvcu_core_action', 52 // __( 'Core Action', 'pvcu' ), 53 // 'pvcu_core_action_render', 54 // 'pluginPage', 55 // 'pvcu_plugin_action_settings' 56 // ); 57 58 add_settings_section( 59 'pvcu_plugin_modal_settings', 60 'Modal Settings', 61 'pvcu_plugin_modal_callback', 62 'pluginPage' 47 63 ); 48 64 … … 52 68 'pvcu_modal_title_render', 53 69 'pluginPage', 54 'pvcu_plugin Page_section'70 'pvcu_plugin_modal_settings' 55 71 ); 56 72 … … 60 76 'pvcu_modal_content_render', 61 77 'pluginPage', 62 'pvcu_plugin Page_section'78 'pvcu_plugin_modal_settings' 63 79 ); 64 80 } … … 66 82 add_action( 'admin_init', 'pvcu_settings_init' ); 67 83 68 function pvcu_enabled_render() { 84 function pvcu_plugin_action_callback() { 85 echo __( '<p>For the two locations below, you can choose to have <em>no</em> protection, <em>warn</em> the user before a plugin update (with a modal window which the user must agree to before the update triggers), or <em>block</em> updates entirely.</p>', 'pvcu' ); 86 } 87 88 function pvcu_plugins_action_render() { 69 89 $options = get_option( 'pvcu_settings' ); ?> 70 <label for='pvcu_settings[pvcu_enabled]'>This plugin scans your WordPress installation looking for Git folders. You can use this checkbox to turn the protection off.<br />You can also use this checkbox to force protection, in case the plugin did not detect your version-controlled settings.</label><br /> 71 <input type='checkbox' name='pvcu_settings[pvcu_enabled]' <?php checked( $options['pvcu_enabled'], 1 ); ?> value='1'> 90 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'none' ); ?> value='none'>None<br /> 91 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'warn' ); ?> value='warn'>Warn<br /> 92 <input type='radio' name='pvcu_settings[pvcu_plugins_action]' <?php checked( $options['pvcu_plugins_action'], 'block' ); ?> value='block'>Block 72 93 <?php 73 94 } 74 95 75 function pvcu_ warn_or_block_render() {96 function pvcu_themes_action_render() { 76 97 $options = get_option( 'pvcu_settings' ); ?> 77 < label for='pvcu_settings[pvcu_warn_or_block]'>You can choose to <em>warn</em> the user before a plugin update, using a modal window which the user must agree to before the update triggers. You can also choose to <em>block</em> updates entirely.</label><br />78 <input type='radio' name='pvcu_settings[pvcu_ warn_or_block]' <?php checked( $options['pvcu_warn_or_block'], 'warn' ); ?> value='warn'>Warn<br />79 <input type='radio' name='pvcu_settings[pvcu_ warn_or_block]' <?php checked( $options['pvcu_warn_or_block'], 'block' ); ?> value='block'>Block98 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'none' ); ?> value='none'>None<br /> 99 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'warn' ); ?> value='warn'>Warn<br /> 100 <input type='radio' name='pvcu_settings[pvcu_themes_action]' <?php checked( $options['pvcu_themes_action'], 'block' ); ?> value='block'>Block 80 101 <?php 102 } 103 104 function pvcu_core_action_render() { 105 $options = get_option( 'pvcu_settings' ); ?> 106 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'none' ); ?> value='none'>None<br /> 107 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'warn' ); ?> value='warn'>Warn<br /> 108 <input type='radio' name='pvcu_settings[pvcu_core_action]' <?php checked( $options['pvcu_core_action'], 'block' ); ?> value='block'>Block 109 <?php 110 } 111 112 function pvcu_plugin_modal_callback() { 113 echo __( '<p>You can set options below for the modal window the user will see for any sectio marked <em>warn</em> or <em>block</em> above.' ); 81 114 } 82 115 … … 84 117 $options = get_option( 'pvcu_settings' ); ?> 85 118 <label>What title do you want to display on the modal window?</label><br /> 86 <input type='text' name='pvcu_settings[pvcu_modal_title]' value='<?php echo $options[ 'pvcu_modal_title']; ?>'>119 <input type='text' name='pvcu_settings[pvcu_modal_title]' value='<?php echo $options[ 'pvcu_modal_title' ]; ?>'> 87 120 <?php 88 121 } … … 91 124 $options = get_option( 'pvcu_settings' ); ?> 92 125 <label>What message do you want to display on the modal window?</label><br /> 93 <textarea cols='40' rows='5' name='pvcu_settings[pvcu_modal_content]'><?php echo $options[ 'pvcu_modal_content']; ?></textarea>126 <textarea cols='40' rows='5' name='pvcu_settings[pvcu_modal_content]'><?php echo $options[ 'pvcu_modal_content' ]; ?></textarea> 94 127 <?php 95 }96 97 function pvcu_settings_section_callback() {98 echo __( 'You can control the settings for the Protect Version Controlled Updates plugin below.', 'pvcu' );99 128 } 100 129 … … 102 131 <form action='options.php' method='post'> 103 132 <h1>Protect Version Controlled Updates</h1> 133 <p>You can control the settings for the Protect Version Controlled Updates plugin below.</p> 104 134 105 135 <?php -
protect-version-controlled-updates/trunk/pvcu-scripts.php
r1429558 r1440619 3 3 // Enqueue bootstrap, JS, and CSS, only on the plugin page 4 4 5 function pvcu_add_scripts( $hook ) { 6 if( ! pvcu_protect_this_page() ) { 5 function pvcu_add_scripts() { 6 7 if( ! pvcu_load_assets() ) { 7 8 return; 8 9 } 9 10 10 wp_enqueue_script( 'bootstrap-js', plugin_dir_url( __FILE__ ) . 'assets/bootstrap/js/bootstrap.min.js' );11 wp_enqueue_script( 'pvcu-js', plugin_dir_url( __FILE__ ) . 'assets/js/pvcu.js', array( 'jquery', 'updates' ), '', TRUE);11 wp_enqueue_script( 'bootstrap-js', plugin_dir_url( __FILE__ ) . 'assets/bootstrap/js/bootstrap.min.js', '', '', true ); 12 wp_enqueue_script( 'pvcu-js', plugin_dir_url( __FILE__ ) . 'assets/js/pvcu.js', array( 'jquery', 'updates' ), '', true ); 12 13 wp_enqueue_style( 'pvcu-css', plugin_dir_url( __FILE__ ) . 'assets/css/pvcu.css' ); 13 14 } -
protect-version-controlled-updates/trunk/readme.txt
r1429558 r1440619 4 4 Requires at least: 4.2 5 5 Tested up to: 4.5.2 6 Stable tag: 1. 0.06 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 31 31 == Frequently Asked Questions == 32 32 33 = Does this auto-detect if I have a Git version-controllled server? =33 = Does this auto-detect if I have a Git or SVN version-controllled server? = 34 34 35 This plugin looks in all the normal spots for .git folders - the root, the wp-content folder, the plugins folder, the themes folder, and even in the current theme and the parent theme (if applicable).35 This plugin looks in all the normal spots for .git and/or .svn folders - the root, the wp-content folder, the plugins folder, the themes folder, and even in the current theme and the parent theme (if applicable). 36 36 37 37 = If it doesn't autodetect my installation, what then? = … … 39 39 You can manually turn on the protection from the options screen. 40 40 41 = What about Subversion? =42 43 The plugin doesn't currently autodetect Subversion repos. You can manually turn on the protection for Subversion version-controlled servers.44 45 41 = Can I turn the protection off? = 46 42 47 From the same options page, you can uncheck the box to allow updates on your site.43 You can turn protection off individually for either plugins or themes. 48 44 49 = Does this protect themes or core? = 45 = Which pages are protected? = 46 47 The plugins page (plugins.php), the plugin install page (plugin-install.php), and the general updates page (update-core.php). Future versions will protect the themes page (themes.php). 48 49 = I can still update my theme from the Themes page, even with protection. What gives? = 50 51 That's a known issue. Future versions will protect theme updates from the Themes screen. 52 53 = Does this protect plugin or theme deletion? = 50 54 51 55 Not at this time, but that's planned for a future version. 52 56 57 = Does this protect core? = 58 59 Not at this time, but that's planned for a future version. 60 61 == Screenshots == 62 63 1. The modal title and description are user-changable. Note that both the plugins and themes are set to "warn." 64 2. The actual modal. Note that there's a cancel button and an update button. 65 3. Setting both plugins and themes to "block." 66 4. The actual modal, now with only a cancel button. 67 53 68 == Changelog == 69 70 = 1.1 = 71 * Extensive refactoring of functions to allow for separate choices for plugins, themes, and core (upcoming release). 72 * Removed the checkbox to disable protection. 73 * Merged the protection disabling into the radio button choices for plugins and for themes. 74 * U 54 75 55 76 = 1.0 =
Note: See TracChangeset
for help on using the changeset viewer.