Created
August 13, 2019 10:41
-
-
Save tranchausky/38007b0cc2f293c039eb736cd0f07cb1 to your computer and use it in GitHub Desktop.
wordpress add option for template (in admin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//for in file functions.php of theme or create new plugin add | |
//include_once ("admin-page-more/options_template.php"); | |
function myplugin_register_settings() { | |
add_option( 'myplugin_option_name', 'This is my option value.'); | |
add_option( 'myplugin_option_name_01', ''); | |
add_option( 'myplugin_option_email_1', ''); | |
register_setting( 'myplugin_options_group', 'myplugin_option_name', 'myplugin_callback' ); | |
register_setting( 'myplugin_options_group', 'myplugin_option_name_01', 'myplugin_callback' ); | |
register_setting( 'myplugin_options_group', 'myplugin_option_email_1', 'myplugin_callback' ); | |
} | |
add_action( 'admin_init', 'myplugin_register_settings' ); | |
function myplugin_register_options_page() { | |
add_options_page('Page Title', 'Plugin Menu', 'manage_options', 'myplugin', 'myplugin_options_page'); | |
} | |
add_action('admin_menu', 'myplugin_register_options_page'); | |
?> | |
<?php function myplugin_options_page() | |
{ | |
?> | |
<div> | |
<?php screen_icon(); ?> | |
<h2>My Plugin Page Title</h2> | |
<form method="post" action="options.php"> | |
<?php settings_fields( 'myplugin_options_group' ); ?> | |
<h3>This is my option</h3> | |
<p>Some text here.</p> | |
<table> | |
<tr valign="top"> | |
<th scope="row"><label for="myplugin_option_name">Label</label></th> | |
<td><input type="text" id="myplugin_option_name" name="myplugin_option_name" value="<?php echo get_option('myplugin_option_name'); ?>" /></td> | |
<th scope="row"><label for="myplugin_option_name_01">Label</label></th> | |
<td><input type="text" id="myplugin_option_name_01" name="myplugin_option_name_01" value="<?php echo get_option('myplugin_option_name_01'); ?>" /></td> | |
</tr> | |
</table> | |
<?php | |
$privacy_policy_page_id = get_option( 'myplugin_option_email_1' ); | |
var_dump($privacy_policy_page_id ); | |
wp_dropdown_pages( | |
array( | |
'name' => 'myplugin_option_email_1', | |
'show_option_none' => __( '— Select —' ), | |
'option_none_value' => '0', | |
'selected' => $privacy_policy_page_id, | |
'post_status' => array( 'draft', 'publish' ), | |
) | |
); | |
?> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
<?php | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment