wordpress - Run one specific action of an action function in PHP
Background:
in my WordPress theme I have the below action functions, which consolidate several hooks, e.g. several functions are consolidated into:
'single_job_listing_meta_start'
public static function template_tags() {
add_action( 'single_job_listing_start', array( __CLASS__, 'single_job_listing_start' ), 10 );
add_action( 'listify_single_job_listing_meta', array( __CLASS__, 'enqueue_scripts' ) );
add_action( 'listify_single_job_listing_meta', array( __CLASS__, 'single_job_listing_meta' ) );
add_action( 'single_job_listing_meta_start', array( __CLASS__, 'the_secondary_image' ), 7 );
add_action( 'single_job_listing_meta_start', 'listify_the_listing_title', 10 );
add_action( 'single_job_listing_meta_start', 'listify_the_listing_location', 20 );
add_action( 'single_job_listing_meta_start', 'listify_the_listing_category', 30 );
add_action( 'single_job_listing_meta_after', 'listify_the_listing_rating' );
add_action( 'listify_single_job_listing_actions', array( __CLASS__, 'the_actions' ) );
add_action( 'listify_single_job_listing_actions_after', array( __CLASS__, 'submit_review_link' ) );
add_action( 'listify_single_job_listing_cover_end', array( __CLASS__, 'cover_gallery' ) );
}
Desired outcome
However, I actually need the more granular functions behind it, i.e.
array( __CLASS__, 'the_secondary_image' )
'listify_the_listing_title'
'listify_the_listing_location'
'listify_the_listing_category'
'listify_the_listing_rating'
Solution attempt
By trying I was able to execute the last 4 hooks of the above, simply via eg
<?php listify_the_listing_rating(); ?>
However, I have two questions:
given these are all hooked (consolidated) into
'single_job_listing_meta_start'
, is there a way to call this (consolidated) action and execute only a specific hook from it? If yes, how would be the code for example?Whilst I was able to execute the above hook functions 2-5 via
<?php listify_the_listing_rating(); ?>
, how would I execute the first hookarray( __CLASS__, 'the_secondary_image'
? I tried<?php array( __CLASS__, 'the_secondary_image') ?>
which didn't work.
Answer
Solution:
I was able to execute the secondary image code with the following:
Listify_WP_Job_Manager_Template_Single_Listing::the_secondary_image();
I believe it refers to the template file (first part of the code) and then the function (second part).
Source