Changeset 1471405
- Timestamp:
- 08/10/2016 09:27:42 AM (9 years ago)
- Location:
- plugins-genius/trunk
- Files:
-
- 2 edited
-
plugins-genius.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins-genius/trunk/plugins-genius.php
r1471399 r1471405 4 4 Plugin URI: http://www.marcocanestrari.it 5 5 Description: Role-based active plugins manager 6 Version: 2.0.06 Version: 1.0.0 7 7 Author: Marco Canestrari 8 8 Author URI: http://www.marcocanestrari.it … … 14 14 define( 'PG_GENIUS_LOCALE', 'pg_language' ); 15 15 16 class PluginsGenius { 17 18 function __construct() { 19 // localization 20 $this->set_lang_file(); 21 22 // load configuration page 23 add_action('pre_current_active_plugins', array($this,'plugin_page')); 24 // add menu item 25 add_action('admin_menu', array($this,'plugin_menu')); 26 27 if(!function_exists('wp_get_current_user')) { 28 // Load pluggable functions. Need current user info 29 require( ABSPATH . WPINC . '/pluggable.php' ); 30 require( ABSPATH . WPINC . '/pluggable-deprecated.php' ); 31 } 32 33 // load other plugins 34 if(WP_ADMIN === true) { 35 36 // we are in the back-end 37 $active; 38 if($_POST['pg_post_action'] == 'pg_save_new_settings') { 39 $my_active_plugins = $_POST['genius']; 40 } else { 41 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 42 } 43 44 45 46 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 47 48 // if PG is first runnuning or has been reset 49 $active = $this->wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 50 51 52 } else { 53 54 // if PG is set, load active plugin role-based 55 $current_user = wp_get_current_user(); 56 57 // load role-based active plugins 58 $active = $this->wp_get_active_and_valid_genius_plugins($my_active_plugins[$current_user->roles[0]]); 59 60 } 61 62 // activate plugins 63 if ($active) { 64 foreach($active as $plugin) { 65 66 if($_POST['pg_post_action'] == 'pg_save_new_settings') { 67 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 68 activate_plugin( $plugin); 69 } 70 71 wp_register_plugin_realpath( $plugin ); 72 include_once($plugin); 73 74 } 75 } 76 77 // PG must be the only active plugin in standard wp framework 78 if(get_option('pg_plugin_genius_active') != "") { 79 $me_active = array(); 80 $me_active[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 81 update_option('active_plugins',$me_active); 82 } 83 84 85 86 } else { 87 88 // we are in the front-end 89 90 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 91 $active; 92 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 93 94 // if PG is first runnuning or has been reset 95 $active = $this->wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 96 97 98 } else { 99 100 // load front-end active plugins 101 $active = $this->wp_get_active_and_valid_genius_plugins($my_active_plugins['front']); 102 103 } 104 105 // activate plugins 106 if ($active) { 107 foreach($active as $plugin) { 108 109 wp_register_plugin_realpath( $plugin ); 110 include_once($plugin); 111 112 } 113 } 114 115 } 116 } 117 118 // load language files 119 function set_lang_file() { 120 # set the language file 121 $currentLocale = get_locale(); 122 if(!empty($currentLocale)) { 123 $moFile = dirname(__FILE__) . "/lang/" . $currentLocale . ".mo"; 124 if (@file_exists($moFile) && is_readable($moFile)) { 125 load_textdomain(PG_GENIUS_LOCALE, $moFile); 126 } 127 128 } 129 } 130 131 // activating the default values 132 static function activate() { 133 $active_plugins = get_option('active_plugins'); 134 update_option('pg_old_active_plugins',$active_plugins); 135 update_option('pg_plugin_genius_active','0'); 136 } 137 138 // deactivating 139 static function deactivate() { 140 // needed for proper deletion of every option 141 add_action('shutdown',array( $this, 'deactivating' )); 142 143 } 144 145 static function deactivating() { 146 $active_plugins = get_option('pg_old_active_plugins'); 147 update_option('active_plugins',$active_plugins); 148 delete_option('pg_plugin_genius_active'); 149 delete_option('pg_old_active_plugins'); 150 delete_option('pg_my_genius_active_plugins'); 151 } 152 153 // uninstalling 154 static function uninstall() { 155 # delete all data stored 156 delete_option('pg_plugin_genius_active'); 157 delete_option('pg_old_active_plugins'); 158 delete_option('pg_my_genius_active_plugins'); 159 } 160 161 // Menu item 162 function plugin_menu() { 163 add_submenu_page( 'plugins.php', 'Plugins Genius', 'Plugins Genius', 'install_plugins', 'plugins.php?tab=genius' ); 164 } 165 166 /* 16 if(!function_exists('wp_get_current_user')) { 17 // Load pluggable functions. Need current user info 18 require( ABSPATH . WPINC . '/pluggable.php' ); 19 require( ABSPATH . WPINC . '/pluggable-deprecated.php' ); 20 } 21 22 // Save settings 23 if ($_POST['pg_post_action'] && current_user_can( 'manage_options' ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'pg_settings_saved' )) { 24 25 switch($_POST['pg_post_action']) { 26 case 'pg_save_new_settings': 27 28 update_option('pg_my_genius_active_plugins',$_POST['genius']); 29 update_option('pg_plugin_genius_active','1'); 30 break; 31 32 case 'pg_restore_defaults': 33 34 delete_option('pg_my_genius_active_plugins'); 35 update_option('pg_plugin_genius_active','0'); 36 break; 37 } 38 39 } 40 41 // load other plugins 42 if(WP_ADMIN === true) { 43 44 // we are in the back-end 45 $active; 46 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 47 48 49 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 50 51 // if PG is first runnuning or has been reset 52 $active = wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 53 54 55 } else { 56 57 // if PG is set, load active plugin role-based 58 $current_user = wp_get_current_user(); 59 60 // load role-based active plugins 61 $active = wp_get_active_and_valid_genius_plugins($my_active_plugins[$current_user->roles[0]]); 62 63 } 64 65 // activate plugins 66 if ($active) { 67 foreach($active as $plugin) { 68 69 include_once($plugin); 70 71 } 72 } 73 74 // PG must be the only active plugin in standard wp framework 75 if(get_option('pg_plugin_genius_active') != "") { 76 $me_active = array(); 77 $me_active[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 78 update_option('active_plugins',$me_active); 79 } 80 81 // load configuration page 82 add_action('pre_current_active_plugins','pg_plugin_page'); 83 84 // add menu item 85 add_action('admin_menu', 'pg_plugin_menu'); 86 87 // register activation/deactivation hooks 88 register_activation_hook(__FILE__, 'pg_activate'); 89 register_deactivation_hook(__FILE__, 'pg_deactivate'); 90 register_uninstall_hook(__FILE__, 'pg_uninstall'); 91 92 // localization 93 pg_set_lang_file(); 94 95 96 } else { 97 98 // we are in the front-end 99 100 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 101 $active; 102 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 103 104 // if PG is first runnuning or has been reset 105 $active = wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 106 107 108 } else { 109 110 // load front-end active plugins 111 $active = wp_get_active_and_valid_genius_plugins($my_active_plugins['front']); 112 113 } 114 115 // activate plugins 116 if ($active) { 117 foreach($active as $plugin) { 118 119 include_once($plugin); 120 121 } 122 } 123 124 } 125 126 // Menu item 127 function pg_plugin_menu() { 128 add_submenu_page( 'plugins.php', 'Plugins Genius', 'Plugins Genius', 'install_plugins', 'plugins.php?tab=genius' ); 129 } 130 131 // load language files 132 function pg_set_lang_file() { 133 # set the language file 134 $currentLocale = get_locale(); 135 if(!empty($currentLocale)) { 136 $moFile = dirname(__FILE__) . "/lang/" . $currentLocale . ".mo"; 137 if (@file_exists($moFile) && is_readable($moFile)) { 138 load_textdomain(PG_GENIUS_LOCALE, $moFile); 139 } 140 141 } 142 } 143 144 // activating the default values 145 function pg_activate() { 146 $active_plugins = get_option('active_plugins'); 147 update_option('pg_old_active_plugins',$active_plugins); 148 update_option('pg_plugin_genius_active','0'); 149 } 150 151 // deactivating 152 function pg_deactivate() { 153 // needed for proper deletion of every option 154 add_action('shutdown','pg_deactivating'); 155 156 } 157 function pg_deactivating() { 158 $active_plugins = get_option('pg_old_active_plugins'); 159 update_option('active_plugins',$active_plugins); 160 delete_option('pg_plugin_genius_active'); 161 delete_option('pg_old_active_plugins'); 162 delete_option('pg_my_genius_active_plugins'); 163 } 164 165 // uninstalling 166 function pg_uninstall() { 167 # delete all data stored 168 delete_option('pg_plugin_genius_active'); 169 delete_option('pg_old_active_plugins'); 170 delete_option('pg_my_genius_active_plugins'); 171 } 172 173 /* 167 174 Configuration page, alters plugins page 168 */ 169 function plugin_page() { 170 171 // show alert messages 172 $this->settings_saved(); 173 174 // Set and load tabs 175 $tab = isset($_GET['tab']) ? $_GET['tab'] : "plugins"; 176 $this->tabs($tab); 177 178 179 switch ($tab) { 180 181 case 'genius': 182 // tab Genius: configure active plugins 183 $this->config(); 184 break; 185 186 default: 187 // default plugin page, alter inactive plugins view 188 echo "<style>.activate {display:none;} .inactive, .update-message {opacity:0.5;} .inactive:hover, .update-message:hover {opacity:1;}</style>"; 189 190 // alert message: PG is active 191 echo '<div id="pg-warning" class="updated fade"><p><strong>' .__("Plugins Genius is active",PG_GENIUS_LOCALE ) .'</strong>. '.__("To configure active plugins, go to",PG_GENIUS_LOCALE ) .' <a href="?tab=genius">'.__("Plugins Genius configuration page",PG_GENIUS_LOCALE ) .'</a>.</p></div>'; 192 } 193 } 194 195 /* 196 Shows alert messages 197 */ 198 function settings_saved() { 199 200 switch($_POST['pg_post_action']) { 201 case 'pg_save_new_settings': 202 echo '<div id="pg-warning" class="updated fade"><p><strong>Plugins Genius: </strong>'.__("new settings saved",PG_GENIUS_LOCALE ) .'.</p></div>'; 203 break; 204 case 'pg_restore_defaults': 205 echo '<div id="pg-warning" class="updated fade"><p><strong>Plugins Genius: </strong>'.__("original settings restored",PG_GENIUS_LOCALE ) .'.</p></div>'; 206 break; 207 } 208 209 210 } 211 212 // Configure tabs 213 function tabs($current = 'plugins') { 214 $tabs = array('plugins' => __('Installed Plugins'), 'genius' => __('Plugins Genius', PG_GENIUS_LOCALE)); 215 $links = array(); 216 foreach( $tabs as $tab => $name ) { 217 if ( $tab == $current ) { 218 $links[] = "<a class='nav-tab nav-tab-active' href='?tab=".$tab."'>$name</a>"; 219 } else { 220 $links[] = "<a class='nav-tab' href='?tab=".$tab."'>$name</a>"; 221 } 222 } 223 224 echo '<h3 class="nav-tab-wrapper">'; 225 foreach ( $links as $link ) { 226 echo $link; 227 } 228 echo '</h3>'; 229 } 230 231 /* 175 */ 176 function pg_plugin_page() { 177 178 // show alert messages 179 pg_settings_saved(); 180 181 // Set and load tabs 182 $tab = isset($_GET['tab']) ? $_GET['tab'] : "plugins"; 183 pg_tabs($tab); 184 185 186 switch ($tab) { 187 188 case 'genius': 189 // tab Genius: configure active plugins 190 pg_config(); 191 break; 192 193 default: 194 // default plugin page, alter inactive plugins view 195 echo "<style>.activate {display:none;} .inactive, .update-message {opacity:0.5;} .inactive:hover, .update-message:hover {opacity:1;}</style>"; 196 197 // alert message: PG is active 198 echo '<div id="pg-warning" class="updated fade"><p><strong>' .__("Plugins Genius is active",PG_GENIUS_LOCALE ) .'</strong>. '.__("To configure active plugins, go to",PG_GENIUS_LOCALE ) .' <a href="?tab=genius">'.__("Plugins Genius configuration page",PG_GENIUS_LOCALE ) .'</a>.</p></div>'; 199 } 200 } 201 202 /* 232 203 PG Configuration page 233 */ 234 function config() { 235 236 global $wp_roles; 237 238 // Save settings 239 if ($_POST['pg_post_action'] && current_user_can( 'manage_options' ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'pg_settings_saved' )) { 240 241 switch($_POST['pg_post_action']) { 242 case 'pg_save_new_settings': 243 244 update_option('pg_my_genius_active_plugins',$_POST['genius']); 245 update_option('pg_plugin_genius_active','1'); 246 wp_redirect('/wp-admin/plugins.php?tab=genius'); 247 break; 248 249 case 'pg_restore_defaults': 250 251 delete_option('pg_my_genius_active_plugins'); 252 update_option('pg_plugin_genius_active','0'); 253 break; 254 } 255 256 } 257 258 259 260 // Hide standard plugins page 261 echo '<style>.plugins, .tablenav, .subsubsub, .search-box {display:none;} .pg_counter {margin-left: 1px;}</style>'; 262 263 // Load configuration 264 $my_genius_active_plugins = get_option('pg_my_genius_active_plugins'); 265 266 echo ' <div style="float:right;"> 267 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> 268 <input type="hidden" name="cmd" value="_s-xclick"> 269 <input type="hidden" name="hosted_button_id" value="WGVV5FF7AKRBQ"> 270 <input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal Ð The safer, easier way to pay online."> 271 <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1"> 272 </form> 273 </div>'; 274 275 // prepare table 276 $all_plugins = get_plugins(); 277 278 echo ' 279 <h2>'. __("Manage plugins loading",PG_GENIUS_LOCALE ) .'</h2> 280 <h3>'. __("Select plugins to load for each role or in the frontend",PG_GENIUS_LOCALE ) .'</h3> 281 <form action="" method="post"> 282 <table class="wp-list-table widefat"> 283 <thead><tr><th></th><th class="manage-column column-description">'. __('Installed Plugins') .' ('.(count($all_plugins) -1).')</th>'; 284 285 // Roles 286 foreach( $wp_roles->role_names as $role => $name ) { 287 288 $count; 289 290 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 291 $count = count(get_option('pg_old_active_plugins')); 292 } else { 293 if($my_genius_active_plugins) { 294 $count = count($my_genius_active_plugins[$role],0); 295 } else { 296 $count = '0'; 297 } 298 299 } 300 301 echo '<th style="text-align:center;" class="manage-column column-description">'.translate_user_role($name).'<br><small class="pg_counter">('.$count.' '.__('active',PG_GENIUS_LOCALE).')</small></th>'; 302 303 304 } 305 306 // Front-end 204 */ 205 function pg_config() { 206 global $wp_roles; 207 208 // Hide standard plugins page 209 echo '<style>.plugins, .tablenav, .subsubsub, .search-box {display:none;} .pg_counter {margin-left: 1px;}</style>'; 210 211 // Load configuration 212 $my_genius_active_plugins = get_option('pg_my_genius_active_plugins'); 213 214 echo ' <div style="float:right;"> 215 <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> 216 <input type="hidden" name="cmd" value="_s-xclick"> 217 <input type="hidden" name="hosted_button_id" value="WGVV5FF7AKRBQ"> 218 <input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal Ð The safer, easier way to pay online."> 219 <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1"> 220 </form> 221 </div>'; 222 223 // prepare table 224 $all_plugins = get_plugins(); 225 226 echo ' 227 <h2>'. __("Manage plugins loading",PG_GENIUS_LOCALE ) .'</h2> 228 <h3>'. __("Select plugins to load for each role or in the frontend",PG_GENIUS_LOCALE ) .'</h3> 229 <form action="" method="post"> 230 <table class="wp-list-table widefat"> 231 <thead><tr><th></th><th class="manage-column column-description">'. __('Installed Plugins') .' ('.(count($all_plugins) -1).')</th>'; 232 233 // Roles 234 foreach( $wp_roles->role_names as $role => $name ) { 235 307 236 $count; 308 237 309 238 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 310 239 $count = count(get_option('pg_old_active_plugins')); 311 240 } else { 312 241 if($my_genius_active_plugins) { 313 $count = count($my_genius_active_plugins[ 'front'],0);242 $count = count($my_genius_active_plugins[$role],0); 314 243 } else { 315 244 $count = '0'; 316 245 } 317 318 } 319 echo '<th style="text-align:center;" class="manage-column column-description">'. __("Frontend",PG_GENIUS_LOCALE ) .'<br><small class="pg_counter">('.$count.' '.__('active',PG_GENIUS_LOCALE).')</small></th>'; 320 321 322 echo '</tr></thead>'; 323 324 // Select all checkboxes 325 // Main 326 echo '<tr style="background:#eee;"><td><input type="checkbox" id="pg_checkbox" onclick="selectAllInput(\'pg_checkbox\')"/></td><td></td>'; 327 328 // Roles 329 $cols = 0; 330 foreach( $wp_roles->role_names as $role => $name ) { 331 332 echo '<td style="text-align:center;"><input type="checkbox" class="pg_checkbox" id="col_'.$cols.'" onclick="selectAllInput(\'col_\'+'.$cols.')"/></td>'; 333 $cols++; 334 335 } 246 247 } 248 249 echo '<th style="text-align:center;" class="manage-column column-description">'.translate_user_role($name).'<br><small class="pg_counter">('.$count.' '.__('active',PG_GENIUS_LOCALE).')</small></th>'; 250 251 252 } 253 254 // Front-end 255 $count; 256 257 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 258 $count = count(get_option('pg_old_active_plugins')); 259 } else { 260 if($my_genius_active_plugins) { 261 $count = count($my_genius_active_plugins['front'],0); 262 } else { 263 $count = '0'; 264 } 265 266 } 267 echo '<th style="text-align:center;" class="manage-column column-description">'. __("Frontend",PG_GENIUS_LOCALE ) .'<br><small class="pg_counter">('.$count.' '.__('active',PG_GENIUS_LOCALE).')</small></th>'; 268 269 270 echo '</tr></thead>'; 271 272 // Select all checkboxes 273 // Main 274 echo '<tr style="background:#eee;"><td><input type="checkbox" id="pg_checkbox" onclick="selectAllInput(\'pg_checkbox\')"/></td><td></td>'; 275 276 // Roles 277 $cols = 0; 278 foreach( $wp_roles->role_names as $role => $name ) { 279 336 280 echo '<td style="text-align:center;"><input type="checkbox" class="pg_checkbox" id="col_'.$cols.'" onclick="selectAllInput(\'col_\'+'.$cols.')"/></td>'; 337 338 echo '</tr>'; 339 340 $rows = 0; 341 342 // Iterate plugins 343 foreach($all_plugins as $key => $plugin) { 344 345 if($key != "plugins-genius/plugins-genius.php") { 346 347 // Select all checkboxes: for plugin 348 echo '<tr><td><input type="checkbox" class="pg_checkbox" id="row_'.$rows.'" onclick="selectAllInput(\'row_\'+'.$rows.')"/></td><td><strong>'.$plugin['Name'].'</strong></td></td>'; 349 $cols = 0; 350 foreach( $wp_roles->role_names as $role => $name ) { 351 $excluded = $my_genius_active_plugins[$role]; 352 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 353 $excluded = get_option('pg_old_active_plugins'); 354 } 355 $checked = ''; 356 if($excluded) { 357 foreach($excluded as $p){ 358 if ($p == $key) { 359 $checked = 'checked'; 360 } 361 } 362 } 363 364 // Checkbox 365 echo '<td style="text-align:center;" class="column-description desc"><input type="checkbox" '.$checked.' name="genius['.$role.'][]" value="'.$key.'" class="pg_checkbox row_'.$rows.' col_'.$cols.'"/> </td>'; 366 $cols++; 367 } 368 369 $excluded = $my_genius_active_plugins['front']; 281 $cols++; 282 283 } 284 echo '<td style="text-align:center;"><input type="checkbox" class="pg_checkbox" id="col_'.$cols.'" onclick="selectAllInput(\'col_\'+'.$cols.')"/></td>'; 285 286 echo '</tr>'; 287 288 $rows = 0; 289 290 // Iterate plugins 291 foreach($all_plugins as $key => $plugin) { 292 293 if($key != "plugins-genius/plugins-genius.php") { 294 295 // Select all checkboxes: for plugin 296 echo '<tr><td><input type="checkbox" class="pg_checkbox" id="row_'.$rows.'" onclick="selectAllInput(\'row_\'+'.$rows.')"/></td><td><strong>'.$plugin['Name'].'</strong></td></td>'; 297 $cols = 0; 298 foreach( $wp_roles->role_names as $role => $name ) { 299 $excluded = $my_genius_active_plugins[$role]; 370 300 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 371 301 $excluded = get_option('pg_old_active_plugins'); … … 379 309 } 380 310 } 381 382 echo '<td style="text-align:center;" class="column-description desc"><input type="checkbox" '.$checked.' name="genius[front][]" value="'.$key.'" class="pg_checkbox row_'.$rows.' col_'.$cols.'"/> </td>'; 311 312 // Checkbox 313 echo '<td style="text-align:center;" class="column-description desc"><input type="checkbox" '.$checked.' name="genius['.$role.'][]" value="'.$key.'" class="pg_checkbox row_'.$rows.' col_'.$cols.'"/> </td>'; 314 $cols++; 383 315 } 384 385 $rows++; 386 387 } 388 389 390 391 echo '<tfoot><tr><th></th><th class="manage-column column-description">'. __('Installed Plugins') .'</th>'; 392 393 foreach( $wp_roles->role_names as $role => $name ) { 394 395 echo '<th style="text-align:center;" class="manage-column column-description">'.translate_user_role($name).'</th>'; 396 397 } 398 echo '<th style="text-align:center;" class="manage-column column-description">'. __("Frontend",PG_GENIUS_LOCALE ) .'</th>'; 399 echo '</tr></tfoot>'; 400 echo ' 401 </table> 402 <div class="clear" style="margin-top: 10px;"></div> 403 <input type="hidden" name="pg_post_action" value="pg_save_new_settings"> 404 <input type="hidden" name="_wpnonce" value="'.wp_create_nonce( 'pg_settings_saved' ).'" /> 405 <input type="submit" name="submit_button" class="button-primary" value="'.__('Save').'" /> 406 </form></p> 407 408 <script type="text/javascript"> 409 410 function selectAllInput(myClass) { 411 412 413 jQuery("."+myClass).each(function() { 414 if(jQuery("#"+myClass).is(\':checked\')) { 415 this.checked = true; 416 } else { 417 418 this.checked = false; 316 317 $excluded = $my_genius_active_plugins['front']; 318 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 319 $excluded = get_option('pg_old_active_plugins'); 320 } 321 $checked = ''; 322 if($excluded) { 323 foreach($excluded as $p){ 324 if ($p == $key) { 325 $checked = 'checked'; 419 326 } 420 } );327 } 421 328 } 422 423 424 </script>'; 425 426 // Advanced: reset PG to old active plugins 427 echo ' 428 <div class="metabox-holder"> 429 430 431 <div id="post-body-content"> 432 <div class="postbox meta-box-sortables ui-sortable" > 433 <form action="" method="post"> 434 <h3 class="hndle"><span>'.__('Advanced').'</span></h3> 435 436 <div class="inside"> 437 438 <table class="form-table"> 439 <tbody> 440 <tr> 441 <th>'.__('Original settings',PG_GENIUS_LOCALE).'</th> 442 <td> 443 444 <input type="submit"class="button-primary" value="'.__('Restore original settings',PG_GENIUS_LOCALE).'"> 445 <input type="hidden" name="pg_post_action" value="pg_restore_defaults"> 446 447 <br><span class="description">'.__('Restore configuration as it was before activating Plugins Genius.',PG_GENIUS_LOCALE).'</span> 448 </td> 449 </tr> 450 </tbody> 451 </table> 452 453 </div> 454 </form> 455 </div> 329 330 echo '<td style="text-align:center;" class="column-description desc"><input type="checkbox" '.$checked.' name="genius[front][]" value="'.$key.'" class="pg_checkbox row_'.$rows.' col_'.$cols.'"/> </td>'; 331 } 332 333 $rows++; 334 335 } 336 337 338 339 echo '<tfoot><tr><th></th><th class="manage-column column-description">'. __('Installed Plugins') .'</th>'; 340 341 foreach( $wp_roles->role_names as $role => $name ) { 342 343 echo '<th style="text-align:center;" class="manage-column column-description">'.translate_user_role($name).'</th>'; 344 345 } 346 echo '<th style="text-align:center;" class="manage-column column-description">'. __("Frontend",PG_GENIUS_LOCALE ) .'</th>'; 347 echo '</tr></tfoot>'; 348 echo ' 349 </table> 350 <div class="clear" style="margin-top: 10px;"></div> 351 <input type="hidden" name="pg_post_action" value="pg_save_new_settings"> 352 <input type="hidden" name="_wpnonce" value="'.wp_create_nonce( 'pg_settings_saved' ).'" /> 353 <input type="submit" name="submit_button" class="button-primary" value="'.__('Save').'" /> 354 </form></p> 355 356 <script type="text/javascript"> 357 358 function selectAllInput(myClass) { 359 360 361 jQuery("."+myClass).each(function() { 362 if(jQuery("#"+myClass).is(\':checked\')) { 363 this.checked = true; 364 } else { 365 366 this.checked = false; 367 } 368 }); 369 } 370 371 372 </script>'; 373 374 // Advanced: reset PG to old active plugins 375 echo ' 376 <div class="metabox-holder"> 377 378 379 <div id="post-body-content"> 380 <div class="postbox meta-box-sortables ui-sortable" > 381 <form action="" method="post"> 382 <h3 class="hndle"><span>'.__('Advanced').'</span></h3> 383 384 <div class="inside"> 385 386 <table class="form-table"> 387 <tbody> 388 <tr> 389 <th>'.__('Original settings',PG_GENIUS_LOCALE).'</th> 390 <td> 391 392 <input type="submit"class="button-primary" value="'.__('Restore original settings',PG_GENIUS_LOCALE).'"> 393 <input type="hidden" name="pg_post_action" value="pg_restore_defaults"> 394 395 <br><span class="description">'.__('Restore configuration as it was before activating Plugins Genius.',PG_GENIUS_LOCALE).'</span> 396 </td> 397 </tr> 398 </tbody> 399 </table> 400 401 </div> 402 </form> 456 403 </div> 457 458 459 460 404 </div> 461 462 463 '; 464 465 } 466 467 /* 405 406 407 408 </div> 409 410 411 '; 412 413 } 414 415 416 // Configure tabs 417 function pg_tabs($current = 'plugins') { 418 $tabs = array('plugins' => __('Installed Plugins'), 'genius' => __('Plugins Genius', PG_GENIUS_LOCALE)); 419 $links = array(); 420 foreach( $tabs as $tab => $name ) { 421 if ( $tab == $current ) { 422 $links[] = "<a class='nav-tab nav-tab-active' href='?tab=".$tab."'>$name</a>"; 423 } else { 424 $links[] = "<a class='nav-tab' href='?tab=".$tab."'>$name</a>"; 425 } 426 } 427 428 echo '<h3 class="nav-tab-wrapper">'; 429 foreach ( $links as $link ) { 430 echo $link; 431 } 432 echo '</h3>'; 433 } 434 435 /* 468 436 Verifies if plugins exists and can be loaded 469 */ 470 public function wp_get_active_and_valid_genius_plugins($active_plugins) { 471 472 $plugins = array(); 473 474 // Check for hacks file if the option is enabled 475 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 476 _deprecated_file( 'my-hacks.php', '1.5' ); 477 array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 478 } 479 480 if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) ) 481 return $plugins; 482 483 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 484 485 foreach ( $active_plugins as $plugin ) { 486 if ( ! validate_file( $plugin ) // $plugin must validate as file 487 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 488 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 489 // not already included as a network plugin 490 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) ) 491 ) 492 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 493 } 437 */ 438 function wp_get_active_and_valid_genius_plugins($active_plugins) { 439 $plugins = array(); 440 441 // Check for hacks file if the option is enabled 442 if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 443 _deprecated_file( 'my-hacks.php', '1.5' ); 444 array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 445 } 446 447 if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) ) 494 448 return $plugins; 495 } 496 497 } 498 499 new PluginsGenius(); 500 501 // register activation/deactivation hooks 502 register_activation_hook(__FILE__, array( 'PluginsGenius', 'activate' )); 503 register_deactivation_hook(__FILE__, array( 'PluginsGenius', 'deactivate' )); 504 register_uninstall_hook(__FILE__, array( 'PluginsGenius', 'uninstall' )); 449 450 $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 451 452 foreach ( $active_plugins as $plugin ) { 453 if ( ! validate_file( $plugin ) // $plugin must validate as file 454 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 455 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 456 // not already included as a network plugin 457 && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) ) 458 ) 459 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 460 } 461 return $plugins; 462 } 463 464 /* 465 Shows alert messages 466 */ 467 function pg_settings_saved() { 468 469 switch($_POST['pg_post_action']) { 470 case 'pg_save_new_settings': 471 echo '<div id="pg-warning" class="updated fade"><p><strong>Plugins Genius: </strong>'.__("new settings saved",PG_GENIUS_LOCALE ) .'.</p></div>'; 472 break; 473 case 'pg_restore_defaults': 474 echo '<div id="pg-warning" class="updated fade"><p><strong>Plugins Genius: </strong>'.__("original settings restored",PG_GENIUS_LOCALE ) .'.</p></div>'; 475 break; 476 } 477 478 479 } 480 481 505 482 506 483 ?> -
plugins-genius/trunk/readme.txt
r1471399 r1471405 4 4 Tags: plugin, plugins, role, roles, wordpress, admin, frontend, backend, speed 5 5 Requires at least: 3.0.0 6 Tested up to: 4. 67 Stable tag: 2.0.06 Tested up to: 4.4 7 Stable tag: 1.0.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 32 32 33 33 == Changelog == 34 35 = 2.0.0 =36 * Plugin Genius code is now Object Oriented37 * Activaction hooks are now fired when a new plugin is activated within Plugins Genius38 * Fixed a bug that caused some plugins not beeing correctly loaded39 40 34 = 1.0.0 = 41 35 * Added nonce security
Note: See TracChangeset
for help on using the changeset viewer.