get_data_from_db( 'map_integration' ); $map_api = ( $map_api_details && '' !== $map_api_details['api'] ) ? $map_api_details['api'] : ''; if ( '' !== $map_api && $current_page && 'addmultiplemarker' === $current_page ) { wp_enqueue_script( 'amm-map-script', 'https://maps.googleapis.com/maps/api/js?key=' . $map_api . '&libraries=drawing,places', array(), ADDMULTIPLEMARKER_VERSION, true ); wp_enqueue_script( 'amm-admin-script', ADDMULTIPLEMARKER_PLUGIN_URL . 'admin/js/amm-scripts.js', array( 'jquery' ), ADDMULTIPLEMARKER_VERSION, true ); } wp_enqueue_script( 'amm-admin-custom-script', ADDMULTIPLEMARKER_PLUGIN_URL . 'admin/js/amm-custom-settings.js', array(), ADDMULTIPLEMARKER_VERSION, true ); wp_localize_script( 'amm-admin-script', 'amm_plugin_obj', array( 'plugin_path' => ADDMULTIPLEMARKER_PLUGIN_URL, 'amm_save_option' => $this->get_data_from_db( 'marker_settings' ), 'ajax_url' => admin_url( 'admin-ajax.php' ), 'map_settings' => $this->get_data_from_db( 'map_integration' ), ) ); wp_localize_script( 'amm-admin-custom-script', 'amm_plugin_custom_obj', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), ) ); } /** * Include frontend style and scripts. */ public function addmultiplemarker_scripts() { wp_enqueue_style( 'amm-frontend-styles', ADDMULTIPLEMARKER_PLUGIN_URL . 'public/css/amm-frontend-style.css', '', ADDMULTIPLEMARKER_VERSION ); } /** * Get data from database. * * @param string $option_name Option name. */ public function get_data_from_db( $option_name ) { if ( 'map_integration' === $option_name ) { $map_details = get_option( 'amm_map_setting' ); } elseif ( 'marker_settings' === $option_name ) { $map_details = get_option( 'amm_maps_marker' ); } return $map_details; } /** * Register admin menu. */ public function addmultiplemarker_admin_menu() { add_menu_page( __( 'Add Multiple Marker', 'add-multiple-marker' ), 'Add Multiple Marker', 'manage_options', 'addmultiplemarker', array( $this, 'addmultiplemarker_global_settings_page' ), ADDMULTIPLEMARKER_PLUGIN_URL . 'admin/images/dash-icon.png' ); add_submenu_page( 'addmultiplemarker', __( 'AMM Map integration', 'add-multiple-marker' ), __( 'Map integration', 'add-multiple-marker' ), 'manage_options', 'amm-map-integration', array( $this, 'addmultiplemarker_map_integration_callback' ) ); } /** * Displaying admin notice. */ public function addmultiplemarker_admin_notice() { $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( $current_page && ( 'addmultiplemarker' === $current_page || 'amm-map-integration' === $current_page ) ) { $map_details = $this->get_data_from_db( 'map_integration' ); if ( ! $map_details || ( isset( $map_details['api'] ) && '' === $map_details['api'] ) ) { echo '

' . esc_html__( 'Please enter valid Google Map API for displaying map.', 'add-multiple-marker' ) . '

'; } } } /** * Display map frontside via shortcode. */ public function display_multiple_marker_map() { $map_details = $this->get_data_from_db( 'map_integration' ); if ( $map_details && isset( $map_details['api'] ) && '' !== $map_details['api'] ) { if ( ! wp_script_is( 'amm-map-script' ) ) { wp_enqueue_script( 'amm-map-script', 'https://maps.googleapis.com/maps/api/js?key=' . $map_details['api'] . '&libraries=drawing,places,marker&callback=initialize&loading=async', array(), ADDMULTIPLEMARKER_VERSION, true ); } if ( ! wp_script_is( 'amm-frontend-scripts' ) ) { wp_enqueue_script( 'amm-frontend-scripts', ADDMULTIPLEMARKER_PLUGIN_URL . 'public/js/frontendscript.js', array( 'jquery' ), ADDMULTIPLEMARKER_VERSION, true ); wp_localize_script( 'amm-frontend-scripts', 'amm_frontend_obj', array( 'amm_save_marker_option' => $this->get_data_from_db( 'marker_settings' ), 'map_settings' => $this->get_data_from_db( 'map_integration' ), ) ); } $map_height = isset( $map_details['map_height'] ) && '' !== $map_details['map_height'] ? $map_details['map_height'] : '500'; $map_width = isset( $map_details['map_width'] ) && '' !== $map_details['map_width'] ? $map_details['map_width'] : '100%'; return '
'; } else { return __( 'Please Enter Valid Google Map API Key', 'add-multiple-marker' ); } } /** * Map API configuration. */ public function addmultiplemarker_global_settings_page() { // Include file. require_once ADDMULTIPLEMARKER_PLUGIN_DIR . 'admin/admin-options.php'; } /** * Setting configuration. */ public function addmultiplemarker_map_integration_callback() { // Include file. require_once ADDMULTIPLEMARKER_PLUGIN_DIR . 'admin/map-integration.php'; } } }