Skip to main content
fix typo; improve text;
Source Link
Celso Bessa
  • 1.1k
  • 8
  • 18

If I am not missing something here, you could haveahave a third/main function, with two different wrappers for it.

function wpse381184_main(){
    //do your thing!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action('acf/save_post', 'my_acf_save_post');

If you need wpse381184_main to use different number of arguments depending on the calling wrapper, you could structure it with the case with more arguments, and simply ignore itsome arguments depending which hook called it, by using the current_filter() function.

function wpse381184_main($post_id, $hook, AC\Column $column, $value){
    if( 'acp/editing/saved' ===  $hook){
        //do your thing in case A and exit!
        return;
    }
    // do your thing in "default" case B!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main($post_id, current_filter());
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    wpse381184_main($post_id, current_filter());
}
add_action('acf/save_post', 'my_acf_save_post');

If I am not missing something here, you could havea third/main function, with two different wrappers for it.

function wpse381184_main(){
    //do your thing!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action('acf/save_post', 'my_acf_save_post');

If you need wpse381184_main to use different arguments, you could structure it with the case with more arguments, and simply ignore it depending which hook called it by using the current_filter() function.

function wpse381184_main($post_id, $hook, AC\Column $column, $value){
    if( 'acp/editing/saved' ===  $hook){
        //do your thing in case A and exit!
        return;
    }
    // do your thing in "default" case B!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main($post_id, current_filter());
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    wpse381184_main($post_id, current_filter());
}
add_action('acf/save_post', 'my_acf_save_post');

If I am not missing something here, you could have a third/main function, with two different wrappers for it.

function wpse381184_main(){
    //do your thing!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action('acf/save_post', 'my_acf_save_post');

If you need wpse381184_main to use different number of arguments depending on the calling wrapper, you could structure it with the case with more arguments, and simply ignore some arguments depending which hook called it, by using the current_filter() function.

function wpse381184_main($post_id, $hook, AC\Column $column, $value){
    if( 'acp/editing/saved' ===  $hook){
        //do your thing in case A and exit!
        return;
    }
    // do your thing in "default" case B!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main($post_id, current_filter());
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    wpse381184_main($post_id, current_filter());
}
add_action('acf/save_post', 'my_acf_save_post');
Source Link
Celso Bessa
  • 1.1k
  • 8
  • 18

If I am not missing something here, you could havea third/main function, with two different wrappers for it.

function wpse381184_main(){
    //do your thing!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    // call wpse381184_main()
    wpse381184_main();
}
add_action('acf/save_post', 'my_acf_save_post');

If you need wpse381184_main to use different arguments, you could structure it with the case with more arguments, and simply ignore it depending which hook called it by using the current_filter() function.

function wpse381184_main($post_id, $hook, AC\Column $column, $value){
    if( 'acp/editing/saved' ===  $hook){
        //do your thing in case A and exit!
        return;
    }
    // do your thing in "default" case B!
}

function acp_editing_saved_usage1( AC\Column $column, $post_id, $value ) {
    // call wpse381184_main()
    wpse381184_main($post_id, current_filter());
}
add_action( 'acp/editing/saved', 'acp_editing_saved_usage', 10, 3 );
function my_acf_save_post( $post_id ) {
    wpse381184_main($post_id, current_filter());
}
add_action('acf/save_post', 'my_acf_save_post');