Support

Home Forums Event Espresso Premium Hooking into the private function _duplicate_event()

Hooking into the private function _duplicate_event()

Posted: December 28, 2017 at 9:36 pm


Patrick

December 28, 2017 at 9:36 pm

Hi,

I am trying to hook into the private function _duplicate_event() located in the Extend_Events_Admin_Page.core.php file to allow duplication of ACF custom fields. The following function does not work :

function rc_duplicate_acf_fields( $orig_event, $new_event ) {

$speaker_first_name = esc_html( get_post_meta($orig_event->ID(), ‘prenom’, true) );
if ( $speaker_first_name ) {
update_post_meta($new_event->ID(), ‘prenom’, $speaker_first_name);
}
}
add_action( ‘AHEE__Extend_Events_Admin_Page___duplicate_event__after’, ‘rc_duplicate_acf_fields’ );

I have tries several priorities without success. Am I to simplistic about hooking into the private function _duplicate_event() ? Or should I start to learn OOP and try to extend the Extend_Events_Admin_Page class ?

Thanks in advance for your help.

Patrick


Tony

  • Support Staff

December 29, 2017 at 2:00 am

Hi Patrick,

If you enable WP_DEBUG on the site and test with the above code it will throw at least 1 notice because:

function rc_duplicate_acf_fields( $orig_event, $new_event )

Your function takes 2 parameters, but:

add_action( ‘AHEE__Extend_Events_Admin_Page___duplicate_event__after’, ‘rc_duplicate_acf_fields’ );

add_action defaults to 1, so you need:

add_action( 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', 'rc_duplicate_acf_fields', 10, 2 );

Try that change and let me know if then works for you.


Patrick

December 29, 2017 at 7:47 am

Thanks Tony !

You are right ! In fact, I forgot to mention that I had already tested with

add_action( 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', 'rc_duplicate_acf_fields', 10, 2 );

But, since one idea leads to another, i found that the arguments where not declared in the right order inside my custom function !

So, this :
function rc_duplicate_acf_fields( $orig_event, $new_event )

should be :
function rc_duplicate_acf_fields( $new_event, $orig_event )

Now, ACF fields are duplicated !

Cheers !

Patrick


Tony

  • Support Staff

December 29, 2017 at 8:17 am

Nice catch!

I’m glad it’s working for you now 🙂

The support post ‘Hooking into the private function _duplicate_event()’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso