Changeset 1472336
- Timestamp:
- 08/11/2016 01:58:06 PM (9 years ago)
- Location:
- plugins-genius
- Files:
-
- 3 added
- 2 edited
-
tags/2.1.0 (added)
-
tags/2.1.0/plugins-genius.php (added)
-
tags/2.1.0/readme.txt (added)
-
trunk/plugins-genius.php (modified) (14 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
plugins-genius/trunk/plugins-genius.php
r1471456 r1472336 4 4 Plugin URI: http://www.marcocanestrari.it 5 5 Description: Role-based active plugins manager 6 Version: 2. 0.06 Version: 2.1.0 7 7 Author: Marco Canestrari 8 8 Author URI: http://www.marcocanestrari.it … … 20 20 } 21 21 22 // load other plugins 23 if(WP_ADMIN === true) { 24 25 // we are in the back-end 26 $active; 22 23 // register activation/deactivation hooks 24 register_activation_hook(__FILE__, array( 'PluginsGenius', 'activate' )); 25 register_deactivation_hook(__FILE__, array( 'PluginsGenius', 'deactivate' )); 26 register_uninstall_hook(__FILE__, array( 'PluginsGenius', 'uninstall' )); 27 28 if(get_option('pg_plugin_genius_active') && $_POST['pg_post_action'] != 'pg_restore_defaults') { 29 add_filter('pre_option_active_plugins', array('PluginsGenius','active_plugins')); 30 } 31 32 33 // Load active plugins 34 $active = PluginsGenius::active_plugins(true); 35 foreach($active as $plugin) { 36 37 wp_register_plugin_realpath( $plugin ); 38 include_once($plugin); 27 39 if($_POST['pg_post_action'] == 'pg_save_new_settings') { 28 $my_active_plugins = $_POST['genius']; 29 } else { 30 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 31 } 32 33 34 35 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 36 37 // if PG is first runnuning or has been reset 38 $active = PluginsGenius::wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 39 40 41 } else { 42 43 // if PG is set, load active plugin role-based 44 $current_user = wp_get_current_user(); 45 46 // load role-based active plugins 47 $active = PluginsGenius::wp_get_active_and_valid_genius_plugins($my_active_plugins[$current_user->roles[0]]); 48 49 } 50 51 // activate plugins 52 if ($active) { 53 foreach($active as $plugin) { 54 55 wp_register_plugin_realpath( $plugin ); 56 include_once($plugin); 57 if($_POST['pg_post_action'] == 'pg_save_new_settings') { 58 59 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 60 do_action('activate_' . $plugin); 61 62 63 } 64 65 } 66 } 67 68 // PG must be the only active plugin in standard wp framework 69 if(get_option('pg_plugin_genius_active') != "") { 70 $me_active = array(); 71 $me_active[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 72 update_option('active_plugins',$me_active); 73 } 74 75 76 77 } else { 78 79 // we are in the front-end 80 81 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 82 $active; 83 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 84 85 // if PG is first runnuning or has been reset 86 $active = PluginsGenius::wp_get_active_and_valid_genius_plugins(get_option('pg_old_active_plugins')); 87 88 89 } else { 90 91 // load front-end active plugins 92 $active = PluginsGenius::wp_get_active_and_valid_genius_plugins($my_active_plugins['front']); 93 94 } 95 96 // activate plugins 97 if ($active) { 98 foreach($active as $plugin) { 99 100 wp_register_plugin_realpath( $plugin ); 101 include_once($plugin); 102 103 } 40 41 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 42 do_action('activate_' . $plugin); 43 44 104 45 } 105 46 106 47 } 48 107 49 108 50 class PluginsGenius { … … 116 58 // add menu item 117 59 add_action('admin_menu', array($this,'plugin_menu')); 118 119 120 } 60 add_action('shutdown',array($this,'activate_me'),99); 61 62 } 63 64 65 public static function activate_me() { 66 67 // PG must be the only active plugin in standard wp framework 68 if(get_option('pg_plugin_genius_active') == 1) { 69 $me_active = array(); 70 $me_active[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 71 update_option('active_plugins',$me_active); 72 } 73 74 } 75 76 public static function active_plugins($validate = false) { 77 78 79 80 if(WP_ADMIN === true) { 81 82 if($_POST['pg_post_action'] == 'pg_save_new_settings') { 83 $my_active_plugins = $_POST['genius']; 84 } else { 85 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 86 } 87 88 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 89 90 // if PG is first runnuning or has been reset 91 if($validate) { 92 $active = self::wp_get_active_and_valid_genius_plugins(get_option('active_plugins')); 93 } else { 94 $active = get_option('active_plugins'); 95 96 97 } 98 99 100 101 } else { 102 103 // if PG is set, load active plugin role-based 104 $current_user = wp_get_current_user(); 105 106 // load role-based active plugins 107 if($validate) { 108 $active = self::wp_get_active_and_valid_genius_plugins($my_active_plugins[$current_user->roles[0]]); 109 } else { 110 $active = $my_active_plugins[$current_user->roles[0]]; 111 112 } 113 114 115 116 } 117 118 } else { 119 120 $my_active_plugins = get_option('pg_my_genius_active_plugins'); 121 $active; 122 if(!$my_active_plugins && get_option('pg_plugin_genius_active') == '0') { 123 124 // if PG is first runnuning or has been reset 125 if($validate) { 126 $active = self::wp_get_active_and_valid_genius_plugins(get_option('active_plugins')); 127 } else { 128 $active = get_option('active_plugins'); 129 130 } 131 132 133 134 } else { 135 136 // load front-end active plugins 137 if($validate) { 138 $active = self::wp_get_active_and_valid_genius_plugins($my_active_plugins['front']); 139 } else { 140 $active = $my_active_plugins['front']; 141 142 } 143 144 145 } 146 147 } 148 149 if(basename($_SERVER['PHP_SELF']) == 'plugins.php') { 150 $active[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 151 } 152 153 154 155 return $active; 156 157 } 158 121 159 122 160 // load language files … … 133 171 } 134 172 135 // activating the default values 136 static function activate() { 137 $active_plugins = get_option('active_plugins'); 138 update_option('pg_old_active_plugins',$active_plugins); 139 update_option('pg_plugin_genius_active','0'); 140 } 141 142 // deactivating 143 static function deactivate() { 144 // needed for proper deletion of every option 145 add_action('shutdown',array( $this, 'deactivating' )); 146 147 } 148 149 static function deactivating() { 150 $active_plugins = get_option('pg_old_active_plugins'); 151 update_option('active_plugins',$active_plugins); 152 delete_option('pg_plugin_genius_active'); 153 delete_option('pg_old_active_plugins'); 154 delete_option('pg_my_genius_active_plugins'); 155 } 156 157 // uninstalling 158 static function uninstall() { 159 # delete all data stored 160 delete_option('pg_plugin_genius_active'); 161 delete_option('pg_old_active_plugins'); 162 delete_option('pg_my_genius_active_plugins'); 163 } 173 164 174 165 175 // Menu item … … 190 200 default: 191 201 // default plugin page, alter inactive plugins view 192 echo "<style>.activate {display:none;} .inactive, .update-message {opacity:0.5;} .inactive:hover, .update-message:hover {opacity:1;}</style>"; 202 if(get_option('pg_plugin_genius_active') == 1) { 203 echo "<style>.activate, .deactivate {display:none;} .inactive, .update-message {opacity:0.5;} .inactive:hover, .update-message:hover {opacity:1;}</style>"; 204 echo ' 205 <script type="text/javascript"> 206 jQuery(document).ready(function(){ 207 jQuery("tr[data-slug=\'plugins-genius\'] .deactivate").css("display","inline"); 208 }); 209 210 </script> 211 212 '; 213 } 214 193 215 194 216 // alert message: PG is active … … 261 283 262 284 delete_option('pg_my_genius_active_plugins'); 263 update_option('pg_plugin_genius_active','0'); 285 delete_option('pg_plugin_genius_active'); 286 $active_plugins = get_option('pg_old_active_plugins'); 287 $active_plugins[] = PG_PLUGIN_DIRECTORY . "/plugins-genius.php" ; 288 update_option('active_plugins',$active_plugins); 289 remove_action('shutdown',array('PluginsGenius','activate_me'),99); 264 290 wp_redirect(get_bloginfo('wpurl') . '/wp-admin/plugins.php?tab=genius&pg_post_action=pg_restore_defaults'); 265 291 break; … … 292 318 <h3>'. __("Select plugins to load for each role or in the frontend",PG_GENIUS_LOCALE ) .'</h3> 293 319 <form action="" method="post"> 294 <table class="wp-list-table widefat ">320 <table class="wp-list-table widefat pg-table"> 295 321 <thead><tr><th></th><th class="manage-column column-description">'. __('Installed Plugins') .' ('.(count($all_plugins) -1).')</th>'; 296 322 … … 301 327 302 328 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 303 $count = count(get_option(' pg_old_active_plugins'));329 $count = count(get_option('active_plugins')) - 1; 304 330 } else { 305 331 if($my_genius_active_plugins) { … … 320 346 321 347 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 322 $count = count(get_option(' pg_old_active_plugins'));348 $count = count(get_option('active_plugins')) - 1; 323 349 } else { 324 350 if($my_genius_active_plugins) { … … 363 389 $excluded = $my_genius_active_plugins[$role]; 364 390 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 365 $excluded = get_option(' pg_old_active_plugins');391 $excluded = get_option('active_plugins'); 366 392 } 367 393 $checked = ''; … … 381 407 $excluded = $my_genius_active_plugins['front']; 382 408 if(!$my_genius_active_plugins && get_option('pg_plugin_genius_active') == '0') { 383 $excluded = get_option(' pg_old_active_plugins');409 $excluded = get_option('active_plugins'); 384 410 } 385 411 $checked = ''; … … 434 460 435 461 436 </script>'; 462 </script> 463 <style> 464 .pg-table td {border-bottom: 1px solid #ddd;} 465 </style>'; 437 466 438 467 // Advanced: reset PG to old active plugins … … 456 485 <input type="submit"class="button-primary" value="'.__('Restore original settings',PG_GENIUS_LOCALE).'"> 457 486 <input type="hidden" name="pg_post_action" value="pg_restore_defaults"> 487 <input type="hidden" name="_wpnonce" value="'.wp_create_nonce( 'pg_settings_saved' ).'" /> 458 488 459 489 <br><span class="description">'.__('Restore configuration as it was before activating Plugins Genius.',PG_GENIUS_LOCALE).'</span> … … 504 534 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 505 535 } 536 $active[] = WP_PLUGIN_DIR . '/' . PG_PLUGIN_DIRECTORY . "/plugins-genius.php"; 506 537 return $plugins; 507 538 } 508 539 540 // activating the default values 541 public static function activate() { 542 $active_plugins = get_option('active_plugins'); 543 $key = array_search(PG_PLUGIN_DIRECTORY . "/plugins-genius.php", $active_plugins); 544 if(false !== $key) { 545 unset($active_plugins[$key]); 546 } 547 update_option('pg_old_active_plugins',$active_plugins); 548 if(get_option('pg_my_genius_active_plugins')) { 549 update_option('pg_plugin_genius_active','1'); 550 } 551 552 553 } 554 555 // deactivating 556 public static function deactivate() { 557 // needed for proper deletion of every option 558 559 delete_option('pg_plugin_genius_active'); 560 add_action('shutdown',array('PluginsGenius','deactivating') ); 561 remove_action('shutdown',array('PluginGenius','activate_me'),99); 562 563 } 564 565 public static function deactivating() { 566 $active_plugins = get_option('pg_old_active_plugins'); 567 $key = array_search(PG_PLUGIN_DIRECTORY . "/plugins-genius.php", $active_plugins); 568 if(false !== $key) { 569 unset($active_plugins[$key]); 570 } 571 update_option('active_plugins',$active_plugins); 572 } 573 574 // uninstalling 575 public static function uninstall() { 576 # delete all data stored 577 delete_option('pg_plugin_genius_active'); 578 delete_option('pg_old_active_plugins'); 579 delete_option('pg_my_genius_active_plugins'); 580 } 581 509 582 } 510 583 511 584 new PluginsGenius(); 512 585 513 // register activation/deactivation hooks 514 register_activation_hook(__FILE__, array( 'PluginsGenius', 'activate' )); 515 register_deactivation_hook(__FILE__, array( 'PluginsGenius', 'deactivate' )); 516 register_uninstall_hook(__FILE__, array( 'PluginsGenius', 'uninstall' )); 586 587 588 517 589 518 590 ?> -
plugins-genius/trunk/readme.txt
r1471456 r1472336 33 33 == Changelog == 34 34 35 = 2.1.0 = 36 * Hooked get_option(‘active_plugins’) to return role-based active plugins 37 * Role-based active plugins displayed on classic plugins page 38 35 39 = 2.0.0 = 36 40 * Plugin Genius code is now Object Oriented
Note: See TracChangeset
for help on using the changeset viewer.