is_yay_wp_installed() ) {
return;
// No need to show notices if dependencies are met
}
$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
echo wp_kses_post(
'
| '
. ( ! $this->is_yay_wp_installed() ? $this->get_yay_wp_required_notice() : '' )
. ' |
'
);
}
/**
* Returns the notice for missing YayMail - WP Email Customizer plugin.
*/
protected function get_yay_wp_required_notice() {
$yay_wp_versions = [
'yay-wp-email-customizer/yay-wp-email-customizer.php',
'yay-wp-email-customizer-pro/yay-wp-email-customizer.php',
];
$all_plugins = get_plugins();
$plugin_to_activate = null;
foreach ( $yay_wp_versions as $plugin_file ) {
if ( array_key_exists( $plugin_file, $all_plugins ) && ! is_plugin_active( $plugin_file ) ) {
$plugin_to_activate = $plugin_file;
break;
}
}
if ( $plugin_to_activate ) {
$activate_url = wp_nonce_url(
admin_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_to_activate ) ),
'activate-plugin_' . $plugin_to_activate
);
return sprintf(
'',
esc_html__( 'To customize WordPress core emails, you need to activate Yay WP Email Customizer plugin.', 'yaymail' ),
esc_url( $activate_url ),
esc_html__( 'Activate Now', 'yaymail' )
);
}
$install_url = wp_nonce_url(
admin_url( 'admin.php?action=yay_wp_install' ),
'yay-wp-install'
);
return sprintf(
'',
esc_html__( 'To customize WordPress core emails, you need to install and activate Yay WP Email Customizer plugin. Get', 'yaymail' ),
esc_url( $install_url ),
esc_html__( 'Yay WP Email Customizer', 'yaymail' ),
);
}
/**
* Handles the installation of YayMail - WP Email Customizer plugin.
*/
public function install_yaymail_wp() {
// Check user permissions
if ( ! current_user_can( 'install_plugins' ) ) {
wp_die( esc_html__( 'You do not have permission to install plugins.', 'yaymail' ) );
}
// Verify nonce
check_admin_referer( 'yay-wp-install' );
// Include required WordPress files
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/misc.php';
// Create upgrader instance
$upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin() );
// Install the plugin
$download_url = 'https://downloads.wordpress.org/plugin/yay-wp-email-customizer.zip';
$result = $upgrader->install( $download_url );
// Check if installation was successful
if ( is_wp_error( $result ) ) {
wp_redirect( admin_url( 'plugins.php?yay-wp-install-error=1' ) );
exit;
}
// Try to activate the plugin
$plugin_file = 'yay-wp-email-customizer/yay-wp-email-customizer.php';
$activate_result = activate_plugin( $plugin_file );
if ( is_wp_error( $activate_result ) ) {
wp_redirect( admin_url( 'plugins.php?yay-wp-installed=1&yay-wp-activate-error=1' ) );
exit;
}
// Success - redirect back to plugins page
wp_redirect( admin_url( 'plugins.php?yay-wp-installed=1&yay-wp-activated=1' ) );
exit;
}
/**
* Displays admin notices after plugin installation.
*/
public function show_install_notices() {
if ( isset( $_GET['yay-wp-install-error'] ) ) {
?>
is_yay_wp_installed() ) {
return;
}
?>