| 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 |
// Prevent duplicate separators when no new menu items exist |
| 23 |
if ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) ) |
| 24 |
return; |
| 25 |
|
| 26 |
// Prevent duplicate separators when no core menu items exist |
| 27 |
if ( !current_user_can( 'manage_options' ) ) |
| 28 |
return; |
| 29 |
|
| 30 |
global $menu; |
| 31 |
|
| 32 |
$menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Tell WordPress we have a custom menu order |
| 37 |
* |
| 38 |
* @since bbPress (r2957) |
| 39 |
* |
| 40 |
* @param bool $menu_order Menu order |
| 41 |
* @return bool Always true |
| 42 |
*/ |
| 43 |
function bbp_admin_custom_menu_order( $menu_order = false ) { |
| 44 |
if ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) ) |
| 45 |
return $menu_order; |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Move our custom separator above our custom post types |
| 52 |
* |
| 53 |
* @since bbPress (r2957) |
| 54 |
* |
| 55 |
* @param array $menu_order Menu Order |
| 56 |
* @uses bbp_get_forum_post_type() To get the forum post type |
| 57 |
* @return array Modified menu order |
| 58 |
*/ |
| 59 |
function bbp_admin_menu_order( $menu_order ) { |
| 60 |
|
| 61 |
// Bail if user cannot see any top level bbPress menus |
| 62 |
if ( empty( $menu_order ) || ( !current_user_can( 'edit_forums' ) && !current_user_can( 'edit_topics' ) && !current_user_can( 'edit_replies' ) ) ) |
| 63 |
return $menu_order; |
| 64 |
|
| 65 |
// Initialize our custom order array |
| 66 |
$bbp_menu_order = array(); |
| 67 |
|
| 68 |
// Menu values |
| 69 |
$second_sep = 'separator2'; |
| 70 |
$custom_menus = array( |
| 71 |
'separator-bbpress', // Separator |
| 72 |
'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums |
| 73 |
'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics |
| 74 |
'edit.php?post_type=' . bbp_get_reply_post_type() // Replies |
| 75 |
); |
| 76 |
|
| 77 |
// Loop through menu order and do some rearranging |
| 78 |
foreach ( $menu_order as $item ) { |
| 79 |
|
| 80 |
// Position bbPress menus above appearance |
| 81 |
if ( $second_sep == $item ) { |
| 82 |
|
| 83 |
// Add our custom menus |
| 84 |
foreach( $custom_menus as $custom_menu ) { |
| 85 |
if ( array_search( $custom_menu, $menu_order ) ) { |
| 86 |
$bbp_menu_order[] = $custom_menu; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
// Add the appearance separator |
| 91 |
$bbp_menu_order[] = $second_sep; |
| 92 |
|
| 93 |
// Skip our menu items |
| 94 |
} elseif ( ! in_array( $item, $custom_menus ) ) { |
| 95 |
$bbp_menu_order[] = $item; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
// Return our custom order |
| 100 |
return $bbp_menu_order; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Filter sample permalinks so that certain languages display properly. |
| 105 |
* |
| 106 |
* @since bbPress (r3336) |
| 107 |
* |
| 108 |
* @param string $post_link Custom post type permalink |
| 109 |
* @param object $_post Post data object |
| 110 |
* @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. |
| 111 |
* @param bool $sample Optional, defaults to false. Is it a sample permalink. |
| 112 |
* |
| 113 |
* @uses is_admin() To make sure we're on an admin page |
| 114 |
* @uses bbp_is_custom_post_type() To get the forum post type |
| 115 |
* |
| 116 |
* @return string The custom post type permalink |
| 117 |
*/ |
| 118 |
function bbp_filter_sample_permalink( $post_link, $_post, $leavename = false, $sample = false ) { |
| 119 |
|
| 120 |
// Bail if not on an admin page and not getting a sample permalink |
| 121 |
if ( !empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) |
| 122 |
return urldecode( $post_link ); |
| 123 |
|
| 124 |
// Return post link |
| 125 |
return $post_link; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Uninstall all bbPress options and capabilities from a specific site. |
| 130 |
* |
| 131 |
* @since bbPress (r3765) |
| 132 |
* @param type $site_id |
| 133 |
*/ |
| 134 |
function bbp_do_uninstall( $site_id = 0 ) { |
| 135 |
if ( empty( $site_id ) ) |
| 136 |
$site_id = get_current_blog_id(); |
| 137 |
|
| 138 |
switch_to_blog( $site_id ); |
| 139 |
bbp_delete_options(); |
| 140 |
bbp_remove_caps(); |
| 141 |
flush_rewrite_rules(); |
| 142 |
restore_current_blog(); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* This tells WP to highlight the Tools > Forums menu item, |
| 147 |
* regardless of which actual bbPress Tools screen we are on. |
| 148 |
* |
| 149 |
* The conditional prevents the override when the user is viewing settings or |
| 150 |
* any third-party plugins. |
| 151 |
* |
| 152 |
* @since bbPress (r3888) |
| 153 |
* @global string $plugin_page |
| 154 |
* @global array $submenu_file |
| 155 |
*/ |
| 156 |
function bbp_tools_modify_menu_highlight() { |
| 157 |
global $plugin_page, $submenu_file; |
| 158 |
|
| 159 |
// This tweaks the Tools subnav menu to only show one bbPress menu item |
| 160 |
if ( ! in_array( $plugin_page, array( 'bbp-settings' ) ) ) |
| 161 |
$submenu_file = 'bbp-repair'; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Output the tabs in the admin area |
| 166 |
* |
| 167 |
* @since bbPress (r3872) |
| 168 |
* @param string $active_tab Name of the tab that is active |
| 169 |
*/ |
| 170 |
function bbp_tools_admin_tabs( $active_tab = '' ) { |
| 171 |
echo bbp_get_tools_admin_tabs( $active_tab ); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Output the tabs in the admin area |
| 176 |
* |
| 177 |
* @since bbPress (r3872) |
| 178 |
* @param string $active_tab Name of the tab that is active |
| 179 |
*/ |
| 180 |
function bbp_get_tools_admin_tabs( $active_tab = '' ) { |
| 181 |
|
| 182 |
// Declare local variables |
| 183 |
$tabs_html = ''; |
| 184 |
$idle_class = 'nav-tab'; |
| 185 |
$active_class = 'nav-tab nav-tab-active'; |
| 186 |
|
| 187 |
// Setup core admin tabs |
| 188 |
$tabs = apply_filters( 'bbp_tools_admin_tabs', array( |
| 189 |
'0' => array( |
| 190 |
'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-repair' ), 'tools.php' ) ), |
| 191 |
'name' => __( 'Repair Forums', 'bbpress' ) |
| 192 |
), |
| 193 |
'1' => array( |
| 194 |
'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-converter' ), 'tools.php' ) ), |
| 195 |
'name' => __( 'Import Forums', 'bbpress' ) |
| 196 |
), |
| 197 |
'2' => array( |
| 198 |
'href' => get_admin_url( '', add_query_arg( array( 'page' => 'bbp-reset' ), 'tools.php' ) ), |
| 199 |
'name' => __( 'Reset Forums', 'bbpress' ) |
| 200 |
) |
| 201 |
) ); |
| 202 |
|
| 203 |
// Loop through tabs and build navigation |
| 204 |
foreach( $tabs as $tab_id => $tab_data ) { |
| 205 |
$is_current = (bool) ( $tab_data['name'] == $active_tab ); |
| 206 |
$tab_class = $is_current ? $active_class : $idle_class; |
| 207 |
$tabs_html .= '<a href="' . $tab_data['href'] . '" class="' . $tab_class . '">' . $tab_data['name'] . '</a>'; |
| 208 |
} |
| 209 |
|
| 210 |
// Output the tabs |
| 211 |
return $tabs_html; |
| 212 |
} |
| 213 |
|