diff --git a/src/Tickets/Commerce/Gateways/PayPal/Provider.php b/src/Tickets/Commerce/Gateways/PayPal/Provider.php index 89bae4e5c0..bae120ec2d 100644 --- a/src/Tickets/Commerce/Gateways/PayPal/Provider.php +++ b/src/Tickets/Commerce/Gateways/PayPal/Provider.php @@ -42,7 +42,13 @@ public function register() { */ protected function register_assets() { $assets = new Assets( $this->container ); - $assets->register(); + + // Register assets only after `init` hook has fired. + if ( did_action( 'init' ) || doing_action( 'init' ) ) { + $assets->register(); + } else { + add_action( 'init', [ $assets, 'register' ] ); + } $this->container->singleton( Assets::class, $assets ); } diff --git a/src/Tickets/Commerce/Order_Modifiers/Admin/Order_Modifier_Fee_Metabox.php b/src/Tickets/Commerce/Order_Modifiers/Admin/Order_Modifier_Fee_Metabox.php index ef11743cc6..1ee3a52d84 100644 --- a/src/Tickets/Commerce/Order_Modifiers/Admin/Order_Modifier_Fee_Metabox.php +++ b/src/Tickets/Commerce/Order_Modifiers/Admin/Order_Modifier_Fee_Metabox.php @@ -78,6 +78,14 @@ class Order_Modifier_Fee_Metabox extends Controller_Contract { */ protected Order_Modifier_Relationship $order_modifiers_relationship_repository; + /** + * The order modifiers controller. + * + * @since TBD + * @var Controller + */ + protected Controller $controller; + /** * Constructor to initialize dependencies and set up the modifier strategy and manager. * @@ -98,11 +106,22 @@ public function __construct( ) { parent::__construct( $container ); // Set up the modifier strategy and manager for handling fees. - $this->modifier_strategy = $controller->get_modifier( $this->modifier_type ); + $this->controller = $controller; $this->manager = $manager; // Set up the order modifiers repository for accessing fee data. $this->order_modifiers_relationship_repository = $order_modifier_relationship; + + add_action( 'init', [ $this, 'set_modifier_strategy' ] ); + } + + /** + * Sets the modifier strategy for applying fees. + * + * @since TBD + */ + public function set_modifier_strategy() { + $this->modifier_strategy = $this->controller->get_modifier( $this->modifier_type ); } /** diff --git a/src/Tickets/Commerce/Order_Modifiers/Checkout/Abstract_Fees.php b/src/Tickets/Commerce/Order_Modifiers/Checkout/Abstract_Fees.php index 2f995808b5..afb1b427ca 100644 --- a/src/Tickets/Commerce/Order_Modifiers/Checkout/Abstract_Fees.php +++ b/src/Tickets/Commerce/Order_Modifiers/Checkout/Abstract_Fees.php @@ -102,6 +102,14 @@ abstract class Abstract_Fees extends Controller_Contract { */ protected static bool $fees_appended = false; + /** + * The order modifiers controller. + * + * @since TBD + * @var Controller + */ + protected Controller $controller; + /** * Constructor * @@ -124,10 +132,21 @@ public function __construct( Modifier_Manager $manager ) { parent::__construct( $container ); - $this->modifier_strategy = $controller->get_modifier( $this->modifier_type ); + $this->controller = $controller; $this->manager = $manager; $this->order_modifiers_repository = $fee_repository; $this->order_modifiers_relationship_repository = $order_modifier_relationship; + + add_action( 'init', [ $this, 'set_modifier_strategy' ] ); + } + + /** + * Sets the modifier strategy for applying fees. + * + * @since TBD + */ + public function set_modifier_strategy() { + $this->modifier_strategy = $this->controller->get_modifier( $this->modifier_type ); } /** diff --git a/src/Tickets/Seating/Health.php b/src/Tickets/Seating/Health.php index 9c2b13597a..c644353364 100644 --- a/src/Tickets/Seating/Health.php +++ b/src/Tickets/Seating/Health.php @@ -57,8 +57,6 @@ class Health extends Controller_Contract { */ public function __construct( Container $container ) { parent::__construct( $container ); - - $this->define_tests(); } /** @@ -68,7 +66,7 @@ public function __construct( Container $container ) { * * @return void */ - protected function define_tests() { + public function define_tests() { $set_license_url = tribe( Settings::class )->get_url( [ 'tab' => 'licenses' ] ); $this->tests = [ @@ -174,6 +172,7 @@ public function get_tests(): array { * @return void */ public function unregister(): void { + remove_action( 'init', [ $this, 'define_tests' ] ); remove_filter( 'site_status_tests', [ $this, 'add_site_status_tests' ] ); foreach ( $this->get_tests() as $callback => $test ) { @@ -189,6 +188,7 @@ public function unregister(): void { * @return void */ protected function do_register(): void { + add_action( 'init', [ $this, 'define_tests' ] ); add_filter( 'site_status_tests', [ $this, 'add_site_status_tests' ] ); foreach ( $this->get_tests() as $callback => $test ) { diff --git a/src/Tickets/Seating/Uplink.php b/src/Tickets/Seating/Uplink.php index 903b203bee..52e4f45df4 100644 --- a/src/Tickets/Seating/Uplink.php +++ b/src/Tickets/Seating/Uplink.php @@ -58,7 +58,6 @@ class Uplink extends Controller_Contract { public function __construct( Container $container ) { parent::__construct( $container ); $this->et_main = Main::instance(); - $this->et_slr_plugin_name = _x( 'Seating', 'Header of the connection controls', 'event-tickets' ); } /** @@ -67,6 +66,7 @@ public function __construct( Container $container ) { * @since 5.16.0 */ public function do_register(): void { + add_action( 'init', [ $this, 'set_slr_plugin_name' ], 9 ); add_action( 'init', [ $this, 'register_plugin' ] ); add_filter( 'stellarwp/uplink/tec/tec-seating/view/authorize_button/link_text', @@ -78,6 +78,15 @@ public function do_register(): void { add_action( 'stellarwp/uplink/tec/tec-seating/connected', [ $this, 'reset_data_on_new_connection' ] ); } + /** + * Set the SLR plugin name. + * + * @since TBD + */ + public function set_slr_plugin_name(): void { + $this->et_slr_plugin_name = _x( 'Seating', 'Header of the connection controls', 'event-tickets' ); + } + /** * Unregister the controller. * @@ -86,6 +95,7 @@ public function do_register(): void { * @return void */ public function unregister(): void { + remove_action( 'init', [ $this, 'set_slr_plugin_name' ], 9 ); remove_action( 'init', [ $this, 'register_plugin' ] ); remove_filter( 'stellarwp/uplink/tec/tec-seating/view/authorize_button/link_text', diff --git a/src/Tribe/Commerce/Currency.php b/src/Tribe/Commerce/Currency.php index f117d16bfe..79a1eb3a90 100644 --- a/src/Tribe/Commerce/Currency.php +++ b/src/Tribe/Commerce/Currency.php @@ -18,7 +18,11 @@ class Tribe__Tickets__Commerce__Currency { * @since 4.7 */ public function __construct() { - $this->generate_default_currency_map(); + if ( did_action( 'init' ) || doing_action( 'init' ) ) { + $this->generate_default_currency_map(); + } else { + add_action( 'init', [ $this, 'generate_default_currency_map' ], 1 ); + } } /** diff --git a/src/Tribe/Commerce/PayPal/Main.php b/src/Tribe/Commerce/PayPal/Main.php index 28e6d08101..0684192f83 100644 --- a/src/Tribe/Commerce/PayPal/Main.php +++ b/src/Tribe/Commerce/PayPal/Main.php @@ -185,7 +185,6 @@ public function __construct() { $main = Tribe__Tickets__Main::instance(); /* Set up some parent's vars */ - $this->plugin_name = esc_html_x( 'Tribe Commerce', 'ticket provider', 'event-tickets' ); $this->plugin_path = $main->plugin_path; $this->plugin_url = $main->plugin_url; @@ -299,6 +298,7 @@ public function bind_implementations() { * @since 4.7 */ public function hooks() { + add_action( 'init', [ $this, 'set_plugin_name' ], 9 ); // if the hooks have already been bound, don't do it again if ( $this->is_loaded ) { return false; @@ -373,6 +373,15 @@ public function hooks() { add_filter( 'tec_cache_listener_save_post_types', [ $this, 'filter_cache_listener_save_post_types' ] ); } + /** + * Sets the RSVPs plugin name. + * + * @since TBD + */ + public function set_plugin_name() { + $this->plugin_name = esc_html_x( 'Tribe Commerce', 'ticket provider', 'event-tickets' ); + } + /** * Hooked to the init action * diff --git a/src/Tribe/Main.php b/src/Tribe/Main.php index b99756535d..374be874ce 100644 --- a/src/Tribe/Main.php +++ b/src/Tribe/Main.php @@ -175,7 +175,6 @@ public static function instance() { */ protected function __construct() { // Set up some of the plugin's properties. - $this->plugin_name = esc_html_x( 'Tickets', 'provider_plugin_name', 'event-tickets' ); $this->plugin_slug = 'tickets'; $this->plugin_path = trailingslashit( EVENT_TICKETS_DIR ); $this->plugin_dir = trailingslashit( basename( $this->plugin_path ) ); @@ -187,14 +186,25 @@ protected function __construct() { $this->plugin_url = trailingslashit( plugins_url( $dir_prefix . $this->plugin_dir ) ); } + /** + * Set the plugin name. + * + * @since TBD + */ + public function set_plugin_name() { + $this->plugin_name = esc_html_x( 'Tickets', 'provider_plugin_name', 'event-tickets' ); + } + /** * Attach our initial hooks and filters * * @since 5.18.0 + * @since TBD Called `set_plugin_name` on `init` hook. * * @return void */ public function do_hooks() { + add_action( 'init', [ $this, 'set_plugin_name' ] ); add_filter( 'tribe_events_integrations_should_load_freemius', '__return_false' ); $this->maybe_set_common_lib_info(); diff --git a/src/Tribe/REST/V1/Messages.php b/src/Tribe/REST/V1/Messages.php index 7d54fa3182..2b90688924 100644 --- a/src/Tribe/REST/V1/Messages.php +++ b/src/Tribe/REST/V1/Messages.php @@ -20,6 +20,17 @@ class Tribe__Tickets__REST__V1__Messages implements Tribe__REST__Messages_Interf * */ public function __construct() { + add_action( 'init', [ $this, 'set_messages' ] ); + } + + /** + * Sets the messages handled by the class. + * + * @since TBD + * + * @return void + */ + public function set_messages() { $this->messages = [ 'missing-attendee-id' => __( 'The attendee ID is missing from the request', 'event-tickets' ), 'attendee-not-found' => __( 'The requested post ID does not exist or is not an attendee', 'event-tickets' ), diff --git a/src/Tribe/RSVP.php b/src/Tribe/RSVP.php index 0c927e4bb7..9a0af2165d 100644 --- a/src/Tribe/RSVP.php +++ b/src/Tribe/RSVP.php @@ -202,7 +202,6 @@ public function __construct() { $main = Tribe__Tickets__Main::instance(); $this->tickets_view = Tribe__Tickets__Tickets_View::instance(); /* Set up parent vars */ - $this->plugin_name = $this->pluginName = esc_html( tribe_get_rsvp_label_plural( 'provider_plugin_name' ) ); $this->plugin_path = $this->pluginPath = $main->plugin_path; $this->plugin_url = $this->pluginUrl = $main->plugin_url; @@ -228,6 +227,7 @@ public function __construct() { * Registers all actions/filters */ public function hooks() { + add_action( 'init', [ $this, 'set_plugin_name' ], 9 ); add_action( 'wp_enqueue_scripts', [ $this, 'register_resources' ], 5 ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_resources' ], 11 ); add_action( 'trashed_post', [ $this, 'maybe_redirect_to_attendees_report' ] ); @@ -258,6 +258,16 @@ public function hooks() { add_filter( 'tec_cache_listener_save_post_types', [ $this, 'filter_cache_listener_save_post_types' ] ); } + /** + * Sets the RSVPs plugin name. + * + * @since TBD + */ + public function set_plugin_name() { + // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase, Squiz.PHP.DisallowMultipleAssignments.Found + $this->plugin_name = $this->pluginName = esc_html( tribe_get_rsvp_label_plural( 'provider_plugin_name' ) ); + } + /** * Handle RSVP processing for the RSVP forms. * diff --git a/src/Tribe/Tickets_Handler.php b/src/Tribe/Tickets_Handler.php index 1cd8eb279d..399d66ae9c 100644 --- a/src/Tribe/Tickets_Handler.php +++ b/src/Tribe/Tickets_Handler.php @@ -106,20 +106,29 @@ class Tribe__Tickets__Tickets_Handler { * Class constructor. */ public function __construct() { - $this->unlimited_term = __( 'Unlimited', 'event-tickets' ); - $this->add_hooks(); $this->path = trailingslashit( dirname( dirname( dirname( __FILE__ ) ) ) ); } + /** + * Set the unlimited term name + * + * @since TBD + */ + public function set_unlimited_term_name() { + $this->unlimited_term = __( 'Unlimited', 'event-tickets' ); + } + /** * Add hooks for saving/meta. * * @since 4.11.4 + * @since TBD Added the `set_unlimited_term_name` method to set the unlimited term name. */ public function add_hooks() { $main = Tribe__Tickets__Main::instance(); + add_action( 'init', [ $this, 'set_unlimited_term_name' ] ); foreach ( $main->post_types() as $post_type ) { add_action( 'save_post_' . $post_type, [ $this, 'save_post' ] ); diff --git a/tests/slr_integration/Health_Test.php b/tests/slr_integration/Health_Test.php index 010ab3b696..67d660f180 100644 --- a/tests/slr_integration/Health_Test.php +++ b/tests/slr_integration/Health_Test.php @@ -29,6 +29,7 @@ class Health_Test extends Controller_Test_Case { public function it_should_add_slr_tests() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $tests = $controller->get_tests(); @@ -56,6 +57,7 @@ public function it_should_fail_when_no_nonce() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $this->expectException( \Exception::class ); // Fail because no nonce. @@ -71,6 +73,7 @@ public function it_should_check_slr_valid_license_with_invalid_license() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $wp_send_json_error = $this->mock_wp_send_json_error(); $wp_send_json_success = $this->mock_wp_send_json_success(); @@ -95,6 +98,7 @@ public function it_should_check_slr_valid_license() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $_REQUEST['_ajax_nonce'] = wp_create_nonce( self::NONCE_ACTION ); @@ -120,6 +124,7 @@ public function it_should_check_slr_can_see_sass_when_sass_unavailable() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $wp_send_json_error = $this->mock_wp_send_json_error(); $wp_send_json_success = $this->mock_wp_send_json_success(); @@ -145,6 +150,7 @@ public function it_should_check_slr_can_see_sass_when_sass_available() { $controller = $this->make_controller(); $controller->register(); + $controller->define_tests(); $wp_send_json_error = $this->mock_wp_send_json_error(); $wp_send_json_success = $this->mock_wp_send_json_success();