I'm creating a plugin for a small business. I need the plugin to do a few things:
- Deactivate + delete pre-installed plugins
- Install Kadence (including kadence theme, child theme and kadence blocks)
- Removing default posts e.g. 'Hello World!'
- Remove old themes e.g. Twenty Twenty Four
- Add plugins such as SVG support
For the most part the plugin works, however when I try to install and activate a plugin I get an error of ob_end_clean(): Failed to delete buffer. No buffer to delete in /var/www/htdocs/wp-admin/includes/plugin.php on line 740 and Cannot modify header information - headers already sent by (output started at /var/www/htdocs/wp-includes/functions.php:5420) in /var/www/htdocs/wp-includes/pluggable.php on line 1435.
All the functions are ran in the plugin's activator file as I need everything to run when the plugin is activated.
I'm using a custom plugin that has been built via https://wppb.me/
Here is the code I'm running when installing Kadence:
public static function add_kadence() {
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
$kadence_blocks_slug = 'kadence-blocks';
$kadence_theme_slug = 'kadence';
$child_theme_slug = $kadence_theme_slug . '-child';
// Theme installation
$kadence_theme_installed = wp_get_theme($kadence_theme_slug);
if (!$kadence_theme_installed->exists()) {
// Theme URL
$kadence_theme_url = 'https://downloads.wordpress.org/theme/' . $kadence_theme_slug . '.zip';
// Create instance of theme installer
$kadence_theme_installer = new Theme_Upgrader();
// Install Theme
$installation = $kadence_theme_installer->install($kadence_theme_url);
if (is_wp_error($installation)) {
error_log('Kadence theme installation failed: ' . $installation->get_error_message());
return;
}
}
// Child Theme installation
$child_theme_installed = wp_get_theme($child_theme_slug);
if (!$child_theme_installed->exists()) {
// Child Theme URL
$kadence_child_theme_url = 'https://dl.dropboxusercontent.com/scl/fi/zca2facxnwbl3le9jg6ke/' . $kadence_theme_slug . '-child.zip?rlkey=fo2sjq4fbmwhctb677u559w2a&dl=0';
// Create instance of theme installer
$kadence_child_theme_installer = new Theme_Upgrader();
// Install Theme
$installation = $kadence_child_theme_installer->install($kadence_child_theme_url);
if (is_wp_error($installation)) {
error_log('Kadence child theme installation failed: ' . $installation->get_error_message());
return;
}
// Switch to Child Theme
switch_theme($child_theme_slug);
}
Plugin installation and activation
$kadence_blocks_installed = is_plugin_active($kadence_blocks_slug . '/' . $kadence_blocks_slug . '.php');
if (!$kadence_blocks_installed) {
// Plugin URL
$kadence_blocks_url = 'https://downloads.wordpress.org/plugin/' . $kadence_blocks_slug . '.zip';
// Create instance of the plugin installer
$kadence_blocks_installer = new Plugin_Upgrader();
// Install Plugin
$installation = $kadence_blocks_installer->install($kadence_blocks_url);
if (is_wp_error($installation)) {
error_log('Kadence Blocks plugin installation failed: ' . $installation->get_error_message());
return;
}
// Activate Plugin
activate_plugin($kadence_blocks_slug . '/' . $kadence_blocks_slug . '.php');
}
}
This is ran within the activate function using self::add_kadence();.
Edit: I have read through similar questions but none are regarding custom plugins within wordpress and doesn't help solve my problem.
?>. Remove the?>if it's the last line of the file. This should fix the issue (note that this issue can be caused by a space or a line break before<?php). Generally, opened<?phpshouldn't be closed, to prevent outputting unwanted line breaks.ob_end_flush()is called and there's no closing?>tag in the file.