Advertisement
PeterC66

TNG Plugin Remover

Jun 26th, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: TNG Plugin Remover (tpr)
  4. Plugin URI: http://www.hcnhistory.org.uk
  5. Description:  Removes some plugins from TNG pages
  6. Author: Peter Cooper and Kamil Grzegorczyk
  7. Version: 1.0
  8. Author URI: http://www.hcnhistory.org.uk
  9. */
  10.  
  11. /*
  12.  * This is based on Cart66 remover from http://lowgravity.pl/blog/quick-tip-how-to-disable-wp-plugin-on-certain-page/
  13.  * (see also https://gist.github.com/markjaquith/1044546 for something similar and better comments)
  14.  *
  15.  * It is needed because TNG and some WordPress plugins (e.g. Tippy) can conflict (e.g. because of multiple jQuery loads)
  16.  * It avoids the conflict by simply preventing listed plugins from being loaded on TNG pages.
  17.  *
  18.  * To adapt this code for your WordPress/TNG integration, TAILOR it where indicated and save in your wp-content\mu-plugins\ folder
  19.  * mu means Must Use - plugins in here are run before everything else - see http://codex.wordpress.org/Must_Use_Plugins
  20.  */
  21.  
  22. // This is the code that filters out listed plugins before any are loaded
  23. add_filter( 'option_active_plugins', 'tpr_disable_some_plugins' );
  24.  
  25. function tpr_disable_some_plugins($plugins){
  26.     // Do the disabling only for TNG pages, and make sure that it is not done for admin screens
  27.     // TAILOR by replacing my blank-for-people by the slug of your blank page for TNG
  28.    
  29.     if(strpos($_SERVER['REQUEST_URI'], '/blank-for-people/') !== FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
  30.  
  31.         // TAILOR by repeating the call to tpr_disable for each plugin you want to disable
  32.         //   the first argument is the name of the main php file of the plugin relative to the wp-content\plugins\ folder
  33.         // I have included most plugins even though they do not conflict, to reduce load times and possible  future conflict
  34.         //  although for this snippet I have removed most of them
  35.        
  36.         tpr_disable( '404-notifier/404-notifier.php', $plugins );
  37.         tpr_disable( 'broken-link-checker/broken-link-checker.php', $plugins );
  38.     }
  39.  
  40.     return $plugins;
  41. }
  42.  
  43. /**
  44.  * Disable a plugin given as filename (e.g. 'cart66/cart66.php') by removing it from the $plugins array
  45.  * Note the $plugins array argument is handled 'by reference' as it preceded by '&'
  46.  */
  47. function tpr_disable( $file , &$plugins ) {
  48.     $key = array_search( $file , $plugins );
  49.  
  50.     if ( false !== $key ) {
  51.         unset( $plugins[$key] );
  52.     }
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement