initialize_admin() ->add_action( 'plugins_loaded', function() { $manager = \AsasVirtuaisWP\WCAddCustomer\Manager::instance(); // Check for WooCommerce being active if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { $manager->admin_warning( __( 'The plugin "WC Add Customer" needs the plugin WooCommerce to be active in order to work.', 'wc-add-customer' ) ); return; } // Hook to menu $manager->add_action( 'admin_menu', function() { // Add users page 'Add Customer' add_users_page( __( 'Add Customer', 'wc-add-customer' ), __( 'Add Customer', 'wc-add-customer' ), 'create_users', 'asas-add-customer', function() { // Another try catch try { $manager = \AsasVirtuaisWP\WCAddCustomer\Manager::instance(); // Prepare the modifications to user-new.php via multiple hooks ( new \AsasVirtuaisWP\WCAddCustomer\CustomerProfile( $manager ) ) ->init_hooks() ->set_default_role() ->enqueue_wc_assets(); // Include user-new.php include_once ABSPATH.'/wp-admin/user-new.php'; // Restore default role do_action( 'asas\wc_add_customer\restore_role' ); } catch (\Throwable $th) { // Try to restore default role just in case do_action( 'asas\wc_add_customer\restore_role' ); // Warn admin echo __( 'An error occured', 'wc-add-customer' ); echo '
' . $manager->get_error_details( $th ) . '
'; } }, 2 ); } ); } ); } catch ( \Throwable $th ) { // Only let the crash happen if WP_DEBUG is true if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) { throw $th; } }