Make WordPress Core

Ticket #42486: 42486.2.diff

File 42486.2.diff, 2.6 KB (added by desrosj, 7 years ago)
  • src/wp-admin/includes/menu.php

     
    185185}
    186186unset( $id, $data, $subs, $first_sub );
    187187
     188// Hide the tools page if it's going to be empty.
     189$manage_taxonomies = false;
     190if ( current_user_can( 'import' ) ) {
     191        $cats = get_taxonomy( 'category' );
     192        $tags = get_taxonomy( 'post_tag' );
     193
     194        if ( current_user_can($cats->cap->manage_terms) || current_user_can($tags->cap->manage_terms) ) {
     195                $manage_taxonomies = true;
     196                add_action( 'tool_box', 'tool_box_categories_tags_converter', 1 );
     197        }
     198}
     199
     200if ( ! isset( $submenu['tools.php'] ) && ! $manage_taxonomies && ! has_action( 'tool_box' ) ) {
     201        foreach ( $menu as $i => $data ) {
     202                if ( 'tools.php' == $data[2] ) {
     203                        unset( $menu[ $i ] );
     204                        break;
     205                }
     206        }
     207        unset( $data );
     208}
     209
    188210/**
     211 * Display the tool box card for the Categories and Tags Converter.
     212 *
     213 * @since 4.9.6
     214 */
     215function tool_box_categories_tags_converter() {
     216        ?>
     217        <div class="card">
     218                <h2 class="title"><?php _e( 'Categories and Tags Converter' ) ?></h2>
     219                <p><?php printf( __('If you want to convert your categories to tags (or vice versa), use the <a href="%s">Categories and Tags Converter</a> available from the Import screen.'), 'import.php' ); ?></p>
     220        </div>
     221        <?php
     222}
     223
     224/**
    189225 * @param string $add
    190226 * @param string $class
    191227 * @return string
  • src/wp-admin/tools.php

     
    2929?>
    3030<div class="wrap">
    3131<h1><?php echo esc_html( $title ); ?></h1>
    32 <?php
    33 if ( current_user_can( 'import' ) ) :
    34 $cats = get_taxonomy('category');
    35 $tags = get_taxonomy('post_tag');
    36 if ( current_user_can($cats->cap->manage_terms) || current_user_can($tags->cap->manage_terms) ) : ?>
    37 <div class="card">
    38         <h2 class="title"><?php _e( 'Categories and Tags Converter' ) ?></h2>
    39         <p><?php printf( __('If you want to convert your categories to tags (or vice versa), use the <a href="%s">Categories and Tags Converter</a> available from the Import screen.'), 'import.php' ); ?></p>
    40 </div>
    41 <?php
    42 endif;
    43 endif;
    4432
    45 /**
    46  * Fires at the end of the Tools Administration screen.
    47  *
    48  * @since 2.8.0
    49  */
    50 do_action( 'tool_box' );
     33<?php if ( ! has_action( 'tool_box' ) ) { ?>
     34        <p><?php _e( 'Sorry, but there are no tools that you can access.' ); ?></p>
     35        <?php
     36} else {
     37        /**
     38         * Fires at the end of the Tools Administration screen.
     39         *
     40         * @since 2.8.0
     41         */
     42        do_action( 'tool_box' );
     43}
    5144?>
    5245</div>
    5346<?php