add_action where function has arguments

WordPress core and third-party plugins can trigger events during the execution of their respective code. When you call add_action on um_members_just_after_name, you’re saying: Whenever this um_members_just_after_name action runs, go ahead and run my function my_members_after_user_name, too. That said, $user_id must be supplied by um_members_just_after_name, in other words, if um_members_just_after_name doesn’t exist or doesn’t supply $user_id, … Read more

Postback redirect through add_action is not triggered

Let’s say your site’s address is example.com. When you want to redirect to example.com/page/subpage you should use site_url(‘/page/subpage’). I assume the WordPress address is http://127.0.0.1:8000. You have in your code site_url( ‘http://127.0.0.1:8000/?page_id=5’ ) and it will be converted to this address: http://127.0.0.1:8000http://127.0.0.1:8000/?page_id=5. Try using this redirection: wp_safe_redirect( site_url( ‘/?page_id=5′ ) ); Second issue, if you’ll … Read more

add action for wordpress query at a specific position

Yes, absolutely, it is possible. And here’s an example: Use an action and pass the post’s position in the loop to the action’s callback/function, and let the callback run the conditional and display the image if applicable. $position = 1; // start at 1 while ( have_posts() ) : the_post(); the_title( ‘<h3>’, ‘</h3>’ ); // … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

How can I see exactly what arguments are being passed through a filter so that I may modify them?

Perhaps you could push the variable contents to error log for later inspection? Like so, function addFilter($views) { // error_log is native php function to log stuff // print_r prints human-readable information about a variable, // print_r second parameter makes the function return result instead of echoing it error_log( print_r( $views, true ) ); return … Read more

add_action in wp_head accessible from class

You’re using the static class method call when supplying a callable/callback to add_action(): add_action( ‘wp_head’, array( ‘test_class’, ‘greeting_head’ ) ); So you should make the greeting_head() a static method in your test_class class. But you’d also need to make the greeting() a static method: class test_class { public static function greeting() { echo ‘Howdy! Test … Read more