PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.4.3
Forumax – AI Powered Advanced Community Forum Plugin v2.4.3
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / lib / bbpress / includes / admin / common.php

common.php in Forumax – AI Powered Advanced Community Forum Plugin 2.4.3, at lib/bbpress/includes/admin/common.php

186 lines 4.3 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 $menu[] = array( '', 'read', 'separator-bbpress', '', 'wp-menu-separator bbpress' );
45 }
46
47 /**
48 * Tell WordPress we have a custom menu order
49 *
50 * @since 2.0.0 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 === bbp_admin()->show_separator ) {
57 return $menu_order;
58 }
59
60 return true;
61 }
62
63 /**
64 * Move our custom separator above our custom post types
65 *
66 * @since 2.0.0 bbPress (r2957)
67 *
68 * @param array $menu_order Menu Order
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 === bbp_admin()->show_separator ) ) {
75 return $menu_order;
76 }
77
78 // Initialize our custom order array
79 $bbp_menu_order = array();
80
81 // Menu values
82 $second_sep = 'separator2';
83 $custom_menus = array(
84 'separator-bbpress', // Separator
85 'edit.php?post_type=' . bbp_get_forum_post_type(), // Forums
86 'edit.php?post_type=' . bbp_get_topic_post_type(), // Topics
87 'edit.php?post_type=' . bbp_get_reply_post_type() // Replies
88 );
89
90 // Loop through menu order and do some rearranging
91 foreach ( $menu_order as $item ) {
92
93 // Position bbPress menus above appearance
94 if ( $second_sep == $item ) {
95
96 // Add our custom menus
97 foreach ( $custom_menus as $custom_menu ) {
98 if ( array_search( $custom_menu, $menu_order ) ) {
99 $bbp_menu_order[] = $custom_menu;
100 }
101 }
102
103 // Add the appearance separator
104 $bbp_menu_order[] = $second_sep;
105
106 // Skip our menu items
107 } elseif ( ! in_array( $item, $custom_menus, true ) ) {
108 $bbp_menu_order[] = $item;
109 }
110 }
111
112 // Return our custom order
113 return $bbp_menu_order;
114 }
115
116 /**
117 * Sanitize permalink slugs when saving the settings page.
118 *
119 * @since 2.6.0 bbPress (r5364)
120 *
121 * @param string $slug
122 * @return string
123 */
124 function bbp_sanitize_slug( $slug = '' ) {
125
126 // Don't allow multiple slashes in a row
127 $value = preg_replace( '#/+#', '/', str_replace( '#', '', $slug ) );
128
129 // Strip out unsafe or unusable chars
130 $value = esc_url_raw( $value );
131
132 // esc_url_raw() adds a scheme via esc_url(), so let's remove it
133 $value = str_replace( 'http://', '', $value );
134
135 // Trim off first and last slashes.
136 //
137 // We already prevent double slashing elsewhere, but let's prevent
138 // accidental poisoning of options values where we can.
139 $value = ltrim( $value, '/' );
140 $value = rtrim( $value, '/' );
141
142 // Filter & return
143 return apply_filters( 'bbp_sanitize_slug', $value, $slug );
144 }
145
146 /**
147 * Uninstall all bbPress options and capabilities from a specific site.
148 *
149 * @since 2.1.0 bbPress (r3765)
150 *
151 * @param int $site_id
152 */
153 function bbp_do_uninstall( $site_id = 0 ) {
154 if ( empty( $site_id ) ) {
155 $site_id = get_current_blog_id();
156 }
157
158 bbp_switch_to_site( $site_id );
159 bbp_delete_options();
160 bbp_remove_roles();
161 bbp_remove_caps();
162 flush_rewrite_rules();
163 bbp_restore_current_site();
164 }
165
166 /**
167 * This tells WP to highlight the Tools > Forums menu item,
168 * regardless of which actual bbPress Tools screen we are on.
169 *
170 * The conditional prevents the override when the user is viewing settings or
171 * any third-party plugins.
172 *
173 * @since 2.1.0 bbPress (r3888)
174 *
175 * @global string $plugin_page
176 * @global array $submenu_file
177 */
178 function bbp_tools_modify_menu_highlight() {
179 global $plugin_page, $submenu_file;
180
181 // This tweaks the Tools subnav menu to only show one bbPress menu item
182 if ( ! in_array( $plugin_page, array( 'bbp-settings' ), true ) ) {
183 $submenu_file = 'bbp-repair';
184 }
185 }
186