i create WordPress Plugin and want to save to wordpress_options table.
But in my save function wont work.
This is my code :
<?php
/**
* Plugin Name: Social Media Plugin
* Plugin URI: http://fanjavaid.com/plugin
* Description: Plugin untuk kebutuhan data sosial media.
* Version: 1.0
* Author: Fandi Akhmad
* Author URI: http://fanjavaid.com
*/
function mp_admin() {
if(isset($_POST['mp_web'])):
update_option('mp_web', $_POST['mp_web']);
echo '<div class="updated"><p><strong>Updated</strong>: Data berhasil diubah</p></div>';
endif;
$mp_web = get_option('mp_web');
?>
<div class="wrap">
<?php echo "<h2>" . __( 'Halaman Konfigurasi My Plugin', 'mp' ) . "</h2>"; ?>
<?php echo "<p>Masukkan detail sosial media untuk website Indotechsci</p>"; ?>
<form name="mp_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="mp_hidden" value="Y">
<p><?php _e("Twitter " ); ?><input type="text" name="mp_twt" value="" size="20" placeholder="username"></p>
<p><?php _e("Facebook " ); ?><input type="text" name="mp_fb" value="" size="20" placeholder="username"></p>
<p><?php _e("Youtube " ); ?><input type="text" name="mp_ytb" value="" size="20" placeholder="username"></p>
<p class="submit">
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'mp' ) ?>" />
</p>
</form>
</div>
<?php } ?>
It wont save.
May be any wrong to my code? And how to call the saved above info into homepage in WordpresS?
Please help me. Thank you.
The problem with your code is that you might be saving the data, but you are not reading the data that is saved, and you are not changing the data in your form according to what you have previously saved.
The code below is a typical way of saving and reading registered variables from database.
The variable names that you use, must be registered with register_setting() function.