I'm searching the WordPress codex for this but I can't seem to find any article on this issue.
When you have installed WordPress multisite and login as the superadmin you have the ability to archive,(de)activate and delete sites. This is however from the 'network' part of the installation, that only the superadmin can see. I want to place take the (de)activate option in every site's dashboard as well, so a specific (non (super)admin) role can use them to.
I want to know, is there a function I can use to display the (de)activate (depending on if the sites is active/deactive at that moment) links where I want to?
If there is not, where is the information about whether a site is active or not stored ? I was hoping for an option with a boolean in it but I can't seem to find it. This way I will be able to check myself if a site is active or not and depending on that display the correct link?
Sorry if my question is unclear or confusing.
Thanks in advance!
Deactivating the site, just adds the deleted attribute on it. And site administrators already can do that by visiting Tools -> Delete site. It is only a little different because it also removes the users from the site if it is clicked from there (it might be made in the future to be the same though).
You can use this function to see if a site with ID 2 for example has the attribute deleted (so it is deactivated):
if ( get_blog_status( 2, 'deleted' ) == 1 ) {
// The site with ID 2 is marked as deleted (it is deactivated)
}
For the specific username rights I used:
//give the right to deactivate sites to 'username' if the user doesn't have it already
$user = new WP_User( 'username' );
if ( ! $user->has_prop( 'can_manage_sites' ) ) {
$user->add_cap( 'can_manage_sites' );
}
if ( ! $user->has_prop( 'username' ) ) {
$user->add_cap( 'manage_sites' );
}
//ofcourse replace 'username' with the username you need
In my view (wich loops mu sites) I simply used an if statement to check if the site was active or not to know what link to use (activate/deactivate)
//deactivated, show activate link
if(get_blog_status( $site->blog_id, 'deleted' ) == '1'){
echo '<span class="dashicons dashicons-no" style="color:red;"></span> Niet actief <br/>';
echo '' . __( 'Activate' ) . '';
}
//activated, show deactivate link
else {
echo '<span class="dashicons dashicons-yes" style="color: green;"></span> Actief<br/>';
echo '<a style="color:red;" href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $site->blog_id ), 'deactivateblog_' . $site->blog_id ) ) . '">' . __( 'Deactivate' ) . '</a>';
}
This code will get you the link you need to (de)activate the site wich will get you to a confirmationpage.In this confirmationpage the user can see a 'sites'tab in the menu, when they click it they have the options for all the sites in the mu. This didn't matter for me since the people who will be using this functionality are colleages and know they shouldn't go there. But you might want to hide that if it concerns people who shouldn't be able to see that
Related
Trying to change the href="" of my website logo based on specific costumer groups (we do have 5 of them).
Here's to add a new class (ex: retailer-5%) when they log in:
add_filter( 'body_class', 'body_class_user_role' );
function body_class_user_role( $classes ) {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = $user->roles;
$classes[] = 'user-role-' . $roles[0];
}
return $classes;
}
What I would like to achieve is when user group class is (ex: retailer-5% ) the link on the logo which is pointing to www.mysite.com points to a specific page like www.mysite.com/retailers-landing
Is there a way to achieve this, please? I'm using Uncode theme and Wordpress latest versions.
Tried this answer but did not work. among others. For my case i need to check first of all the costumer group then change the link of the logo.
Any help would be appreciated.
I am using the plugin force login: https://en-gb.wordpress.org/plugins/wp-force-login/ and need to allow guests to get to the order received page after purchasing.
After checking out, a user which is logged in would be forwarded to this page: [mydomain]/checkout/order-received/[order_id]/?key=[order_key]. I have tried this: Show customer details on WooCommerce Thankyou page even if not registered but could not figure out what to do after I added it.
I currently have this code which allows certain pages to be whitelisted so users that are not logged in can bypass the "force-login" plugin and pay for the relevant product:
add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
function my_forcelogin_whitelist() {
return array(
home_url( '/cart/' ),
home_url( '/checkout/' ),
home_url( '/cart/?add-to-cart=1465' ),
);
}
I want none logged in users to be forwarded to a page which looks like this after checkout:
[mydomain]/checkout/order-received/5304/?key=wc_order_5cffcfbc96028
For anyone that has this problem this is how I got it working. Since some of the URL's generated are dynamic I needed a work around for those. Using the following code in function.php works for ALL URL's assiciated with woocommerce:
function my_forcelogin_bypass( $bypass ) {
if ( class_exists( 'WooCommerce' ) ) {
if ( is_woocommerce() || is_wc_endpoint_url() ) {
$bypass = true;
}
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );
WooCommerce Checkout/order-received issue
For the problem of [mydomain]/checkout/order-received/[order_id]/?key=[order_key] it is not loading right or is not showing something or 500 Internal Server Error ?
For Temporary purpose because whenever the plugin will be updated the file will be updated in a woo-commerce plugin?
Open File Zilla
The Visit : /var/www/html/wp-content/plugins/woocommerce/includes directory
Then in the directory open : class-wc-order.php
Find this with ctrl+F : get_checkout_order_received_url()
There Will be two lines of code(Earlier) :
$order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() );
$order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
Change to(Updated) Add a comment in the second line :
$order_received_url = wc_get_endpoint_url( 'order-received', $this->get_id(), wc_get_checkout_url() );
//$order_received_url = add_query_arg( 'key', $this->get_order_key(), $order_received_url );
Save it and update it to the server.
You issue will be resolved, but it's for temporary it will be changes whenever the woocommerce plugin will be updated, so you have to update it again.
Thanks!
How a post in wordpress add comment only for logged users?
visitors must answer their own add in comments. but i need a post, leave a comment (only for logged users) and users must register to site beforce add comment to post
can use functions file to do it ?
i found that 2 code but not work and do not know how to use it:
in facing link find this:
https://codex.wordpress.org/Function_Reference/wp_get_current_user
Code:
<?php
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
} else {
// Logged in.
}
?>
and in facing link find this:
https://codex.wordpress.org/Function_Reference/comment_form
code:
'<p class="must-log-in">' . sprintf( __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>'
and from the combination of these two together, I built below function!
<?php
$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
// Not logged in.
'<p class="must-log-in">' . sprintf( __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>'
} else {
// Logged in.
}
?>
and add this to my post with Insert PHP Code Snippet plugin for use only (a) post
please help me to do this. thank you all
Settings > Discussion you will find the option: Users must be registered and logged in to comment. - http://prntscr.com/k2f02d
Checked this option and save the settings your requirement will be fulfilled.
Review below menu navigation
Settings >>> Discussion
Checked the "Users must be registered and logged in to comment " checkbox
The profile-update URLs for User Profiles are language specific: .../nl/profile.php and .../en/profile.php. When users click "Update Profile" I can redirect them to any URL. But now I want to test the current URL to see if there's /nl/ in there, so I can give them a redirect to their own language. I use the code below but the result of the 'if statement' is always false. I can see that: when I enter another url there, it picks up that one. So the code seems to work, just the test fails. Any ideas what I'm doing wrong?
add_action( 'profile_update', 'custom_profile_redirect', 12 );
function custom_profile_redirect() {
if(strpos("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", '/nl/') === false ) {
wp_redirect( trailingslashit( home_url() . '/en' ) );
} else {
wp_redirect( trailingslashit( home_url() . '/nl' ) );
}
exit;
}
[edit:] Variables I managed to retrieve are all set to 'en' after the profile update, even the plugin's global variable. I now worked around it by adding a LanguagePreference dropdown in the sign up form. In the After-Update-Redirect, I read the usermeta and redirect to their own preference.
There must be better ways to achieve this...
Is it possible to call bp_get_options_nav() for a specific group ? I need to get the same in-group navigation in every post with a defined post type.
Posts are associated with Groups by slugs and both the group has a meta of post id and the post has a meta of group id (Groups were created from posts), and I'm trying to make the navigation between them seamless.
Read This url:-
http://www.generalthreat.com/2011/10/creating-a-buddypress-group-home-page/
https://wordpress.stackexchange.com/questions/58485/adding-navigation-item-page-for-quick-chat-plugin-to-each-of-my-buddypress-group
Or Try
Creating a BuddyPress Group Home Page
Step One: Create an Activity tab for the activity stream, since we’re displacing it.
To do this, we’re going to use parts of the Group Extension API to create a new nav item for the group.
In your theme’s functions.php, add the following:
function add_activity_tab() {
global $bp;
if(bp_is_group()) {
bp_core_new_subnav_item(
array(
'name' => 'Activity',
'slug' => 'activity',
'parent_slug' => $bp->groups->current_group->slug,
'parent_url' => bp_get_group_permalink( $bp->groups->current_group ),
'position' => 11,
'item_css_id' => 'nav-activity',
'screen_function' => create_function('',"bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );"),
'user_has_access' => 1
)
);
if ( bp_is_current_action( 'activity' ) ) {
add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( 'Activity' ) . '";' ) );
add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( 'Activity' ) . '";' ) );
}
}
}
add_action( 'bp_actions', 'add_activity_tab', 8 );
That adds a tab called ‘Activity’ to every group’s navigation bar, pointing to a page called ‘activity’ within the group. This new activity page is calling the same groups/single/home.php template file as the current home page. That template actually handles routing for ALL group pages, as we’ll see in a minute.
Step Two: Create a template file for your group Home page
If you’re going to have a Group home page, you need to control how it’s displayed. To do that, you’ll need a template file in your theme’s groups/single directory. It can be called whatever you’d like, but for this guide, we’re sticking with front.php.
Create this file and put whatever you want in it. This template will be in the “group loop”, so you can use functions like bp_group_description() to display group info.
Here’s an example:
<div class="home-page single-group" role="main">
<?php if(bp_is_item_admin()) { ?>
<div class="notice info">
<p>Welcome to your group home page!<br />
Click Admin above to set the content for this page.</p>
</div>
<?php } ?>
<?php bp_group_description(); ?>
</div>
Up to now, all we’ve done is create a new Activity tab on the group page that doesn’t even show the activity stream. But this last piece will make everything work:
Step Three: Edit your theme’s groups/single/home.php template file
Look for this section in your home.php file:
elseif ( bp_group_is_visible() && bp_is_active( 'activity' ) ) :
locate_template( array( 'groups/single/activity.php' ), true );
elseif ( bp_group_is_visible() ) :
locate_template( array( 'groups/single/members.php' ), true );
This directs a visitor to either the activity stream or the member list, depending on whether activity has been enabled. It’s a catch-all routing section, and it’s where we’ll be adding our group home page.
Change the lines above to:
elseif ( bp_group_is_visible() && bp_is_group_activity() ) :
locate_template( array( 'groups/single/activity.php' ), true );
elseif ( bp_group_is_visible() ) :
locate_template( array( 'groups/single/front.php' ), true );
This enables the Activity tab AND sends requests for the group home page to your new template! Of course, if you used a name other than front.php, you’ll need to change that line to match the name you chose.
Update! Step Four – Let BuddyPress JS know how to classify your new activity posts
Now you can make activity updates, but BuddyPress won’t remember that they came from your group. In order to fix that, we need to relax a check in another file, activity/post-form.php.
<?php elseif ( bp_is_group_home() ) : ?>
<input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
<input type="hidden" id="whats-new-post-in" name="whats-new-post-in" value="<?php bp_group_id(); ?>" />
<?php endif; ?>
Without those hidden fields, BuddyPress thinks we’re just posting a personal status update. So let’s expand that to cover our new Activity page:
<?php elseif ( bp_is_group() ) : ?>
<input type="hidden" id="whats-new-post-object" name="whats-new-post-object" value="groups" />
<input type="hidden" id="whats-new-post-in" name="whats-new-post-in" value="<?php bp_group_id(); ?>" />
<?php endif; ?>
Now BuddyPress will tie the update to a group no matter where in the group we post it.
That’s it! Check out your new group home page and enjoy the results your BuddyPress hacking chops. And if you do something really cool with a group Home page, send a link my way!