Changeset 13437 for trunk/src/bp-groups/bp-groups-template.php
- Timestamp:
- 03/18/2023 09:42:31 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-groups/bp-groups-template.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-template.php
r13436 r13437 118 118 */ 119 119 function bp_get_groups_directory_url( $path_chunks = array() ) { 120 $supported_chunks = array_fill_keys( array( 'create_single_item', ' directory_type' ), true );120 $supported_chunks = array_fill_keys( array( 'create_single_item', 'create_single_item_variables', 'directory_type' ), true ); 121 121 122 122 $path_chunks = bp_parse_args( … … 1237 1237 1238 1238 /** 1239 * Output the permalinkfor the group.1240 * 1241 * @since 1 .0.01239 * Output the URL for the group. 1240 * 1241 * @since 12.0.0 1242 1242 * 1243 1243 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object. 1244 1244 * Default: false. 1245 1245 */ 1246 function bp_group_url( $group = false ) { 1247 echo esc_url( bp_get_group_url( $group ) ); 1248 } 1249 1250 /** 1251 * Returns the Groups single item's URL. 1252 * 1253 * @since 12.0.0 1254 * 1255 * @param integer|BP_Groups_Group $group The group ID or the Group object. 1256 * @param array $path_chunks { 1257 * An array of arguments. Optional. 1258 * 1259 * @type string $single_item_component The component slug the action is relative to. 1260 * @type string $single_item_action The slug of the action to perform. 1261 * @type array $single_item_action_variables An array of additional informations about the action to perform. 1262 * } 1263 * @return string The URL built for the BP Rewrites URL parser. 1264 */ 1265 function bp_get_group_url( $group = 0, $path_chunks = array() ) { 1266 $url = ''; 1267 $slug = groups_get_slug( $group ); 1268 1269 if ( $group instanceof BP_Groups_Group ) { 1270 $group_id = (int) $group->id; 1271 } else { 1272 $group_id = (int) $group; 1273 } 1274 1275 if ( $slug ) { 1276 $supported_chunks = array_fill_keys( array( 'single_item_component', 'single_item_action', 'single_item_action_variables' ), true ); 1277 $path_chunks = bp_parse_args( 1278 array_intersect_key( $path_chunks, $supported_chunks ), 1279 array( 1280 'component_id' => 'groups', 1281 'single_item' => $slug, 1282 ) 1283 ); 1284 1285 $url = bp_rewrites_get_url( $path_chunks ); 1286 } 1287 1288 /** 1289 * Filters the URL for the passed group. 1290 * 1291 * @since 12.0.0 1292 * 1293 * @param string $url The group url. 1294 * @param integer $group_id The group ID. 1295 * @param string $slug The group slug. 1296 * @param array $path_chunks { 1297 * An array of arguments. Optional. 1298 * 1299 * @type string $single_item_component The component slug the action is relative to. 1300 * @type string $single_item_action The slug of the action to perform. 1301 * @type array $single_item_action_variables An array of additional informations about the action to perform. 1302 * } 1303 */ 1304 return apply_filters( 'bp_get_group_url', $url, $group_id, $slug, $path_chunks ); 1305 } 1306 1307 /** 1308 * Output the permalink for the group. 1309 * 1310 * @since 1.0.0 1311 * @deprecated 12.0.0 1312 * 1313 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object. 1314 * Default: false. 1315 */ 1246 1316 function bp_group_permalink( $group = false ) { 1247 echo bp_get_group_permalink( $group ); 1317 _deprecated_function( __FUNCTION__, '12.0.0', 'bp_group_url' ); 1318 bp_group_url( $group ); 1248 1319 } 1249 1320 /** … … 1258 1329 */ 1259 1330 function bp_get_group_permalink( $group = false ) { 1260 $group = bp_get_group( $group ); 1261 1262 if ( empty( $group->id ) ) { 1263 return ''; 1264 } 1331 /* 1332 * This function is used at many places and we need to review all this 1333 * places during the 12.0 development cycle. Using BP Rewrites means we 1334 * cannot concatenate URL chunks to build our URL anymore. We now need 1335 * to use `bp_get_group_url( $group, $array )` and make sure to use 1336 * the right arguments inside this `$array`. 1337 * 1338 * @todo Once every link reviewed, we'll be able to remove this check 1339 * and let PHPUnit tell us the one we forgot, eventually! 1340 */ 1341 if ( ! buddypress()->is_phpunit_running ) { 1342 _deprecated_function( __FUNCTION__, '12.0.0', 'bp_get_group_url' ); 1343 } 1344 1345 $url = bp_get_group_url( $group ); 1265 1346 1266 1347 /** … … 1269 1350 * @since 1.0.0 1270 1351 * @since 2.5.0 Added the `$group` parameter. 1271 * 1272 * @param string $permalink Permalink for the group. 1273 * @param BP_Groups_Group $group The group object. 1274 */ 1275 return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group ); 1352 * @deprecated 12.0.0 1353 * 1354 * @param string $url Permalink for the group. 1355 * @param BP_Groups_Group $group The group object. 1356 */ 1357 return apply_filters_deprecated( 'bp_get_group_permalink', array( $url, $group ), '12.0.0', 'bp_get_group_url' ); 1276 1358 } 1277 1359 … … 1306 1388 $link = sprintf( 1307 1389 '<a href="%s" class="bp-group-home-link %s-home-link">%s</a>', 1308 esc_url( bp_get_group_ permalink( $group ) ),1390 esc_url( bp_get_group_url( $group ) ), 1309 1391 esc_attr( bp_get_group_slug( $group ) ), 1310 1392 esc_html( bp_get_group_name( $group ) ) … … 3199 3281 } 3200 3282 3283 $views = bp_get_group_screens( 'read' ); 3284 if ( isset( $views[ $page ]['rewrite_id'] ) ) { 3285 $page = bp_rewrites_get_slug( 'groups', $views[ $page ]['rewrite_id'], $page ); 3286 } 3287 3288 $url = bp_get_group_url( 3289 $group, 3290 array( 3291 'single_item_action' => $page, 3292 ) 3293 ); 3294 3201 3295 /** 3202 3296 * Filters the 'action' attribute for a group form. … … 3205 3299 * @since 2.5.0 Added the `$group` parameter. 3206 3300 * 3207 * @param string $ valueAction attribute for a group form.3301 * @param string $url Action attribute for a group form. 3208 3302 * @param BP_Groups_Group $group The group object. 3209 3303 * @param int|string|bool $page Page slug. 3210 3304 */ 3211 return apply_filters( 'bp_group_form_action', trailingslashit( bp_get_group_permalink( $group ) . $page ), $group, $page );3305 return apply_filters( 'bp_group_form_action', $url, $group, $page ); 3212 3306 } 3213 3307 … … 3559 3653 * @param object $group Group object. 3560 3654 */ 3561 return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_ permalink( $group ), $group );3655 return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_url( $group ), $group ); 3562 3656 } 3563 3657 … … 3719 3813 'wrapper_class' => 'group-button ' . $group->status, 3720 3814 'wrapper_id' => 'groupbutton-' . $group->id, 3721 'link_href' => add_query_arg( 'redirect_to', bp_get_group_ permalink( $group ), bp_get_group_accept_invite_link( $group ) ),3815 'link_href' => add_query_arg( 'redirect_to', bp_get_group_url( $group ), bp_get_group_accept_invite_link( $group ) ), 3722 3816 'link_text' => __( 'Accept Invitation', 'buddypress' ), 3723 3817 'link_title' => __( 'Accept Invitation', 'buddypress' ), … … 3735 3829 'wrapper_class' => 'group-button pending ' . $group->status, 3736 3830 'wrapper_id' => 'groupbutton-' . $group->id, 3737 'link_href' => bp_get_group_ permalink( $group ),3831 'link_href' => bp_get_group_url( $group ), 3738 3832 'link_text' => __( 'Request Sent', 'buddypress' ), 3739 3833 'link_title' => __( 'Request Sent', 'buddypress' ), … … 3828 3922 'link_text' => __( 'Create a Group', 'buddypress' ), 3829 3923 'link_class' => 'group-create no-ajax', 3830 'link_href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ), 3924 'link_href' => bp_get_groups_directory_url( 3925 array( 3926 'create_single_item' => 1, 3927 ) 3928 ), 3831 3929 'wrapper' => false, 3832 3930 'block_self' => false, … … 4890 4988 4891 4989 /** 4892 * @since 1.0.04893 * 4894 * @ return bool4990 * Outputs the Group creation tabs. 4991 * 4992 * @since 1.0.0 4895 4993 */ 4896 4994 function bp_group_creation_tabs() { 4897 $bp = buddypress(); 4898 4899 if ( !is_array( $bp->groups->group_creation_steps ) ) { 4995 $bp = buddypress(); 4996 $create_steps = $bp->groups->group_creation_steps; 4997 4998 if ( ! is_array( $create_steps ) ) { 4900 4999 return false; 4901 5000 } 4902 5001 4903 if ( ! bp_get_groups_current_create_step() ) {4904 $keys = array_keys( $bp->groups->group_creation_steps );5002 if ( ! bp_get_groups_current_create_step() ) { 5003 $keys = array_keys( $create_steps ); 4905 5004 $bp->groups->current_create_step = array_shift( $keys ); 4906 5005 } … … 4908 5007 $counter = 1; 4909 5008 4910 foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) { 4911 $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?> 4912 4913 <li<?php if ( bp_get_groups_current_create_step() == $slug ) : ?> class="current"<?php endif; ?>><?php if ( $is_enabled ) : ?><a href="<?php bp_groups_directory_permalink(); ?>create/step/<?php echo $slug ?>/"><?php else: ?><span><?php endif; ?><?php echo $counter ?>. <?php echo $step['name'] ?><?php if ( $is_enabled ) : ?></a><?php else: ?></span><?php endif ?></li><?php 5009 foreach ( (array) $create_steps as $create_step => $step ) { 5010 $is_enabled = bp_are_previous_group_creation_steps_complete( $create_step ); 5011 $current_class = ''; 5012 $step_name = $step['name']; 5013 5014 if ( bp_get_groups_current_create_step() === $create_step ) { 5015 $current_class = ' class="current"'; 5016 } 5017 5018 if ( $is_enabled && isset( $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ) ) { 5019 $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' ); 5020 $step_slug = bp_rewrites_get_slug( 'groups', $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ); 5021 $url = bp_get_groups_directory_url( 5022 array( 5023 'create_single_item' => 1, 5024 'create_single_item_variables' => array( $create_step_slug, $step_slug ), 5025 ) 5026 ); 5027 5028 $step_name = sprintf( '<a href="%1$s">%2$s. %3$s</a>', esc_url( $url ), absint( $counter ), esc_html( $step_name ) ); 5029 } else { 5030 $step_name = sprintf( '<span>%1$s. %2$s</span>', absint( $counter ), esc_html( $step_name ) ); 5031 } 5032 5033 5034 printf( '<li%1$s>%2$s</li>', $current_class, $step_name ); 4914 5035 $counter++; 4915 } 4916 4917 unset( $is_enabled ); 5036 unset( $is_enabled ); 5037 } 4918 5038 4919 5039 /** … … 4954 5074 */ 4955 5075 function bp_get_group_creation_form_action() { 4956 $bp = buddypress(); 4957 4958 if ( !bp_action_variable( 1 ) ) { 4959 $keys = array_keys( $bp->groups->group_creation_steps ); 5076 $bp = buddypress(); 5077 $create_steps = $bp->groups->group_creation_steps; 5078 $url = ''; 5079 5080 if ( ! bp_action_variable( 1 ) ) { 5081 $keys = array_keys( $create_steps ); 4960 5082 $bp->action_variables[1] = array_shift( $keys ); 4961 5083 } 4962 5084 5085 $create_step = bp_action_variable( 1 ); 5086 if ( $create_step && isset( $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ) ) { 5087 $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' ); 5088 $step_slug = bp_rewrites_get_slug( 'groups', $create_steps[ $create_step ]['rewrite_id'], $create_steps[ $create_step ]['default_slug'] ); 5089 5090 $url = bp_get_groups_directory_url( 5091 array( 5092 'create_single_item' => 1, 5093 'create_single_item_variables' => array( $create_step_slug, $step_slug ), 5094 ) 5095 ); 5096 } 5097 4963 5098 /** 4964 5099 * Filters the group creation form action. … … 4966 5101 * @since 1.1.0 4967 5102 * 4968 * @param string $ valueAction to be used with group creation form.4969 */ 4970 return apply_filters( 'bp_get_group_creation_form_action', trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_action_variable( 1 ) ));5103 * @param string $url Action to be used with group creation form. 5104 */ 5105 return apply_filters( 'bp_get_group_creation_form_action', $url ); 4971 5106 } 4972 5107 … … 5298 5433 */ 5299 5434 function bp_get_group_creation_previous_link() { 5300 $bp = buddypress(); 5301 $steps = array_keys( $bp->groups->group_creation_steps ); 5435 $create_steps = buddypress()->groups->group_creation_steps; 5436 $steps = array_keys( $create_steps ); 5437 $url = ''; 5302 5438 5303 5439 // Loop through steps. … … 5314 5450 5315 5451 // Generate the URL for the previous step. 5316 $group_directory = bp_get_groups_directory_permalink(); 5317 $create_step = 'create/step/'; 5318 $previous_step = array_pop( $previous_steps ); 5319 $url = trailingslashit( $group_directory . $create_step . $previous_step ); 5452 $previous_step = array_pop( $previous_steps ); 5453 5454 if ( isset( $create_steps[ $previous_step ]['rewrite_id'], $create_steps[ $previous_step ]['default_slug'] ) ) { 5455 $create_step_slug = bp_rewrites_get_slug( 'groups', 'bp_group_create_step', 'step' ); 5456 $previous_step = bp_rewrites_get_slug( 'groups', $create_steps[ $previous_step ]['rewrite_id'], $create_steps[ $previous_step ]['default_slug'] ); 5457 5458 $url = bp_get_groups_directory_url( 5459 array( 5460 'create_single_item' => 1, 5461 'create_single_item_variables' => array( $create_step_slug, $previous_step ), 5462 ) 5463 ); 5464 } 5320 5465 5321 5466 /** … … 6582 6727 $url = bp_get_group_permalink( $current_group ) . $action; 6583 6728 } else { 6584 $url = bp_get_group_ permalink( $current_group );6729 $url = bp_get_group_url( $current_group ); 6585 6730 } 6586 6731
Note: See TracChangeset
for help on using the changeset viewer.