Wordpress: Disable plugin in attachment page - wordpress

I Have plugin for image lazy load, and i need to disable this plugin in any attachment page.
How can do that ?

By default admin has the access to manage the plugins page in WP.
But you can make this accessible by public also.
Just need to add a capability to subscriber role
function add_theme_caps() {
// gets the subscriber role
$role = get_role( 'subscriber' );
//add capability to this role
$role->add_cap( 'activate_plugins' );
}
add_action( 'admin_init', 'add_theme_caps');
activate_plugins is a capability provided to admin user only by WordPress.
but we can add the capability to any other user role. And Subscriber is considered as the public of WP site, So this code will do the needful.
Note : This can be dangerous in terms of security.

Related

Allow Woocommerce shop manager to assign a role when creating a user

The custom role shop manager created by Woocommerce can only assign the customer role when adding a user.
I'm trying to let shop manager choose from the different roles by enabling the capability promote_users.
function shop_manager_add_users() {
$role = get_role( 'shop_manager' );
$role->add_cap( 'promote_users' );
}
add_action( 'admin_init', 'shop_manager_add_users');
It's not working, the selection drop down only offers the customer role, and other roles are still hidden.
Is there another capability that should be enabled?
Actually Woocommerce adds specific restrictions to the Shop Manager role.
This worked and allowed a consigner custom role to be available in the dropdown :
function shop_manager_role_edit_cap( $roles ) {
$roles[] = 'consigner';
return $roles;
}
add_filter( 'woocommerce_shop_manager_editable_roles', 'shop_manager_role_edit_cap' );
Source: developer.woocommerce.com/

Is there a way to access WordPress logged user from another asp.net site?

I have 2 totally separate sites, first is WordPress, and second is asp.net. I need when a user open asp.net website, check if he didn't logged in WordPress site, redirect to login form of WordPress.
You Can Call Api To Asp.net After User Logged Action And Loggout Acction
With The Below Code
you can use this code in your functions.php At Your Active Theme
<?php
function your_function( $user_login, $user ) {
// your code
// Clall APi To Asp.net -> User Logged IN
}
add_action('wp_login', 'your_function', 10, 2);
?>
For Logout, You Can Call Another API
function wpdocs_redirect_after_logout() {
$current_user = wp_get_current_user();
// Your Api Code Here
}
add_action( 'wp_logout', 'wpdocs_redirect_after_logout' );

WordPress WooCommerce - Disable "my account" screen and allow users to go to wp-admin

When you install WooCommerce, a new page is created called "My Account".
When subscriber level users attempt to go to any admin page, including the user's profile at /wp-admin/users.php they get redirected.
Cannot access this screen with WooCommerce as a subscriber:
How can I disable this behavior? What are the filters or hooks that need to be changed?
This is meant to redirect users with "customer" role to a custom URL
add_filter( 'woocommerce_login_redirect', 'custom_login_redirect');
function custom_login_redirect( $redirect, $user ) {
if ( wc_user_has_role( $user, 'customer' ) ) {
$redirect = get_home_url(); // homepage
//$redirect = '/custom_url'; // custom URL same site
}
return $redirect;
}

How to assign admin role to a user in wordpress?

I am working on a website where I have student guardian relationships. So when a guardian is visiting his student profile, he should be able to edit, delete all the fields that a user itself can do. I am using buddypress and have used rtmedia plugin. Now For example, student uploads media, images. By default, other user can't delete or edit the media. But in my case, guardian should be capable of editing and deleting students media. I am thinking that if I assign the admin role to guardian when he is viewing students profile then my problem can be solved. But I don't know how to assign a user amdin role. Thanks
I would recommend reading up on the User admin screen in the WordPress codex:
https://codex.wordpress.org/Users_Screen#Change_Roles_to
It explains how to switch roles for existing users, as well as assigning roles to existing ones:
https://codex.wordpress.org/Users_Add_New_Screen
You don't want to give them an admin role.
You want to check for a student/guardian relationship and if found allow edit access.
To allow such access, you'll have to do various operations, for example, in BP, filter the profile screens loop to allow editing.
Create php file to plugins directory and add below content
<?php
/* Plugin Name: Add role */
function add_roles() {
$result = add_role(
'admin',
__( 'Admin' ),
array(
'edit_posts' => true, // true allows this capability
'read' => true,
'delete_posts' => false, // Use false to explicitly deny
)
);
if ( $result !== null ) {
echo 'New role created';
}
else {
echo 'Role already exists..';
}
}
register_activation_hook( __FILE__, 'add_roles' );
Above more capabilities can be added accordingly
More about capabilities at http://code.tutsplus.com/articles/wordpress-roles-and-capabilities-the-basics--wp-25921
Activate plugin and check under users to assign admin role
for guardian role assign capabilities to delete or edit the media.
For guardian (after visiting his student profile to edit or delete all the fields that a user itself can do) assign admin role and assign capabilities same as student by editing capabilities of plugin.
Then after reactivate plugin.

Woocommerce New Customer Admin Notification Email

I am building an ecommerce site using Wordpress and Woocommerce. I need the site to send out a notification email to the site administrator when a new customer account is registered. I thought this functionality would be built into Woocommerce since it uses the Wordpress user account structure and Wordpress sends new user notifications, but it doesn't appear to be. Does anyone know of a plugin or a function I can use to add this functionality? Thanks!
I'm assuming that you are using html inside emails. If you are using plain text the procedure is similar.
You need to override the woocommerce template structure. Here you can find how: http://docs.woothemes.com/document/template-structure/.
Actually the only file you need to override is your_template_directory/woocommerce/emails/customer-new-account.php.
At the end of this file add this line of code:
<?php do_action( 'new_customer_registered', $user_login ); ?>
In functions.php add this:
function new_customer_registered_send_email_admin($user_login) {
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>The user '.esc_html( $user_login ).' is registered to the website</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');
add_action('woocommerce_created_customer', 'admin_email_on_registration', 10 , 1);
function admin_email_on_registration( $customer_id) {
wp_new_user_notification( $customer_id );
}
woocommerce_created_customer is hook which is called when user created by woocommerce. It only sends notification to customer. we will use wp_new_user_notification() function to send notification to Admin.
I was pulling my hair out trying to figure this same issue out and after going back and forth with the developers the default is to not send new customer registration notification emails to admin.
After trying various email plugins and even resorting to using WP SMTP Email, I finally decided to leave it alone.
That said, WooCommerce 2.0 was released today so it may be built in the new version.
the answers is in the emails sections of "woocommerce / settings"
simply change the from email to wordpress#yourdomain.com
worked for me as i also had the same issues
To notify admin whn new user has registered use:
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id )
{
wp_send_new_user_notifications( $customer_id, 'admin' );
}
See documentation on https://woocommerce.com/document/notify-admin-new-account-created/

Resources