Make WordPress Core

Ticket #20659: wp-shortcode-desc-1.patch

File wp-shortcode-desc-1.patch, 4.3 KB (added by voxpelli, 11 years ago)

Sketch of what an implementation of something like this could look codewise - interface not worked on and code not complete

  • wp-includes/shortcodes.php

     
    128128}
    129129
    130130/**
     131 * Gets descriptions of all shortcodes.
     132 *
     133 * @uses $shortcode_tags
     134 *
     135 * @return array An array containing all shortcodes and description of them and its attributes
     136 */
     137function get_shortcode_descriptions() {
     138        global $shortcode_tags;
     139
     140        $descriptions = array();
     141
     142        foreach ( $shortcode_tags as $shortcode => $func ) {
     143                $descriptions[$shortcode] = get_shortcode_description( $shortcode );
     144        }
     145
     146        $descriptions = array_filter($descriptions);
     147        ksort($descriptions);
     148
     149        return $descriptions;
     150}
     151
     152/**
     153 * Gets description of a shortcode.
     154 *
     155 * @uses $shortcode_tags
     156 *
     157 * @param string $shortcode The namn of the shortcode to get the description of
     158 * @return array An array containing descriptions of the shortcode and its attributes
     159 */
     160function get_shortcode_description($shortcode) {
     161        global $shortcode_tags;
     162
     163        if ( !isset( $shortcode_tags[$shortcode] ) ) {
     164                return false;
     165        }
     166
     167        $description = array(
     168                'shortcode' => $shortcode,
     169                'description' => '',
     170                'atts' => array(),
     171        );
     172
     173        return apply_filters( 'shortcode_description', $description, $shortcode );
     174}
     175
     176/**
    131177 * Search content for shortcodes and filter shortcodes through their hooks.
    132178 *
    133179 * If there are no shortcode tags defined, then the content will be returned
  • wp-includes/media.php

     
    10621062
    10631063                // After a post is saved, cache oEmbed items via AJAX
    10641064                add_action( 'edit_form_advanced', array(&$this, 'maybe_run_ajax_cache') );
     1065
     1066                // Describe shortcode in post form
     1067                add_filter( 'shortcode_description', array(&$this, 'describe_shortcode') );
    10651068        }
    10661069
    10671070        /**
     
    10971100                return $content;
    10981101        }
    10991102
     1103        function describe_shortcode( $description ) {
     1104                if ( isset($description['shortcode']) && $description['shortcode'] == 'embed' ) {
     1105                        $description['description'] = 'Embeds the wrapped URL';
     1106                        $description['atts'] = array(
     1107                                'width' => 'Max width of the embed',
     1108                                'height' => 'Max height of the embed',
     1109                        );
     1110                }
     1111                return $description;
     1112        }
     1113
    11001114        /**
    11011115         * If a post/page was saved, then output JavaScript to make
    11021116         * an AJAX request that will call WP_Embed::cache_oembed().
  • wp-admin/includes/meta-boxes.php

     
    381381}
    382382
    383383/**
     384 * Display descriptions of shortcodes.
     385 *
     386 * @param object $post
     387 */
     388function post_shortcodedesc_meta_box($post) {
     389        $shortcodes = get_shortcode_descriptions();
     390
     391        $descriptions = '<ul>';
     392        foreach ($shortcodes as $shortcodes) {
     393                $descriptions .= "\n\t<li>\n\t\t<strong>[" . esc_html($shortcodes['shortcode']) . "]</strong> ";
     394                if (!empty($shortcodes['description'])) {
     395                        $descriptions .= '- ' . esc_html($shortcodes['description']);
     396                }
     397                if (!empty($shortcodes['atts'])) {
     398                        $descriptions .= "\n\t\t<ul>";
     399                        foreach ($shortcodes['atts'] as $attribute => $attributeDescription) {
     400                                $descriptions .= "\n\t\t\t<li><strong>" . esc_html($attribute) . "</strong> ";
     401                                if (!empty($attributeDescription)) {
     402                                        $descriptions .= '- ' . esc_html($attributeDescription);
     403                                }
     404                        }
     405                        $descriptions .= "\n\t\t</ul>";
     406                }
     407                $descriptions .= "\n\t</li>";
     408        }
     409        $descriptions .= '</ul>';
     410
     411        echo $descriptions;
     412}
     413
     414
     415/**
    384416 * Display trackback links form fields.
    385417 *
    386418 * @since 2.6.0
  • wp-admin/edit-form-advanced.php

     
    130130if ( post_type_supports($post_type, 'excerpt') )
    131131        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core');
    132132
     133if ( post_type_supports($post_type, 'editor') )
     134        add_meta_box('shortcodedesc', __('Shortcodes'), 'post_shortcodedesc_meta_box', null, 'side', 'core');
     135
    133136if ( post_type_supports($post_type, 'trackbacks') )
    134137        add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', null, 'normal', 'core');
    135138