wp_localize_script

Definition:
function wp_localize_script( $handle, $object_name, $l10n ) {}

Wrapper for $wp_scripts->localize().
Used to localizes a script. Works only if the script has already been added. Accepts an associative array $l10n and creates JS object: "$object_name" = { key: value, key: value, … } See http://core.trac.wordpress.org/ticket/11520 for more information.

Parameters

  • string $handle: The script handle that was registered or used in script-loader
  • string $object_name: Name for the created JS object. This is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/
  • array $l10n: Associative PHP array containing the translated strings. HTML entities will be converted and the array will be JSON encoded.

Return values

returns:Whether the localization was added successfully.

Source code

function wp_localize_script( $handle, $object_name, $l10n ) {

	global $wp_scripts;

	if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {

		if ( ! did_action( 'init' ) )

			_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),

				'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );



		return false;

	}



	return $wp_scripts->localize( $handle, $object_name, $l10n );

}

3877

wp_load_image

Definition:
function wp_load_image( $file ) {}

Load an image from a string, if PHP supports it.

Parameters

  • string $file: Filename of the image to load.

Return values

returns:The resulting image resource on success, Error string on failure.

Defined filters

  • image_memory_limit
    apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT )

Source code

function wp_load_image( $file ) {

	if ( is_numeric( $file ) )

		$file = get_attached_file( $file );



	if ( ! file_exists( $file ) )

		return sprintf(__('File “%s” doesn’t exist?'), $file);



	if ( ! function_exists('imagecreatefromstring') )

		return __('The GD image library is not installed.');



	// Set artificially high because GD uses uncompressed images in memory

	@ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) );

	$image = imagecreatefromstring( file_get_contents( $file ) );



	if ( !is_resource( $image ) )

		return sprintf(__('File “%s” is not an image.'), $file);



	return $image;

}

3875

wp_load_core_site_options

Definition:
function wp_load_core_site_options( $site_id = null ) {}

Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.

Parameters

  • int $site_id: Optional site ID for which to query the options. Defaults to the current site.

Source code

function wp_load_core_site_options( $site_id = null ) {

	global $wpdb, $_wp_using_ext_object_cache;



	if ( !is_multisite() || $_wp_using_ext_object_cache || defined( 'WP_INSTALLING' ) )

		return;



	if ( empty($site_id) )

		$site_id = $wpdb->siteid;



	$core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled' );



	$core_options_in = "'" . implode("', '", $core_options) . "'";

	$options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) );



	foreach ( $options as $option ) {

		$key = $option->meta_key;

		$cache_key = "{$site_id}:$key";

		$option->meta_value = maybe_unserialize( $option->meta_value );



		wp_cache_set( $cache_key, $option->meta_value, 'site-options' );

	}

3873

wp_load_alloptions

Definition:
function wp_load_alloptions() {}

Loads and caches all autoloaded options, if available or all options.

Return values

returns:List of all options.

Source code

function wp_load_alloptions() {

	global $wpdb;



	if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )

		$alloptions = wp_cache_get( 'alloptions', 'options' );

	else

		$alloptions = false;



	if ( !$alloptions ) {

		$suppress = $wpdb->suppress_errors();

		if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )

			$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );

		$wpdb->suppress_errors($suppress);

		$alloptions = array();

		foreach ( (array) $alloptions_db as $o ) {

			$alloptions[$o->option_name] = $o->option_value;

		}

		if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )

			wp_cache_add( 'alloptions', $alloptions, 'options' );

	}



	return $alloptions;

}

3871