Support

Home Forums Event Espresso Premium How to declare 'EE_SPCO_Reg_Step_Attendee_Information.class' as usable?

How to declare 'EE_SPCO_Reg_Step_Attendee_Information.class' as usable?

Posted: December 8, 2018 at 3:29 pm


info@bhaa.ie

December 8, 2018 at 3:29 pm

Hi,

I’m trying to customise the EventEspresso ‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’ action. My plugin code declares


add_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end',
$this,'bhaa_process_wpuser_for_attendee',11,5
);

which then invokes my implementation function, that has this signature


function bhaa_process_wpuser_for_attendee(EE_SPCO_Reg_Step_Attendee_Information $spco, $valid_data)

and EE_SPCO_Reg_Step_Attendee_Information is defined within the EventEspresso plugin. I’m getting this error


[08-Dec-2018 14:00:23 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to BHAA\core\eventexpresso\EventExpresso::bhaa_process_wpuser_for_attendee() must
be an instance of BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information, instance of EE_SPCO_Reg_Step_Attendee_Information given,
called in /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php on line 286 and defined in /home/bhaa/projects/bhaa_wordpress_plugin/src/core/eventexpresso/EventExpresso.php:61
Stack trace:
#0 /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php(286): BHAA\core\eventexpresso\EventExpresso->bhaa_process_wpuser_for_attendee(Object(EE_SPCO_Reg_Step_Attendee_Information), Array)
#1 /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#2 /home/bhaa/projects/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /home/bhaa/projects/wordpress/wp-content/plugins/event-espresso-core-reg/modules/single_page_checkout/reg_steps/attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.ph in /home/bhaa/projects/bhaa_wordpress_plugin/src/core/eventexpresso/EventExpresso.php on line 61

I suspect i need to ‘import’ or declare in my php class a ‘use’ declaration to the ‘EE_SPCO_Reg_Step_Attendee_Information’ class but i’m unsure how to handle this with PSR-4 namespacing. Any help would be appreciated.


info@bhaa.ie

December 8, 2018 at 3:59 pm

To be clear, my plugin uses composer to build it’s autoload classpath. I guess the question become, how can i add the event espresso classes i need to the composer autoloader.


Tony

  • Support Staff

December 10, 2018 at 5:40 am

Hi there,

Your function is declaring the type of object required:

function bhaa_process_wpuser_for_attendee(EE_SPCO_Reg_Step_Attendee_Information $spco, $valid_data)

Remove EE_SPCO_Reg_Step_Attendee_Information from the above as it’s looking within your own classes namespace for that class, which is why you get this error:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to BHAA\core\eventexpresso\EventExpresso::bhaa_process_wpuser_for_attendee() must
be an instance of BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information, instance of EE_SPCO_Reg_Step_Attendee_Information given,

It’s saying the object given to the hook is an instance of EE_SPCO_Reg_Step_Attendee_Information rather than an instance of your BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information

Either remove that and check $spco is instanceof EE_SPCO_Reg_Step_Attendee_Information within your function:

if(! $spco instanceof EE_SPCO_Reg_Step_Attendee_Information ) {
    return
}

Or tell your class to use the EE namespace, unless I’m mistaken you should be able to just add:

use EventEspresso\core\services\loaders\LoaderFactory;

To the begging of the file to include those, I’ll check with our developers on this.


info@bhaa.ie

December 10, 2018 at 2:54 pm

Hi Tony,
Yes, removing the EE_SPCO_Reg_Step_Attendee_Information class name from the method signature avoids the initial fatal error. I did add the ‘use …LoaderFactory’ but it doesn’t help. I believe i need to declare ‘eventespresso/event-espresso-core’ within my composer.json file, this will ensure there is a version of the EE_SPCO_Reg_Step_Attendee_Information class available on my classpath. Any advice on this would be appreciated.


Tony

  • Support Staff

December 11, 2018 at 6:59 am

I checked with the developers and the only change you need to make is to add \ to the EE class name so it uses the root namespace.

Or add use EE_SPCO_Reg_Step_Attendee_Information; (preferable) to the top of the file as then you know it’s using another namespace straight away.

I believe i need to declare ‘eventespresso/event-espresso-core’ within my composer.json file, this will ensure there is a version of the EE_SPCO_Reg_Step_Attendee_Information class available on my classpath.

This won’t help, it’s not an issue with your composer config, it’s incorrect usage of a class.

Any non-namespaced implementations within your namespaced class are assumed to be from that namespace, EE_SPCO_Reg_Step_Attendee_Information is not, it’s in the root namespace so you need to declare namespace, either by adding \ to the class or importing with use above.


info@bhaa.ie

December 11, 2018 at 2:59 pm

Tony,

Thanks for that. I still had issues with the suggested solutions. At this stage I’m going to use the ‘FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item’ filter since it passes me the required data in a standard php array.
Best Regards and this thread can be closed.
Paul

The support post ‘How to declare 'EE_SPCO_Reg_Step_Attendee_Information.class' as usable?’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  info@bhaa.ie 1 day, 8 hours ago ago

Topic Tags

Notifications

This topic is: resolved
Do NOT follow this link or you will be banned from the site!