The Problem:
When wp-cron.php
is called, it includes only:
require_once( dirname( __FILE__ ) . '/wp-load.php' );
so the problem you are facing is that
wpmu_delete_blog()
is undefined when you call it from your remove_blogs_daily()
function.
Possible Solution:
You therefore need to add this line:
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
into your code to fix that.
Try this for example:
function remove_blogs_daily()
{
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
if( ! function_exists( 'wpmu_delete_blog' ) ) return;
$all_blogs = wp_get_sites();
$blogs_to_keep = array( 1, 2 );
foreach ( $all_blogs as $key => $val )
{
if ( ! in_array( $val['blog_id'], $blogs_to_keep ) )
{
wpmu_delete_blog( $val['blog_id'], TRUE );
}
}
}
Related Posts:
- WP-CLI cron on multisite using WP-Toolkit “succeded”, but callback not executed
- How to disable wordpress cron jobs for a subsite?
- When hooking wp-cron to system
- WordPress Multisite Cron Issue
- Cron job disappering without notice?
- What are options are there to implement a multi language site
- Where is the robots.txt stored for a WordPress Multisite install?
- Settings API in Multisite – Missing update message
- WordPress Multisite Multiple child theme
- WordPress Multisite: How to make all media library items available for every site?
- How to setup LDAP authentication with WP multisite
- WordPress Multisite. Can domain be used instead of subdomain?
- Built to scale, or worry later?
- Multisite Subdomains result in 403 Forbidden
- Set subdomains live in a next step
- latest 5 posts using switch_to_blog loop
- W3 Total Cache Plugin with WP 3 MultiUser [closed]
- restore_current_blog() vs. multiple switch_to_blog() followed by removing $GLOBALS[‘_wp_switched_stack’]
- Should multi-language site using multi-site architecture have default language in base site?
- Multisite Installation: how do I setup global search?
- Register email as username
- Two WordPress sites sharing the same database
- Help with updating a wp_get_sites to get_sites and sorting by alphebetical order
- Multisite Subdomain Using More Resources Than Others?
- Can I use multisite functions in a single-site installation?
- Multisite – create new site with precreated pages, menu etc
- WordPress Multisite prevent direct access to subdomain
- WordPress mutisite migration
- WordPress multisite change language
- How to work on a live WPMS blog when domain is unresolved? [closed]
- Multisite, multiple domains per site
- delete_user_meta : how to delete all the metadata of a given user (witout SQL)
- wp_redirect not working on admin menu page
- Bootstrapping WordPress MultiSite Outsite of WordPress – No $wpdb
- How to disable the default WordPress redirect to non-www URLs?
- Bulk theme settings in wordpress multisite
- Permalinks not working using wordPress Networking with custom post types
- Should I use a multisite installation to achieve a multi-language site?
- Multisite domain naming
- Site kit Google Analytics setup giving Error: {“error”:”invalid ‘redirect_uri'”}
- All pages have 302 redirect, which I can’t remove
- Can is_page and is_front_page both be true?
- Switch a single site to a multi-site
- migrate a MU sub blog to a single install
- Preferred method of setting user role only works on Main Site in Network
- WordPress Multisite with Addon Domains (not parked domain) [closed]
- How to share primary navigation of main site with subsites usining switch_to_blog
- WordPress 4.5+ Multisite Domain Mapping
- Register submenu on network menu from the subsite
- Multisite sub-directories IIS 7.5 change media/uploads location
- One Domain, Two Installs of WordPress
- add_rewrite_rule not working in WordPress Multisite
- WordPress multisite install on two subdomains, each belonging to a separate domain
- How do I find where the current value of the option ‘registration’ in the SQL database?
- Can’t access Dashboard of a Multisite WordPress. Chrome results in “ERR_TOO_MANY_REDIRECTS”
- is_main_site() Always Returns True
- Strange multisite issue where all sites return same id with get_current_site()
- Mass Update Broken Links
- Permalink with a Category and then a Post
- Performance disadvantge of second installation instead multisite feature?
- Creating a subdomain network in a subdomain
- Sub-sub folders of WordPress Multisite subdirectory
- Allow editors to switch sites (Multisite)
- moving tables between multisite installs
- How much resources are good enough for 3.9.2
- Best Practise: Linking to WPMU sites from other sites
- Common user login for two different wordpress installation and bbpress
- Can I run multiple blogs from my local machine
- Trouble with SQL SELECT inside switch_to_blog()
- WordPress Multisite and how to apply sef urls only to specific sites
- Custom css – WordPress Multisite
- Migration: previous URL redirection after migrating
- how to convert a wp multisite into a single site with content from subsites
- Getting stylesheet error after setting subdomain to false in multisite
- “Multisite support is not enabled.” After Multisite Config Changes
- String translation within WordPress multisite with i18n not working on all sites
- Add new sites on the same level as the parent URL in a multisite
- URLs for (MultiSite) link images are always relative
- Search returns “Nothing Found” on a sub directory
- Add radio button on theme at the select of the theme the same theme should be activated after generation of new site in multi site
- Moving wordpress multisite to new domain
- Users getting linked unwanted to main mu in WordPress multisite (WPMU)
- Which action hook to update custom field at network/site-info.php in multisite on update site info
- Changed singlesite to multisite, but new site shows Maintenance
- multisite shared settings
- Multi Site Translate Strings
- Responsive Wordress Site – Serve different post types to each device
- Should I use MultiSite for a subdomain based wp site?
- Can’t import posts in multisite
- User registration problem on multisites web
- Admin user getting redirected to /wp-admin/user
- Getting 404 after Update in Multisite
- Is there a way to have wordpress 301 versus 302 urls by default?
- Some Subdomains on a Multisite Install Not Found
- personal_options hook on WordPress multisite
- There is no featured image in my post in wordpress multisite theme [closed]
- Multi site root site installed on subdomain, with child sites as subdirectories
- Integrating WordPress for blog and other content pages in a web app
- get_category_link() or get_tag_link() return wrong category/tag base in wordpress multisite
- Multisite subdomain microsite on secondary domain