add_action into another add_action not working

The preferred method of creating a settings page is to use the WordPress Settings API. From your code example, it looks like it’s too late to remove the admin_notices hook inside your callback in the admin_menu hook. You should try to move the logic from the customfunc() callback into another callback activated from some earlier … Read more

Create new custom post and post category of same name

You are way off, if you say that wp_publish_post() has been renamed to {$new_status}_{$post->post_type}. The latter actually is a hook, while the former is a function. Where the latter is part of the former, because it’s part of wp_insert_post. The hook {$new_status}_{$post->post_type} is part of wp_transition_post_status() – additionally see the source. You might want to … Read more

Insert custom postmeta when custom post type published

Newer New solution: function wpse153622_transition_solution( $new_status, $old_status, $post ) { if ( $new_status != $old_status && ‘publish’ === $new_status && ‘my-solution’ === $post->post_type ) { update_post_meta( $post_id, ‘my_json’, ‘json’ ); } } add_action( ‘transition_post_status’, ‘wpse153622_transition_solution’, 10, 3 ); This should trigger only when 1. the new post status isn’t the same as the old one … Read more

WordPress wp_loaded action hook

wp_loaded is called long, long before the post content is fetched. Put that code into a plugin. Also, you shouldn’t echo anything that early. The HTTP headers aren’t sent yet on wp_loaded, so you will get the Headers already sent error, and your user authentication will not work: you cannot log in anymore.

How passing values ​​to construct function with Actions?

<?php class someClass { public function __construct($options = null, $initialize = true, $error_messages = null, $path, $qnty) { //construct what you see fit here…. } //etc.. } // Action listener add_action( ‘action_name’, create_function(”, “new someClass(implode(‘,’,func_get_args()));”), 10, 5 // IMPORTANT, number of arguments your construct function accept ); // Call the action $options = “options”; $initialize … Read more

How to trace SUBMIT button

Still using jQuery, you can do this: $(‘form’).submit(function() { // Use this to echo in JS console. console.log( $(this).attr(‘action’) ); // Use this to display a popup. alert( $(this).attr(‘action’) ); }); This will track every form being submitted. Place this between <script> tags or in a JS file. Like @dev said, this for debug purpose, … Read more

How to access author data from header action

The global $authordata variable is only available by default when $wp_query->is_author() && isset($wp_query->post) condition is satisfied. It means that you can’t access $authordata inside a single post page. You may try to get author data via $wp_query: add_action(‘wp_head’, function() { global $wp_query; $userdata = get_userdata($wp_query->post->post_author); $avatar_url = get_avatar_ur($userdata->user_email); … }, 10, 0);