Smart Custom Fields - Version 2.3.0

Version Description

  • Support displayed thumbnail when value of file and image field is file url.
Download this release

Release Info

Developer inc2734
Plugin Icon wp plugin Smart Custom Fields
Version 2.3.0
Comparing to
See all releases

Code changes from version 2.2.3 to 2.3.0

classes/fields/class.field-file.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_File
4
- * Version : 1.2.0
5
  * Author : inc2734
6
  * Created : October 7, 2014
7
- * Modified : June 4, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -54,9 +54,27 @@ class Smart_Custom_Fields_Field_File extends Smart_Custom_Fields_Field_Base {
54
  $hide_class = 'hide';
55
  $image = $btn_remove;
56
  if ( $value ) {
57
- $image_src = wp_get_attachment_image_src( $value, 'thumbnail', true );
58
- if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
59
- $image_src = $image_src[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  $image = sprintf(
61
  '<a href="%s" target="_blank"><img src="%s" alt="" /></a>%s',
62
  wp_get_attachment_url( $value ),
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_File
4
+ * Version : 1.3.0
5
  * Author : inc2734
6
  * Created : October 7, 2014
7
+ * Modified : September 6, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
54
  $hide_class = 'hide';
55
  $image = $btn_remove;
56
  if ( $value ) {
57
+ // Usually, $value is attachment ID.
58
+ // If a customized, for example, $value is not an ID,
59
+ // Regarded the $value is file URL.
60
+ if ( preg_match( '/^\d+$/', $value ) ) {
61
+ $image_src = wp_get_attachment_image_src( $value, 'thumbnail', true );
62
+ if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
63
+ $image_src = $image_src[0];
64
+ }
65
+ } else {
66
+ $imag_url = $value;
67
+ $path = str_replace( home_url(), '', $value );
68
+ $image_path = ABSPATH . untrailingslashit( $path );
69
+ if ( file_exists( $image_path ) ) {
70
+ $wp_check_filetype = wp_check_filetype( $image_path );
71
+ if ( ! empty( $wp_check_filetype['type'] ) ) {
72
+ $image_src = $image_url;
73
+ }
74
+ }
75
+ }
76
+
77
+ if ( $image_src && ! is_array( $image_src ) ) {
78
  $image = sprintf(
79
  '<a href="%s" target="_blank"><img src="%s" alt="" /></a>%s',
80
  wp_get_attachment_url( $value ),
classes/fields/class.field-image.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Image
4
- * Version : 1.2.0
5
  * Author : inc2734
6
  * Created : October 7, 2014
7
- * Modified : June 4, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
@@ -55,9 +55,27 @@ class Smart_Custom_Fields_Field_Image extends Smart_Custom_Fields_Field_Base {
55
  $hide_class = 'hide';
56
  $image = $btn_remove;
57
  if ( $value ) {
58
- $image_src = wp_get_attachment_image_src( $value, $this->get( 'size' ) );
59
- if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
60
- $image_src = $image_src[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  $image = sprintf(
62
  '<img src="%s" alt="" />%s',
63
  esc_url( $image_src ),
1
  <?php
2
  /**
3
  * Smart_Custom_Fields_Field_Image
4
+ * Version : 1.3.0
5
  * Author : inc2734
6
  * Created : October 7, 2014
7
+ * Modified : September 6, 2016
8
  * License : GPLv2 or later
9
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  */
55
  $hide_class = 'hide';
56
  $image = $btn_remove;
57
  if ( $value ) {
58
+ // Usually, $value is attachment ID.
59
+ // If a customized, for example, $value is not an ID,
60
+ // Regarded the $value is file URL.
61
+ if ( preg_match( '/^\d+$/', $value ) ) {
62
+ $image_src = wp_get_attachment_image_src( $value, $this->get( 'size' ) );
63
+ if ( is_array( $image_src ) && isset( $image_src[0] ) ) {
64
+ $image_src = $image_src[0];
65
+ }
66
+ } else {
67
+ $image_url = $value;
68
+ $path = str_replace( home_url(), '', $value );
69
+ $image_path = ABSPATH . untrailingslashit( $path );
70
+ if ( file_exists( $image_path ) ) {
71
+ $wp_check_filetype = wp_check_filetype( $image_path );
72
+ if ( ! empty( $wp_check_filetype['type'] ) ) {
73
+ $image_src = $image_url;
74
+ }
75
+ }
76
+ }
77
+
78
+ if ( $image_src && ! is_array( $image_src ) ) {
79
  $image = sprintf(
80
  '<img src="%s" alt="" />%s',
81
  esc_url( $image_src ),
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.6.0
7
- Stable tag: 2.2.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -125,6 +125,9 @@ You can send your own language pack to me.
125
 
126
  == Changelog ==
127
 
 
 
 
128
  = 2.2.3 =
129
  * Fix get_post_metadata hooked only preview #43 (by [@wireframeslayout](https://github.com/wireframeslayout))
130
 
4
  Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
5
  Requires at least: 3.9
6
  Tested up to: 4.6.0
7
+ Stable tag: 2.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
125
 
126
  == Changelog ==
127
 
128
+ = 2.3.0 =
129
+ * Support displayed thumbnail when value of file and image field is file url.
130
+
131
  = 2.2.3 =
132
  * Fix get_post_metadata hooked only preview #43 (by [@wireframeslayout](https://github.com/wireframeslayout))
133
 
smart-custom-fields.php CHANGED
@@ -3,11 +3,11 @@
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
- * Version: 2.2.3
7
  * Author: inc2734
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
- * Modified: August 24, 2016
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2 or later
3
  * Plugin name: Smart Custom Fields
4
  * Plugin URI: https://github.com/inc2734/smart-custom-fields/
5
  * Description: Smart Custom Fields is a simple plugin that management custom fields.
6
+ * Version: 2.3.0
7
  * Author: inc2734
8
  * Author URI: http://2inc.org
9
  * Created: October 9, 2014
10
+ * Modified: September 6, 2016
11
  * Text Domain: smart-custom-fields
12
  * Domain Path: /languages
13
  * License: GPLv2 or later