wp/wp-admin/includes/template.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Template WordPress Administration API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * A Big Mess. Also some neat functions that are nicely written.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
/** Walker_Category_Checklist class */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    12
require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
/** WP_Internal_Pointers class */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
// Category Checklists
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 * Output an unordered list of checkbox input elements labeled with category names.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 * @since 2.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
 * @see wp_terms_checklist()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
 * @param int    $post_id              Optional. Post to generate a categories checklist for. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
 *                                     $selected_cats must not be an array. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
 * @param int    $descendants_and_self Optional. ID of the category to output along with its descendants.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
 *                                     Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
 * @param array  $selected_cats        Optional. List of categories to mark as checked. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
 * @param array  $popular_cats         Optional. List of categories to receive the "popular-category" class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
 *                                     Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
 * @param object $walker               Optional. Walker object to use to build the output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
 *                                     Default is a Walker_Category_Checklist instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
 * @param bool   $checked_ontop        Optional. Whether to move checked items out of the hierarchy and to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
 *                                     the top of the list. Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	wp_terms_checklist( $post_id, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		'taxonomy' => 'category',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		'descendants_and_self' => $descendants_and_self,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		'selected_cats' => $selected_cats,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		'popular_cats' => $popular_cats,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		'walker' => $walker,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		'checked_ontop' => $checked_ontop
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
 * Output an unordered list of checkbox input elements labelled with term names.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
 * Taxonomy-independent version of wp_category_checklist().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
 * @since 4.4.0 Introduced the `$echo` argument.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
 * @param int          $post_id Optional. Post ID. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
 * @param array|string $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
 *     Optional. Array or string of arguments for generating a terms checklist. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
 *     @type int    $descendants_and_self ID of the category to output along with its descendants.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
 *                                        Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
 *     @type array  $selected_cats        List of categories to mark as checked. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
 *     @type array  $popular_cats         List of categories to receive the "popular-category" class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
 *                                        Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
 *     @type object $walker               Walker object to use to build the output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
 *                                        Default is a Walker_Category_Checklist instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
 *     @type string $taxonomy             Taxonomy to generate the checklist for. Default 'category'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
 *     @type bool   $checked_ontop        Whether to move checked items out of the hierarchy and to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
 *                                        the top of the list. Default true.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
 *     @type bool   $echo                 Whether to echo the generated markup. False to return the markup instead
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
 *                                        of echoing it. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
function wp_terms_checklist( $post_id = 0, $args = array() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
 	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		'descendants_and_self' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		'selected_cats' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		'popular_cats' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		'walker' => null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		'taxonomy' => 'category',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
		'checked_ontop' => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
		'echo' => true,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
	 * Filters the taxonomy terms checklist arguments.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	 * @see wp_terms_checklist()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	 * @param array $args    An array of arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	 * @param int   $post_id The post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
	$params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	$r = wp_parse_args( $params, $defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
		$walker = new Walker_Category_Checklist;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
		$walker = $r['walker'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
	$taxonomy = $r['taxonomy'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
	$descendants_and_self = (int) $r['descendants_and_self'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	$args = array( 'taxonomy' => $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
	$tax = get_taxonomy( $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	$args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
	$args['list_only'] = ! empty( $r['list_only'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	if ( is_array( $r['selected_cats'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
		$args['selected_cats'] = $r['selected_cats'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	} elseif ( $post_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
		$args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
		$args['selected_cats'] = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	if ( is_array( $r['popular_cats'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
		$args['popular_cats'] = $r['popular_cats'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		$args['popular_cats'] = get_terms( $taxonomy, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
			'fields' => 'ids',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
			'orderby' => 'count',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
			'order' => 'DESC',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
			'number' => 10,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
			'hierarchical' => false
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	if ( $descendants_and_self ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		$categories = (array) get_terms( $taxonomy, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
			'child_of' => $descendants_and_self,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			'hierarchical' => 0,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
			'hide_empty' => 0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		$self = get_term( $descendants_and_self, $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		array_unshift( $categories, $self );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
		$categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
	$output = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
	if ( $r['checked_ontop'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
		// Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		$checked_categories = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		$keys = array_keys( $categories );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   155
		foreach ( $keys as $k ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
			if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
				$checked_categories[] = $categories[$k];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
				unset( $categories[$k] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		// Put checked cats on top
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   163
		$output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	// Then the rest of them
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
	$output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
	if ( $r['echo'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
		echo $output;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
	return $output;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 * Retrieve a list of the most popular terms from the specified taxonomy.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 * If the $echo argument is true then the elements for a list of checkbox
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
 * `<input>` elements labelled with the names of the selected terms is output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * If the $post_ID global isn't empty then the terms associated with that
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 * post will be marked as checked.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @param string $taxonomy Taxonomy to retrieve terms from.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
 * @param int $default Not used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * @param int $number Number of terms to retrieve. Defaults to 10.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * @param bool $echo Optionally output the list as well. Defaults to true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * @return array List of popular term IDs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	if ( $post && $post->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		$checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		$checked_terms = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	$terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	$tax = get_taxonomy($taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	$popular_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
	foreach ( (array) $terms as $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		$popular_ids[] = $term->term_id;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
		if ( !$echo ) // Hack for Ajax use.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
		$id = "popular-$taxonomy-$term->term_id";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		$checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		<li id="<?php echo $id; ?>" class="popular-category">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			<label class="selectit">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
				<input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> />
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
				<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
				/** This filter is documented in wp-includes/category-template.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
				echo esc_html( apply_filters( 'the_category', $term->name, '', '' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
				?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		</li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	return $popular_ids;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
 * Outputs a link category checklist element.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * @since 2.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
 * @param int $link_id
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
function wp_link_category_checklist( $link_id = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	$default = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
	$checked_categories = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	if ( $link_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		$checked_categories = wp_get_link_cats( $link_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		// No selected categories, strange
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
		if ( ! count( $checked_categories ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
			$checked_categories[] = $default;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		$checked_categories[] = $default;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	$categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	if ( empty( $categories ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	foreach ( $categories as $category ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		$cat_id = $category->term_id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
		/** This filter is documented in wp-includes/category-template.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   258
		$name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		$checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
 * Adds hidden fields with the data for use in the inline editor for posts and pages.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
 * @param WP_Post $post Post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
function get_inline_data($post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	$post_type_object = get_post_type_object($post->post_type);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	if ( ! current_user_can( 'edit_post', $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	$title = esc_textarea( trim( $post->post_title ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
	/** This filter is documented in wp-admin/edit-tag-form.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	echo '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
<div class="hidden" id="inline_' . $post->ID . '">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
	<div class="post_title">' . $title . '</div>' .
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
	/** This filter is documented in wp-admin/edit-tag-form.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   283
	'<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	<div class="post_author">' . $post->post_author . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	<div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	<div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	<div class="_status">' . esc_html( $post->post_status ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	<div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	<div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	<div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	<div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	<div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	<div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	<div class="post_password">' . esc_html( $post->post_password ) . '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   296
	if ( $post_type_object->hierarchical ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		echo '<div class="post_parent">' . $post->post_parent . '</div>';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   298
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   300
	echo '<div class="page_template">' . ( $post->page_template ? esc_html( $post->page_template ) : 'default' ) . '</div>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
	if ( post_type_supports( $post->post_type, 'page-attributes' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		echo '<div class="menu_order">' . $post->menu_order . '</div>';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	$taxonomy_names = get_object_taxonomies( $post->post_type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	foreach ( $taxonomy_names as $taxonomy_name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		$taxonomy = get_taxonomy( $taxonomy_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
			$terms = get_object_term_cache( $post->ID, $taxonomy_name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
			if ( false === $terms ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
				$terms = wp_get_object_terms( $post->ID, $taxonomy_name );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
				wp_cache_add( $post->ID, wp_list_pluck( $terms, 'term_id' ), $taxonomy_name . '_relationships' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
			$term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
			echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		} elseif ( $taxonomy->show_ui ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   323
			$terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
			if ( ! is_string( $terms_to_edit ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
				$terms_to_edit = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">'
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
				. esc_html( str_replace( ',', ', ', $terms_to_edit ) ) . '</div>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	if ( !$post_type_object->hierarchical )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	if ( post_type_supports( $post->post_type, 'post-formats' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
	 * Fires after outputting the fields for the inline editor for posts and pages.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
	 * @since 4.9.8
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
	 * @param WP_Post      $post             The current post object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
	 * @param WP_Post_Type $post_type_object The current post's post type object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
	do_action( 'add_inline_data', $post, $post_type_object );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
 * Outputs the in-line comment reply-to form in the Comments list table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
 * @global WP_List_Table $wp_list_table
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
 * @param int    $position
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
 * @param bool   $checkbox
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
 * @param string $mode
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
 * @param bool   $table_row
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
	global $wp_list_table;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
	 * Filters the in-line comment reply-to form output in the Comments
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
	 * list table.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	 * Returning a non-empty value here will short-circuit display
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
	 * of the in-line comment-reply form in the Comments list table,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
	 * echoing the returned value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	 * @since 2.7.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
	 * @see wp_comment_reply()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
	 * @param string $content The reply-to form content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
	 * @param array  $args    An array of default args.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	$content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
	if ( ! empty($content) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		echo $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
	if ( ! $wp_list_table ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
		if ( $mode == 'single' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
			$wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
			$wp_list_table = _get_list_table('WP_Comments_List_Table');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
<form method="get">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
<?php if ( $table_row ) : ?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
<table style="display:none;"><tbody id="com-reply"><tr id="replyrow" class="inline-edit-row" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
<?php else : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
<div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
<?php endif; ?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
	<fieldset class="comment-reply">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
	<legend>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
		<span class="hidden" id="editlegend"><?php _e( 'Edit Comment' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
		<span class="hidden" id="replyhead"><?php _e( 'Reply to Comment' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
		<span class="hidden" id="addhead"><?php _e( 'Add new Comment' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
	</legend>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
	<div id="replycontainer">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
	<label for="replycontent" class="screen-reader-text"><?php _e( 'Comment' ); ?></label>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
	<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
	$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
	wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
	?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
	</div>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	<div id="edithead" style="display:none;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		<div class="inside">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
		<label for="author-name"><?php _e( 'Name' ) ?></label>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
		<input type="text" name="newcomment_author" size="50" value="" id="author-name" />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		<div class="inside">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
		<label for="author-email"><?php _e('Email') ?></label>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
		<input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		<div class="inside">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		<label for="author-url"><?php _e('URL') ?></label>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
		<input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
	<div id="replysubmit" class="submit">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
		<p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
			<a href="#comments-form" class="save button button-primary alignright">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
				<span id="addbtn" style="display: none;"><?php _e( 'Add Comment' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   440
				<span id="savebtn" style="display: none;"><?php _e( 'Update Comment' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   441
				<span id="replybtn" style="display: none;"><?php _e( 'Submit Reply' ); ?></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
			</a>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   443
			<a href="#comments-form" class="cancel button alignleft"><?php _e( 'Cancel' ); ?></a>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   444
			<span class="waiting spinner"></span>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
		</p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
		<br class="clear" />
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   447
		<div class="notice notice-error notice-alt inline hidden">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   448
			<p class="error"></p>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   449
		</div>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   450
	</div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	<input type="hidden" name="action" id="action" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	<input type="hidden" name="comment_ID" id="comment_ID" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	<input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	<input type="hidden" name="status" id="status" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	<input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	<input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	<input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		if ( current_user_can( 'unfiltered_html' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   464
	</fieldset>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
<?php if ( $table_row ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
</td></tr></tbody></table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
<?php else : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
</div></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
 * Output 'undo move to trash' text for comments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
function wp_comment_trashnotice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
<div class="hidden" id="trash-undo-holder">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	<div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
<div class="hidden" id="spam-undo-holder">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	<div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
 * Outputs a post's public meta data in the Custom Fields meta box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
 * @param array $meta
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
function list_meta( $meta ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	// Exit if no meta
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	if ( ! $meta ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		echo '
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
<table id="list-table" style="display: none;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	<thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		<th class="left">' . _x( 'Name', 'meta name' ) . '</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		<th>' . __( 'Value' ) . '</th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	<tbody id="the-list" data-wp-lists="list:meta">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	<tr><td></td></tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
</table>'; //TBODY needed for list-manipulation JS
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	$count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
<table id="list-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	<thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		<th class="left"><?php _ex( 'Name', 'meta name' ) ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		<th><?php _e( 'Value' ) ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	<tbody id='the-list' data-wp-lists='list:meta'>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	foreach ( $meta as $entry )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
		echo _list_meta_row( $entry, $count );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   534
 * Outputs a single row of public meta data in the Custom Fields meta box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   538
 * @staticvar string $update_nonce
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   539
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
 * @param array $entry
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
 * @param int   $count
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
 * @return string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
function _list_meta_row( $entry, &$count ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   545
	static $update_nonce = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	if ( is_protected_meta( $entry['meta_key'], 'post' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
		return '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   550
	if ( ! $update_nonce )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
		$update_nonce = wp_create_nonce( 'add-meta' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	++ $count;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	if ( is_serialized( $entry['meta_value'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
		if ( is_serialized_string( $entry['meta_value'] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
			// This is a serialized string, so we should display it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
			$entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
			// This is a serialized array/object so we should NOT display it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
			--$count;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
			return '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	$entry['meta_key'] = esc_attr($entry['meta_key']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	$entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	$entry['meta_id'] = (int) $entry['meta_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
	$delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
	$r .= "\n\t<tr id='meta-{$entry['meta_id']}'>";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
	$r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta-{$entry['meta_id']}-key'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	$r .= "\n\t\t<div class='submit'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	$r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	$r .= "\n\t\t";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
	$r .= get_submit_button( __( 'Update' ), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	$r .= "</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	$r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	$r .= "</td>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
	$r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	return $r;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
 * Prints the form in the Custom Fields meta box.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   593
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   594
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
 * @param WP_Post $post Optional. The post being edited.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
function meta_form( $post = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
	$post = get_post( $post );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   602
	 * Filters values for the meta key dropdown in the Custom Fields meta box.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   603
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   604
	 * Returning a non-null value will effectively short-circuit and avoid a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   605
	 * potentially expensive query against postmeta.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   607
	 * @since 4.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   609
	 * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
	 * @param WP_Post    $post The current post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   612
	$keys = apply_filters( 'postmeta_form_keys', null, $post );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   614
	if ( null === $keys ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   615
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   616
		 * Filters the number of custom fields to retrieve for the drop-down
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   617
		 * in the Custom Fields meta box.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   618
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   619
		 * @since 2.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   620
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   621
		 * @param int $limit Number of custom fields to retrieve. Default 30.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   622
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   623
		$limit = apply_filters( 'postmeta_form_limit', 30 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   624
		$sql = "SELECT DISTINCT meta_key
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   625
			FROM $wpdb->postmeta
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   626
			WHERE meta_key NOT BETWEEN '_' AND '_z'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   627
			HAVING meta_key NOT LIKE %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   628
			ORDER BY meta_key
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   629
			LIMIT %d";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   630
		$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   631
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   632
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
	if ( $keys ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
		natcasesort( $keys );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   635
		$meta_key_input_id = 'metakeyselect';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
		$meta_key_input_id = 'metakeyinput';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
<p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
<table id="newmeta">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
<thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
<tr>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
<th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
<th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
<td id="newmetaleft" class="left">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
<?php if ( $keys ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
<select id="metakeyselect" name="metakeyselect">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
<option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	foreach ( $keys as $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
		if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
		echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
<input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
<span id="enternew"><?php _e('Enter new'); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
<span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
<?php } else { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
<input type="text" id="metakeyinput" name="metakeyinput" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
<tr><td colspan="2">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
<div class="submit">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   677
<?php submit_button( __( 'Add Custom Field' ), '', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
<?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
</td></tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
 * Print out HTML form date elements for editing post or comment publish date.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
 * @since 0.71
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
 * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   692
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   693
 * @global WP_Locale  $wp_locale
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   695
 * @param int|bool $edit      Accepts 1|true for editing the date, 0|false for adding the date.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   696
 * @param int|bool $for_post  Accepts 1|true for applying the date to a post, 0|false for a comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
 * @param int      $tab_index The tabindex attribute to add. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   698
 * @param int|bool $multi     Optional. Whether the additional fields and buttons should be added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   699
 *                            Default 0|false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   702
	global $wp_locale;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	if ( $for_post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		$edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	$tab_index_attribute = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
	if ( (int) $tab_index > 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		$tab_index_attribute = " tabindex=\"$tab_index\"";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   712
	// todo: Remove this?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	// echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	$time_adj = current_time('timestamp');
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   716
	$post_date = ($for_post) ? $post->post_date : get_comment()->comment_date;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	$jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	$mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	$aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	$hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
	$mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	$ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
	$cur_jj = gmdate( 'd', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	$cur_mm = gmdate( 'm', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
	$cur_aa = gmdate( 'Y', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	$cur_hh = gmdate( 'H', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	$cur_mn = gmdate( 'i', $time_adj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   730
	$month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	for ( $i = 1; $i < 13; $i = $i +1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
		$monthnum = zeroise($i, 2);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   733
		$monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   734
		$month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
		/* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   736
		$month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   738
	$month .= '</select></label>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   740
	$day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   741
	$year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   742
	$hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
	$minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
	echo '<div class="timestamp-wrap">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	/* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   747
	printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
	if ( $multi ) return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
	echo "\n\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
	$map = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
		'mm' => array( $mm, $cur_mm ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
		'jj' => array( $jj, $cur_jj ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
		'aa' => array( $aa, $cur_aa ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
		'hh' => array( $hh, $cur_hh ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
		'mn' => array( $mn, $cur_mn ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   760
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   761
	foreach ( $map as $timeunit => $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
		list( $unit, $curr ) = $value;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   763
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
		echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		$cur_timeunit = 'cur_' . $timeunit;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
		echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
<a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
<a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
 * Print out option HTML elements for the page templates drop-down.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   781
 * @since 4.7.0 Added the `$post_type` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   783
 * @param string $default   Optional. The template file name. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   784
 * @param string $post_type Optional. Post type to get templates for. Default 'post'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   786
function page_template_dropdown( $default = '', $post_type = 'page' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
	$templates = get_page_templates( null, $post_type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
	ksort( $templates );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
	foreach ( array_keys( $templates ) as $template ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
		$selected = selected( $default, $templates[ $template ], false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
		echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . "</option>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
 * Print out option HTML elements for the page parents drop-down.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
 * @since 1.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   799
 * @since 4.4.0 `$post` argument was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   801
 * @global wpdb $wpdb WordPress database abstraction object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   802
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   803
 * @param int         $default Optional. The default page ID to be pre-selected. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   804
 * @param int         $parent  Optional. The parent page ID. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   805
 * @param int         $level   Optional. Page depth level. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   806
 * @param int|WP_Post $post    Post ID or WP_Post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
 * @return null|false Boolean False if page has no children, otherwise print out html elements
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   810
function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
	global $wpdb;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   812
	$post = get_post( $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	if ( $items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
		foreach ( $items as $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
			// A page cannot be its own parent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
			if ( $post && $post->ID && $item->ID == $post->ID )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
			$pad = str_repeat( '&nbsp;', $level * 3 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
			$selected = selected( $default, $item->ID, false );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
			echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
			parent_dropdown( $default, $item->ID, $level +1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
 * Print out option html elements for role selectors.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
 * @param string $selected Slug for the role that should be already selected.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
function wp_dropdown_roles( $selected = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
	$r = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	$editable_roles = array_reverse( get_editable_roles() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
	foreach ( $editable_roles as $role => $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
		$name = translate_user_role($details['name'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   846
		// preselect specified role
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   847
		if ( $selected == $role ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   848
			$r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   849
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   850
			$r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>";
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   851
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   853
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   854
	echo $r;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
 * Outputs the form used by the importers to accept the data to be imported
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
 * @param string $action The action attribute for the form.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
function wp_import_upload_form( $action ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   867
	 * Filters the maximum allowed upload size for import files.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
	 * @since 2.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
	 * @see wp_max_upload_size()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
	 * @param int $max_upload_size Allowed upload size. Default 1 MB.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
	$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	$size = size_format( $bytes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	$upload_dir = wp_upload_dir();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	if ( ! empty( $upload_dir['error'] ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		<p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
	else :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
<form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
<input type="file" id="upload" name="import" size="25" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
<input type="hidden" name="action" value="save" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
</p>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   890
<?php submit_button( __('Upload file and import'), 'primary' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   897
 * Adds a meta box to one or more screens.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
 * @since 2.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   900
 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   902
 * @global array $wp_meta_boxes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   903
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   904
 * @param string                 $id            Meta box ID (used in the 'id' attribute for the meta box).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   905
 * @param string                 $title         Title of the meta box.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   906
 * @param callable               $callback      Function that fills the box with the desired content.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   907
 *                                              The function should echo its output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   908
 * @param string|array|WP_Screen $screen        Optional. The screen or screens on which to show the box
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   909
 *                                              (such as a post type, 'link', or 'comment'). Accepts a single
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   910
 *                                              screen ID, WP_Screen object, or array of screen IDs. Default
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   911
 *                                              is the current screen.  If you have used add_menu_page() or
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   912
 *                                              add_submenu_page() to create a new screen (and hence screen_id),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   913
 *                                              make sure your menu slug conforms to the limits of sanitize_key()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   914
 *                                              otherwise the 'screen' menu may not correctly render on your page.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   915
 * @param string                 $context       Optional. The context within the screen where the boxes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   916
 *                                              should display. Available contexts vary from screen to
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   917
 *                                              screen. Post edit screen contexts include 'normal', 'side',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   918
 *                                              and 'advanced'. Comments screen contexts include 'normal'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   919
 *                                              and 'side'. Menus meta boxes (accordion sections) all use
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   920
 *                                              the 'side' context. Global default is 'advanced'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   921
 * @param string                 $priority      Optional. The priority within the context where the boxes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   922
 *                                              should show ('high', 'low'). Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   923
 * @param array                  $callback_args Optional. Data that should be set as the $args property
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   924
 *                                              of the box array (which is the second parameter passed
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   925
 *                                              to your callback). Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
	global $wp_meta_boxes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   930
	if ( empty( $screen ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		$screen = get_current_screen();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   932
	} elseif ( is_string( $screen ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		$screen = convert_to_screen( $screen );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   934
	} elseif ( is_array( $screen ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   935
		foreach ( $screen as $single_screen ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   936
			add_meta_box( $id, $title, $callback, $single_screen, $context, $priority, $callback_args );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   937
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   938
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   939
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   940
	if ( ! isset( $screen->id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   941
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   942
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	$page = $screen->id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	if ( !isset($wp_meta_boxes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		$wp_meta_boxes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	if ( !isset($wp_meta_boxes[$page]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
		$wp_meta_boxes[$page] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	if ( !isset($wp_meta_boxes[$page][$context]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
		$wp_meta_boxes[$page][$context] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
			// If a core box was previously added or removed by a plugin, don't add.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
			if ( 'core' == $priority ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
				// If core box previously deleted, don't add
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
				if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
					return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
				/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
				 * If box was added with default priority, give it core priority to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   966
				 * maintain sort order.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   967
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
				if ( 'default' == $a_priority ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
					$wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
					unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
			// If no priority given and id already present, use existing priority.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			if ( empty($priority) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
				$priority = $a_priority;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
			 * Else, if we're adding to the sorted priority, we don't know the title
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
			 * or callback. Grab them from the previously added context/priority.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
			} elseif ( 'sorted' == $priority ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
				$title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
				$callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
				$callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
			// An id can be in only one priority and one context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
			if ( $priority != $a_priority || $context != $a_context )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
				unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
	if ( empty($priority) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		$priority = 'low';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
	if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
		$wp_meta_boxes[$page][$context][$priority] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
 * Meta-Box template function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1006
 * @global array $wp_meta_boxes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1007
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
 * @staticvar bool $already_sorted
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1009
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1010
 * @param string|WP_Screen $screen  Screen identifier. If you have used add_menu_page() or
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1011
 *                                  add_submenu_page() to create a new screen (and hence screen_id)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1012
 *                                  make sure your menu slug conforms to the limits of sanitize_key()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1013
 *                                  otherwise the 'screen' menu may not correctly render on your page.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1014
 * @param string           $context box context
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1015
 * @param mixed            $object  gets passed to the box callback function as first parameter
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
 * @return int number of meta_boxes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
function do_meta_boxes( $screen, $context, $object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
	global $wp_meta_boxes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	static $already_sorted = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	if ( empty( $screen ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		$screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	elseif ( is_string( $screen ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
		$screen = convert_to_screen( $screen );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	$page = $screen->id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
	$hidden = get_hidden_meta_boxes( $screen );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1031
	printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
	// Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
	if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
		foreach ( $sorted as $box_context => $ids ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
			foreach ( explode( ',', $ids ) as $id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
				if ( $id && 'dashboard_browser_nag' !== $id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
					add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
	$already_sorted = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
	$i = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
	if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
		foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
			if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ]) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
				foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
					if ( false == $box || ! $box['title'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
						continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
					$i++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
					$hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
					echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1057
					if ( 'dashboard_browser_nag' != $box['id'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1058
						$widget_title = $box[ 'title' ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1059
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1060
						if ( is_array( $box[ 'args' ] ) && isset( $box[ 'args' ][ '__widget_basename' ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1061
							$widget_title = $box[ 'args' ][ '__widget_basename' ];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1062
							// Do not pass this parameter to the user callback function.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1063
							unset( $box[ 'args' ][ '__widget_basename' ] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1066
						echo '<button type="button" class="handlediv" aria-expanded="true">';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1067
						echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
						echo '<span class="toggle-indicator" aria-hidden="true"></span>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1069
						echo '</button>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1070
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
					echo "<h2 class='hndle'><span>{$box['title']}</span></h2>\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
					echo '<div class="inside">' . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
					call_user_func($box['callback'], $object, $box);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
					echo "</div>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
					echo "</div>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1079
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
	echo "</div>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	return $i;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1088
 * Removes a meta box from one or more screens.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
 * @since 2.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
 * @global array $wp_meta_boxes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
 * @param string                 $id      Meta box ID (used in the 'id' attribute for the meta box).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
 * @param string|array|WP_Screen $screen  The screen or screens on which the meta box is shown (such as a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
 *                                        post type, 'link', or 'comment'). Accepts a single screen ID,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
 *                                        WP_Screen object, or array of screen IDs.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1099
 * @param string                 $context The context within the screen where the box is set to display.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1100
 *                                        Contexts vary from screen to screen. Post edit screen contexts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
 *                                        include 'normal', 'side', and 'advanced'. Comments screen contexts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
 *                                        include 'normal' and 'side'. Menus meta boxes (accordion sections)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
 *                                        all use the 'side' context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
function remove_meta_box( $id, $screen, $context ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
	global $wp_meta_boxes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
	if ( empty( $screen ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
		$screen = get_current_screen();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
	} elseif ( is_string( $screen ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
		$screen = convert_to_screen( $screen );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
	} elseif ( is_array( $screen ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
		foreach ( $screen as $single_screen ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
			remove_meta_box( $id, $single_screen, $context );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
	if ( ! isset( $screen->id ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
	$page = $screen->id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
	if ( !isset($wp_meta_boxes) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
		$wp_meta_boxes = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
	if ( !isset($wp_meta_boxes[$page]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
		$wp_meta_boxes[$page] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
	if ( !isset($wp_meta_boxes[$page][$context]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
		$wp_meta_boxes[$page][$context] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
	foreach ( array('high', 'core', 'default', 'low') as $priority )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
		$wp_meta_boxes[$page][$context][$priority][$id] = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
 * Meta Box Accordion Template Function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1138
 * Largely made up of abstracted code from do_meta_boxes(), this
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
 * function serves to build meta boxes as list items for display as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
 * a collapsible accordion.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
 * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
 * @param string|object $screen  The screen identifier.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
 * @param string        $context The meta box context.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1148
 * @param mixed         $object  gets passed to the section callback function as first parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
 * @return int number of meta boxes as accordion sections.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
function do_accordion_sections( $screen, $context, $object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
	global $wp_meta_boxes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
	wp_enqueue_script( 'accordion' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
	if ( empty( $screen ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
		$screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
	elseif ( is_string( $screen ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
		$screen = convert_to_screen( $screen );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
	$page = $screen->id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	$hidden = get_hidden_meta_boxes( $screen );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
	<div id="side-sortables" class="accordion-container">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		<ul class="outer-border">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	$i = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
	$first_open = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
	if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
		foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
			if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
				foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
					if ( false == $box || ! $box['title'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
						continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
					$i++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
					$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
					$open_class = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
					if ( ! $first_open && empty( $hidden_class ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
						$first_open = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
						$open_class = 'open';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
					?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
					<li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
						<h3 class="accordion-section-title hndle" tabindex="0">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
							<?php echo esc_html( $box['title'] ); ?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1189
							<span class="screen-reader-text"><?php _e( 'Press return or enter to open this section' ); ?></span>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
						</h3>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
						<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
							<div class="inside">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
								<?php call_user_func( $box['callback'], $object, $box ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
							</div><!-- .inside -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
						</div><!-- .accordion-section-content -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
					</li><!-- .accordion-section -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
					<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		</ul><!-- .outer-border -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
	</div><!-- .accordion-container -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
	return $i;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
 * Add a new section to a settings page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
 * Part of the Settings API. Use this to define new settings sections for an admin page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
 * Show settings sections in your admin page callback function with do_settings_sections().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
 * Add settings fields to your section with add_settings_field()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
 * The $callback argument should be the name of a function that echoes out any
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
 * content you want to show at the top of the settings section before the actual
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
 * fields. It can output nothing if you want.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1224
 * @param string   $id       Slug-name to identify the section. Used in the 'id' attribute of tags.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1225
 * @param string   $title    Formatted title of the section. Shown as the heading for the section.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1226
 * @param callable $callback Function that echos out any content at the top of the section (between heading and fields).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1227
 * @param string   $page     The slug-name of the settings page on which to show the section. Built-in pages include
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1228
 *                           'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1229
 *                           add_options_page();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
function add_settings_section($id, $title, $callback, $page) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
	global $wp_settings_sections;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
	if ( 'misc' == $page ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1235
		_deprecated_argument( __FUNCTION__, '3.0.0',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1236
			/* translators: %s: misc */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1237
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1238
				'misc'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1239
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1240
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
		$page = 'general';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	if ( 'privacy' == $page ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1245
		_deprecated_argument( __FUNCTION__, '3.5.0',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1246
			/* translators: %s: privacy */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1247
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1248
				'privacy'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1249
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1250
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		$page = 'reading';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
	$wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
 * Add a new field to a section of a settings page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
 * Part of the Settings API. Use this to define a settings field that will show
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
 * as part of a settings section inside a settings page. The fields are shown using
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
 * do_settings_fields() in do_settings-sections()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
 * The $callback argument should be the name of a function that echoes out the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
 * html input tags for this setting field. Use get_option() to retrieve existing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
 * values to show.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
 * @since 2.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
 * @since 4.2.0 The `$class` argument was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1273
 * @param string   $id       Slug-name to identify the field. Used in the 'id' attribute of tags.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1274
 * @param string   $title    Formatted title of the field. Shown as the label for the field
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1275
 *                           during output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1276
 * @param callable $callback Function that fills the field with the desired form inputs. The
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1277
 *                           function should echo its output.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1278
 * @param string   $page     The slug-name of the settings page on which to show the section
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1279
 *                           (general, reading, writing, ...).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1280
 * @param string   $section  Optional. The slug-name of the section of the settings page
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1281
 *                           in which to show the box. Default 'default'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1282
 * @param array    $args {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1283
 *     Optional. Extra arguments used when outputting the field.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1284
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
 *     @type string $label_for When supplied, the setting title will be wrapped
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1286
 *                             in a `<label>` element, its `for` attribute populated
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1287
 *                             with this value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1288
 *     @type string $class     CSS Class to be added to the `<tr>` element when the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
 *                             field is output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1290
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	global $wp_settings_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
	if ( 'misc' == $page ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1296
		_deprecated_argument( __FUNCTION__, '3.0.0',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1297
			/* translators: %s: misc */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1299
				'misc'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1300
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1301
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
		$page = 'general';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
	if ( 'privacy' == $page ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1306
		_deprecated_argument( __FUNCTION__, '3.5.0',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1307
			/* translators: %s: privacy */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1308
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1309
				'privacy'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1310
			)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1311
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
		$page = 'reading';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
	$wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
 * Prints out all settings sections added to a particular settings page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
 * Part of the Settings API. Use this in a settings page callback function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
 * to output all the sections and fields that were added to that $page with
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
 * add_settings_section() and add_settings_field()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
 * @global $wp_settings_sections Storage array of all settings sections added to admin pages
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
 * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1329
 * @param string $page The slug name of the page whose settings sections you want to output
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
function do_settings_sections( $page ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
	global $wp_settings_sections, $wp_settings_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
	if ( ! isset( $wp_settings_sections[$page] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
	foreach ( (array) $wp_settings_sections[$page] as $section ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
		if ( $section['title'] )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1339
			echo "<h2>{$section['title']}</h2>\n";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
		if ( $section['callback'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
			call_user_func( $section['callback'], $section );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
		if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
		echo '<table class="form-table">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
		do_settings_fields( $page, $section['id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
		echo '</table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
 * Print out the settings fields for a particular settings section
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
 * Part of the Settings API. Use this in a settings page to output
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
 * a specific section. Should normally be called by do_settings_sections()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
 * rather than directly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
 * @global $wp_settings_fields Storage array of settings fields and their pages/sections
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
 * @param string $page Slug title of the admin page who's settings fields you want to show.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
 * @param string $section Slug title of the settings section who's fields you want to show.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
function do_settings_fields($page, $section) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
	global $wp_settings_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
	if ( ! isset( $wp_settings_fields[$page][$section] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
	foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1373
		$class = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1374
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1375
		if ( ! empty( $field['args']['class'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
			$class = ' class="' . esc_attr( $field['args']['class'] ) . '"';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
		echo "<tr{$class}>";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1381
		if ( ! empty( $field['args']['label_for'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
			echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1383
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
			echo '<th scope="row">' . $field['title'] . '</th>';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
		echo '<td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
		call_user_func($field['callback'], $field['args']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
		echo '</td>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
		echo '</tr>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
 * Register a settings error to be displayed to the user
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
 * Part of the Settings API. Use this to show messages to users about settings validation
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
 * problems, missing settings or anything else.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
 * Settings errors should be added inside the $sanitize_callback function defined in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
 * register_setting() for a given setting to give feedback about the submission.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
 * By default messages will show immediately after the submission that generated the error.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
 * Additional calls to settings_errors() can be used to show errors even when the settings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
 * page is first accessed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
 * @global array $wp_settings_errors Storage array of errors registered during this pageload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
 * @param string $setting Slug title of the setting to which this error applies
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
 * @param string $code    Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
 * @param string $message The formatted message text to display to the user (will be shown inside styled
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
 *                        `<div>` and `<p>` tags).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
 * @param string $type    Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
 *                        Default 'error'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	global $wp_settings_errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1421
	$wp_settings_errors[] = array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
		'setting' => $setting,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
		'code'    => $code,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
		'message' => $message,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
		'type'    => $type
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
 * Fetch settings errors registered by add_settings_error()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
 * Checks the $wp_settings_errors array for any errors declared during the current
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
 * pageload and returns them.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
 * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
 * to the 'settings_errors' transient then those errors will be returned instead. This
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
 * is used to pass errors back across pageloads.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
 * Use the $sanitize argument to manually re-sanitize the option before returning errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
 * This is useful if you have errors or notices you want to show even when the user
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
 * hasn't submitted data (i.e. when they first load an options page, or in the {@see 'admin_notices'}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1442
 * action hook).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
 * @global array $wp_settings_errors Storage array of errors registered during this pageload
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
 * @param string $setting Optional slug title of a specific setting who's errors you want.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
 * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
 * @return array Array of settings errors
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
function get_settings_errors( $setting = '', $sanitize = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
	global $wp_settings_errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
	 * If $sanitize is true, manually re-run the sanitization for this option
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
	 * This allows the $sanitize_callback from register_setting() to run, adding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
	 * any settings errors you want to show by default.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
	if ( $sanitize )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
		sanitize_option( $setting, get_option( $setting ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
	// If settings were passed back from options.php then use them.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
	if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
		$wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
		delete_transient( 'settings_errors' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
	// Check global in case errors have been added on this pageload.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1470
	if ( empty( $wp_settings_errors ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
		return array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1472
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
	// Filter the results to those of a specific setting if one was set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
	if ( $setting ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
		$setting_errors = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
		foreach ( (array) $wp_settings_errors as $key => $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
			if ( $setting == $details['setting'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
				$setting_errors[] = $wp_settings_errors[$key];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
		return $setting_errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
	return $wp_settings_errors;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
 * Display settings errors registered by add_settings_error().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
 * Part of the Settings API. Outputs a div for each error retrieved by
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1491
 * get_settings_errors().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
 * This is called automatically after a settings page based on the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
 * Settings API is submitted. Errors should be added during the validation
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1495
 * callback function for a setting defined in register_setting().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1497
 * The $sanitize option is passed into get_settings_errors() and will
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
 * re-run the setting sanitization
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
 * on its current value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1500
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
 * The $hide_on_update option will cause errors to only show when the settings
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
 * page is first loaded. if the user has already saved new values it will be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
 * hidden to avoid repeating messages already shown in the default error
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
 * reporting after submission. This is useful to show general errors like
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
 * missing settings when the user arrives at the settings page.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1509
 * @param string $setting        Optional slug title of a specific setting who's errors you want.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
 * @param bool   $sanitize       Whether to re-sanitize the setting value before returning errors.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1511
 * @param bool   $hide_on_update If set to true errors will not be shown if the settings page has
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1512
 *                               already been submitted.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
	if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
	$settings_errors = get_settings_errors( $setting, $sanitize );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
	if ( empty( $settings_errors ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
	$output = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
	foreach ( $settings_errors as $key => $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
		$css_id = 'setting-error-' . $details['code'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
		$css_class = $details['type'] . ' settings-error notice is-dismissible';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
		$output .= "<div id='$css_id' class='$css_class'> \n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
		$output .= "<p><strong>{$details['message']}</strong></p>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
		$output .= "</div> \n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
	echo $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1536
 * Outputs the modal window used for attaching media to posts or pages in the media-listing screen.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
 * @param string $found_action
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
function find_posts_div($found_action = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1544
	<div id="find-posts" class="find-box" style="display: none;">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1545
		<div id="find-posts-head" class="find-box-head">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1546
			<?php _e( 'Attach to existing content' ); ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1547
			<button type="button" id="find-posts-close"><span class="screen-reader-text"><?php _e( 'Close media attachment panel' ); ?></span></button>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1548
		</div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
		<div class="find-box-inside">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
			<div class="find-box-search">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
				<?php if ( $found_action ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
					<input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
				<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
				<input type="hidden" name="affected" id="affected" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
				<?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
				<label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
				<input type="text" id="find-posts-input" name="ps" value="" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
				<span class="spinner"></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
				<input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" />
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1560
				<div class="clear"></div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
			</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
			<div id="find-posts-response"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
		<div class="find-box-buttons">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1565
			<?php submit_button( __( 'Select' ), 'primary alignright', 'find-posts-submit', false ); ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1566
			<div class="clear"></div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1573
 * Displays the post password.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1575
 * The password is passed through esc_attr() to ensure that it is safe for placing in an html attribute.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
function the_post_password() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
	if ( isset( $post->post_password ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
		echo esc_attr( $post->post_password );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
 * Get the post title.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
 * The post title is fetched and if it is blank then a default string is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
 * returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
 * @since 2.7.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1592
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1593
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
 * @return string The post title if set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
function _draft_or_post_title( $post = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
	$title = get_the_title( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
	if ( empty( $title ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
		$title = __( '(no title)' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
	return esc_html( $title );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1604
 * Displays the search query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1606
 * A simple wrapper to display the "s" parameter in a `GET` URI. This function
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1607
 * should only be used when the_search_query() cannot.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
function _admin_search_query() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
	echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
 * Generic Iframe header for use with Thickbox
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1620
 * @global string    $hook_suffix
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1621
 * @global string    $admin_body_class
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1622
 * @global WP_Locale $wp_locale
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1623
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1624
 * @param string $title      Optional. Title of the Iframe page. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1625
 * @param bool   $deprecated Not used.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1627
function iframe_header( $title = '', $deprecated = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
	show_admin_bar( false );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
	global $hook_suffix, $admin_body_class, $wp_locale;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
	$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
	$current_screen = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
	@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
	_wp_admin_html_begin();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
<title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
wp_enqueue_style( 'colors' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1640
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1641
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
	pagenow = '<?php echo $current_screen->id; ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
	typenow = '<?php echo $current_screen->post_type; ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
	adminpage = '<?php echo $admin_body_class; ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
	thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
	decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	isRtl = <?php echo (int) is_rtl(); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1653
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
do_action( 'admin_enqueue_scripts', $hook_suffix );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1655
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1656
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1657
do_action( "admin_print_styles-$hook_suffix" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1659
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1660
do_action( 'admin_print_styles' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1661
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1662
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1663
do_action( "admin_print_scripts-$hook_suffix" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1664
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1665
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1666
do_action( 'admin_print_scripts' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1667
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1668
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
do_action( "admin_head-$hook_suffix" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1670
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1671
/** This action is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1672
do_action( 'admin_head' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1674
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
if ( is_rtl() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
	$admin_body_class .= ' rtl';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
</head>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1681
<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1682
/** This filter is documented in wp-admin/admin-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1683
$admin_body_classes = apply_filters( 'admin_body_class', '' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1684
?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1685
<body<?php
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1686
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1687
 * @global string $body_id
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1688
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1689
if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
var c = document.body.className;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
c = c.replace(/no-js/, 'js');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
document.body.className = c;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
})();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
 * Generic Iframe footer for use with Thickbox
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
function iframe_footer() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1706
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1707
	 * We're going to hide any footer output on iFrame pages,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1708
	 * but run the hooks anyway since they output JavaScript
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1709
	 * or other needed content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1710
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1711
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1712
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1713
	 * @global string $hook_suffix
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1714
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1715
	global $hook_suffix;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1716
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
	<div class="hidden">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1719
	/** This action is documented in wp-admin/admin-footer.php */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1720
	do_action( 'admin_footer', $hook_suffix );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1721
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1722
	/** This action is documented in wp-admin/admin-footer.php */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1723
	do_action( "admin_print_footer_scripts-$hook_suffix" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1724
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1725
	/** This action is documented in wp-admin/admin-footer.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1726
	do_action( 'admin_print_footer_scripts' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1727
?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
<script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
</body>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
</html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1735
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1736
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1737
 * @param WP_Post $post
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1738
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
function _post_states($post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
	$post_states = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
	if ( isset( $_REQUEST['post_status'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1742
		$post_status = $_REQUEST['post_status'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1743
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
		$post_status = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1746
	if ( !empty($post->post_password) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
		$post_states['protected'] = __('Password protected');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
	if ( 'private' == $post->post_status && 'private' != $post_status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
		$post_states['private'] = __('Private');
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1750
	if ( 'draft' === $post->post_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1751
		if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1752
			$post_states[] = __( 'Customization Draft' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1753
		} elseif ( 'draft' !== $post_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1754
			$post_states['draft'] = __( 'Draft' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1755
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1756
	} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1757
		$post_states[] = __( 'Customization Draft' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1758
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
	if ( 'pending' == $post->post_status && 'pending' != $post_status )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1760
		$post_states['pending'] = _x('Pending', 'post status');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
	if ( is_sticky($post->ID) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
		$post_states['sticky'] = __('Sticky');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1764
	if ( 'future' === $post->post_status ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1765
		$post_states['scheduled'] = __( 'Scheduled' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1766
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1767
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1768
	if ( 'page' === get_option( 'show_on_front' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1769
		if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1770
			$post_states['page_on_front'] = __( 'Front Page' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1771
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1772
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1773
		if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1774
			$post_states['page_for_posts'] = __( 'Posts Page' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1775
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1776
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1777
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1778
	if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1779
		$post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1780
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1781
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1782
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1783
	 * Filters the default post display states used in the posts list table.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1784
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1785
	 * @since 2.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1786
	 * @since 3.6.0 Added the `$post` parameter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1787
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1788
	 * @param array   $post_states An array of post display states.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1789
	 * @param WP_Post $post        The current post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1790
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
	$post_states = apply_filters( 'display_post_states', $post_states, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
	if ( ! empty($post_states) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
		$state_count = count($post_states);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
		$i = 0;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1796
		echo ' &mdash; ';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
		foreach ( $post_states as $state ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
			++$i;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
			( $i == $state_count ) ? $sep = '' : $sep = ', ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
			echo "<span class='post-state'>$state$sep</span>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1806
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1807
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1808
 * @param WP_Post $post
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1809
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
function _media_states( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
	$media_states = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
	$stylesheet = get_option('stylesheet');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
	if ( current_theme_supports( 'custom-header') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
		$meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1816
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1817
		if ( is_random_header_image() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1818
			$header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1819
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1820
			if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1821
				$media_states[] = __( 'Header Image' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1822
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1823
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1824
			$header_image = get_header_image();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1825
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1826
			// Display "Header Image" if the image was ever used as a header image
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1827
			if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1828
				$media_states[] = __( 'Header Image' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1829
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1830
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1831
			// Display "Current Header Image" if the image is currently the header image
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1832
			if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1833
				$media_states[] = __( 'Current Header Image' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1834
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1835
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	if ( current_theme_supports( 'custom-background') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
		$meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1840
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1841
		if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
			$media_states[] = __( 'Background Image' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1843
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1844
			$background_image = get_background_image();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1845
			if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1846
				$media_states[] = __( 'Current Background Image' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1847
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1848
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1849
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1850
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1851
	if ( $post->ID == get_option( 'site_icon' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1852
		$media_states[] = __( 'Site Icon' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1853
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1854
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1855
	if ( $post->ID == get_theme_mod( 'custom_logo' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1856
		$media_states[] = __( 'Logo' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1859
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1860
	 * Filters the default media display states for items in the Media list table.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1861
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1862
	 * @since 3.2.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1863
	 * @since 4.8.0 Added the `$post` parameter.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1864
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1865
	 * @param array   $media_states An array of media states. Default 'Header Image',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1866
	 *                              'Background Image', 'Site Icon', 'Logo'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1867
	 * @param WP_Post $post         The current attachment object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1868
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1869
	$media_states = apply_filters( 'display_media_states', $media_states, $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
	if ( ! empty( $media_states ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
		$state_count = count( $media_states );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1873
		$i = 0;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1874
		echo ' &mdash; ';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
		foreach ( $media_states as $state ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1876
			++$i;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
			( $i == $state_count ) ? $sep = '' : $sep = ', ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
			echo "<span class='post-state'>$state$sep</span>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
 * Test support for compressing JavaScript from PHP
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
 * Outputs JavaScript that tests if compression from PHP works as expected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
 * and sets an option with the result. Has no effect when the current user
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
 * is not an administrator. To run the test again the option 'can_compress_scripts'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1889
 * has to be deleted.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
function compression_test() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
	<script type="text/javascript">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1896
	var compressionNonce = <?php echo wp_json_encode( wp_create_nonce( 'update_can_compress_scripts' ) ); ?>;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
	var testCompression = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
		get : function(test) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
			var x;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
			if ( window.XMLHttpRequest ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
				x = new XMLHttpRequest();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
				try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1904
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
			if (x) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
				x.onreadystatechange = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
					var r, h;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
					if ( x.readyState == 4 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
						r = x.responseText.substr(0, 18);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
						h = x.getResponseHeader('Content-Encoding');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
						testCompression.check(r, h, test);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1914
				};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1916
				x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&_ajax_nonce='+compressionNonce+'&'+(new Date()).getTime(), true);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
				x.send('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
		check : function(r, h, test) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
			if ( ! r && ! test )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
				this.get(1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
			if ( 1 == test ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
				if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
					this.get('no');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
					this.get(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
			if ( 2 == test ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
				if ( '"wpCompressionTest' == r )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
					this.get('yes');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1937
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
					this.get('no');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
	testCompression.check();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
	</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1948
 * Echoes a submit button, with provided text and appropriate class(es).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1952
 * @see get_submit_button()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1954
 * @param string       $text             The text of the button (defaults to 'Save Changes')
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1955
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1956
 *                                       include 'primary', 'small', and 'large'. Default 'primary'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1957
 * @param string       $name             The HTML name of the submit button. Defaults to "submit". If no
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1958
 *                                       id attribute is given in $other_attributes below, $name will be
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1959
 *                                       used as the button's id.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1960
 * @param bool         $wrap             True if the output button should be wrapped in a paragraph tag,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1961
 *                                       false otherwise. Defaults to true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1962
 * @param array|string $other_attributes Other attributes that should be output with the button, mapping
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1963
 *                                       attributes to their values, such as setting tabindex to 1, etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1964
 *                                       These key/value attribute pairs will be output as attribute="value",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1965
 *                                       where attribute is the key. Other attributes can also be provided
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1966
 *                                       as a string such as 'tabindex="1"', though the array format is
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1967
 *                                       preferred. Default null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
	echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
 * Returns a submit button, with provided text and appropriate class
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1978
 * @param string       $text             Optional. The text of the button. Default 'Save Changes'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1979
 * @param string       $type             Optional. The type and CSS class(es) of the button. Core values
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1980
 *                                       include 'primary', 'small', and 'large'. Default 'primary large'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
 * @param string       $name             Optional. The HTML name of the submit button. Defaults to "submit".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1982
 *                                       If no id attribute is given in $other_attributes below, `$name` will
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1983
 *                                       be used as the button's id. Default 'submit'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1984
 * @param bool         $wrap             Optional. True if the output button should be wrapped in a paragraph
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1985
 *                                       tag, false otherwise. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1986
 * @param array|string $other_attributes Optional. Other attributes that should be output with the button,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1987
 *                                       mapping attributes to their values, such as `array( 'tabindex' => '1' )`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1988
 *                                       These attributes will be output as `attribute="value"`, such as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1989
 *                                       `tabindex="1"`. Other attributes can also be provided as a string such
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1990
 *                                       as `tabindex="1"`, though the array format is typically cleaner.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1991
 *                                       Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1992
 * @return string Submit button HTML.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1994
function get_submit_button( $text = '', $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
	if ( ! is_array( $type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
		$type = explode( ' ', $type );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
	$button_shorthand = array( 'primary', 'small', 'large' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	$classes = array( 'button' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
	foreach ( $type as $t ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
		if ( 'secondary' === $t || 'button-secondary' === $t )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
		$classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2005
	// Remove empty items, remove duplicate items, and finally build a string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2006
	$class = implode( ' ', array_unique( array_filter( $classes ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2007
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
	$text = $text ? $text : __( 'Save Changes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
	// Default the id attribute to $name unless an id was specifically provided in $other_attributes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
	$id = $name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
	if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
		$id = $other_attributes['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2014
		unset( $other_attributes['id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
	$attributes = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
	if ( is_array( $other_attributes ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
		foreach ( $other_attributes as $attribute => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
			$attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2022
	} elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
		$attributes = $other_attributes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2025
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2026
	// Don't output empty name and id attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2027
	$name_attr = $name ? ' name="' . esc_attr( $name ) . '"' : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2028
	$id_attr = $id ? ' id="' . esc_attr( $id ) . '"' : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2029
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
	$button = '<input type="submit"' . $name_attr . $id_attr . ' class="' . esc_attr( $class );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2031
	$button	.= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
	if ( $wrap ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
		$button = '<p class="submit">' . $button . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2037
	return $button;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2039
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2040
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2041
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2042
 * @global bool $is_IE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2043
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
function _wp_admin_html_begin() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2045
	global $is_IE;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2046
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
	$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2048
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2049
	if ( $is_IE )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2050
		@header('X-UA-Compatible: IE=edge');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2051
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
<!DOCTYPE html>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
<!--[if IE 8]>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2055
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2056
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2057
	 * Fires inside the HTML tag in the admin header.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2058
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2059
	 * @since 2.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2060
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2061
	do_action( 'admin_xml_ns' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2062
?> <?php language_attributes(); ?>>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
<![endif]-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
<!--[if !(IE 8) ]><!-->
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2065
<html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2066
	/** This action is documented in wp-admin/includes/template.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2067
	do_action( 'admin_xml_ns' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2068
?> <?php language_attributes(); ?>>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
<!--<![endif]-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
<head>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2073
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
 * Convert a screen string to a screen object
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
 * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
 * @return WP_Screen Screen object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
function convert_to_screen( $hook_name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
	if ( ! class_exists( 'WP_Screen' ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2085
		_doing_it_wrong(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2086
			'convert_to_screen(), add_meta_box()',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2087
			sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2088
				/* translators: 1: wp-admin/includes/template.php 2: add_meta_box() 3: add_meta_boxes */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2089
				__( 'Likely direct inclusion of %1$s in order to use %2$s. This is very wrong. Hook the %2$s call into the %3$s action instead.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2090
				'<code>wp-admin/includes/template.php</code>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2091
				'<code>add_meta_box()</code>',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2092
				'<code>add_meta_boxes</code>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2093
			),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2094
			'3.3.0'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2095
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
		return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
	return WP_Screen::get( $hook_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
 * Output the HTML for restoring the post data from DOM storage
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2105
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
function _local_storage_notice() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
	?>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2110
	<div id="local-storage-notice" class="hidden notice is-dismissible">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
	<p class="local-restore">
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2112
		<?php _e( 'The backup of this post in your browser is different from the version below.' ); ?>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2113
		<button type="button" class="button restore-backup"><?php _e('Restore the backup'); ?></button>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
	</p>
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2115
	<p class="help">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2116
		<?php _e( 'This will replace the current editor content with the last backup version. You can use undo and redo in the editor to get the old content back or to return to the restored version.' ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2121
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2122
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2123
 * Output a HTML element with a star rating for a given rating.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2124
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2125
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2126
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2127
 * number of ratings may also be displayed by passing the $number parameter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2128
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2129
 * @since 3.8.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2130
 * @since 4.4.0 Introduced the `echo` parameter.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2131
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2132
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2133
 *     Optional. Array of star ratings arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2134
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2135
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2136
 *                             or percentage. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2137
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2138
 *                             or, 'percent'. Default 'rating'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2139
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2140
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2141
 *                             of echoing it. Default true.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2142
 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2143
 * @return string Star rating HTML.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2144
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2145
function wp_star_rating( $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2146
	$defaults = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2147
		'rating' => 0,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2148
		'type'   => 'rating',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2149
		'number' => 0,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2150
		'echo'   => true,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
	$r = wp_parse_args( $args, $defaults );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2153
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2154
	// Non-English decimal places when the $rating is coming from a string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2155
	$rating = (float) str_replace( ',', '.', $r['rating'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2156
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2157
	// Convert Percentage to star rating, 0..5 in .5 increments
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2158
	if ( 'percent' === $r['type'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2159
		$rating = round( $rating / 10, 0 ) / 2;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2160
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2161
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2162
	// Calculate the number of each type of star needed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2163
	$full_stars = floor( $rating );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2164
	$half_stars = ceil( $rating - $full_stars );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2165
	$empty_stars = 5 - $full_stars - $half_stars;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2166
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2167
	if ( $r['number'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2168
		/* translators: 1: The rating, 2: The number of ratings */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2169
		$format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2170
		$title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2171
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2172
		/* translators: 1: The rating */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2173
		$title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2174
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2175
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2176
	$output = '<div class="star-rating">';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2177
	$output .= '<span class="screen-reader-text">' . $title . '</span>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2178
	$output .= str_repeat( '<div class="star star-full" aria-hidden="true"></div>', $full_stars );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2179
	$output .= str_repeat( '<div class="star star-half" aria-hidden="true"></div>', $half_stars );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2180
	$output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2181
	$output .= '</div>';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2182
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2183
	if ( $r['echo'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2184
		echo $output;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2185
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2186
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2187
	return $output;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2188
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2189
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2190
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2191
 * Output a notice when editing the page for posts (internal use only).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2192
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2193
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2194
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2195
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2196
function _wp_posts_page_notice() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2197
	echo '<div class="notice notice-warning inline"><p>' . __( 'You are currently editing the page that shows your latest posts.' ) . '</p></div>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2198
}