Last active
December 17, 2015 18:49
-
-
Save rodica-andronache/5656386 to your computer and use it in GitHub Desktop.
WORDPRESS - Creare thme-options(submenu la meniurile default wordpress)
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
Creez un fisier 'create_option.php', pe care il includ in functions.php si in care pun: | |
<?php | |
add_action('admin_menu', 'register_my_custom_submenu_page'); | |
function register_my_custom_submenu_page() { | |
add_submenu_page( 'themes.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); | |
//aici, mai pot folosi(si e recomandat sa fac asta) | |
//in loc de add_submenu_page | |
//add_theme_page('My Custom Submenu Page', 'My Custom Submenu Page', 'read', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); | |
} | |
function my_custom_submenu_page_callback() { | |
if(isset($_POST["phone"])) { | |
$phone = esc_attr($_POST["phone"]); | |
} | |
if (isset($_POST["update_settings"])) { | |
update_option("phone_number", $phone); | |
} | |
?> | |
<div class="wrap"> | |
<form method="POST" action=""> | |
<label for="phone"> | |
Phone number: | |
</label> | |
<?php | |
$ph = get_option("phone_number"); | |
?> | |
<input type="text" name="phone" size="25" value="<?php echo $ph; ?>" /> | |
<input type="hidden" name="update_settings" value="Y" /> | |
<input type="submit" value="Save settings" class="button-primary"/> | |
</form> | |
</div> | |
<?php | |
} | |
?> | |
Si, cand vreau sa afisez valoarea salvata, folosesc: get_option("phone_number"); | |
Primul parametru de la add_submenu_page() , spune la care meniu va fi adaugat submeniul.(aici mi-l adauga in appearance) | |
Examples: | |
For Dashboard: add_submenu_page( 'index.php', ... ); | |
For Posts: add_submenu_page( 'edit.php', ... ); | |
For Media: add_submenu_page( 'upload.php', ... ); | |
For Links: add_submenu_page( 'link-manager.php', ... ); | |
For Pages: add_submenu_page( 'edit.php?post_type=page', ... ); | |
For Comments: add_submenu_page( 'edit-comments.php', ... ); | |
For Custom Post Types: add_submenu_page( 'edit.php?post_type=your_post_type', ... ); | |
For Appearance: add_submenu_page( 'themes.php', ... ); | |
For Plugins: add_submenu_page( 'plugins.php', ... ); | |
For Users: add_submenu_page( 'users.php', ... ); | |
For Tools: add_submenu_page( 'tools.php', ... ); | |
For Settings: add_submenu_page( 'options-general.php', ... ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment