This commit is contained in:
2026-10-06 18:51:23 -06:00
parent 8424dacd03
commit e2c26b7f21
4223 changed files with 737986 additions and 53 deletions
@@ -0,0 +1,56 @@
<?php
namespace WP_Rocket\Engine\Optimization\RUCSS\Context;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Common\Context\AbstractContext;
use WP_Rocket\Engine\Optimization\RUCSS\Controller\Filesystem;
class RUCSSContext extends AbstractContext {
/**
* Filesystem instance
*
* @var Filesystem
*/
protected $filesystem;
/**
* Instantiate the class.
*
* @param Options_Data $options Options.
* @param Filesystem $filesystem Filesystem instance.
*/
public function __construct( Options_Data $options, Filesystem $filesystem ) {
parent::__construct( $options );
$this->filesystem = $filesystem;
}
/**
* Check if the operation is allowed.
*
* @param array $data Data to provide to the context.
* @return bool
*/
public function is_allowed( array $data = [] ): bool {
$is_allowed = $this->run_common_checks(
[
'do_not_optimize' => false,
'bypass' => false,
'option' => 'remove_unused_css',
'password_protected' => false,
'post_excluded' => 'remove_unused_css',
'logged_in' => false,
]
);
if ( ! $is_allowed ) {
return false;
}
return $this->filesystem->is_writable_folder();
}
}
@@ -0,0 +1,46 @@
<?php
namespace WP_Rocket\Engine\Optimization\RUCSS\Context;
use WP_Rocket\Engine\Common\Context\AbstractContext;
class RUCSSOptimizeContext extends AbstractContext {
/**
* Check if the operation is allowed.
*
* @param array $data Data to provide to the context.
* @return bool
*/
public function is_allowed( array $data = [] ): bool {
$is_allowed = $this->run_common_checks(
[
'bypass' => false,
'option' => 'remove_unused_css',
'post_excluded' => 'remove_unused_css',
]
);
if ( 'local' === wp_get_environment_type() ) {
return false;
}
if ( ! current_user_can( 'rocket_remove_unused_css' ) ) {
return false;
}
if ( is_admin() ) {
return false;
}
if ( ! $is_allowed ) {
return false;
}
if ( ! rocket_can_display_options() ) {
return false;
}
return true;
}
}