[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Admin Slug Functions. 4 * 5 * @package BuddyPress 6 * @subpackage CoreAdministration 7 * @since 2.3.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Renders the page mapping admin panel. 15 * 16 * @since 1.6.0 17 * @todo Use settings API 18 */ 19 function bp_core_admin_slugs_settings() { 20 ?> 21 22 <div class="wrap"> 23 24 <h1 class="wp-heading-inline"><?php esc_html_e( 'BuddyPress Settings', 'buddypress' ); ?> </h1> 25 <hr class="wp-header-end"> 26 27 <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( esc_html__( 'Pages', 'buddypress' ) ); ?></h2> 28 <form action="" method="post" id="bp-admin-page-form"> 29 30 <?php bp_core_admin_slugs_options(); ?> 31 32 <p class="submit clear"> 33 <input class="button-primary" type="submit" name="bp-admin-pages-submit" id="bp-admin-pages-submit" value="<?php esc_attr_e( 'Save Settings', 'buddypress' ) ?>"/> 34 </p> 35 36 <?php wp_nonce_field( 'bp-admin-pages-setup' ); ?> 37 38 </form> 39 </div> 40 41 <?php 42 } 43 44 /** 45 * Generate a list of directory pages, for use when building Components panel markup. 46 * 47 * @since 2.4.1 48 * 49 * @return array 50 */ 51 function bp_core_admin_get_directory_pages() { 52 $bp = buddypress(); 53 $directory_pages = array(); 54 55 // Loop through loaded components and collect directories. 56 if ( is_array( $bp->loaded_components ) ) { 57 foreach( $bp->loaded_components as $component_slug => $component_id ) { 58 59 // Only components that need directories should be listed here. 60 if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) { 61 62 // The component->name property was introduced in BP 1.5, so we must provide a fallback. 63 $directory_pages[$component_id] = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id ); 64 } 65 } 66 } 67 68 /** Directory Display *****************************************************/ 69 70 /** 71 * Filters the loaded components needing directory page association to a WordPress page. 72 * 73 * @since 1.5.0 74 * 75 * @param array $directory_pages Array of available components to set associations for. 76 */ 77 return apply_filters( 'bp_directory_pages', $directory_pages ); 78 } 79 80 /** 81 * Generate a list of static pages, for use when building Components panel markup. 82 * 83 * By default, this list contains 'register' and 'activate'. 84 * 85 * @since 2.4.1 86 * 87 * @return array 88 */ 89 function bp_core_admin_get_static_pages() { 90 $static_pages = array( 91 'register' => __( 'Register', 'buddypress' ), 92 'activate' => __( 'Activate', 'buddypress' ), 93 ); 94 95 /** 96 * Filters the default static pages for BuddyPress setup. 97 * 98 * @since 1.6.0 99 * 100 * @param array $static_pages Array of static default static pages. 101 */ 102 return apply_filters( 'bp_static_pages', $static_pages ); 103 } 104 105 /** 106 * Creates reusable markup for page setup on the Components and Pages dashboard panel. 107 * 108 * @package BuddyPress 109 * @since 1.6.0 110 * @todo Use settings API 111 */ 112 function bp_core_admin_slugs_options() { 113 114 // Get the existing WP pages. 115 $existing_pages = bp_core_get_directory_page_ids(); 116 117 // Set up an array of components (along with component names) that have directory pages. 118 $directory_pages = bp_core_admin_get_directory_pages(); 119 120 if ( !empty( $directory_pages ) ) : ?> 121 122 <h3><?php _e( 'Directories', 'buddypress' ); ?></h3> 123 124 <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p> 125 126 <table class="form-table"> 127 <tbody> 128 129 <?php foreach ( $directory_pages as $name => $label ) : ?> 130 131 <tr valign="top"> 132 <th scope="row"> 133 <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label> 134 </th> 135 136 <td> 137 138 <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?> 139 140 <?php echo wp_dropdown_pages( array( 141 'name' => 'bp_pages[' . esc_attr( $name ) . ']', 142 'echo' => false, 143 'show_option_none' => __( '- None -', 'buddypress' ), 144 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false 145 ) ); ?> 146 147 <?php if ( ! empty( $existing_pages[ $name ] ) && get_post( $existing_pages[ $name ] ) ) : ?> 148 149 <a href="<?php echo esc_url( get_permalink( $existing_pages[$name] ) ); ?>" class="button-secondary" target="_bp"> 150 <?php _e( 'View', 'buddypress' ); ?> <span class="dashicons dashicons-external" aria-hidden="true"></span> 151 <span class="screen-reader-text"><?php esc_html_e( '(opens in a new tab)', 'buddypress' ); ?></span> 152 </a> 153 154 <?php endif; ?> 155 156 <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?> 157 158 </td> 159 </tr> 160 161 162 <?php endforeach ?> 163 164 <?php 165 166 /** 167 * Fires after the display of default directories. 168 * 169 * Allows plugins to add their own directory associations. 170 * 171 * @since 1.5.0 172 */ 173 do_action( 'bp_active_external_directories' ); ?> 174 175 </tbody> 176 </table> 177 178 <?php 179 180 endif; 181 182 /** Static Display ********************************************************/ 183 184 $static_pages = bp_core_admin_get_static_pages(); 185 186 if ( !empty( $static_pages ) ) : ?> 187 188 <h3><?php _e( 'Registration', 'buddypress' ); ?></h3> 189 190 <?php if ( bp_get_signup_allowed() ) : ?> 191 <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p> 192 <?php else : ?> 193 <?php if ( is_multisite() ) : ?> 194 <p> 195 <?php 196 /* translators: %s: the link to the Network settings page */ 197 printf( __( 'Registration is currently disabled. Before associating a page is allowed, please enable registration by selecting either the "User accounts may be registered" or "Both sites and user accounts can be registered" option on <a href="%s">this page</a>.', 'buddypress' ), network_admin_url( 'settings.php' ) ); 198 ?> 199 </p> 200 <?php else : ?> 201 <p> 202 <?php 203 /* translators: %s: the link to the Site settings page */ 204 printf( __( 'Registration is currently disabled. Before associating a page is allowed, please enable registration by clicking on the "Anyone can register" checkbox on <a href="%s">this page</a>.', 'buddypress' ), admin_url( 'options-general.php' ) ); 205 ?> 206 </p> 207 <?php endif; ?> 208 <?php endif; ?> 209 210 <table class="form-table"> 211 <tbody> 212 213 <?php if ( bp_get_signup_allowed() ) : foreach ( $static_pages as $name => $label ) : ?> 214 215 <tr valign="top"> 216 <th scope="row"> 217 <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label> 218 </th> 219 220 <td> 221 222 <?php if ( ! bp_is_root_blog() ) switch_to_blog( bp_get_root_blog_id() ); ?> 223 224 <?php echo wp_dropdown_pages( array( 225 'name' => 'bp_pages[' . esc_attr( $name ) . ']', 226 'echo' => false, 227 'show_option_none' => __( '- None -', 'buddypress' ), 228 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false 229 ) ) ?> 230 231 <?php if ( ! empty( $existing_pages[ $name ] ) && get_post( $existing_pages[ $name ] ) ) : ?> 232 233 <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a> 234 235 <?php endif; ?> 236 237 <?php if ( ! bp_is_root_blog() ) restore_current_blog(); ?> 238 239 </td> 240 </tr> 241 242 <?php endforeach; endif; ?> 243 244 <?php 245 246 /** 247 * Fires after the display of default static pages for BuddyPress setup. 248 * 249 * @since 1.5.0 250 */ 251 do_action( 'bp_active_external_pages' ); ?> 252 253 </tbody> 254 </table> 255 256 <?php 257 endif; 258 } 259 260 /** 261 * Handle saving of the BuddyPress slugs. 262 * 263 * @since 1.6.0 264 * @todo Use settings API 265 */ 266 function bp_core_admin_slugs_setup_handler() { 267 268 if ( isset( $_POST['bp-admin-pages-submit'] ) ) { 269 if ( !check_admin_referer( 'bp-admin-pages-setup' ) ) 270 return false; 271 272 // Then, update the directory pages. 273 if ( isset( $_POST['bp_pages'] ) ) { 274 $valid_pages = array_merge( bp_core_admin_get_directory_pages(), bp_core_admin_get_static_pages() ); 275 276 $new_directory_pages = array(); 277 foreach ( (array) $_POST['bp_pages'] as $key => $value ) { 278 if ( isset( $valid_pages[ $key ] ) ) { 279 $new_directory_pages[ $key ] = (int) $value; 280 } 281 } 282 bp_core_update_directory_page_ids( $new_directory_pages ); 283 } 284 285 $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings', 'updated' => 'true' ), 'admin.php' ) ); 286 287 wp_redirect( $base_url ); 288 } 289 } 290 add_action( 'bp_admin_init', 'bp_core_admin_slugs_setup_handler' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 28 01:01:36 2021 | Cross-referenced by PHPXref 0.7.1 |