PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
bbpress / includes / admin / common.php

common.php in bbPress 2.6.17, at includes/admin/common.php

189 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Admin Functions
5 *
6 * @package bbPress
7 * @subpackage Administration
8 */
9
10 // Exit if accessed directly
11 defined( 'ABSPATH' ) || exit;
12
13 /** Admin Menus ***************************************************************/
14
15 /**
16 * Add a separator to the WordPress admin menus
17 *
18 * @since 2.0.0 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 bbp_admin()->show_separator = true;
33 break;
34 }
35 }
36
37 // Bail if no separator
38 if ( false === bbp_admin()->show_separator ) {
39 return;
40 }
41
42 global $menu;
43
44 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
45 $menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' );
46 }
47
48 /**
49 * Tell WordPress we have a custom menu order
50 *
51 * @since 2.0.0 bbPress (r2957)
52 *
53 * @param bool $menu_order Menu order
54 * @return mixed True if separator, false if not
55 */
56 function bbp_admin_custom_menu_order( $menu_order = false ) {
57 if ( false === bbp_admin()->show_separator ) {
58 return $menu_order;
59 }
60
61 return true;
62 }
63
64 /**
65 * Move our custom separator above our custom post types
66 *
67 * @since 2.0.0 bbPress (r2957)
68 *
69 * @param array $menu_order Menu Order
70 * @return array Modified menu order
71 */
72 function bbp_admin_menu_order( $menu_order ) {
73
74 // Bail if user cannot see any top level bbPress menus
75 if ( empty( $menu_order ) || ( false === bbp_admin()->show_separator ) ) {
76 return $menu_order;
77 }
78
79 // Initialize our custom order array
80 $bbp_menu_order = array();
81
82 // Menu values
83 $second_sep = 'separator2';
84 $custom_menus = array(
85 'separator-bbpress', // Separator
86 'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums
87 'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics
88 'edit.php?post_type=' . bbp_get_reply_post_type() // Replies
89 );
90
91 // Loop through menu order and do some rearranging
92 foreach ( $menu_order as $item ) {
93
94 // Position bbPress menus above appearance
95 if ( $second_sep == $item ) {
96
97 // Add our custom menus
98 foreach ( $custom_menus as $custom_menu ) {
99 if ( array_search( $custom_menu, $menu_order ) ) {
100 $bbp_menu_order[] = $custom_menu;
101 }
102 }
103
104 // Add the appearance separator
105 $bbp_menu_order[] = $second_sep;
106
107 // Skip our menu items
108 } elseif ( ! in_array( $item, $custom_menus, true ) ) {
109 $bbp_menu_order[] = $item;
110 }
111 }
112
113 // Return our custom order
114 return $bbp_menu_order;
115 }
116
117 /**
118 * Sanitize permalink slugs when saving the settings page.
119 *
120 * @since 2.6.0 bbPress (r5364)
121 *
122 * @param string $slug
123 * @return string
124 */
125 function bbp_sanitize_slug( $slug = '' ) {
126
127 // Don't allow multiple slashes in a row
128 $value = preg_replace( '#/+#', '/', str_replace( '#', '', $slug ) );
129
130 // Strip out unsafe or unusable chars
131 $value = esc_url_raw( $value );
132
133 // esc_url_raw() adds a scheme via esc_url(), so let's remove it
134 $value = str_replace( 'http://', '', $value );
135
136 // Trim off first and last slashes.
137 //
138 // We already prevent double slashing elsewhere, but let's prevent
139 // accidental poisoning of options values where we can.
140 $value = ltrim( $value, '/' );
141 $value = rtrim( $value, '/' );
142
143 // Filter & return
144 return apply_filters( 'bbp_sanitize_slug', $value, $slug );
145 }
146
147 /**
148 * Uninstall all bbPress options and capabilities from a specific site.
149 *
150 * @since 2.1.0 bbPress (r3765)
151 *
152 * @param int $site_id
153 */
154 function bbp_do_uninstall( $site_id = 0 ) {
155 if ( empty( $site_id ) ) {
156 $site_id = get_current_blog_id();
157 }
158
159 bbp_switch_to_site( $site_id );
160 bbp_delete_options();
161 bbp_remove_roles();
162 bbp_remove_caps();
163 flush_rewrite_rules();
164 bbp_restore_current_site();
165 }
166
167 /**
168 * This tells WP to highlight the Tools > Forums menu item,
169 * regardless of which actual bbPress Tools screen we are on.
170 *
171 * The conditional prevents the override when the user is viewing settings or
172 * any third-party plugins.
173 *
174 * @since 2.1.0 bbPress (r3888)
175 *
176 * @global string $plugin_page
177 * @global array $submenu_file
178 */
179 function bbp_tools_modify_menu_highlight() {
180 global $plugin_page, $submenu_file;
181
182 // This tweaks the Tools subnav menu to only show one bbPress menu item
183 if ( ! in_array( $plugin_page, array( 'bbp-settings' ), true ) ) {
184
185 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
186 $submenu_file = 'bbp-repair';
187 }
188 }
189