Ticket #7210: 7210.admin.patch
File 7210.admin.patch, 6.1 KB (added by , 3 years ago) |
---|
-
src/bp-groups/bp-groups-admin.php
1046 1046 return; 1047 1047 } 1048 1048 1049 $types = bp_groups_get_group_types( array(), 'objects' ); 1050 $current_type = bp_groups_get_group_type( $group->id ); 1049 $types = bp_groups_get_group_types( array(), 'objects' ); 1050 $current_types = bp_groups_get_group_type( $group->id, false ); 1051 $backend_only = bp_groups_get_group_types( array( 'show_in_create_screen' => false ) ); 1051 1052 ?> 1052 1053 1053 1054 <label for="bp-groups-group-type" class="screen-reader-text"><?php 1054 1055 /* translators: accessibility text */ 1055 1056 esc_html_e( 'Select group type', 'buddypress' ); 1056 1057 ?></label> 1057 <select name="bp-groups-group-type" id="bp-groups-group-type"> 1058 <option value="" <?php selected( '', $current_type ); ?>><?php /* translators: no option picked in select box */ esc_attr_e( '----', 'buddypress' ) ?></option> 1058 1059 1060 <ul class="categorychecklist form-no-clear"> 1059 1061 <?php foreach ( $types as $type ) : ?> 1060 <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( $type->name, $current_type ) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option> 1062 <li> 1063 <label class="selectit"><input value="<?php echo esc_attr( $type->name ) ?>" name="bp-groups-group-type[]" type="checkbox" <?php checked( true, in_array( $type->name, $current_types ) ); ?>> 1064 <?php 1065 echo esc_html( $type->labels['singular_name'] ); 1066 if ( in_array( $type->name, $backend_only ) ) { 1067 printf( ' <span class="description">%s</span>', esc_html__( '(Not available on the frontend)', 'buddypress' ) ); 1068 } 1069 ?> 1070 1071 </label> 1072 </li> 1073 1061 1074 <?php endforeach; ?> 1062 </select> 1075 1076 </ul> 1063 1077 1064 1078 <?php 1065 1079 … … 1072 1086 * @since 2.6.0 1073 1087 */ 1074 1088 function bp_groups_process_group_type_update( $group_id ) { 1075 if ( ! isset( $_POST['bp-group-type-nonce'] ) || ! isset( $_POST['bp-groups-group-type'] ) ) {1076 return;1077 }1078 1079 1089 check_admin_referer( 'bp-group-type-change-' . $group_id, 'bp-group-type-nonce' ); 1080 1090 1081 1091 // Permission check. … … 1083 1093 return; 1084 1094 } 1085 1095 1086 // Group type string must either reference a valid group type, or be empty. 1087 $group_type = wp_unslash( $_POST['bp-groups-group-type'] ); 1088 if ( $group_type && ! bp_groups_get_group_type_object( $group_type ) ) { 1089 return; 1090 } 1096 $group_types = ! empty( $_POST['bp-groups-group-type'] ) ? wp_unslash( $_POST['bp-groups-group-type'] ) : array(); 1091 1097 1092 1098 /* 1093 1099 * If an invalid group type is passed, someone's doing something 1094 1100 * fishy with the POST request, so we can fail silently. 1095 1101 */ 1096 if ( bp_groups_set_group_type( $group_id, $group_type ) ) {1102 if ( bp_groups_set_group_type( $group_id, $group_types ) ) { 1097 1103 // @todo Success messages can't be posted because other stuff happens on the page load. 1098 1104 } 1099 1105 } -
src/bp-groups/bp-groups-template.php
223 223 * @type string $label Label to add before the list. Defaults to 'Group Types:'. 224 224 * @type string $label_element Element to wrap around the label. Defaults to 'strong'. 225 225 * @type array $label_attr Element attributes for label element. Defaults to array(). 226 * @type bool $show_all Whether to show all registered group types. Defaults to 'false'. If 227 * 'false', only shows group types with the 'show_in_list' parameter set to 228 * true. See bp_groups_register_group_type() for more info. 226 229 * } 227 230 * @return string 228 231 */ … … 238 241 ), 239 242 'label' => __( 'Group Types:', 'buddypress' ), 240 243 'label_element' => 'strong', 241 'label_attr' => array() 244 'label_attr' => array(), 245 'show_all' => false, 242 246 ), 'group_type_list' ); 243 247 244 248 $retval = ''; 245 249 246 250 if ( $types = bp_groups_get_group_type( $group_id, false ) ) { 247 251 // Make sure we can show the type in the list. 248 $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types ); 249 if ( empty( $types ) ) { 250 return $retval; 252 if ( false === $show_all ) { 253 $types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types ); 254 if ( empty( $types ) ) { 255 return $retval; 256 } 251 257 } 252 258 253 259 $before = $after = $label = ''; -
src/bp-groups/classes/class-bp-groups-list-table.php
715 715 return $retval; 716 716 } 717 717 718 // Get the group type.719 $ type = bp_groups_get_group_type( $item['id'] );720 721 // Output the722 if ( $type_obj = bp_groups_get_group_type_object( $type ) ) {723 $url = add_query_arg( array( 'bp-group-type' => urlencode( $type ) ) );724 $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['singular_name'] ) . '</a>';725 }718 add_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 ); 719 $retval = bp_get_group_type_list( $item['id'], array( 720 'parent_element' => '', 721 'label_element' => '', 722 'label' => '', 723 'show_all' => true 724 ) ); 725 remove_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 ); 726 726 727 727 /** 728 728 * Filters the markup for the Group Type column. … … 736 736 } 737 737 738 738 /** 739 * Filters the group type list permalink in the Group Type column. 740 * 741 * Changes the group type permalink to use the admin URL. 742 * 743 * @since 2.7.0 744 * 745 * @param string $retval Current group type permalink. 746 * @param object $type Group type object. 747 * @return string 748 */ 749 public function group_type_permalink_use_admin_filter( $retval, $type ) { 750 return add_query_arg( array( 'bp-group-type' => urlencode( $type->name ) ) ); 751 } 752 753 /** 739 754 * Markup for the Group Type bulk change select. 740 755 * 741 756 * @since 2.7.0