Advertisement
Guest User

Untitled

a guest
Jun 30th, 2014
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * bbPress Admin Functions
  5.  *
  6.  * @package bbPress
  7.  * @subpackage Administration
  8.  */
  9.  
  10. // Exit if accessed directly
  11. if ( !defined( 'ABSPATH' ) ) exit;
  12.  
  13. /** Admin Menus ***************************************************************/
  14.  
  15. /**
  16.  * Add a separator to the WordPress admin menus
  17.  *
  18.  * @since bbPress (r2957)
  19.  */
  20. function bbp_admin_separator() {
  21.  
  22.     // Caps necessary where a separator is necessary
  23.     $caps = array(
  24.         'bbp_forums_admin',
  25.         'bbp_topics_admin',
  26.         'bbp_replies_admin',
  27.     );
  28.  
  29.     // Loop through caps, and look for a reason to show the separator
  30.     foreach ( $caps as $cap ) {
  31.         if ( current_user_can( $cap ) ) {
  32.             bbpress()->admin->show_separator = true;
  33.             break;
  34.         }
  35.     }
  36.  
  37.     // Bail if no separator
  38.     if ( false === bbpress()->admin->show_separator ) {
  39.         return;
  40.     }
  41.  
  42.     global $menu;
  43.  
  44.     $menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' );
  45. }
  46.  
  47. /**
  48.  * Tell WordPress we have a custom menu order
  49.  *
  50.  * @since bbPress (r2957)
  51.  *
  52.  * @param bool $menu_order Menu order
  53.  * @return mixed True if separator, false if not
  54.  */
  55. function bbp_admin_custom_menu_order( $menu_order = false ) {
  56.     if ( false === bbpress()->admin->show_separator )
  57.         return $menu_order;
  58.  
  59.     return true;
  60. }
  61.  
  62. /**
  63.  * Move our custom separator above our custom post types
  64.  *
  65.  * @since bbPress (r2957)
  66.  *
  67.  * @param array $menu_order Menu Order
  68.  * @uses bbp_get_forum_post_type() To get the forum post type
  69.  * @return array Modified menu order
  70.  */
  71. function bbp_admin_menu_order( $menu_order ) {
  72.  
  73.     // Bail if user cannot see any top level bbPress menus
  74.     if ( empty( $menu_order ) || ( false === bbpress()->admin->show_separator ) )
  75.         return $menu_order;
  76.  
  77.     // Initialize our custom order array
  78.     $bbp_menu_order = array();
  79.  
  80.     // Menu values
  81.     $second_sep   = 'separator2';
  82.     $custom_menus = array(
  83.         'separator-bbpress',                               // Separator
  84.         'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums
  85.         'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics
  86.         'edit.php?post_type=' . bbp_get_reply_post_type()  // Replies
  87.     );
  88.  
  89.     // Loop through menu order and do some rearranging
  90.     foreach ( $menu_order as $item ) {
  91.  
  92.         // Position bbPress menus above appearance
  93.         if ( $second_sep == $item ) {
  94.  
  95.             // Add our custom menus
  96.             foreach ( $custom_menus as $custom_menu ) {
  97.                 if ( array_search( $custom_menu, $menu_order ) ) {
  98.                     $bbp_menu_order[] = $custom_menu;
  99.                 }
  100.             }
  101.  
  102.             // Add the appearance separator
  103.             $bbp_menu_order[] = $second_sep;
  104.  
  105.         // Skip our menu items
  106.         } elseif ( ! in_array( $item, $custom_menus ) ) {
  107.             $bbp_menu_order[] = $item;
  108.         }
  109.     }
  110.  
  111.     // Return our custom order
  112.     return $bbp_menu_order;
  113. }
  114.  
  115. /**
  116.  * Filter sample permalinks so that certain languages display properly.
  117.  *
  118.  * @since bbPress (r3336)
  119.  *
  120.  * @param string $post_link Custom post type permalink
  121.  * @param object $_post Post data object
  122.  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
  123.  * @param bool $sample Optional, defaults to false. Is it a sample permalink.
  124.  *
  125.  * @uses is_admin() To make sure we're on an admin page
  126.  * @uses bbp_is_custom_post_type() To get the forum post type
  127.  *
  128.  * @return string The custom post type permalink
  129.  */
  130. function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) {
  131.  
  132.     // Bail if not on an admin page and not getting a sample permalink
  133.     if ( !empty( $sample ) && is_admin() && bbp_is_custom_post_type() )
  134.         return urldecode( $post_link );
  135.  
  136.     // Return post link
  137.     return $post_link;
  138. }
  139.  
  140. /**
  141.  * Sanitize permalink slugs when saving the settings page.
  142.  *
  143.  * @since bbPress (r5364)
  144.  *
  145.  * @param string $slug
  146.  * @return string
  147.  */
  148. function bbp_sanitize_slug( $slug = '' ) {
  149.  
  150.     // Don't allow multiple slashes in a row
  151.     $value = preg_replace( '#/+#', '/', str_replace( '#', '', $slug ) );
  152.  
  153.     // Strip out unsafe or unusable chars
  154.     $value = esc_url_raw( $value );
  155.  
  156.     // esc_url_raw() adds a scheme via esc_url(), so let's remove it
  157.     $value = str_replace( 'http://', '', $value );
  158.  
  159.     // Trim off first and last slashes.
  160.     //
  161.     // We already prevent double slashing elsewhere, but let's prevent
  162.     // accidental poisoning of options values where we can.
  163.     $value = ltrim( $value, '/' );
  164.     $value = rtrim( $value, '/' );
  165.  
  166.     // Filter the result and return
  167.     return apply_filters( 'bbp_sanitize_slug', $value, $slug );
  168. }
  169.  
  170. /**
  171. * Uninstall all bbPress options and capabilities from a specific site.
  172. *
  173. * @since bbPress (r3765)
  174. * @param type $site_id
  175. */
  176. function bbp_do_uninstall( $site_id = 0 ) {
  177.     if ( empty( $site_id ) )
  178.         $site_id = get_current_blog_id();
  179.  
  180.     switch_to_blog( $site_id );
  181.     bbp_delete_options();
  182.     bbp_remove_caps();
  183.     flush_rewrite_rules();
  184.     restore_current_blog();
  185. }
  186.  
  187. /**
  188. * Redirect user to bbPress's What's New page on activation
  189. *
  190. * @since bbPress (r4389)
  191. *
  192. * @internal Used internally to redirect bbPress to the about page on activation
  193. *
  194. * @uses get_transient() To see if transient to redirect exists
  195. * @uses delete_transient() To delete the transient if it exists
  196. * @uses is_network_admin() To bail if being network activated
  197. * @uses wp_safe_redirect() To redirect
  198. * @uses add_query_arg() To help build the URL to redirect to
  199. * @uses admin_url() To get the admin URL to index.php
  200. *
  201. * @return If no transient, or in network admin, or is bulk activation
  202. */
  203. function bbp_do_activation_redirect() {
  204.  
  205.     // Bail if no activation redirect
  206.    if ( ! get_transient( '_bbp_activation_redirect' ) ) {
  207.         return;
  208.     }
  209.  
  210.     // Delete the redirect transient
  211.     delete_transient( '_bbp_activation_redirect' );
  212.  
  213.     // Bail if activating from network, or bulk
  214.     if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
  215.         return;
  216.     }
  217.  
  218.     // Bail if the current user cannot see the about page
  219.     if ( ! current_user_can( 'bbp_about_page' ) ) {
  220.         return;
  221.     }
  222.  
  223.     // Redirect to bbPress about page
  224.     wp_safe_redirect( add_query_arg( array( 'page' => 'bbp-about' ), admin_url( 'index.php' ) ) );
  225. }
  226.  
  227. /**
  228. * This tells WP to highlight the Tools > Forums menu item,
  229. * regardless of which actual bbPress Tools screen we are on.
  230. *
  231. * The conditional prevents the override when the user is viewing settings or
  232. * any third-party plugins.
  233. *
  234. * @since bbPress (r3888)
  235. * @global string $plugin_page
  236. * @global array $submenu_file
  237. */
  238. function bbp_tools_modify_menu_highlight() {
  239.     global $plugin_page, $submenu_file;
  240.  
  241.     // This tweaks the Tools subnav menu to only show one bbPress menu item
  242.     if ( ! in_array( $plugin_page, array( 'bbp-settings' ) ) )
  243.         $submenu_file = 'bbp-repair';
  244. }
  245.  
  246. /**
  247. * Output the tabs in the admin area
  248. *
  249. * @since bbPress (r3872)
  250. * @param string $active_tab Name of the tab that is active
  251. */
  252. function bbp_tools_admin_tabs( $active_tab = '' ) {
  253.     echo bbp_get_tools_admin_tabs( $active_tab );
  254. }
  255.  
  256.     /**
  257.      * Output the tabs in the admin area
  258.      *
  259.      * @since bbPress (r3872)
  260.      * @param string $active_tab Name of the tab that is active
  261.      */
  262.     function bbp_get_tools_admin_tabs( $active_tab = '' ) {
  263.  
  264.         // Declare local variables
  265.         $tabs_html    = '';
  266.         $idle_class   = 'nav-tab';
  267.         $active_class = 'nav-tab nav-tab-active';
  268.  
  269.         // Setup core admin tabs
  270.         $tabs = apply_filters( 'bbp_tools_admin_tabs', array(
  271.             '0' => array(
  272.                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair'    ), 'tools.php' ) ),
  273.                 'name' => __( 'Repair Forums', 'bbpress' )
  274.             ),
  275.             '1' => array(
  276.                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ),
  277.                 'name' => __( 'Import Forums', 'bbpress' )
  278.             ),
  279.             '2' => array(
  280.                 'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset'     ), 'tools.php' ) ),
  281.                 'name' => __( 'Reset Forums', 'bbpress' )
  282.             )
  283.         ) );
  284.  
  285.         // Loop through tabs and build navigation
  286.         foreach ( array_values( $tabs ) as $tab_data ) {
  287.             $is_current = (bool) ( $tab_data['name'] == $active_tab );
  288.             $tab_class  = $is_current ? $active_class : $idle_class;
  289.             $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
  290.         }
  291.  
  292.         // Output the tabs
  293.         return $tabs_html;
  294.     }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement