wp_count_comments

Definition:
function wp_count_comments( $post_id = 0 ) {}

Retrieve total comments for blog or single post.
The properties of the returned object contain the ‘moderated’, ‘approved’, and spam comments for either the entire blog or single post. Those properties contain the amount of comments that match the status. The ‘total_comments’ property contains the integer of total comments.

Parameters

  • int $post_id: Optional. Post ID.

Return values

returns:stats.

Defined filters

  • wp_count_comments
    apply_filters('wp_count_comments', array()

Source code

function wp_count_comments( $post_id = 0 ) {

	global $wpdb;



	$post_id = (int) $post_id;



	$stats = apply_filters('wp_count_comments', array(), $post_id);

	if ( !empty($stats) )

		return $stats;



	$count = wp_cache_get("comments-{$post_id}", 'counts');

3499

wp_count_attachments

Definition:
function wp_count_attachments( $mime_type = '' ) {}

Count number of attachments for the mime type(s).
If you set the optional mime_type parameter, then an array will still be returned, but will only have the item you are looking for. It does not give you the number of attachments that are children of a post. You can get that by counting the number of children that post has.

Parameters

  • string|array $mime_type: Optional. Array or comma-separated list of MIME patterns.

Return values

returns:Number of posts for each mime type.

Source code

function wp_count_attachments( $mime_type = '' ) {

	global $wpdb;



	$and = wp_post_mime_type_where( $mime_type );

	$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );



	$stats = array( );

	foreach( (array) $count as $row ) {

		$stats[$row['post_mime_type']] = $row['num_posts'];

	}

	$stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");



	return (object) $stats;

}

3497

wp_cookie_constants

Definition:
function wp_cookie_constants( ) {}

Defines cookie related WordPress constants
Defines constants after multisite is loaded. Cookie-related constants may be overridden in ms_network_cookies().

Source code

function wp_cookie_constants( ) {

	global $wp_default_secret_key;



	/**

	 * Used to guarantee unique hash cookies

	 * @since 1.5

	 */

	if ( !defined( 'COOKIEHASH' ) ) {

		$siteurl = get_site_option( 'siteurl' );

		if ( $siteurl )

			define( 'COOKIEHASH', md5( $siteurl ) );

		else

			define( 'COOKIEHASH', '' );

	}



	/**

	 * Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php

	 * @since 2.5.0

	 */

	$wp_default_secret_key = 'put your unique phrase here';



	/**

	 * @since 2.0.0

	 */

	if ( !defined('USER_COOKIE') )

		define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);



	/**

	 * @since 2.0.0

	 */

	if ( !defined('PASS_COOKIE') )

		define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);



	/**

	 * @since 2.5.0

	 */

	if ( !defined('AUTH_COOKIE') )

		define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);



	/**

	 * @since 2.6.0

	 */

	if ( !defined('SECURE_AUTH_COOKIE') )

		define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);



	/**

	 * @since 2.6.0

	 */

	if ( !defined('LOGGED_IN_COOKIE') )

		define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);



	/**

	 * @since 2.3.0

	 */

	if ( !defined('TEST_COOKIE') )

		define('TEST_COOKIE', 'wordpress_test_cookie');



	/**

	 * @since 1.2.0

	 */

	if ( !defined('COOKIEPATH') )

		define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );



	/**

	 * @since 1.5.0

	 */

	if ( !defined('SITECOOKIEPATH') )

		define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );



	/**

	 * @since 2.6.0

	 */

	if ( !defined('ADMIN_COOKIE_PATH') )

		define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );



	/**

	 * @since 2.6.0

	 */

	if ( !defined('PLUGINS_COOKIE_PATH') )

		define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL)  );



	/**

	 * @since 2.0.0

	 */

	if ( !defined('COOKIE_DOMAIN') )

		define('COOKIE_DOMAIN', false);

}

3495

wp_convert_widget_settings

Definition:
function wp_convert_widget_settings($base_name, $option_name, $settings) {}

Convert the widget settings from single to multi-widget format.

Parameters

  • $base_name
  • $option_name
  • $settings

Source code

function wp_convert_widget_settings($base_name, $option_name, $settings) {

	// This test may need expanding.

	$single = $changed = false;

	if ( empty($settings) ) {

		$single = true;

	} else {

		foreach ( array_keys($settings) as $number ) {

			if ( 'number' == $number )

				continue;

			if ( !is_numeric($number) ) {

				$single = true;

				break;

			}

		}

	}



	if ( $single ) {

		$settings = array( 2 => $settings );



		// If loading from the front page, update sidebar in memory but don't save to options

		if ( is_admin() ) {

			$sidebars_widgets = get_option('sidebars_widgets');

		} else {

			if ( empty($GLOBALS['_wp_sidebars_widgets']) )

				$GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array());

			$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets'];

		}



		foreach ( (array) $sidebars_widgets as $index => $sidebar ) {

			if ( is_array($sidebar) ) {

				foreach ( $sidebar as $i => $name ) {

					if ( $base_name == $name ) {

						$sidebars_widgets[$index][$i] = "$name-2";

						$changed = true;

						break 2;

					}

				}

			}

		}



		if ( is_admin() && $changed )

			update_option('sidebars_widgets', $sidebars_widgets);

	}



	$settings['_multiwidget'] = 1;

	if ( is_admin() )

		update_option( $option_name, $settings );



	return $settings;

}

3493

wp_convert_hr_to_bytes

Definition:
function wp_convert_hr_to_bytes( $size ) {}

Parameters

  • unknown_type $size

Source code

function wp_convert_hr_to_bytes( $size ) {

	$size = strtolower($size);

	$bytes = (int) $size;

	if ( strpos($size, 'k') !== false )

		$bytes = intval($size) * 1024;

	elseif ( strpos($size, 'm') !== false )

		$bytes = intval($size) * 1024 * 1024;

	elseif ( strpos($size, 'g') !== false )

		$bytes = intval($size) * 1024 * 1024 * 1024;

	return $bytes;

}

3491