settings = NIMAP_DATA::get_instance();
//store list
add_filter( 'manage_nimap_store_posts_columns', array( $this, 'add_column' ), 10, 1 );
add_action( 'manage_nimap_store_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
//store details
add_action( 'add_meta_boxes', array( $this, 'add_custom_meta_box' ) );
// add_action( 'add_meta_boxes', array( $this, 'address_custom_meta_box' ), 20 );
// add_action( 'edit_form_after_title', array( $this, 'add_store_details' ) );
add_action( 'save_post', array( $this, 'save_meta_box' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_script' ) );
}
public function add_column( $columns ) {
$columns['address'] = esc_html__( 'Address', '9map-map-multi-locations' );
$columns['contact'] = esc_html__( 'Contact', '9map-map-multi-locations' );
$columns['coordinates'] = esc_html__( 'Coordinates', '9map-map-multi-locations' );
// $columns['category'] = esc_html__( 'Category', '9map-map-multi-locations' );
$columns['status'] = esc_html__( 'Status', '9map-map-multi-locations' );
return $columns;
}
public function add_column_data( $column, $post_id ) {
switch ( $column ) {
case 'address':
$address_meta = get_post_meta( $post_id, 'nimap_store_address', true );
echo isset( $address_meta['address'] ) ? esc_html( $address_meta['address'] ) : '';
echo isset( $address_meta['city'] ) && ! empty( $address_meta['city'] ) ? ' - ' . esc_html( $address_meta['city'] ) : '';
echo isset( $address_meta['state'] ) && ! empty( $address_meta['state'] ) ? ' - ' . esc_html( $address_meta['state'] ) : '';
echo isset( $address_meta['country'] ) && ! empty( $address_meta['country'] ) ? ' - ' . esc_html( $address_meta['country'] ) : '';
break;
case 'contact':
$information_meta = get_post_meta( $post_id, 'nimap_store_information', true );
echo '
';
break;
case 'coordinates':
$address_meta = get_post_meta( $post_id, 'nimap_store_address', true );
echo '';
echo '
' . esc_html__( 'Latitude: ', '9map-map-multi-locations' );
echo esc_html( isset( $address_meta['latitude'] ) ? esc_html( $address_meta['latitude'] ) : '' );
echo '
';
echo '
' . esc_html__( 'Longitude: ', '9map-map-multi-locations' );
echo esc_html( isset( $address_meta['longitude'] ) ? esc_html( $address_meta['longitude'] ) : '' );
echo '
';
echo '
';
break;
// case 'category':
// $category_meta = get_post_meta( $post_id, 'nimap_store_category', true );
// $category_print = '';
// if ( $category_meta && ! empty( $category_meta ) ) {
// foreach ( $category_meta as $c_k => $c_v ) {
// $category_print .= empty( $category_print ) ? $c_v : ', ' . $c_v;
// }
// }
// echo esc_html( $category_print );
// break;
case 'status':
$status_meta = get_post_status( $post_id );
echo $status_meta == 'publish' ? esc_html__( 'Active', '9map-map-multi-locations' ) : esc_html__( 'Inactive', '9map-map-multi-locations' );
break;
default:
}
}
function add_custom_meta_box() {
if ( get_current_screen()->id != 'nimap_store' ) {
return;
}
add_meta_box(
'custom_meta_box_nimap_description', // $id
esc_html__( 'Description', '9map-map-multi-locations' ), // $title
array( $this, 'description_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'normal', // $context
'low' // $priority
);
add_meta_box(
'custom_meta_box_nimap_address', // $id
esc_html__( 'Store address', '9map-map-multi-locations' ), // $title
array( $this, 'address_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'normal', // $context
'default' // $priority
);
add_meta_box(
'custom_meta_box_nimap_information', // $id
esc_html__( 'Store information', '9map-map-multi-locations' ), // $title
array( $this, 'information_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'normal', // $context
'default' // $priority
);
add_meta_box(
'custom_meta_box_nimap_opening', // $id
esc_html__( 'Store opening hour', '9map-map-multi-locations' ), // $title
array( $this, 'opening_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'normal', // $context
'default' // $priority
);
add_meta_box(
'custom_meta_box_nimap_image', // $id
esc_html__( 'Store image', '9map-map-multi-locations' ), // $title
array( $this, 'image_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'side', // $context
'default' // $priority
);
// add_meta_box(
// 'custom_meta_box_nimap_category', // $id
// esc_html__( 'Store category', '9map-map-multi-locations' ), // $title
// array( $this, 'category_custom_meta_box_content' ), // $callback
// 'nimap_store', // $page
// 'side', // $context
// 'default' // $priority
// );
}
//not use
function address_custom_meta_box() {
if ( get_current_screen()->id != 'nimap_store' ) {
return;
}
add_meta_box(
'custom_meta_box_nimap_address', // $id
esc_html__( 'Store address', '9map-map-multi-locations' ), // $title
array( $this, 'address_custom_meta_box_content' ), // $callback
'nimap_store', // $page
'normal', // $context
'default' // $priority
);
}
function description_custom_meta_box_content( $post ) {
$value = get_post_meta( $post->ID, 'nimap_store_description', true );
if ( empty( $value ) ) {
$value = '';
}
wp_enqueue_editor(); ?>
50,
'media_buttons' => false,
'textarea_name' => 'nimap_store_description'
] ); ?>
ID, 'nimap_store_address', true ) ?: '';
$address_value = $this->get_data( $address_meta, 'address' );
$city_value = $this->get_data( $address_meta, 'city' );
$state_value = $this->get_data( $address_meta, 'state' );
$zip_value = $this->get_data( $address_meta, 'zip' );
$country_value = $this->get_data( $address_meta, 'country' );
$latitude_value = $this->get_data( $address_meta, 'latitude' );
$longitude_value = $this->get_data( $address_meta, 'longitude' );
$state_html = '';
$states = apply_filters( 'nimap_states', include NIMAP_TEMPLATES . 'wc' . DIRECTORY_SEPARATOR . 'states.php' );
$countries = apply_filters( 'nimap_countries', include NIMAP_TEMPLATES . 'wc' . DIRECTORY_SEPARATOR . 'countries.php' );
$_nonce = wp_create_nonce( 'nimap_nonce_field' );
if ( $states && is_array( $states ) && ! empty( $country_value ) && isset( $states[ $country_value ] ) ) {
$state_html = '';
}
?>
ID, 'nimap_store_information', true ) ?: '';
$website_value = $this->get_data( $information_meta, 'website' );
$phone_value = $this->get_data( $information_meta, 'phone' );
$fax_value = $this->get_data( $information_meta, 'fax' );
$email_value = $this->get_data( $information_meta, 'email' );
$custom_value = $this->get_data( $information_meta, 'custom' );
?>
ID, 'nimap_store_opening', true ) ?: '';
$monday_value = $this->get_data( $opening_meta, 'monday' );
$tuesday_value = $this->get_data( $opening_meta, 'tuesday' );
$wednesday_value = $this->get_data( $opening_meta, 'wednesday' );
$thursday_value = $this->get_data( $opening_meta, 'thursday' );
$friday_value = $this->get_data( $opening_meta, 'friday' );
$saturday_value = $this->get_data( $opening_meta, 'saturday' );
$sunday_value = $this->get_data( $opening_meta, 'sunday' );
?>
ID, 'nimap_store_image', true ) ?: '';
$upload_link = esc_url( get_upload_iframe_src( 'image', $post->ID ) );
// Get WordPress' media upload URL
$store_img_src = wp_get_attachment_image_src( $value, 'full' );
$store_have_img = is_array( $store_img_src );
wp_enqueue_editor(); ?>
ID, 'nimap_store_category', true ) ?: '';
}
function add_store_details() {
if ( get_current_screen()->id != 'nimap_store' ) {
return;
} ?>
id;
$min = WP_DEBUG ? '' : '.min';
global $post;
if ( $page_id == 'nimap_store' ) {
$address_meta = get_post_meta( $post->ID, 'nimap_store_address', true ) ?: '';
$latitude_value = $this->get_data( $address_meta, 'latitude' );
$longitude_value = $this->get_data( $address_meta, 'longitude' );
$m_settings = $this->settings->get_params();
NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $m_settings );
wp_enqueue_media();
wp_enqueue_style( 'button', NIMAP_CSS . 'button.min.css', array(), NIMAP_VERSION );
wp_enqueue_style( 'table', NIMAP_CSS . 'table.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, false );
wp_enqueue_style( 'checkbox', NIMAP_CSS . 'checkbox.min.css', array(), NIMAP_VERSION, false );
wp_enqueue_style( 'segment', NIMAP_CSS . 'segment.min.css', array(), NIMAP_VERSION, false );
wp_enqueue_style( 'icon', NIMAP_CSS . 'icon.min.css', array(), NIMAP_VERSION, false );
wp_enqueue_style( 'nimap-stores', NIMAP_CSS . 'nimap-stores' . $min . '.css', array(), NIMAP_VERSION, false );
wp_enqueue_script( 'dropdown', NIMAP_JS . 'dropdown.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'checkbox', NIMAP_JS . 'checkbox.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'form', NIMAP_JS . 'form.min.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_enqueue_script( 'transition', NIMAP_JS . 'transition.min.js', array( 'jquery' ), NIMAP_VERSION , false);
wp_enqueue_script( 'nimap-stores', NIMAP_JS . 'nimap-stores' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false );
wp_localize_script( 'nimap-stores', 'nimapVars', array(
'wc_states' => apply_filters( 'nimap_states', include NIMAP_TEMPLATES . 'wc' . DIRECTORY_SEPARATOR . 'states.php' ),
'country_select' => esc_html__( 'Select an option', '9map-map-multi-locations' ),
'startLatitude' => $latitude_value,
'startLongitude' => $longitude_value,
'mapId' => $this->settings->get_params( 'general_map_id' ) ?: 'DEMO_MAP_ID',
'mapSIconType' => $this->settings->get_params( 'map_store_marker' ),
'mapSIcon' => $this->settings->get_params( 'map_store_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' ),
) );
}
}
}