settings = NIMAP_DATA::get_instance();
add_action( 'admin_head', [ $this, 'setup_wizard' ] );
add_action( 'wp_ajax_nimap_setup_wizard_action', [ $this, 'nimap_setup_wizard_action' ] );
}
public static function instance() {
return self::$instance == null ? self::$instance = new self() : self::$instance;
}
public function setup_wizard() {
if ( isset( $_GET['nimap_setup_wizard'], $_GET['_wpnonce'] ) && ! empty( $_GET['nimap_setup_wizard'] ) //phpcs:ignore WordPress.Security.NonceVerification.Recommended
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'nimap_setup_nonce' ) ) {
$step = isset( $_GET['step'] ) ? absint( wp_unslash( $_GET['step'] ) ) : 1;
$func = 'set_up_step_' . $step;
delete_option('nimap_setup_wizard' );
if ( method_exists( $this, $func ) ) {
$this->current_url = remove_query_arg( 'step', esc_url_raw( $_SERVER['REQUEST_URI'] ) );// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$steps_state = array(
'api' => '',
'store' => '',
'locator' => '',
);
switch ( $step ) {
case 2:
$steps_state['api'] = '';
$steps_state['store'] = 'active';
$steps_state['locator'] = 'disabled';
break;
case 3:
$steps_state['api'] = '';
$steps_state['store'] = '';
$steps_state['locator'] = 'active';
break;
default:
$steps_state['api'] = 'active';
$steps_state['store'] = 'disabled';
$steps_state['locator'] = 'disabled';
break;
}
?>
settings->get_params( 'general_api_key' );
?>
%s, %s',
esc_html__( 'Please go to', '9map-map-multi-locations' ),
esc_html__( 'Google Cloud console page', '9map-map-multi-locations' ),
esc_html__( 'create a Project and add Maps JavaScript API to use Google Map service in plugin', '9map-map-multi-locations' ) ) ?>
'nimap_store',
'order' => 'ASC',
'numberposts' => - 1,
] );
?>
|
|
ID : '';
$s_title = property_exists( $result_data, 'post_title' ) ? $result_data->post_title : '';
$s_address_data = get_post_meta( $s_id, 'nimap_store_address', true ) ?: '';
$s_address = is_array( $s_address_data ) && isset( $s_address_data['address'] ) ? $s_address_data['address'] : '';
?>
|
|
|
[
esc_html__( 'Store locator', '9map-map-multi-locations' ),
$this->settings->get_params( 'general_store_locator' ),
'[nimap_store_locator]'
],
'general_store_list' => [
esc_html__( 'Store list', '9map-map-multi-locations' ),
$this->settings->get_params( 'general_store_list' ),
'[nimap_store_search]'
],
'general_store_detail' => [
esc_html__( 'Store detail', '9map-map-multi-locations' ),
$this->settings->get_params( 'general_store_detail' ),
'[nimap_store_detail]'
],
];
?>
'success', 'message' => 'empty' ] );
}
try {
$data_default = $nimap_settings ?: $this->settings->get_default();
if ( isset( $data_default['general_api_key'] ) && ! empty( $data_default['general_api_key'] ) &&
$data_default['general_api_key'] == $api_setup ) {
wp_send_json( [ 'status' => 'success', 'message' => 'success' ] );
}
$data_default['general_api_key'] = $api_setup;
$nimap_settings = array_merge( $nimap_settings, $data_default );
update_option( 'nimap_multi_locator', $data_default );
$this->settings = NIMAP_DATA::get_instance( true );
wp_send_json( [ 'status' => 'success', 'message' => 'success' ] );
} catch ( \Exception $e ) {
wp_send_json( [ 'status' => 'error', 'message' => $e->getMessage() ] );
}
break;
case 'page':
global $nimap_settings;
$page_content = isset( $_POST['content'] ) ? sanitize_text_field( wp_unslash( $_POST['content'] ) ) : '';
$page_type = isset( $_POST['page'] ) ? sanitize_text_field( wp_unslash( $_POST['page'] ) ) : '';
$_p = array();
$_p['post_title'] = $add_title;
$_p['post_content'] = $page_content;
$_p['post_status'] = 'publish';
$_p['post_type'] = 'page';
$_p['comment_status'] = 'closed';
$_p['ping_status'] = 'closed';
$_p['post_category'] = array( 1 );
try {
$the_page_id = wp_insert_post( $_p );
update_post_meta( $the_page_id, '_wp_page_template', 'page-wide.php' );
$data_default = $nimap_settings ?: $this->settings->get_default();
$data_default[ $page_type ] = $the_page_id;
$nimap_settings = array_merge( $nimap_settings, $data_default );
update_option( 'nimap_multi_locator', $data_default );
$this->settings = NIMAP_DATA::get_instance( true );
wp_send_json( [ 'status' => 'success', 'message' => 'success' ] );
} catch ( \Exception $e ) {
wp_send_json( [ 'status' => 'error', 'message' => $e->getMessage() ] );
}
break;
case 'store':
$add_address = isset( $_POST['address'] ) ? sanitize_text_field( wp_unslash( $_POST['address'] ) ) : '';
$add_latitude = isset( $_POST['latitude'] ) ? sanitize_text_field( wp_unslash( $_POST['latitude'] ) ) : '';
$add_longitude = isset( $_POST['longitude'] ) ? sanitize_text_field( wp_unslash( $_POST['longitude'] ) ) : '';
$post_args = array(
'post_type' => 'nimap_store',
'post_status' => 'publish',
'post_title' => $add_title,
);
try {
$post_id = wp_insert_post( $post_args );
update_post_meta( $post_id, 'nimap_store_address', [
'address' => $add_address,
'city' => '',
'state' => '',
'country' => '',
'zip' => '',
'latitude' => $add_latitude,
'longitude' => $add_longitude,
] );
wp_send_json( [ 'status' => 'success', 'message' => 'success' ] );
} catch ( \Exception $e ) {
wp_send_json( [ 'status' => 'error', 'message' => $e->getMessage() ] );
}
break;
}
wp_send_json( [
'status' => 'error',
'message' => esc_html__( 'Unexpected error, please try again later', '9map-map-multi-locations' )
] );
}
}