settings = NIMAP_DATA::get_instance();
$this->languages = array();
$this->languages_count = 0;
$this->languages_data = array();
$this->default_language = '';
add_filter(
'plugin_action_links_9map-map-multi-locations/9map-map-multi-locations.php', array(
$this,
'settings_link'
)
);
add_action( 'init', array( $this, 'init' ) );
add_action( 'admin_menu', array( $this, 'add_menu' ) );
add_action( 'admin_init', array( $this, 'save_settings' ) );
add_action( 'wp_ajax_nimap_search_page', array( $this, 'nimap_search_page' ) );
// add_action( 'wp_print_scripts', array( $this, 'custom_script' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_script' ) );
}
function init() {
$this->register_post_type();
$this->register_taxonomies();
// load_plugin_textdomain( '9map-map-multi-locations' );
$this->load_plugin_textDomain();
if ( class_exists( 'VillaTheme_Support' ) ) {
new VillaTheme_Support(
array(
'support' => 'https://wordpress.org/support/plugin/9map-map-multi-locations/',
'docs' => 'https://docs.villatheme.com/?item=9map',
'review' => 'https://wordpress.org/support/plugin/9map-map-multi-locations/reviews/?rate=5#rate-response',
'css' => NIMAP_CSS,
'image' => NIMAP_IMAGES,
'version' => NIMAP_VERSION,
'slug' => '9map-map-multi-locations',
'menu_slug' => '9map-map-multi-locations',
'survey_url' => 'https://script.google.com/macros/s/AKfycbzjrqBMwDE95qiudWkyas4tQCYXSFy-f-x3R3zIimt1JK3MaIxAVg-xvFD9-yITxVE_/exec',
)
);
}
}
/**
* load Language translate
*/
function load_plugin_textDomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), '9map-map-multi-locations' );
// Admin Locale
if ( is_admin() ) {
load_textdomain( '9map-map-multi-locations', NIMAP_LANGUAGES . "9map-map-multi-locations-$locale.mo" );
}
// Global + Frontend Locale
load_textdomain( '9map-map-multi-locations', NIMAP_LANGUAGES . "9map-map-multi-locations-$locale.mo" );
// load_plugin_textdomain( '9map-map-multi-locations', false, NIMAP_LANGUAGES );
}
function add_menu() {
add_menu_page(
esc_html__( '9Map - Map Multi Locations', '9map-map-multi-locations' ),
esc_html__( '9Map', '9map-map-multi-locations' ),
'manage_options',
'9map-map-multi-locations',
array(
$this,
'settings_page'
), 'dashicons-location-alt', 2
);
add_submenu_page(
'9map-map-multi-locations',
esc_html__( 'Add New Store', '9map-map-multi-locations' ),
esc_html__( 'Add New Store', '9map-map-multi-locations' ),
'manage_options',
'post-new.php?post_type=nimap_store',
array(),
null
);;
add_submenu_page(
'9map-map-multi-locations',
esc_html__( 'Store Categories', '9map-map-multi-locations' ),
esc_html__( 'Store Categories', '9map-map-multi-locations' ),
'manage_options',
'edit-tags.php?taxonomy=nimap_store_category&post_type=nimap_store',
array(),
null
);
add_submenu_page(
'9map-map-multi-locations',
esc_html__( '9Map Settings', '9map-map-multi-locations' ),
esc_html__( 'Settings', '9map-map-multi-locations' ),
'manage_options',
'9map-map-multi-locations',
array(
$this,
'settings_page'
)
);
}
public function custom_script() {
$script = 'var nimap_ajax_url = "' . esc_url( admin_url( 'admin-ajax.php' ) ) . '"'; ?>
'page',
'meta_query' => array(// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
array(
'key' => '_wp_page_template',
'value' => $template,
'compare' => '=',
)
)
) );
if ( isset( $pages[0] ) ) {
$url = get_permalink( $pages[0]->ID );
}
return $url;
}
/**
* Save data.
*/
public function save_settings() {
global $nimap_settings;
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
if ( ! isset( $_POST['nimap_params'] ) || ! isset( $_POST['nimap_nonce_field'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nimap_nonce_field'] ) ), 'nimap_nonce_field' ) ) {
return;
}
$input_data = array_map( 'sanitize_text_field', wp_unslash( $_POST['nimap_params'] ) );// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$data_default = $this->settings->get_default();
foreach ( $data_default as $key => $value ) {
switch ( $key ) {
default:
$data[ $key ] = isset( $input_data[ $key ] ) ? $input_data[ $key ] : $value;
}
}
$nimap_settings = array_merge( $nimap_settings, $data );
update_option( 'nimap_multi_locator', $data );
$this->settings = NIMAP_DATA::get_instance( true );
}
public function settings_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$general_store_types = array(
'google' => 'Google map API',
'calc' => 'Calculate with latitude and longitude',
);
$layout_types = array(
'fullwidth' => 'Full width',
'2col' => 'Two column',
);
$distance_types = array(
'ml' => 'Miles',
'km' => 'Kilometer',
);
$route_types = array(
'google' => 'Redirect to google',
'local' => 'Current map',
);
$load_location_init = array(
'user' => 'Use user location',
'select' => 'Set from selected location',
);
$user_location_init = array(
'user' => 'Use user location',
'city' => 'City of user',
'country' => 'Country of user',
'store' => 'Nearest store',
);
$map_view_types = array(
'1' => '1 World view',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'10' => '10',
'11' => '11',
'12' => '12 Road view',
);
$map_layout_types = array(
'default' => 'Default',
'custom' => 'Custom',
);
$info_display_fields = array(
'image' => 'Image',
'title' => 'Title',
'address' => 'Address',
'description' => 'Description',
'phone' => 'Phone number',
'email' => 'Email',
'website' => 'Website',
'open_time' => 'Open time',
'category' => 'Category',
'zip' => 'Zip Code',
);
$link_button_types = array(
'none' => 'Select action',
'store' => 'Link to store page',
'website' => 'Link to website of store',
'direction' => 'Direction to store',
);
$list_sort_types = array(
'distance' => 'Distance',
'alphabet' => 'Alphabet',
);
$search_button_types = array(
'text' => 'Text',
'icon' => 'Icon',
);
$locator_permalink = get_permalink( $this->settings->get_page_locator( 'general_store_locator' ) );
$customize_link = get_admin_url() . 'customize.php?url=' . $locator_permalink . '&autofocus%5Bpanel%5D=nimap_design';
?>
'publish',
'post_type' => 'page',
'posts_per_page' => 50,
's' => $keyword
);
$the_query = new WP_Query( $arg );
$found_page = array();
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$nimap_page_id = get_the_ID();
$nimap_page_title = get_the_title();
$nimap_page = array( 'id' => $nimap_page_id, 'text' => $nimap_page_title );
$found_page[] = $nimap_page;
}
}
wp_send_json( $found_page );
}
/**
* Link to Settings
*
* @param $links
*
* @return mixed
*/
public function settings_link( $links ) {
$settings_link = '' . esc_html__( 'Settings', '9map-map-multi-locations' ) . '';
array_unshift( $links, $settings_link );
return $links;
}
protected function register_post_type() {
if ( post_type_exists( 'nimap_store' ) ) {
return;
}
$labels = array(
'name' => esc_html_x( 'Store', 'Post name', '9map-map-multi-locations' ),
'singular_name' => esc_html_x( 'Store', 'Post singular name', '9map-map-multi-locations' ),
'menu_name' => esc_html_x( '9Map Store Locator', 'Admin menu', '9map-map-multi-locations' ),
'name_admin_bar' => esc_html_x( 'Store', 'Add new on Admin bar', '9map-map-multi-locations' ),
'add_new' => esc_html_x( 'Add New Store', 'Add new post type', '9map-map-multi-locations' ),
'add_new_item' => esc_html__( 'Add New Store', '9map-map-multi-locations' ),
'new_item' => esc_html__( 'New Store', '9map-map-multi-locations' ),
'edit_item' => esc_html__( 'Edit Store', '9map-map-multi-locations' ),
'view_item' => esc_html__( 'View Store', '9map-map-multi-locations' ),
'all_items' => esc_html__( 'Manage Stores', '9map-map-multi-locations' ),
'search_items' => esc_html__( 'Search Store', '9map-map-multi-locations' ),
'parent_item_colon' => esc_html__( 'Parent Store:', '9map-map-multi-locations' ),
'not_found' => esc_html__( 'No Store found.', '9map-map-multi-locations' ),
'not_found_in_trash' => esc_html__( 'No Store found in Trash.', '9map-map-multi-locations' )
);
$args = apply_filters( 'nimap_store_args', array(
'labels' => $labels,
'description' => 'Post Type 9Map Store',
'supports' => array(
'title',
),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => '9map-map-multi-locations',
'show_in_nav_menus' => true,
'show_in_admin_bar' => false,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'post'
) );
register_post_type( 'nimap_store', $args );
}
public function register_taxonomies() {
$labels = array(
'name' => esc_html__( 'Store Categories', '9map-map-multi-locations' ),
'singular_name' => esc_html__( 'Store Category', '9map-map-multi-locations' ),
'search_items' => esc_html__( 'Search Store Categories', '9map-map-multi-locations' ),
'all_items' => esc_html__( 'All Store Categories', '9map-map-multi-locations' ),
'parent_item' => esc_html__( 'Parent Store Category', '9map-map-multi-locations' ),
'parent_item_colon' => esc_html__( 'Parent Store Category:', '9map-map-multi-locations' ),
'edit_item' => esc_html__( 'Edit Store Category', '9map-map-multi-locations' ),
'update_item' => esc_html__( 'Update Store Category', '9map-map-multi-locations' ),
'add_new_item' => esc_html__( 'Add New Store Category', '9map-map-multi-locations' ),
'new_item_name' => esc_html__( 'New Store Category Name', '9map-map-multi-locations' ),
'menu_name' => esc_html__( 'Store Categories', '9map-map-multi-locations' ),
);
$args = apply_filters( 'nimap_store_category_args', array(
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => false,
'show_in_rest' => true
)
);
register_taxonomy( 'nimap_store_category', 'nimap_store', $args );
}
/**
* Include style and script
*/
public function admin_enqueue_script() {
if ( isset( $_REQUEST['nimap_admin_nonce'] ) && ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['nimap_admin_nonce'] ) ), 'nimap_admin_nonce' ) ) {// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return;
}
$page = isset( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : '';
$min = WP_DEBUG ? '' : '.min';
if ( $page == '9map-map-multi-locations' ) {
$m_settings = $this->settings->get_params();
NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $m_settings, 'coordinate' );
// style
wp_enqueue_style( 'button', NIMAP_CSS . 'button.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'tab', NIMAP_CSS . 'tab.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'dropdown', NIMAP_CSS . 'dropdown.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'transition', NIMAP_CSS . 'transition.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'menu', NIMAP_CSS . 'menu.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'header', NIMAP_CSS . 'header.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'form', NIMAP_CSS . 'form.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'segment', NIMAP_CSS . 'segment.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'icon', NIMAP_CSS . 'icon.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'select2', NIMAP_CSS . 'select2.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'nimap-setting', NIMAP_CSS . 'nimap-admin' . $min . '.css', array(), NIMAP_VERSION );
//script
wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array(
'jquery-ui-draggable',
'jquery-ui-slider',
'jquery-touch-punch'
), NIMAP_VERSION, 1 );
wp_enqueue_script( 'tab-js', NIMAP_JS . 'tab.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'address-js', NIMAP_JS . 'address.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'dropdown-js', NIMAP_JS . 'dropdown.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'transition-js', NIMAP_JS . 'transition.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'form-js', NIMAP_JS . 'form.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'select2', NIMAP_JS . 'select2.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'nimap-setting', NIMAP_JS . 'nimap-admin' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false );
$st_localize = [
'startLatitude' => $this->settings->get_params( 'map_start_latitude' ),
'startLongitude' => $this->settings->get_params( 'map_start_longitude' ),
'mapId' => $this->settings->get_params( 'general_map_id' ) ?: 'DEMO_MAP_ID',
'mapUIconType' => $this->settings->get_params( 'map_user_marker' ),
'mapUIcon' => $this->settings->get_params( 'map_user_marker_custom' ),
'startPoint' => esc_html__( 'Start location', '9map-map-multi-locations' ),
'markerUrl' => NIMAP_IMAGES,
'generalGeoError' => esc_html__( 'An unknown error occurred.', '9map-map-multi-locations' ),
'unavailable' => esc_html__( 'Location information is unavailable.', '9map-map-multi-locations' ),
];
wp_localize_script( 'nimap-setting', 'nimapSettings', $st_localize );
}
$screen_id = get_current_screen()->id;
if ( isset( $_GET['nimap_setup_wizard'], $_GET['_wpnonce'] ) && ! empty( $_GET['nimap_setup_wizard'] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'nimap_setup_nonce' ) ) {// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$m_settings = $this->settings->get_params();
NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $m_settings, 'setup' );
wp_enqueue_style( 'button', NIMAP_CSS . 'button.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'tab', NIMAP_CSS . 'tab.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'dropdown', NIMAP_CSS . 'dropdown.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'transition', NIMAP_CSS . 'transition.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'menu', NIMAP_CSS . 'menu.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'header', NIMAP_CSS . 'header.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'form', NIMAP_CSS . 'form.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'segment', NIMAP_CSS . 'segment.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'icon', NIMAP_CSS . 'icon.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'modal', NIMAP_CSS . 'modal.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'dimmer', NIMAP_CSS . 'dimmer.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'step', NIMAP_CSS . 'step.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'table', NIMAP_CSS . 'table.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'input', NIMAP_CSS . 'input.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'checkbox', NIMAP_CSS . 'checkbox.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'message', NIMAP_CSS . 'message.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'select2', NIMAP_CSS . 'select2.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'nimap-setup', NIMAP_CSS . 'nimap-setup' . $min . '.css', array(), NIMAP_VERSION );
wp_enqueue_script( 'tab', NIMAP_JS . 'tab.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'dimmer', NIMAP_JS . 'dimmer.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'dropdown', NIMAP_JS . 'dropdown.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'transition', NIMAP_JS . 'transition.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'modal', NIMAP_JS . 'modal.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'jqColorPicker', NIMAP_JS . 'jqColorPicker.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'form', NIMAP_JS . 'form.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'select2', NIMAP_JS . 'select2.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'nimap-setup', NIMAP_JS . 'nimap-setup' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false );
$su_localize = [
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'nimap_security' ),
'mapId' => $this->settings->get_params( 'general_map_id' ) ?: 'DEMO_MAP_ID',
'startPoint' => esc_html__( 'Shop Location', '9map-map-multi-locations' ),
'generalGeoError' => esc_html__( 'Unavailable to get location, please try again later.', '9map-map-multi-locations' ),
'unavailable' => esc_html__( 'Geolocate is unavailable, please try again later.', '9map-map-multi-locations' ),
'finish' => esc_url( admin_url( 'admin.php?page=9map-map-multi-locations' ) ),
];
wp_localize_script( 'nimap-setup', 'nimapSetup', $su_localize );
}
}
}