check_comment_flood_db

Definition:
function check_comment_flood_db( $ip, $email, $date ) {}

Check whether comment flooding is occurring.
Won’t run, if current user can manage options, so to not block administrators.

Parameters

  • string $ip: Comment IP.
  • string $email: Comment author email address.
  • string $date: MySQL time string.

Defined filters

  • comment_flood_filter
    apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment)

Defined actions

  • comment_flood_trigger
    do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);

Source code

function check_comment_flood_db( $ip, $email, $date ) {

	global $wpdb;

	if ( current_user_can( 'manage_options' ) )

		return; // don't throttle admins

	$hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 );

	if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) {

		$time_lastcomment = mysql2date('U', $lasttime, false);

		$time_newcomment  = mysql2date('U', $date, false);

		$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);

		if ( $flood_die ) {

			do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);



			if ( defined('DOING_AJAX') )

				die( __('You are posting comments too quickly.  Slow down.') );



			wp_die( __('You are posting comments too quickly.  Slow down.'), '', array('response' => 403) );

		}

	}

}

603

check_comment

Definition:
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {}

Checks whether a comment passes internal checks to be allowed to add.
If comment moderation is set in the administration, then all comments, regardless of their type and whitelist will be set to false. If the number of links exceeds the amount in the administration, then the check fails. If any of the parameter contents match the blacklist of words, then the check fails.

Parameters

  • string $author: Comment Author’s name
  • string $email: Comment Author’s email
  • string $url: Comment Author’s URL
  • string $comment: Comment contents
  • string $user_ip: Comment Author’s IP address
  • string $user_agent: Comment Author’s User Agent
  • string $comment_type: Comment type, either user submitted comment, trackback, or pingback

Return values

returns:Whether the checks passed (true) and the comments should be displayed or set to moderated

Defined filters

  • comment_text
    apply_filters( 'comment_text', $comment )
  • comment_max_links_url
    apply_filters( 'comment_max_links_url', $num_links, $url )

Source code

function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {

	global $wpdb;



	if ( 1 == get_option('comment_moderation') )

		return false; // If moderation is set to manual



	$comment = apply_filters( 'comment_text', $comment );



	// Check # of external links

	if ( $max_links = get_option( 'comment_max_links' ) ) {

		$num_links = preg_match_all( '/<a [^>]*href/i', $comment, $out );

		$num_links = apply_filters( 'comment_max_links_url', $num_links, $url ); // provide for counting of $url as a link

		if ( $num_links >= $max_links )

			return false;

	}



	$mod_keys = trim(get_option('moderation_keys'));

	if ( !empty($mod_keys) ) {

		$words = explode("\n", $mod_keys );



		foreach ( (array) $words as $word) {

			$word = trim($word);



			// Skip empty lines

			if ( empty($word) )

				continue;



			// Do some escaping magic so that '#' chars in the

			// spam words don't break things:

			$word = preg_quote($word, '#');



			$pattern = "#$word#i";

			if ( preg_match($pattern, $author) ) return false;

			if ( preg_match($pattern, $email) ) return false;

			if ( preg_match($pattern, $url) ) return false;

			if ( preg_match($pattern, $comment) ) return false;

			if ( preg_match($pattern, $user_ip) ) return false;

			if ( preg_match($pattern, $user_agent) ) return false;

		}

	}



	// Comment whitelisting:

	if ( 1 == get_option('comment_whitelist')) {

		if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {

			// expected_slashed ($author, $email)

			$ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1");

			if ( ( 1 == $ok_to_comment ) &&

				( empty($mod_keys) || false === strpos( $email, $mod_keys) ) )

					return true;

			else

				return false;

		} else {

			return false;

		}

	}

	return true;

}

601

check_column

Definition:
function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {}

Check column matches criteria.
Uses the SQL DESC for retrieving the table info for the column. It will help understand the parameters, if you do more research on what column information is returned by the SQL statement. Pass in null to skip checking that criteria.

Parameters

  • string $table_name: Table name
  • string $col_name: Column name
  • string $col_type: Column type
  • bool $is_null: Optional. Check is null.
  • mixed $key: Optional. Key info.
  • mixed $default: Optional. Default value.
  • mixed $extra: Optional. Extra value.

Return values

returns:True, if matches. False, if not matching.

Source code

function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {

	global $wpdb, $debug;

	$diffs = 0;

	$results = $wpdb->get_results("DESC $table_name");



	foreach ($results as $row ) {

		if ($debug > 1) print_r($row);



		if ($row->Field == $col_name) {

			// got our column, check the params

			if ($debug) echo ("checking $row->Type against $col_type\n");

			if (($col_type != null) && ($row->Type != $col_type)) {

				++$diffs;

			}

			if (($is_null != null) && ($row->Null != $is_null)) {

				++$diffs;

			}

			if (($key != null) && ($row->Key  != $key)) {

				++$diffs;

			}

			if (($default != null) && ($row->Default != $default)) {

				++$diffs;

			}

			if (($extra != null) && ($row->Extra != $extra)) {

				++$diffs;

			}

			if ($diffs > 0) {

				if ($debug) echo ("diffs = $diffs returning false\n");

				return false;

			}

			return true;

		} // end if found our column

	}

	return false;

}

599

check_and_publish_future_post

Definition:
function check_and_publish_future_post($post_id) {}

Publish future post and make sure post ID has future post status.
Invoked by cron ‘publish_future_post’ event. This safeguard prevents cron from publishing drafts, etc.

Parameters

  • int $post_id: Post ID.

Return values

returns:Nothing is returned. Which can mean that no action is required or post was published.

Source code

function check_and_publish_future_post($post_id) {



	$post = get_post($post_id);



	if ( empty($post) )

		return;



	if ( 'future' != $post->post_status )

		return;



	$time = strtotime( $post->post_date_gmt . ' GMT' );



	if ( $time > time() ) { // Uh oh, someone jumped the gun!

		wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system

		wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) );

		return;

	}



	return wp_publish_post($post_id);

}

597

check_ajax_referer

Definition:
function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {}

Verifies the AJAX request to prevent processing requests external of the blog.

Parameters

  • string $action: Action nonce
  • string $query_arg: where to look for nonce in $_REQUEST (since 2.5)
  • $die

Defined actions

  • check_ajax_referer
    do_action('check_ajax_referer', $action, $result);

Source code

function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {

	if ( $query_arg )

		$nonce = $_REQUEST[$query_arg];

	else

		$nonce = isset($_REQUEST['_ajax_nonce']) ? $_REQUEST['_ajax_nonce'] : $_REQUEST['_wpnonce'];



	$result = wp_verify_nonce( $nonce, $action );



	if ( $die && false == $result )

		die('-1');



	do_action('check_ajax_referer', $action, $result);



	return $result;

}

595