Make WordPress Core


Ignore:
Timestamp:
09/16/2015 03:34:17 PM (10 years ago)
Author:
wonderboymusic
Message:

wp-admin/includes/template.php is now a loader for 3 files made via svn cp:

  • Walker_Category_Checklist class
  • WP_Internal_Pointers class
  • template-functions.php

This is BC for plugins that are loading wp-admin/includes/template.php for fun.

See #33413.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template-functions.php

    r34238 r34241  
    77 * @package WordPress
    88 * @subpackage Administration
     9 * @since 4.4.0
    910 */
    1011
     
    1213// Category Checklists
    1314//
    14 
    15 /**
    16  * Walker to output an unordered list of category checkbox input elements.
    17  *
    18  * @since 2.5.1
    19  *
    20  * @see Walker
    21  * @see wp_category_checklist()
    22  * @see wp_terms_checklist()
    23  */
    24 class Walker_Category_Checklist extends Walker {
    25     public $tree_type = 'category';
    26     public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
    27 
    28     /**
    29      * Starts the list before the elements are added.
    30      *
    31      * @see Walker:start_lvl()
    32      *
    33      * @since 2.5.1
    34      *
    35      * @param string $output Passed by reference. Used to append additional content.
    36      * @param int    $depth  Depth of category. Used for tab indentation.
    37      * @param array  $args   An array of arguments. @see wp_terms_checklist()
    38      */
    39     public function start_lvl( &$output, $depth = 0, $args = array() ) {
    40         $indent = str_repeat("\t", $depth);
    41         $output .= "$indent<ul class='children'>\n";
    42     }
    43 
    44     /**
    45      * Ends the list of after the elements are added.
    46      *
    47      * @see Walker::end_lvl()
    48      *
    49      * @since 2.5.1
    50      *
    51      * @param string $output Passed by reference. Used to append additional content.
    52      * @param int    $depth  Depth of category. Used for tab indentation.
    53      * @param array  $args   An array of arguments. @see wp_terms_checklist()
    54      */
    55     public function end_lvl( &$output, $depth = 0, $args = array() ) {
    56         $indent = str_repeat("\t", $depth);
    57         $output .= "$indent</ul>\n";
    58     }
    59 
    60     /**
    61      * Start the element output.
    62      *
    63      * @see Walker::start_el()
    64      *
    65      * @since 2.5.1
    66      *
    67      * @param string $output   Passed by reference. Used to append additional content.
    68      * @param object $category The current term object.
    69      * @param int    $depth    Depth of the term in reference to parents. Default 0.
    70      * @param array  $args     An array of arguments. @see wp_terms_checklist()
    71      * @param int    $id       ID of the current term.
    72      */
    73     public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
    74         if ( empty( $args['taxonomy'] ) ) {
    75             $taxonomy = 'category';
    76         } else {
    77             $taxonomy = $args['taxonomy'];
    78         }
    79 
    80         if ( $taxonomy == 'category' ) {
    81             $name = 'post_category';
    82         } else {
    83             $name = 'tax_input[' . $taxonomy . ']';
    84         }
    85 
    86         $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
    87         $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
    88 
    89         $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
    90 
    91         /** This filter is documented in wp-includes/category-template.php */
    92         if ( ! empty( $args['list_only'] ) ) {
    93             $aria_cheched = 'false';
    94             $inner_class = 'category';
    95 
    96             if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
    97                 $inner_class .= ' selected';
    98                 $aria_cheched = 'true';
    99             }
    100 
    101             $output .= "\n" . '<li' . $class . '>' .
    102                 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
    103                 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .
    104                 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>';
    105         } else {
    106             $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
    107                 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
    108                 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
    109                 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
    110                 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
    111         }
    112     }
    113 
    114     /**
    115      * Ends the element output, if needed.
    116      *
    117      * @see Walker::end_el()
    118      *
    119      * @since 2.5.1
    120      *
    121      * @param string $output   Passed by reference. Used to append additional content.
    122      * @param object $category The current term object.
    123      * @param int    $depth    Depth of the term in reference to parents. Default 0.
    124      * @param array  $args     An array of arguments. @see wp_terms_checklist()
    125      */
    126     public function end_el( &$output, $category, $depth = 0, $args = array() ) {
    127         $output .= "</li>\n";
    128     }
    129 }
    13015
    13116/**
     
    20161901}
    20171902
    2018 final class WP_Internal_Pointers {
    2019     /**
    2020      * Initializes the new feature pointers.
    2021      *
    2022      * @since 3.3.0
    2023      *
    2024      * All pointers can be disabled using the following:
    2025      *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
    2026      *
    2027      * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
    2028      *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
    2029      *
    2030      * @static
    2031      *
    2032      * @param string $hook_suffix The current admin page.
    2033      */
    2034     public static function enqueue_scripts( $hook_suffix ) {
    2035         /*
    2036          * Register feature pointers
    2037          *
    2038          * Format:
    2039          *     array(
    2040          *         hook_suffix => pointer callback
    2041          *     )
    2042          *
    2043          * Example:
    2044          *     array(
    2045          *         'themes.php' => 'wp390_widgets'
    2046          *     )
    2047          */
    2048         $registered_pointers = array(
    2049             // None currently
    2050         );
    2051 
    2052         // Check if screen related pointer is registered
    2053         if ( empty( $registered_pointers[ $hook_suffix ] ) )
    2054             return;
    2055 
    2056         $pointers = (array) $registered_pointers[ $hook_suffix ];
    2057 
    2058         /*
    2059          * Specify required capabilities for feature pointers
    2060          *
    2061          * Format:
    2062          *     array(
    2063          *         pointer callback => Array of required capabilities
    2064          *     )
    2065          *
    2066          * Example:
    2067          *     array(
    2068          *         'wp390_widgets' => array( 'edit_theme_options' )
    2069          *     )
    2070          */
    2071         $caps_required = array(
    2072             // None currently
    2073         );
    2074 
    2075         // Get dismissed pointers
    2076         $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    2077 
    2078         $got_pointers = false;
    2079         foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
    2080             if ( isset( $caps_required[ $pointer ] ) ) {
    2081                 foreach ( $caps_required[ $pointer ] as $cap ) {
    2082                     if ( ! current_user_can( $cap ) )
    2083                         continue 2;
    2084                 }
    2085             }
    2086 
    2087             // Bind pointer print function
    2088             add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
    2089             $got_pointers = true;
    2090         }
    2091 
    2092         if ( ! $got_pointers )
    2093             return;
    2094 
    2095         // Add pointers script and style to queue
    2096         wp_enqueue_style( 'wp-pointer' );
    2097         wp_enqueue_script( 'wp-pointer' );
    2098     }
    2099 
    2100     /**
    2101      * Print the pointer JavaScript data.
    2102      *
    2103      * @since 3.3.0
    2104      *
    2105      * @static
    2106      *
    2107      * @param string $pointer_id The pointer ID.
    2108      * @param string $selector The HTML elements, on which the pointer should be attached.
    2109      * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.js).
    2110      */
    2111     private static function print_js( $pointer_id, $selector, $args ) {
    2112         if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
    2113             return;
    2114 
    2115         ?>
    2116         <script type="text/javascript">
    2117         (function($){
    2118             var options = <?php echo wp_json_encode( $args ); ?>, setup;
    2119 
    2120             if ( ! options )
    2121                 return;
    2122 
    2123             options = $.extend( options, {
    2124                 close: function() {
    2125                     $.post( ajaxurl, {
    2126                         pointer: '<?php echo $pointer_id; ?>',
    2127                         action: 'dismiss-wp-pointer'
    2128                     });
    2129                 }
    2130             });
    2131 
    2132             setup = function() {
    2133                 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
    2134             };
    2135 
    2136             if ( options.position && options.position.defer_loading )
    2137                 $(window).bind( 'load.wp-pointers', setup );
    2138             else
    2139                 $(document).ready( setup );
    2140 
    2141         })( jQuery );
    2142         </script>
    2143         <?php
    2144     }
    2145 
    2146     public static function pointer_wp330_toolbar() {}
    2147     public static function pointer_wp330_media_uploader() {}
    2148     public static function pointer_wp330_saving_widgets() {}
    2149     public static function pointer_wp340_customize_current_theme_link() {}
    2150     public static function pointer_wp340_choose_image_from_library() {}
    2151     public static function pointer_wp350_media() {}
    2152     public static function pointer_wp360_revisions() {}
    2153     public static function pointer_wp360_locks() {}
    2154     public static function pointer_wp390_widgets() {}
    2155     public static function pointer_wp410_dfw() {}
    2156 
    2157     /**
    2158      * Prevents new users from seeing existing 'new feature' pointers.
    2159      *
    2160      * @since 3.3.0
    2161      *
    2162      * @static
    2163      *
    2164      * @param int $user_id User ID.
    2165      */
    2166     public static function dismiss_pointers_for_new_users( $user_id ) {
    2167         add_user_meta( $user_id, 'dismissed_wp_pointers', '' );
    2168     }
    2169 }
    2170 
    21711903/**
    21721904 * Convert a screen string to a screen object
Note: See TracChangeset for help on using the changeset viewer.