global_terms

Advertisement

Summery Summery

Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.

Syntax Syntax

global_terms( int $term_id, string $deprecated = '' )

Parameters Parameters

$term_id

(Required) An ID for a term on the current blog.

$deprecated

(Optional) Not used.

Default value: ''

Return Return

(int) An ID from the global terms table mapped from $term_id.

Source Source

File: wp-includes/ms-functions.php

	$user = get_userdata( (int) $user_id );
	if ( $user ) {
		$wpdb->insert(
			$wpdb->registration_log,
			array(
				'email'           => $user->user_email,
				'IP'              => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ),
				'blog_id'         => $blog_id,
				'date_registered' => current_time( 'mysql' ),
			)
		);
	}
}

/**
 * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table.
 *
 * @since 3.0.0
 *
 * @see term_id_filter
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $term_id    An ID for a term on the current blog.
 * @param string $deprecated Not used.
 * @return int An ID from the global terms table mapped from $term_id.
 */
function global_terms( $term_id, $deprecated = '' ) {
	global $wpdb;
	static $global_terms_recurse = null;

	if ( ! global_terms_enabled() ) {
		return $term_id;
	}

	// Prevent a race condition.
	$recurse_start = false;
	if ( null === $global_terms_recurse ) {
		$recurse_start        = true;
		$global_terms_recurse = 1;
	} elseif ( 10 < $global_terms_recurse++ ) {
		return $term_id;
	}

	$term_id = intval( $term_id );
	$c       = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );

	$global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) );
	if ( null == $global_id ) {
		$used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) );
		if ( null == $used_global_id ) {
			$wpdb->insert(
				$wpdb->sitecategories,
				array(
					'cat_ID'            => $term_id,
					'cat_name'          => $c->name,
					'category_nicename' => $c->slug,
				)
			);
			$global_id = $wpdb->insert_id;
			if ( empty( $global_id ) ) {
				return $term_id;
			}
		} else {
			$max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" );
			$max_local_id  = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );
			$new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 );
			$wpdb->insert(
				$wpdb->sitecategories,
				array(
					'cat_ID'            => $new_global_id,
					'cat_name'          => $c->name,
					'category_nicename' => $c->slug,
				)
			);
			$global_id = $wpdb->insert_id;
		}

Advertisement

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

See also See also

Advertisement

Leave a Reply