wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
698 stars 218 forks source link

Implement DJE Safe Mode Feature #7058

Open Miraeld opened 2 days ago

Miraeld commented 2 days ago

Remove the placeholder from the textarea. Add a checkbox labeled "Delay JavaScript Execution safe mode" before the textarea. Display a warning message when the checkbox is checked, detailing potential performance impacts and suggesting users contact support.

Implement logic to handle the checkbox state. Update the exclusions list based on the checkbox state. Ensure the system correctly applies these changes when the settings are saved.

Miraeld commented 2 days ago

Scope a solution

Frontend changes

Click to expand code ``` php 'delay_js_execution_safe_mode' => [ 'type' => 'checkbox', 'label' => __( 'Delay JavaScript Execution safe mode', 'rocket' ), 'container_class' => [ 'wpr-field--children', 'wpr-isParent', ], 'description' => $invalid_license ? __( 'Delay JavaScript Execution safe mode temporarily resolves issues with Delay JavaScript execution but may reduce your PageSpeed Scores and performance. Contact support for help excluding problematic scripts to use this feature fully.', 'rocket' ) : '', 'section' => 'js', 'parent' => 'delay_js', 'page' => 'file_optimization', 'default' => 0, 'sanitize_callback' => 'sanitize_checkbox', 'input_attr' => [ 'disabled' => get_rocket_option( 'delay_js_execution_safe_mode' ) ? 1 : 0, ], 'helper' => '', ], 'delay_js_execution_safe_mode_method' => [ 'type' => 'radio_buttons', 'label' => __( 'Delay JavaScript Execution safe mode', 'rocket' ), 'container_class' => [ 'wpr-field--children', 'wpr-field--js-execution-safe-mode-delivery', 'wpr-field--optimize-css-delivery', ], 'buttons_container_class' => '', 'parent' => 'delay_js_execution_safe_mode', 'section' => 'js', 'page' => 'file_optimization', 'default' => 'dje_safe_mode', 'sanitize_callback' => 'sanitize_checkbox', 'options' => [ 'dje_safe_mode' => [ 'label' => __( 'Delay JavaScript Execution safe mode', 'rocket' ), 'disabled' => $invalid_license ? 'disabled' : false, 'description' => '', // translators: %1$s = opening tag, %2$s = closing tag. 'warning' => $invalid_license ? [] : [ 'title' => __( 'This will decrease the effect of Delay JavaScript Execution', 'rocket' ), 'description' => __( 'This mode temporarily resolves issues with Delay JavaScript execution but may reduce your PageSpeed Scores and performance. Contact support for help excluding problematic scripts to use this feature fully.', 'rocket' ), 'button_label' => __( 'Activate Safe Mode', 'rocket' ), ], 'sub_fields' => $invalid_license ? [] : [ 'delay_js_exclusions' => [ 'type' => 'textarea', 'label' => __( 'Excluded JavaScript Files', 'rocket' ), 'description' => __( 'Specify URLs or keywords that can identify inline or JavaScript files to be excluded from delaying execution (one per line).', 'rocket' ), 'parent' => '', 'section' => 'js', 'page' => 'file_optimization', 'default' => [], 'sanitize_callback' => 'sanitize_textarea', 'input_attr' => [ 'disabled' => get_rocket_option( 'delay_js_execution_safe_mode' ) ? 0 : 1, ], 'helper' => DelayJSSettings::exclusion_list_has_default() ? $delay_js_found_list_helper : $delay_js_list_helper, 'placeholder' => '', ], ], ], ], ```

Probably need to modify wpr-admin.js to display the notice on click of the checkbox.

Backend changes

mostafa-hisham commented 1 day ago

@Miraeld I think the JS function that shows the warning is here. not sure if you need to edit the function but you can check https://github.com/wp-media/wp-rocket/blob/e3f0cb1b343f9e589ef6ce4bea005204d0d9b311/assets/js/wpr-admin.js#L564

jeawhanlee commented 1 day ago

LGTM