Skip to content
This repository
Browse code

Add filters for text strings so users can change it without using tra…

…nslation.

Maybe better filter names?
  • Loading branch information...
commit 13f1f39af33cf2ff5b4b965a28ca11acd0ea2b6a 1 parent 6221daa
Tran Ngoc Tuan Anh authored
18 inc/fields/file-advanced.php
@@ -26,11 +26,11 @@ static function admin_enqueue_scripts()
26 26 static function add_actions()
27 27 {
28 28 parent::add_actions();
29   -
  29 +
30 30 // Attach images via Ajax
31 31 add_action( 'wp_ajax_rwmb_attach_file', array( __CLASS__, 'wp_ajax_attach_file' ) );
32 32 }
33   -
  33 +
34 34 static function wp_ajax_attach_file()
35 35 {
36 36 $post_id = is_numeric( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : 0;
@@ -38,13 +38,13 @@ static function wp_ajax_attach_file()
38 38 $attachment_id = isset( $_POST['attachment_id'] ) ? $_POST['attachment_id'] : 0;
39 39
40 40 check_ajax_referer( "rwmb-attach-file_{$field_id}" );
41   -
  41 +
42 42 add_post_meta( $post_id, $field_id, $attachment_id, false );
43   -
  43 +
44 44 RW_Meta_Box::ajax_response( self::file_html( $attachment_id ), 'success' );
45 45 }
46 46
47   -
  47 +
48 48 /**
49 49 * Get field HTML
50 50 *
@@ -56,8 +56,8 @@ static function wp_ajax_attach_file()
56 56 */
57 57 static function html( $html, $meta, $field )
58 58 {
59   - $i18n_title = _x( 'Select files', 'file upload', 'rwmb' );
60   - $attach_nonce = wp_create_nonce( "rwmb-attach-file_{$field['id']}" );
  59 + $i18n_title = apply_filters( 'rwmb_file_advanced_select_string', _x( 'Select Files', 'file upload', 'rwmb' ), $field );
  60 + $attach_nonce = wp_create_nonce( "rwmb-attach-file_{$field['id']}" );
61 61
62 62 // Uploaded files
63 63 $html = self::get_uploaded_files( $meta, $field );
@@ -72,7 +72,7 @@ static function html( $html, $meta, $field )
72 72
73 73 return $html;
74 74 }
75   -
  75 +
76 76 /**
77 77 * Get field value
78 78 * It's the combination of new (uploaded) images and saved images
@@ -90,4 +90,4 @@ static function value( $new, $old, $post_id, $field )
90 90 return array_unique( array_merge( $old, $new ) );
91 91 }
92 92 }
93   -}
  93 +}
10 inc/fields/file.php
@@ -77,8 +77,8 @@ static function wp_ajax_delete_file()
77 77 */
78 78 static function html( $html, $meta, $field )
79 79 {
80   - $i18n_title = _x( 'Upload files', 'file upload', 'rwmb' );
81   - $i18n_more = _x( '+ Add new file', 'file upload', 'rwmb' );
  80 + $i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'rwmb' ), $field );
  81 + $i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'rwmb' ), $field );
82 82
83 83 // Uploaded files
84 84 $html = self::get_uploaded_files( $meta, $field );
@@ -130,8 +130,8 @@ static function get_uploaded_files( $files, $field )
130 130
131 131 static function file_html( $attachment_id )
132 132 {
133   - $i18n_delete = _x( 'Delete', 'file upload', 'rwmb' );
134   - $i18n_edit = _x( 'Edit', 'file upload', 'rwmb' );
  133 + $i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'rwmb' ) );
  134 + $i18n_edit = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'rwmb' ) );
135 135 $li = '
136 136 <li>
137 137 <div class="rwmb-icon">%s</div>
@@ -272,4 +272,4 @@ static function meta( $meta, $post_id, $saved, $field )
272 272 return (array) $meta;
273 273 }
274 274 }
275   -}
  275 +}
16 inc/fields/image-advanced.php
@@ -16,7 +16,7 @@ static function admin_enqueue_scripts()
16 16 parent::admin_enqueue_scripts();
17 17 wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', array( 'jquery' ), RWMB_VER, true );
18 18 }
19   -
  19 +
20 20 /**
21 21 * Add actions
22 22 *
@@ -30,7 +30,7 @@ static function add_actions()
30 30 // Attach images via Ajax
31 31 add_action( 'wp_ajax_rwmb_attach_media', array( __CLASS__, 'wp_ajax_attach_media' ) );
32 32 }
33   -
  33 +
34 34 /**
35 35 * Ajax callback for attaching media to field
36 36 *
@@ -43,9 +43,9 @@ static function wp_ajax_attach_media()
43 43 $attachment_id = isset( $_POST['attachment_id'] ) ? $_POST['attachment_id'] : 0;
44 44
45 45 check_ajax_referer( "rwmb-attach-media_{$field_id}" );
46   -
  46 +
47 47 add_post_meta( $post_id, $field_id, $attachment_id, false );
48   -
  48 +
49 49 RW_Meta_Box::ajax_response( self::img_html( $attachment_id ), 'success' );
50 50 }
51 51
@@ -60,7 +60,7 @@ static function wp_ajax_attach_media()
60 60 */
61 61 static function html( $html, $meta, $field )
62 62 {
63   - $i18n_title = _x( 'Select or Upload Images', 'image upload', 'rwmb' );
  63 + $i18n_title = apply_filters( 'rwmb_image_advanced_select_string', _x( 'Select or Upload Images', 'image upload', 'rwmb' ), $field );
64 64 $attach_nonce = wp_create_nonce( "rwmb-attach-media_{$field['id']}" );
65 65
66 66 // Uploaded images
@@ -70,13 +70,13 @@ static function html( $html, $meta, $field )
70 70 $classes = array( 'button', 'rwmb-image-advanced-upload', 'hide-if-no-js', 'new-files' );
71 71 if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] )
72 72 $classes[] = 'hidden';
73   -
  73 +
74 74 $classes = implode( ' ', $classes );
75 75 $html .= "<a href='#' class='{$classes}' data-attach_media_nonce={$attach_nonce}>{$i18n_title}</a>";
76 76
77 77 return $html;
78 78 }
79   -
  79 +
80 80 /**
81 81 * Get field value
82 82 * It's the combination of new (uploaded) images and saved images
@@ -95,4 +95,4 @@ static function value( $new, $old, $post_id, $field )
95 95 }
96 96
97 97 }
98   -}
  98 +}
11 inc/fields/image.php
@@ -75,8 +75,8 @@ static function wp_ajax_reorder_images()
75 75 */
76 76 static function html( $html, $meta, $field )
77 77 {
78   - $i18n_title = _x( 'Upload images', 'image upload', 'rwmb' );
79   - $i18n_more = _x( '+ Add new image', 'image upload', 'rwmb' );
  78 + $i18n_title = apply_filters( 'rwmb_image_upload_string', _x( 'Upload Images', 'image upload', 'rwmb' ), $field );
  79 + $i18n_more = apply_filters( 'rwmb_image_add_string', _x( '+ Add new image', 'image upload', 'rwmb' ), $field );
80 80
81 81 // Uploaded images
82 82 $html .= self::get_uploaded_images( $meta, $field );
@@ -136,14 +136,13 @@ static function get_uploaded_images( $images, $field )
136 136 * Get HTML markup for ONE uploaded image
137 137 *
138 138 * @param int $image Image ID
139   - * @param int $field
140 139 *
141 140 * @return string
142 141 */
143 142 static function img_html( $image )
144 143 {
145   - $i18n_delete = _x( 'Delete', 'image upload', 'rwmb' );
146   - $i18n_edit = _x( 'Edit', 'image upload', 'rwmb' );
  144 + $i18n_delete = apply_filters( 'rwmb_image_delete_string', _x( 'Delete', 'image upload', 'rwmb' ) );
  145 + $i18n_edit = apply_filters( 'rwmb_image_edit_string', _x( 'Edit', 'image upload', 'rwmb' ) );
147 146 $li = '
148 147 <li id="item_%s">
149 148 <img src="%s" />
@@ -199,4 +198,4 @@ static function meta( $meta, $post_id, $saved, $field )
199 198 return (array) $meta;
200 199 }
201 200 }
202   -}
  201 +}
17 inc/fields/plupload-image.php
@@ -37,7 +37,7 @@ static function handle_upload()
37 37 //Get next menu_order
38 38 $meta = get_post_meta( $post_id, $field_id, false );
39 39 if( empty( $meta ) ){
40   - $next = 0;
  40 + $next = 0;
41 41 } else {
42 42 $meta = implode( ',' , (array) $meta );
43 43 $max = $wpdb->get_var( "
@@ -47,7 +47,7 @@ static function handle_upload()
47 47 " );
48 48 $next = is_numeric($max) ? (int) $max + 1: 0;
49 49 }
50   -
  50 +
51 51 $attachment = array(
52 52 'guid' => $file_attr['url'],
53 53 'post_mime_type' => $file_attr['type'],
@@ -65,7 +65,7 @@ static function handle_upload()
65 65
66 66 // Save file ID in meta field
67 67 add_post_meta( $post_id, $field_id, $id, false );
68   -
  68 +
69 69 RW_Meta_Box::ajax_response( self::img_html( $id ), 'success' );
70 70 }
71 71
@@ -101,12 +101,11 @@ static function html( $html, $meta, $field )
101 101 $meta = ( array ) $meta;
102 102
103 103 // Filter to change the drag & drop box background string
104   - $i18n_drop = apply_filters( 'rwmb_upload_drop_string', _x( 'Drop images here', 'image upload', 'rwmb' ) );
105   - $i18n_or = _x( 'or', 'image upload', 'rwmb' );
106   - $i18n_select = _x( 'Select Files', 'image upload', 'rwmb' );
  104 + $i18n_drop = apply_filters( 'rwmb_plupload_image_drop_string', _x( 'Drop images here', 'image upload', 'rwmb' ), $field );
  105 + $i18n_or = apply_filters( 'rwmb_plupload_image_or_string', _x( 'or', 'image upload', 'rwmb' ), $field );
  106 + $i18n_select = apply_filters( 'rwmb_plupload_image_select_string', _x( 'Select Files', 'image upload', 'rwmb' ), $field );
107 107
108 108 // Uploaded images
109   -
110 109
111 110 // Check for max_file_uploads
112 111 $classes = array( 'rwmb-drag-drop', 'drag-drop', 'hide-if-no-js', 'new-files');
@@ -154,7 +153,7 @@ static function value( $new, $old, $post_id, $field )
154 153 $new = (array) $new;
155 154 return array_unique( array_merge( $old, $new ) );
156 155 }
157   -
  156 +
158 157 /**
159 158 * Normalize parameters for field
160 159 *
@@ -193,4 +192,4 @@ static function normalize_field( $field )
193 192 return $field;
194 193 }
195 194 }
196   -}
  195 +}
4 inc/fields/thickbox-image.php
@@ -32,7 +32,7 @@ static function admin_enqueue_scripts()
32 32 */
33 33 static function html( $html, $meta, $field )
34 34 {
35   - $i18n_title = _x( 'Upload images', 'image upload', 'rwmb' );
  35 + $i18n_title = apply_filters( 'rwmb_thickbox_image_upload_string', _x( 'Upload Images', 'image upload', 'rwmb' ), $field );
36 36
37 37 $html = wp_nonce_field( "rwmb-delete-file_{$field['id']}", "nonce-delete-file_{$field['id']}", false, false );
38 38 $html .= wp_nonce_field( "rwmb-reorder-images_{$field['id']}", "nonce-reorder-images_{$field['id']}", false, false );
@@ -64,4 +64,4 @@ static function value( $new, $old, $post_id, $field )
64 64 return array_unique( array_merge( $old, $new ) );
65 65 }
66 66 }
67   -}
  67 +}

0 comments on commit 13f1f39

Please sign in to comment.
Something went wrong with that request. Please try again.