Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #7075: Plugin - Accommodate new oneclick exclusions UI for delayjs #7090

Open
wants to merge 43 commits into
base: feature/3.18
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
edd48af
Updates styling
jeawhanlee Nov 5, 2024
e37bd40
Updated js
jeawhanlee Nov 5, 2024
b70282a
Updated styling
jeawhanlee Nov 5, 2024
7e7149c
Updated section
jeawhanlee Nov 5, 2024
479c901
Updated wording
jeawhanlee Nov 5, 2024
10a47e1
Updated array structure
jeawhanlee Nov 5, 2024
8c3dbbd
Updated condition
jeawhanlee Nov 5, 2024
c059d75
Added compatibility for new data structure
jeawhanlee Nov 5, 2024
d0f95d4
Added tests
jeawhanlee Nov 5, 2024
8469471
Updated tests
jeawhanlee Nov 5, 2024
923865a
Added new array element to sub category check
jeawhanlee Nov 5, 2024
3b63e37
Use new array element to check for sub categories
jeawhanlee Nov 5, 2024
30d0140
Fixed phpstan
jeawhanlee Nov 5, 2024
64d522b
phpcs fix
jeawhanlee Nov 5, 2024
e6c2c72
Updated for compatibility with new structure
jeawhanlee Nov 15, 2024
518ded8
Updated test data
jeawhanlee Nov 15, 2024
6e57a6f
Merge branch 'feature/3.18' into feature/7075-3.18-accommodate-new-on…
Miraeld Dec 2, 2024
d19457c
Update js
Miraeld Dec 2, 2024
7965420
Make section header bold
jeawhanlee Dec 4, 2024
10cf914
Keep select all option checked with all exclusions checked
jeawhanlee Dec 4, 2024
a624fdf
Add built assets
jeawhanlee Dec 4, 2024
8fb8505
Merge branch 'feature/3.18' into feature/7075-3.18-accommodate-new-on…
jeawhanlee Dec 4, 2024
7d52f1c
Updated api url to v2
jeawhanlee Dec 5, 2024
eecd60f
Added argument to rollback action
jeawhanlee Dec 9, 2024
841aa7b
Added logic to update dynamic list during rollback
jeawhanlee Dec 9, 2024
d716506
Added logic to update dynamic list during rollback
jeawhanlee Dec 9, 2024
8cb957b
Use rocket_get_constant
jeawhanlee Dec 9, 2024
8643661
Added new svg icons
jeawhanlee Dec 9, 2024
802faee
Updated styling
jeawhanlee Dec 9, 2024
f0dd5af
Updated data structure to accomodate svg icon
jeawhanlee Dec 9, 2024
d10ec5f
Updated view
jeawhanlee Dec 9, 2024
3689b18
Updated tests
jeawhanlee Dec 9, 2024
5c2db81
Resolved conflicts
jeawhanlee Dec 9, 2024
284971d
Fixed linter error
jeawhanlee Dec 9, 2024
e663621
Revert back to no arg
jeawhanlee Dec 9, 2024
93a9757
Remove argument
jeawhanlee Dec 9, 2024
97f762d
Updated icons
jeawhanlee Dec 10, 2024
0db2348
Updated html structure
jeawhanlee Dec 10, 2024
1f46931
Updated styling
jeawhanlee Dec 10, 2024
b2444ad
Updated html structure
jeawhanlee Dec 10, 2024
9fc705e
Updated test
jeawhanlee Dec 10, 2024
1b8d715
Fixed linter error
jeawhanlee Dec 10, 2024
5b44c41
Updated icon size
jeawhanlee Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion assets/css/wpr-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -3104,9 +3104,37 @@ div.wpr-tutorial-item {
}
.wpr-field--categorizedmultiselect .wpr-list.open .wpr-list-header {
max-height: 32px;
cursor: pointer;
}
.wpr-field--categorizedmultiselect .wpr-list .wpr-list-header {
max-height: 32px;
cursor: pointer;
}
.wpr-field--categorizedmultiselect .wpr-list .wpr-list-header .wpr-badge-counter {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
margin: 2px 0 0px 2px;
padding: 0 7px;
min-width: 18px;
height: 18px;
border-radius: 9px;
background-color: #eb714a;
color: #fff;
font-size: 11px;
font-weight: bold;
line-height: 1.6;
text-align: center;
}
.wpr-field--categorizedmultiselect .wpr-list .wpr-list-header .wpr-list-header-data {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.wpr-field--categorizedmultiselect .wpr-list .wpr-list-header .wpr-list-header-data img {
width: 16px;
height: 16px;
}
.wpr-field--categorizedmultiselect .wpr-list [type=checkbox] + label:before {
top: 4px;
Expand Down Expand Up @@ -3139,8 +3167,21 @@ div.wpr-tutorial-item {
color: #72777c;
}
.wpr-field--categorizedmultiselect .wpr-multiple-select-title {
cursor: pointer;
font-weight: bold;
margin-left: 5px;
}
.wpr-field--categorizedmultiselect .wpr-subsection {
padding-left: 30px;
}
.wpr-field--categorizedmultiselect .wpr-select-all {
border-bottom: 2px solid #e9e9e9;
width: 150px;
padding-bottom: 10px;
}

[data-parent=delay_js].wpr-field--children {
margin-left: 32px;
padding-left: 0;
}

@media only screen and (min-width: 782px) {
Expand Down
2 changes: 1 addition & 1 deletion assets/css/wpr-admin.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions assets/img/ad_network.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/img/analytics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/img/payment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/img/plugins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/img/themes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 23 additions & 2 deletions assets/js/wpr-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ private function assets_section() {
'delay_js_exclusions_selected' => [
'type' => 'categorized_multiselect',
'label' => __( 'One-click exclusions', 'rocket' ),
'description' => __( 'When using the Delay JavaScript Execution, you might experience delay loading elements located in the viewport that need to appear immediately - e.g. slider, header, menu.', 'rocket' ),
'sub_description' => __( 'If you need instant visibility, click below on files that should NOT be delayed. This selection will help users interact with the elements straight away.', 'rocket' ),
'description' => __( 'When using the Delay JavaScript feature, you might notice that some elements in the viewport take time to appear.', 'rocket' ),
'sub_description' => __( 'If you need these elements to load immediately, select the related plugins, themes, or services below to ensure they appear without delay.', 'rocket' ),
'container_class' => [
'wpr-field--children',
],
Expand Down
186 changes: 154 additions & 32 deletions inc/Engine/Optimization/DelayJS/Admin/SiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,58 @@ private function get_theme_in_list( string $item_id ) {
* Check if script is in the list and return it if found.
*
* @param string $item_id Script ID.
* @param string $script_type Script Type.
*
* @return array
*/
private function get_script_in_list( string $item_id ) {
$scripts = $this->get_scripts_from_list();
private function get_script_in_list( string $item_id, string $script_type ) {
$list = $this->dynamic_lists->get_delayjs_list();
$scripts = ! empty( $list->scripts->$script_type ) ? (array) $list->scripts->$script_type : [];

return ! empty( $scripts[ $item_id ] ) ? (array) $scripts[ $item_id ] : [];
}

/**
* Get all scripts from the list.
* Get Analytics scripts from the list.
*
* @return array
*/
private function get_analytics_from_list() {
$list = $this->dynamic_lists->get_delayjs_list();
return ! empty( $list->scripts->analytics ) ? (array) $list->scripts->analytics : [];
}

/**
* Get Ad Networks from the list.
*
* @return array
*/
private function get_ad_networks_from_list() {
$list = $this->dynamic_lists->get_delayjs_list();
return ! empty( $list->scripts->ad_networks ) ? (array) $list->scripts->ad_networks : [];
}

/**
* Get Payment Processors from the list.
*
* @return array
*/
private function get_payment_processors_from_list() {
$list = $this->dynamic_lists->get_delayjs_list();
return ! empty( $list->scripts->payment_processors ) ? (array) $list->scripts->payment_processors : [];
}

/**
* Get Other Services from the list.
*
* @return array
*/
private function get_scripts_from_list() {
private function get_other_services_from_list() {
$list = $this->dynamic_lists->get_delayjs_list();
return ! empty( $list->scripts ) ? (array) $list->scripts : [];
return ! empty( $list->scripts->other_services ) ? (array) $list->scripts->other_services : [];
}


/**
* Get all plugins from the list.
*
Expand Down Expand Up @@ -117,7 +151,22 @@ private function get_themes_from_list() {
* @return array
*/
public function get_delayjs_exclusions_by_id( string $item_id ) {
$item = $this->get_script_in_list( $item_id );
$item = $this->get_script_in_list( $item_id, 'analytics' );
if ( $item ) {
return $item['exclusions'];
}

$item = $this->get_script_in_list( $item_id, 'ad_networks' );
if ( $item ) {
return $item['exclusions'];
}

$item = $this->get_script_in_list( $item_id, 'payment_processors' );
if ( $item ) {
return $item['exclusions'];
}

$item = $this->get_script_in_list( $item_id, 'other_services' );
if ( $item ) {
return $item['exclusions'];
}
Expand Down Expand Up @@ -190,59 +239,127 @@ public function get_active_plugins() {
*/
public function prepare_delayjs_ui_list() {
$full_list = [
'scripts' => [
'title' => __( 'Analytics & Ads', 'rocket' ),
'items' => [],
'dashicon-class' => 'analytics',
'third_parties' => [
'analytics' => [
'title' => __( 'Analytics & Trackers', 'rocket' ),
'items' => [],
'svg-icon' => 'analytics',
],
'ad_networks' => [
'title' => __( 'Ad Networks', 'rocket' ),
'items' => [],
'svg-icon' => 'ad_network',
],
'payment_processors' => [
'title' => __( 'Payment Processors', 'rocket' ),
'items' => [],
'svg-icon' => 'payment',
],
'other_services' => [
'title' => __( 'Other Services', 'rocket' ),
'items' => [],
'svg-icon' => 'plugins',
],
'has_subcats' => false,
],
'plugins' => [
'title' => __( 'Plugins', 'rocket' ),
'items' => [],
'dashicon-class' => 'admin-plugins',
],
'themes' => [
'title' => __( 'Themes', 'rocket' ),
'items' => [],
'dashicon-class' => 'admin-appearance',
'wordpress' => [
'themes' => [
'title' => __( 'Themes', 'rocket' ),
'items' => [],
'svg-icon' => 'themes',
],
'plugins' => [
'title' => __( 'Plugins', 'rocket' ),
'items' => [],
'svg-icon' => 'plugins',
],
'has_subcats' => false,
],
];

$has_subcats = false;

// Scripts.
$scripts = $this->get_scripts_from_list();
$scripts = $this->get_analytics_from_list();
foreach ( $scripts as $script_key => $script ) {
$full_list['scripts']['items'][] = [
$full_list['third_parties']['analytics']['items'][] = [
'id' => $script_key,
'title' => $script->title,
'icon' => $this->get_icon( $script ),
];

$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$active_plugins = $this->get_active_plugins();
foreach ( $this->get_plugins_from_list() as $plugin_key => $plugin ) {
if ( ! in_array( $plugin->condition, $active_plugins, true ) ) {
continue;
}
$scripts = $this->get_ad_networks_from_list();
foreach ( $scripts as $script_key => $script ) {
$full_list['third_parties']['ad_networks']['items'][] = [
'id' => $script_key,
'title' => $script->title,
'icon' => $this->get_icon( $script ),
];

$full_list['plugins']['items'][] = [
'id' => $plugin_key,
'title' => $plugin->title,
'icon' => $this->get_icon( $plugin ),
$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$scripts = $this->get_payment_processors_from_list();
foreach ( $scripts as $script_key => $script ) {
$full_list['third_parties']['payment_processors']['items'][] = [
'id' => $script_key,
'title' => $script->title,
'icon' => $this->get_icon( $script ),
];

$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$scripts = $this->get_other_services_from_list();
foreach ( $scripts as $script_key => $script ) {
$full_list['third_parties']['other_services']['items'][] = [
'id' => $script_key,
'title' => $script->title,
'icon' => $this->get_icon( $script ),
];

$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$full_list['third_parties']['has_subcats'] = $has_subcats;
$has_subcats = false;

$active_theme = $this->get_active_theme();
foreach ( $this->get_themes_from_list() as $theme_key => $theme ) {
if ( $theme->condition !== $active_theme ) {
continue;
}

$full_list['themes']['items'][] = [
$full_list['wordpress']['themes']['items'][] = [
'id' => $theme_key,
'title' => $theme->title,
'icon' => $this->get_icon( $theme ),
];

$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$active_plugins = $this->get_active_plugins();
foreach ( $this->get_plugins_from_list() as $plugin_key => $plugin ) {
if ( ! in_array( $plugin->condition, $active_plugins, true ) ) {
continue;
}

$full_list['wordpress']['plugins']['items'][] = [
'id' => $plugin_key,
'title' => $plugin->title,
'icon' => $this->get_icon( $plugin ),
];

$has_subcats = ! $has_subcats ? true : $has_subcats;
}

$full_list['wordpress']['has_subcats'] = $has_subcats;
$has_subcats = false;

return $full_list;
}

Expand Down Expand Up @@ -495,7 +612,12 @@ public function replace_theme_selection( $new_theme, $old_theme ) {
public function get_default_exclusions() {
$items = [];

$scripts = $this->get_scripts_from_list();
$scripts = array_merge(
$this->get_analytics_from_list(),
$this->get_ad_networks_from_list(),
$this->get_payment_processors_from_list(),
$this->get_other_services_from_list()
);
foreach ( $scripts as $script_key => $script ) {
if ( ! $script->is_default ) {
continue;
Expand Down
11 changes: 10 additions & 1 deletion inc/Engine/Optimization/DynamicLists/AbstractAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class AbstractAPIClient {
/**
* API URL.
*/
const API_URL = 'https://b.rucss.wp-rocket.me/api/';
const API_URL = 'https://b.rucss.wp-rocket.me/api/v2/';

/**
* Response Code.
Expand Down Expand Up @@ -92,10 +92,19 @@ public function get_exclusions_list( $hash ) {
* @return bool
*/
private function handle_request( array $args ) {
$use_old_api_url = false;

// Handle logic to set API Url to old version when rolling back to versions < 3.18.
if ( version_compare( rocket_get_constant( 'WP_ROCKET_LASTVERSION' ), '3.18', '<' ) && 'rocket_before_rollback' === current_action() ) {
$use_old_api_url = true;
}

$api_url = rocket_get_constant( 'WP_ROCKET_EXCLUSIONS_API_URL', false )
? rocket_get_constant( 'WP_ROCKET_EXCLUSIONS_API_URL', false )
: self::API_URL;

$api_url = $use_old_api_url ? str_replace( 'v2/', '', $api_url ) : $api_url;

if ( empty( $args['body'] ) ) {
$args['body'] = [];
}
Expand Down
Loading
Loading