Implementazione di un Must Use Plugin

Installazione di un Must use plugins

/**
 * Copy mu-plugins file on activation
 */
register_activation_hook( __FILE__, 'wpsp_pluggable_functions' );
function wpsp_pluggable_functions() {

    $enable_mu_plugin = true;

    if ( ! defined( 'WPMU_PLUGIN_DIR' ) ) {
        add_option( 'wpsp_ext_admin_notices', 'WPMU_PLUGIN_DIR not defined' );
        $enable_mu_plugin = false;
    }

    $src_file  = WPSPE_PATH . 'mu-plugins/wpsp-ext-pluggable.php';
    $dest_file = WPMU_PLUGIN_DIR . '/wpsp-ext-pluggable.php';

    if ( ! file_exists( $dest_file ) ) {
        if ( ! copy( $src_file, $dest_file ) ) {
            add_option( 'wpsp_ext_admin_notices', 'Unable to copy files to mu-plugins directory' );
            $enable_mu_plugin = false;
        }
    } else {
        return true;
    }


    if ( $enable_mu_plugin ) {
        add_option( 'wpsp_ext_mu_plugins_status', true );
    } else {
        add_option( 'wpsp_ext_mu_plugins_status', false );
    }

    return true;
}

/**
 * Check mu-plugins file is copied to dir mu-plugins
 */
add_action( 'init', 'wpsp_ext_init' );
function wpsp_ext_init() {

    if ( wpsp_pluggable_functions() ) {
        return true;
    }

    /**
     * In admin backend show notice
     */
    if ( is_admin() ) {
        add_action( 'admin_notices', function () {

            $enable_mu_plugin = get_option( 'wpsp_ext_mu_plugins_status', false );
            $admin_notices    = get_option( 'wpsp_ext_admin_notices', '' );

            if ( ! $enable_mu_plugin ) {

                if ( '' !== $admin_notices ) {
                    printf( '<div class="notices notice-error is-dismissible">%s</div>',
                        esc_attr( $admin_notices )
                    );
                } else {
                    if ( ! wpsp_pluggable_functions() ) {
                        wpsp_ext_init();
                    }
                }
            }
        }, 10 );
    } //is_admin
}

Reference : https://wordpress.org/support/article/must-use-plugins/