<?php
perform myplugin_register_settings() {
add_option('marker_pin','');
register_setting( 'marker_group', 'marker_pin', 'myplugin_callback' );
}
add_action( 'admin_init', 'myplugin_register_settings' );
perform myplugin_register_options_page() {
add_options_page('Google Map', 'Map', 'manage_options', 'Google_map', 'myplugin_options_page');
}
add_action('admin_menu', 'myplugin_register_options_page');
perform plugin_admin_enqueue_styles() {
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBPUcMLet39Rn_MXvOJErCbT7VnsOAVPWc&libraries=locations&callback=initMap', array('jquery'),'1.0', true );
wp_enqueue_script( 'ajax-js', 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js', array('jquery'),'1.0', true );
wp_enqueue_script( 'code-js', 'https://code.jquery.com/jquery-1.11.3.min.js', array('jquery'),'1.0', true );
}
add_action( 'admin_enqueue_scripts', 'plugin_admin_enqueue_styles' );
perform myplugin_options_page()
{
?>
<div>
<?php screen_icon(); ?>
<h2>My Plugin Web page Title</h2>
<type technique="submit" motion="choices.php">
<?php settings_fields( 'marker_group' ); ?>
<h3>That is my possibility</h3>
<p>Some textual content right here.</p>
<desk>
<tr valign="high">
<th scope="row"><label for="marker">Metropolis:</label></th>
<td>
<?php $pins = get_option('marker_pin'); ?>
<div id="pac-container">
<enter id="pac_input" sort="textual content" title="pac_input"
placeholder="Enter Metropolis" worth="<?php echo $pins; ?>">
</div>
</td>
</tr>
</desk>
<?php submit_button(); ?>
<enter sort='button' worth='Add Button' id='addButton'>
</type>
</div>
<?php
}
perform update_option_fn()
{
$title=$_POST['name_palce'];
echo $title;
update_option('marker_pin',$title);
}
add_action('wp_ajax_update_option_fn', 'update_option_fn');
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
perform initMap() {
var enter = doc.getElementById("pac_input");
var autocomplete = new google.maps.locations.Autocomplete(enter);
autocomplete.addListener('place_changed', perform() {
var place = autocomplete.getPlace();
var placename = place.title;
enter.worth=placename;
if (!place.geometry) {
alert("No particulars out there for enter: '" + place.title + "'");
return;
}
});
}
$(doc).prepared(perform() {
/*$('#pac_input').on('enter', perform()*/
$('#pac_input').focusout(perform() {
var Place = $('#pac_input').val();
console.log(Place);
$.ajax({
url: '<?php admin_url( 'admin-ajax.php' );?>',
information: {"motion":"update_option_fn","name_palce" :Place},
/*information: {name_palce :Place},*/
sort: 'POST',
success:perform(information){
console.log("success"+information);
}
});
});
$("#submit").click on(perform() {
<?php
$id = $_POST['name_palce'];
update_option('marker_pin',$id,true);
?>
});
});
</script>
This my code, I need to retailer a worth which come from ajax into wp_option desk
how I can do it????