Skip to content
Browse files

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

…nslation.

Maybe better filter names?
  • Loading branch information...
1 parent 6221daa commit 13f1f39af33cf2ff5b4b965a28ca11acd0ea2b6a @rilwis committed Mar 24, 2013
View
18 inc/fields/file-advanced.php
@@ -26,25 +26,25 @@ static function admin_enqueue_scripts()
static function add_actions()
{
parent::add_actions();
-
+
// Attach images via Ajax
add_action( 'wp_ajax_rwmb_attach_file', array( __CLASS__, 'wp_ajax_attach_file' ) );
}
-
+
static function wp_ajax_attach_file()
{
$post_id = is_numeric( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : 0;
$field_id = isset( $_POST['field_id'] ) ? $_POST['field_id'] : 0;
$attachment_id = isset( $_POST['attachment_id'] ) ? $_POST['attachment_id'] : 0;
check_ajax_referer( "rwmb-attach-file_{$field_id}" );
-
+
add_post_meta( $post_id, $field_id, $attachment_id, false );
-
+
RW_Meta_Box::ajax_response( self::file_html( $attachment_id ), 'success' );
}
-
+
/**
* Get field HTML
*
@@ -56,8 +56,8 @@ static function wp_ajax_attach_file()
*/
static function html( $html, $meta, $field )
{
- $i18n_title = _x( 'Select files', 'file upload', 'rwmb' );
- $attach_nonce = wp_create_nonce( "rwmb-attach-file_{$field['id']}" );
+ $i18n_title = apply_filters( 'rwmb_file_advanced_select_string', _x( 'Select Files', 'file upload', 'rwmb' ), $field );
+ $attach_nonce = wp_create_nonce( "rwmb-attach-file_{$field['id']}" );
// Uploaded files
$html = self::get_uploaded_files( $meta, $field );
@@ -72,7 +72,7 @@ static function html( $html, $meta, $field )
return $html;
}
-
+
/**
* Get field value
* It's the combination of new (uploaded) images and saved images
@@ -90,4 +90,4 @@ static function value( $new, $old, $post_id, $field )
return array_unique( array_merge( $old, $new ) );
}
}
-}
+}
View
10 inc/fields/file.php
@@ -77,8 +77,8 @@ static function wp_ajax_delete_file()
*/
static function html( $html, $meta, $field )
{
- $i18n_title = _x( 'Upload files', 'file upload', 'rwmb' );
- $i18n_more = _x( '+ Add new file', 'file upload', 'rwmb' );
+ $i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'rwmb' ), $field );
+ $i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'rwmb' ), $field );
// Uploaded files
$html = self::get_uploaded_files( $meta, $field );
@@ -130,8 +130,8 @@ static function get_uploaded_files( $files, $field )
static function file_html( $attachment_id )
{
- $i18n_delete = _x( 'Delete', 'file upload', 'rwmb' );
- $i18n_edit = _x( 'Edit', 'file upload', 'rwmb' );
+ $i18n_delete = apply_filters( 'rwmb_file_delete_string', _x( 'Delete', 'file upload', 'rwmb' ) );
+ $i18n_edit = apply_filters( 'rwmb_file_edit_string', _x( 'Edit', 'file upload', 'rwmb' ) );
$li = '
<li>
<div class="rwmb-icon">%s</div>
@@ -272,4 +272,4 @@ static function meta( $meta, $post_id, $saved, $field )
return (array) $meta;
}
}
-}
+}
View
16 inc/fields/image-advanced.php
@@ -16,7 +16,7 @@ static function admin_enqueue_scripts()
parent::admin_enqueue_scripts();
wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', array( 'jquery' ), RWMB_VER, true );
}
-
+
/**
* Add actions
*
@@ -30,7 +30,7 @@ static function add_actions()
// Attach images via Ajax
add_action( 'wp_ajax_rwmb_attach_media', array( __CLASS__, 'wp_ajax_attach_media' ) );
}
-
+
/**
* Ajax callback for attaching media to field
*
@@ -43,9 +43,9 @@ static function wp_ajax_attach_media()
$attachment_id = isset( $_POST['attachment_id'] ) ? $_POST['attachment_id'] : 0;
check_ajax_referer( "rwmb-attach-media_{$field_id}" );
-
+
add_post_meta( $post_id, $field_id, $attachment_id, false );
-
+
RW_Meta_Box::ajax_response( self::img_html( $attachment_id ), 'success' );
}
@@ -60,7 +60,7 @@ static function wp_ajax_attach_media()
*/
static function html( $html, $meta, $field )
{
- $i18n_title = _x( 'Select or Upload Images', 'image upload', 'rwmb' );
+ $i18n_title = apply_filters( 'rwmb_image_advanced_select_string', _x( 'Select or Upload Images', 'image upload', 'rwmb' ), $field );
$attach_nonce = wp_create_nonce( "rwmb-attach-media_{$field['id']}" );
// Uploaded images
@@ -70,13 +70,13 @@ static function html( $html, $meta, $field )
$classes = array( 'button', 'rwmb-image-advanced-upload', 'hide-if-no-js', 'new-files' );
if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] )
$classes[] = 'hidden';
-
+
$classes = implode( ' ', $classes );
$html .= "<a href='#' class='{$classes}' data-attach_media_nonce={$attach_nonce}>{$i18n_title}</a>";
return $html;
}
-
+
/**
* Get field value
* It's the combination of new (uploaded) images and saved images
@@ -95,4 +95,4 @@ static function value( $new, $old, $post_id, $field )
}
}
-}
+}
View
11 inc/fields/image.php
@@ -75,8 +75,8 @@ static function wp_ajax_reorder_images()
*/
static function html( $html, $meta, $field )
{
- $i18n_title = _x( 'Upload images', 'image upload', 'rwmb' );
- $i18n_more = _x( '+ Add new image', 'image upload', 'rwmb' );
+ $i18n_title = apply_filters( 'rwmb_image_upload_string', _x( 'Upload Images', 'image upload', 'rwmb' ), $field );
+ $i18n_more = apply_filters( 'rwmb_image_add_string', _x( '+ Add new image', 'image upload', 'rwmb' ), $field );
// Uploaded images
$html .= self::get_uploaded_images( $meta, $field );
@@ -136,14 +136,13 @@ static function get_uploaded_images( $images, $field )
* Get HTML markup for ONE uploaded image
*
* @param int $image Image ID
- * @param int $field
*
* @return string
*/
static function img_html( $image )
{
- $i18n_delete = _x( 'Delete', 'image upload', 'rwmb' );
- $i18n_edit = _x( 'Edit', 'image upload', 'rwmb' );
+ $i18n_delete = apply_filters( 'rwmb_image_delete_string', _x( 'Delete', 'image upload', 'rwmb' ) );
+ $i18n_edit = apply_filters( 'rwmb_image_edit_string', _x( 'Edit', 'image upload', 'rwmb' ) );
$li = '
<li id="item_%s">
<img src="%s" />
@@ -199,4 +198,4 @@ static function meta( $meta, $post_id, $saved, $field )
return (array) $meta;
}
}
-}
+}
View
17 inc/fields/plupload-image.php
@@ -37,7 +37,7 @@ static function handle_upload()
//Get next menu_order
$meta = get_post_meta( $post_id, $field_id, false );
if( empty( $meta ) ){
- $next = 0;
+ $next = 0;
} else {
$meta = implode( ',' , (array) $meta );
$max = $wpdb->get_var( "
@@ -47,7 +47,7 @@ static function handle_upload()
" );
$next = is_numeric($max) ? (int) $max + 1: 0;
}
-
+
$attachment = array(
'guid' => $file_attr['url'],
'post_mime_type' => $file_attr['type'],
@@ -65,7 +65,7 @@ static function handle_upload()
// Save file ID in meta field
add_post_meta( $post_id, $field_id, $id, false );
-
+
RW_Meta_Box::ajax_response( self::img_html( $id ), 'success' );
}
@@ -101,12 +101,11 @@ static function html( $html, $meta, $field )
$meta = ( array ) $meta;
// Filter to change the drag & drop box background string
- $i18n_drop = apply_filters( 'rwmb_upload_drop_string', _x( 'Drop images here', 'image upload', 'rwmb' ) );
- $i18n_or = _x( 'or', 'image upload', 'rwmb' );
- $i18n_select = _x( 'Select Files', 'image upload', 'rwmb' );
+ $i18n_drop = apply_filters( 'rwmb_plupload_image_drop_string', _x( 'Drop images here', 'image upload', 'rwmb' ), $field );
+ $i18n_or = apply_filters( 'rwmb_plupload_image_or_string', _x( 'or', 'image upload', 'rwmb' ), $field );
+ $i18n_select = apply_filters( 'rwmb_plupload_image_select_string', _x( 'Select Files', 'image upload', 'rwmb' ), $field );
// Uploaded images
-
// Check for max_file_uploads
$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 )
$new = (array) $new;
return array_unique( array_merge( $old, $new ) );
}
-
+
/**
* Normalize parameters for field
*
@@ -193,4 +192,4 @@ static function normalize_field( $field )
return $field;
}
}
-}
+}
View
4 inc/fields/thickbox-image.php
@@ -32,7 +32,7 @@ static function admin_enqueue_scripts()
*/
static function html( $html, $meta, $field )
{
- $i18n_title = _x( 'Upload images', 'image upload', 'rwmb' );
+ $i18n_title = apply_filters( 'rwmb_thickbox_image_upload_string', _x( 'Upload Images', 'image upload', 'rwmb' ), $field );
$html = wp_nonce_field( "rwmb-delete-file_{$field['id']}", "nonce-delete-file_{$field['id']}", false, false );
$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 )
return array_unique( array_merge( $old, $new ) );
}
}
-}
+}

0 comments on commit 13f1f39

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