Changeset 4212 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 10/11/2016 06:27:26 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r4202 r4212 42 42 add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 ); 43 43 add_filter( 'term_link', array( $this, 'term_link' ), 10, 2 ); 44 add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ), 10, 2 );45 add_filter( 'tax_input_pre', array( $this, 'filter_tax_input' ) );46 44 add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) ); 47 45 add_filter( 'rest_api_allowed_post_types', array( $this, 'filter_allowed_post_types' ) ); … … 129 127 'show_ui' => current_user_can( 'plugin_set_section' ), 130 128 'show_admin_column' => current_user_can( 'plugin_set_section' ), 131 'meta_box_cb' => false, // 'post_categories_meta_box',132 129 'capabilities' => array( 133 130 'assign_terms' => 'plugin_set_section', … … 159 156 'show_ui' => true, 160 157 'show_admin_column' => true, 161 'meta_box_cb' => array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),162 158 'capabilities' => array( 163 159 'assign_terms' => 'plugin_set_category', … … 175 171 'show_ui' => true, 176 172 'show_admin_column' => false, 177 'meta_box_cb' => false, // array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),173 'meta_box_cb' => false, 178 174 'capabilities' => array( 179 175 'assign_terms' => 'plugin_set_category', … … 191 187 'show_ui' => true, 192 188 'show_admin_column' => false, 193 'meta_box_cb' => false, // array( __NAMESPACE__ . '\Admin\Metabox\Plugin_Categories', 'display' ),189 'meta_box_cb' => false, 194 190 'capabilities' => array( 195 191 'assign_terms' => 'plugin_set_category', … … 454 450 } 455 451 if ( 'plugin_built_for' == $term->taxonomy ) { 456 457 452 // Term slug = Post Slug = /%postname%/ 458 453 return trailingslashit( home_url( $term->slug ) ); … … 460 455 461 456 return $term_link; 462 }463 464 /**465 * Checks if the current users is a super admin before allowing terms to be added.466 *467 * @param string $term The term to add or update.468 * @param string $taxonomy The taxonomy of the term.469 * @return string|\WP_Error The term to add or update or WP_Error on failure.470 */471 public function pre_insert_term_prevent( $term, $taxonomy ) {472 $allowed_taxonomies = array( 'plugin_tags', 'plugin_contributors' );473 474 if ( ! in_array( $taxonomy, $allowed_taxonomies ) && ! is_super_admin() ) {475 $term = new \WP_Error( 'not-allowed', __( 'You are not allowed to add terms.', 'wporg-plugins' ) );476 }477 478 return $term;479 457 } 480 458 … … 773 751 774 752 if ( 'tags' === $path[2] ) { 775 if ( isset( Tag_To_Category::$map[ $path[3] ] ) ) { 776 wp_safe_redirect( home_url( '/category/' . Tag_To_Category::$map[ $path[3] ] . '/' ) ); 777 die(); 778 } else if ( isset( $path[3] ) ) { 779 wp_safe_redirect( home_url( '/search/' . $path[3] . '/' ) ); 753 if ( isset( $path[3] ) ) { 754 wp_safe_redirect( home_url( '/search/' . urlencode( $path[3] ) . '/' ) ); 780 755 die(); 781 756 } else { … … 793 768 // Otherwise, handle a plugin redirect. 794 769 if ( $plugin = self::get_plugin_post( $path[2] ) ) { 795 $is_disabled = in_array( $plugin->post_status, array( 'disabled', 'closed' ), true ); 796 797 if ( $is_disabled && current_user_can( 'edit_post', $plugin ) ) { 798 wp_safe_redirect( add_query_arg( array( 799 'post' => $plugin->ID, 800 'action' => 'edit', 801 ), admin_url( 'post.php' ) ) ); 802 die(); 803 } else if ( ! $is_disabled ) { 804 wp_safe_redirect( get_permalink( $plugin->ID ) ); 770 $permalink = get_permalink( $plugin->ID ); 771 if ( parse_url( $permalink, PHP_URL_PATH ) != $_SERVER['REQUEST_URI'] ) { 772 wp_safe_redirect( $permalink ); 805 773 die(); 806 774 } … … 966 934 967 935 return $content_pages; 968 }969 970 /**971 * Filters the value of tax_inputs before saving.972 *973 * Used both in the admin and the uploader.974 *975 * @param array $tax_input Array of taxonomies with selected terms.976 * @return array977 */978 public function filter_tax_input( $tax_input ) {979 980 // Limit the amount of assignable categories to 3.981 if ( isset( $tax_input['plugin_category'] ) ) {982 $tax_input['plugin_category'] = array_slice( array_filter( $tax_input['plugin_category'] ), 0, 3 );983 }984 985 return $tax_input;986 936 } 987 937
Note: See TracChangeset
for help on using the changeset viewer.