dbDelta

Definition:
function dbDelta($queries, $execute = true) {}

Parameters

  • unknown_type $queries
  • unknown_type $execute

Source code

function dbDelta($queries, $execute = true) {

	global $wpdb;



	// Separate individual queries into an array

	if ( !is_array($queries) ) {

		$queries = explode( ';', $queries );

		if ('' == $queries[count($queries) - 1]) array_pop($queries);

	}



	$cqueries = array(); // Creation Queries

	$iqueries = array(); // Insertion Queries

	$for_update = array();



	// Create a tablename index for an array ($cqueries) of queries

	foreach($queries as $qry) {

		if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {

			$cqueries[trim( strtolower($matches[1]), '`' )] = $qry;

			$for_update[$matches[1]] = 'Created table '.$matches[1];

		} else if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {

			array_unshift($cqueries, $qry);

		} else if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {

			$iqueries[] = $qry;

		} else if (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {

			$iqueries[] = $qry;

		} else {

			// Unrecognized query type

		}

	}



	// Check to see which tables and fields exist

	if ($tables = $wpdb->get_col('SHOW TABLES;')) {

		// For every table in the database

		foreach ($tables as $table) {

			// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.

			if ( in_array($table, $wpdb->tables('global')) && ( !is_main_site() || defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) )

				continue;



			// If a table query exists for the database table...

			if ( array_key_exists(strtolower($table), $cqueries) ) {

				// Clear the field and index arrays

				$cfields = $indices = array();

				// Get all of the field names in the query from between the parens

				preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);

				$qryline = trim($match2[1]);



				// Separate field lines into an array

				$flds = explode("\n", $qryline);



				//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";



				// For every field line specified in the query

				foreach ($flds as $fld) {

					// Extract the field name

					preg_match("|^([^ ]*)|", trim($fld), $fvals);

					$fieldname = trim( $fvals[1], '`' );



					// Verify the found field name

					$validfield = true;

					switch (strtolower($fieldname)) {

					case '':

					case 'primary':

					case 'index':

					case 'fulltext':

					case 'unique':

					case 'key':

						$validfield = false;

						$indices[] = trim(trim($fld), ", \n");

						break;

					}

					$fld = trim($fld);



					// If it's a valid field, add it to the field array

					if ($validfield) {

						$cfields[strtolower($fieldname)] = trim($fld, ", \n");

					}

				}



				// Fetch the table column structure from the database

				$tablefields = $wpdb->get_results("DESCRIBE {$table};");



				// For every field in the table

				foreach ($tablefields as $tablefield) {

					// If the table field exists in the field array...

					if (array_key_exists(strtolower($tablefield->Field), $cfields)) {

						// Get the field type from the query

						preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);

						$fieldtype = $matches[1];



						// Is actual field type different from the field type in query?

						if ($tablefield->Type != $fieldtype) {

							// Add a query to change the column type

							$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];

							$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";

764

date_i18n

Definition:
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {}

Retrieve the date in localized format, based on timestamp.
If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn’t, then the date format string will be used instead.

Parameters

  • string $dateformatstring: Format to display the date.
  • int $unixtimestamp: Optional. Unix timestamp.
  • bool $gmt: Optional, default is false. Whether to convert to GMT for time.

Return values

returns:The date, translated if locale specifies it.

Defined filters

  • date_i18n
    apply_filters('date_i18n', $j, $req_format, $i, $gmt)

Source code

function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {

	global $wp_locale;

	$i = $unixtimestamp;



	if ( false === $i ) {

		if ( ! $gmt )

			$i = current_time( 'timestamp' );

		else

			$i = time();

		// we should not let date() interfere with our

		// specially computed timestamp

		$gmt = true;

	}



	// store original value for language with untypical grammars

	// see http://core.trac.wordpress.org/ticket/9396

	$req_format = $dateformatstring;



	$datefunc = $gmt? 'gmdate' : 'date';



	if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {

		$datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );

		$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );

		$dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );

		$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );

		$datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );

		$datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );

		$dateformatstring = ' '.$dateformatstring;

		$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );

		$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );

		$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );

		$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );

		$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );

		$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );



		$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );

	}

	$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' );

	$timezone_formats_re = implode( '|', $timezone_formats );

	if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) {

		$timezone_string = get_option( 'timezone_string' );

		if ( $timezone_string ) {

			$timezone_object = timezone_open( $timezone_string );

			$date_object = date_create( null, $timezone_object );

			foreach( $timezone_formats as $timezone_format ) {

				if ( false !== strpos( $dateformatstring, $timezone_format ) ) {

					$formatted = date_format( $date_object, $timezone_format );

					$dateformatstring = ' '.$dateformatstring;

					$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring );

					$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );

				}

			}

		}

	}

	$j = @$datefunc( $dateformatstring, $i );

	// allow plugins to redo this entirely for languages with untypical grammars

	$j = apply_filters('date_i18n', $j, $req_format, $i, $gmt);

	return $j;

}

762

dashboard_quota

Definition:
function dashboard_quota() {}

Source code

function dashboard_quota() {

	if ( get_site_option( 'upload_space_check_disabled' ) )

		return true;



	$quota = get_space_allowed();

	$used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;



	if ( $used > $quota )

		$percentused = '100';

	else

		$percentused = ( $used / $quota ) * 100;

	$used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam';

	$used = round( $used, 2 );

	$percentused = number_format( $percentused );



	?>

	<p class="sub musub"><?php _e( 'Storage Space' ); ?></p>

	<div class="table table_content musubtable">

	<table>

		<tr class="first">

			<td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), $quota ); ?></td>

			<td class="t posts"><?php _e( 'Space Allowed' ); ?></td>

		</tr>

	</table>

	</div>

	<div class="table table_discussion musubtable">

	<table>

		<tr class="first">

			<td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), $used, $percentused ); ?></td>

			<td class="last t comments <?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>

		</tr>

	</table>

	</div>

	<br class="clear" />

	<?php

}

760

current_user_can_for_blog

Definition:
function current_user_can_for_blog( $blog_id, $capability ) {}

Whether current user has a capability or role for a given blog.

Parameters

  • int $blog_id: Blog ID
  • string $capability: Capability or role name.

Source code

function current_user_can_for_blog( $blog_id, $capability ) {

	$current_user = wp_get_current_user();



	if ( empty( $current_user ) )

		return false;



	// Create new object to avoid stomping the global current_user.

	$user = new WP_User( $current_user->ID) ;



	// Set the blog id.  @todo add blog id arg to WP_User constructor?

	$user->for_blog( $blog_id );



	$args = array_slice( func_get_args(), 2 );

	$args = array_merge( array( $capability ), $args );



	return call_user_func_array( array( &$user, 'has_cap' ), $args );

}

758

current_user_can

Definition:
function current_user_can( $capability ) {}

Whether current user has capability or role.

Parameters

  • string $capability: Capability or role name.

Source code

function current_user_can( $capability ) {

	$current_user = wp_get_current_user();



	if ( empty( $current_user ) )

		return false;



	$args = array_slice( func_get_args(), 1 );

	$args = array_merge( array( $capability ), $args );



	return call_user_func_array( array( $current_user, 'has_cap' ), $args );

}

756