@@ -53,7 +53,7 @@ public function enqueue_scripts( $hook ) {
53
53
54
54
$ max_file_size = wp_max_upload_size ();
55
55
// translators: %s is the max file size in MB.
56
- $ max_file_size_error = sprintf ( __ ( 'File size is too large. Max file size is %sMB ' , 'optimole ' ), $ max_file_size / 1024 / 1024 );
56
+ $ max_file_size_error = sprintf ( __ ( 'File size is too large. Max file size is %sMB ' , 'optimole-wp ' ), $ max_file_size / 1024 / 1024 );
57
57
58
58
wp_enqueue_style ( 'optml-attachment-edit ' , OPTML_URL . 'assets/css/single-attachment.css ' , [], OPTML_VERSION );
59
59
@@ -68,7 +68,7 @@ public function enqueue_scripts( $hook ) {
68
68
'mimeType ' => $ mime_type ,
69
69
'i18n ' => [
70
70
'maxFileSizeError ' => $ max_file_size_error ,
71
- 'replaceFileError ' => __ ( 'Error replacing file ' , 'optimole ' ),
71
+ 'replaceFileError ' => __ ( 'Error replacing file ' , 'optimole-wp ' ),
72
72
],
73
73
]
74
74
);
@@ -100,13 +100,13 @@ public function add_attachment_fields( $form_fields, $post ) {
100
100
}
101
101
102
102
$ form_fields ['optml_rename_file ' ] = [
103
- 'label ' => __ ( 'Rename attached file ' , 'optimole ' ),
103
+ 'label ' => __ ( 'Rename attached file ' , 'optimole-wp ' ),
104
104
'input ' => 'html ' ,
105
105
'html ' => $ this ->get_rename_field ( $ attachment ),
106
106
];
107
107
108
108
$ form_fields ['optml_replace_file ' ] = [
109
- 'label ' => __ ( 'Replace file ' , 'optimole ' ),
109
+ 'label ' => __ ( 'Replace file ' , 'optimole-wp ' ),
110
110
'input ' => 'html ' ,
111
111
'html ' => $ this ->get_replace_field ( $ attachment ),
112
112
];
@@ -146,7 +146,7 @@ private function get_rename_field( \Optml_Attachment_Model $attachment ) {
146
146
$ html .= '<span class="optml-file-ext">. ' . esc_html ( $ file_ext ) . '</span> ' ;
147
147
$ html .= '</div> ' ;
148
148
149
- $ html .= '<button type="button" disabled class="button optml-btn primary" id="optml-rename-file-btn"> ' . __ ( 'Rename ' , 'optimole ' ) . '</button> ' ;
149
+ $ html .= '<button type="button" disabled class="button optml-btn primary" id="optml-rename-file-btn"> ' . __ ( 'Rename ' , 'optimole-wp ' ) . '</button> ' ;
150
150
$ html .= '</div> ' ;
151
151
152
152
$ html .= '<input type="hidden" name="optml_current_ext" value=" ' . esc_attr ( $ file_ext ) . '"> ' ;
@@ -169,17 +169,17 @@ private function get_replace_field( \Optml_Attachment_Model $attachment ) {
169
169
$ html = '<div class="optml-replace-section"> ' ;
170
170
$ html .= '<div class="optml-replace-input"> ' ;
171
171
$ html .= '<label for="optml-replace-file-field" id="optml-file-drop-area"> ' ;
172
- $ html .= '<span class="label-text"> ' . __ ( 'Click to select a file or drag & drop here ' , 'optimole ' ) . ' ( ' . implode ( ', ' , $ file_ext ) . ')</span> ' ;
172
+ $ html .= '<span class="label-text"> ' . __ ( 'Click to select a file or drag & drop here ' , 'optimole-wp ' ) . ' ( ' . implode ( ', ' , $ file_ext ) . ')</span> ' ;
173
173
$ html .= '<div class="optml-replace-file-preview"></div> ' ;
174
174
$ html .= '</label> ' ;
175
175
176
176
$ html .= '<input type="file" class="hidden" id="optml-replace-file-field" name="optml-replace-file-field" accept=" ' . implode ( ', ' , $ file_ext ) . '"> ' ;
177
177
178
178
$ html .= '<div class="optml-replace-file-actions"> ' ;
179
- $ html .= '<button type="button" class="button optml-btn primary" id="optml-replace-file-btn"> ' . __ ( 'Replace file ' , 'optimole ' ) . '</button> ' ;
180
- $ html .= '<button type="button" class="button optml-btn destructive" id="optml-replace-clear-btn"> ' . __ ( 'Clear ' , 'optimole ' ) . '</button> ' ;
179
+ $ html .= '<button disabled type="button" class="button optml-btn primary" id="optml-replace-file-btn"> ' . __ ( 'Replace file ' , 'optimole-wp ' ) . '</button> ' ;
180
+ $ html .= '<button disabled type="button" class="button optml-btn destructive" id="optml-replace-clear-btn"> ' . __ ( 'Clear ' , 'optimole-wp ' ) . '</button> ' ;
181
181
$ html .= $ this ->get_svg_loader ();
182
- $ html .= '<p class="optml-description"> ' . __ ( 'This will replace the current file with the new one. This action cannot be undone. ' , 'optimole ' ) . '</p> ' ;
182
+ $ html .= '<p class="optml-description"> ' . __ ( 'This will replace the current file with the new one. This action cannot be undone. ' , 'optimole-wp ' ) . '</p> ' ;
183
183
$ html .= '</div> ' ;
184
184
185
185
$ html .= '<div class="optml-replace-file-error hidden"></div> ' ;
@@ -197,9 +197,9 @@ private function get_replace_field( \Optml_Attachment_Model $attachment ) {
197
197
private function get_footer_html () {
198
198
$ html = '' ;
199
199
$ html .= '<div class="optml-logo-contianer"> ' ;
200
- $ html .= '<img src=" ' . OPTML_URL . 'assets/img/logo.svg" alt=" ' . __ ( 'Optimole logo ' , 'optimole ' ) . '"/> ' ;
200
+ $ html .= '<img src=" ' . OPTML_URL . 'assets/img/logo.svg" alt=" ' . __ ( 'Optimole logo ' , 'optimole-wp ' ) . '"/> ' ;
201
201
// translators: %s is the 'Optimole'.
202
- $ html .= '<span> ' . sprintf ( __ ( 'Powered by %s ' , 'optimole ' ), '<strong>Optimole</strong> ' ) . '</span> ' ;
202
+ $ html .= '<span> ' . sprintf ( __ ( 'Powered by %s ' , 'optimole-wp ' ), '<strong>Optimole</strong> ' ) . '</span> ' ;
203
203
$ html .= '</div> ' ;
204
204
205
205
return $ html ;
@@ -218,6 +218,10 @@ public function prepare_attachment_filename( array $post_data, array $attachment
218
218
return $ post_data ;
219
219
}
220
220
221
+ if ( $ post_data ['post_type ' ] !== 'attachment ' ) {
222
+ return $ post_data ;
223
+ }
224
+
221
225
if ( ! isset ( $ post_data ['optml_rename_nonce ' ] ) || ! wp_verify_nonce ( sanitize_text_field ( $ post_data ['optml_rename_nonce ' ] ), 'optml_rename_media_nonce ' ) ) {
222
226
return $ post_data ;
223
227
}
@@ -230,7 +234,7 @@ public function prepare_attachment_filename( array $post_data, array $attachment
230
234
return $ post_data ;
231
235
}
232
236
233
- if ( strlen ( $ new_name ) < 3 || strlen ( $ new_name ) > 100 ) {
237
+ if ( strlen ( $ new_name ) > 100 ) {
234
238
return $ post_data ;
235
239
}
236
240
@@ -262,7 +266,11 @@ public function save_attachment_filename( $post_id ) {
262
266
delete_post_meta ( $ post_id , '_optml_pending_rename ' );
263
267
264
268
$ renamer = new Optml_Attachment_Rename ( $ post_id , $ new_filename );
265
- $ renamer ->rename ();
269
+ $ status = $ renamer ->rename ();
270
+
271
+ if ( is_wp_error ( $ status ) ) {
272
+ wp_die ( $ status ->get_error_message () );
273
+ }
266
274
}
267
275
268
276
/**
@@ -272,11 +280,11 @@ public function replace_file() {
272
280
$ id = sanitize_text_field ( $ _POST ['attachment_id ' ] );
273
281
274
282
if ( ! current_user_can ( 'edit_post ' , $ id ) ) {
275
- wp_send_json_error ( __ ( 'You are not allowed to replace this file ' , 'optimole ' ) );
283
+ wp_send_json_error ( __ ( 'You are not allowed to replace this file ' , 'optimole-wp ' ) );
276
284
}
277
285
278
286
if ( ! isset ( $ _FILES ['file ' ] ) ) {
279
- wp_send_json_error ( __ ( 'No file uploaded ' , 'optimole ' ) );
287
+ wp_send_json_error ( __ ( 'No file uploaded ' , 'optimole-wp ' ) );
280
288
}
281
289
282
290
$ replacer = new Optml_Attachment_Replace ( $ id , $ _FILES ['file ' ] );
@@ -287,7 +295,7 @@ public function replace_file() {
287
295
288
296
$ response = [
289
297
'success ' => ! $ is_error ,
290
- 'message ' => $ is_error ? $ replaced ->get_error_message () : __ ( 'File replaced successfully ' , 'optimole ' ),
298
+ 'message ' => $ is_error ? $ replaced ->get_error_message () : __ ( 'File replaced successfully ' , 'optimole-wp ' ),
291
299
];
292
300
293
301
wp_send_json ( $ response );
0 commit comments