Last active
August 29, 2015 13:59
-
-
Save dboulet/10509260 to your computer and use it in GitHub Desktop.
Disable Blog: Remove Posts and Comments from Wordpress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Disable Blog | |
* Description: Disable Posts and Comments in Wordpress. | |
* Author: Dan Boulet | |
* Author URI: http://danboulet.com/ | |
*/ | |
class Customize_Disable_Blog { | |
/** | |
* Set up actions and filters. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function init() { | |
add_action( 'admin_menu', array( __CLASS__, 'alter_admin_menu' ) ); | |
add_action( 'add_admin_bar_menus', array( __CLASS__, 'remove_admin_bar_menus' ) ); | |
add_action( 'wp_before_admin_bar_render', array( __CLASS__, 'alter_admin_toolbar' ) ); | |
add_action( 'admin_init', array( __CLASS__, 'remove_dashboard_widgets' ) ); | |
add_filter( 'manage_pages_columns', array( __CLASS__, 'remove_comments_columns' ) ); | |
add_filter( 'manage_media_columns', array( __CLASS__, 'remove_comments_columns' ) ); | |
remove_action( 'wp_head', 'feed_links', 2 ); // Remove main feeds. | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove post comments feed. | |
add_action( 'wp_head', array( __CLASS__, 'restore_rss_feed' ), 1 ); // Restore the main feed. | |
} | |
/* | |
* Alter admin menu links. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function alter_admin_menu() { | |
// We don’t need the posts edit page. | |
remove_menu_page( 'edit.php' ); | |
// We don’t need to see comments. | |
remove_menu_page( 'edit-comments.php' ); | |
} | |
/** | |
* Remove menus from the admin bar. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function remove_admin_bar_menus() { | |
// Remove comments menu from admin bar. | |
remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); | |
} | |
/* | |
* Customize links in admin bar. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function alter_admin_toolbar() { | |
global $wp_admin_bar; | |
// Alter the New link. | |
$new_content_link = $wp_admin_bar->get_node( 'new-content' ); | |
$new_content_link->href .= '?post_type=page'; | |
$wp_admin_bar->add_node( $new_content_link ); | |
// Remove link to add a new Post. | |
$wp_admin_bar->remove_menu( 'new-post', 'new-content' ); | |
} | |
/** | |
* Disable Dashboard widgets. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function remove_dashboard_widgets() { | |
// Remove Quick Draft since we aren’t making use of Posts. | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'normal' ); | |
// Don’t display recent comments. | |
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); | |
} | |
/** | |
* Remove comments column from Pages list. | |
*/ | |
public static function remove_comments_columns( $columns ) { | |
unset( $columns['comments'] ); | |
return $columns; | |
} | |
/** | |
* Output main feed link. | |
* | |
* @static | |
* @access public | |
*/ | |
public static function restore_rss_feed() { | |
echo '<link rel="alternate" type="application/rss+xml" title="' . get_bloginfo( 'sitename' ) . ' » Feed" href="' . get_bloginfo( 'rss2_url' ) . '">' . "\n"; | |
} | |
} | |
add_action( 'init', array( 'Customize_Disable_Blog', 'init' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment