Action uncanny-automator

automator_template_library_admin_load

Fires when the Automator template library admin area is loaded, providing access to the library object.

add_action( 'automator_template_library_admin_load', $callback, 10, 1 );

Description

Fires after the WordPress admin loads the Automator template library page, but before its content is rendered. Developers can use this hook to perform actions like enqueuing custom scripts, adding meta boxes, or modifying the library's data before it's displayed. The `$this` parameter provides access to the `Admin_Template_Library` object.


Usage

add_action( 'automator_template_library_admin_load', 'your_function_name', 10, 1 );

Parameters

$this (mixed)
This parameter is an instance of the `UncannyAutomator_Admin_Template_Library` class, which manages the template library admin page.

Examples

add_action( 'automator_template_library_admin_load', function( $admin_template_library_instance ) {
    // Enqueue custom scripts and styles for the template library admin page.
    // This ensures that our specific admin UI elements load correctly.

    if ( ! wp_script_is( 'automator-template-library-admin', 'enqueued' ) ) {
        wp_enqueue_script(
            'automator-template-library-admin',
            plugins_url( 'assets/js/admin-template-library.js', __FILE__ ),
            array( 'jquery', 'wp-util' ),
            filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/admin-template-library.js' )
        );
    }

    if ( ! wp_style_is( 'automator-template-library-admin', 'enqueued' ) ) {
        wp_enqueue_style(
            'automator-template-library-admin',
            plugins_url( 'assets/css/admin-template-library.css', __FILE__ ),
            array(),
            filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/admin-template-library.css' )
        );
    }

    // Potentially set up some data that will be passed to the JavaScript.
    // For example, localization strings or initial data for the template library.
    $admin_template_library_instance->localize_data();

}, 10, 1 ); // 10 is the default priority, 1 indicates that the callback accepts 1 argument ($this)

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/core/admin/class-admin-template-library.php:68

public function submenu_page() {

		// Add submenu
		$this->admin_hook = add_submenu_page(
			'edit.php?post_type=uo-recipe',
			/* translators: 1. Trademarked term */
			sprintf( esc_attr__( '%1$s settings', 'uncanny-automator' ), 'Uncanny Automator' ),
			esc_attr__( 'Recipe templates', 'uncanny-automator' ),
			automator_get_capability(),
			'uncanny-automator-template-library',
			array( $this, 'submenu_page_output' ),
			3
		);

		// Add load hook
		add_action(
			"load-{$this->admin_hook}",
			function () {
				do_action( 'automator_template_library_admin_load', $this );
			}
		);
	}

Internal Usage

Found in src/core/admin/class-admin-template-library.php:41:

add_action( 'automator_template_library_admin_load', array( $this, 'admin_load' ) );
Scroll to Top