How do I add some javascript validation to the admin interface form’s onsubmit?

Every post / page / post type is wrapped around a universal form with the ID of #post. So if you want to validate a page before submitting it you just need to say something like: jQuery(document).ready(function($){ $(‘#post’).submit(function(){ // Validate Stuff return false; }); }); Then you’ll want to actually enqueue your javascript – View … Read more

A question about add_action()

The emailer::send is the function callback for a publish_post action hook. This action hook accepts only one parameter which is the post ID and it is passed by WordPress. When you define an action hook, you set what parameters are passed to the callback functions. For example: $arg_1 = “The aregument value”; do_action( ‘my_custom_action’, $arg_1 … Read more

missing argument 2 when passing arguments to add_action

This problem can be met when hooking in whatever hook that has already been triggered by a precedent do_action (ie. when this_hook has already been mentionned in a do_action within the core files of wordpress or within whatever plugin files) In that particular case, demanding arguments when registering a new function within an add_action(‘this_hook’,’function’, $priority, … Read more

Can’t Get Metabox Data Saved Assistance Needed

The save_post hook is the only one you need, also, your callback function is missing a parameter, check this example: /** * Save post metadata when a post is saved. * * @param int $post_id The ID of the post. */ function save_book_meta( $post_id ) { /* * In production code, $slug should be set … Read more

How to get menu location in wp_update_nav_menu hook

get_nav_menu_locations will give you menu IDs keyed by location which should correspond to the $id also passed with wp_update_nav_menu. add_action(‘wp_update_nav_menu’, function ($id, $data = NULL){ foreach( get_nav_menu_locations() as $location => $menu_id ){ if( $id == $menu_id ){ echo ‘location is ‘ . $location; } } }, 10, 2);

Why does my delete_post hook get called twice

I found my solution. The function you hook into delete_post (or probably any other similar hook) executes as many times as needed. Considering delete_post needs to delete the post and all of its revisions, it will always run more than once. In order to avoid having your function execute each time WordPress deletes a record … Read more