, * and for an admin that page shows a bar where they click the address fields * instead of typing CSS selectors. assets/js/picker.js sends the picks back to * the settings screen, which fills in the setup for the admin to check and save. */ class WPSunshine_Address_Autocomplete_Picker { public function __construct() { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ) ); } public static function is_active() { return ! is_admin() && isset( $_GET['wps_aa_picker'] ) && current_user_can( 'manage_options' ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['wps_aa_picker'] ) ), 'wps_aa_picker' ); } public function enqueue() { if ( ! self::is_active() ) { return; } // Address suggestions would get in the way of clicking fields add_filter( 'wps_aa_load_scripts', '__return_false' ); $version = ( defined( 'WPS_AA_PREMIUM_VERSION' ) ) ? WPS_AA_PREMIUM_VERSION : WPS_AA_VERSION; wp_enqueue_style( 'wps-aa-picker', WPS_AA_URL . 'assets/css/picker.css', array(), $version ); wp_enqueue_script( 'wps-aa-picker', WPS_AA_URL . 'assets/js/picker.js', array(), $version, true ); // The picks go back to the settings screen, which may be on another address than the site $admin = wp_parse_url( admin_url() ); wp_localize_script( 'wps-aa-picker', 'wps_aa_picker', array( 'admin_origin' => $admin['scheme'] . '://' . $admin['host'] . ( ! empty( $admin['port'] ) ? ':' . $admin['port'] : '' ), 'i18n' => array( 'title' => __( 'Address Autocomplete', 'address-autocomplete-anything' ), 'find_street' => __( 'Click the field where people type their street address.', 'address-autocomplete-anything' ), 'found' => __( 'These look like the address fields. Check the tags, then click Done. To change one, click the field.', 'address-autocomplete-anything' ), 'change' => __( 'Check the tags, then click Done. To change one, click the field.', 'address-autocomplete-anything' ), 'click_role' => __( 'Click the %s field.', 'address-autocomplete-anything' ), 'which' => __( 'What is this field?', 'address-autocomplete-anything' ), 'not_address' => __( 'Not an address field', 'address-autocomplete-anything' ), 'paused' => __( 'Paused. Use the page as normal, for example to open a popup or go to the next step, then click Resume.', 'address-autocomplete-anything' ), 'sent' => __( 'Sent to your settings. Check the fields there, then save.', 'address-autocomplete-anything' ), 'no_opener' => __( 'Start from Settings > Address Autocomplete > Pick fields on my page, so your picks can be sent back.', 'address-autocomplete-anything' ), 'pause' => __( 'Pause', 'address-autocomplete-anything' ), 'resume' => __( 'Resume', 'address-autocomplete-anything' ), 'cancel' => __( 'Cancel', 'address-autocomplete-anything' ), 'done' => __( 'Done', 'address-autocomplete-anything' ), 'roles' => array( 'address1' => __( 'Street address', 'address-autocomplete-anything' ), 'address2' => __( 'Address line 2', 'address-autocomplete-anything' ), 'city' => __( 'City', 'address-autocomplete-anything' ), 'state' => __( 'State', 'address-autocomplete-anything' ), 'postcode' => __( 'Zip / Postcode', 'address-autocomplete-anything' ), 'country' => __( 'Country', 'address-autocomplete-anything' ), ), ), ) ); } } new WPSunshine_Address_Autocomplete_Picker();