I am developing a gallery plugin. So i created a custom post type and under it i created a submenu page for changing gallery options such a border-width, border-color, border-radius etc. when i update the values, all are working but update notification is not showing.
I am writing main code here. Please let me know what is problem.
function gallery_setting_pages() {
add_submenu_page(
'edit.php?post_type=gallary',
'Gallery Settings',
'Settings',
'manage_options',
'gallery-setting',
'gallery_option_page_functions'
);
}
add_action('admin_menu','gallery_setting_pages');
if ( is_admin() ) :
function ppmscrollbar_register_settings() {
register_setting('gallery_plugin_options','rt_gallery_options','rt_gallery_validate_options');
}
add_action('admin_init','ppmscrollbar_register_settings');
function gallery_option_page_functions() {
global $rt_gallery_options;
if ( ! isset ($_REQUEST['updated'] ) )
$_REQUEST['updated']=false;
?>
<?php if ( false !==$_REQUEST['updated'] ) : ?>
<div class="updated fade"><p><strong><?php _e('options saved'); ?></strong></p></div>
<?php endif; // If the form has just been submitted, this show the notification ?>
<form method="post" action="options.php">
<?php $settings=get_option( 'rt_gallery_options', $rt_gallery_options); ?>
<?php settings_fields('gallery_plugin_options'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cursor_color">Select Gallery Border Color</label></th>
<td>
<input id="cursor_color" type="text" name="rt_gallery_options[cursor_color]" value="<?php echo stripslashes($settings['cursor_color']); ?>" class="my-color-field" /><p class="description">In a few words, explain what is this.</p>
</td>
</tr>
</table>
<p class="submit"><input type="submit" value="Save Changes" class="button button-primary" id="submit" name="submit"></p>
</form>
</div>
<?php
}
function rt_gallery_validate_options( $input ){
global $rt_gallery_options;
$settings = get_option( 'rt_gallery_options', $rt_gallery_options );
//We strip all tags from the text field, to avoid vulnerablilties like XSS
$input['cursor_color']=wp_filter_post_kses( $input['cursor_color']);
return $input;
}
endif; //EndIf is_admin()
thanks for being posted the question on stackoverflow to get answers. We are here to help you.Please mention the page name you are using above , and let me know where you are updating the variable "updated" in your page. The issue might be, if you are not setting the variable, then if condition always fails, and notification will not be shown.
Related
I need to apply WHERE status!='disable' in my php code at $result after I click on the checkbox and then on uncheck of the checkbox it should be removed again and both enable and disable datas from MySql should be shown in the php, is that possible without using AJAX codes, if it is then how can I do that. Can anyone find where am I going wrong
Checkbox, code given below:
<h4 id="CATEGORIESfilters">Availability</h4>
<table border="0" cellspacing="0" id="Availabilitytable">
<tr>
<td>
<input type="checkbox" name="Availability" id="Availabilitycheckboxexcludeoutofstock" >
</td>
<td>
<label for="Availabilitycheckboxexcludeoutofstock">Exclude Out Of Stock</label>
<td>
</tr>
</table>
Php Code is given below:
<?php
include "db_connection.php";
if(isset($_REQUEST['Availability']))
{
$availability="WHERE status!='disable'";
}
else
{
$availability="";
}
$result = mysql_query("SELECT * FROM burger $availability ORDER BY product_no_id DESC");
while($data=mysql_fetch_array($result)):
if($data['status']=="enable")
{
?>
<div class="productwrap">
<div id="Instockwrap">
In Stock
</div>
</div>
<?php
}
else
{
?>
<div class="productwrap">
<div id="Outofstockwrap">
Out Of Stock
</div>
</div>
<?php
}
endwhile;
?>
you can add a class to the out of stock items and hide them via jquery if checkbox is checked, so you dont have to reload the page on checkbox changes
I want to show dynamic title that means user can add his own title from theme options, but it's not going up. My theme options page is working fine and even my title is showing up in the options page ... while unable to show on page.
Here is mine code for theme options.
<!-- Option 2: Custom Heading for banner -->
<tr valign="top">
<th scope="row"><?php _e( 'Heading for page banner' ); ?></th>
<td>
<input id="theme_settings[heading]" type="text" size="36" name="theme_settings[heading]" value="<?php esc_attr_e( $options['heading'] ); ?>" />
<label for="theme_settings[heading]"><?php _e( 'Enter your desired title here' ); ?></label>
</td>
</tr>
It shows a good title like shown below in image theme options page!
Now the problem is that once I use code in my main page it never shows up, while its saved in WordPress as shown in red rectangle in above image.
Here is the code I am using in my main page, that code is being used in 2 pages, index.php and frontpage.php:
<?php if($options['heading']) { ?>
<h1><?php echo $options['heading']; ?></h1>
<?php } else { ?>
<h1>a fresh start for the family</h1>
<?php } ?>
Can any one point out the mistake?
Image removed as I could not upload ... simply means that my theme options allow me to add title in backend and even saved that title but now my page still shows that static title.
If you are not getting your value from database then you can use get_option to simply fetch your value and then you can proceed.
Here is the example code snippet:
<p><?php echo esc_html( sprintf( __( 'Character set: %s', 'textdomain' ), get_option( 'blog_charset' ) ) ); ?></p>
Here is the full WordPress get_option page reference URL ... https://developer.wordpress.org/reference/functions/get_option/
I am trying to add color picker in wordpress settings API for plugin development. But I am facing problem to do that. I have code this for color picker.
// Create this function for color picker.
add_action( 'admin_enqueue_scripts', 'mw_enqueue_color_picker' );
function mw_enqueue_color_picker( $hook_suffix ) {
// first check that $hook_suffix is appropriate for your admin page
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'my-script-handle', plugins_url('my-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}
//Call it in my input field option
<tr valign="top">
<th scope="row"><label for="cursor_color">ScrollBar Color</label></th>
<td>
<input id= "cursor_color" type="text" name="ppmscrollbar_options[cursor_color]" value="<?php echo stripslashes($settings['cursor_color']);?>" class="my-color-field"/><p class="description">Select Icon holder color here. You can also add html HEX code.</p>
</td>
</tr>
//In my-script.js file I have written this bellow code.
jQuery(document).ready(function($){
$('.my-color-field').wpColorPicker();
});
I did not solve the issue. Can anyone tell me what can I do?
I'm really not sure why your code is not working, maybe the issue is not in the code you posted... The following is almost the same as yours, but a complete demonstration:
add_action('admin_menu', 'color_pick_so_23696173');
function color_pick_so_23696173()
{
$my_page = add_dashboard_page(
'colorpick',
'colorpick',
'add_users',
'colorpick-page',
'color_pick_callback_so_23696173'
);
add_action( "admin_print_scripts-$my_page", 'enqueue_so_23696173' );
}
function enqueue_so_23696173()
{
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script(
'colorpick',
plugins_url( 'my-script.js', __FILE__ ),
array( 'wp-color-picker'),
false,
true
);
}
function color_pick_callback_so_23696173()
{
?>
<div class="wrap">
<h2>Test</h2>
<table>
<tr valign="top">
<th scope="row"><label for="cursor_color">ScrollBar Color</label></th>
<td>
<input id= "cursor_color" type="text" name="ppmscrollbar_options[cursor_color]" value="" class="my-color-field"/>
<p class="description">Select Icon holder color here. You can also add html HEX code.</p>
</td>
</tr>
</table>
</div>
<?php
}
And my-script.js is exactly the same as yours.
I'm using the following inside images-options which is linked to functions.php. When clicked on submit button it crashes in WordPress admin.
<th scope="row">Image 1:</th>
<td>
<input type="text" name="director_image1" value="<?php print get_option('director_image1'); ?>" />
<br/>
</td>
</tr>
I am using this to get the image in header.php.
var theImage=<?php $image = get_option('director_image1');?>
<?php if( $image) : ?>
<?php echo "'".$image."';"; ?>
<?php endif; ?>
And finally i am using theImage variable inside a javascript file :
{
src: theImage
fade: 3000
}
Could you please help me out the image is not being displayed.
The problem was that i didn't add , after the link which is necessary in javascript. But i used ; which is shouldn't be added after a link src in javascript.
I have form where the select boxes are there and select all option, i want to post all the data without click on check boxes, i dont want to view this page, mean if user go to signup page the data will already selected by default how can i do that wothout any view?
this is my view code
<?php v_start($this);?>
<?php
#if(element exits of controller-action)
echo $this->element('validations/users/signup');
?>
<script>
function toggleChecked(status)
{
jQuery(".new-checkbox input").each( function() {
jQuery(this).attr("checked",status);
}
)
}
</script>
<h1><span style="color:CornflowerBlue"><?php echo __l('Step1');?></span></h1>
<?php
$form = $this->FormManager;
echo $form->create('User',array_merge($form_options,array('default'=>true)));
?>
<table width = "100%">
<tbody>
<tr>
<td>
<?php echo $form->input('',array('id'=>'mark-all','onclick'=>'toggleChecked(this.checked)','type'=>'checkbox','label'=>'Select All Products' ));?>
<?php echo $form->input('product_id',
array(
'multiple'=>'checkbox',
'options'=>$products,
'div'=>false,
'class'=>'new-checkbox'
)
);
?>
</td>
</tr>
<tr>
<td>
<?php
echo $this->FormManager->end(LBL_BTN_NEXT);
?>
</td>
</tr>
</tbody>
</table>
i dont want this page, the user will select the data by default.
this is my controller code
$products = $this
->User
->ProductsUser
->Product
->find('list',array(
'fields' => 'product_id,name',
'conditions'=>array(
'Product.is_visible'=>true
)
)
);
$this->set('products',$products);
if($this->request->is('post'))
{
$this->Session->write('signUp.signUpProduct',$this->request->data['User']);
$this->redirect(array('action'=>'signup_product'));
}
}
how can i do that, Thanks in advance.
The attr() doesn't take true or false as an argument.
jQuery(this).attr("checked","checked"); // Correct usage of attr()
Although I think attr is deprecated for the favorable prop() method.
jQuery(this).prop("checked",status);
Which indeed does take a true/fales argument. :)
Hope this helps.