I am working on uninstall.php script and want to know how to properly delete option in multi-sites environment. So far I have the following:
if ( ! is_multisite() ) {
delete_option('my-option-name');
} else {
# Get all sites
$sites = # Not sure how to get this
foreach ( $sites as $site ) {
switch_to_blog( $site);
delete_option('my-options-name')
}
restore_current_blog();
}
Or does the following code achieve the same thing?
if ( ! is_multisite() ) {
delete_option('my-option-name');
} else {
delete_site_option('my-option-name');
}
Related
I need help, I have been at this for too many hours for me to no be embarrassed. Please, why am I not getting this?
function members_only() {
$cookie_name = 'cookie_name';
$error_url = home_url($path = '/403-error/');
global $pagenow;
$array_cookie_value = json_decode( stripslashes($_COOKIE[$cookie_name]), true);
$woo_user_id = $array_cookie_value['user_id'];
$user_meta = get_user_meta($woo_user_id);
$user_order_status = $user_meta['doris_shop_enabled'][0];
if ( is_admin() || is_front_page() || $pagenow == 'wp-login.php' || is_page('403-error') ) {
echo('Do nothing');
} elseif ( !isset($_COOKIE[$cookie_name]) || (isset($_COOKIE[$cookie_name]) && $user_order_status === 0) ) {
wp_safe_redirect( $error_url );
exit;
} else {
echo("Very limited.");
}
}
add_action( 'wp', 'members_only' );
The problem was in Chrome data that was saved, outside of the cookie and hard-refresh which I make regularly. I needed to go into the Settings > Cookies and other website data and empty it all from there. After that I got it to work.
Yes I made some minor changes to the code also, but that was the main problem.
Thanks all for trying to help :)
I was trying to make this with nginx and also with php header redirect in wordpress index.php but I always find myself in an infinite loop.
I just want to redirect iphone user to /category/iphone/ or android user to /category/android/ of my wordpress page.
Is this possible?
Thank you for your help!
Edit:
Maybe I was not totally clear. I only want to redirect a user if he comes to INDEX/MAIN page. He can still browse other categories without redirecting him to iphone/android category.
This if statment will allow you to to detect iOS and mobile device visitors using one of the following:
if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
$device = "ipad";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
$device = "iphone";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
$device = "blackberry";
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
$device = "android";
}
if( $device ) {
return $device;
} return false; {
return false;
}
}
Even you can use .htaccess file like:
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://www.yoururl.com [R=301]
For in your functions.php file:
add_action( 'template_redirect', 'device_redirect' );
function device_redirect(){
if ( is_front_page() && is_home() ) {
if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
wp_redirect( "http://www.example.com/iphone", 301 );
} else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
wp_redirect( "http://www.example.com/andriod", 301 );
}
}
}
In case you use a static homepage or blog page you have to change the if.
For example
if ( is_front_page() && is_home() ) {
// Default homepage
}
if ( is_front_page()){
//Static homepage
}
if ( is_home()){
//Blog page
}
Here is a simple example of what I am trying to achieve:
I have a gravity form with different sections that will be shown conditionally by pre-populating dynamically. The thing is that I can't seem to populate them based on my ACF data (which are checkboxes as well).
If I put the values into the code it works like this:
add_filter( 'gform_pre_render_2', 'my_populate_checkbox' );
function my_populate_checkbox( $form ) {
foreach( $form['fields'] as &$field ) {
if( 11 === $field->id ) {
foreach( $field->choices as &$choice ) {
if( 'mychoice' === $choice['value'] || 'anotherchoice' === $choice['value'] ) {
$choice['isSelected'] = true;
}
}
}
}
return $form;
}
To get it to be populated dynamically I was trying something like this which didn't work (not that good with php):
add_filter( 'gform_pre_render_2', 'my_populate_checkbox' );
function my_populate_checkbox( $form ) {
foreach( $form['fields'] as &$field ) {
if( 11 === $field->id ) {
foreach( $field->choices as &$choice ) {
$addons = get_field('addons');
if( $addons === $choice['value'] ) {
$choice['isSelected'] = true;
}
}
}
}
return $form;
}
It's not working and I know I am missing something here but can't figure out what it is:/ Any help or pointers would be highly appreciated! I tried keeping it precise but if any more information is required please let me know and I will update the post accordingly.
Figured it out with some help:) In case anybody needs this functionality, here is how it works:
add_filter( 'gform_pre_render_2', 'my_populate_checkbox' );
function my_populate_checkbox( $form ) {
global $post;
$adfields = get_field( 'addons', get_the_ID() );
foreach( $form['fields'] as &$field ) {
if( 11 === $field->id ) {
foreach( $field->choices as &$choice ) {
if( in_array( $choice['value'] ,$adfields )) {
$choice['isSelected'] = true;
}
}
}
}
return $form;
}
I'm trying to alter the experience of the user by changing the page templates based on URL UTM variables.
Example, if the utm_source=google I want to show the person the page-google.php.
Here's the code I have so far.
<?php if ( isset( $_GET['utm_source'] ) && $_GET['utm_source'] == 'test' )
{
get_page_template(test);
}
else {
get_page_template(gallery);
}
?>
I'm not sure 1) if this is the right way 2) where it should be placed in wordpress.
Thanks for your help!
in page.php
<?php if ( isset( $_GET['utm_source'] ) && $_GET['utm_source'] == 'test' ) {
get_template_part('test');
}
else {
get_template_part('gallery');
}
?>
this is if test.php is in your sites theme directory
I have a problem.
I want to disable 'dev_mode' if 'opt_name' not redux_demo, using the if statment, but it did not work ... where does the fault ??
I found the code on Here
and I turn it into like this
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
if ( $redux->args['dev_mode'] == true ) {
$redux->args['dev_mode'] = false;
}
} else {
if ( $redux->args['dev_mode'] == false ) {
$redux->args['dev_mode'] = true;
}
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
the above code, I input in config.php
Thanks B4 and sorry my english is not good. :D
You can also filter the args JUST for your opt_name using this:
apply_filters( "redux/args/{$this->args['opt_name']}", $this->args );
if ( ! function_exists( 'redux_disable_dev_mode_plugin' ) ) {
function redux_disable_dev_mode_plugin( $redux ) {
if ( $redux->args['opt_name'] != 'redux_demo' ) {
$redux->args['dev_mode'] = false;
}
}
add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}
In framework.php (for me it's from line 1281). It worked for me after making those two attr false.
// Force dev_mode on WP_DEBUG = true and if it's a local server
if ( Redux_Helpers::isLocalHost() || ( Redux_Helpers::isWpDebug() ) ) {
if ( $this->args['dev_mode'] != true ) {
$this->args['update_notice'] = false;
}
$this->dev_mode_forced = true; // make it false
$this->args['dev_mode'] = true; //make it false
}