drop-in (копируется автоматически)'; return $actions; } ); add_action( 'admin_notices', function () { if ( ! current_user_can( 'manage_options' ) ) { return; } $source = WP_CONTENT_DIR . '/plugins/memcached/object-cache.php'; $target = WP_CONTENT_DIR . '/object-cache.php'; if ( ! file_exists( $source ) ) { return; } if ( file_exists( $target ) ) { return; } if ( class_exists( 'Memcache' ) || class_exists( 'Memcached' ) ) { return; } printf( '
%s
memcache не найдено.
Установите его на сервере (sudo apt install php-memcache), после чего drop-in скопируется автоматически.
Не активируйте плагин — это вызовет фатальную ошибку. Он работает как drop-in.'
);
} );
// ============================================================
// 7. WP-CLI
// ============================================================
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'dekart cache-flush', function () {
my_cache_bump_version();
WP_CLI::success( 'Cache flushed + version bumped.' );
} );
WP_CLI::add_command( 'dekart cache-memcached', function () {
$source = WP_CONTENT_DIR . '/plugins/memcached/object-cache.php';
$target = WP_CONTENT_DIR . '/object-cache.php';
if ( ! file_exists( $source ) ) {
WP_CLI::error( 'Memcached Object Cache plugin not installed. Run: wp plugin install memcached' );
return;
}
if ( file_exists( $target ) ) {
WP_CLI::success( 'Drop-in already exists at wp-content/object-cache.php' );
return;
}
if ( ! class_exists( 'Memcache' ) && ! class_exists( 'Memcached' ) ) {
WP_CLI::warning( 'PHP memcache extension not found. Install it:' );
WP_CLI::line( ' sudo apt install php-memcache' );
WP_CLI::line( ' sudo systemctl restart php8.3-fpm' );
WP_CLI::line( 'Then run this command again.' );
return;
}
if ( copy( $source, $target ) ) {
WP_CLI::success( 'Memcached drop-in installed to wp-content/object-cache.php' );
} else {
WP_CLI::error( 'Failed to copy drop-in. Check permissions.' );
}
} );
}
// ============================================================
// 8. ЛОГИРОВАНИЕ
// ============================================================
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
add_action( 'init', function () {
$b = dekart_detect_cache_backend();
if ( 'none' === $b ) {
error_log( '[Object Cache] WARNING: No cache backend available.' );
}
}, 0 );
}