Version Description
- New field: wysiwyg
- Fields will now properly respect line breaks
- Fields will now properly return HTML instead of escaped HTML
Download this release
Release Info
| Developer | jchristopher |
| Plugin | |
| Version | 3.1 |
| Comparing to | |
| See all releases | |
Code changes from version 3.0.8.2 to 3.1
- README.md +15 -10
- classes/class.attachments.php +77 -14
- classes/class.field.php +2 -2
- classes/fields/class.field.text.php +1 -1
- classes/fields/class.field.textarea.php +3 -3
- classes/fields/class.field.wysiwyg.php +96 -0
- css/attachments.css +1 -0
- index.php +1 -1
- js/attachments.js +7 -1
- readme.txt +14 -9
- views/options.php +8 -4
README.md
CHANGED
|
@@ -118,7 +118,7 @@ function my_attachments( $attachments )
|
|
| 118 |
*
|
| 119 |
* name - (string) The field name used. No special characters.
|
| 120 |
* type - (string) The registered field type.
|
| 121 |
-
* Fields available: text, textarea
|
| 122 |
* label - (string) The label displayed for the field.
|
| 123 |
*/
|
| 124 |
|
|
@@ -130,14 +130,9 @@ function my_attachments( $attachments )
|
|
| 130 |
),
|
| 131 |
array(
|
| 132 |
'name' => 'caption', // unique field name
|
| 133 |
-
'type' => '
|
| 134 |
'label' => __( 'Caption', 'attachments' ), // label to display
|
| 135 |
-
)
|
| 136 |
-
array(
|
| 137 |
-
'name' => 'copyright', // unique field name
|
| 138 |
-
'type' => 'text', // registered field type
|
| 139 |
-
'label' => __( 'Copyright', 'attachments' ), // label to display
|
| 140 |
-
),
|
| 141 |
),
|
| 142 |
|
| 143 |
);
|
|
@@ -255,8 +250,19 @@ Attachments uses WordPress' built in Media library for uploads and storage.
|
|
| 255 |
|
| 256 |
<dl>
|
| 257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
<dt>3.0.8.1</dt>
|
| 259 |
-
<
|
| 260 |
|
| 261 |
<dt>3.0.8</dt>
|
| 262 |
<dd>Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label</dd>
|
|
@@ -309,7 +315,6 @@ Attachments uses WordPress' built in Media library for uploads and storage.
|
|
| 309 |
|
| 310 |
Planned feature additions include:
|
| 311 |
|
| 312 |
-
* Additional field type: WYSIWYG
|
| 313 |
* Additional field type: checkbox
|
| 314 |
* Additional field type: radio
|
| 315 |
* Additional field type: select
|
| 118 |
*
|
| 119 |
* name - (string) The field name used. No special characters.
|
| 120 |
* type - (string) The registered field type.
|
| 121 |
+
* Fields available: text, textarea, wysiwyg
|
| 122 |
* label - (string) The label displayed for the field.
|
| 123 |
*/
|
| 124 |
|
| 130 |
),
|
| 131 |
array(
|
| 132 |
'name' => 'caption', // unique field name
|
| 133 |
+
'type' => 'wysiwyg', // registered field type
|
| 134 |
'label' => __( 'Caption', 'attachments' ), // label to display
|
| 135 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
),
|
| 137 |
|
| 138 |
);
|
| 250 |
|
| 251 |
<dl>
|
| 252 |
|
| 253 |
+
<dt>3.1</dt>
|
| 254 |
+
<dd>New field: wysiwyg</dd>
|
| 255 |
+
<dd>Fields will now properly respect line breaks</dd>
|
| 256 |
+
<dd>Fields will now properly return HTML instead of escaped HTML</dd>
|
| 257 |
+
|
| 258 |
+
<dt>3.0.9</dt>
|
| 259 |
+
<dd>Fixed an issue where special characters would break title/caption fields during migration</dd>
|
| 260 |
+
|
| 261 |
+
<dt>3.0.8.2</dt>
|
| 262 |
+
<dd>Fixed a CSS issue with only one text field</dd>
|
| 263 |
+
|
| 264 |
<dt>3.0.8.1</dt>
|
| 265 |
+
<dd>Better storage of special characters for PHP 5.4+</dd>
|
| 266 |
|
| 267 |
<dt>3.0.8</dt>
|
| 268 |
<dd>Fixed an issue in Firefox where you weren't able to focus inputs unless you clicked their label</dd>
|
| 315 |
|
| 316 |
Planned feature additions include:
|
| 317 |
|
|
|
|
| 318 |
* Additional field type: checkbox
|
| 319 |
* Additional field type: radio
|
| 320 |
* Additional field type: select
|
classes/class.attachments.php
CHANGED
|
@@ -56,7 +56,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 56 |
global $_wp_additional_image_sizes;
|
| 57 |
|
| 58 |
// establish our environment variables
|
| 59 |
-
$this->version = '3.
|
| 60 |
$this->url = ATTACHMENTS_URL;
|
| 61 |
$this->dir = ATTACHMENTS_DIR;
|
| 62 |
|
|
@@ -67,6 +67,8 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 67 |
// deal with our legacy issues if the user hasn't dismissed or migrated already
|
| 68 |
if( false == get_option( 'attachments_migrated' ) && false == get_option( 'attachments_ignore_migration' ) )
|
| 69 |
{
|
|
|
|
|
|
|
| 70 |
$legacy = new WP_Query( 'post_type=any&post_status=any&posts_per_page=1&meta_key=_attachments' );
|
| 71 |
$this->legacy = empty( $legacy->found_posts ) ? false : true;
|
| 72 |
}
|
|
@@ -89,7 +91,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 89 |
add_action( 'init', array( $this, 'do_actions_filters' ) );
|
| 90 |
|
| 91 |
// determine which instances apply to the current post type
|
| 92 |
-
add_action( 'init', array( $this, 'set_instances_for_current_post_type' )
|
| 93 |
|
| 94 |
add_action( 'add_meta_boxes', array( $this, 'meta_box_init' ) );
|
| 95 |
|
|
@@ -102,6 +104,8 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 102 |
// with version 3 we'll be giving at least one admin notice
|
| 103 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
|
| 104 |
|
|
|
|
|
|
|
| 105 |
// set our attachments if necessary
|
| 106 |
if( !is_null( $instance ) )
|
| 107 |
$this->attachments = $this->get_attachments( $instance, $post_id );
|
|
@@ -406,7 +410,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 406 |
|
| 407 |
?>
|
| 408 |
|
| 409 |
-
<div id="attachments-<?php echo $instance->name; ?>">
|
| 410 |
<?php if( !empty( $instance->note ) ) : ?>
|
| 411 |
<div class="attachments-note"><?php echo apply_filters( 'the_content', $instance->note ); ?></div>
|
| 412 |
<?php endif; ?>
|
|
@@ -505,6 +509,8 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 505 |
// append the template
|
| 506 |
$element.find('.attachments-container').append(template(templateData));
|
| 507 |
|
|
|
|
|
|
|
| 508 |
// if it wasn't an image we need to ditch the dimensions
|
| 509 |
if(!attachments_isset(attachment.attributes.width)||!attachments_isset(attachment.attributes.height)){
|
| 510 |
$element.find('.attachments-attachment:last .dimensions').hide();
|
|
@@ -549,29 +555,39 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 549 |
$field_types = array(
|
| 550 |
'text' => ATTACHMENTS_DIR . 'classes/fields/class.field.text.php',
|
| 551 |
'textarea' => ATTACHMENTS_DIR . 'classes/fields/class.field.textarea.php',
|
|
|
|
| 552 |
);
|
| 553 |
|
| 554 |
// support custom field types
|
| 555 |
// $field_types = apply_filters( 'attachments_fields', $field_types );
|
| 556 |
|
|
|
|
| 557 |
foreach( $field_types as $type => $path )
|
| 558 |
{
|
| 559 |
-
// store the registered classes so we can single out what gets added
|
| 560 |
-
$classes_before = get_declared_classes();
|
| 561 |
-
|
| 562 |
// proceed with inclusion
|
| 563 |
if( file_exists( $path ) )
|
| 564 |
{
|
| 565 |
// include the file
|
| 566 |
include_once( $path );
|
| 567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
// determine it's class
|
| 569 |
-
$
|
| 570 |
-
|
| 571 |
-
|
|
|
|
| 572 |
|
| 573 |
// create our link using our new field class
|
| 574 |
$field_types[$type] = $field_class;
|
|
|
|
|
|
|
| 575 |
}
|
| 576 |
}
|
| 577 |
|
|
@@ -690,7 +706,6 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 690 |
foreach( $params['post_type'] as $key => $post_type )
|
| 691 |
$params['post_type'][$key] = sanitize_key( $post_type );
|
| 692 |
|
| 693 |
-
// print_r($params['post_type']);
|
| 694 |
|
| 695 |
// make sure the instance name is proper
|
| 696 |
$instance = str_replace( '-', '_', sanitize_title( $name ) );
|
|
@@ -808,7 +823,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 808 |
$value = ( isset( $attachment->fields->$name ) ) ? $attachment->fields->$name : null;
|
| 809 |
|
| 810 |
$field = new $this->fields[$type]( $name, $label, $value );
|
| 811 |
-
$field->
|
| 812 |
|
| 813 |
// does this field already have a unique ID?
|
| 814 |
$uid = ( isset( $attachment->uid ) ) ? $attachment->uid : null;
|
|
@@ -921,6 +936,33 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 921 |
|
| 922 |
|
| 923 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 924 |
/**
|
| 925 |
* Outputs all necessary Backbone templates
|
| 926 |
* Each Backbone template includes each field present in an instance
|
|
@@ -990,8 +1032,24 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 990 |
|
| 991 |
foreach( $attachment['fields'] as $key => $field_value )
|
| 992 |
{
|
| 993 |
-
//
|
| 994 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 995 |
}
|
| 996 |
}
|
| 997 |
|
|
@@ -1036,6 +1094,7 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 1036 |
return;
|
| 1037 |
}
|
| 1038 |
|
|
|
|
| 1039 |
// grab our JSON and decode it
|
| 1040 |
$attachments_json = get_post_meta( $post_id, $this->meta_key, true );
|
| 1041 |
$attachments_raw = is_string( $attachments_json ) ? json_decode( $attachments_json ) : false;
|
|
@@ -1062,7 +1121,6 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 1062 |
break;
|
| 1063 |
}
|
| 1064 |
}
|
| 1065 |
-
|
| 1066 |
if( isset( $this->fields[$type] ) )
|
| 1067 |
{
|
| 1068 |
// we need to decode the html entities that were encoded for the save
|
|
@@ -1074,6 +1132,11 @@ if ( !class_exists( 'Attachments' ) ) :
|
|
| 1074 |
$attachment->fields->$key = false;
|
| 1075 |
}
|
| 1076 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
}
|
| 1078 |
}
|
| 1079 |
$attachments[] = $attachment;
|
| 56 |
global $_wp_additional_image_sizes;
|
| 57 |
|
| 58 |
// establish our environment variables
|
| 59 |
+
$this->version = '3.1';
|
| 60 |
$this->url = ATTACHMENTS_URL;
|
| 61 |
$this->dir = ATTACHMENTS_DIR;
|
| 62 |
|
| 67 |
// deal with our legacy issues if the user hasn't dismissed or migrated already
|
| 68 |
if( false == get_option( 'attachments_migrated' ) && false == get_option( 'attachments_ignore_migration' ) )
|
| 69 |
{
|
| 70 |
+
// TODO: this will not retrieve posts that have exclude_from_search = true
|
| 71 |
+
// TODO: make this reusable elsewhere
|
| 72 |
$legacy = new WP_Query( 'post_type=any&post_status=any&posts_per_page=1&meta_key=_attachments' );
|
| 73 |
$this->legacy = empty( $legacy->found_posts ) ? false : true;
|
| 74 |
}
|
| 91 |
add_action( 'init', array( $this, 'do_actions_filters' ) );
|
| 92 |
|
| 93 |
// determine which instances apply to the current post type
|
| 94 |
+
add_action( 'init', array( $this, 'set_instances_for_current_post_type' ) );
|
| 95 |
|
| 96 |
add_action( 'add_meta_boxes', array( $this, 'meta_box_init' ) );
|
| 97 |
|
| 104 |
// with version 3 we'll be giving at least one admin notice
|
| 105 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
|
| 106 |
|
| 107 |
+
add_action( 'admin_print_footer_scripts', array( $this, 'field_assets' ) );
|
| 108 |
+
|
| 109 |
// set our attachments if necessary
|
| 110 |
if( !is_null( $instance ) )
|
| 111 |
$this->attachments = $this->get_attachments( $instance, $post_id );
|
| 410 |
|
| 411 |
?>
|
| 412 |
|
| 413 |
+
<div id="attachments-<?php echo $instance->name; ?>" class="attachments-parent-container">
|
| 414 |
<?php if( !empty( $instance->note ) ) : ?>
|
| 415 |
<div class="attachments-note"><?php echo apply_filters( 'the_content', $instance->note ); ?></div>
|
| 416 |
<?php endif; ?>
|
| 509 |
// append the template
|
| 510 |
$element.find('.attachments-container').append(template(templateData));
|
| 511 |
|
| 512 |
+
$('body').trigger('attachments/new');
|
| 513 |
+
|
| 514 |
// if it wasn't an image we need to ditch the dimensions
|
| 515 |
if(!attachments_isset(attachment.attributes.width)||!attachments_isset(attachment.attributes.height)){
|
| 516 |
$element.find('.attachments-attachment:last .dimensions').hide();
|
| 555 |
$field_types = array(
|
| 556 |
'text' => ATTACHMENTS_DIR . 'classes/fields/class.field.text.php',
|
| 557 |
'textarea' => ATTACHMENTS_DIR . 'classes/fields/class.field.textarea.php',
|
| 558 |
+
'wysiwyg' => ATTACHMENTS_DIR . 'classes/fields/class.field.wysiwyg.php',
|
| 559 |
);
|
| 560 |
|
| 561 |
// support custom field types
|
| 562 |
// $field_types = apply_filters( 'attachments_fields', $field_types );
|
| 563 |
|
| 564 |
+
$field_index = 0;
|
| 565 |
foreach( $field_types as $type => $path )
|
| 566 |
{
|
|
|
|
|
|
|
|
|
|
| 567 |
// proceed with inclusion
|
| 568 |
if( file_exists( $path ) )
|
| 569 |
{
|
| 570 |
// include the file
|
| 571 |
include_once( $path );
|
| 572 |
|
| 573 |
+
// store the registered classes so we can single out what gets added
|
| 574 |
+
$existing_classes = get_declared_classes();
|
| 575 |
+
|
| 576 |
+
// we're going to use our Attachments class as a reference because
|
| 577 |
+
// during subsequent instantiations of Attachments (e.g. within template files)
|
| 578 |
+
// these field classes WILL NOT be added to the array again because
|
| 579 |
+
// we're using include_once() so that strategy is no longer useful
|
| 580 |
+
|
| 581 |
// determine it's class
|
| 582 |
+
$flag = array_search( 'Attachments_Field', $existing_classes );
|
| 583 |
+
|
| 584 |
+
// the field's class is next
|
| 585 |
+
$field_class = $existing_classes[$flag + $field_index + 1];
|
| 586 |
|
| 587 |
// create our link using our new field class
|
| 588 |
$field_types[$type] = $field_class;
|
| 589 |
+
|
| 590 |
+
$field_index++;
|
| 591 |
}
|
| 592 |
}
|
| 593 |
|
| 706 |
foreach( $params['post_type'] as $key => $post_type )
|
| 707 |
$params['post_type'][$key] = sanitize_key( $post_type );
|
| 708 |
|
|
|
|
| 709 |
|
| 710 |
// make sure the instance name is proper
|
| 711 |
$instance = str_replace( '-', '_', sanitize_title( $name ) );
|
| 823 |
$value = ( isset( $attachment->fields->$name ) ) ? $attachment->fields->$name : null;
|
| 824 |
|
| 825 |
$field = new $this->fields[$type]( $name, $label, $value );
|
| 826 |
+
$field->value = $field->format_value_for_input( $field->value );
|
| 827 |
|
| 828 |
// does this field already have a unique ID?
|
| 829 |
$uid = ( isset( $attachment->uid ) ) ? $attachment->uid : null;
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
+
function field_assets()
|
| 940 |
+
{
|
| 941 |
+
// all metaboxes have been put in place, we can now determine which field assets need to be included
|
| 942 |
+
|
| 943 |
+
// first we'll get a list of the field types on screen
|
| 944 |
+
$fieldtypes = array();
|
| 945 |
+
foreach( $this->instances_for_post_type as $instance )
|
| 946 |
+
{
|
| 947 |
+
foreach( $this->instances[$instance]['fields'] as $field )
|
| 948 |
+
{
|
| 949 |
+
$fieldtypes[] = $field['type'];
|
| 950 |
+
}
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
// we only want to dump out assets once for each field type
|
| 954 |
+
$fieldtypes = array_unique( $fieldtypes );
|
| 955 |
+
|
| 956 |
+
// loop through and dump out all the assets
|
| 957 |
+
foreach( $fieldtypes as $fieldtype )
|
| 958 |
+
{
|
| 959 |
+
$field = new $this->fields[$fieldtype];
|
| 960 |
+
$field->assets();
|
| 961 |
+
}
|
| 962 |
+
}
|
| 963 |
+
|
| 964 |
+
|
| 965 |
+
|
| 966 |
/**
|
| 967 |
* Outputs all necessary Backbone templates
|
| 968 |
* Each Backbone template includes each field present in an instance
|
| 1032 |
|
| 1033 |
foreach( $attachment['fields'] as $key => $field_value )
|
| 1034 |
{
|
| 1035 |
+
// take care of our returns
|
| 1036 |
+
$field_value = str_replace( "\r\n", "\n", $field_value );
|
| 1037 |
+
$field_value = str_replace( "\r", "\n", $field_value );
|
| 1038 |
+
|
| 1039 |
+
// we dont want to strip out our newlines so we're going to flag them
|
| 1040 |
+
$field_value = str_replace("\n", "%%ATTACHMENTS_NEWLINE%%", $field_value );
|
| 1041 |
+
|
| 1042 |
+
// slashes were already added so we're going to strip them
|
| 1043 |
+
$field_value = stripslashes( $field_value );
|
| 1044 |
+
|
| 1045 |
+
// put back our newlines
|
| 1046 |
+
$field_value = str_replace("%%ATTACHMENTS_NEWLINE%%", "\\n", $field_value );
|
| 1047 |
+
|
| 1048 |
+
// encode the whole thing
|
| 1049 |
+
$field_value = htmlentities( $field_value, ENT_QUOTES, 'UTF-8' );
|
| 1050 |
+
|
| 1051 |
+
// encode things properly
|
| 1052 |
+
$attachment['fields'][$key] = $field_value;
|
| 1053 |
}
|
| 1054 |
}
|
| 1055 |
|
| 1094 |
return;
|
| 1095 |
}
|
| 1096 |
|
| 1097 |
+
|
| 1098 |
// grab our JSON and decode it
|
| 1099 |
$attachments_json = get_post_meta( $post_id, $this->meta_key, true );
|
| 1100 |
$attachments_raw = is_string( $attachments_json ) ? json_decode( $attachments_json ) : false;
|
| 1121 |
break;
|
| 1122 |
}
|
| 1123 |
}
|
|
|
|
| 1124 |
if( isset( $this->fields[$type] ) )
|
| 1125 |
{
|
| 1126 |
// we need to decode the html entities that were encoded for the save
|
| 1132 |
$attachment->fields->$key = false;
|
| 1133 |
}
|
| 1134 |
}
|
| 1135 |
+
else
|
| 1136 |
+
{
|
| 1137 |
+
// this was a theme file request, just grab it
|
| 1138 |
+
$attachment->fields->$key = html_entity_decode( $attachment->fields->$key, ENT_QUOTES, 'UTF-8' );
|
| 1139 |
+
}
|
| 1140 |
}
|
| 1141 |
}
|
| 1142 |
$attachments[] = $attachment;
|
classes/class.field.php
CHANGED
|
@@ -14,7 +14,7 @@ if ( !class_exists( 'Attachments_Field' ) ) :
|
|
| 14 |
{
|
| 15 |
public function html( $field );
|
| 16 |
public function format_value_for_input( $value, $field = null );
|
| 17 |
-
public function
|
| 18 |
}
|
| 19 |
|
| 20 |
class Attachments_Field implements Attachments_Field_Template
|
|
@@ -75,7 +75,7 @@ if ( !class_exists( 'Attachments_Field' ) ) :
|
|
| 75 |
return $value;
|
| 76 |
}
|
| 77 |
|
| 78 |
-
public function
|
| 79 |
{
|
| 80 |
return;
|
| 81 |
}
|
| 14 |
{
|
| 15 |
public function html( $field );
|
| 16 |
public function format_value_for_input( $value, $field = null );
|
| 17 |
+
public function assets( $field );
|
| 18 |
}
|
| 19 |
|
| 20 |
class Attachments_Field implements Attachments_Field_Template
|
| 75 |
return $value;
|
| 76 |
}
|
| 77 |
|
| 78 |
+
public function assets( $field )
|
| 79 |
{
|
| 80 |
return;
|
| 81 |
}
|
classes/fields/class.field.text.php
CHANGED
|
@@ -27,7 +27,7 @@ class Attachments_Field_Text extends Attachments_Field implements Attachments_Fi
|
|
| 27 |
return htmlspecialchars( $value, ENT_QUOTES );
|
| 28 |
}
|
| 29 |
|
| 30 |
-
public function
|
| 31 |
{
|
| 32 |
return;
|
| 33 |
}
|
| 27 |
return htmlspecialchars( $value, ENT_QUOTES );
|
| 28 |
}
|
| 29 |
|
| 30 |
+
public function assets( $field = null )
|
| 31 |
{
|
| 32 |
return;
|
| 33 |
}
|
classes/fields/class.field.textarea.php
CHANGED
|
@@ -22,12 +22,12 @@ class Attachments_Field_Textarea extends Attachments_Field implements Attachment
|
|
| 22 |
<?php
|
| 23 |
}
|
| 24 |
|
| 25 |
-
function format_value_for_input( $value, $field = null
|
| 26 |
{
|
| 27 |
-
return
|
| 28 |
}
|
| 29 |
|
| 30 |
-
public function
|
| 31 |
{
|
| 32 |
return;
|
| 33 |
}
|
| 22 |
<?php
|
| 23 |
}
|
| 24 |
|
| 25 |
+
function format_value_for_input( $value, $field = null )
|
| 26 |
{
|
| 27 |
+
return $value;
|
| 28 |
}
|
| 29 |
|
| 30 |
+
public function assets( $field = null )
|
| 31 |
{
|
| 32 |
return;
|
| 33 |
}
|
classes/fields/class.field.wysiwyg.php
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Attachments WYSIWYG field
|
| 5 |
+
*
|
| 6 |
+
* @package Attachments
|
| 7 |
+
* @subpackage Main
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
class Attachments_Field_WYSIWYG extends Attachments_Field implements Attachments_Field_Template
|
| 11 |
+
{
|
| 12 |
+
|
| 13 |
+
function __construct( $name = 'name', $label = 'Name', $value = null )
|
| 14 |
+
{
|
| 15 |
+
parent::__construct( $name, $label, $value );
|
| 16 |
+
|
| 17 |
+
add_filter( 'wp_default_editor', array( $this, 'wp_default_editor' ) );
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function html( $field )
|
| 21 |
+
{
|
| 22 |
+
?>
|
| 23 |
+
<div class="wp-editor-wrap attachments-field-wysiwyg-editor-wrap">
|
| 24 |
+
<div class="wp-editor-container">
|
| 25 |
+
<textarea name="<?php esc_attr_e( $field->field_name ); ?>" id="<?php esc_attr_e( $field->field_id ); ?>" class="wp-editor-area attachments attachments-field attachments-field-wysiwyg attachments-field-<?php esc_attr_e( $field->field_name ); ?> attachments-field-<?php esc_attr_e( $field->field_id ); ?>" rows="10"><?php echo $field->value; ?></textarea>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
<?php
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function assets( $field = null )
|
| 32 |
+
{
|
| 33 |
+
if( 'true' == get_user_meta( get_current_user_id(), 'rich_editing', true ) ) :
|
| 34 |
+
?>
|
| 35 |
+
<style type="text/css">
|
| 36 |
+
.attachments-field-wysiwyg-editor-wrap { background:#fff; }
|
| 37 |
+
</style>
|
| 38 |
+
<script>
|
| 39 |
+
(function($) {
|
| 40 |
+
|
| 41 |
+
var wpautop = true;
|
| 42 |
+
|
| 43 |
+
// handle both initial and subsequent additions
|
| 44 |
+
$(function() {
|
| 45 |
+
wpautop = tinyMCE.settings.wpautop;
|
| 46 |
+
$(document).on( 'attachments/new', function( event ) {
|
| 47 |
+
$('.attachments-field-wysiwyg:not(.ready)').init_wysiwyg();
|
| 48 |
+
});
|
| 49 |
+
$('.attachments-field-wysiwyg').init_wysiwyg();
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
$.fn.init_wysiwyg = function() {
|
| 53 |
+
this.each(function() {
|
| 54 |
+
|
| 55 |
+
$(this).addClass('ready');
|
| 56 |
+
|
| 57 |
+
var input_id = $(this).attr('id');
|
| 58 |
+
|
| 59 |
+
// create wysiwyg
|
| 60 |
+
tinyMCE.settings.theme_advanced_buttons2 += ',code';
|
| 61 |
+
tinyMCE.settings.wpautop = false;
|
| 62 |
+
tinyMCE.execCommand('mceAddControl', false, input_id);
|
| 63 |
+
tinyMCE.settings.wpautop = wpautop;
|
| 64 |
+
});
|
| 65 |
+
};
|
| 66 |
+
|
| 67 |
+
$(document).on('attachments/sortable_start', function(event, ui) {
|
| 68 |
+
tinyMCE.settings.wpautop = false;
|
| 69 |
+
$('.attachments-field-wysiwyg').each(function() {
|
| 70 |
+
tinyMCE.execCommand('mceRemoveControl', false, $(this).attr('id'));
|
| 71 |
+
});
|
| 72 |
+
});
|
| 73 |
+
|
| 74 |
+
$(document).on('attachments/sortable_stop', function(event, ui) {
|
| 75 |
+
$('.attachments-field-wysiwyg').each(function() {
|
| 76 |
+
tinyMCE.execCommand('mceAddControl', false, $(this).attr('id'));
|
| 77 |
+
});
|
| 78 |
+
tinyMCE.settings.wpautop = wpautop;
|
| 79 |
+
});
|
| 80 |
+
})(jQuery);
|
| 81 |
+
</script>
|
| 82 |
+
<?php
|
| 83 |
+
endif;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function format_value_for_input( $value, $field = null )
|
| 87 |
+
{
|
| 88 |
+
return wp_richedit_pre( $value );
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function wp_default_editor()
|
| 92 |
+
{
|
| 93 |
+
return 'tinymce'; // html or tinymce
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
}
|
css/attachments.css
CHANGED
|
@@ -7,6 +7,7 @@ a.attachments-invoke {
|
|
| 7 |
position:relative;
|
| 8 |
padding:5px 0 25px;
|
| 9 |
border-bottom:1px solid #e7e7e7;
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
.attachments-attachment:before,
|
| 7 |
position:relative;
|
| 8 |
padding:5px 0 25px;
|
| 9 |
border-bottom:1px solid #e7e7e7;
|
| 10 |
+
min-height:125px;
|
| 11 |
}
|
| 12 |
|
| 13 |
.attachments-attachment:before,
|
index.php
CHANGED
|
@@ -6,7 +6,7 @@
|
|
| 6 |
* Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
|
| 7 |
* Author: Jonathan Christopher
|
| 8 |
* Author URI: http://mondaybynoon.com/
|
| 9 |
-
* Version: 3.
|
| 10 |
* Text Domain: attachments
|
| 11 |
* Domain Path: /languages/
|
| 12 |
* License: GPLv2 or later
|
| 6 |
* Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
|
| 7 |
* Author: Jonathan Christopher
|
| 8 |
* Author URI: http://mondaybynoon.com/
|
| 9 |
+
* Version: 3.1
|
| 10 |
* Text Domain: attachments
|
| 11 |
* Domain Path: /languages/
|
| 12 |
* License: GPLv2 or later
|
js/attachments.js
CHANGED
|
@@ -84,6 +84,12 @@ jQuery(document).ready(function($){
|
|
| 84 |
tolerance: 'intersect',
|
| 85 |
axis: 'y',
|
| 86 |
containment: 'parent',
|
| 87 |
-
handle: '.attachments-handle img'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
});
|
| 89 |
});
|
| 84 |
tolerance: 'intersect',
|
| 85 |
axis: 'y',
|
| 86 |
containment: 'parent',
|
| 87 |
+
handle: '.attachments-handle img',
|
| 88 |
+
start: function(event, ui) {
|
| 89 |
+
$(document).trigger('attachments/sortable_start');
|
| 90 |
+
},
|
| 91 |
+
stop: function(event, ui) {
|
| 92 |
+
$(document).trigger('attachments/sortable_stop');
|
| 93 |
+
},
|
| 94 |
});
|
| 95 |
});
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Donate link: http://mondaybynoon.com/donate/
|
|
| 4 |
Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
|
| 5 |
Requires at least: 3.0
|
| 6 |
Tested up to: 3.5
|
| 7 |
-
Stable tag: 3.
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
|
@@ -95,6 +95,17 @@ Attachments uses WordPress' built in Media library for uploads and storage.
|
|
| 95 |
|
| 96 |
== Changelog ==
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
= 3.0.8.1 =
|
| 99 |
* Better storage of special characters for PHP 5.4+
|
| 100 |
|
|
@@ -291,7 +302,6 @@ Attachments are now stored in such a way that removes an in-place limitation on
|
|
| 291 |
|
| 292 |
Planned feature additions include:
|
| 293 |
|
| 294 |
-
* Additional field type: WYSIWYG
|
| 295 |
* Additional field type: checkbox
|
| 296 |
* Additional field type: radio
|
| 297 |
* Additional field type: select
|
|
@@ -344,7 +354,7 @@ function my_attachments( $attachments )
|
|
| 344 |
*
|
| 345 |
* name - (string) The field name used. No special characters.
|
| 346 |
* type - (string) The registered field type.
|
| 347 |
-
* Fields available: text, textarea
|
| 348 |
* label - (string) The label displayed for the field.
|
| 349 |
*/
|
| 350 |
|
|
@@ -356,14 +366,9 @@ function my_attachments( $attachments )
|
|
| 356 |
),
|
| 357 |
array(
|
| 358 |
'name' => 'caption', // unique field name
|
| 359 |
-
'type' => '
|
| 360 |
'label' => __( 'Caption', 'attachments' ), // label to display
|
| 361 |
),
|
| 362 |
-
array(
|
| 363 |
-
'name' => 'copyright', // unique field name
|
| 364 |
-
'type' => 'text', // registered field type
|
| 365 |
-
'label' => __( 'Copyright', 'attachments' ), // label to display
|
| 366 |
-
),
|
| 367 |
),
|
| 368 |
|
| 369 |
);
|
| 4 |
Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
|
| 5 |
Requires at least: 3.0
|
| 6 |
Tested up to: 3.5
|
| 7 |
+
Stable tag: 3.1
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 95 |
|
| 96 |
== Changelog ==
|
| 97 |
|
| 98 |
+
= 3.1 =
|
| 99 |
+
* New field: wysiwyg
|
| 100 |
+
* Fields will now properly respect line breaks
|
| 101 |
+
* Fields will now properly return HTML instead of escaped HTML
|
| 102 |
+
|
| 103 |
+
= 3.0.9 =
|
| 104 |
+
* Fixed an issue where special characters would break title/caption fields during migration
|
| 105 |
+
|
| 106 |
+
= 3.0.8.2 =
|
| 107 |
+
* Fixed a CSS issue with only one text field
|
| 108 |
+
|
| 109 |
= 3.0.8.1 =
|
| 110 |
* Better storage of special characters for PHP 5.4+
|
| 111 |
|
| 302 |
|
| 303 |
Planned feature additions include:
|
| 304 |
|
|
|
|
| 305 |
* Additional field type: checkbox
|
| 306 |
* Additional field type: radio
|
| 307 |
* Additional field type: select
|
| 354 |
*
|
| 355 |
* name - (string) The field name used. No special characters.
|
| 356 |
* type - (string) The registered field type.
|
| 357 |
+
* Fields available: text, textarea, wysiwyg
|
| 358 |
* label - (string) The label displayed for the field.
|
| 359 |
*/
|
| 360 |
|
| 366 |
),
|
| 367 |
array(
|
| 368 |
'name' => 'caption', // unique field name
|
| 369 |
+
'type' => 'wysiwyg', // registered field type
|
| 370 |
'label' => __( 'Caption', 'attachments' ), // label to display
|
| 371 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
),
|
| 373 |
|
| 374 |
);
|
views/options.php
CHANGED
|
@@ -22,6 +22,8 @@
|
|
| 22 |
include_once( ATTACHMENTS_DIR . '/deprecated/get-attachments.php' );
|
| 23 |
|
| 24 |
// grab all of the posts we need to migrate
|
|
|
|
|
|
|
| 25 |
$query = new WP_Query( 'post_type=any&post_status=any&posts_per_page=-1&meta_key=_attachments' );
|
| 26 |
|
| 27 |
$count = 0;
|
|
@@ -83,10 +85,10 @@
|
|
| 83 |
// fields are technically optional so we'll add those separately
|
| 84 |
// we're also going to encode them in the same way the main class does
|
| 85 |
if( $title )
|
| 86 |
-
$converted_attachment['fields'][$title] = htmlentities( stripslashes( $legacy_attachment['title'] ), ENT_QUOTES );
|
| 87 |
|
| 88 |
if( $caption )
|
| 89 |
-
$converted_attachment['fields'][$caption] = htmlentities( stripslashes( $legacy_attachment['caption'] ), ENT_QUOTES );
|
| 90 |
|
| 91 |
// check to see if the existing Attachments have our target instance
|
| 92 |
if( !isset( $existing_attachments->$instance ) )
|
|
@@ -104,7 +106,7 @@
|
|
| 104 |
}
|
| 105 |
|
| 106 |
// we're done! let's save everything in our new format
|
| 107 |
-
$existing_attachments = json_encode( $
|
| 108 |
|
| 109 |
// save it to the database
|
| 110 |
update_post_meta( $query->post->ID, 'attachments', $existing_attachments );
|
|
@@ -173,6 +175,8 @@
|
|
| 173 |
<?php
|
| 174 |
|
| 175 |
// check for any legacy Attachments
|
|
|
|
|
|
|
| 176 |
$legacy = new WP_Query( 'post_type=any&post_status=any&posts_per_page=1&meta_key=_attachments' );
|
| 177 |
|
| 178 |
// check to see if we're migrating
|
|
@@ -231,7 +235,7 @@
|
|
| 231 |
if( !wp_verify_nonce( $_GET['nonce'], 'attachments-migrate-2') ) wp_die( __( 'Invalid request', 'attachments' ) );
|
| 232 |
|
| 233 |
$total = attachments_migrate( $_GET['attachments-instance'], $_GET['attachments-title'], $_GET['attachments-caption'] );
|
| 234 |
-
|
| 235 |
if( false == get_option( 'attachments_migrated' ) ) :
|
| 236 |
?>
|
| 237 |
<h3><?php _e( 'Migration Complete!', 'attachments' ); ?></h3>
|
| 22 |
include_once( ATTACHMENTS_DIR . '/deprecated/get-attachments.php' );
|
| 23 |
|
| 24 |
// grab all of the posts we need to migrate
|
| 25 |
+
// TODO: this will not retrieve posts that have exclude_from_search = true
|
| 26 |
+
// TODO: make this reusable elsewhere
|
| 27 |
$query = new WP_Query( 'post_type=any&post_status=any&posts_per_page=-1&meta_key=_attachments' );
|
| 28 |
|
| 29 |
$count = 0;
|
| 85 |
// fields are technically optional so we'll add those separately
|
| 86 |
// we're also going to encode them in the same way the main class does
|
| 87 |
if( $title )
|
| 88 |
+
$converted_attachment['fields'][$title] = htmlentities( stripslashes( $legacy_attachment['title'] ), ENT_QUOTES, 'UTF-8' );
|
| 89 |
|
| 90 |
if( $caption )
|
| 91 |
+
$converted_attachment['fields'][$caption] = htmlentities( stripslashes( $legacy_attachment['caption'] ), ENT_QUOTES, 'UTF-8' );
|
| 92 |
|
| 93 |
// check to see if the existing Attachments have our target instance
|
| 94 |
if( !isset( $existing_attachments->$instance ) )
|
| 106 |
}
|
| 107 |
|
| 108 |
// we're done! let's save everything in our new format
|
| 109 |
+
$existing_attachments = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $attachments, JSON_UNESCAPED_UNICODE ) : json_encode( $attachments );
|
| 110 |
|
| 111 |
// save it to the database
|
| 112 |
update_post_meta( $query->post->ID, 'attachments', $existing_attachments );
|
| 175 |
<?php
|
| 176 |
|
| 177 |
// check for any legacy Attachments
|
| 178 |
+
// TODO: this will not retrieve posts that have exclude_from_search = true
|
| 179 |
+
// TODO: make this reusable elsewhere
|
| 180 |
$legacy = new WP_Query( 'post_type=any&post_status=any&posts_per_page=1&meta_key=_attachments' );
|
| 181 |
|
| 182 |
// check to see if we're migrating
|
| 235 |
if( !wp_verify_nonce( $_GET['nonce'], 'attachments-migrate-2') ) wp_die( __( 'Invalid request', 'attachments' ) );
|
| 236 |
|
| 237 |
$total = attachments_migrate( $_GET['attachments-instance'], $_GET['attachments-title'], $_GET['attachments-caption'] );
|
| 238 |
+
|
| 239 |
if( false == get_option( 'attachments_migrated' ) ) :
|
| 240 |
?>
|
| 241 |
<h3><?php _e( 'Migration Complete!', 'attachments' ); ?></h3>
|
