web/wp-admin/includes/ajax-actions.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    27 
    27 
    28 /*
    28 /*
    29  * GET-based Ajax handlers.
    29  * GET-based Ajax handlers.
    30  */
    30  */
    31 function wp_ajax_fetch_list() {
    31 function wp_ajax_fetch_list() {
    32 	global $current_screen, $wp_list_table;
    32 	global $wp_list_table;
    33 
    33 
    34 	$list_class = $_GET['list_args']['class'];
    34 	$list_class = $_GET['list_args']['class'];
    35 	check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
    35 	check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
    36 
    36 
    37 	$current_screen = convert_to_screen( $_GET['list_args']['screen']['id'] );
    37 	$wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
    38 
       
    39 	define( 'WP_NETWORK_ADMIN', $current_screen->is_network );
       
    40 	define( 'WP_USER_ADMIN', $current_screen->is_user );
       
    41 
       
    42 	$wp_list_table = _get_list_table( $list_class );
       
    43 	if ( ! $wp_list_table )
    38 	if ( ! $wp_list_table )
    44 		wp_die( 0 );
    39 		wp_die( 0 );
    45 
    40 
    46 	if ( ! $wp_list_table->ajax_user_can() )
    41 	if ( ! $wp_list_table->ajax_user_can() )
    47 		wp_die( -1 );
    42 		wp_die( -1 );
   191 
   186 
   192 	wp_die( json_encode( $return ) );
   187 	wp_die( json_encode( $return ) );
   193 }
   188 }
   194 
   189 
   195 function wp_ajax_dashboard_widgets() {
   190 function wp_ajax_dashboard_widgets() {
   196 	require ABSPATH . 'wp-admin/includes/dashboard.php';
   191 	require_once ABSPATH . 'wp-admin/includes/dashboard.php';
   197 
   192 
   198 	switch ( $_GET['widget'] ) {
   193 	switch ( $_GET['widget'] ) {
   199 		case 'dashboard_incoming_links' :
   194 		case 'dashboard_incoming_links' :
   200 			wp_dashboard_incoming_links();
   195 			wp_dashboard_incoming_links();
   201 			break;
   196 			break;
   329 	if ( $parent ) { // Foncy - replace the parent and all its children
   324 	if ( $parent ) { // Foncy - replace the parent and all its children
   330 		$parent = get_term( $parent, $taxonomy->name );
   325 		$parent = get_term( $parent, $taxonomy->name );
   331 		$term_id = $parent->term_id;
   326 		$term_id = $parent->term_id;
   332 
   327 
   333 		while ( $parent->parent ) { // get the top parent
   328 		while ( $parent->parent ) { // get the top parent
   334 			$parent = &get_term( $parent->parent, $taxonomy->name );
   329 			$parent = get_term( $parent->parent, $taxonomy->name );
   335 			if ( is_wp_error( $parent ) )
   330 			if ( is_wp_error( $parent ) )
   336 				break;
   331 				break;
   337 			$term_id = $parent->term_id;
   332 			$term_id = $parent->term_id;
   338 		}
   333 		}
   339 
   334 
   510 
   505 
   511 	check_ajax_referer( "{$action}_$id" );
   506 	check_ajax_referer( "{$action}_$id" );
   512 	if ( !current_user_can( 'delete_page', $id ) )
   507 	if ( !current_user_can( 'delete_page', $id ) )
   513 		wp_die( -1 );
   508 		wp_die( -1 );
   514 
   509 
   515 	if ( !get_page( $id ) )
   510 	if ( ! get_post( $id ) )
   516 		wp_die( 1 );
   511 		wp_die( 1 );
   517 
   512 
   518 	if ( wp_delete_post( $id ) )
   513 	if ( wp_delete_post( $id ) )
   519 		wp_die( 1 );
   514 		wp_die( 1 );
   520 	else
   515 	else
   613 			'data' => new WP_Error('error', $message )
   608 			'data' => new WP_Error('error', $message )
   614 		) );
   609 		) );
   615 		$x->send();
   610 		$x->send();
   616 	}
   611 	}
   617 
   612 
   618 	set_current_screen( $_POST['screen'] );
   613 	$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
   619 
       
   620 	$wp_list_table = _get_list_table('WP_Terms_List_Table');
       
   621 
   614 
   622 	$level = 0;
   615 	$level = 0;
   623 	if ( is_taxonomy_hierarchical($taxonomy) ) {
   616 	if ( is_taxonomy_hierarchical($taxonomy) ) {
   624 		$level = count( get_ancestors( $tag->term_id, $taxonomy ) );
   617 		$level = count( get_ancestors( $tag->term_id, $taxonomy ) );
   625 		ob_start();
   618 		ob_start();
   684 	if ( empty( $action ) )
   677 	if ( empty( $action ) )
   685 		$action = 'get-comments';
   678 		$action = 'get-comments';
   686 
   679 
   687 	check_ajax_referer( $action );
   680 	check_ajax_referer( $action );
   688 
   681 
   689 	set_current_screen( 'edit-comments' );
   682 	$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
   690 
       
   691 	$wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
       
   692 
   683 
   693 	if ( !current_user_can( 'edit_post', $post_id ) )
   684 	if ( !current_user_can( 'edit_post', $post_id ) )
   694 		wp_die( -1 );
   685 		wp_die( -1 );
   695 
   686 
   696 	$wp_list_table->prepare_items();
   687 	$wp_list_table->prepare_items();
   720 	global $wp_list_table, $wpdb;
   711 	global $wp_list_table, $wpdb;
   721 	if ( empty( $action ) )
   712 	if ( empty( $action ) )
   722 		$action = 'replyto-comment';
   713 		$action = 'replyto-comment';
   723 
   714 
   724 	check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
   715 	check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
   725 
       
   726 	set_current_screen( 'edit-comments' );
       
   727 
   716 
   728 	$comment_post_ID = (int) $_POST['comment_post_ID'];
   717 	$comment_post_ID = (int) $_POST['comment_post_ID'];
   729 	if ( !current_user_can( 'edit_post', $comment_post_ID ) )
   718 	if ( !current_user_can( 'edit_post', $comment_post_ID ) )
   730 		wp_die( -1 );
   719 		wp_die( -1 );
   731 
   720 
   758 
   747 
   759 	$comment_parent = absint($_POST['comment_ID']);
   748 	$comment_parent = absint($_POST['comment_ID']);
   760 	$comment_auto_approved = false;
   749 	$comment_auto_approved = false;
   761 	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
   750 	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
   762 
   751 
   763 	$comment_id = wp_new_comment( $commentdata );
       
   764 	$comment = get_comment($comment_id);
       
   765 	if ( ! $comment ) wp_die( 1 );
       
   766 
       
   767 	$position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
       
   768 
       
   769 	// automatically approve parent comment
   752 	// automatically approve parent comment
   770 	if ( !empty($_POST['approve_parent']) ) {
   753 	if ( !empty($_POST['approve_parent']) ) {
   771 		$parent = get_comment( $comment_parent );
   754 		$parent = get_comment( $comment_parent );
   772 
   755 
   773 		if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
   756 		if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
   774 			if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
   757 			if ( wp_set_comment_status( $parent->comment_ID, 'approve' ) )
   775 				$comment_auto_approved = true;
   758 				$comment_auto_approved = true;
   776 		}
   759 		}
   777 	}
   760 	}
       
   761 
       
   762 	$comment_id = wp_new_comment( $commentdata );
       
   763 	$comment = get_comment($comment_id);
       
   764 	if ( ! $comment ) wp_die( 1 );
       
   765 
       
   766 	$position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
   778 
   767 
   779 	ob_start();
   768 	ob_start();
   780 		if ( 'dashboard' == $_REQUEST['mode'] ) {
   769 		if ( 'dashboard' == $_REQUEST['mode'] ) {
   781 			require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
   770 			require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
   782 			_wp_dashboard_recent_comments_row( $comment );
   771 			_wp_dashboard_recent_comments_row( $comment );
   783 		} else {
   772 		} else {
   784 			if ( 'single' == $_REQUEST['mode'] ) {
   773 			if ( 'single' == $_REQUEST['mode'] ) {
   785 				$wp_list_table = _get_list_table('WP_Post_Comments_List_Table');
   774 				$wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
   786 			} else {
   775 			} else {
   787 				$wp_list_table = _get_list_table('WP_Comments_List_Table');
   776 				$wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
   788 			}
   777 			}
   789 			$wp_list_table->single_row( $comment );
   778 			$wp_list_table->single_row( $comment );
   790 		}
   779 		}
   791 		$comment_list_item = ob_get_contents();
   780 		$comment_list_item = ob_get_contents();
   792 	ob_end_clean();
   781 	ob_end_clean();
   809 function wp_ajax_edit_comment() {
   798 function wp_ajax_edit_comment() {
   810 	global $wp_list_table;
   799 	global $wp_list_table;
   811 
   800 
   812 	check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
   801 	check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
   813 
   802 
   814 	set_current_screen( 'edit-comments' );
       
   815 
       
   816 	$comment_id = (int) $_POST['comment_ID'];
   803 	$comment_id = (int) $_POST['comment_ID'];
   817 	if ( ! current_user_can( 'edit_comment', $comment_id ) )
   804 	if ( ! current_user_can( 'edit_comment', $comment_id ) )
   818 		wp_die( -1 );
   805 		wp_die( -1 );
   819 
   806 
   820 	if ( '' == $_POST['content'] )
   807 	if ( '' == $_POST['content'] )
   825 
   812 
   826 	$position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
   813 	$position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
   827 	$comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
   814 	$comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
   828 
   815 
   829 	$checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
   816 	$checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
   830 	$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table' );
   817 	$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
   831 
   818 
   832 	$comment = get_comment( $comment_id );
   819 	$comment = get_comment( $comment_id );
   833 
   820 
   834 	ob_start();
   821 	ob_start();
   835 		$wp_list_table->single_row( $comment );
   822 		$wp_list_table->single_row( $comment );
  1016 			'what' => 'user',
  1003 			'what' => 'user',
  1017 			'id' => $user_id
  1004 			'id' => $user_id
  1018 		) );
  1005 		) );
  1019 		$x->send();
  1006 		$x->send();
  1020 	}
  1007 	}
  1021 	$user_object = new WP_User( $user_id );
  1008 	$user_object = get_userdata( $user_id );
  1022 
  1009 
  1023 	$wp_list_table = _get_list_table('WP_Users_List_Table');
  1010 	$wp_list_table = _get_list_table('WP_Users_List_Table');
       
  1011 
       
  1012 	$role = current( $user_object->roles );
  1024 
  1013 
  1025 	$x = new WP_Ajax_Response( array(
  1014 	$x = new WP_Ajax_Response( array(
  1026 		'what' => 'user',
  1015 		'what' => 'user',
  1027 		'id' => $user_id,
  1016 		'id' => $user_id,
  1028 		'data' => $wp_list_table->single_row( $user_object, '', $user_object->roles[0] ),
  1017 		'data' => $wp_list_table->single_row( $user_object, '', $role ),
  1029 		'supplemental' => array(
  1018 		'supplemental' => array(
  1030 			'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
  1019 			'show-link' => sprintf(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login),
  1031 			'role' => $user_object->roles[0]
  1020 			'role' => $role,
  1032 		)
  1021 		)
  1033 	) );
  1022 	) );
  1034 	$x->send();
  1023 	$x->send();
  1035 }
  1024 }
  1036 
  1025 
  1326 	} else {
  1315 	} else {
  1327 		if ( ! current_user_can( 'edit_post', $post_ID ) )
  1316 		if ( ! current_user_can( 'edit_post', $post_ID ) )
  1328 			wp_die( __( 'You are not allowed to edit this post.' ) );
  1317 			wp_die( __( 'You are not allowed to edit this post.' ) );
  1329 	}
  1318 	}
  1330 
  1319 
  1331 	set_current_screen( $_POST['screen'] );
       
  1332 
       
  1333 	if ( $last = wp_check_post_lock( $post_ID ) ) {
  1320 	if ( $last = wp_check_post_lock( $post_ID ) ) {
  1334 		$last_user = get_userdata( $last );
  1321 		$last_user = get_userdata( $last );
  1335 		$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
  1322 		$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
  1336 		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 ) );
  1323 		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 ) );
  1337 		wp_die();
  1324 		wp_die();
  1363 		$data['ping_status'] = 'closed';
  1350 		$data['ping_status'] = 'closed';
  1364 
  1351 
  1365 	// update the post
  1352 	// update the post
  1366 	edit_post();
  1353 	edit_post();
  1367 
  1354 
  1368 	$wp_list_table = _get_list_table('WP_Posts_List_Table');
  1355 	$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
  1369 
  1356 
  1370 	$mode = $_POST['post_view'];
  1357 	$mode = $_POST['post_view'];
  1371 	$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
  1358 
       
  1359 	$level = 0;
       
  1360 	$request_post = array( get_post( $_POST['post_ID'] ) );
       
  1361 	$parent = $request_post[0]->post_parent;
       
  1362 
       
  1363 	while ( $parent > 0 ) {
       
  1364 		$parent_post = get_post( $parent );
       
  1365 		$parent = $parent_post->post_parent;
       
  1366 		$level++;
       
  1367 	}
       
  1368 
       
  1369 	$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
  1372 
  1370 
  1373 	wp_die();
  1371 	wp_die();
  1374 }
  1372 }
  1375 
  1373 
  1376 function wp_ajax_inline_save_tax() {
  1374 function wp_ajax_inline_save_tax() {
  1384 		wp_die( 0 );
  1382 		wp_die( 0 );
  1385 
  1383 
  1386 	if ( ! current_user_can( $tax->cap->edit_terms ) )
  1384 	if ( ! current_user_can( $tax->cap->edit_terms ) )
  1387 		wp_die( -1 );
  1385 		wp_die( -1 );
  1388 
  1386 
  1389 	set_current_screen( 'edit-' . $taxonomy );
  1387 	$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );
  1390 
       
  1391 	$wp_list_table = _get_list_table('WP_Terms_List_Table');
       
  1392 
  1388 
  1393 	if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
  1389 	if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
  1394 		wp_die( -1 );
  1390 		wp_die( -1 );
  1395 
  1391 
  1396 	$tag = get_term( $id, $taxonomy );
  1392 	$tag = get_term( $id, $taxonomy );
  1402 		if ( !$tag || is_wp_error( $tag ) ) {
  1398 		if ( !$tag || is_wp_error( $tag ) ) {
  1403 			if ( is_wp_error($tag) && $tag->get_error_message() )
  1399 			if ( is_wp_error($tag) && $tag->get_error_message() )
  1404 				wp_die( $tag->get_error_message() );
  1400 				wp_die( $tag->get_error_message() );
  1405 			wp_die( __( 'Item not updated.' ) );
  1401 			wp_die( __( 'Item not updated.' ) );
  1406 		}
  1402 		}
  1407 
       
  1408 		echo $wp_list_table->single_row( $tag );
       
  1409 	} else {
  1403 	} else {
  1410 		if ( is_wp_error($updated) && $updated->get_error_message() )
  1404 		if ( is_wp_error($updated) && $updated->get_error_message() )
  1411 			wp_die( $updated->get_error_message() );
  1405 			wp_die( $updated->get_error_message() );
  1412 		wp_die( __( 'Item not updated.' ) );
  1406 		wp_die( __( 'Item not updated.' ) );
  1413 	}
  1407 	}
  1414 
  1408 	$level = 0;
       
  1409 	$parent = $tag->parent;
       
  1410 	while ( $parent > 0 ) {
       
  1411 		$parent_tag = get_term( $parent, $taxonomy );
       
  1412 		$parent = $parent_tag->parent;
       
  1413 		$level++;
       
  1414 	}
       
  1415 	echo $wp_list_table->single_row( $tag, $level );
  1415 	wp_die();
  1416 	wp_die();
  1416 }
  1417 }
  1417 
  1418 
  1418 function wp_ajax_find_posts() {
  1419 function wp_ajax_find_posts() {
  1419 	global $wpdb;
  1420 	global $wpdb;
  1420 
  1421 
  1421 	check_ajax_referer( 'find-posts' );
  1422 	check_ajax_referer( 'find-posts' );
  1422 
  1423 
  1423 	if ( empty($_POST['ps']) )
  1424 	$post_types = get_post_types( array( 'public' => true ), 'objects' );
  1424 		wp_die();
  1425 	unset( $post_types['attachment'] );
  1425 
  1426 
  1426 	if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
  1427 	$s = stripslashes( $_POST['ps'] );
  1427 		$what = $_POST['post_type'];
       
  1428 	else
       
  1429 		$what = 'post';
       
  1430 
       
  1431 	$s = stripslashes($_POST['ps']);
       
  1432 	preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
       
  1433 	$search_terms = array_map('_search_terms_tidy', $matches[0]);
       
  1434 
       
  1435 	$searchand = $search = '';
  1428 	$searchand = $search = '';
  1436 	foreach ( (array) $search_terms as $term ) {
  1429 	$args = array(
  1437 		$term = esc_sql( like_escape( $term ) );
  1430 		'post_type' => array_keys( $post_types ),
  1438 		$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
  1431 		'post_status' => 'any',
  1439 		$searchand = ' AND ';
  1432 		'posts_per_page' => 50,
  1440 	}
  1433 	);
  1441 	$term = esc_sql( like_escape( $s ) );
  1434 	if ( '' !== $s )
  1442 	if ( count($search_terms) > 1 && $search_terms[0] != $s )
  1435 		$args['s'] = $s;
  1443 		$search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
  1436 
  1444 
  1437 	$posts = get_posts( $args );
  1445 	$posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
  1438 
  1446 
  1439 	if ( ! $posts )
  1447 	if ( ! $posts ) {
  1440 		wp_die( __('No items found.') );
  1448 		$posttype = get_post_type_object($what);
  1441 
  1449 		wp_die( $posttype->labels->not_found );
  1442 	$html = '<table class="widefat" cellspacing="0"><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>';
  1450 	}
       
  1451 
       
  1452 	$html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
       
  1453 	foreach ( $posts as $post ) {
  1443 	foreach ( $posts as $post ) {
       
  1444 		$title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
  1454 
  1445 
  1455 		switch ( $post->post_status ) {
  1446 		switch ( $post->post_status ) {
  1456 			case 'publish' :
  1447 			case 'publish' :
  1457 			case 'private' :
  1448 			case 'private' :
  1458 				$stat = __('Published');
  1449 				$stat = __('Published');
  1474 			/* translators: date format in table columns, see http://php.net/date */
  1465 			/* translators: date format in table columns, see http://php.net/date */
  1475 			$time = mysql2date(__('Y/m/d'), $post->post_date);
  1466 			$time = mysql2date(__('Y/m/d'), $post->post_date);
  1476 		}
  1467 		}
  1477 
  1468 
  1478 		$html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
  1469 		$html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
  1479 		$html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n";
  1470 		$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";
  1480 	}
  1471 	}
       
  1472 
  1481 	$html .= '</tbody></table>';
  1473 	$html .= '</tbody></table>';
  1482 
  1474 
  1483 	$x = new WP_Ajax_Response();
  1475 	$x = new WP_Ajax_Response();
  1484 	$x->add( array(
  1476 	$x->add( array(
  1485 		'what' => $what,
       
  1486 		'data' => $html
  1477 		'data' => $html
  1487 	));
  1478 	));
  1488 	$x->send();
  1479 	$x->send();
  1489 
       
  1490 }
  1480 }
  1491 
  1481 
  1492 function wp_ajax_widgets_order() {
  1482 function wp_ajax_widgets_order() {
  1493 	check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
  1483 	check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
  1494 
  1484 
  1593 
  1583 
  1594 function wp_ajax_upload_attachment() {
  1584 function wp_ajax_upload_attachment() {
  1595 	check_ajax_referer( 'media-form' );
  1585 	check_ajax_referer( 'media-form' );
  1596 
  1586 
  1597 	if ( ! current_user_can( 'upload_files' ) )
  1587 	if ( ! current_user_can( 'upload_files' ) )
  1598 		wp_die( -1 );
  1588 		wp_die();
  1599 
  1589 
  1600 	if ( isset( $_REQUEST['post_id'] ) ) {
  1590 	if ( isset( $_REQUEST['post_id'] ) ) {
  1601 		$post_id = $_REQUEST['post_id'];
  1591 		$post_id = $_REQUEST['post_id'];
  1602 		if ( ! current_user_can( 'edit_post', $post_id ) )
  1592 		if ( ! current_user_can( 'edit_post', $post_id ) )
  1603 			wp_die( -1 );
  1593 			wp_die();
  1604 	} else {
  1594 	} else {
  1605 		$post_id = null;
  1595 		$post_id = null;
  1606 	}
  1596 	}
  1607 
  1597 
  1608 	$post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
  1598 	$post_data = isset( $_REQUEST['post_data'] ) ? $_REQUEST['post_data'] : array();
  1609 
  1599 
       
  1600 	// If the context is custom header or background, make sure the uploaded file is an image.
       
  1601 	if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
       
  1602 		$wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'], false );
       
  1603 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
       
  1604 			echo json_encode( array(
       
  1605 				'success' => false,
       
  1606 				'data'    => array(
       
  1607 					'message'  => __( 'The uploaded file is not a valid image. Please try again.' ),
       
  1608 					'filename' => $_FILES['async-upload']['name'],
       
  1609 				)
       
  1610 			) );
       
  1611 
       
  1612 			wp_die();
       
  1613 		}
       
  1614 	}
       
  1615 
  1610 	$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
  1616 	$attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
  1611 
  1617 
  1612 	if ( is_wp_error( $attachment_id ) ) {
  1618 	if ( is_wp_error( $attachment_id ) ) {
  1613 		echo json_encode( array(
  1619 		echo json_encode( array(
  1614 			'type' => 'error',
  1620 			'success' => false,
  1615 			'data' => array(
  1621 			'data'    => array(
  1616 				'message'  => $attachment_id->get_error_message(),
  1622 				'message'  => $attachment_id->get_error_message(),
  1617 				'filename' => $_FILES['async-upload']['name'],
  1623 				'filename' => $_FILES['async-upload']['name'],
  1618 			),
  1624 			)
  1619 		) );
  1625 		) );
       
  1626 
  1620 		wp_die();
  1627 		wp_die();
  1621 	}
  1628 	}
  1622 
  1629 
  1623 	if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
  1630 	if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
  1624 		if ( 'custom-background' === $post_data['context'] )
  1631 		if ( 'custom-background' === $post_data['context'] )
  1626 
  1633 
  1627 		if ( 'custom-header' === $post_data['context'] )
  1634 		if ( 'custom-header' === $post_data['context'] )
  1628 			update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
  1635 			update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
  1629 	}
  1636 	}
  1630 
  1637 
  1631 	$post = get_post( $attachment_id );
  1638 	if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) )
       
  1639 		wp_die();
  1632 
  1640 
  1633 	echo json_encode( array(
  1641 	echo json_encode( array(
  1634 		'type' => 'success',
  1642 		'success' => true,
  1635 		'data' => array(
  1643 		'data'    => $attachment,
  1636 			'id'       => $attachment_id,
       
  1637 			'title'    => esc_attr( $post->post_title ),
       
  1638 			'filename' => esc_html( basename( $post->guid ) ),
       
  1639 			'url'      => wp_get_attachment_url( $attachment_id ),
       
  1640 			'meta'     => wp_get_attachment_metadata( $attachment_id ),
       
  1641 		),
       
  1642 	) );
  1644 	) );
       
  1645 
  1643 	wp_die();
  1646 	wp_die();
  1644 }
  1647 }
  1645 
  1648 
  1646 function wp_ajax_image_editor() {
  1649 function wp_ajax_image_editor() {
  1647 	$attachment_id = intval($_POST['postid']);
  1650 	$attachment_id = intval($_POST['postid']);
  1669 	wp_image_editor($attachment_id, $msg);
  1672 	wp_image_editor($attachment_id, $msg);
  1670 	wp_die();
  1673 	wp_die();
  1671 }
  1674 }
  1672 
  1675 
  1673 function wp_ajax_set_post_thumbnail() {
  1676 function wp_ajax_set_post_thumbnail() {
       
  1677 	$json = ! empty( $_REQUEST['json'] ); // New-style request
       
  1678 
  1674 	$post_ID = intval( $_POST['post_id'] );
  1679 	$post_ID = intval( $_POST['post_id'] );
  1675 	if ( !current_user_can( 'edit_post', $post_ID ) )
  1680 	if ( ! current_user_can( 'edit_post', $post_ID ) )
  1676 		wp_die( -1 );
  1681 		wp_die( -1 );
       
  1682 
  1677 	$thumbnail_id = intval( $_POST['thumbnail_id'] );
  1683 	$thumbnail_id = intval( $_POST['thumbnail_id'] );
  1678 
  1684 
  1679 	check_ajax_referer( "set_post_thumbnail-$post_ID" );
  1685 	if ( $json )
       
  1686 		check_ajax_referer( "update-post_$post_ID" );
       
  1687 	else
       
  1688 		check_ajax_referer( "set_post_thumbnail-$post_ID" );
  1680 
  1689 
  1681 	if ( $thumbnail_id == '-1' ) {
  1690 	if ( $thumbnail_id == '-1' ) {
  1682 		if ( delete_post_thumbnail( $post_ID ) )
  1691 		if ( delete_post_thumbnail( $post_ID ) ) {
  1683 			wp_die( _wp_post_thumbnail_html( null, $post_ID ) );
  1692 			$return = _wp_post_thumbnail_html( null, $post_ID );
  1684 		else
  1693 			$json ? wp_send_json_success( $return ) : wp_die( $return );
       
  1694 		} else {
  1685 			wp_die( 0 );
  1695 			wp_die( 0 );
  1686 	}
  1696 		}
  1687 
  1697 	}
  1688 	if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
  1698 
  1689 		wp_die( _wp_post_thumbnail_html( $thumbnail_id, $post_ID ) );
  1699 	if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) {
       
  1700 		$return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID );
       
  1701 		$json ? wp_send_json_success( $return ) : wp_die( $return );
       
  1702 	}
       
  1703 
  1690 	wp_die( 0 );
  1704 	wp_die( 0 );
  1691 }
  1705 }
  1692 
  1706 
  1693 function wp_ajax_date_format() {
  1707 function wp_ajax_date_format() {
  1694 	wp_die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
  1708 	wp_die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
  1709 	if ( $post )
  1723 	if ( $post )
  1710 		$post_type = $post->post_type;
  1724 		$post_type = $post->post_type;
  1711 	elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) )
  1725 	elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) )
  1712 		$post_type = $_POST['post_type'];
  1726 		$post_type = $_POST['post_type'];
  1713 
  1727 
  1714 	check_ajax_referer('update-' . $post_type . '_' . $post_id, '_wpnonce');
  1728 	check_ajax_referer('update-post_' . $post_id, '_wpnonce');
  1715 
  1729 
  1716 	$post_id = edit_post();
  1730 	$post_id = edit_post();
  1717 
  1731 
  1718 	if ( is_wp_error($post_id) ) {
  1732 	if ( is_wp_error($post_id) ) {
  1719 		if ( $post_id->get_error_message() )
  1733 		if ( $post_id->get_error_message() )
  1751 		wp_die( 0 );
  1765 		wp_die( 0 );
  1752 	$post_id = (int) $_POST['post_ID'];
  1766 	$post_id = (int) $_POST['post_ID'];
  1753 	if ( ! $post = get_post( $post_id ) )
  1767 	if ( ! $post = get_post( $post_id ) )
  1754 		wp_die( 0 );
  1768 		wp_die( 0 );
  1755 
  1769 
  1756 	check_ajax_referer( 'update-' . $post->post_type . '_' . $post_id );
  1770 	check_ajax_referer( 'update-post_' . $post_id );
  1757 
  1771 
  1758 	if ( ! current_user_can( 'edit_post', $post_id ) )
  1772 	if ( ! current_user_can( 'edit_post', $post_id ) )
  1759 		wp_die( -1 );
  1773 		wp_die( -1 );
  1760 
  1774 
  1761 	$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
  1775 	$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
  1783 	$dismissed = implode( ',', $dismissed );
  1797 	$dismissed = implode( ',', $dismissed );
  1784 
  1798 
  1785 	update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
  1799 	update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
  1786 	wp_die( 1 );
  1800 	wp_die( 1 );
  1787 }
  1801 }
       
  1802 
       
  1803 /**
       
  1804  * Get an attachment.
       
  1805  *
       
  1806  * @since 3.5.0
       
  1807  */
       
  1808 function wp_ajax_get_attachment() {
       
  1809 	if ( ! isset( $_REQUEST['id'] ) )
       
  1810 		wp_send_json_error();
       
  1811 
       
  1812 	if ( ! $id = absint( $_REQUEST['id'] ) )
       
  1813 		wp_send_json_error();
       
  1814 
       
  1815 	if ( ! $post = get_post( $id ) )
       
  1816 		wp_send_json_error();
       
  1817 
       
  1818 	if ( 'attachment' != $post->post_type )
       
  1819 		wp_send_json_error();
       
  1820 
       
  1821 	if ( ! current_user_can( 'upload_files' ) )
       
  1822 		wp_send_json_error();
       
  1823 
       
  1824 	if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
       
  1825 		wp_send_json_error();
       
  1826 
       
  1827 	wp_send_json_success( $attachment );
       
  1828 }
       
  1829 
       
  1830 /**
       
  1831  * Query for attachments.
       
  1832  *
       
  1833  * @since 3.5.0
       
  1834  */
       
  1835 function wp_ajax_query_attachments() {
       
  1836 	if ( ! current_user_can( 'upload_files' ) )
       
  1837 		wp_send_json_error();
       
  1838 
       
  1839 	$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
       
  1840 	$query = array_intersect_key( $query, array_flip( array(
       
  1841 		's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
       
  1842 		'post_parent', 'post__in', 'post__not_in',
       
  1843 	) ) );
       
  1844 
       
  1845 	$query['post_type'] = 'attachment';
       
  1846 	$query['post_status'] = 'inherit';
       
  1847 	if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) )
       
  1848 		$query['post_status'] .= ',private';
       
  1849 
       
  1850 	$query = new WP_Query( $query );
       
  1851 
       
  1852 	$posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
       
  1853 	$posts = array_filter( $posts );
       
  1854 
       
  1855 	wp_send_json_success( $posts );
       
  1856 }
       
  1857 
       
  1858 /**
       
  1859  * Save attachment attributes.
       
  1860  *
       
  1861  * @since 3.5.0
       
  1862  */
       
  1863 function wp_ajax_save_attachment() {
       
  1864 	if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) )
       
  1865 		wp_send_json_error();
       
  1866 
       
  1867 	if ( ! $id = absint( $_REQUEST['id'] ) )
       
  1868 		wp_send_json_error();
       
  1869 
       
  1870 	check_ajax_referer( 'update-post_' . $id, 'nonce' );
       
  1871 
       
  1872 	if ( ! current_user_can( 'edit_post', $id ) )
       
  1873 		wp_send_json_error();
       
  1874 
       
  1875 	$changes = $_REQUEST['changes'];
       
  1876 	$post    = get_post( $id, ARRAY_A );
       
  1877 
       
  1878 	if ( 'attachment' != $post['post_type'] )
       
  1879 		wp_send_json_error();
       
  1880 
       
  1881 	if ( isset( $changes['title'] ) )
       
  1882 		$post['post_title'] = $changes['title'];
       
  1883 
       
  1884 	if ( isset( $changes['caption'] ) )
       
  1885 		$post['post_excerpt'] = $changes['caption'];
       
  1886 
       
  1887 	if ( isset( $changes['description'] ) )
       
  1888 		$post['post_content'] = $changes['description'];
       
  1889 
       
  1890 	if ( isset( $changes['alt'] ) ) {
       
  1891 		$alt = get_post_meta( $id, '_wp_attachment_image_alt', true );
       
  1892 		$new_alt = stripslashes( $changes['alt'] );
       
  1893 		if ( $alt != $new_alt ) {
       
  1894 			$new_alt = wp_strip_all_tags( $new_alt, true );
       
  1895 			update_post_meta( $id, '_wp_attachment_image_alt', addslashes( $new_alt ) );
       
  1896 		}
       
  1897 	}
       
  1898 
       
  1899 	wp_update_post( $post );
       
  1900 	wp_send_json_success();
       
  1901 }
       
  1902 
       
  1903 /**
       
  1904  * Save backwards compatible attachment attributes.
       
  1905  *
       
  1906  * @since 3.5.0
       
  1907  */
       
  1908 function wp_ajax_save_attachment_compat() {
       
  1909 	if ( ! isset( $_REQUEST['id'] ) )
       
  1910 		wp_send_json_error();
       
  1911 
       
  1912 	if ( ! $id = absint( $_REQUEST['id'] ) )
       
  1913 		wp_send_json_error();
       
  1914 
       
  1915 	if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) )
       
  1916 		wp_send_json_error();
       
  1917 	$attachment_data = $_REQUEST['attachments'][ $id ];
       
  1918 
       
  1919 	check_ajax_referer( 'update-post_' . $id, 'nonce' );
       
  1920 
       
  1921 	if ( ! current_user_can( 'edit_post', $id ) )
       
  1922 		wp_send_json_error();
       
  1923 
       
  1924 	$post = get_post( $id, ARRAY_A );
       
  1925 
       
  1926 	if ( 'attachment' != $post['post_type'] )
       
  1927 		wp_send_json_error();
       
  1928 
       
  1929 	$post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
       
  1930 
       
  1931 	if ( isset( $post['errors'] ) ) {
       
  1932 		$errors = $post['errors']; // @todo return me and display me!
       
  1933 		unset( $post['errors'] );
       
  1934 	}
       
  1935 
       
  1936 	wp_update_post( $post );
       
  1937 
       
  1938 	foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
       
  1939 		if ( isset( $attachment_data[ $taxonomy ] ) )
       
  1940 			wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
       
  1941 	}
       
  1942 
       
  1943 	if ( ! $attachment = wp_prepare_attachment_for_js( $id ) )
       
  1944 		wp_send_json_error();
       
  1945 
       
  1946 	wp_send_json_success( $attachment );
       
  1947 }
       
  1948 
       
  1949 function wp_ajax_save_attachment_order() {
       
  1950 	if ( ! isset( $_REQUEST['post_id'] ) )
       
  1951 		wp_send_json_error();
       
  1952 
       
  1953 	if ( ! $post_id = absint( $_REQUEST['post_id'] ) )
       
  1954 		wp_send_json_error();
       
  1955 
       
  1956 	if ( empty( $_REQUEST['attachments'] ) )
       
  1957 		wp_send_json_error();
       
  1958 
       
  1959 	check_ajax_referer( 'update-post_' . $post_id, 'nonce' );
       
  1960 
       
  1961 	$attachments = $_REQUEST['attachments'];
       
  1962 
       
  1963 	if ( ! current_user_can( 'edit_post', $post_id ) )
       
  1964 		wp_send_json_error();
       
  1965 
       
  1966 	$post = get_post( $post_id, ARRAY_A );
       
  1967 
       
  1968 	foreach ( $attachments as $attachment_id => $menu_order ) {
       
  1969 		if ( ! current_user_can( 'edit_post', $attachment_id ) )
       
  1970 			continue;
       
  1971 		if ( ! $attachment = get_post( $attachment_id ) )
       
  1972 			continue;
       
  1973 		if ( 'attachment' != $attachment->post_type )
       
  1974 			continue;
       
  1975 
       
  1976 		wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) );
       
  1977 	}
       
  1978 
       
  1979 	wp_send_json_success();
       
  1980 }
       
  1981 
       
  1982 /**
       
  1983  * Generates the HTML to send an attachment to the editor.
       
  1984  * Backwards compatible with the media_send_to_editor filter and the chain
       
  1985  * of filters that follow.
       
  1986  *
       
  1987  * @since 3.5.0
       
  1988  */
       
  1989 function wp_ajax_send_attachment_to_editor() {
       
  1990 	check_ajax_referer( 'media-send-to-editor', 'nonce' );
       
  1991 
       
  1992 	$attachment = stripslashes_deep( $_POST['attachment'] );
       
  1993 
       
  1994 	$id = intval( $attachment['id'] );
       
  1995 
       
  1996 	if ( ! $post = get_post( $id ) )
       
  1997 		wp_send_json_error();
       
  1998 
       
  1999 	if ( 'attachment' != $post->post_type )
       
  2000 		wp_send_json_error();
       
  2001 
       
  2002 	if ( current_user_can( 'edit_post', $id ) ) {
       
  2003 		// If this attachment is unattached, attach it. Primarily a back compat thing.
       
  2004 		if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) {
       
  2005 			wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) );
       
  2006 		}
       
  2007 	}
       
  2008 
       
  2009 	$rel = $url = '';
       
  2010 	$html = $title = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
       
  2011 	if ( ! empty( $attachment['url'] ) ) {
       
  2012 		$url = $attachment['url'];
       
  2013 		if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url )
       
  2014 			$rel = ' rel="attachment wp-att-' . $id . '"';
       
  2015 		$html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>';
       
  2016 	}
       
  2017 
       
  2018 	remove_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 );
       
  2019 
       
  2020 	if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
       
  2021 		$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
       
  2022 		$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
       
  2023 		$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
       
  2024 		$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
       
  2025 		$title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
       
  2026 		$html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt );
       
  2027 	}
       
  2028 
       
  2029 	$html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
       
  2030 
       
  2031 	wp_send_json_success( $html );
       
  2032 }
       
  2033 
       
  2034 /**
       
  2035  * Generates the HTML to send a non-image embed link to the editor.
       
  2036  *
       
  2037  * Backwards compatible with the following filters:
       
  2038  * - file_send_to_editor_url
       
  2039  * - audio_send_to_editor_url
       
  2040  * - video_send_to_editor_url
       
  2041  *
       
  2042  * @since 3.5.0
       
  2043  */
       
  2044 function wp_ajax_send_link_to_editor() {
       
  2045 	check_ajax_referer( 'media-send-to-editor', 'nonce' );
       
  2046 
       
  2047 	if ( ! $src = stripslashes( $_POST['src'] ) )
       
  2048 		wp_send_json_error();
       
  2049 
       
  2050 	if ( ! strpos( $src, '://' ) )
       
  2051 		$src = 'http://' . $src;
       
  2052 
       
  2053 	if ( ! $src = esc_url_raw( $src ) )
       
  2054 		wp_send_json_error();
       
  2055 
       
  2056 	if ( ! $title = trim( stripslashes( $_POST['title'] ) ) )
       
  2057 		$title = wp_basename( $src );
       
  2058 
       
  2059 	$html = '';
       
  2060 	if ( $title )
       
  2061 		$html = '<a href="' . esc_url( $src ) . '">' . $title . '</a>';
       
  2062 
       
  2063 	// Figure out what filter to run:
       
  2064 	$type = 'file';
       
  2065 	if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
       
  2066 		&& ( 'audio' == $ext_type || 'video' == $ext_type ) )
       
  2067 			$type = $ext_type;
       
  2068 
       
  2069 	$html = apply_filters( $type . '_send_to_editor_url', $html, $src, $title );
       
  2070 
       
  2071 	wp_send_json_success( $html );
       
  2072 }