includes(); $this->init_hooks(); } protected function includes() { } protected function init_hooks() { // Add settings page add_action( 'admin_menu', array( $this, 'settings_page_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); // Tabs add_action( 'admin_init', array( $this, 'set_tabs' ) ); // Show settings tab add_action( 'wps_aa_options_tab_settings', array( $this, 'settings_tab' ) ); // Save settings add_action( 'admin_init', array( $this, 'save_options' ) ); add_action( 'admin_notices', array( $this, 'show_notices' ), 999 ); // Header links add_action( 'wps_aa_header_links', array( $this, 'header_links' ) ); } public function settings_page_menu() { add_options_page( __( 'Address Autocomplete', 'address-autocomplete-anything' ), __( 'Address Autocomplete', 'address-autocomplete-anything' ), 'manage_options', 'wps_aa', array( $this, 'options_page' ) ); } public function admin_enqueue_scripts() { if ( isset( $_GET['page'] ) && $_GET['page'] == 'wps_aa' ) { wp_enqueue_style( 'wps-aa-admin', WPS_AA_URL . 'assets/css/admin.css' ); wp_enqueue_script( 'select2', WPS_AA_URL . 'assets/js/select2/select2.min.js', array( 'jquery' ), '4.0.13' ); wp_enqueue_style( 'select2', WPS_AA_URL . 'assets/js/select2/select2.min.css', '4.0.13' ); } } public function is_premium() { return apply_filters( 'wps_aa_premium', false ); } public function set_tabs() { $this->tabs = apply_filters( 'wps_aa_tabs', array( 'settings' => __( 'Settings', 'confetti' ) ) ); $this->tab = array_key_first( $this->tabs ); if ( isset( $_GET['tab'] ) ) { $this->tab = sanitize_key( $_GET['tab'] ); } } public function header_links( $links ) { $links = array( 'documentation' => array( 'url' => 'https://wpsunshine.com/support/', 'label' => 'Documentation' ), 'review' => array( 'url' => 'https://wordpress.org/support/plugin/address-autocomplete-anything/reviews/#new-post', 'label' => 'Write a Review' ), 'feedback' => array( 'url' => 'https://wpsunshine.com/feedback', 'label' => 'Feedback' ), 'upgrade' => array( 'url' => 'https://wpsunshine.com/plugins/address-autocomplete/?utm_source=plugin&utm_medium=banner&utm_content=upgrade&utm_campaign=aa_upgrade', 'label' => 'Upgrade' ) ); return $links; } public function options_page() { $options = WPS_AA()->get_options( true ); ?>
'; foreach ( $header_links as $key => $link ) { echo '' . esc_html( $link['label'] ) . ''; } echo '
'; } ?> tabs ) > 1 ) { ?>

tab ); if ( isset( $_GET['instance'] ) ) { $form_url = add_query_arg( 'instance', $_GET['instance'] ); } ?>
tab ); ?> tab ); ?> tab ); ?>

get_instances(); do_action( 'wps_aa_instances_nav', $instances ); if ( empty( $this->active_instance ) ) { $this->active_instance = isset( $_GET['instance'] ) ? $_GET['instance'] : array_key_first( $instances ); } foreach ( $instances as $key => $instance ) { if ( $this->active_instance != $key ) { continue; } ?>
$field ) { if ( empty( $field['selector'] ) ) { continue; } ?>

or
'; echo ''; foreach ( $pages as $page ) { $selected = in_array($page->ID, (array) $instance['page']) ? ' selected="selected"' : ''; echo ''; } echo ''; ?>
Learn more
get_instances(); $instances = array(); foreach ( $available_instances as $key => $instance ) { // If no data posted, then let's just keep as is if ( empty( $_POST['instance'] ) || $_POST['instance'] != $key ) { $instances[ $key ] = $instance; continue; } $fields = array(); foreach ( $_POST['fields'] as $field ) { if ( empty( $field['selector'] ) ) { continue; } $fields[] = array( 'selector' => isset( $field['selector'] ) ? sanitize_text_field( stripslashes( $field['selector'] ) ) : '', 'data' => isset( $field['data'] ) ? sanitize_text_field( stripslashes( $field['data'] ) ) : '', ); } $instances[ $key ] = array( 'label' => isset( $_POST['label'] ) ? sanitize_text_field( $_POST['label'] ) : '', 'page' => isset( $_POST['allowed_page'] ) ? array_map( 'intval', $_POST['allowed_page'] ) : '', 'init' => isset( $_POST['init'] ) ? sanitize_text_field( stripslashes( $_POST['init'] ) ) : '', 'allowed_countries' => ( !empty( $_POST['allowed_countries'] ) ) ? array_map( 'sanitize_text_field', $_POST['allowed_countries'] ) : '', 'delay' => isset( $_POST['delay'] ) ? sanitize_text_field( $_POST['delay'] ) : '', 'fields' => $fields ); $this->active_instance = $key; } $instances = apply_filters( 'wps_aa_save_instances', $instances ); do_action( 'wps_aa_save_options' ); // If all valid if ( count( self::$errors ) > 0 ) { foreach ( self::$errors as $error ) { $this->add_notice( $error, 'error' ); } } update_option( 'wps_aa_instances', $instances ); if ( isset( $_POST['google_api_key'] ) ) { update_option( 'wps_aa_google_api_key', sanitize_text_field( $_POST['google_api_key'] ) ); } $this->add_notice( __( 'Settings saved!', 'address-autocomplete-anything' ) ); } public static function add_notice( $text, $type = 'success' ) { self::$notices[] = array( 'text' => $text, 'type' => $type ); } public static function show_notices() { if ( !empty( self::$notices ) ) { foreach ( self::$notices as $notice ) { echo '

' . wp_kses_post( $notice['text'] ) . '

'; } } } private function countries() { return array( "AF" => "Afghanistan", "AL" => "Albania", "DZ" => "Algeria", "AS" => "American Samoa", "AD" => "Andorra", "AO" => "Angola", "AI" => "Anguilla", "AQ" => "Antarctica", "AG" => "Antigua and Barbuda", "AR" => "Argentina", "AM" => "Armenia", "AW" => "Aruba", "AU" => "Australia", "AT" => "Austria", "AZ" => "Azerbaijan", "BS" => "Bahamas", "BH" => "Bahrain", "BD" => "Bangladesh", "BB" => "Barbados", "BY" => "Belarus", "BE" => "Belgium", "BZ" => "Belize", "BJ" => "Benin", "BM" => "Bermuda", "BT" => "Bhutan", "BO" => "Bolivia", "BA" => "Bosnia and Herzegovina", "BW" => "Botswana", "BV" => "Bouvet Island", "BR" => "Brazil", "IO" => "British Indian Ocean Territory", "BN" => "Brunei Darussalam", "BG" => "Bulgaria", "BF" => "Burkina Faso", "BI" => "Burundi", "KH" => "Cambodia", "CM" => "Cameroon", "CA" => "Canada", "CV" => "Cape Verde", "KY" => "Cayman Islands", "CF" => "Central African Republic", "TD" => "Chad", "CL" => "Chile", "CN" => "China", "CX" => "Christmas Island", "CC" => "Cocos (Keeling) Islands", "CO" => "Colombia", "KM" => "Comoros", "CG" => "Congo", "CD" => "Congo, the Democratic Republic of the", "CK" => "Cook Islands", "CR" => "Costa Rica", "CI" => "Cote D'Ivoire", "HR" => "Croatia", "CU" => "Cuba", "CY" => "Cyprus", "CZ" => "Czech Republic", "DK" => "Denmark", "DJ" => "Djibouti", "DM" => "Dominica", "DO" => "Dominican Republic", "EC" => "Ecuador", "EG" => "Egypt", "SV" => "El Salvador", "GQ" => "Equatorial Guinea", "ER" => "Eritrea", "EE" => "Estonia", "ET" => "Ethiopia", "FK" => "Falkland Islands (Malvinas)", "FO" => "Faroe Islands", "FJ" => "Fiji", "FI" => "Finland", "FR" => "France", "GF" => "French Guiana", "PF" => "French Polynesia", "TF" => "French Southern Territories", "GA" => "Gabon", "GM" => "Gambia", "GE" => "Georgia", "DE" => "Germany", "GH" => "Ghana", "GI" => "Gibraltar", "GR" => "Greece", "GL" => "Greenland", "GD" => "Grenada", "GP" => "Guadeloupe", "GU" => "Guam", "GT" => "Guatemala", "GN" => "Guinea", "GW" => "Guinea-Bissau", "GY" => "Guyana", "HT" => "Haiti", "HM" => "Heard Island and Mcdonald Islands", "VA" => "Holy See (Vatican City State)", "HN" => "Honduras", "HK" => "Hong Kong", "HU" => "Hungary", "IS" => "Iceland", "IN" => "India", "ID" => "Indonesia", "IR" => "Iran, Islamic Republic of", "IQ" => "Iraq", "IE" => "Ireland", "IL" => "Israel", "IT" => "Italy", "JM" => "Jamaica", "JP" => "Japan", "JO" => "Jordan", "KZ" => "Kazakhstan", "KE" => "Kenya", "KI" => "Kiribati", "KP" => "Korea, Democratic People's Republic of", "KR" => "Korea, Republic of", "KW" => "Kuwait", "KG" => "Kyrgyzstan", "LA" => "Lao People's Democratic Republic", "LV" => "Latvia", "LB" => "Lebanon", "LS" => "Lesotho", "LR" => "Liberia", "LY" => "Libyan Arab Jamahiriya", "LI" => "Liechtenstein", "LT" => "Lithuania", "LU" => "Luxembourg", "MO" => "Macao", "MK" => "Macedonia, the Former Yugoslav Republic of", "MG" => "Madagascar", "MW" => "Malawi", "MY" => "Malaysia", "MV" => "Maldives", "ML" => "Mali", "MT" => "Malta", "MH" => "Marshall Islands", "MQ" => "Martinique", "MR" => "Mauritania", "MU" => "Mauritius", "YT" => "Mayotte", "MX" => "Mexico", "FM" => "Micronesia, Federated States of", "MD" => "Moldova, Republic of", "MC" => "Monaco", "MN" => "Mongolia", "MS" => "Montserrat", "MA" => "Morocco", "MZ" => "Mozambique", "MM" => "Myanmar", "NA" => "Namibia", "NR" => "Nauru", "NP" => "Nepal", "NL" => "Netherlands", "AN" => "Netherlands Antilles", "NC" => "New Caledonia", "NZ" => "New Zealand", "NI" => "Nicaragua", "NE" => "Niger", "NG" => "Nigeria", "NU" => "Niue", "NF" => "Norfolk Island", "MP" => "Northern Mariana Islands", "NO" => "Norway", "OM" => "Oman", "PK" => "Pakistan", "PW" => "Palau", "PS" => "Palestinian Territory, Occupied", "PA" => "Panama", "PG" => "Papua New Guinea", "PY" => "Paraguay", "PE" => "Peru", "PH" => "Philippines", "PN" => "Pitcairn", "PL" => "Poland", "PT" => "Portugal", "PR" => "Puerto Rico", "QA" => "Qatar", "RE" => "Reunion", "RO" => "Romania", "RU" => "Russian Federation", "RW" => "Rwanda", "SH" => "Saint Helena", "KN" => "Saint Kitts and Nevis", "LC" => "Saint Lucia", "PM" => "Saint Pierre and Miquelon", "VC" => "Saint Vincent and the Grenadines", "WS" => "Samoa", "SM" => "San Marino", "ST" => "Sao Tome and Principe", "SA" => "Saudi Arabia", "SN" => "Senegal", "CS" => "Serbia and Montenegro", "SC" => "Seychelles", "SL" => "Sierra Leone", "SG" => "Singapore", "SK" => "Slovakia", "SI" => "Slovenia", "SB" => "Solomon Islands", "SO" => "Somalia", "ZA" => "South Africa", "GS" => "South Georgia and the South Sandwich Islands", "ES" => "Spain", "LK" => "Sri Lanka", "SD" => "Sudan", "SR" => "Suriname", "SJ" => "Svalbard and Jan Mayen", "SZ" => "Swaziland", "SE" => "Sweden", "CH" => "Switzerland", "SY" => "Syrian Arab Republic", "TW" => "Taiwan, Province of China", "TJ" => "Tajikistan", "TZ" => "Tanzania, United Republic of", "TH" => "Thailand", "TL" => "Timor-Leste", "TG" => "Togo", "TK" => "Tokelau", "TO" => "Tonga", "TT" => "Trinidad and Tobago", "TN" => "Tunisia", "TR" => "Turkey", "TM" => "Turkmenistan", "TC" => "Turks and Caicos Islands", "TV" => "Tuvalu", "UG" => "Uganda", "UA" => "Ukraine", "AE" => "United Arab Emirates", "GB" => "United Kingdom", "US" => "United States", "UM" => "United States Minor Outlying Islands", "UY" => "Uruguay", "UZ" => "Uzbekistan", "VU" => "Vanuatu", "VE" => "Venezuela", "VN" => "Viet Nam", "VG" => "Virgin Islands, British", "VI" => "Virgin Islands, U.s.", "WF" => "Wallis and Futuna", "EH" => "Western Sahara", "YE" => "Yemen", "ZM" => "Zambia", "ZW" => "Zimbabwe" ); } } $wps_aa_options = new WPSunshine_Address_Autocomplete_Options();