Modify available templates (in dropdown)

The list of available templates is generated by get_page_templates. By the end of this function you see a filter that allows you to modify the output. You can use that to change it under certain conditions like this: add_filter (‘theme_page_templates’,’wpse302574_conditional_templates’, 10, 4); function wpse302574_conditional_templates ($post_templates, $this, $post, $post_type) { $parent_id = wp_get_post_parent_id ($post->ID); if (get_page_template_slug … Read more

Automatically set post_parent value

You can do that easily using save_post hook like so: function set_post_parent_on_save($post_id) { // If this is just a revision, don’t do anything if ( wp_is_post_revision( $post_id ) ) return; // Check if it is a post if ( ‘post’ == get_post_type( $post_id ) ) { // unhook this function so it doesn’t loop infinitely … Read more

How to change a WordPress term’s slug before saving

You add the following snippet to your theme’s functions.php file; The “wp_insert_term_data” filter allows you to modify a term’s name, slug or term_group before it is added to the database. This works for terms added via WP All Import and also manually through admin as well. The filter passes all taxonomy terms, not just woocommerce … Read more

How to run hooks one by one manually?

When there’s an issue such as yours, there is probably 1 function stuck somewhere that delays the loading. You can retrieve a list of all functions attached to a hook this way: global $wp_filter; $actions = $wp_filter[‘init’] ; Now you can remove the functions from the hook one by one, by using remove_action() and see … Read more

How to remove a class function from a plugin by using remove_action()?

[ Nova_Restaurant::init(), ‘sort_menu_item_queries_by_menu_order’ ] You want something of type callable, that matches what was given when add_action. There are only a handful of valid callables: [ ‘my_function_name’ ] aka my_function_name(); [ ‘my_class_name’, ‘my_static_function’ ] aka my_class_name::my_stati_function() [ $object, ‘the_objects_function’ ] aka $object->the_objects_function [ function() {} ] an anonymous function or closure So some translation: remove_action(‘parse_query’,’WM_Nova_Restaurant’, … Read more

WordPress cronjob get scheduled but function does not run

I believe you need to use wp_get_current_user() (see https://codex.wordpress.org/Function_Reference/wp_get_current_user ), which will return the current WP user information as an object. From there, you can get the user name (or other parameters). From that page, this example should get you started: $current_user = wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( … Read more