f ( 'display' !== $queue ) { $this->admin_classes[ $class ] = true ; } } } /** * Add an array of classes to the queue. * * @since 4.12.6 * * @param array $class The classes to add. * @return void */ public function add_classes( array $classes, $queue = 'display' ) { foreach ( $classes as $key => $value ) { // If the classes are passed as class => bool, only add ones set to true. if ( is_bool( $value ) && false !== $value ) { $this->add_class( $key, $queue ); } else { $this->add_class( $value, $queue ); } } } /** * Remove a single class from the queue. * * @since 4.12.6 * * @param string $class The class to remove. * @return void */ public function remove_class( $class, $queue = 'display' ) { if ( 'admin' !== $queue ) { $this->classes = array_filter( $this->classes, static function( $k ) use ( $class ) { return $k !== $class; }, ARRAY_FILTER_USE_KEY ); } if ( 'display' !== $queue ) { $this->admin_classes = array_filter( $this->admin_classes, static function( $k ) use ( $class ) { return $k !== $class; }, ARRAY_FILTER_USE_KEY ); } } /** * Remove an array of classes from the queue. * * @since 4.12.6 * * @param array $classes The classes to remove. * @return void */ public function remove_classes( array $classes, $queue = 'display' ) { if ( empty( $classes ) || ! is_array( $classes) ) { return; } foreach ( $classes as $class ) { $this->remove_class( $class, $queue ); } } /** * Adds the enqueued classes to the body class array. * * @since 4.12.6 * * @param array $classes An array of body class names. * @return array Array of body classes. */ public function add_body_classes( $classes = [] ) { // Make sure they should be added. if( ! $this->should_add_body_classes( $this->get_class_names(), (array) $classes, 'display' ) ) { return $classes; } $element_classes = new Element_Classes( $this->get_class_names() ); return array_merge( $classes, $element_classes->get_classes() ); } /** * Adds the enqueued classes to the body class array. * * @since 4.12.6 * * @param string $classes The existing body class names. * * @return string String of admin body classes. */ public function add_admin_body_classes( $classes ) { $existing_classes = explode( ' ', $classes ); // Make sure they should be added. if ( ! $this->should_add_body_classes( $this->get_class_names( 'admin' ), (array) $existing_classes, 'admin' ) ) { // Ensure we return the current string on false! return $classes; } $element_classes = new Element_Classes( $this->get_class_names( 'admin' ) ); return implode( ' ', array_merge( $existing_classes, $element_classes->get_classes() ) ); } /** * Should a individual class be added to the queue. * * @since 4.12.6 * * @param string $class The body class we wish to add. * * @return boolean Whether to add tribe body classes to the queue. */ private function should_add_body_class_to_queue( $class, $queue = 'display' ) { /** * Filter whether to add the body class to the queue or not. * * @since 4.12.6 * * @param boolean $add Whether to add the class to the queue or not. * @param array $class The array of body class names to add. * @param string $queue The queue we want to get 'admin', 'display', 'all'. */ return (bool) apply_filters( 'tribe_body_class_should_add_to_queue', false, $class, $queue ); } /** * Logic for whether the body classes, as a whole, should be added. * * @since 4.12.6 * * @param array $add_classes An array of body class names to add. * @param array $existing_classes An array of existing body class names from WP. * @param string $queue The queue we want to get 'admin', 'display', 'all'. * * @return boolean Whether to add tribe body classes. */ private function should_add_body_classes( array $add_classes, array $existing_classes, $queue ) { /** * Filter whether to add tribe body classes or not. * * @since 4.12.6 * * @param boolean $add Whether to add classes or not. * @param string $queue The queue we want to get 'admin', 'display', 'all'. * @param array $add_classes The array of body class names to add. * @param array $existing_classes An array of existing body class names from WP. * */ return (bool)apply_filters( 'tribe_body_classes_should_add', false, $queue, $add_classes, $existing_classes ); } } ( PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( Package::container()->get( Cheque::class ) ); $payment_method_registry->register( Package::container()->get( PayPal::class ) ); $payment_method_registry->register( Package::container()->get( BankTransfer::class ) ); $payment_method_registry->register( Package::container()->get( CashOnDelivery::class ) ); } /** * Verify all dependencies of registered payment methods have been registered. * If not, remove that payment method script from the list of dependencies * of Cart and Checkout block scripts so it doesn't break the blocks and show * an error in the admin. */ public function verify_payment_methods_dependencies() { // Check that the wc-blocks script is registered before continuing. Some extensions may cause this function to run // before the payment method scripts' dependencies are registered. if ( ! wp_script_is( 'wc-blocks', 'registered' ) ) { return; } $wp_scripts = wp_scripts(); $payment_method_scripts = $this->payment_method_registry->get_all_active_payment_method_script_dependencies(); foreach ( $payment_method_scripts as $payment_method_script ) { if ( ! array_key_exists( $payment_method_script, $wp_scripts->registered ) || ! property_exists( $wp_scripts->registered[ $payment_method_script ], 'deps' ) ) { continue; } $deps = $wp_scripts->registered[ $payment_method_script ]->deps; foreach ( $deps as $dep ) { if ( ! wp_script_is( $dep, 'registered' ) ) { $error_handle = $dep . '-dependency-error'; $error_message = sprintf( 'Payment gateway with handle \'%1$s\' has been deactivated in Cart and Checkout blocks because its dependency \'%2$s\' is not registered. Read the docs about registering assets for payment methods: https://github.com/woocommerce/woocommerce-blocks/blob/060f63c04f0f34f645200b5d4da9212125c49177/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md#registering-assets', esc_html( $payment_method_script ), esc_html( $dep ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( $error_message ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion wp_register_script( $error_handle, '' ); wp_enqueue_script( $error_handle ); wp_add_inline_script( $error_handle, sprintf( 'console.error( "%s" );', $error_message ) ); $cart_checkout_scripts = [ 'wc-cart-block', 'wc-cart-block-frontend', 'wc-checkout-block', 'wc-checkout-block-frontend' ]; foreach ( $cart_checkout_scripts as $script_handle ) { if ( ! array_key_exists( $script_handle, $wp_scripts->registered ) || ! property_exists( $wp_scripts->registered[ $script_handle ], 'deps' ) ) { continue; } // Remove payment method script from dependencies. $wp_scripts->registered[ $script_handle ]->deps = array_diff( $wp_scripts->registered[ $script_handle ]->deps, [ $payment_method_script ] ); } } } } } }