Skip to content

Commit 7cff367

Browse files
author
Md. Alimuzzaman Alim
committed
Issue #277
1 parent 05211a4 commit 7cff367

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

lib/classes/class-bootstrap.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,18 @@ public function admin_enqueue_scripts( $hook ) {
831831
wp_enqueue_script( 'wp-stateless-angular' );
832832
wp_enqueue_script( 'wp-stateless' );
833833
wp_enqueue_style( 'jquery-ui-regenthumbs' );
834+
835+
$data = array(
836+
'key' => 'stateless-cache-busting',
837+
'class' => 'notice',
838+
'title' => sprintf( __( "Stateless mode enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),
839+
'message' => sprintf( __("WordPress looks at local files to prevent files with the same filenames.
840+
Since Stateless mode bypasses this check, there is a potential for files to be stored with the same file name. We enforce the Cache-Busting option to prevent this.
841+
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain),"https://github.com/wpCloud/wp-stateless/wiki/Constants#wp_stateless_media_cache_busting", "WP_STATELESS_MEDIA_CACHE_BUSTING" ),
842+
);
843+
echo "<script id='template-stateless-cache-busting' type='text/html'>";
844+
include ud_get_stateless_media()->path( '/static/views/error-notice.php', 'dir' );
845+
echo "</script>";
834846
default: break;
835847
}
836848

@@ -1075,15 +1087,19 @@ public function activate() {
10751087
public function is_new_install($plugin =''){
10761088
if( $plugin == plugin_basename( $this->boot_file ) ) {
10771089
$sm_mode = get_option('sm_mode', null);
1078-
if(empty($sm_mode)){
1090+
$hashify_file_name = get_option('sm_hashify_file_name', null);
1091+
if($sm_mode == 'stateless' && $hashify_file_name == 'false'){
1092+
delete_option('dismissed_notice_stateless_cache_busting');
1093+
}
1094+
else{
10791095
update_option('dismissed_notice_stateless_cache_busting', true);
10801096
}
10811097
}
10821098
}
10831099

10841100
public function show_notice_stateless_cache_busting(){
10851101
$this->errors->add( array(
1086-
'key' => 'stateless_cache_busting',
1102+
'key' => 'stateless-cache-busting',
10871103
'button' => 'View Settings',
10881104
'button_link' => admin_url('upload.php?page=stateless-settings'),
10891105
'title' => sprintf( __( "Stateless mode now requires the Cache-Busting option.", ud_get_stateless_media()->domain ) ),

lib/classes/class-errors.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ public function has_errors() {
155155
public function admin_notices() {
156156
global $wp_version;
157157

158+
wp_enqueue_style("stateless-error-style", ud_get_stateless_media()->path('static/styles/error-notice.css'));
159+
//enqueue dismiss js for ajax requests
160+
$script_path = \UsabilityDynamics\WP\Utility::path( 'static/scripts/ud-dismiss.js', 'url' );
161+
wp_enqueue_script( "sateless-error-notice-js", ud_get_stateless_media()->path( 'static/scripts/error-notice.js', 'url' ), array( 'jquery' ) );
162+
wp_enqueue_script( "ud-dismiss", $script_path, array( 'jquery' ) );
163+
wp_localize_script( "ud-dismiss", "_ud_vars", array(
164+
"ajaxurl" => admin_url( 'admin-ajax.php' ),
165+
) );
166+
167+
158168
//** Don't show the message if the user has no enough permissions. */
159169
if ( ! function_exists( 'wp_get_current_user' ) ) {
160170
require_once( ABSPATH . 'wp-includes/pluggable.php' );
@@ -179,10 +189,6 @@ public function admin_notices() {
179189

180190
$errors = apply_filters( 'ud:errors:admin_notices', $this->errors, $this->args );
181191
$notices = apply_filters( 'stateless:notices:admin_notices', $this->notices, $this->args );
182-
183-
if( !empty( $errors ) || !empty( $notices ) ) {
184-
wp_enqueue_style("stateless-error-style", ud_get_stateless_media()->path('static/styles/error-notice.css'));
185-
}
186192

187193
//** Errors Block */
188194
if( !empty( $errors ) && is_array( $errors ) ) {
@@ -222,16 +228,6 @@ public function admin_notices() {
222228
}
223229
}
224230

225-
if ( $has_notice) {
226-
//enqueue dismiss js for ajax requests
227-
$script_path = \UsabilityDynamics\WP\Utility::path( 'static/scripts/ud-dismiss.js', 'url' );
228-
wp_enqueue_script( "sateless-error-notice-js", ud_get_stateless_media()->path( 'static/scripts/error-notice.js', 'url' ), array( 'jquery' ) );
229-
wp_enqueue_script( "ud-dismiss", $script_path, array( 'jquery' ) );
230-
wp_localize_script( "ud-dismiss", "_ud_vars", array(
231-
"ajaxurl" => admin_url( 'admin-ajax.php' ),
232-
) );
233-
}
234-
235231
}
236232

237233
/**

static/scripts/error-notice.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,20 @@ jQuery( document ).ready( function () {
2626
}, "json" );
2727
return false;
2828
});
29+
30+
jQuery('#stless_settings_tab .sm-mode input[type=radio]').on('change', function(){
31+
var $this = jQuery('#sm_mode_stateless');
32+
if($this.is(':checked')){
33+
var notice = jQuery('#stateless-notice-stateless-cache-busting');
34+
if(!notice.length){
35+
notice = jQuery(jQuery('#template-stateless-cache-busting').html());
36+
notice.appendTo("#stateless-settings-page-title");
37+
}
38+
jQuery('#stateless-notice-stateless-cache-busting').show();
39+
}
40+
else{
41+
jQuery('#stateless-notice-stateless-cache-busting').hide();
42+
}
43+
});
2944

3045
} );

static/views/error-notice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="ud-admin-notice <?php echo $data['class'];?> update-nag fade">
1+
<div id="stateless-notice-<?php echo $data['key'];?>" class="ud-admin-notice <?php echo $data['class'];?> update-nag fade">
22
<div>
33
<div class="title"><?php echo $data['title'];?></div>
44
<div class="description"><?php echo $data['message'];?></div>

0 commit comments

Comments
 (0)