| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/plugins/woocommerce/packages/blueprint/src/ |
Upload File : |
<?php
namespace Automattic\WooCommerce\Blueprint;
trait UsePluginHelpers {
use UseWPFunctions;
/**
* Activate a plugin by its slug.
*
* Searches for the plugin with the specified slug in the installed plugins
* and activates it.
*
* @param string $slug The slug of the plugin to activate.
*
* @return false|null|WP_Error Null on success, WP_Error on invalid file, false if not found.
*/
public function activate_plugin_by_slug( $slug ) {
// Get all installed plugins.
$all_plugins = $this->wp_get_plugins();
// Loop through all plugins to find the one with the specified slug.
foreach ( $all_plugins as $plugin_path => $plugin_info ) {
// Check if the plugin path contains the slug.
if ( strpos( $plugin_path, $slug . '/' ) === 0 ) {
// Deactivate the plugin.
return $this->wp_activate_plugin( $plugin_path );
}
}
return false;
}
/**
* Check if a plugin with the specified slug is installed.
*
* @param string $slug The slug of the plugin to check.
*
* @return bool
*/
public function is_plugin_dir( $slug ) {
$all_plugins = $this->wp_get_plugins();
foreach ( $all_plugins as $plugin_file => $plugin_data ) {
// Extract the directory name from the plugin file path.
$plugin_dir = explode( '/', $plugin_file )[0];
// Check for an exact match with the slug.
if ( $plugin_dir === $slug ) {
return true;
}
}
return false;
}
/**
* Deactivate and delete a plugin by its slug.
*
* Searches for the plugin with the specified slug in the installed plugins,
* deactivates it if active, and then deletes it.
*
* @param string $slug The slug of the plugin to delete.
*
* @return bool|WP_Error True if the plugin was deleted, false otherwise.
*/
public function delete_plugin_by_slug( $slug ) {
// Get all installed plugins.
$all_plugins = $this->wp_get_plugins();
// Loop through all plugins to find the one with the specified slug.
foreach ( $all_plugins as $plugin_path => $plugin_info ) {
// Check if the plugin path contains the slug.
if ( strpos( $plugin_path, $slug . '/' ) === 0 ) {
// Deactivate the plugin.
if ( $this->deactivate_plugin_by_slug( $slug ) ) {
// Delete the plugin.
return $this->wp_delete_plugins( array( $plugin_path ) );
}
}
}
return false;
}
/**
* Deactivate a plugin by its slug.
*
* Searches for the plugin with the specified slug in the installed plugins
* and deactivates it.
*
* @param string $slug The slug of the plugin to deactivate.
*
* @return bool True if the plugin was deactivated, false otherwise.
*/
public function deactivate_plugin_by_slug( $slug ) {
// Get all installed plugins.
$all_plugins = $this->wp_get_plugins();
// Loop through all plugins to find the one with the specified slug.
foreach ( $all_plugins as $plugin_path => $plugin_info ) {
// Check if the plugin path contains the slug.
if ( strpos( $plugin_path, $slug . '/' ) === 0 ) {
// Deactivate the plugin.
deactivate_plugins( $plugin_path );
// Check if the plugin has been deactivated.
if ( ! is_plugin_active( $plugin_path ) ) {
return true;
}
}
}
return false;
}
}