added, and only saves the same options the settings * screens save, so skipping it or running it again never breaks anything. */ class WPSunshine_Address_Autocomplete_Setup { public function __construct() { add_action( 'admin_init', array( $this, 'maybe_redirect' ) ); add_action( 'admin_init', array( $this, 'save_step' ) ); add_action( 'wps_aa_setup_page', array( $this, 'page' ) ); add_action( 'wps_aa_setup_step_google', array( $this, 'step_google' ) ); add_action( 'wps_aa_setup_step_integrations', array( $this, 'step_integrations' ) ); add_action( 'wps_aa_setup_step_done', array( $this, 'step_done' ) ); add_action( 'wps_aa_setup_save_google', array( $this, 'save_google' ) ); add_action( 'wps_aa_setup_integrations_list', array( $this, 'integrations_promo' ) ); } /** * The steps in order. Premium adds its license step in front. */ public static function steps() { return apply_filters( 'wps_aa_setup_steps', array( 'google' => __( 'Google', 'address-autocomplete-anything' ), 'integrations' => __( 'Integrations', 'address-autocomplete-anything' ), 'done' => __( 'Done', 'address-autocomplete-anything' ), ) ); } public static function url( $step = '' ) { if ( ! $step ) { $step = array_key_first( self::steps() ); } return admin_url( 'options-general.php?page=wps_aa&wps_aa_setup=' . $step ); } /** * Plugins Address Autocomplete connects to, and whether each is active here. * The addon keys are what gets saved in wps_aa_addons when one is turned on. */ public static function integration_plugins() { return apply_filters( 'wps_aa_integration_plugins', array( 'woocommerce' => array( 'name' => 'WooCommerce', 'active' => class_exists( 'WooCommerce' ), 'addons' => array( 'woocommerce_checkout', 'woocommerce_myaccount' ), 'doc' => 'how-to-enable-address-autocomplete-in-woocommerce', ), 'edd' => array( 'name' => 'Easy Digital Downloads', 'active' => class_exists( 'Easy_Digital_Downloads' ), 'addons' => array( 'edd_checkout', 'edd_myaccount' ), 'doc' => 'how-to-enable-address-autocomplete-on-easy-digital-downloads', ), 'gravityforms' => array( 'name' => 'Gravity Forms', 'active' => class_exists( 'GFForms' ), 'addons' => array(), 'note' => __( 'Turned on per address field, in the field\'s Advanced settings in Gravity Forms.', 'address-autocomplete-anything' ), 'doc' => 'how-to-enable-address-autocomplete-on-gravity-forms', ), 'lifterlms' => array( 'name' => 'LifterLMS', 'active' => class_exists( 'LifterLMS' ), 'addons' => array( 'lifterlms_purchase' ), 'doc' => 'how-to-enable-address-autocomplete-on-lifterlms', ), 'paidmembershipspro' => array( 'name' => 'Paid Memberships Pro', 'active' => defined( 'PMPRO_VERSION' ), 'addons' => array( 'paidmembershipspro' ), 'doc' => 'how-to-enable-address-autocomplete-on-paid-memberships-pro', ), 'charitable' => array( 'name' => 'Charitable', 'active' => class_exists( 'Charitable' ), 'addons' => array( 'charitable_donation', 'charitable_profile' ), 'doc' => 'how-to-enable-address-autocomplete-on-charitable', ), 'fluentcart' => array( 'name' => 'FluentCart', 'active' => defined( 'FLUENTCART_VERSION' ), 'addons' => array( 'fluentcart_checkout' ), 'doc' => 'how-to-enable-address-autocomplete-on-fluentcart', ), 'givewp' => array( 'name' => 'GiveWP', 'active' => class_exists( 'Give' ), 'addons' => array( 'givewp' ), 'note' => __( 'Works on forms made with the visual form builder that have a Billing Address block.', 'address-autocomplete-anything' ), 'doc' => 'how-to-enable-address-autocomplete-on-givewp', ), 'tutor' => array( 'name' => 'Tutor LMS', 'active' => function_exists( 'tutor' ), 'addons' => array( 'tutor_checkout' ), 'note' => __( 'Works on Tutor\'s own checkout. Stores that sell courses through WooCommerce or Easy Digital Downloads use those integrations instead.', 'address-autocomplete-anything' ), 'doc' => 'how-to-enable-address-autocomplete-on-tutor-lms', ), 'memberpress' => array( 'name' => 'MemberPress', 'active' => defined( 'MEPR_VERSION' ), 'addons' => array( 'memberpress_signup', 'memberpress_account' ), 'note' => __( 'Needs the address fields shown in MemberPress, under Settings > Fields: tick "Show on Signup", "Show on Account", or both.', 'address-autocomplete-anything' ), 'doc' => 'how-to-enable-address-autocomplete-on-memberpress', ), 'paymattic' => array( 'name' => 'Paymattic', 'active' => defined( 'WPPAYFORM_VERSION' ), 'addons' => array(), 'note' => __( 'Turned on per Address field, in the field\'s Advanced settings in Paymattic.', 'address-autocomplete-anything' ), 'doc' => 'how-to-enable-address-autocomplete-on-paymattic', ), ) ); } /** * Send people to the wizard the first time the plugin is turned on. * Updates never trigger this, and neither does a site that already has a * Google API key saved. */ public function maybe_redirect() { if ( ! get_transient( 'wps_aa_activated' ) ) { return; } delete_transient( 'wps_aa_activated' ); if ( isset( $_GET['activate-multi'] ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { return; } // Already set up, like a free user moving to Premium. Premium uses this // filter to send them to the License tab when there is no license yet. if ( get_option( 'wps_aa_onboarding' ) || get_option( 'wps_aa_google_api_key' ) ) { $url = apply_filters( 'wps_aa_activation_redirect', '' ); if ( $url ) { wp_safe_redirect( $url ); exit; } return; } update_option( 'wps_aa_onboarding', 'shown', false ); wp_safe_redirect( self::url() ); exit; } public function save_step() { if ( ! isset( $_POST['wps_aa_setup'] ) || ! wp_verify_nonce( $_POST['wps_aa_setup'], 'wps_aa_setup' ) || ! current_user_can( 'manage_options' ) ) { return; } $steps = array_keys( self::steps() ); $step = isset( $_POST['step'] ) ? sanitize_key( $_POST['step'] ) : ''; if ( ! in_array( $step, $steps, true ) ) { return; } // A save handler that finds a problem (a bad license key, say) returns // false from this filter to keep people on the same step. $ok = true; if ( empty( $_POST['skip'] ) ) { do_action( 'wps_aa_setup_save_' . $step ); $ok = apply_filters( 'wps_aa_setup_save_ok', true, $step ); } if ( ! $ok ) { return; } $next = $steps[ min( array_search( $step, $steps, true ) + 1, count( $steps ) - 1 ) ]; wp_safe_redirect( self::url( $next ) ); exit; } public function save_google() { if ( isset( $_POST['google_api_key'] ) ) { update_option( 'wps_aa_google_api_key', sanitize_text_field( $_POST['google_api_key'] ) ); } if ( isset( $_POST['places_api'] ) ) { update_option( 'wps_aa_places_api', ( $_POST['places_api'] === 'legacy' ) ? 'legacy' : 'new' ); } } public function page() { $steps = self::steps(); $step = sanitize_key( $_GET['wps_aa_setup'] ); if ( ! isset( $steps[ $step ] ) ) { $step = array_key_first( $steps ); } if ( $step == 'done' ) { update_option( 'wps_aa_onboarding', 'done', false ); } $position = array_search( $step, array_keys( $steps ), true ); ?>