This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

plugin disable admin pages

By: a guest on Oct 8th, 2013  |  syntax: PHP  |  size: 6.50 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*  
  4.  Copyright 2013  Frank Staude  (email : frank@staude.net)
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  19. */
  20.  
  21.  
  22. class disable_author_pages {
  23.  
  24.     /**
  25.      * Constructor
  26.      *
  27.      * Register all actions and filters
  28.      */
  29.     function __construct() {
  30.         add_action( 'template_redirect',    array( 'disable_author_pages', 'disable_author_page' ) );
  31.         add_action( 'admin_init',           array( 'disable_author_pages', 'register_settings' ) );
  32.         add_action( 'admin_menu',           array( 'disable_author_pages', 'options_menu' ) );        
  33.         add_action( 'plugins_loaded',       array( 'disable_author_pages', 'load_translations' ) );
  34.         add_filter( 'author_link',          array( 'disable_author_pages', 'disable_autor_link') );
  35.     }
  36.  
  37.     /**
  38.      * Redirect the user
  39.      *
  40.      * This function is registerd to the template_redirect hook and do the following checks
  41.      * if the current pages a autorpage (is_author) and the Plugin is active, the redirect the
  42.      * user to the selected page (or to the homepage)
  43.      *
  44.      *
  45.      */
  46.     function disable_author_page() {
  47.         if (is_author() && get_option( 'disable_author_pages_activate' ) == 1 ) {
  48.                     $adminonly= get_option( 'disable_author_pages_adminonly', '0' );
  49.                         if ($adminonly && author_can( get_the_ID(), 'administrator' )||!$adminonly){
  50.                                 $status = get_option( 'disable_author_pages_status', '301' );
  51.                                 $url = get_option( 'disable_author_pages_destination', '' );
  52.                                 if ( $url == '' ) {
  53.                                         $url = home_url();
  54.                                 }
  55.                                 wp_redirect( $url, $status );
  56.                                 exit;
  57.                         }
  58.         }
  59.     }
  60.  
  61.     /**
  62.      * Register all settings
  63.      *
  64.      * Register all the settings, the plugin uses.
  65.      */
  66.    function register_settings() {
  67.         register_setting( 'disable_author_pages_settings', 'disable_author_pages_activate' );
  68.         register_setting( 'disable_author_pages_settings', 'disable_author_pages_destination' );
  69.         register_setting( 'disable_author_pages_settings', 'disable_author_pages_status' );
  70.         register_setting( 'disable_author_pages_settings', 'disable_author_pages_authorlink' );
  71.         register_setting( 'disable_author_pages_settings', 'disable_author_pages_adminonly' );         
  72.    }
  73.    
  74.    /**
  75.     * Overwrite the author url with an empty string
  76.     *
  77.     * @param string $content url to author page
  78.     * @return string
  79.     */
  80.    function disable_autor_link( $content ) {
  81.        if ( get_option( 'disable_author_pages_authorlink', '0' ) == 1 ) {
  82.            return "";
  83.        } else {
  84.            return $content;
  85.        }
  86.    }
  87.    
  88.     /**
  89.      * load the plugin textdomain
  90.      *
  91.      * load the plugin textdomain with translations for the backend settingspage
  92.      */
  93.     function load_translations() {
  94.         load_plugin_textdomain( 'disable_author_pages', false, apply_filters ( 'disable_author_pages_translationpath', dirname( plugin_basename( __FILE__ )) . '/languages/' ) );
  95.     }    
  96.  
  97.     /**
  98.      * Generate the options menu page
  99.      *
  100.      * Generate the options page under the options menu
  101.      */
  102.     function options_menu() {
  103.         add_options_page( 'Disable Autor Pages',  __('Author Pages','disable_author_pages', 'hinweis'), 'manage_options',
  104.         __FILE__, array( 'disable_author_pages', 'create_options_disable_author_menu' ) );
  105.     }
  106.  
  107.     /**
  108.      * Generate the options page for the plugin
  109.      *
  110.      * @global type $settings
  111.      */
  112.     function create_options_disable_author_menu() {
  113.         global $settings;
  114.     ?>
  115.     <div class="wrap"  id="disableauthorpages">
  116.     <h2><?php _e( 'Disable Author settings', 'disable_author_pages' ); ?></h2>
  117.     <p><?php _e( 'Settings to disable the author pages.', 'disable_author_pages' ); ?></p>
  118.     <form method="POST" action="options.php">
  119.     <?php
  120.     settings_fields( 'disable_author_pages_settings' );
  121.     echo '<table class="form-table">';
  122.     ?>
  123.     <tr>
  124.         <td style="width: 13px;"><input type="checkbox" name="disable_author_pages_activate" value="1" <?php if ( get_option( 'disable_author_pages_activate' ) ) echo " checked "; ?> /></td>
  125.         <td><?php _e( 'Disable Author Pages', 'disable_author_pages' ); ?></td>
  126.     </tr>
  127.     <tr>
  128.         <td></td>
  129.         <td>
  130.             <select name="disable_author_pages_status">
  131.                 <option value="301" <?php if ( get_option( 'disable_author_pages_status' ) == '301' ) { echo ' selected '; } ?> ><?php _e( '301 (Moved Permanently)', 'disable_author_pages' );?></option>
  132.                 <option value="307" <?php if ( get_option( 'disable_author_pages_status' ) == '307' ) { echo ' selected '; } ?> ><?php _e( '307 (Temporary Redirect)', 'disable_author_pages' );?></option>
  133.             </select> <?php _e( 'HTTP Status', 'disable_author_pages' );?>
  134.         </td>
  135.     </tr>
  136.     <tr>
  137.         <td></td>
  138.         <td>
  139.             <?php  echo wp_dropdown_pages("name=disable_author_pages_destination&echo=0&show_option_none=" . __( 'Homepage', 'disable_author_pages' ) ); ?>
  140.             <?php _e( 'Destinationpage', 'disable_author_pages' ); ?>
  141.         </td>
  142.     </tr>    
  143.     <tr>
  144.         <td></td>
  145.         <td>
  146.             <input type="checkbox" name="disable_author_pages_authorlink" value="1" <?php if ( get_option( 'disable_author_pages_authorlink' ) ) echo " checked "; ?> />
  147.             <?php _e( 'Disable Authorlink', 'disable_author_pages' ); ?>
  148.         </td>
  149.         </tr>
  150.         <tr>
  151.                 <td></td>
  152.         <td>
  153.             <input type="checkbox" name="disable_author_pages_adminonly" value="1" <?php if ( get_option( 'disable_author_pages_adminonly' ) ) echo " checked "; ?> />
  154.             <?php _e( 'Disable for admin authorpages only', 'disable_author_pages' ); ?>
  155.         </td>          
  156.     </tr>
  157.    
  158.     </table>
  159.     <br/>
  160.     <input type="submit" class="button-primary" value="<?php _e('Save Changes', 'disable_author_pages' )?>" />
  161.     </form>
  162.     </div>
  163.     <?php  
  164.     }
  165. }
  166. ?>
clone this paste RAW Paste Data