class Fieldmanager_Util_Assets (View source)

Asset management.

Properties

protected array $scripts

Array of scripts to enqueue during *_enqueue_scripts

protected array $styles

Array of scripts to enqueue during *_enqueue_styles

bool $hooked

Ensure that the enqueue method only gets hooked once.

Methods

instance()

Get the singleton instance.

enqueue_assets()

Enqueue all assets during the correct action.

pre_enqueue_script(array $args)

Enqueue or output a script.

enqueue_script(array $args)

Enqueue a script.

pre_enqueue_style(array $args)

Enqueue or output a style.

enqueue_style(array $args)

Enqueue a style.

hook_enqueue()

Hook into admin_enqueue_scripts and wp_enqueue_scripts if we haven't already.

add_script(array $args)

Enqueue a script, optionally localizing data to it.

add_style(array $args)

Register and enqueue a style.

Details

static Fieldmanager_Util_Assets instance()

Get the singleton instance.

enqueue_assets()

Enqueue all assets during the correct action.

protected pre_enqueue_script(array $args)

Enqueue or output a script.

Checks if the *_enqueue_scripts action has already fired and if so, outputs the script immediately. If not, the handle gets added to an array to enqueue later.

Parameters

array $args

Script arguments. Fieldmanager_Util_Assets::add_script().

protected enqueue_script(array $args)

Enqueue a script.

Parameters

array $args

Script arguments. Fieldmanager_Util_Assets::add_script().

protected pre_enqueue_style(array $args)

Enqueue or output a style.

Checks if the *_enqueue_scripts action has already fired and if so, outputs the style immediately. If not, the handle gets added to an array to enqueue later.

Parameters

array $args

Stylesheet arguments. Fieldmanager_Util_Assets::add_style().

protected enqueue_style(array $args)

Enqueue a style.

Parameters

array $args

Stylesheet arguments. Fieldmanager_Util_Assets::add_style().

protected hook_enqueue()

Hook into admin_enqueue_scripts and wp_enqueue_scripts if we haven't already.

add_script(array $args)

Enqueue a script, optionally localizing data to it.

Parameters

array $args

{ Script arguments.

@type string $handle Script handle.
@type string|bool $path Optional. The path to the file inside $plugin_dir.
                        If absent, the script will only be enqueued
                        and not registered. Default false.
@type array $deps Optional. Script dependencies. Default empty array.
@type string|bool $ver Optional. Script version. Default false.
@type bool $in_footer Optional. Whether to render the script in the
                      footer. Default false.
@type string $data_object Optional. The $object_name in
                          wp_localize_script(). Default none.
@type array $data Optional. The $l10n in wp_localize_script().
                  Default empty array.
@type string $plugin_dir The base URL to the directory with the
                         script. Default none.

}

See also

wp_enqueue_script() for detail about $handle, $deps, $ver, and $in_footer.
wp_localize_script() for detail about $data_object and $data.
FM_GLOBAL_ASSET_VERSION for detail about the fallback value of $ver.
fieldmanager_get_baseurl() for detail about the fallback value of $plugin_dir.

add_style(array $args)

Register and enqueue a style.

Parameters

array $args

{ Stylesheet arguments.

@type string $handle Stylesheet name.
@type string $path Optional. Path to the file inside of the Fieldmanager
                   base URL. If absent, the style will only be enqueued
                   and not registered. Default false.
@type array $deps Optional. Stylesheet dependencies. Default empty array.
@type string|bool Optional. Stylesheet version. Default none.
@type string $media Optional. Media for this stylesheet. Default 'all'.
@type string $plugin_dir The base URL for the directory with the style.
                         Default none.

}

See also

wp_enqueue_script() for detail about $handle, $path, $deps, $ver, and $media.
FM_GLOBAL_ASSET_VERSION for detail about the fallback value of $ver.
fieldmanager_get_baseurl() for detail about base URL.