How to see which sites use my installed plugins (wordpress multisite)

How can I (easily) determine which of my wordpress sites are using a given plugin, on a Wordpress Multisite install? Let's say I have 1,000 wordpress sites on a Wordpress Multisite install. I have 100 plugins. For each plugin, I want to list all of the sites that are using that plugin. In the GUI, I can only see how this can be done in about 1 million clicks. Is there a query I can run against the DB (and …
Category: Web

Best Way to Enter Maintenance Mode Programmatically

I need the site to be in maintenance mode while I complete a cron job within a plugin. I have solved this by creating a ".maintenance" file in my plugin directory and using the following code in my cron job: $plugin_dir = ABSPATH . 'wp-content/plugins/my_plugin/'; $base_dir = ABSPATH; $static_maintenance_file = $plugin_dir . '.maintenance'; $new_maintenance_file = $base_dir . '.maintenance'; copy( $static_maintenance_file, $new_maintenance_file ); // do the business end of the cron job unlink( $new_maintenance_file ); It works as designed. However, it …
Category: Web

I have a snippet to redirect all users to a maintenance page. How do I exclude users with admin role?

I have a snippet that redirects all users to a maintenance page. How can I tweak it to All users except admin users? <?php add_action( 'template_redirect', function() { if ( is_page( 4848 ) ) { return; } wp_redirect( esc_url_raw( home_url( 'maintenance/' ) ) ); //wp_redirect( esc_url_raw( home_url( 'index.php?page_id=4848' ) ) ); exit; } );
Category: Web

Does using WP-cron make the site slower for the user?

Forgive my "beginnerness" in this matter but I have 2 options to trigger a heavy task (massive update on users' properties to solve an issue between 2 plugins that weren't meant to cooperate): (1) Use Unix Cron in my server OR (2) Use WP-Cron I do prefer to do everything IN WordPress and use WP-Cron if they are similiar but (from my undestanding) since wp-cron is a pseudo-cron that waits for some visitor to come and trigger it, I fear …
Category: Web

Maintenance mode excluding site administrators

I want to set the site into maintenance mode without using a plugin so that anyone who accesses the site who is not a site admin will see a "sorry site under maintenance" page. I created a .maintenance file with the code below: <?php function is_user_logged_in() { $loggedin = false; foreach ( (array) $_COOKIE as $cookie => $value ) { if ( stristr($cookie, 'wordpress_logged_in_') ) $loggedin = true; } return $loggedin; } if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], …
Category: Web

Manage Admin permissions by URL GET parameters

I have a site which requires a lot of maintenance - hence I plan to give those tasks away to some acquaintance ppl. They need to have access to some submenus of plugins which do not implement proper permission management - which is something I have seen very often. Usually some general permission-request like "manage-option" or similarly is used, which is a pretty bad design. Now I'm thinking, without modifying the plugins code, how can I give permission to someone …
Category: Web

Is it safe to delete from db orphaned posts i.e. whose post_parent no longer exists?

I inherited a couple of WP + WooCommerce shops with roughly 30,000 products for sale each, and a wp_postmeta which is over a million lines. The former webmasters ran away. In an effort to clean up old stuff, I noticed a post_parent field in wp_posts, and queried the database for orphans: SELECT ID FROM wp_posts WHERE NOT post_parent IN (SELECT ID FROM wp_posts) AND post_parent>0 and found thousands of records. All of these records have a post_parent which no longer …
Category: Web

Making an under maintenance page (without using plugins)

There are a bazillion plugins that does this. And every time I use one, I end up spending hours trying to style the message (and logo and background) to fit the styling of the page. So I was wondering if I could make one easily myself, by using this function: function custom_maintenance_page() { if ( ! is_user_logged_in() ) { if( $_SERVER['REQUEST_URI'] != '/under-maintenance/' ){ wp_redirect( 'https://example.org/under-maintenance' ); } } } add_action( 'template_redirect', 'custom_maintenance_page' ); And then making a new page, …
Category: Web

Change role in maintenance mode

I'm using https://de.wordpress.org/plugins/wp-maintenance-mode/ . I need to test the wp-admin page with different user roles while in maintenance mode. When I switch to a different role than admin the maintenance screen shows up. Is there a way to test the wp-admin page with a different role while in maintenance mode?
Category: Web

Under which circumstances is the .maintenance file not deleted?

When WordPress does plugin/theme/core updates, it creates a .maintenance file which temporarily puts the site in maintenance mode. Sometimes this file does not get deleted and users are locked out of their site (until they search and find that they have to delete that file). As plugin developer it's frustrating because I regularly get blamed for breaking their site. My question: Under which circumstances is the file not deleted? Is there anything I, as a plugin developer, can do to …
Category: Web

wp_redirection_404 table has grown to 7GB

The company I work for has an enterprise Wordpress site that was acquired from a different company. I don't know if there was a past hack or if it's just accumulated spam or what, but the wp_redirection_404 table has grown to roughly 7GB. I tried grepping the table for Viagra, Versace, Nike, etc. and got pages of results for each. It's obviously full of junk. It doesn't appear to be doing anything. In fact, when downloading it locally to work …
Category: Web

The site is experiencing technical difficulties. Please check your site admin email inbox for instructions

I was updating my plugins, after one plug in update went a bit wrong my site was stuck in maintenance mode, the solution I found online was to delete the .maintanence file, which I did. But straight after that I got this message: The site is experiencing technical difficulties. Please check your site admin email inbox for instructions. How do I fix it now?..
Category: Web

How to programmatically put wordpress in maintenance mode

I used this code for several years now: add_action('wp_loaded', 'check_maintenance_mode'); function check_maintenance_mode(){ global $pagenow; if(defined('IN_MAINTENANCE') && IN_MAINTENANCE && $pagenow !== 'wp-login.php' && !is_user_logged_in()){ header('HTTP/1.1 Service Unavailable', true, 503); header('Content-Type: text/html; charset=utf-8'); if(file_exists(WP_CONTENT_DIR . '/maintenance.php')){ require_once( WP_CONTENT_DIR . '/maintenance.php' ); } die(); } } The IN_MAINTENANCE and WP_CONTENT_DIR constants are initialised and setted by me. Anyway, this code suddenly stopped to work. The website is always visible even with IN_MAINTENANCE setted to true. By logging from the function, I can confirm …
Category: Web

Redirect entire website to a single page

I need to redirect a whole WordPress site to a single WordPress page. A sort of maintenance mode, but the redirect has to go to a published WordPress page. Unfortunately, the maintenance page I need to show has to use other WordPress plugins. I am not aware of any Maintenance Mode plugin which lets you do this. At most, they let you write custom HTML/CSS code. I was thinking about a .htaccess mod_rewrite rule. However, I am very weak with …
Category: Web

Possible to stay on Version 4?

The recent security Update to WP 5.0.1 also brough an update with Version 4 to 4.9.9. I got a clients project which where build on swamp land ages ago. Every Update is Hoping nothing will happen. Now i do think of staying with WordPress 4 for my maintained nightmare project, if they still develop important security updates. There is also the classic editor Plugin, which isn't working for every case. Got already another Project where an very old unmaintained Plugin …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.