Trying to write a function in an external php file to manage admin menu visibility

It’s becouse you’r calling alter_item function outside action admin_menu here’s working example i just made, try to figure what’s wrong with your’s by your self, if you fail i’ll explain add_action( ‘admin_menu’, ‘alter_items’ ); function alter_items() { global $current_user, $menu; get_currentuserinfo(); $scopes = apply_filters( ‘alter_items’, array() ); if( ! empty( $scopes ) ) { foreach( … Read more

Other than save_post any other actions on add / edit post screen?

you can use load-{page-hook}. It is called prior to the admin screen loading. add_action( ‘load-post-new.php’, ‘post_listing_page’ ); function post_listing_page() { // ‘add new’ page, you may have to check post type.. } {page-hook} on the ‘add new’ page of any post type, it is post-new.php {page-hook} on the edit page of any post type, it … Read more

add_action in the loop hooks

Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action). To stop this, the action should be removed. See remove_action: function do_entry() { if ( get_the_title() ) { add_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } else { remove_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } add_action(‘loop_entry_entry’, ‘function_that_adds_content_structure’); } In your case, I … Read more

Action on WordPress Install

The main component you are probably missing is dropping your customizations in an install.php file in the wp-content directory. If you look at the /wp-admin/includes/upgrade.php you will be able to see exactly how it is included and the installation functions you can override. I am not sure if that will be good enough to catch … Read more

Where to place add_action when enqueueing?

Makes no difference. Despite the fact add_action doesn’t actually check if the callback is indeed callable (i.e. is a valid function/class/method), PHP will first “load” function and class definitions before executing inline code, hence why you can do something like: wpse_185390_function(); // Perfectly fine, even though the function is defined “afterwards” function wpse_185390_function() { echo … Read more

What hook to add at start of WordPress load

The earliest hook accessible from external code is muplugins_loaded. In order to use it, create a directory mu-plugins in your wp-content directory and put a PHP file into that directory. Sample code, will have side effects(!): add_action( ‘muplugins_loaded’, function() { print current_filter(); }); This is, of course, not “before anything else in WordPress executes”. WordPress … Read more

How can I edit comment meta value before it is saved?

You can use “save_post” action-hook Add the code below into functions.php and enchance with your comment_meta code. function update_comments_meta( $post_id ) { // Do whatever add/update_comment_meta code you need } add_action( ‘save_post’, ‘update_comments_meta’ ); UPDATE. As an example i’ve attach code below. It performs on post save/update action fired. Code gets current post comments (all) … Read more