wp_timezone_override_offset

Definition:
function wp_timezone_override_offset() {}

gmt_offset modification for smart timezone handling.
Overrides the gmt_offset option if we have a timezone_string available.

Source code

function wp_timezone_override_offset() {

	if ( !$timezone_string = get_option( 'timezone_string' ) ) {

		return false;

	}



	$timezone_object = timezone_open( $timezone_string );

	$datetime_object = date_create();

	if ( false === $timezone_object || false === $datetime_object ) {

		return false;

	}

	return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 );

}

4169

wp_timezone_choice

Definition:
function wp_timezone_choice( $selected_zone ) {}

Gives a nicely formatted list of timezone strings. // temporary! Not in final

Parameters

  • string $selected_zone: Selected Zone

Source code

function wp_timezone_choice( $selected_zone ) {

	static $mo_loaded = false;



	$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');



	// Load translations for continents and cities

	if ( !$mo_loaded ) {

		$locale = get_locale();

		$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';

		load_textdomain( 'continents-cities', $mofile );

		$mo_loaded = true;

	}



	$zonen = array();

	foreach ( timezone_identifiers_list() as $zone ) {

		$zone = explode( '/', $zone );

		if ( !in_array( $zone[0], $continents ) ) {

			continue;

		}



		// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later

		$exists = array(

			0 => ( isset( $zone[0] ) && $zone[0] ),

			1 => ( isset( $zone[1] ) && $zone[1] ),

			2 => ( isset( $zone[2] ) && $zone[2] ),

		);

		$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );

		$exists[4] = ( $exists[1] && $exists[3] );

		$exists[5] = ( $exists[2] && $exists[3] );



		$zonen[] = array(

			'continent'   => ( $exists[0] ? $zone[0] : '' ),

			'city'        => ( $exists[1] ? $zone[1] : '' ),

			'subcity'     => ( $exists[2] ? $zone[2] : '' ),

			't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),

			't_city'      => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),

			't_subcity'   => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' )

		);

	}

	usort( $zonen, '_wp_timezone_choice_usort_callback' );



	$structure = array();



	if ( empty( $selected_zone ) ) {

		$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';

	}



	foreach ( $zonen as $key => $zone ) {

		// Build value in an array to join later

		$value = array( $zone['continent'] );



		if ( empty( $zone['city'] ) ) {

			// It's at the continent level (generally won't happen)

			$display = $zone['t_continent'];

		} else {

			// It's inside a continent group



			// Continent optgroup

			if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) {

				$label = $zone['t_continent'];

				$structure[] = '<optgroup label="'. esc_attr( $label ) .'">';

			}



			// Add the city to the value

			$value[] = $zone['city'];



			$display = $zone['t_city'];

			if ( !empty( $zone['subcity'] ) ) {

				// Add the subcity to the value

				$value[] = $zone['subcity'];

				$display .= ' - ' . $zone['t_subcity'];

			}

		}



		// Build the value

		$value = join( '/', $value );

		$selected = '';

		if ( $value === $selected_zone ) {

			$selected = 'selected="selected" ';

		}

		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>";



		// Close continent optgroup

		if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) {

			$structure[] = '</optgroup>';

		}

	}



	// Do UTC

	$structure[] = '<optgroup label="'. esc_attr__( 'UTC' ) .'">';

	$selected = '';

	if ( 'UTC' === $selected_zone )

		$selected = 'selected="selected" ';

	$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>';

	$structure[] = '</optgroup>';



	// Do manual UTC offsets

	$structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';

	$offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5,

		0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);

	foreach ( $offset_range as $offset ) {

		if ( 0 <= $offset )

			$offset_name = '+' . $offset;

		else

			$offset_name = (string) $offset;



		$offset_value = $offset_name;

		$offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);

		$offset_name = 'UTC' . $offset_name;

		$offset_value = 'UTC' . $offset_value;

		$selected = '';

		if ( $offset_value === $selected_zone )

			$selected = 'selected="selected" ';

		$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";



	}

	$structure[] = '</optgroup>';



	return join( "\n", $structure );

}

4167

wp_throttle_comment_flood

Definition:
function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {}

Whether comment should be blocked because of comment flood.

Parameters

  • bool $block: Whether plugin has already blocked comment.
  • int $time_lastcomment: Timestamp for last comment.
  • int $time_newcomment: Timestamp for new comment.

Return values

returns:Whether comment should be blocked.

Source code

function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {

	if ( $block ) // a plugin has already blocked... we'll let that decision stand

		return $block;

	if ( ($time_newcomment - $time_lastcomment) < 15 )

		return true;

	return false;

}

4165

wp_text_diff

Definition:
function wp_text_diff( $left_string, $right_string, $args = null ) {}

Displays a human readable HTML representation of the difference between two strings.
The Diff is available for getting the changes between versions. The output is HTML, so the primary use is for displaying the changes. If the two strings are equivalent, then an empty string will be returned.

Parameters

  • string $left_string: “old” (left) version of string
  • string $right_string: “new” (right) version of string
  • string|array $args: Optional. Change ‘title’, ‘title_left’, and ‘title_right’ defaults.

Return values

returns:Empty string if strings are equivalent or HTML with differences.

Source code

function wp_text_diff( $left_string, $right_string, $args = null ) {

	$defaults = array( 'title' => '', 'title_left' => '', 'title_right' => '' );

	$args = wp_parse_args( $args, $defaults );



	if ( !class_exists( 'WP_Text_Diff_Renderer_Table' ) )

		require( ABSPATH . WPINC . '/wp-diff.php' );



	$left_string  = normalize_whitespace($left_string);

	$right_string = normalize_whitespace($right_string);



	$left_lines  = split("\n", $left_string);

	$right_lines = split("\n", $right_string);



	$text_diff = new Text_Diff($left_lines, $right_lines);

	$renderer  = new WP_Text_Diff_Renderer_Table();

	$diff = $renderer->render($text_diff);



	if ( !$diff )

		return '';



	$r  = "<table class='diff'>\n";

	$r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />";



	if ( $args['title'] || $args['title_left'] || $args['title_right'] )

		$r .= "<thead>";

	if ( $args['title'] )

		$r .= "<tr class='diff-title'><th colspan='4'>$args[title]</th></tr>\n";

	if ( $args['title_left'] || $args['title_right'] ) {

		$r .= "<tr class='diff-sub-title'>\n";

		$r .= "\t<td></td><th>$args[title_left]</th>\n";

		$r .= "\t<td></td><th>$args[title_right]</th>\n";

		$r .= "</tr>\n";

	}

	if ( $args['title'] || $args['title_left'] || $args['title_right'] )

		$r .= "</thead>\n";



	$r .= "<tbody>\n$diff\n</tbody>\n";

	$r .= "</table>";



	return $r;

}

4163

wp_terms_checklist

Definition:
function wp_terms_checklist($post_id = 0, $args = array() {}

Taxonomy independent version of wp_category_checklist

Parameters

  • int $post_id
  • array $args

Source code

function wp_terms_checklist($post_id = 0, $args = array()) {

 	$defaults = array(

		'descendants_and_self' => 0,

		'selected_cats' => false,

		'popular_cats' => false,

		'walker' => null,

		'taxonomy' => 'category',

		'checked_ontop' => true

	);

	extract( wp_parse_args($args, $defaults), EXTR_SKIP );



	if ( empty($walker) || !is_a($walker, 'Walker') )

		$walker = new Walker_Category_Checklist;



	$descendants_and_self = (int) $descendants_and_self;



	$args = array('taxonomy' => $taxonomy);



	$tax = get_taxonomy($taxonomy);

	$args['disabled'] = !current_user_can($tax->cap->assign_terms);



	if ( is_array( $selected_cats ) )

		$args['selected_cats'] = $selected_cats;

	elseif ( $post_id )

		$args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));

	else

		$args['selected_cats'] = array();



	if ( is_array( $popular_cats ) )

		$args['popular_cats'] = $popular_cats;

	else

		$args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );



	if ( $descendants_and_self ) {

		$categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );

		$self = get_term( $descendants_and_self, $taxonomy );

		array_unshift( $categories, $self );

	} else {

		$categories = (array) get_terms($taxonomy, array('get' => 'all'));

	}



	if ( $checked_ontop ) {

		// Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)

		$checked_categories = array();

		$keys = array_keys( $categories );



		foreach( $keys as $k ) {

			if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {

				$checked_categories[] = $categories[$k];

				unset( $categories[$k] );

			}

		}



		// Put checked cats on top

		echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));

	}

	// Then the rest of them

	echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));

}

4161