wp/wp-admin/includes/comment.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    19  * @global wpdb $wpdb WordPress database abstraction object.
    19  * @global wpdb $wpdb WordPress database abstraction object.
    20  *
    20  *
    21  * @param string $comment_author Author of the comment.
    21  * @param string $comment_author Author of the comment.
    22  * @param string $comment_date   Date of the comment.
    22  * @param string $comment_date   Date of the comment.
    23  * @param string $timezone       Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
    23  * @param string $timezone       Timezone. Accepts 'blog' or 'gmt'. Default 'blog'.
    24  *
    24  * @return string|null Comment post ID on success.
    25  * @return mixed Comment post ID on success.
       
    26  */
    25  */
    27 function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
    26 function comment_exists( $comment_author, $comment_date, $timezone = 'blog' ) {
    28 	global $wpdb;
    27 	global $wpdb;
    29 
    28 
    30 	$date_field = 'comment_date';
    29 	$date_field = 'comment_date';
    44 
    43 
    45 /**
    44 /**
    46  * Update a comment with values provided in $_POST.
    45  * Update a comment with values provided in $_POST.
    47  *
    46  *
    48  * @since 2.0.0
    47  * @since 2.0.0
       
    48  * @since 5.5.0 A return value was added.
       
    49  *
       
    50  * @return int|WP_Error The value 1 if the comment was updated, 0 if not updated.
       
    51  *                      A WP_Error object on failure.
    49  */
    52  */
    50 function edit_comment() {
    53 function edit_comment() {
    51 	if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
    54 	if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
    52 		wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
    55 		wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
    53 	}
    56 	}
    77 			break;
    80 			break;
    78 		}
    81 		}
    79 	}
    82 	}
    80 
    83 
    81 	if ( ! empty( $_POST['edit_date'] ) ) {
    84 	if ( ! empty( $_POST['edit_date'] ) ) {
    82 		$aa                    = $_POST['aa'];
    85 		$aa = $_POST['aa'];
    83 		$mm                    = $_POST['mm'];
    86 		$mm = $_POST['mm'];
    84 		$jj                    = $_POST['jj'];
    87 		$jj = $_POST['jj'];
    85 		$hh                    = $_POST['hh'];
    88 		$hh = $_POST['hh'];
    86 		$mn                    = $_POST['mn'];
    89 		$mn = $_POST['mn'];
    87 		$ss                    = $_POST['ss'];
    90 		$ss = $_POST['ss'];
    88 		$jj                    = ( $jj > 31 ) ? 31 : $jj;
    91 		$jj = ( $jj > 31 ) ? 31 : $jj;
    89 		$hh                    = ( $hh > 23 ) ? $hh - 24 : $hh;
    92 		$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
    90 		$mn                    = ( $mn > 59 ) ? $mn - 60 : $mn;
    93 		$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
    91 		$ss                    = ( $ss > 59 ) ? $ss - 60 : $ss;
    94 		$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
       
    95 
    92 		$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    96 		$_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    93 	}
    97 	}
    94 
    98 
    95 	wp_update_comment( $_POST );
    99 	return wp_update_comment( $_POST, true );
    96 }
   100 }
    97 
   101 
    98 /**
   102 /**
    99  * Returns a WP_Comment object based on comment ID.
   103  * Returns a WP_Comment object based on comment ID.
   100  *
   104  *
   102  *
   106  *
   103  * @param int $id ID of comment to retrieve.
   107  * @param int $id ID of comment to retrieve.
   104  * @return WP_Comment|false Comment if found. False on failure.
   108  * @return WP_Comment|false Comment if found. False on failure.
   105  */
   109  */
   106 function get_comment_to_edit( $id ) {
   110 function get_comment_to_edit( $id ) {
   107 	if ( ! $comment = get_comment( $id ) ) {
   111 	$comment = get_comment( $id );
       
   112 	if ( ! $comment ) {
   108 		return false;
   113 		return false;
   109 	}
   114 	}
   110 
   115 
   111 	$comment->comment_ID      = (int) $comment->comment_ID;
   116 	$comment->comment_ID      = (int) $comment->comment_ID;
   112 	$comment->comment_post_ID = (int) $comment->comment_post_ID;
   117 	$comment->comment_post_ID = (int) $comment->comment_post_ID;
   115 	/**
   120 	/**
   116 	 * Filters the comment content before editing.
   121 	 * Filters the comment content before editing.
   117 	 *
   122 	 *
   118 	 * @since 2.0.0
   123 	 * @since 2.0.0
   119 	 *
   124 	 *
   120 	 * @param string $comment->comment_content Comment content.
   125 	 * @param string $comment_content Comment content.
   121 	 */
   126 	 */
   122 	$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
   127 	$comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
   123 
   128 
   124 	$comment->comment_author       = format_to_edit( $comment->comment_author );
   129 	$comment->comment_author       = format_to_edit( $comment->comment_author );
   125 	$comment->comment_author_email = format_to_edit( $comment->comment_author_email );
   130 	$comment->comment_author_email = format_to_edit( $comment->comment_author_email );
   162 		}
   167 		}
   163 	}
   168 	}
   164 
   169 
   165 	$pending_keyed = array();
   170 	$pending_keyed = array();
   166 
   171 
   167 	// Default to zero pending for all posts in request
   172 	// Default to zero pending for all posts in request.
   168 	foreach ( $post_id_array as $id ) {
   173 	foreach ( $post_id_array as $id ) {
   169 		$pending_keyed[ $id ] = 0;
   174 		$pending_keyed[ $id ] = 0;
   170 	}
   175 	}
   171 
   176 
   172 	if ( ! empty( $pending ) ) {
   177 	if ( ! empty( $pending ) ) {
   177 
   182 
   178 	return $pending_keyed;
   183 	return $pending_keyed;
   179 }
   184 }
   180 
   185 
   181 /**
   186 /**
   182  * Add avatars to relevant places in admin, or try to.
   187  * Adds avatars to relevant places in admin.
   183  *
   188  *
   184  * @since 2.5.0
   189  * @since 2.5.0
   185  *
   190  *
   186  * @param string $name User name.
   191  * @param string $name User name.
   187  * @return string Avatar with Admin name.
   192  * @return string Avatar with the user name.
   188  */
   193  */
   189 function floated_admin_avatar( $name ) {
   194 function floated_admin_avatar( $name ) {
   190 	$avatar = get_avatar( get_comment(), 32, 'mystery' );
   195 	$avatar = get_avatar( get_comment(), 32, 'mystery' );
   191 	return "$avatar $name";
   196 	return "$avatar $name";
   192 }
   197 }
   193 
   198 
   194 /**
   199 /**
   195  * @since 2.7.0
   200  * @since 2.7.0
   196  */
   201  */
   197 function enqueue_comment_hotkeys_js() {
   202 function enqueue_comment_hotkeys_js() {
   198 	if ( 'true' == get_user_option( 'comment_shortcuts' ) ) {
   203 	if ( 'true' === get_user_option( 'comment_shortcuts' ) ) {
   199 		wp_enqueue_script( 'jquery-table-hotkeys' );
   204 		wp_enqueue_script( 'jquery-table-hotkeys' );
   200 	}
   205 	}
   201 }
   206 }
   202 
   207 
   203 /**
   208 /**
   205  *
   210  *
   206  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
   211  * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
   207  */
   212  */
   208 function comment_footer_die( $msg ) {
   213 function comment_footer_die( $msg ) {
   209 	echo "<div class='wrap'><p>$msg</p></div>";
   214 	echo "<div class='wrap'><p>$msg</p></div>";
   210 	include( ABSPATH . 'wp-admin/admin-footer.php' );
   215 	require_once ABSPATH . 'wp-admin/admin-footer.php';
   211 	die;
   216 	die;
   212 }
   217 }