Tag Info

Hot answers tagged

2

range of priority values? range of priority values? Generally, speaking, you can't know a priori what priority something is hooked with. The priority needed depends on how other callbacks where hooked in. Often that is the default value of 10 but it could be anywhere between 1 and PHP_INT_MAX and there is no way to be sure except by experiment and, if ...


2

WordPress puts your actions into an array with an indexed priorities. You can see this by printing out ( in the admin panel admin_init ) $wp_filter: *Note* as @s_ha_dum points out in the comments below, admin_init may not catch all added hooks into the action, the more reliable print out may be hooking into shutdown instead. function filter_print() { ...


1

Use the use keyword: $title = $instance['title']; add_action( 'wp_footer', function() use ( $title ) { echo $title; });


1

Try using the filter hook: function user1462_login_redirect( $redirect_to, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'administrator', $user->roles ) ) { return $redirect_to . '?message=hiadmin'; } else { return home_url(); ...


1

The main benefit with hooks ( such as add_action ) is that they allow you to add additional logic very easily based on priority. The only way to achieve the same thing with a standalone function is to edit the function directly. You wouldn't want to do this in premium theme ( or core ) as any time there's an update your function will be overwritten. Take ...


1

Use this instead: Concatenate the html then return it. function check_my_login( $atts) { $html = '<form action="" name="" method="post" enctype="multipart/form-data">'; $html .= '<div class="form-group">'; $html .= '<label for="description">Project Description</label>'; $html .= '<textarea name="p_description" ...


1

If you check the source for admin-ajax.php you will notice that the admin_init hook fires and that the system checks $_REQUEST['action'] for hooks. Given that, you could hook to admin_init, check the "request" super global, construct wp_ajax_* and wp_ajax_nopriv_* values, then use has_action() to see if anything is hooked in.



Only top voted, non community-wiki answers of a minimum length are eligible