WP Delete User Button missing - wordpress

We have a Wordpress installation with a lot of users. If we wanted to delete a user so far, it took a long time until the delete button appeared. Then the deletion always worked. But now the button doesn't appear anymore. I have the feeling it's because it always first goes through the 400,000 users and it's because of that. I'm using WP version 4.9.8

if there are many users it is loading very long. then you can filter the users to be displayed like this:
add_action( 'load-users.php', function () {
// Make sure the "action" is "delete".
if ( 'delete' !== filter_input( INPUT_GET, 'action' ) ) {
return;
}
add_filter( 'wp_dropdown_users_args', function ( $query_args, $args ) {
if ( 'reassign_user' === $args[ 'name' ] ) {
$query_args[ 'role' ] = 'administrator';
}
return $query_args;
}, 10, 2 );
} );

Related

Change the default Buddypress user landing page differently depending on the type of user

I made a custom navigation page for users, using the plugins.php file.
But I would like this page/option to be only available for some types of users; and make it the default landing page for them.
I can't figure out how to that.
I tried to make it the default landing page, and in the plugins template file, adding a condition that redirect users depending on their type... but redirection doesn't work by there it seems.
Any clue, plz?
I'm using Wordpress 5.8.2 and Buddypress 9.1.1.
Thanks
I found a solution.
First, here's how I created a new navigation item; I put this code in my bp-custom.php file:
function bp_custom_user_nav_item() {
global $bp;
$args = array(
'name' => __('newnavitem', 'buddypress'),
'slug' => 'newnavitem',
'default_subnav_slug' => 'newnavitem',
'position' => 0,
'show_for_displayed_user' => true,
'screen_function' => 'bp_custom_user_nav_item_screen',
'item_css_id' => 'newnavitem'
);
bp_core_new_nav_item( $args );
}
add_action( 'bp_setup_nav', 'bp_custom_user_nav_item', 99 );
After I created a new directory in community/members/single in my theme directory, and in this directory I will put my newnavitem loop and edit template files.
And I linked the newnavitem and its template with this function
function bp_custom_user_nav_item_screen() {
add_action( 'bp_template_content', 'bp_custom_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/newnavitem' ) );
}
And here's how I disabled the current nav item for certain user types, and set it as default landing page for another certain user types.
function conditionally_disable_newnavitem( $enabled, $component) {
if (user_can(bp_displayed_user_id(),'firstusertype') && $component === 'newnavitem') {
$enabled = false;
}
return $enabled;
}
add_filter( 'bp_is_active', 'conditionally_disable_new_navitem', 10, 2 );
function set_default_component () {
if ( user_can(bp_displayed_user_id(),'secondusertype') || user_can(bp_displayed_user_id(),'thirdusertype')) {
define ( 'BP_DEFAULT_COMPONENT', 'newnavitem' );
add_filter( 'bp_is_active', function($retval, $component){
if($component === 'newnavitem') return true;
return $retval;
}, 10, 2 );
} else {
define ( 'BP_DEFAULT_COMPONENT', 'activity' );
}
}
add_action( 'bp_core_setup_globals', 'set_default_component' );

Execute function only if action hook fires

Can anybody give me a hint? :D
I want the function update_option only to be executed, if the action hook "pre-plupload-upload-ui" fires.
Actually it's loading on every page load.
Goal: Everytime the Upload Panel loads, the option should switch to "redirect" :)
function pz_action_pre_plupload_upload_ui( ) {
$download_method = get_option( 'woocommerce_file_download_method' );
if ( $download_method && $download_method != 'redirect') {
update_option( 'woocommerce_file_download_method', 'redirect' );
}
};
add_action( 'pre-plupload-upload-ui', 'pz_action_pre_plupload_upload_ui', 10, 0 );
You could use the did_action() function to retrieve the number of times an action is fired.
Source # https://developer.wordpress.org/reference/functions/did_action/
<?php
if ( did_action( 'pre-plupload-upload-ui' ) >= 1 ) {
// ...
};
[1]: https://developer.wordpress.org/reference/functions/did_action/

Disable password change option for specific user

How can I disable the password change option for specific user in Wordpress?
I have a user where I set a new password each week for multiple users. But some tried to change the password for this user. I don't want that - but only for this specific user profile. All the other users should be able toi change their password.
I have tried different plugins but none of them work.
Thanks a lot if you can help on this!
Add this in your function.php file
class Password_Reset_Removed
{
function __construct()
{
add_filter( 'show_password_fields', array( $this, 'disable' ) );
add_filter( 'allow_password_reset', array( $this, 'disable' ) );
}
function disable()
{
if ( is_admin() ) {
$userdata = wp_get_current_user();
$user = new WP_User($userdata->ID);
if ( !empty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
return true;
}
return false;
}
}
$pass_reset_removed = new Password_Reset_Removed();
We have just removed the fields to change password from the back-end of the WordPress. Now, some users will also try to reset the password using the Lost your password? form from the log-in page.
In order to prevent them from doing that, we will remove lost password link and disable the lost password form by adding below code
function remove_lost_your_password($text)
{
return str_replace( array('Lost your password?', 'Lost your password'), '', trim($text, '?') );
}
add_filter( 'gettext', 'remove_lost_your_password' );
function disable_reset_lost_password()
{
return false;
}
add_filter( 'allow_password_reset', 'disable_reset_lost_password');
Note - you can update userid - as per your requirements

How to Display Custom meta field value insted of title on custon post list table?

I have created a custom post type "cinfo" and removed title and editor form the edit page. With the help of this code. Also displayed some custom meta fields which are relevant to my plugin.
function remove_box(){
remove_post_type_support('cinfo', 'title');
remove_post_type_support('cinfo', 'editor');
}
add_action("admin_init", "remove_box");
It looks something like this.
Now when i see the list page I still see the title with edit, view and delete button beneath it. which I don't want because the title field doesn't exist in the edit page So it looks a bit irrelevant in the listing page. Instead of that I tried to display the custom meta field "email" but I was only able to change the heading of the column. which looks something like this.
I just did some research and found one action and filter but they still didn't seems to be much of a help to me. Still for the better view of the problem. Also I tried to use a plugin Post List View Count but it also didn't accomplish my purpose. I hope You understand what I basically want to do. Thanks for your time to read my question.
add_filter('manage_cinfo_posts_columns', 'bs_cinfo_table_head');
function bs_cinfo_table_head( $defaults ) {
$defaults['title'] = 'Email';
return $defaults;
}
add_action( 'manage_cinfo_posts_custom_column', 'card_cinfo_table_content', 10, 2 );
function card_cinfo_table_content( $column_name, $post_id ) {
if ($column_name == 'title') {
echo "its working";
}
}
The action manage_cinfo_posts_custom_column will never be true. It's better to remove the defaults on manage_cinfo_posts_columns and do the regular custom stuff in the other filter.
I tried this with a fast class to test all together inside my setup:
class SO23467344
{
private $cpt = 'portfolio';
private $custom_field = 'video';
public function __construct()
{
add_filter( "manage_edit-{$this->cpt}_columns", array( $this, 'column_register' ), 20, 1 );
add_action( "manage_{$this->cpt}_posts_custom_column", array( $this, 'column_display' ), 20, 2 );
add_action( "admin_init", array( $this, "remove_box" ) );
}
function column_register( $columns )
{
$columns['my-col'] = 'My column';
# Remove default columns
unset( $columns['title'], $columns['categories'], $columns['comments'], $columns['date'] );
return $columns;
}
function column_display( $column_name, $post_id )
{
if ( 'my-col' != $column_name )
return;
if ( $field = get_post_meta( $post_id, $this->custom_field, true ) )
echo '<br/><strong style="color:#0f0;font-size:4em"> • </strong>';
}
function remove_box(){
remove_post_type_support( $this->cpt, 'title' );
remove_post_type_support( $this->cpt, 'editor' );
}
}
new SO23467344;

hide a woocommerce setting tab

I would like to hide a specific woocommerce setting tab by user role. Not the entire submenu, but just a tab(checkout to be specific).
I want shop managers to be able to access most of the settings, but be unable to affect the checkout settings.
How can I achieve this?
If you want to remove the tabs instead of hiding them using CSS, then you can add the following to yours theme functions.php:
add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $tabs ) {
// Declare the tabs we want to hide
$tabs_to_hide = array(
'Tax',
'Checkout',
'Emails',
'API',
'Accounts',
);
// Get the current user
$user = wp_get_current_user();
// Check if user is a shop-manager
if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {
// Remove the tabs we want to hide
$tabs = array_diff($tabs, $tabs_to_hide);
}
return $tabs;
}
This uses the WooCommerce 'woocommerce_settings_tabs_array' filter. For more information on all the WooCommerce filters and hooks you can look here: https://docs.woocommerce.com/wc-apidocs/hook-docs.html
This just has the added benefit that it is no longer in the HTML, so if anyone looks at the source, they won't find the elements.
You can still access the URLs. This is just a way of removing the tabs instead of hiding them.
EDIT:
I've figured out how to stop access to the URLs. Copy the following:
add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $array ) {
// Declare the tabs we want to hide
$tabs_to_hide = array(
'tax' => 'Tax',
'checkout' => 'Checkout',
'email' => 'Emails',
'api' => 'API',
'account' => 'Accounts',
);
// Get the current user
$user = wp_get_current_user();
// Check if user is a shop_manager
if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {
// Remove the tabs we want to hide from the array
$array = array_diff_key($array, $tabs_to_hide);
// Loop through the tabs we want to remove and hook into their settings action
foreach($tabs_to_hide as $tabs => $tab_title) {
add_action( 'woocommerce_settings_' . $tabs , 'redirect_from_tab_page');
}
}
return $array;
}
function redirect_from_tab_page() {
// Get the Admin URL and then redirect to it
$admin_url = get_admin_url();
wp_redirect($admin_url);
exit;
}
This is pretty much the same as the first bit of code, apart from the array is structured differently and I've added a foreach. The foreach goes through the list of tabs we want to block, hooks into the 'woocommerce_settings_{$tab}' action which is used to show the settings pages.
Then I created a redirect_from_tab_page function to redirect the users to the default admin URL. This stops direct access to the different settings tabs.
Put this code in your theme/child theme functions.php or somewhere else:
if (!function_exists('hide_setting_checkout_for_shop_manager')){
function hide_setting_checkout_for_shop_manager() {
$user = wp_get_current_user();
//check if user is shop_manager
if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {
echo '<style> .woocommerce_page_wc-settings form .woo-nav-tab-wrapper a[href="'.admin_url('admin.php?page=wc-settings&tab=checkout').'"]{ display: none; } </style>';
}
}
}
add_action('admin_head', 'hide_setting_checkout_for_shop_manager');
The style will be output to html head only at wp-admin and the login user role is shop_manager.
For more about admin_head hook, please check https://codex.wordpress.org/Plugin_API/Action_Reference/admin_head

Resources