"Settings Updated" message Stopped showing - php

I was using the code below as a Plugin to create a "Options Menu Page" for wordpress:
add_action('admin_init', 'cardin_options_init' );
add_action('admin_menu', 'cardin_options_add_page');
function cardin_options_init(){
register_setting( 'cardin_options_options', 'cardin_options');
}
function cardin_options_add_page() {
add_options_page('Cardin Options', 'Cardin Options', 'manage_options', 'cardin_options', 'cardin_options_do_page');
}
function cardin_options_do_page() {
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"><br></div>
<h2>Cardin Options</h2>
<form method="post" action="options.php">
<?php settings_fields('cardin_options_options'); ?>
<?php $options = get_option('cardin_options'); ?>
<table class="form-table">
<tr valign="top"><th scope="row">Information</th>
<td><input type="text" name="cardin_options[information]" value="<?php echo $options['information']; ?>" /></td>
</tr>
</table>
<input type="submit" class="button-primary" name="submit" value="<?php _e('Save Changes') ?>" />
</form>
</div>
<?php
}
It's working how it should, but, later I decided to create my Own Plugin Menu Page, not a 'Settings' sub-menu, then, I changed the line below:
add_options_page('Cardin Options', 'Cardin Options', 'manage_options', 'cardin_options', 'cardin_options_do_page');
to:
add_menu_page('Cardin Options', 'Cardin Options', 'manage_options', 'cardin_options', 'cardin_options_do_page');
It worked, but when i click "Save Changes" the "Settings Updated" message doesn't display anymore. What should I do to make it display again?
Thanks alot in advance and sorry for the bad english.

<?php if($_POST['oscimp_hidden'] == 'Y') { ?>
<div id="message" class="updated">
<p><strong><?php _e('Settings saved.') ?></strong></p>
</div>
edit:
heres a guide: http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/
search for: if($_POST['oscimp_hidden'] == 'Y') {

Related

wordpress admin panel get parameter

I'm developing a plugin in wordpress, there is data that needs to be listed by search but I can't get them with the get parameter.
I can send with the post parameter, but when the user refreshes the page, she has to search again according to the order number.
Following my code:functions.php
add_action('admin_menu', 'testPluginAdminMenu');
function testPluginAdminMenu()
{
add_menu_page('Return Request',
'Return Request',
'manage_options',
'list',
'myFunction'
);
add_submenu_page(
'null',
'Return Request List',
'Return Request List',
'manage_options',
'listAll',
'myFunctionList');
}
index.php
<?php
function myFunctionList(){
if(isset($_GET['request_order'])){
echo $search = $_GET['request_order'];
}
}
function myFunction(){ ?>
<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
<input type="text" name="request_order" placeholder="Search Order Number..">
<button type="submit" >Search</button>
</form>
<?php } ?>
Output from url: localhost/wordpress/wp-admin/admin.php?request_order=7481
page=listAll not appearing on url
Thank you advance.
Can you try something like this
$qs = array(
'page' => 'listAll',
'request_order' => $_GET['request_order']
);
$qs = http_build_query($qs, null, "&", PHP_QUERY_RFC3986);
<?php echo admin_url('admin.php?' . $qs ) ?>
UPDATE 1
<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
<input type="text" name="request_order" placeholder="Search Order Number..">
<input type="hidden" name="page" value="listAll" />
<button type="submit" >Search</button>
</form>

Store a dynamic value for a custom Woocommerce plugin

I read different articles, but they describe more other things. I do not want to make the wrong code with too much space. In the module there will be one single value that can be changed in the admin panel and other extraneous functions. How correctly to create a database for value of this window in a plugin?
I found the documentation, but I do not have enough experience to cut the excess, if it is.
My code /plugins/custom-counter/custom-counter.php
/*
Plugin Name: Custom Counter
Plugin URI: https://example.com
Description: This plugin adds counter.
Author: Kuznetsova Alexandra
Author URI: https://example.com
*/
// Hook for adding admin menus
add_action('admin_menu', 'custom_counter_menu');
// action function for above hook
function custom_counter_menu() {
// Add a submenu to Woocommerce menu:
add_submenu_page('woocommerce', 'Custom Counter', 'Custom Counter', 'administrator', 'custom-counter', 'custom_counter_page');
}
// custom_counter_page() displays the page content
function custom_counter_page() {
?>
<div class="wrap">
<h2>Custom Counter</h2>
<form method="post" action="options.php">
<?php settings_fields( 'baw-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Total Counter</th>
<td><input type="text" name="custom-counter" value="..." /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php }
Updated - As this is a unique value that will be updated multiple times, you can use the wp_options table with the following WordPress dedicated functions:
get_option($option); where $option is the name of option to retrieve
update_option($option, $new_value); where $option is the name of option and $new_value the new value to be updated.
The fact that options are cached is not a problem if you use some tricks as you will see below, to avoid this data to be cached.
So try the following code:
// Add a custom admin submenu to Woocommerce
add_action('admin_menu', 'custom_counter_menu');
function custom_counter_menu() {
add_submenu_page('woocommerce', 'Custom Counter', 'Custom Counter', 'administrator', 'custom-counter', 'custom_counter_page');
}
// Content for the custom Woocommerce admin submenu
function custom_counter_page() {
$option_name = 'wc-custom-counter' ;
if( isset($_POST[$option_name]) ){
$new_value = sanitize_text_field( $_POST[$option_name] );
if ( get_option( $option_name ) !== false ) {
update_option($option_name, $new_value );
} else {
add_option( $option_name, $new_value, null, 'no' );
}
}
$default = ''; // Set the default value
$value = get_option( $option_name ) ? get_option( $option_name ) : $default;
?>
<div class="wrap">
<h2><?php _e('Custom Counter'); ?></h2>
<form method="post" action="">
<?php settings_fields( 'baw-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Total Counter'); ?></th>
<td><input type="text" name="<?php echo $option_name; ?>" value="<?php echo $value; ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
Code goes in function.php file of the active child theme (or active theme). tested and work.
If the option already exist, to avoid caching issue, you should need to delete it using:
delete_option('wc-custom-counter');
And adding it in your function.php file. Then browse any page of your web site and remove it.
If you only want to store one thing, like a setting, then you can use wp_options. You can then use WordPress functions to interact with the database instead of writing your own SQL.

If the value exists show in wordpress admin (Form's have been created on the fly so number increments)

I'm creating my first options page and i'm trying to upload images for a slider, I don't know how many images are going to be in the slider so I will need to add more with a + button, It will automatically show one text input an upload button and a + button to start off with, should I require more i'll click the + button which will then add another text input, upload button a + button and a - button.
I've got this working to a point, it still needs a little help but it's getting there http://jsfiddle.net/vs8p5/5/
So far if I upload an image and click the + button, it will give me the option to upload another, this is working great and the images upload to wordpress.
Now for the issue.
I'm using this part of code to retrieve the data from wordpress
if( isset( $hero_options['upload_image_link_1'] ) && $hero_options[ 'upload_image_link_1' ] ) {
echo "<script type='text/javascript'>alert('yes it has');</script>";
}
This tells me that if there is a value then echo the alert
Now, working form that code above I've
function kandibox_hero_upload_image_link_callback($args) {
$hero_options = get_option( 'hero_options' ); ?>
<div id="upload_image_sets"> <?php
$hero_options = get_option ( 'hero_options' );
if( isset( $hero_options['upload_image_link_1'] ) && $hero_options[ 'upload_image_link_1' ] ) { ?>
<div id="clonedInput1" class="clonedInput">
<input id="upload_image_link_1" type="text" size="36" name="hero_options[upload_image_link_1]" value="<?php echo $hero_options['upload_image_link_1']; ?>" />
<input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
<div class="actions">
<button class="clone">Clone</button>
<button class="remove">Remove</button>
</div>
</div> <?php
}
else { ?>
<div id="clonedInput1" class="clonedInput">
<input id="upload_image_link_1" type="text" size="36" name="hero_options[upload_image_link_1]" value="<?php echo $hero_options['upload_image_link_1']; ?>" />
<input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
<div class="actions">
<button class="clone">Clone</button>
<button class="remove">Remove</button>
</div>
</div>
<?php } ?>
</div> <?php
}
What i'm trying to do here is echo a form with a value, if nothing exists, echo a blank form, this seems to work although I don't think it's correct.
The main issue is that it will only echo the first form, when you click the + buttons, the form's id, name, and value script increments.
So now the question.
How can I get the form to look for all the $hero_options['upload_image_link_...'] and echo out a form for each if it exists? then echo out 1 blank form if nothing exists?
I'm pretty sure i've covered everything you might need but if i've missed something, let me know and i'll add it.
I've followed about 20 tutorials old and new and come up with this.
To add the information to the wordpress database, i'm using the following code.
function register_hero_options() {
add_settings_section(
'hero_settings_section', // ID used to identify this section and with which to register options
__( 'hero Options', 'kandibox' ), // Title to be displayed on the administration page
'kandibox_hero_options_callback', // Callback used to render the description of the section
'hero_options' // Page on which to add this section of options
);
add_settings_field(
'show_hero_options', // ID used to identify the field throughout the theme
__( 'hero', 'kandibox' ), // The label to the left of the option interface element
'kandibox_toggle_hero_callback', // The name of the function responsible for rendering the option interface
'hero_options', // The page on which this option will be displayed
'hero_settings_section' // The name of the section to which this field belongs
);
$hero_options = get_option ( 'hero_options' );
if( isset( $hero_options['show_hero_options'] ) && $hero_options[ 'show_hero_options' ] ) {
add_settings_field(
'hero_size',
__( 'Size', 'kandibox' ),
'kandibox_hero_size_callback',
'hero_options',
'hero_settings_section'
);
add_settings_field(
'hero_background',
__( 'Background', 'kandibox' ),
'kandibox_hero_background_callback',
'hero_options',
'hero_settings_section'
);
add_settings_field(
'upload_image_links',
__( 'Upload Image', 'kandibox' ),
'kandibox_hero_upload_image_link_callback',
'hero_options',
'hero_settings_section'
);
}
register_setting(
'hero_options',
'hero_options'
);
}
add_action( 'admin_init', 'register_hero_options' );
$hero_options = get_option( 'hero_options' );
$count=count($hero_options);
$totalimg=$count-4; ?>
<div id="upload_image_sets"> <?php
if( isset( $hero_options['upload_image_link_1'] ) && $hero_options[ 'upload_image_link_1' ] ) {
for($i=1;$i<=$totalimg;$i++){ ?>
<div id="clonedInput1" class="clonedInput">
<input type="text" size="36" name="hero_options[upload_image_link_<?=$i ?>]" value="<?php echo $hero_options['upload_image_link_'.$i]; ?>" />
<input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
<div class="actions">
<button class="clone">Clone</button>
<button class="remove">Remove</button>
</div>
</div> <?php
}}
?>
ok i juss wrote a rough code for you might this will help you. this is according to the array you have go. there might be some better ways of doing it.
$hero_options = get_option( 'hero_options' );
$count=count($hero_options);
$totalimg=$count-4; ?>
<div id="upload_image_sets"> <?php
if( isset( $hero_options['upload_image_link_1'] ) && $hero_options[ 'upload_image_link_1' ] ) {
for($i=1;$i<=$totalimg;$i++){ ?>
<div id="clonedInput1" class="clonedInput">
<input type="text" size="36" name="hero_options[upload_image_link_<?=$i ?>]" value="<?php echo $hero_options['upload_image_link_'.$i]; ?>" />
<input id="show_upload_image_link_button_1" class="button upload_images" type="button" value="Upload Image" />
<div class="actions">
<button class="clone">Clone</button>
<button class="remove">Remove</button>
</div>
</div> <?php
}}
?>
</div> <?php
Updated the code so now it's correct.

Wordpress - Error: Options Page Not Found

I know there's a few solutions out there for this problem, but none of them seem to fix my code.
I've been following a lynda.com tutorial on creating plugins. However I believe they are using an older version of wordpress, which is why I think I'm running into trouble.
I'm trying to add an options page, but everytime I "save" on my options page it gives me "not found" error for the options.php page.
Tried linking to options.php directly (with full URL), no dice.
Tried changing register_setting to both equal the same thing, as stated in Wordpress Codex, but that didn't work.
Here's my code:
function cc_init(){
register_setting('cc_options,','cc_cc_email');
}add_action('admin_init','cc_init');
function cc_option_page(){
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>CC Comments Options</h2>
<p>Welcome to the CC comments plugin. here you can edit the email(s) to CC your comments to.</p>
<form action="options.php" method="post" id="cc-comments-email-options-form">
<?php settings_fields('cc_options'); ?>
<h3><label for="cc_cc_email">Eamil to send CC to:</label>
<input type="text" id="cc_cc_email" name="cc_cc_email"
value="<?php echo esc_attr(get_option('cc_cc_email')); ?>" /></h3>
<p><input type="submit" name="submit" value="Save Email" /></p>
</form>
</div>
<?php
}
function cc_plugin_menu(){
add_options_page('CC Comments Settings','CC Comments','manage_options','cc-comments-plugin','cc_option_page');
}add_action('admin_menu','cc_plugin_menu');
I think I had my add_action('admin_menu', 'cc_plugin_menu'); in the wrong spot. I moved it into the cc_plugin_menu function and it seems to save OK now.
Here's the updated code:
add_action('admin_menu', 'cc_plugin_menu');
function register_mysettings() {
register_setting( 'cc_options', 'cc_cc_email' );
}
function cc_option_page() {
?>
<div class="wrap">
<h2>CC Comments Options</h2>
<p>Welcome to the CC comments plugin. here you can edit the email(s) to CC your comments to.</p>
<form method="post" action="options.php" id="cc-comments-email-options-form">
<?php settings_fields( 'cc_options' ); ?>
<?php do_settings_sections( 'cc_options' ); ?>
<h3><label for="cc_cc_email">Eamil to send CC to:</label>
<input type="text" id="cc_cc_email" name="cc_cc_email"
value="<?php echo esc_attr(get_option('cc_cc_email')); ?>" /></h3>
<p><input type="submit" name="submit" value="Save Email" /></p>
</form>
</div>
<?php
}
function cc_plugin_menu(){
add_options_page('CC Comments Settings','CC Comments','manage_options','cc-comments-plugin','cc_option_page');
add_action( 'admin_init', 'register_mysettings' );
}

Wordpress Theme Options field not retaining value

I'm having what im sure is a simple issue but i can't manage to figure it out.
I'm coding a theme options page for my wordpress template and i've managed to get it where the values are saved and i can use them on the site but whenever i reload the theme options page all the form fields are blank and any previously applied settings are gone. My code is below.
<?php
//Theme Options Functionality is Below
if (get_option('pardue_theme_options')){
$theme_options = get_option('pardue_theme_options');
} else {
add_option('pardue_theme_options', array(
'sidebar2_on' => true,
'footer_text' => 'Made by William'
));
}
?>
<?php add_action('admin_menu', 'theme_page_add');
function theme_page_add() {
add_submenu_page('themes.php', 'Pardue Theme Options', 'Theme Options', 'administrator', 'themeoptions', 'theme_page_options');
}
function theme_page_options() {
global $theme_options;
$new_values = array(
'footer_text' => htmlentities($_POST['footer_text'], ENT_QUOTES),
);
update_option('pardue_theme_options', $new_values);
$theme_options = get_option('pardue_theme_options');
echo '<div class="wrap">';
echo '<h2>Theme Options</h2>';
?>
<form action="themes.php?page=themeoptions" method="post">
<label for="footer_text">Footer Text: </label><input name="footer_text" id="footer_text" value="<?php echo $theme_options['footer_text']; ?>" /> <br /> <br />
<label for="sidebar_checkbox">Sidebar 2 on: </label> <input name="sidebar_checkbox" id="sidebar_checkbox" value="on" type="checkbox" /> <br /> <br />
<input type="submit" value="Update Options" name="submit" />
</form>
<?php
echo '</div>';
}
?>
I found a good solution for coding my theme options. The plugin at the link below makes it very easy to code up theme options.
Link to plugin
Documentation is included when you activate the plugin.

Categories