wp_nonce_field

Definition:
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {}

Retrieve or display nonce hidden field for forms.
The nonce field is used to validate that the contents of the form came from the location on the current site and not somewhere else. The nonce does not offer absolute protection, but should protect against most cases. It is very important to use nonce field in forms.

Parameters

  • string $action: Optional. Action name.
  • string $name: Optional. Nonce name.
  • bool $referer: Optional, default true. Whether to set the referer field for validation.
  • bool $echo: Optional, default true. Whether to display or return hidden form field.

Return values

returns:Nonce field.

Source code

function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) {

	$name = esc_attr( $name );

	$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';



	if ( $referer )

		$nonce_field .= wp_referer_field( false );



	if ( $echo )

		echo $nonce_field;



	return $nonce_field;

}

3949

wp_nonce_ays

Definition:
function wp_nonce_ays( $action ) {}

Display "Are You Sure" message to confirm the action being taken.
If the action has the nonce explain message, then it will be displayed along with the "Are you sure?" message.

Parameters

  • string $action: The nonce action.

Source code

function wp_nonce_ays( $action ) {

	$title = __( 'WordPress Failure Notice' );

	$html = esc_html( wp_explain_nonce( $action ) );

	if ( 'log-out' == $action )

		$html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() );

	elseif ( wp_get_referer() )

		$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";



	wp_die( $html, $title, array('response' => 403) );

}

3947

wp_next_scheduled

Definition:
function wp_next_scheduled( $hook, $args = array() {}

Retrieve the next timestamp for a cron event.

Parameters

  • string $hook: Action hook to execute when cron is run.
  • array $args: Optional. Arguments to pass to the hook’s callback function.

Return values

returns:The UNIX timestamp of the next time the scheduled event will occur.

Source code

function wp_next_scheduled( $hook, $args = array() ) {

	$crons = _get_cron_array();

	$key = md5(serialize($args));

	if ( empty($crons) )

		return false;

	foreach ( $crons as $timestamp => $cron ) {

		if ( isset( $cron[$hook][$key] ) )

			return $timestamp;

	}

	return false;

}

3945

wp_new_user_notification

Definition:
function wp_new_user_notification($user_id, $plaintext_pass = '') {}

Notify the blog admin of a new user, normally via email.

Parameters

  • int $user_id: User ID
  • string $plaintext_pass: Optional. The user’s plaintext password

Source code

function wp_new_user_notification($user_id, $plaintext_pass = '') {

	$user = new WP_User($user_id);



	$user_login = stripslashes($user->user_login);

	$user_email = stripslashes($user->user_email);



	// The blogname option is escaped with esc_html on the way into the database in sanitize_option

	// we want to reverse this for the plain text arena of emails.

	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);



	$message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";

	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";

	$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";



	@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);



	if ( empty($plaintext_pass) )

		return;



	$message  = sprintf(__('Username: %s'), $user_login) . "\r\n";

	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";

	$message .= wp_login_url() . "\r\n";



	wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);



}

3943

wp_new_comment

Definition:
function wp_new_comment( $commentdata ) {}

Adds a new comment to the database.
Filters new comment to ensure that the fields are sanitized and valid before inserting comment into database. Calls ‘comment_post’ action with comment ID and whether comment is approved by WordPress. Also has ‘preprocess_comment’ filter for processing the comment data before the function handles it.

Parameters

  • array $commentdata: Contains information on the comment.

Return values

returns:The ID of the comment after adding.

Defined filters

  • preprocess_comment
    apply_filters('preprocess_comment', $commentdata)

Defined actions

  • comment_post
    do_action('comment_post', $comment_ID, $commentdata['comment_approved']);

Source code

function wp_new_comment( $commentdata ) {

	$commentdata = apply_filters('preprocess_comment', $commentdata);



	$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];

	if ( isset($commentdata['user_ID']) )

		$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];

	elseif ( isset($commentdata['user_id']) )

		$commentdata['user_id'] = (int) $commentdata['user_id'];



	$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;

	$parent_status = ( 0 < $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';

	$commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;



	$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );

	$commentdata['comment_agent']     = substr($_SERVER['HTTP_USER_AGENT'], 0, 254);



	$commentdata['comment_date']     = current_time('mysql');

	$commentdata['comment_date_gmt'] = current_time('mysql', 1);



	$commentdata = wp_filter_comment($commentdata);



	$commentdata['comment_approved'] = wp_allow_comment($commentdata);



	$comment_ID = wp_insert_comment($commentdata);



	do_action('comment_post', $comment_ID, $commentdata['comment_approved']);



	if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching

		if ( '0' == $commentdata['comment_approved'] )

			wp_notify_moderator($comment_ID);



		$post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment



		if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )

			wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );

	}



	return $comment_ID;

}

3941