mirror of
https://github.com/WordPress/WordPress.git
synced 2024-08-26 15:53:08 +02:00
The exceptions to this are update_post_meta() and add_post_meta() which are often used by plugins in POST handlers and will continue accepting slashed data for now. Introduce wp_upate_post_meta() and wp_add_post_meta() as unslashed alternatives to update_post_meta() and add_post_meta(). These functions could become methods in WP_Post so don't use them too heavily yet. Remove all escape() calls from wp_xmlrpc_server. Now that core expects unslashed data this is no longer needed. Remove addslashes(), addslashes_gpc(), add_magic_quotes() calls on data being prepared for handoff to core functions that until now expected slashed data. Adding slashes in no longer necessary. Introduce wp_unslash() and use to it remove slashes from GPCS data before using it in core API. Almost every instance of stripslashes() in core should now be wp_unslash(). In the future (a release or three) when GPCS is no longer slashed, wp_unslash() will stop stripping slashes and simply return what is passed. At this point wp_unslash() calls can be removed from core. Introduce wp_slash() for slashing GPCS data. This will also turn into a noop once GPCS is no longer slashed. wp_slash() should almost never be used. It is mainly of use in unit tests. Plugins should use wp_unslash() on data being passed to core API. Plugins should no longer slash data being passed to core. So when you get_post() and then wp_insert_post() the post data from get_post() no longer needs addslashes(). Most plugins were not bothering with this. They will magically start doing the right thing. Unfortunately, those few souls who did it properly will now have to avoid calling addslashes() for 3.6 and newer. Use wp_kses_post() and wp_kses_data(), which expect unslashed data, instead of wp_filter_post_kses() and wp_filter_kses(), which expect slashed data. Filters are no longer passed slashed data. Remove many no longer necessary calls to $wpdb->escape() and esc_sql(). In wp_get_referer() and wp_get_original_referer(), return unslashed data. Remove old stripslashes() calls from WP_Widget::update() handlers. These haven't been necessary since WP_Widget. Switch several queries over to prepare(). Expect something to break. Props alexkingorg see #21767 git-svn-id: http://core.svn.wordpress.org/trunk@23416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
102 lines
3.5 KiB
PHP
102 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Handles Comment Post to WordPress and prevents duplicate comment posting.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
|
|
header('Allow: POST');
|
|
header('HTTP/1.1 405 Method Not Allowed');
|
|
header('Content-Type: text/plain');
|
|
exit;
|
|
}
|
|
|
|
/** Sets up the WordPress Environment. */
|
|
require( dirname(__FILE__) . '/wp-load.php' );
|
|
|
|
nocache_headers();
|
|
|
|
$post_data = wp_unslash( $_POST );
|
|
|
|
$comment_post_ID = isset($post_data['comment_post_ID']) ? (int) $post_data['comment_post_ID'] : 0;
|
|
|
|
$post = get_post($comment_post_ID);
|
|
|
|
if ( empty($post->comment_status) ) {
|
|
do_action('comment_id_not_found', $comment_post_ID);
|
|
exit;
|
|
}
|
|
|
|
// get_post_status() will get the parent status for attachments.
|
|
$status = get_post_status($post);
|
|
|
|
$status_obj = get_post_status_object($status);
|
|
|
|
if ( !comments_open($comment_post_ID) ) {
|
|
do_action('comment_closed', $comment_post_ID);
|
|
wp_die( __('Sorry, comments are closed for this item.') );
|
|
} elseif ( 'trash' == $status ) {
|
|
do_action('comment_on_trash', $comment_post_ID);
|
|
exit;
|
|
} elseif ( !$status_obj->public && !$status_obj->private ) {
|
|
do_action('comment_on_draft', $comment_post_ID);
|
|
exit;
|
|
} elseif ( post_password_required($comment_post_ID) ) {
|
|
do_action('comment_on_password_protected', $comment_post_ID);
|
|
exit;
|
|
} else {
|
|
do_action('pre_comment_on_post', $comment_post_ID);
|
|
}
|
|
|
|
$comment_author = ( isset( $post_data['author'] ) ) ? trim( strip_tags( $post_data['author'] ) ) : null;
|
|
$comment_author_email = ( isset( $post_data['email'] ) ) ? trim( $post_data['email'] ) : null;
|
|
$comment_author_url = ( isset( $post_data['url'] ) ) ? trim( $post_data['url'] ) : null;
|
|
$comment_content = ( isset( $post_data['comment'] ) ) ? trim( $post_data['comment'] ) : null;
|
|
|
|
// If the user is logged in
|
|
$user = wp_get_current_user();
|
|
if ( $user->exists() ) {
|
|
if ( empty( $user->display_name ) )
|
|
$user->display_name = $user->user_login;
|
|
$comment_author = $user->display_name;
|
|
$comment_author_email = $user->user_email;
|
|
$comment_author_url = $user->user_url;
|
|
if ( current_user_can('unfiltered_html') ) {
|
|
if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $post_data['_wp_unfiltered_html_comment'] ) {
|
|
kses_remove_filters(); // start with a clean slate
|
|
kses_init_filters(); // set up the filters
|
|
}
|
|
}
|
|
} else {
|
|
if ( get_option('comment_registration') || 'private' == $status )
|
|
wp_die( __('Sorry, you must be logged in to post a comment.') );
|
|
}
|
|
|
|
$comment_type = '';
|
|
|
|
if ( get_option('require_name_email') && !$user->exists() ) {
|
|
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
|
|
wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
|
|
elseif ( !is_email($comment_author_email))
|
|
wp_die( __('<strong>ERROR</strong>: please enter a valid email address.') );
|
|
}
|
|
|
|
if ( '' == $comment_content )
|
|
wp_die( __('<strong>ERROR</strong>: please type a comment.') );
|
|
|
|
$comment_parent = isset($post_data['comment_parent']) ? absint($post_data['comment_parent']) : 0;
|
|
|
|
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
|
|
|
|
$comment_id = wp_new_comment( $commentdata );
|
|
|
|
$comment = get_comment($comment_id);
|
|
do_action('set_comment_cookies', $comment, $user);
|
|
|
|
$location = empty($post_data['redirect_to']) ? get_comment_link($comment_id) : $post_data['redirect_to'] . '#comment-' . $comment_id;
|
|
$location = apply_filters('comment_post_redirect', $location, $comment);
|
|
|
|
wp_safe_redirect( $location );
|
|
exit;
|