wp/wp-admin/includes/ajax-actions.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
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
 * WordPress Core Ajax Handlers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
// No-privilege Ajax handlers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
//
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
 * Ajax handler for the Heartbeat API in
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
 * the no-privilege context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 * Runs when the user is not logged in.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
function wp_ajax_nopriv_heartbeat() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	$response = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	// screen_id is the same as $current_screen->id and the JS global 'pagenow'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	if ( ! empty($_POST['screen_id']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		$screen_id = sanitize_key($_POST['screen_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		$screen_id = 'front';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	if ( ! empty($_POST['data']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		$data = wp_unslash( (array) $_POST['data'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		 * Filter Heartbeat AJAX response in no-privilege environments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		 * @param array|object $response  The no-priv Heartbeat response object or array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		 * @param array        $data      An array of data passed via $_POST.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 * Filter Heartbeat AJAX response when no data is passed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 * @param array|object $response  The Heartbeat response object or array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 * Fires when Heartbeat ticks in no-privilege environments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 * Allows the transport to be easily replaced with long-polling.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	 * @param array|object $response  The no-priv Heartbeat response.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	// Send the current time according to the server.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	$response['server_time'] = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	wp_send_json($response);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
// GET-based Ajax handlers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
 * Ajax handler for fetching a list table.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
 * @since 3.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
function wp_ajax_fetch_list() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
	$list_class = $_GET['list_args']['class'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	$wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	if ( ! $wp_list_table )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	if ( ! $wp_list_table->ajax_user_can() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	$wp_list_table->ajax_response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
 * Ajax handler for tag search.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
function wp_ajax_ajax_tag_search() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	if ( ! isset( $_GET['tax'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	$taxonomy = sanitize_key( $_GET['tax'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	$tax = get_taxonomy( $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
	if ( ! $tax ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
		wp_die( 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	}
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
	if ( ! current_user_can( $tax->cap->assign_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
		wp_die( -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	$s = wp_unslash( $_GET['q'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	$comma = _x( ',', 'tag delimiter' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	if ( ',' !== $comma )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		$s = str_replace( $comma, ',', $s );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	if ( false !== strpos( $s, ',' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		$s = explode( ',', $s );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
		$s = $s[count( $s ) - 1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	$s = trim( $s );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
	 * Filter the minimum number of characters required to fire a tag search via AJAX.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
	 * @param int    $characters The minimum number of characters required. Default 2.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
	 * @param object $tax        The taxonomy object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
	 * @param string $s          The search term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
	$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
	 * Require $term_search_min_chars chars for matching (default: 2)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
	 * ensure it's a non-negative, non-zero integer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ){
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
		wp_die();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	$results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	echo join( $results, "\n" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
 * Ajax handler for compression testing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
function wp_ajax_wp_compression_test() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	if ( !current_user_can( 'manage_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	if ( ini_get('zlib.output_compression') || 'ob_gzhandler' == ini_get('output_handler') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		update_site_option('can_compress_scripts', 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	if ( isset($_GET['test']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		header( 'Pragma: no-cache' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
		header('Content-Type: application/javascript; charset=UTF-8');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		$force_gzip = ( defined('ENFORCE_GZIP') && ENFORCE_GZIP );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
		 if ( 1 == $_GET['test'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		 	echo $test_str;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
		 	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
		 } elseif ( 2 == $_GET['test'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
			if ( !isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
				wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
				header('Content-Encoding: deflate');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
				$out = gzdeflate( $test_str, 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			} elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				header('Content-Encoding: gzip');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
				$out = gzencode( $test_str, 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
				wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
			echo $out;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
		} elseif ( 'no' == $_GET['test'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			update_site_option('can_compress_scripts', 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		} elseif ( 'yes' == $_GET['test'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
			update_site_option('can_compress_scripts', 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
 * Ajax handler for image editor previews.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
function wp_ajax_imgedit_preview() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	$post_id = intval($_GET['postid']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	if ( empty($post_id) || !current_user_can('edit_post', $post_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
	check_ajax_referer( "image_editor-$post_id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	if ( ! stream_preview_image($post_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
 * Ajax handler for oEmbed caching.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
function wp_ajax_oembed_cache() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
	$GLOBALS['wp_embed']->cache_oembed( $_GET['post'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	wp_die( 0 );
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
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   235
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
 * Ajax handler for user autocomplete.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
function wp_ajax_autocomplete_user() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	/** This filter is documented in wp-admin/user-new.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	if ( ! is_super_admin() && ! apply_filters( 'autocomplete_users_for_site_admins', false ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	$return = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	// Check the type of request
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
	// Current allowed values are `add` and `search`
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
	if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		$type = $_REQUEST['autocomplete_type'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		$type = 'add';
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
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
	// Check the desired field for value
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
	// Current allowed values are `user_email` and `user_login`
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
	if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		$field = $_REQUEST['autocomplete_field'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
		$field = 'user_login';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	// Exclude current users of this blog
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	if ( isset( $_REQUEST['site_id'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		$id = absint( $_REQUEST['site_id'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		$id = get_current_blog_id();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	$include_blog_users = ( $type == 'search' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	$exclude_blog_users = ( $type == 'add' ? get_users( array( 'blog_id' => $id, 'fields' => 'ID' ) ) : array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	$users = get_users( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		'blog_id' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		'search'  => '*' . $_REQUEST['term'] . '*',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		'include' => $include_blog_users,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		'exclude' => $exclude_blog_users,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	foreach ( $users as $user ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		$return[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			/* translators: 1: user_login, 2: user_email */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
			'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
			'value' => $user->$field,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	wp_die( wp_json_encode( $return ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
 * Ajax handler for dashboard widgets.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
function wp_ajax_dashboard_widgets() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	require_once ABSPATH . 'wp-admin/includes/dashboard.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
	$pagenow = $_GET['pagenow'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
	if ( $pagenow === 'dashboard-user' || $pagenow === 'dashboard-network' || $pagenow === 'dashboard' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
		set_current_screen( $pagenow );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	switch ( $_GET['widget'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
		case 'dashboard_primary' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			wp_dashboard_primary();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
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
 * Ajax handler for Customizer preview logged-in status.
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
 * @since 3.4.0
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
function wp_ajax_logged_in() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
// Ajax helpers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
//
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
 * Sends back current comment total and new page links if they need to be updated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
 * Contrary to normal success AJAX response ("1"), die with time() on success.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
 * @since 2.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
 * @param int $comment_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 * @return die
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	$total    = isset( $_POST['_total'] )    ? (int) $_POST['_total']    : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	$per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
	$page     = isset( $_POST['_page'] )     ? (int) $_POST['_page']     : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	$url      = isset( $_POST['_url'] )      ? esc_url_raw( $_POST['_url'] ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	// JS didn't send us everything we need to know. Just die with success message
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	if ( !$total || !$per_page || !$page || !$url )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	$total += $delta;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	if ( $total < 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		$total = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
	// Only do the expensive stuff on a page-break, and about 1 other time per page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		$post_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		$status = 'total_comments'; // What type of comment count are we looking for?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		$parsed = parse_url( $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		if ( isset( $parsed['query'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			parse_str( $parsed['query'], $query_vars );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			if ( !empty( $query_vars['comment_status'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
				$status = $query_vars['comment_status'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			if ( !empty( $query_vars['p'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
				$post_id = (int) $query_vars['p'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		$comment_count = wp_count_comments($post_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
		// We're looking for a known type of comment count.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
		if ( isset( $comment_count->$status ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			$total = $comment_count->$status;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
			// Else use the decremented value from above.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
	// The time since the last comment count.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
	$time = time();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		'what' => 'comment',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
		// Here for completeness - not used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
		'id' => $comment_id,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		'supplemental' => array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
			'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			'total_pages' => ceil( $total / $per_page ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			'total' => $total,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			'time' => $time
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
// POST-based Ajax handlers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
 * Ajax handler for adding a hierarchical term.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
 * @since 3.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
function _wp_ajax_add_hierarchical_term() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	$action = $_POST['action'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	$taxonomy = get_taxonomy(substr($action, 4));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	if ( !current_user_can( $taxonomy->cap->edit_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	$names = explode(',', $_POST['new'.$taxonomy->name]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	$parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	if ( 0 > $parent )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		$parent = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	if ( $taxonomy->name == 'category' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		$post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		$post_category = ( isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy->name]) ) ? (array) $_POST['tax_input'][$taxonomy->name] : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	$checked_categories = array_map( 'absint', (array) $post_category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	$popular_ids = wp_popular_terms_checklist($taxonomy->name, 0, 10, false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	foreach ( $names as $cat_name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		$cat_name = trim($cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		$category_nicename = sanitize_title($cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		if ( '' === $category_nicename )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
		if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
		if ( is_wp_error( $cat_id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
		} elseif ( is_array( $cat_id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
			$cat_id = $cat_id['term_id'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
		$checked_categories[] = $cat_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		if ( $parent ) // Do these all at once in a second
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy->name, 'descendants_and_self' => $cat_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids ));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		$data = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
		$add = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
			'what' => $taxonomy->name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
			'id' => $cat_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			'data' => str_replace( array("\n", "\t"), '', $data),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
			'position' => -1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	if ( $parent ) { // Foncy - replace the parent and all its children
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		$parent = get_term( $parent, $taxonomy->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		$term_id = $parent->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		while ( $parent->parent ) { // get the top parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			$parent = get_term( $parent->parent, $taxonomy->name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			if ( is_wp_error( $parent ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
			$term_id = $parent->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			wp_terms_checklist( 0, array('taxonomy' => $taxonomy->name, 'descendants_and_self' => $term_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		$data = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		$add = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
			'what' => $taxonomy->name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			'id' => $term_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			'data' => str_replace( array("\n", "\t"), '', $data),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			'position' => -1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		wp_dropdown_categories( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
			'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			'hierarchical' => 1, 'show_option_none' => '&mdash; '.$taxonomy->labels->parent_item.' &mdash;'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	$sup = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	$add['supplemental'] = array( 'newcat_parent' => $sup );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	$x = new WP_Ajax_Response( $add );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
 * Ajax handler for deleting a comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
function wp_ajax_delete_comment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	if ( !$comment = get_comment( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
		wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	check_ajax_referer( "delete-comment_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	$status = wp_get_comment_status( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	$delta = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
		if ( 'trash' == $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
			wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		$r = wp_trash_comment( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	} elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		if ( 'trash' != $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
			wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		$r = wp_untrash_comment( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
		if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) // undo trash, not in trash
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
			$delta = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	} elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		if ( 'spam' == $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
			wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		$r = wp_spam_comment( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	} elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		if ( 'spam' != $status )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
			wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		$r = wp_unspam_comment( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) // undo spam, not in spam
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
			$delta = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	} elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		$r = wp_delete_comment( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
		_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
 * Ajax handler for deleting a tag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
function wp_ajax_delete_tag() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
	$tag_id = (int) $_POST['tag_ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	check_ajax_referer( "delete-tag_$tag_id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	$tax = get_taxonomy($taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	if ( !current_user_can( $tax->cap->delete_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	$tag = get_term( $tag_id, $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	if ( !$tag || is_wp_error( $tag ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	if ( wp_delete_term($tag_id, $taxonomy))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
 * Ajax handler for deleting a link.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
function wp_ajax_delete_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	check_ajax_referer( "delete-bookmark_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	if ( !current_user_can( 'manage_links' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	$link = get_bookmark( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
	if ( !$link || is_wp_error( $link ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	if ( wp_delete_link( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
 * Ajax handler for deleting meta.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
function wp_ajax_delete_meta() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	check_ajax_referer( "delete-meta_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
	if ( !$meta = get_metadata_by_mid( 'post', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta',  $meta->post_id, $meta->meta_key ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
	if ( delete_meta( $meta->meta_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
 * Ajax handler for deleting a post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
function wp_ajax_delete_post( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
		$action = 'delete-post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	check_ajax_referer( "{$action}_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	if ( !current_user_can( 'delete_post', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	if ( !get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	if ( wp_delete_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
 * Ajax handler for sending a post to the trash.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   626
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
function wp_ajax_trash_post( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		$action = 'trash-post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
	check_ajax_referer( "{$action}_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	if ( !current_user_can( 'delete_post', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	if ( !get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	if ( 'trash-post' == $action )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
		$done = wp_trash_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
		$done = wp_untrash_post( $id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	if ( $done )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
 * Ajax handler to restore a post from the trash.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   654
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   656
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
function wp_ajax_untrash_post( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
		$action = 'untrash-post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	wp_ajax_trash_post( $action );
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
function wp_ajax_delete_page( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		$action = 'delete-page';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	check_ajax_referer( "{$action}_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	if ( !current_user_can( 'delete_page', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	if ( ! get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	if ( wp_delete_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
 * Ajax handler to dim a comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
function wp_ajax_dim_comment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	if ( !$comment = get_comment( $id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			'what' => 'comment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
		$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
	$current = wp_get_comment_status( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	if ( isset( $_POST['new'] ) && $_POST['new'] == $current )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		wp_die( time() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	check_ajax_referer( "approve-comment_$id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	if ( in_array( $current, array( 'unapproved', 'spam' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		$result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		$result = wp_set_comment_status( $comment->comment_ID, 'hold', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	if ( is_wp_error($result) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
			'what' => 'comment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
			'id' => $result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	// Decide if we need to send back '1' or a more complicated response including page links and comment counts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	_wp_ajax_delete_comment_response( $comment->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
 * Ajax handler for deleting a link category.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
function wp_ajax_add_link_category( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
		$action = 'add-link-category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
	check_ajax_referer( $action );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
	if ( !current_user_can( 'manage_categories' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
	$names = explode(',', wp_unslash( $_POST['newcat'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
	$x = new WP_Ajax_Response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
	foreach ( $names as $cat_name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		$cat_name = trim($cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		$slug = sanitize_title($cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		if ( '' === $slug )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
		if ( !$cat_id = term_exists( $cat_name, 'link_category' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
			$cat_id = wp_insert_term( $cat_name, 'link_category' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
		if ( is_wp_error( $cat_id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
		} elseif ( is_array( $cat_id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
			$cat_id = $cat_id['term_id'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		$cat_name = esc_html( $cat_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
		$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
			'what' => 'link-category',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
			'id' => $cat_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
			'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr($cat_id) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>",
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
			'position' => -1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   761
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
 * Ajax handler to add a tag.
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
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   765
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
function wp_ajax_add_tag() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	$taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	$tax = get_taxonomy($taxonomy);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	if ( !current_user_can( $tax->cap->edit_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
	$x = new WP_Ajax_Response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	$tag = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	if ( !$tag || is_wp_error($tag) || (!$tag = get_term( $tag['term_id'], $taxonomy )) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
		$message = __('An error has occurred. Please reload the page and try again.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		if ( is_wp_error($tag) && $tag->get_error_message() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
			$message = $tag->get_error_message();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
			'what' => 'taxonomy',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			'data' => new WP_Error('error', $message )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
		$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	$level = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
	if ( is_taxonomy_hierarchical($taxonomy) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
		$level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		$wp_list_table->single_row( $tag, $level );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
		$noparents = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
	$wp_list_table->single_row( $tag );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	$parents = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
	$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
		'what' => 'taxonomy',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
		'supplemental' => compact('parents', 'noparents')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
	$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		'what' => 'term',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
		'position' => $level,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
		'supplemental' => (array) $tag
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   818
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
 * Ajax handler for getting a tagcloud.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
function wp_ajax_get_tagcloud() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
	if ( ! isset( $_POST['tax'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
	$taxonomy = sanitize_key( $_POST['tax'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
	$tax = get_taxonomy( $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
	if ( ! $tax ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
		wp_die( 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
	if ( ! current_user_can( $tax->cap->assign_terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
		wp_die( -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
	$tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
	if ( empty( $tags ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		wp_die( $tax->labels->not_found );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	if ( is_wp_error( $tags ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
		wp_die( $tags->get_error_message() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
	foreach ( $tags as $key => $tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
		$tags[ $key ]->link = '#';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
		$tags[ $key ]->id = $tag->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
	// We need raw tag names here, so don't filter the output
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
	$return = wp_generate_tag_cloud( $tags, array('filter' => 0) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
	if ( empty($return) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	echo $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
 * Ajax handler for getting comments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
function wp_ajax_get_comments( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
	global $wp_list_table, $post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
		$action = 'get-comments';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
	check_ajax_referer( $action );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
	if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
		$id = absint( $_REQUEST['p'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		if ( ! empty( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
			$post_id = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
	if ( empty( $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
	$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
	if ( ! current_user_can( 'edit_post', $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	$wp_list_table->prepare_items();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	if ( !$wp_list_table->has_items() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	$x = new WP_Ajax_Response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	foreach ( $wp_list_table->items as $comment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		get_comment( $comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
		$wp_list_table->single_row( $comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	$comment_list_item = ob_get_contents();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		'what' => 'comments',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		'data' => $comment_list_item
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
 * Ajax handler for replying to a comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
function wp_ajax_replyto_comment( $action ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
	global $wp_list_table;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
		$action = 'replyto-comment';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
	check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
	$comment_post_ID = (int) $_POST['comment_post_ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
	$post = get_post( $comment_post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
	if ( ! $post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	if ( !current_user_can( 'edit_post', $comment_post_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
	if ( empty( $post->post_status ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
	elseif ( in_array($post->post_status, array('draft', 'pending', 'trash') ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
		wp_die( __('ERROR: you are replying to a comment on a draft post.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	$user = wp_get_current_user();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
	if ( $user->exists() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
		$user_ID = $user->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		$comment_author       = wp_slash( $user->display_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
		$comment_author_email = wp_slash( $user->user_email );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		$comment_author_url   = wp_slash( $user->user_url );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
		$comment_content      = trim( $_POST['content'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
		$comment_type         = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		if ( current_user_can( 'unfiltered_html' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
			if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
				$_POST['_wp_unfiltered_html_comment'] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
			if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
				kses_remove_filters(); // start with a clean slate
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
				kses_init_filters(); // set up the filters
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	if ( '' == $comment_content )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
		wp_die( __( 'ERROR: please type a comment.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	$comment_parent = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	if ( isset( $_POST['comment_ID'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
		$comment_parent = absint( $_POST['comment_ID'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	$comment_auto_approved = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   970
	// Automatically approve parent comment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	if ( !empty($_POST['approve_parent']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		$parent = get_comment( $comment_parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
		if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
				$comment_auto_approved = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
	$comment_id = wp_new_comment( $commentdata );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
	$comment = get_comment($comment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	if ( ! $comment ) wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	$position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
	if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
		require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		_wp_dashboard_recent_comments_row( $comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
			$wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
			$wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
		$wp_list_table->single_row( $comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	$comment_list_item = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
	$response =  array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
		'what' => 'comment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		'id' => $comment->comment_ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
		'data' => $comment_list_item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		'position' => $position
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	if ( $comment_auto_approved )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
		$response['supplemental'] = array( 'parent_approved' => $parent->comment_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	$x = new WP_Ajax_Response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	$x->add( $response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
 * Ajax handler for editing a comment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1018
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
function wp_ajax_edit_comment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	$comment_id = (int) $_POST['comment_ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	if ( ! current_user_can( 'edit_comment', $comment_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
	if ( '' == $_POST['content'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		wp_die( __( 'ERROR: please type a comment.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	if ( isset( $_POST['status'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
		$_POST['comment_status'] = $_POST['status'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
	edit_comment();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	$position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	$checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
	$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
	$comment = get_comment( $comment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	if ( empty( $comment->comment_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
	$wp_list_table->single_row( $comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	$comment_list_item = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	$x = new WP_Ajax_Response();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
	$x->add( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
		'what' => 'edit_comment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
		'id' => $comment->comment_ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
		'data' => $comment_list_item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
		'position' => $position
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
	));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1060
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
 * Ajax handler for adding a menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
function wp_ajax_add_menu_item() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
	check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
	if ( ! current_user_can( 'edit_theme_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
	// For performance reasons, we omit some object properties from the checklist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	// The following is a hacky way to restore them when adding non-custom items.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	$menu_items_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
	foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
		if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
			! empty( $menu_item_data['menu-item-type'] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
			'custom' != $menu_item_data['menu-item-type'] &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
			! empty( $menu_item_data['menu-item-object-id'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
		) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
			switch( $menu_item_data['menu-item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
				case 'post_type' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
					$_object = get_post( $menu_item_data['menu-item-object-id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
				case 'taxonomy' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
					$_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
			$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
			$_menu_item = reset( $_menu_items );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
			// Restore the missing menu item properties
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
			$menu_item_data['menu-item-description'] = $_menu_item->description;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
		$menu_items_data[] = $menu_item_data;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
	$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
	if ( is_wp_error( $item_ids ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
	$menu_items = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
	foreach ( (array) $item_ids as $menu_item_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
		$menu_obj = get_post( $menu_item_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
		if ( ! empty( $menu_obj->ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
			$menu_obj = wp_setup_nav_menu_item( $menu_obj );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
			$menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
			$menu_items[] = $menu_obj;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
	/** This filter is documented in wp-admin/includes/nav-menu.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
	$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
	if ( ! class_exists( $walker_class_name ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
		wp_die( 0 );
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 ( ! empty( $menu_items ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
		$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
			'after' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
			'before' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
			'link_after' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
			'link_before' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
			'walker' => new $walker_class_name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
		echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
 * Ajax handler for adding meta.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
function wp_ajax_add_meta() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
	check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
	$c = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
	$pid = (int) $_POST['post_id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
	$post = get_post( $pid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
	if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
		if ( !current_user_can( 'edit_post', $pid ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
			wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
		if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
			wp_die( 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
		// If the post is an autodraft, save the post as a draft and then attempt to save the meta.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
		if ( $post->post_status == 'auto-draft' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
			$save_POST = $_POST; // Backup $_POST
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
			$_POST = array(); // Make it empty for edit_post()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
			$_POST['action'] = 'draft'; // Warning fix
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
			$_POST['post_ID'] = $pid;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
			$_POST['post_type'] = $post->post_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
			$_POST['post_status'] = 'draft';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
			$now = current_time('timestamp', 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			$_POST['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( get_option( 'date_format' ), $now ), date( get_option( 'time_format' ), $now ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
			if ( $pid = edit_post() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
				if ( is_wp_error( $pid ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
					$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
						'what' => 'meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
						'data' => $pid
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
					) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
					$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
				$_POST = $save_POST; // Now we can restore original $_POST again
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
				if ( !$mid = add_meta( $pid ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
					wp_die( __( 'Please provide a custom field value.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
				wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
		} elseif ( ! $mid = add_meta( $pid ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
			wp_die( __( 'Please provide a custom field value.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
		$meta = get_metadata_by_mid( 'post', $mid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
		$pid = (int) $meta->post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		$meta = get_object_vars( $meta );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
		$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
			'what' => 'meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			'id' => $mid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
			'data' => _list_meta_row( $meta, $c ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
			'position' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
			'supplemental' => array('postid' => $pid)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
	} else { // Update?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
		$mid = (int) key( $_POST['meta'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
		$key = wp_unslash( $_POST['meta'][$mid]['key'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
		$value = wp_unslash( $_POST['meta'][$mid]['value'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
		if ( '' == trim($key) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
			wp_die( __( 'Please provide a custom field name.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
		if ( '' == trim($value) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
			wp_die( __( 'Please provide a custom field value.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
		if ( ! $meta = get_metadata_by_mid( 'post', $mid ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
			wp_die( 0 ); // if meta doesn't exist
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
		if ( is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
			! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
			! current_user_can( 'edit_post_meta', $meta->post_id, $key ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
			wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
		if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
			if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
				wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
		$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
			'what' => 'meta',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
			'id' => $mid, 'old_id' => $mid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
			'data' => _list_meta_row( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
				'meta_key' => $key,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
				'meta_value' => $value,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
				'meta_id' => $mid
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
			), $c ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
			'position' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1221
			'supplemental' => array('postid' => $meta->post_id)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1223
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1224
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
 * Ajax handler for adding a user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
 * @param string $action Action to perform.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
function wp_ajax_add_user( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
	if ( empty( $action ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
		$action = 'add-user';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
	check_ajax_referer( $action );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
	if ( ! current_user_can('create_users') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
	if ( ! $user_id = edit_user() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
	} elseif ( is_wp_error( $user_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
		$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
			'what' => 'user',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
			'id' => $user_id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
		$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
	$user_object = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	$wp_list_table = _get_list_table('WP_Users_List_Table');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
	$role = current( $user_object->roles );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
	$x = new WP_Ajax_Response( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
		'what' => 'user',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
		'id' => $user_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
		'data' => $wp_list_table->single_row( $user_object, '', $role ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
		'supplemental' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
			'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
			'role' => $role,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
	$x->send();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
 * Ajax handler for closed post boxes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
function wp_ajax_closed_postboxes() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
	check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
	$closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed']) : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
	$closed = array_filter($closed);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
	$hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden']) : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
	$hidden = array_filter($hidden);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
	$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
	if ( $page != sanitize_key( $page ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
	if ( ! $user = wp_get_current_user() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
	if ( is_array($closed) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
		update_user_option($user->ID, "closedpostboxes_$page", $closed, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
	if ( is_array($hidden) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
		$hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu') ); // postboxes that are always shown
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
		update_user_option($user->ID, "metaboxhidden_$page", $hidden, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1302
 * Ajax handler for hidden columns.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1303
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
function wp_ajax_hidden_columns() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
	check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1308
	$hidden = explode( ',', isset( $_POST['hidden'] ) ? $_POST['hidden'] : '' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
	$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
	if ( $page != sanitize_key( $page ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
	if ( ! $user = wp_get_current_user() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
	if ( is_array($hidden) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
		update_user_option($user->ID, "manage{$page}columnshidden", $hidden, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1323
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1324
 * Ajax handler for updating whether to display the welcome panel.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1325
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1326
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1327
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
function wp_ajax_update_welcome_panel() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
	check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
	if ( ! current_user_can( 'edit_theme_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
	update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1339
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1340
 * Ajax handler for retrieving menu meta boxes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1341
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1342
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1343
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
function wp_ajax_menu_get_metabox() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
	if ( ! current_user_can( 'edit_theme_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
	require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
	if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
		$type = 'posttype';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
		$callback = 'wp_nav_menu_item_post_type_meta_box';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
		$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
	} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
		$type = 'taxonomy';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
		$callback = 'wp_nav_menu_item_taxonomy_meta_box';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
		$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
	if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
		$menus_meta_box_object = $items[ $_POST['item-object'] ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1362
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1363
		/** This filter is documented in wp-admin/includes/nav-menu.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
		$item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
		ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
		call_user_func_array($callback, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
			null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
				'id' => 'add-' . $item->name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
				'title' => $item->labels->name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
				'callback' => $callback,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
				'args' => $item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
		));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
		$markup = ob_get_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
		echo wp_json_encode(array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
			'replace-id' => $type . '-' . $item->name,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
			'markup' => $markup,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
		));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
 * Ajax handler for internal linking.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
function wp_ajax_wp_link_ajax() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
	check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
	$args = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
	if ( isset( $_POST['search'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
		$args['s'] = wp_unslash( $_POST['search'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
	$args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
	require(ABSPATH . WPINC . '/class-wp-editor.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
	$results = _WP_Editors::wp_link_query( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
	if ( ! isset( $results ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1406
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
	echo wp_json_encode( $results );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
	echo "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
 * Ajax handler for menu locations save.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1417
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
function wp_ajax_menu_locations_save() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
	if ( ! current_user_can( 'edit_theme_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
	check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
	if ( ! isset( $_POST['menu-locations'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
	set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
 * Ajax handler for saving the meta box order.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1431
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1432
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
function wp_ajax_meta_box_order() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
	check_ajax_referer( 'meta-box-order' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
	$order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
	$page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
	if ( $page_columns != 'auto' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
		$page_columns = (int) $page_columns;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
	$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
	if ( $page != sanitize_key( $page ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
		wp_die( 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
	if ( ! $user = wp_get_current_user() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
	if ( $order )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
		update_user_option($user->ID, "meta-box-order_$page", $order, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
	if ( $page_columns )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
		update_user_option($user->ID, "screen_layout_$page", $page_columns, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1456
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
 * Ajax handler for menu quick searching.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
function wp_ajax_menu_quick_search() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1464
	if ( ! current_user_can( 'edit_theme_options' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1465
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
	require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
	_wp_ajax_menu_quick_search( $_POST );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1472
}
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
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
 * Ajax handler to retrieve a permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
function wp_ajax_get_permalink() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
	check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
	$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
	wp_die( add_query_arg( array( 'preview' => 'true' ), get_permalink( $post_id ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
 * Ajax handler to retrieve a sample permalink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
function wp_ajax_sample_permalink() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
	check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1492
	$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1493
	$title = isset($_POST['new_title'])? $_POST['new_title'] : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
	$slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1495
	wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
 * Ajax handler for Quick Edit saving a post from a list table.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
function wp_ajax_inline_save() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
	check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
	if ( 'page' == $_POST['post_type'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
		if ( ! current_user_can( 'edit_page', $post_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
			wp_die( __( 'You are not allowed to edit this page.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
		if ( ! current_user_can( 'edit_post', $post_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
			wp_die( __( 'You are not allowed to edit this post.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
	if ( $last = wp_check_post_lock( $post_ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
		$last_user = get_userdata( $last );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
		$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
		printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ),	esc_html( $last_user_name ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
	$data = &$_POST;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
	$post = get_post( $post_ID, ARRAY_A );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1530
	// Since it's coming from the database.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1531
	$post = wp_slash($post);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
	$data['content'] = $post['post_content'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
	$data['excerpt'] = $post['post_excerpt'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1536
	// Rename.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
	$data['user_ID'] = get_current_user_id();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
	if ( isset($data['post_parent']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
		$data['parent_id'] = $data['post_parent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1542
	// Status.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
	if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
		$data['post_status'] = 'private';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
		$data['post_status'] = $data['_status'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
	if ( empty($data['comment_status']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
		$data['comment_status'] = 'closed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
	if ( empty($data['ping_status']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
		$data['ping_status'] = 'closed';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1553
	// Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1554
	if ( ! empty( $data['tax_input'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1555
		foreach ( $data['tax_input'] as $taxonomy => $terms ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1556
			$tax_object = get_taxonomy( $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1557
			/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1558
			if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1559
				unset( $data['tax_input'][ $taxonomy ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1560
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1561
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1562
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1563
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
	// Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
	if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
		$post['post_status'] = 'publish';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
		$data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1570
	// Update the post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
	edit_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
	$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
	$level = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
	$request_post = array( get_post( $_POST['post_ID'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
	$parent = $request_post[0]->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
	while ( $parent > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		$parent_post = get_post( $parent );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
		$parent = $parent_post->post_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
		$level++;
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
	$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1590
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1591
 * Ajax handler for quick edit saving for a term.
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
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1594
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
function wp_ajax_inline_save_tax() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1596
	global $wp_list_table;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1597
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1598
	check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1600
	$taxonomy = sanitize_key( $_POST['taxonomy'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
	$tax = get_taxonomy( $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
	if ( ! $tax )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1605
	if ( ! current_user_can( $tax->cap->edit_terms ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1606
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1608
	$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1610
	if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
	$tag = get_term( $id, $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1614
	$_POST['description'] = $tag->description;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1615
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1616
	$updated = wp_update_term($id, $taxonomy, $_POST);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1617
	if ( $updated && !is_wp_error($updated) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1618
		$tag = get_term( $updated['term_id'], $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
		if ( !$tag || is_wp_error( $tag ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
			if ( is_wp_error($tag) && $tag->get_error_message() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
				wp_die( $tag->get_error_message() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
			wp_die( __( 'Item not updated.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1623
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1624
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1625
		if ( is_wp_error($updated) && $updated->get_error_message() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1626
			wp_die( $updated->get_error_message() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
		wp_die( __( 'Item not updated.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
	$level = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
	$parent = $tag->parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
	while ( $parent > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
		$parent_tag = get_term( $parent, $taxonomy );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
		$parent = $parent_tag->parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
		$level++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
	$wp_list_table->single_row( $tag, $level );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1639
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1640
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1641
 * Ajax handler for querying posts for the Find Posts modal.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1642
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1643
 * @see window.findPosts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1644
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1645
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1646
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
function wp_ajax_find_posts() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
	check_ajax_referer( 'find-posts' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	$post_types = get_post_types( array( 'public' => true ), 'objects' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1651
	unset( $post_types['attachment'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1653
	$s = wp_unslash( $_POST['ps'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1654
	$args = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
		'post_type' => array_keys( $post_types ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1656
		'post_status' => 'any',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1657
		'posts_per_page' => 50,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1658
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1659
	if ( '' !== $s )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
		$args['s'] = $s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1661
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1662
	$posts = get_posts( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1664
	if ( ! $posts ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1665
		wp_send_json_error( __( 'No items found.' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1666
	}
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
	$html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
	$alt = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
	foreach ( $posts as $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
		$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1672
		$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
		switch ( $post->post_status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
			case 'publish' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
			case 'private' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
				$stat = __('Published');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
			case 'future' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
				$stat = __('Scheduled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
			case 'pending' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
				$stat = __('Pending Review');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
			case 'draft' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
				$stat = __('Draft');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
		if ( '0000-00-00 00:00:00' == $post->post_date ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
			$time = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
			/* translators: date format in table columns, see http://php.net/date */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
			$time = mysql2date(__('Y/m/d'), $post->post_date);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1697
		$html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
		$html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n";
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
	$html .= '</tbody></table>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1703
	wp_send_json_success( $html );
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
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
 * Ajax handler for saving the widgets order.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1708
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1709
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1710
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1711
function wp_ajax_widgets_order() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
	check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
	if ( !current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
	unset( $_POST['savewidgets'], $_POST['action'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1719
	// Save widgets order for all sidebars.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
	if ( is_array($_POST['sidebars']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
		$sidebars = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
		foreach ( $_POST['sidebars'] as $key => $val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1723
			$sb = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1724
			if ( !empty($val) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1725
				$val = explode(',', $val);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1726
				foreach ( $val as $k => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
					if ( strpos($v, 'widget-') === false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
						continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
					$sb[$k] = substr($v, strpos($v, '_') + 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
			$sidebars[$key] = $sb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
		wp_set_sidebars_widgets($sidebars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1736
		wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1737
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
	wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1740
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1741
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1743
 * Ajax handler for saving a widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1744
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1745
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1746
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1747
function wp_ajax_save_widget() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1748
	global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1749
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1750
	check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1752
	if ( !current_user_can('edit_theme_options') || !isset($_POST['id_base']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1755
	unset( $_POST['savewidgets'], $_POST['action'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1756
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1758
	 * Fires early when editing the widgets displayed in sidebars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1759
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1761
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1762
	do_action( 'load-widgets.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1764
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
	 * Fires early when editing the widgets displayed in sidebars.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
	do_action( 'widgets.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1770
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1771
	/** This action is documented in wp-admin/widgets.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
	do_action( 'sidebar_admin_setup' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
	$id_base = $_POST['id_base'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	$widget_id = $_POST['widget-id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
	$sidebar_id = $_POST['sidebar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
	$multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
	$settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
	$error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
	$sidebars = wp_get_sidebars_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
	$sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1784
	// Delete.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
	if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
		if ( !isset($wp_registered_widgets[$widget_id]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1788
			wp_die( $error );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
		$sidebar = array_diff( $sidebar, array($widget_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
		$_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
	} elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
		if ( !$multi_number )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
			wp_die( $error );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1796
		$_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
		$widget_id = $id_base . '-' . $multi_number;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
		$sidebar[] = $widget_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
	$_POST['widget-id'] = $sidebar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
	foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
		if ( $name == $id_base ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
			if ( !is_callable( $control['callback'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
			ob_start();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
				call_user_func_array( $control['callback'], $control['params'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
			ob_end_clean();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
	if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1816
		$sidebars[$sidebar_id] = $sidebar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
		wp_set_sidebars_widgets($sidebars);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
		echo "deleted:$widget_id";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1820
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1821
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
	if ( !empty($_POST['add_new']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
	if ( $form = $wp_registered_widget_controls[$widget_id] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
		call_user_func_array( $form['callback'], $form['params'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1827
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1828
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1829
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1831
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1832
 * Ajax handler for saving a widget.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1833
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1834
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1835
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1836
function wp_ajax_update_widget() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1837
	global $wp_customize;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1838
	$wp_customize->widgets->wp_ajax_update_widget();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1839
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1840
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1841
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1842
 * Ajax handler for uploading attachments
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1843
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1844
 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1845
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
function wp_ajax_upload_attachment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1847
	check_ajax_referer( 'media-form' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1848
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1849
	 * This function does not use wp_send_json_success() / wp_send_json_error()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1850
	 * as the html4 Plupload handler requires a text/html content-type for older IE.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1851
	 * See https://core.trac.wordpress.org/ticket/31037
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1852
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1853
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1854
	if ( ! current_user_can( 'upload_files' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
		echo wp_json_encode( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
			'success' => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1857
			'data'    => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1858
				'message'  => __( "You don't have permission to upload files." ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1859
				'filename' => $_FILES['async-upload']['name'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1860
			)
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
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
		wp_die();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1864
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
	if ( isset( $_REQUEST['post_id'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
		$post_id = $_REQUEST['post_id'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1868
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
			echo wp_json_encode( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1870
				'success' => false,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1871
				'data'    => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1872
					'message'  => __( "You don't have permission to attach files to this post." ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1873
					'filename' => $_FILES['async-upload']['name'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1874
				)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1875
			) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
			wp_die();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1878
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
		$post_id = null;
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
	$post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
	// If the context is custom header or background, make sure the uploaded file is an image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
	if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1887
		$wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1889
			echo wp_json_encode( array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1890
				'success' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
				'data'    => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1892
					'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
					'filename' => $_FILES['async-upload']['name'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
			) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
			wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1898
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1899
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1900
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1901
	$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1902
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1903
	if ( is_wp_error( $attachment_id ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1904
		echo wp_json_encode( array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1905
			'success' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1906
			'data'    => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
				'message'  => $attachment_id->get_error_message(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
				'filename' => $_FILES['async-upload']['name'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1909
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1910
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1911
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1912
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1913
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1914
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
	if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1916
		if ( 'custom-background' === $post_data['context'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1917
			update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1918
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
		if ( 'custom-header' === $post_data['context'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
			update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
	if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
		wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1925
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1926
	echo wp_json_encode( array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1927
		'success' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
		'data'    => $attachment,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1934
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1935
 * Ajax handler for image editing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1936
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1937
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1938
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1939
function wp_ajax_image_editor() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1940
	$attachment_id = intval($_POST['postid']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
	if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
	check_ajax_referer( "image_editor-$attachment_id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
	include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1947
	$msg = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
	switch ( $_POST['do'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
		case 'save' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1950
			$msg = wp_save_image($attachment_id);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1951
			$msg = wp_json_encode($msg);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
			wp_die( $msg );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1953
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
		case 'scale' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
			$msg = wp_save_image($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1957
		case 'restore' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
			$msg = wp_restore_image($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
	wp_image_editor($attachment_id, $msg);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
	wp_die();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1966
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1967
 * Ajax handler for setting the featured image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1968
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1969
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1970
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
function wp_ajax_set_post_thumbnail() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1972
	$json = ! empty( $_REQUEST['json'] ); // New-style request
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
	$post_ID = intval( $_POST['post_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
	if ( ! current_user_can( 'edit_post', $post_ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1978
	$thumbnail_id = intval( $_POST['thumbnail_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
	if ( $json )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
		check_ajax_referer( "update-post_$post_ID" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
		check_ajax_referer( "set_post_thumbnail-$post_ID" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
	if ( $thumbnail_id == '-1' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
		if ( delete_post_thumbnail( $post_ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
			$return = _wp_post_thumbnail_html( null, $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
			$json ? wp_send_json_success( $return ) : wp_die( $return );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
			wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
	if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
		$return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1996
		$json ? wp_send_json_success( $return ) : wp_die( $return );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
	wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2002
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2003
 * AJAX handler for setting the featured image for an attachment.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2004
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2005
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2006
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2007
 * @see set_post_thumbnail()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2008
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2009
function wp_ajax_set_attachment_thumbnail() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2010
	if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2011
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2012
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2013
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2014
	$thumbnail_id = (int) $_POST['thumbnail_id'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2015
	if ( empty( $thumbnail_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2016
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2017
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2018
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2019
	$post_ids = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2020
	// For each URL, try to find its corresponding post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2021
	foreach ( $_POST['urls'] as $url ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2022
		$post_id = attachment_url_to_postid( $url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2023
		if ( ! empty( $post_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2024
			$post_ids[] = $post_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2025
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2026
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2027
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2028
	if ( empty( $post_ids ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2029
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2031
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2032
	$success = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2033
	// For each found attachment, set its thumbnail.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2034
	foreach ( $post_ids as $post_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2035
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2036
			continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2037
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2038
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2039
		if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2040
			$success++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2041
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2042
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2043
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2044
	if ( 0 === $success ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2045
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2046
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2047
		wp_send_json_success();
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
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2050
	wp_send_json_error();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2053
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2054
 * Ajax handler for date formatting.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2055
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2056
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2057
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2058
function wp_ajax_date_format() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2059
	wp_die( date_i18n( sanitize_option( 'date_format', wp_unslash( $_POST['date'] ) ) ) );
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
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2062
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2063
 * Ajax handler for time formatting.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2064
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2065
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2066
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
function wp_ajax_time_format() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2068
	wp_die( date_i18n( sanitize_option( 'time_format', wp_unslash( $_POST['date'] ) ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2071
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2072
 * Ajax handler for saving posts from the fullscreen editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2073
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2074
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2075
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
function wp_ajax_wp_fullscreen_save_post() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
	$post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2079
	$post = null;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
	if ( $post_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
		$post = get_post( $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
	check_ajax_referer('update-post_' . $post_id, '_wpnonce');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
	$post_id = edit_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2088
	if ( is_wp_error( $post_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2089
		wp_send_json_error();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
	if ( $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
		$last_date = mysql2date( get_option('date_format'), $post->post_modified );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
		$last_time = mysql2date( get_option('time_format'), $post->post_modified );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
		$last_date = date_i18n( get_option('date_format') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
		$last_time = date_i18n( get_option('time_format') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2100
	if ( $last_id = get_post_meta( $post_id, '_edit_last', true ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2101
		$last_user = get_userdata( $last_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
		$last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
		$last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2107
	wp_send_json_success( array( 'last_edited' => $last_edited ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2110
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2111
 * Ajax handler for removing a post lock.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2112
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2113
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2114
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
function wp_ajax_wp_remove_post_lock() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2116
	if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2117
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
	$post_id = (int) $_POST['post_ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
	if ( ! $post = get_post( $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
	check_ajax_referer( 'update-post_' . $post_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
	if ( ! current_user_can( 'edit_post', $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
		wp_die( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
	$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
	if ( $active_lock[1] != get_current_user_id() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2129
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2132
	 * Filter the post lock window duration.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
	 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2136
	 * @param int $interval The interval in seconds the post lock duration
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2137
	 *                      should last, plus 5 seconds. Default 150.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2139
	$new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 150 ) + 5 ) . ':' . $active_lock[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
	update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2141
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
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
 * Ajax handler for dismissing a WordPress pointer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2146
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2147
 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2148
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
function wp_ajax_dismiss_wp_pointer() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
	$pointer = $_POST['pointer'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2151
	if ( $pointer != sanitize_key( $pointer ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2152
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
//	check_ajax_referer( 'dismiss-pointer_' . $pointer );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
	$dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
	if ( in_array( $pointer, $dismissed ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
		wp_die( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
	$dismissed[] = $pointer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2162
	$dismissed = implode( ',', $dismissed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2164
	update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2165
	wp_die( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2169
 * Ajax handler for getting an attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
function wp_ajax_get_attachment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2174
	if ( ! isset( $_REQUEST['id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2175
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
	if ( ! $id = absint( $_REQUEST['id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2180
	if ( ! $post = get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	if ( 'attachment' != $post->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
	if ( ! current_user_can( 'upload_files' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
	if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
	wp_send_json_success( $attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2196
 * Ajax handler for querying attachments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2198
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
function wp_ajax_query_attachments() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
	if ( ! current_user_can( 'upload_files' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
	$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2205
	$keys = array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
		's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2207
		'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2208
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2209
	foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2210
		if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2211
			$keys[] = $t->query_var;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2212
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2213
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2214
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2215
	$query = array_intersect_key( $query, array_flip( $keys ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
	$query['post_type'] = 'attachment';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2217
	if ( MEDIA_TRASH
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2218
		&& ! empty( $_REQUEST['query']['post_status'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2219
		&& 'trash' === $_REQUEST['query']['post_status'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2220
		$query['post_status'] = 'trash';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2221
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2222
		$query['post_status'] = 'inherit';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2223
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2224
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
	if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
		$query['post_status'] .= ',private';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2228
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2229
	 * Filter the arguments passed to WP_Query during an AJAX
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2230
	 * call for querying attachments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2231
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2234
	 * @see WP_Query::parse_query()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2235
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2236
	 * @param array $query An array of query variables.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
	$query = apply_filters( 'ajax_query_attachments_args', $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
	$query = new WP_Query( $query );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
	$posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
	$posts = array_filter( $posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
	wp_send_json_success( $posts );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2248
 * Ajax handler for updating attachment attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
function wp_ajax_save_attachment() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
	if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
	if ( ! $id = absint( $_REQUEST['id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
	check_ajax_referer( 'update-post_' . $id, 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2261
	if ( ! current_user_can( 'edit_post', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2262
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
	$changes = $_REQUEST['changes'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
	$post    = get_post( $id, ARRAY_A );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
	if ( 'attachment' != $post['post_type'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2270
	if ( isset( $changes['parent'] ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2271
		$post['post_parent'] = $changes['parent'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2272
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
	if ( isset( $changes['title'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
		$post['post_title'] = $changes['title'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
	if ( isset( $changes['caption'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
		$post['post_excerpt'] = $changes['caption'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
	if ( isset( $changes['description'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
		$post['post_content'] = $changes['description'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2282
	if ( MEDIA_TRASH && isset( $changes['status'] ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2283
		$post['post_status'] = $changes['status'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2284
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2285
	if ( isset( $changes['alt'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2286
		$alt = wp_unslash( $changes['alt'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
		if ( $alt != get_post_meta( $id, '_wp_attachment_image_alt', true ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
			$alt = wp_strip_all_tags( $alt, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
			update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2293
	if ( wp_attachment_is( 'audio', $post['ID'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2294
		$changed = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2295
		$id3data = wp_get_attachment_metadata( $post['ID'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2296
		if ( ! is_array( $id3data ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2297
			$changed = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2298
			$id3data = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2299
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2300
		foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2301
			if ( isset( $changes[ $key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2302
				$changed = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2303
				$id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2304
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2305
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2306
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2307
		if ( $changed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2308
			wp_update_attachment_metadata( $id, $id3data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2309
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2310
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2311
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2312
	if ( MEDIA_TRASH && isset( $changes['status'] ) && 'trash' === $changes['status'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2313
		wp_delete_post( $id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2314
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2315
		wp_update_post( $post );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2316
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2317
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
	wp_send_json_success();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2322
 * Ajax handler for saving backwards compatible attachment attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
function wp_ajax_save_attachment_compat() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
	if ( ! isset( $_REQUEST['id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
	if ( ! $id = absint( $_REQUEST['id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
	if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
	$attachment_data = $_REQUEST['attachments'][ $id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
	check_ajax_referer( 'update-post_' . $id, 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
	if ( ! current_user_can( 'edit_post', $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
	$post = get_post( $id, ARRAY_A );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
	if ( 'attachment' != $post['post_type'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
	/** This filter is documented in wp-admin/includes/media.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2348
	$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2350
	if ( isset( $post['errors'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2351
		$errors = $post['errors']; // @todo return me and display me!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2352
		unset( $post['errors'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2353
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2354
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
	wp_update_post( $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2357
	foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
		if ( isset( $attachment_data[ $taxonomy ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
			wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
	if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2365
	wp_send_json_success( $attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2368
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2369
 * Ajax handler for saving the attachment order.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2370
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
function wp_ajax_save_attachment_order() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
	if ( ! isset( $_REQUEST['post_id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2375
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2377
	if ( ! $post_id = absint( $_REQUEST['post_id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2378
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2380
	if ( empty( $_REQUEST['attachments'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2381
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
	check_ajax_referer( 'update-post_' . $post_id, 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2385
	$attachments = $_REQUEST['attachments'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2387
	if ( ! current_user_can( 'edit_post', $post_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2388
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
	foreach ( $attachments as $attachment_id => $menu_order ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2391
		if ( ! current_user_can( 'edit_post', $attachment_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2392
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
		if ( ! $attachment = get_post( $attachment_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2395
		if ( 'attachment' != $attachment->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2396
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2398
		wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2401
	wp_send_json_success();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2405
 * Ajax handler for sending an attachment to the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2406
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
 * Generates the HTML to send an attachment to the editor.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2408
 * Backwards compatible with the media_send_to_editor filter
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2409
 * and the chain of filters that follow.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
function wp_ajax_send_attachment_to_editor() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
	check_ajax_referer( 'media-send-to-editor', 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
	$attachment = wp_unslash( $_POST['attachment'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2418
	$id = intval( $attachment['id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	if ( ! $post = get_post( $id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
	if ( 'attachment' != $post->post_type )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
	if ( current_user_can( 'edit_post', $id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
		// If this attachment is unattached, attach it. Primarily a back compat thing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
		if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
			wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
	$rel = $url = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2434
	$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
	if ( ! empty( $attachment['url'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
		$url = $attachment['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
		if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
			$rel = ' rel="attachment wp-att-' . $id . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
		$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
	remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2444
	if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
		$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
		$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
		$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2448
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2449
		// No whitespace-only captions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2450
		$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2451
		if ( '' === trim( $caption ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2452
			$caption = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2453
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2454
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2455
		$title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
		$html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2457
	} elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post )  ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2458
		$html = stripslashes_deep( $_POST['html'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2459
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2460
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2461
	/** This filter is documented in wp-admin/includes/media.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2462
	$html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2464
	wp_send_json_success( $html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2468
 * Ajax handler for sending a link to the editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2469
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
 * Generates the HTML to send a non-image embed link to the editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
 * Backwards compatible with the following filters:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
 * - file_send_to_editor_url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
 * - audio_send_to_editor_url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
 * - video_send_to_editor_url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
function wp_ajax_send_link_to_editor() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2480
	global $post, $wp_embed;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2481
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
	check_ajax_referer( 'media-send-to-editor', 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
	if ( ! $src = wp_unslash( $_POST['src'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
	if ( ! strpos( $src, '://' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
		$src = 'http://' . $src;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
	if ( ! $src = esc_url_raw( $src ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2491
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2493
	if ( ! $link_text = trim( wp_unslash( $_POST['link_text'] ) ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2494
		$link_text = wp_basename( $src );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2495
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2496
	$post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2497
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2498
	// Ping WordPress for an embed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2499
	$check_embed = $wp_embed->run_shortcode( '[embed]'. $src .'[/embed]' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2500
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2501
	// Fallback that WordPress creates when no oEmbed was found.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2502
	$fallback = $wp_embed->maybe_make_link( $src );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2503
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2504
	if ( $check_embed !== $fallback ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2505
		// TinyMCE view for [embed] will parse this
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2506
		$html = '[embed]' . $src . '[/embed]';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2507
	} elseif ( $link_text ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2508
		$html = '<a href="' . esc_url( $src ) . '">' . $link_text . '</a>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2509
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2510
		$html = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2511
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2512
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2513
	// Figure out what filter to run:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2514
	$type = 'file';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2515
	if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2516
		&& ( 'audio' == $ext_type || 'video' == $ext_type ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2517
			$type = $ext_type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2519
	/** This filter is documented in wp-admin/includes/media.php */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2520
	$html = apply_filters( $type . '_send_to_editor_url', $html, $src, $link_text );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2522
	wp_send_json_success( $html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2523
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2524
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2525
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2526
 * Ajax handler for the Heartbeat API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2527
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2528
 * Runs when the user is logged in.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2529
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2530
 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2531
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2532
function wp_ajax_heartbeat() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2533
	if ( empty( $_POST['_nonce'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2534
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2535
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2536
	$response = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2538
	if ( false === wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2539
		// User is logged in but nonces have expired.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2540
		$response['nonces_expired'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2541
		wp_send_json($response);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2542
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2543
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2544
	// screen_id is the same as $current_screen->id and the JS global 'pagenow'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2545
	if ( ! empty($_POST['screen_id']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2546
		$screen_id = sanitize_key($_POST['screen_id']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2547
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2548
		$screen_id = 'front';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2549
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2550
	if ( ! empty($_POST['data']) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2551
		$data = wp_unslash( (array) $_POST['data'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2553
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2554
		 * Filter the Heartbeat response received.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2555
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2556
		 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2557
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2558
		 * @param array|object $response  The Heartbeat response object or array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2559
		 * @param array        $data      The $_POST data sent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2560
		 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2561
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2562
		$response = apply_filters( 'heartbeat_received', $response, $data, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2563
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2565
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2566
	 * Filter the Heartbeat response sent.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2567
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2568
	 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2569
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2570
	 * @param array|object $response  The Heartbeat response object or array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2571
	 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2572
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2573
	$response = apply_filters( 'heartbeat_send', $response, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2575
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2576
	 * Fires when Heartbeat ticks in logged-in environments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2577
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2578
	 * Allows the transport to be easily replaced with long-polling.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2580
	 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2581
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2582
	 * @param array|object $response  The Heartbeat response object or array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2583
	 * @param string       $screen_id The screen id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2584
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2585
	do_action( 'heartbeat_tick', $response, $screen_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2587
	// Send the current time according to the server
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2588
	$response['server_time'] = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2590
	wp_send_json($response);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2591
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2592
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2593
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2594
 * Ajax handler for getting revision diffs.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2595
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2596
 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2597
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2598
function wp_ajax_get_revision_diffs() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2599
	require ABSPATH . 'wp-admin/includes/revision.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2601
	if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2602
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2603
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2604
	if ( ! current_user_can( 'read_post', $post->ID ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2605
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2607
	// Really just pre-loading the cache here.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2608
	if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2609
		wp_send_json_error();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2611
	$return = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2612
	@set_time_limit( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2614
	foreach ( $_REQUEST['compare'] as $compare_key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2615
		list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2617
		$return[] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2618
			'id' => $compare_key,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2619
			'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2620
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2621
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2622
	wp_send_json_success( $return );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2623
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2624
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2625
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2626
 * Ajax handler for auto-saving the selected color scheme for
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2627
 * a user's own profile.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2628
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2629
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2630
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2631
function wp_ajax_save_user_color_scheme() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2632
	global $_wp_admin_css_colors;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2633
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2634
	check_ajax_referer( 'save-color-scheme', 'nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2635
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2636
	$color_scheme = sanitize_key( $_POST['color_scheme'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2637
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2638
	if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2639
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2640
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2641
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2642
	$previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2643
	update_user_meta( get_current_user_id(), 'admin_color', $color_scheme );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2644
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2645
	wp_send_json_success( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2646
		'previousScheme' => 'admin-color-' . $previous_color_scheme,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2647
		'currentScheme'  => 'admin-color-' . $color_scheme
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2648
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2649
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2650
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2651
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2652
 * Ajax handler for getting themes from themes_api().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2653
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2654
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2655
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2656
function wp_ajax_query_themes() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2657
	global $themes_allowedtags, $theme_field_defaults;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2658
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2659
	if ( ! current_user_can( 'install_themes' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2660
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2661
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2662
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2663
	$args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2664
		'per_page' => 20,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2665
		'fields'   => $theme_field_defaults
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2666
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2667
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2668
	$old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2669
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2670
	/** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2671
	$args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2672
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2673
	$api = themes_api( 'query_themes', $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2674
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2675
	if ( is_wp_error( $api ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2676
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2677
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2678
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2679
	$update_php = network_admin_url( 'update.php?action=install-theme' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2680
	foreach ( $api->themes as &$theme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2681
		$theme->install_url = add_query_arg( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2682
			'theme'    => $theme->slug,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2683
			'_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2684
		), $update_php );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2685
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2686
		$theme->name        = wp_kses( $theme->name, $themes_allowedtags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2687
		$theme->author      = wp_kses( $theme->author, $themes_allowedtags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2688
		$theme->version     = wp_kses( $theme->version, $themes_allowedtags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2689
		$theme->description = wp_kses( $theme->description, $themes_allowedtags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2690
		$theme->num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2691
		$theme->preview_url = set_url_scheme( $theme->preview_url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2692
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2693
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2694
	wp_send_json_success( $api );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2695
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2696
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2697
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2698
 * Apply [embed] AJAX handlers to a string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2699
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2700
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2701
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2702
 * @global WP_Post  $post     Global $post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2703
 * @global WP_Embed $wp_embed Embed API instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2704
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2705
function wp_ajax_parse_embed() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2706
	global $post, $wp_embed;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2707
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2708
	if ( ! $post = get_post( (int) $_POST['post_ID'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2710
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2712
	if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'edit_post', $post->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2713
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2714
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2716
	$shortcode = wp_unslash( $_POST['shortcode'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2717
	$url = str_replace( '[embed]', '', str_replace( '[/embed]', '', $shortcode ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2718
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2719
	$parsed = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2720
	setup_postdata( $post );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2721
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2722
	$wp_embed->return_false_on_fail = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2723
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2724
	if ( is_ssl() && preg_match( '%^\\[embed[^\\]]*\\]http://%i', $shortcode ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2725
		// Admin is ssl and the user pasted non-ssl URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2726
		// Check if the provider supports ssl embeds and use that for the preview.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2727
		$ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2728
		$parsed = $wp_embed->run_shortcode( $ssl_shortcode );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2729
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2730
		if ( ! $parsed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2731
			$no_ssl_support = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2732
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2733
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2734
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2735
	if ( ! $parsed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2736
		$parsed = $wp_embed->run_shortcode( $shortcode );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2737
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2738
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2739
	if ( ! $parsed ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2740
		wp_send_json_error( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
			'type' => 'not-embeddable',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2742
			'message' => sprintf( __( '%s failed to embed.' ), '<code>' . esc_html( $url ) . '</code>' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2743
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2744
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2745
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2746
	if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2747
		$styles = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2748
		$mce_styles = wpview_media_sandbox_styles();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2749
		foreach ( $mce_styles as $style ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2750
			$styles .= sprintf( '<link rel="stylesheet" href="%s"/>', $style );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2751
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2752
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2753
		$html = do_shortcode( $parsed );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2754
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2755
		global $wp_scripts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2756
		if ( ! empty( $wp_scripts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2757
			$wp_scripts->done = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2758
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2759
		ob_start();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2760
		wp_print_scripts( 'wp-mediaelement' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2761
		$scripts = ob_get_clean();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2762
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2763
		$parsed = $styles . $html . $scripts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2764
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2765
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2766
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2767
	if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) ||
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2768
		preg_match( '%<link [^>]*href="http://%', $parsed ) ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2769
		// Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2770
		wp_send_json_error( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2771
			'type' => 'not-ssl',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2772
			'message' => __( 'This preview is unavailable in the editor.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2773
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
	wp_send_json_success( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2777
		'body' => $parsed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2778
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2779
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2780
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2781
function wp_ajax_parse_media_shortcode() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2782
	global $post, $wp_scripts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2783
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2784
	if ( empty( $_POST['shortcode'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2785
		wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2786
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2787
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2788
	$shortcode = wp_unslash( $_POST['shortcode'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2789
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2790
	if ( ! empty( $_POST['post_ID'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2791
		$post = get_post( (int) $_POST['post_ID'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2792
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2793
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2794
	// the embed shortcode requires a post
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2795
	if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2796
		if ( 'embed' === $shortcode ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2797
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2798
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2799
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2800
		setup_postdata( $post );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2801
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2802
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2803
	$parsed = do_shortcode( $shortcode  );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2804
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2805
	if ( empty( $parsed ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2806
		wp_send_json_error( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2807
			'type' => 'no-items',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2808
			'message' => __( 'No items found.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2809
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2810
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2811
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2812
	$head = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2813
	$styles = wpview_media_sandbox_styles();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2814
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2815
	foreach ( $styles as $style ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2816
		$head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2817
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2818
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2819
	if ( ! empty( $wp_scripts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2820
		$wp_scripts->done = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2821
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2822
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2823
	ob_start();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2824
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2825
	echo $parsed;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2826
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2827
	if ( 'playlist' === $_REQUEST['type'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2828
		wp_underscore_playlist_templates();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2829
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2830
		wp_print_scripts( 'wp-playlist' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2831
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2832
		wp_print_scripts( array( 'froogaloop', 'wp-mediaelement' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2835
	wp_send_json_success( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2836
		'head' => $head,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2837
		'body' => ob_get_clean()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2838
	) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2839
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2840
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2841
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2842
 * AJAX handler for destroying multiple open sessions for a user.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2843
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2844
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2845
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2846
function wp_ajax_destroy_sessions() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2847
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2848
	$user = get_userdata( (int) $_POST['user_id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2849
	if ( $user ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2850
		if ( ! current_user_can( 'edit_user', $user->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2851
			$user = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2852
		} elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2853
			$user = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2854
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2855
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2856
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2857
	if ( ! $user ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2858
		wp_send_json_error( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2859
			'message' => __( 'Could not log out user sessions. Please try again.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2860
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2861
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2862
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2863
	$sessions = WP_Session_Tokens::get_instance( $user->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2864
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2865
	if ( $user->ID === get_current_user_id() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2866
		$sessions->destroy_others( wp_get_session_token() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2867
		$message = __( 'You are now logged out everywhere else.' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2868
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2869
		$sessions->destroy_all();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2870
		/* translators: 1: User's display name. */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2871
		$message = sprintf( __( '%s has been logged out.' ), $user->display_name );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2872
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2874
	wp_send_json_success( array( 'message' => $message ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2875
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2876
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2877
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2878
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2879
 * AJAX handler for updating a plugin.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2880
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2881
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2882
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2883
 * @see Plugin_Upgrader
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2885
function wp_ajax_update_plugin() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
	$plugin = urldecode( $_POST['plugin'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2887
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2888
	$status = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2889
		'update'     => 'plugin',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
		'plugin'     => $plugin,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
		'slug'       => sanitize_key( $_POST['slug'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2892
		'oldVersion' => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
		'newVersion' => '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2895
	$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2896
	if ( $plugin_data['Version'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2897
		$status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2898
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2899
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2900
	if ( ! current_user_can( 'update_plugins' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2901
		$status['error'] = __( 'You do not have sufficient permissions to update plugins on this site.' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2902
 		wp_send_json_error( $status );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2903
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2904
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2905
	check_ajax_referer( 'updates' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2906
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2907
	include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2908
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2909
	$current = get_site_transient( 'update_plugins' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2910
	if ( empty( $current ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2911
		wp_update_plugins();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2912
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2913
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2914
	$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2915
	$result = $upgrader->bulk_upgrade( array( $plugin ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2916
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2917
	if ( is_array( $result ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2918
		$plugin_update_data = current( $result );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2919
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2920
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2921
		 * If the `update_plugins` site transient is empty (e.g. when you update
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2922
		 * two plugins in quick succession before the transient repopulates),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2923
		 * this may be the return.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2924
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2925
		 * Preferably something can be done to ensure `update_plugins` isn't empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2926
		 * For now, surface some sort of error here.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2927
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2928
		if ( $plugin_update_data === true ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2929
 			wp_send_json_error( $status );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2930
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2931
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2932
		$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2933
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2934
		if ( $plugin_data['Version'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2935
			$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2936
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2937
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2938
		wp_send_json_success( $status );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2939
	} else if ( is_wp_error( $result ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2940
		$status['error'] = $result->get_error_message();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2941
 		wp_send_json_error( $status );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2942
	} else if ( is_bool( $result ) && ! $result ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2943
		$status['errorCode'] = 'unable_to_connect_to_filesystem';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2944
		$status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2945
		wp_send_json_error( $status );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2946
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2947
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2948
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2949
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2950
 * AJAX handler for saving a post from Press This.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2951
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2952
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2953
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2954
function wp_ajax_press_this_save_post() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2955
	if ( empty( $GLOBALS['wp_press_this'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2956
		include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2957
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2958
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2959
	$GLOBALS['wp_press_this']->save_post();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2960
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2961
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2962
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2963
 * AJAX handler for creating new category from Press This.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2964
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2965
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2966
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2967
function wp_ajax_press_this_add_category() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2968
	if ( empty( $GLOBALS['wp_press_this'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2969
		include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2970
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2971
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2972
	$GLOBALS['wp_press_this']->add_category();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2973
}