SHARE
TWEET

Some Tweaks to WP Document Repository Plugin

cgrymala Sep 9th, 2011 180 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Removes menus from the admin menu that aren't needed on the documents site
  4.  */
  5. add_action( 'admin_menu', 'radl_remove_excess_menus', 99, 0 );
  6. function radl_remove_excess_menus() {
  7.         if( !class_exists( 'RA_Document_Post_Type' ) )
  8.                 return;
  9.        
  10.         $pages_to_remove = array( 'edit.php', 'upload.php', 'link-manager.php', 'edit.php?post_type=page', 'gf_edit_forms' );
  11.         foreach( $pages_to_remove as $p ) {
  12.                 remove_menu_page( $p );
  13.         }
  14. }
  15.  
  16. /**
  17.  * Removes editors' abilities to manage taxonomies on the documents site
  18.  * Removes authors' ability to publish posts on the documents site (they can only save as pending/draft)
  19.  */
  20. add_action( 'init', 'radl_remove_tax_edit_caps', 99, 0 );
  21. function radl_remove_tax_edit_caps() {
  22.         if( !class_exists( 'RA_Document_Post_Type' ) )
  23.                 return;
  24.        
  25.         foreach( array( 'editor' ) as $r ) {
  26.                 $role = get_role( $r );
  27.                 $role->remove_cap( 'manage_categories' );
  28.                 $role->remove_cap( 'manage_terms' );
  29.                 $role->remove_cap( 'edit_terms' );
  30.                 $role->remove_cap( 'delete_terms' );
  31.         }
  32.        
  33.         $role = get_role( 'author' );
  34.         $role->remove_cap( 'publish_posts' );
  35. }
  36.  
  37. /**
  38.  * Removes the Quick Press item from the Document Site dashboard (since we aren't using standard posts in any way)
  39.  */
  40. add_action( 'wp_dashboard_setup', 'radl_remove_quick_press' );
  41. function radl_remove_quick_press() {
  42.         if( !class_exists( 'RA_Document_Post_Type' ) )
  43.                 return;
  44.        
  45.         global $wp_meta_boxes;
  46.         $screen_id = is_network_admin() ? 'dashboard-network' : 'dashboard';
  47.         unset( $wp_meta_boxes[$screen_id]['side']['core']['dashboard_quick_press'] );
  48.        
  49.         return;
  50. }
  51.  
  52. /**
  53.  * Removes the "Insert Gravity Form" button from the document editor
  54.  */
  55. function remove_gforms_media_button_from_document_editor() {
  56.         /**
  57.          * Check to see if this is the document site
  58.          * If not, we exit the function
  59.          */
  60.         if( !class_exists( 'RA_Document_Post_Type' ) )
  61.                 return;
  62.         /**
  63.          * Check to see if we are editing a post or adding a new post
  64.          * If we are doing neither, exit the function
  65.          */
  66.         if( !isset( $_GET['post_type'] ) && ( !isset( $_GET['action'] ) || 'edit' != $_GET['action'] ) )
  67.                 return;
  68.         /**
  69.          * Set a variable with the name of the post_type being edited/added
  70.          */
  71.         $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : get_post_type( $_GET['post'] );
  72.         /**
  73.          * If the post_type is not a document, exit the function
  74.          */
  75.         if( 'umw_document' != $post_type )
  76.                 return;
  77.         /**
  78.          * Assuming we passed all the criteria above, remove the GForms button
  79.          */
  80.         remove_action( 'media_buttons_context', array('RGForms', 'add_form_button') );
  81. }
  82. /**
  83.  * Make sure this action is hooked in after the init action is finished.
  84.  * If we hook into the admin_init action, we avoid having to check to make
  85.  *              sure we're in the admin area (since this action only fires in the admin area)
  86.  */
  87. add_action( 'admin_init', 'remove_gforms_media_button_from_document_editor' );
  88. ?>
RAW Paste Data
Top