Intercept loading of a certain page

One way to approach this is to intercept the page load with the template_redirect action and test user status before rending the login page. Based on user status you could redirect to another page instead of loading the original page content. function wpse_is_user_good_enough() { if ( ! is_page( ‘your-login-page-slug-here’ ) ) { return; // Not … Read more

Is it likely that do_action will have unexpected results?

In the described scenario, f1 was added and it was indicated it only takes a single parameter, so only one parameter is provided ( the first ). So f1 is never called with more than one parameter. However, it is possible to make a mistake, if you call add_action and declare that f1 can receive … Read more

WP hook to add custom content after the_title()

You need to introduce your own hook (that’s how I’d do it). I’ve added a custom hook in the following snippet: <header class=”entry-header alignwide”> <?php the_title( ‘<h1 class=”entry-title”>’, ‘</h1>’ ); ?> <?php do_action(‘custom_after_title_hook’); ?> <?php twenty_twenty_one_post_thumbnail(); ?> </header> In order for this to work, you need to have: Access to the header.php OR overwrite it … Read more

What is the hook to remove a menu items group from Appearance > Menus column Add menu items

You can use the register_post_type_args filter and just set the show_in_nav_menus argument to false. E.g. add_filter( ‘register_post_type_args’, ‘my_register_post_type_args’, 10, 2 ); function my_register_post_type_args( $args, $post_type ) { if ( ‘post’ === $post_type ) { // or use below to check against two or more post types // if ( in_array( $post_type, array( ‘post’, ‘cpt_1’, ‘cpt_2’, … Read more

How to call do_action() to pass arguments to hooked functions that take different number of args?

All the additional arguments passed to do_action() are passed as arguments, in order, to any hooked callback function. The callback functions can only choose how many of them to use, by setting the $accepted_args parameter of add_action(). They can’t choose which arguments to accept. So you would need to do something like this: add_action(‘myaction’, ‘my_multiplication’, … Read more

template_redirect hooks redirect wrong URL

The code adds the functions like this: add_action (‘template_redirect’, array( ‘loginForm’, ‘set_submit_login_func’)); Which tells PHP to do this when template_redirect happens: loginForm::set_submit_login_func(); But we can see set_submit_login_func in the questions code and it is clear that it is not a static function: public function set_submit_login_func(){ What you want is a dynamic callable, e.g. class MyClass … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)