X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a6f44f0edcda2471c5a33e4156c1c9488c7f3210..refs/tags/wordpress-3.7:/wp-admin/includes/ajax-actions.php?ds=sidebyside diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 734409fe..e6c28344 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -26,12 +26,39 @@ function wp_ajax_nopriv_heartbeat() { if ( ! empty($_POST['data']) ) { $data = wp_unslash( (array) $_POST['data'] ); + + /** + * Filter Heartbeat AJAX response in no-privilege environments. + * + * @since 3.6.0 + * + * @param array|object $response The no-priv Heartbeat response object or array. + * @param array $data An array of data passed via $_POST. + * @param string $screen_id The screen id. + */ $response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id ); } + /** + * Filter Heartbeat AJAX response when no data is passed. + * + * @since 3.6.0 + * + * @param array|object $response The Heartbeat response object or array. + * @param string $screen_id The screen id. + */ $response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id ); - // Allow the transport to be replaced with long-polling easily + /** + * Fires when Heartbeat ticks in no-privilege environments. + * + * Allows the transport to be easily replaced with long-polling. + * + * @since 3.6.0 + * + * @param array|object $response The no-priv Heartbeat response. + * @param string $screen_id The screen id. + */ do_action( 'heartbeat_nopriv_tick', $response, $screen_id ); // send the current time according to the server @@ -87,7 +114,7 @@ function wp_ajax_ajax_tag_search() { if ( strlen( $s ) < 2 ) wp_die(); // require 2 chars for matching - $results = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.name LIKE (%s)", $taxonomy, '%' . like_escape( $s ) . '%' ) ); + $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) ); echo join( $results, "\n" ); wp_die(); @@ -163,6 +190,7 @@ function wp_ajax_autocomplete_user() { if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) wp_die( -1 ); + /** This filter is documented in wp-admin/user-new.php */ if ( ! is_super_admin() && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) wp_die( -1 ); @@ -241,10 +269,11 @@ function wp_ajax_logged_in() { * @return die */ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) { - $total = (int) @$_POST['_total']; - $per_page = (int) @$_POST['_per_page']; - $page = (int) @$_POST['_page']; - $url = esc_url_raw( @$_POST['_url'] ); + $total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0; + $per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0; + $page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0; + $url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : ''; + // JS didn't send us everything we need to know. Just die with success message if ( !$total || !$per_page || !$page || !$url ) wp_die( time() ); @@ -546,7 +575,7 @@ function wp_ajax_dim_comment() { wp_die( -1 ); $current = wp_get_comment_status( $comment->comment_ID ); - if ( $_POST['new'] == $current ) + if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) wp_die( time() ); check_ajax_referer( "approve-comment_$id" ); @@ -694,9 +723,18 @@ function wp_ajax_get_comments( $action ) { check_ajax_referer( $action ); + if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) { + $id = absint( $_REQUEST['p'] ); + if ( ! empty( $id ) ) + $post_id = $id; + } + + if ( empty( $post_id ) ) + wp_die( -1 ); + $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); - if ( !current_user_can( 'edit_post', $post_id ) ) + if ( ! current_user_can( 'edit_post', $post_id ) ) wp_die( -1 ); $wp_list_table->prepare_items(); @@ -750,6 +788,9 @@ function wp_ajax_replyto_comment( $action ) { $comment_author_url = wp_slash( $user->user_url ); $comment_content = trim($_POST['content']); if ( current_user_can( 'unfiltered_html' ) ) { + if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) + $_POST['_wp_unfiltered_html_comment'] = ''; + if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) { kses_remove_filters(); // start with a clean slate kses_init_filters(); // set up the filters @@ -762,7 +803,9 @@ function wp_ajax_replyto_comment( $action ) { if ( '' == $comment_content ) wp_die( __( 'ERROR: please type a comment.' ) ); - $comment_parent = absint($_POST['comment_ID']); + $comment_parent = 0; + if ( isset( $_POST['comment_ID'] ) ) + $comment_parent = absint( $_POST['comment_ID'] ); $comment_auto_approved = false; $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID'); @@ -783,19 +826,18 @@ function wp_ajax_replyto_comment( $action ) { $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; ob_start(); - if ( 'dashboard' == $_REQUEST['mode'] ) { - require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); - _wp_dashboard_recent_comments_row( $comment ); + if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) { + require_once( ABSPATH . 'wp-admin/includes/dashboard.php' ); + _wp_dashboard_recent_comments_row( $comment ); + } else { + if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) { + $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); } else { - if ( 'single' == $_REQUEST['mode'] ) { - $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); - } else { - $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); - } - $wp_list_table->single_row( $comment ); + $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); } - $comment_list_item = ob_get_contents(); - ob_end_clean(); + $wp_list_table->single_row( $comment ); + } + $comment_list_item = ob_get_clean(); $response = array( 'what' => 'comment', @@ -824,7 +866,8 @@ function wp_ajax_edit_comment() { if ( '' == $_POST['content'] ) wp_die( __( 'ERROR: please type a comment.' ) ); - $_POST['comment_status'] = $_POST['status']; + if ( isset( $_POST['status'] ) ) + $_POST['comment_status'] = $_POST['status']; edit_comment(); $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1'; @@ -834,11 +877,12 @@ function wp_ajax_edit_comment() { $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); $comment = get_comment( $comment_id ); + if ( empty( $comment->comment_ID ) ) + wp_die( -1 ); ob_start(); - $wp_list_table->single_row( $comment ); - $comment_list_item = ob_get_contents(); - ob_end_clean(); + $wp_list_table->single_row( $comment ); + $comment_list_item = ob_get_clean(); $x = new WP_Ajax_Response(); @@ -905,6 +949,14 @@ function wp_ajax_add_menu_item() { } } + /** + * Filter the Walker class used when adding nav menu items. + * + * @since 3.4.0 + * + * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. + * @param int $menu_id The menu id, derived from $_POST['menu']. + */ $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] ); if ( ! class_exists( $walker_class_name ) ) @@ -1046,9 +1098,10 @@ function wp_ajax_autosave() { check_ajax_referer( 'autosave', 'autosavenonce' ); - $_POST['post_category'] = explode(",", $_POST['catslist']); - if ( $_POST['post_type'] == 'page' || empty($_POST['post_category']) ) - unset($_POST['post_category']); + if ( ! empty( $_POST['catslist'] ) ) + $_POST['post_category'] = explode( ',', $_POST['catslist'] ); + if ( $_POST['post_type'] == 'page' || empty( $_POST['post_category'] ) ) + unset( $_POST['post_category'] ); $data = ''; $supplemental = array(); @@ -1056,18 +1109,16 @@ function wp_ajax_autosave() { $post_id = (int) $_POST['post_id']; $_POST['ID'] = $_POST['post_ID'] = $post_id; - $post = get_post($post_id); + $post = get_post( $post_id ); + if ( empty( $post->ID ) || ! current_user_can( 'edit_post', $post->ID ) ) + wp_die( __( 'You are not allowed to edit this post.' ) ); + + if ( 'page' == $post->post_type && ! current_user_can( 'edit_page', $post->ID ) ) + wp_die( __( 'You are not allowed to edit this page.' ) ); + if ( 'auto-draft' == $post->post_status ) $_POST['post_status'] = 'draft'; - if ( 'page' == $post->post_type ) { - if ( !current_user_can('edit_page', $post->ID) ) - wp_die( __( 'You are not allowed to edit this page.' ) ); - } else { - if ( !current_user_can('edit_post', $post->ID) ) - wp_die( __( 'You are not allowed to edit this post.' ) ); - } - if ( ! empty( $_POST['autosave'] ) ) { if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked @@ -1177,7 +1228,15 @@ function wp_ajax_menu_get_metabox() { } if ( ! empty( $_POST['item-object'] ) && isset( $items[$_POST['item-object']] ) ) { - $item = apply_filters( 'nav_menu_meta_box_object', $items[ $_POST['item-object'] ] ); + $menus_meta_box_object = $items[ $_POST['item-object'] ]; + /** + * Filter a nav menu meta box object. + * + * @since 3.0.0 + * + * @param object $menus_meta_box_object A nav menu meta box object, such as Page, Post, Category, Tag, etc. + */ + $item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object ); ob_start(); call_user_func_array($callback, array( null, @@ -1313,7 +1372,7 @@ function wp_ajax_inline_save() { $data['excerpt'] = $post['post_excerpt']; // rename - $data['user_ID'] = $GLOBALS['user_ID']; + $data['user_ID'] = get_current_user_id(); if ( isset($data['post_parent']) ) $data['parent_id'] = $data['post_parent']; @@ -1506,9 +1565,26 @@ function wp_ajax_save_widget() { unset( $_POST['savewidgets'], $_POST['action'] ); - do_action('load-widgets.php'); - do_action('widgets.php'); - do_action('sidebar_admin_setup'); + /** + * Fires early when editing the widgets displayed in sidebars. + * + * @since 2.8.0 + */ + do_action( 'load-widgets.php' ); + + /** + * Fires early when editing the widgets displayed in sidebars. + * + * @since 2.8.0 + */ + do_action( 'widgets.php' ); + + /** + * Fires early when editing the widgets displayed in sidebars. + * + * @since 2.2.0 + */ + do_action( 'sidebar_admin_setup' ); $id_base = $_POST['id_base']; $widget_id = $_POST['widget-id']; @@ -1762,6 +1838,13 @@ function wp_ajax_wp_remove_post_lock() { if ( $active_lock[1] != get_current_user_id() ) wp_die( 0 ); + /** + * Filter the post lock window duration. + * + * @since 3.3.0 + * + * @param int $interval The interval in seconds the post lock duration should last, plus 5 seconds. Default 120. + */ $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5 ) . ':' . $active_lock[1]; update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); wp_die( 1 ); @@ -1833,6 +1916,14 @@ function wp_ajax_query_attachments() { if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) $query['post_status'] .= ',private'; + /** + * Filter the arguments passed to WP_Query during an AJAX call for querying attachments. + * + * @since 3.7.0 + * + * @param array $query An array of query variables. @see WP_Query::parse_query() + */ + $query = apply_filters( 'ajax_query_attachments_args', $query ); $query = new WP_Query( $query ); $posts = array_map( 'wp_prepare_attachment_for_js', $query->posts ); @@ -1911,6 +2002,7 @@ function wp_ajax_save_attachment_compat() { if ( 'attachment' != $post['post_type'] ) wp_send_json_error(); + /** This filter is documented in wp-admin/includes/media.php */ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); if ( isset( $post['errors'] ) ) { @@ -2013,6 +2105,7 @@ function wp_ajax_send_attachment_to_editor() { $html = stripslashes_deep( $_POST['html'] ); } + /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment ); wp_send_json_success( $html ); @@ -2053,6 +2146,7 @@ function wp_ajax_send_link_to_editor() { && ( 'audio' == $ext_type || 'video' == $ext_type ) ) $type = $ext_type; + /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( $type . '_send_to_editor_url', $html, $src, $title ); wp_send_json_success( $html ); @@ -2083,12 +2177,39 @@ function wp_ajax_heartbeat() { if ( ! empty($_POST['data']) ) { $data = (array) $_POST['data']; + + /** + * Filter the Heartbeat response received. + * + * @since 3.6.0 + * + * @param array|object $response The Heartbeat response object or array. + * @param array $data The $_POST data sent. + * @param string $screen_id The screen id. + */ $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id ); } + /** + * Filter the Heartbeat response sent. + * + * @since 3.6.0 + * + * @param array|object $response The Heartbeat response object or array. + * @param string $screen_id The screen id. + */ $response = apply_filters( 'heartbeat_send', $response, $screen_id ); - // Allow the transport to be replaced with long-polling easily + /** + * Fires when Heartbeat ticks in logged-in environments. + * + * Allows the transport to be easily replaced with long-polling. + * + * @since 3.6.0 + * + * @param array|object $response The Heartbeat response object or array. + * @param string $screen_id The screen id. + */ do_action( 'heartbeat_tick', $response, $screen_id ); // Send the current time according to the server