Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created July 11, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/92cc9ded27e238d1497d4d4405c1376f to your computer and use it in GitHub Desktop.
Save Shelob9/92cc9ded27e238d1497d4d4405c1376f to your computer and use it in GitHub Desktop.
Examples of using the caldera_forms_admin_pre_enqueue and related hooks
<?php
/**
* Replace assets for Caldera Forms main admin page
*/
add_action( 'caldera_forms_admin_pre_enqueue', function (){
//do not act if in editor (which uses main admin's assets)
if( ! Caldera_Forms_Admin::is_edit() ){
//remove default callback
remove_action( 'caldera_forms_admin_main_enqueue', ['Caldera_Forms_Admin_Assets', 'admin_common' ],1);
//Add your own
add_action( 'caldera_forms_admin_main_enqueue', function(){
wp_enqueue_script('something-else');
});
}
});
/**
* Replace assets for Caldera Forms form editor or main admin page
*/
add_action( 'caldera_forms_admin_pre_enqueue', function (){
//remove default callback for main admin
remove_action( 'caldera_forms_admin_main_enqueue', ['Caldera_Forms_Admin_Assets', 'admin_common' ],1);
//remove default callback for form editor
remove_action( 'caldera_forms_admin_enqueue_form_editor', ['Caldera_Forms_Admin_Assets', 'form_editor' ]);
//Add your own
add_action( 'caldera_forms_admin_main_enqueue', function(){
wp_enqueue_script('something-else');
});
});
/**
* Remove Caldera Forms assets from the post editor if Gutenberg is in use for the current post
*/
add_action( 'caldera_forms_admin_pre_enqueue', function (){
if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ){
remove_action( 'caldera_forms_admin_enqueue_post_editor', ['Caldera_Forms_Admin_Assets', 'post_editor' ]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment