Featured Image From URL - Version 2.5.1

Version Description

  • New feature: save image dimensions.
Download this release

Release Info

Developer marceljm
Plugin Icon 128x128 Featured Image From URL
Version 2.5.1
Comparing to
See all releases

Code changes from version 2.5.0 to 2.5.1

admin/api.php CHANGED
@@ -21,6 +21,15 @@ function fifu_data_clean_api(WP_REST_Request $request) {
21
  update_option('fifu_data_generation', 'toggleoff', 'no');
22
  }
23
 
 
 
 
 
 
 
 
 
 
24
  function fifu_test_execution_time() {
25
  for ($i = 0; $i <= 120; $i++) {
26
  error_log($i);
@@ -45,5 +54,9 @@ add_action('rest_api_init', function () {
45
  'methods' => 'POST',
46
  'callback' => 'fifu_data_clean_api'
47
  ));
 
 
 
 
48
  });
49
 
21
  update_option('fifu_data_generation', 'toggleoff', 'no');
22
  }
23
 
24
+ function fifu_save_dimensions_all_api(WP_REST_Request $request) {
25
+ update_option('fifu_save_dimensions_all', 'toggleoff', 'no');
26
+
27
+ if (fifu_is_off('fifu_save_dimensions'))
28
+ return;
29
+
30
+ fifu_db_save_dimensions_all();
31
+ }
32
+
33
  function fifu_test_execution_time() {
34
  for ($i = 0; $i <= 120; $i++) {
35
  error_log($i);
54
  'methods' => 'POST',
55
  'callback' => 'fifu_data_clean_api'
56
  ));
57
+ register_rest_route('featured-image-from-url/v2', '/save_dimensions_all_api/', array(
58
+ 'methods' => 'POST',
59
+ 'callback' => 'fifu_save_dimensions_all_api'
60
+ ));
61
  });
62
 
admin/db.php CHANGED
@@ -189,6 +189,29 @@ class FifuDb {
189
  );
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  // get attachments without post
193
  function get_attachments_without_post($post_id) {
194
  $result = $this->wpdb->get_results("
@@ -447,6 +470,18 @@ class FifuDb {
447
  return "(" . $this->author . ", '" . $url . "', '" . str_replace("'", "", $alt) . "', 'image/jpeg', 'attachment', 'inherit', '" . $post_parent . "', now(), now(), now(), now(), '', '', '', '', '')";
448
  }
449
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  /* insert fake internal featured image */
451
 
452
  function insert_attachment_category() {
@@ -558,6 +593,46 @@ class FifuDb {
558
  $this->delete_empty_urls_category();
559
  }
560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
  /* save 1 post */
562
 
563
  function update_fake_attach_id($post_id) {
@@ -771,6 +846,13 @@ function fifu_db_change_url_length() {
771
  $db->change_url_length();
772
  }
773
 
 
 
 
 
 
 
 
774
  /* clean metadata */
775
 
776
  function fifu_db_enable_clean() {
189
  );
190
  }
191
 
192
+ // get posts without dimensions
193
+ function get_posts_without_dimensions() {
194
+ return $this->wpdb->get_results("
195
+ SELECT *
196
+ FROM " . $this->posts . " p
197
+ WHERE p.post_type IN ('$this->types')
198
+ AND post_status NOT IN ('auto-draft', 'trash')
199
+ AND EXISTS (
200
+ SELECT 1
201
+ FROM " . $this->postmeta . " pm
202
+ WHERE p.id = pm.post_id
203
+ AND pm.meta_key IN ('fifu_image_url')
204
+ )
205
+ AND NOT EXISTS (
206
+ SELECT 1
207
+ FROM " . $this->postmeta . " pm2
208
+ WHERE p.id = pm2.post_id
209
+ AND pm2.meta_key IN ('fifu_image_dimension')
210
+ )
211
+ ORDER BY p.ID"
212
+ );
213
+ }
214
+
215
  // get attachments without post
216
  function get_attachments_without_post($post_id) {
217
  $result = $this->wpdb->get_results("
470
  return "(" . $this->author . ", '" . $url . "', '" . str_replace("'", "", $alt) . "', 'image/jpeg', 'attachment', 'inherit', '" . $post_parent . "', now(), now(), now(), now(), '', '', '', '', '')";
471
  }
472
 
473
+ /* insert dimension */
474
+
475
+ function insert_dimension_by($value) {
476
+ $this->wpdb->get_results("
477
+ INSERT INTO " . $this->postmeta . " (post_id, meta_key, meta_value)
478
+ VALUES " . $value);
479
+ }
480
+
481
+ function get_formatted_dimension_value($post_id, $dimension) {
482
+ return "(" . $post_id . ", 'fifu_image_dimension', '" . $dimension . "')";
483
+ }
484
+
485
  /* insert fake internal featured image */
486
 
487
  function insert_attachment_category() {
593
  $this->delete_empty_urls_category();
594
  }
595
 
596
+ /* dimensions: save all */
597
+
598
+ function save_dimensions_all() {
599
+ $value = null;
600
+ $i = 1;
601
+ $count = 1;
602
+ // get all posts or all posts without dimensions
603
+ $result = $this->get_posts_without_dimensions();
604
+ foreach ($result as $res) {
605
+ $post_id = $res->ID;
606
+
607
+ // set featured image
608
+ $url = fifu_main_image_url($post_id);
609
+
610
+ if (!$url) {
611
+ $count++;
612
+ continue;
613
+ }
614
+
615
+ // get dimensions
616
+ $dimension = fifu_get_dimension_backend($url);
617
+
618
+ if (!$dimension) {
619
+ $count++;
620
+ continue;
621
+ }
622
+
623
+ $aux = $this->get_formatted_dimension_value($post_id, $dimension);
624
+ $value = ($i == 1) ? $aux : ($value . "," . $aux);
625
+ if ($value && (($i % $this->MAX_INSERT == 0) || ($i % $this->MAX_INSERT != 0 && count($result) == $count))) {
626
+ wp_cache_flush();
627
+ $this->insert_dimension_by($value);
628
+ $value = null;
629
+ $i = 1;
630
+ } else
631
+ $i++;
632
+ $count++;
633
+ }
634
+ }
635
+
636
  /* save 1 post */
637
 
638
  function update_fake_attach_id($post_id) {
846
  $db->change_url_length();
847
  }
848
 
849
+ /* dimensions: save all */
850
+
851
+ function fifu_db_save_dimensions_all() {
852
+ $db = new FifuDb();
853
+ return $db->save_dimensions_all();
854
+ }
855
+
856
  /* clean metadata */
857
 
858
  function fifu_db_enable_clean() {
admin/html/js/menu.js CHANGED
@@ -131,3 +131,27 @@ function fifu_clean_js() {
131
  }
132
  });
133
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
  });
133
  }
134
+
135
+ function fifu_save_dimensions_all_js() {
136
+ if (jQuery("#fifu_toggle_save_dimensions_all").attr('class') != 'toggleon')
137
+ return;
138
+
139
+ jQuery('.wrap').block({message: 'Please wait. It can take several minutes...', css: {backgroundColor: 'none', border: 'none', color: 'white'}});
140
+
141
+ jQuery.ajax({
142
+ method: "POST",
143
+ url: homeUrl() + '?rest_route=/featured-image-from-url/v2/save_dimensions_all_api/',
144
+ async: true,
145
+ success: function (data) {
146
+ },
147
+ error: function (jqXHR, textStatus, errorThrown) {
148
+ console.log(jqXHR);
149
+ console.log(textStatus);
150
+ console.log(errorThrown);
151
+ },
152
+ complete: function () {
153
+ jQuery("#fifu_toggle_save_dimensions_all").attr('class', 'toggleoff');
154
+ jQuery('.wrap').unblock();
155
+ }
156
+ });
157
+ }
admin/html/js/meta-box.js CHANGED
@@ -22,8 +22,6 @@ function previewImage() {
22
  jQuery("#fifu_input_alt").show();
23
  jQuery("#fifu_image").show();
24
  jQuery("#fifu_link").show();
25
-
26
- //getMeta($url);
27
  }
28
  }
29
 
22
  jQuery("#fifu_input_alt").show();
23
  jQuery("#fifu_image").show();
24
  jQuery("#fifu_link").show();
 
 
25
  }
26
  }
27
 
admin/html/menu.html CHANGED
@@ -939,7 +939,76 @@
939
  <input type="submit" value="Submit" >
940
  </form>
941
  </div>
942
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
 
944
  <div class="box">
945
  <h2>Priority</h2>
@@ -2558,6 +2627,8 @@ fifu_original:<?php echo $enable_original ?>;
2558
  fifu_ovw_first:<?php echo $enable_ovw_first ?>;
2559
  fifu_pop_first:<?php echo $enable_pop_first ?>;
2560
  fifu_priority:<?php echo $enable_priority ?>;
 
 
2561
  fifu_social:<?php echo $enable_social ?>;
2562
  fifu_wc_lbox:<?php echo $enable_wc_lbox ?>;
2563
  fifu_wc_zoom:<?php echo $enable_wc_zoom ?>;
939
  <input type="submit" value="Submit" >
940
  </form>
941
  </div>
942
+ </div>
943
+
944
+ <div class="box">
945
+
946
+ <h2>Save Image Dimensions</h2>
947
+
948
+ <div class="greybox">
949
+ Enable that to save the image dimensions. A few themes may need the image width and height to avoid style issues.
950
+ </div>
951
+
952
+ <br>
953
+
954
+ <table style="text-align:left">
955
+ <tr>
956
+ <th>
957
+ <form
958
+ id="fifu_form_save_dimensions"
959
+ action="javascript:void(0)"
960
+ method="post">
961
+ <input
962
+ type="image"
963
+ href="javascript:void(0)"
964
+ id="fifu_toggle_save_dimensions"
965
+ onclick="invert('save_dimensions')"
966
+ name="fifu_toggle_save_dimensions"
967
+ class="<?php echo $enable_save_dimensions; ?>"
968
+ value=""
969
+ style="display:block">
970
+
971
+ <input
972
+ type="hidden"
973
+ id="fifu_input_save_dimensions"
974
+ name="fifu_input_save_dimensions"
975
+ value="" >
976
+ </form>
977
+ </th>
978
+ <th>
979
+ save image dimensions (makes posts updates slower)
980
+ </th>
981
+ </tr>
982
+ <tr>
983
+ <th>
984
+ <form
985
+ id="fifu_form_save_dimensions_all"
986
+ action="javascript:void(0)"
987
+ method="post">
988
+ <input
989
+ type="image"
990
+ href="javascript:void(0)"
991
+ id="fifu_toggle_save_dimensions_all"
992
+ onclick="invert('save_dimensions_all');fifu_save_dimensions_all_js();"
993
+ name="fifu_toggle_save_dimensions_all"
994
+ class="<?php echo $enable_save_dimensions_all; ?>"
995
+ value=""
996
+ style="display:block">
997
+
998
+ <input
999
+ type="hidden"
1000
+ id="fifu_input_save_dimensions_all"
1001
+ name="fifu_input_save_dimensions_all"
1002
+ value="" >
1003
+ </form>
1004
+ </th>
1005
+ <th>
1006
+ save the image dimensions of all external featured images now (it shoud take 1-5 seconds by image and requires php-curl installed)
1007
+ </th>
1008
+ </tr>
1009
+ </table>
1010
+
1011
+ </div>
1012
 
1013
  <div class="box">
1014
  <h2>Priority</h2>
2627
  fifu_ovw_first:<?php echo $enable_ovw_first ?>;
2628
  fifu_pop_first:<?php echo $enable_pop_first ?>;
2629
  fifu_priority:<?php echo $enable_priority ?>;
2630
+ fifu_save_dimensions:<?php echo $enable_save_dimensions ?>;
2631
+ fifu_save_dimensions_all:<?php echo $enable_save_dimensions_all ?>;
2632
  fifu_social:<?php echo $enable_social ?>;
2633
  fifu_wc_lbox:<?php echo $enable_wc_lbox ?>;
2634
  fifu_wc_zoom:<?php echo $enable_wc_zoom ?>;
admin/html/meta-box.html CHANGED
@@ -55,6 +55,6 @@
55
  background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">Please report any problem to <b>marcel@featuredimagefromurl.com</b></p>
56
  <p style="font-size: 12px; padding: 10px; border-bottom: 2px solid #00b0ff; border-top: 2px solid #00b0ff; color: black; background: repeating-linear-gradient(-55deg,white,white 2px,whitesmoke 2px,white 5px);
57
  background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">Product Gallery, Video and Slider fields are only available in <a href="wp-admin/admin.php?page=featured-image-from-url#tabs-a"><b>premium</b></a> version.</p>
58
- <p style="font-size: 12px; padding: 10px; border-bottom: 2px solid blue; border-top: 2px solid blue; color: black; background: repeating-linear-gradient(-55deg,white,white 2px,whitesmoke 2px,white 5px);
59
- background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">New feature: auto set first video.</p>
60
  </div>
55
  background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">Please report any problem to <b>marcel@featuredimagefromurl.com</b></p>
56
  <p style="font-size: 12px; padding: 10px; border-bottom: 2px solid #00b0ff; border-top: 2px solid #00b0ff; color: black; background: repeating-linear-gradient(-55deg,white,white 2px,whitesmoke 2px,white 5px);
57
  background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">Product Gallery, Video and Slider fields are only available in <a href="wp-admin/admin.php?page=featured-image-from-url#tabs-a"><b>premium</b></a> version.</p>
58
+ <p style="font-size: 12px; padding: 10px; border-bottom: 2px solid orange; border-top: 2px solid orange; color: black; background: repeating-linear-gradient(-55deg,white,white 2px,whitesmoke 2px,white 5px);
59
+ background-color: whitesmoke; border-radius: 15px 5px 15px 5px; position: relative; top: 5px;">New feature: save image dimensions.</p>
60
  </div>
admin/menu.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- define('FIFU_SETTINGS', serialize(array('fifu_social', 'fifu_original', 'fifu_lazy', 'fifu_content', 'fifu_content_page', 'fifu_enable_default_url', 'fifu_fake', 'fifu_fake2', 'fifu_css', 'fifu_default_url', 'fifu_wc_lbox', 'fifu_wc_zoom', 'fifu_hide_page', 'fifu_hide_post', 'fifu_get_first', 'fifu_pop_first', 'fifu_ovw_first', 'fifu_column_height', 'fifu_priority', 'fifu_grid_category', 'fifu_auto_alt', 'fifu_data_generation', 'fifu_data_clean', 'fifu_image_height_shop', 'fifu_image_width_shop', 'fifu_image_height_prod', 'fifu_image_width_prod', 'fifu_image_height_cart', 'fifu_image_width_cart', 'fifu_image_height_ctgr', 'fifu_image_width_ctgr', 'fifu_image_height_arch', 'fifu_image_width_arch', 'fifu_image_height_home', 'fifu_image_width_home', 'fifu_image_height_page', 'fifu_image_width_page', 'fifu_image_height_post', 'fifu_image_width_post')));
4
 
5
  add_action('admin_menu', 'fifu_insert_menu');
6
 
@@ -64,6 +64,8 @@ function fifu_get_menu_html() {
64
  $max_image_width_page = get_option('fifu_image_width_page');
65
  $max_image_height_post = get_option('fifu_image_height_post');
66
  $max_image_width_post = get_option('fifu_image_width_post');
 
 
67
 
68
  include 'html/menu.html';
69
 
@@ -158,6 +160,8 @@ function fifu_update_menu_options() {
158
  fifu_update_option('fifu_input_image_width_page', 'fifu_image_width_page');
159
  fifu_update_option('fifu_input_image_height_post', 'fifu_image_height_post');
160
  fifu_update_option('fifu_input_image_width_post', 'fifu_image_width_post');
 
 
161
  }
162
 
163
  function fifu_update_option($input, $type) {
1
  <?php
2
 
3
+ define('FIFU_SETTINGS', serialize(array('fifu_social', 'fifu_original', 'fifu_lazy', 'fifu_content', 'fifu_content_page', 'fifu_enable_default_url', 'fifu_fake', 'fifu_fake2', 'fifu_css', 'fifu_default_url', 'fifu_wc_lbox', 'fifu_wc_zoom', 'fifu_hide_page', 'fifu_hide_post', 'fifu_get_first', 'fifu_pop_first', 'fifu_ovw_first', 'fifu_column_height', 'fifu_priority', 'fifu_grid_category', 'fifu_auto_alt', 'fifu_data_generation', 'fifu_data_clean', 'fifu_image_height_shop', 'fifu_image_width_shop', 'fifu_image_height_prod', 'fifu_image_width_prod', 'fifu_image_height_cart', 'fifu_image_width_cart', 'fifu_image_height_ctgr', 'fifu_image_width_ctgr', 'fifu_image_height_arch', 'fifu_image_width_arch', 'fifu_image_height_home', 'fifu_image_width_home', 'fifu_image_height_page', 'fifu_image_width_page', 'fifu_image_height_post', 'fifu_image_width_post', 'fifu_save_dimensions', 'fifu_save_dimensions_all')));
4
 
5
  add_action('admin_menu', 'fifu_insert_menu');
6
 
64
  $max_image_width_page = get_option('fifu_image_width_page');
65
  $max_image_height_post = get_option('fifu_image_height_post');
66
  $max_image_width_post = get_option('fifu_image_width_post');
67
+ $enable_save_dimensions = get_option('fifu_save_dimensions');
68
+ $enable_save_dimensions_all = get_option('fifu_save_dimensions_all');
69
 
70
  include 'html/menu.html';
71
 
160
  fifu_update_option('fifu_input_image_width_page', 'fifu_image_width_page');
161
  fifu_update_option('fifu_input_image_height_post', 'fifu_image_height_post');
162
  fifu_update_option('fifu_input_image_width_post', 'fifu_image_width_post');
163
+ fifu_update_option('fifu_input_save_dimensions', 'fifu_save_dimensions');
164
+ fifu_update_option('fifu_input_save_dimensions_all', 'fifu_save_dimensions_all');
165
  }
166
 
167
  function fifu_update_option($input, $type) {
admin/meta-box.php CHANGED
@@ -67,11 +67,6 @@ function fifu_save_properties($post_id) {
67
  if (!$_POST || get_post_type($post_id) == 'nav_menu_item')
68
  return;
69
 
70
- //if (isset($_POST['fifu_input_image_width']))
71
- //$width = $_POST['fifu_input_image_width'];
72
- //if (isset($_POST['fifu_input_image_height']))
73
- //$height = $_POST['fifu_input_image_height'];
74
-
75
  /* image url */
76
  if (isset($_POST['fifu_input_url'])) {
77
  $url = esc_url_raw($_POST['fifu_input_url']);
@@ -79,13 +74,15 @@ function fifu_save_properties($post_id) {
79
  if ($first && fifu_is_on('fifu_get_first') && (!$url || fifu_is_on('fifu_ovw_first')))
80
  $url = $first;
81
  fifu_update_or_delete($post_id, 'fifu_image_url', $url);
 
 
82
  }
83
 
84
  /* alt */
85
  if (isset($_POST['fifu_input_alt'])) {
86
  $alt = wp_strip_all_tags($_POST['fifu_input_alt']);
87
  $alt = !$alt && $url && fifu_is_on('fifu_auto_alt') ? get_the_title() : $alt;
88
- fifu_update_or_delete_alt($post_id, 'fifu_image_alt', $alt);
89
  }
90
 
91
  fifu_save($post_id);
@@ -102,7 +99,7 @@ function fifu_update_or_delete($post_id, $field, $url) {
102
  delete_post_meta($post_id, $field, $url);
103
  }
104
 
105
- function fifu_update_or_delete_alt($post_id, $field, $value) {
106
  if ($value)
107
  update_post_meta($post_id, $field, $value);
108
  else
@@ -117,6 +114,16 @@ function fifu_wai_save($post_id) {
117
  fifu_save($post_id);
118
  }
119
 
 
 
 
 
 
 
 
 
 
 
120
  add_action('before_delete_post', 'fifu_db_before_delete_post');
121
 
122
  /* regular woocommerce import */
67
  if (!$_POST || get_post_type($post_id) == 'nav_menu_item')
68
  return;
69
 
 
 
 
 
 
70
  /* image url */
71
  if (isset($_POST['fifu_input_url'])) {
72
  $url = esc_url_raw($_POST['fifu_input_url']);
74
  if ($first && fifu_is_on('fifu_get_first') && (!$url || fifu_is_on('fifu_ovw_first')))
75
  $url = $first;
76
  fifu_update_or_delete($post_id, 'fifu_image_url', $url);
77
+ if (fifu_is_on('fifu_save_dimensions'))
78
+ fifu_save_dimensions($post_id, $url);
79
  }
80
 
81
  /* alt */
82
  if (isset($_POST['fifu_input_alt'])) {
83
  $alt = wp_strip_all_tags($_POST['fifu_input_alt']);
84
  $alt = !$alt && $url && fifu_is_on('fifu_auto_alt') ? get_the_title() : $alt;
85
+ fifu_update_or_delete_value($post_id, 'fifu_image_alt', $alt);
86
  }
87
 
88
  fifu_save($post_id);
99
  delete_post_meta($post_id, $field, $url);
100
  }
101
 
102
+ function fifu_update_or_delete_value($post_id, $field, $value) {
103
  if ($value)
104
  update_post_meta($post_id, $field, $value);
105
  else
114
  fifu_save($post_id);
115
  }
116
 
117
+ function fifu_save_dimensions($post_id, $url) {
118
+ $size = getimagesize($url);
119
+ if ($size) {
120
+ $width = $size[0];
121
+ $height = $size[1];
122
+ if ($width && $height)
123
+ fifu_update_or_delete_value($post_id, 'fifu_image_dimension', $width . ';' . $height);
124
+ }
125
+ }
126
+
127
  add_action('before_delete_post', 'fifu_db_before_delete_post');
128
 
129
  /* regular woocommerce import */
featured-image-from-url.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Featured Image from URL
5
  * Plugin URI: https://featuredimagefromurl.com/
6
  * Description: Use an external image as Featured Image of your post/page/custom post type (WooCommerce). Includes Auto Set (External Post), Product Gallery, Social Tags and more.
7
- * Version: 2.5.0
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
4
  * Plugin Name: Featured Image from URL
5
  * Plugin URI: https://featuredimagefromurl.com/
6
  * Description: Use an external image as Featured Image of your post/page/custom post type (WooCommerce). Includes Auto Set (External Post), Product Gallery, Social Tags and more.
7
+ * Version: 2.5.1
8
  * Author: Marcel Jacques Machado
9
  * Author URI: https://www.linkedin.com/in/marceljm/
10
  */
includes/attachment.php CHANGED
@@ -77,12 +77,22 @@ function fifu_replace_attachment_image_src($image, $att_id, $size) {
77
  null,
78
  );
79
  }
80
- $width = fifu_maximum('width');
81
- $height = fifu_maximum('height');
 
 
 
 
 
 
 
 
 
 
82
  return array(
83
  strpos($image[0], fifu_get_internal_image_path()) !== false ? get_post($att_id)->guid : $image[0],
84
- isset($image_size['width']) && $image_size['width'] < $width ? $image_size['width'] : $width,
85
- isset($image_size['height']) && $image_size['height'] < $height ? $image_size['height'] : $height,
86
  isset($image_size['crop']) ? $image_size['crop'] : '',
87
  );
88
  }
77
  null,
78
  );
79
  }
80
+
81
+ $dimension = get_post_meta($post->post_parent, 'fifu_image_dimension');
82
+ if ($dimension) {
83
+ $dimension = $dimension[0];
84
+ $width = explode(';', $dimension)[0];
85
+ $height = explode(';', $dimension)[1];
86
+ } else {
87
+ $dimension = null;
88
+ $width = fifu_maximum('width');
89
+ $height = fifu_maximum('height');
90
+ }
91
+
92
  return array(
93
  strpos($image[0], fifu_get_internal_image_path()) !== false ? get_post($att_id)->guid : $image[0],
94
+ !$dimension && isset($image_size['width']) && $image_size['width'] < $width ? $image_size['width'] : $width,
95
+ !$dimension && isset($image_size['height']) && $image_size['height'] < $height ? $image_size['height'] : $height,
96
  isset($image_size['crop']) ? $image_size['crop'] : '',
97
  );
98
  }
includes/util.php CHANGED
@@ -56,3 +56,21 @@ function fifu_maximum($dimension) {
56
  return $size ? $size : '1024';
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  return $size ? $size : '1024';
57
  }
58
 
59
+ /* dimensions */
60
+
61
+ function fifu_curl($url) {
62
+ $curl = curl_init($url);
63
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
64
+ $data = curl_exec($curl);
65
+ curl_close($curl);
66
+ return $data;
67
+ }
68
+
69
+ function fifu_get_dimension_backend($url) {
70
+ $raw = fifu_curl($url);
71
+ $img = imagecreatefromstring($raw);
72
+ $width = imagesx($img);
73
+ $height = imagesy($img);
74
+ return $width . ";" . $height;
75
+ }
76
+
readme.txt CHANGED
@@ -159,6 +159,9 @@ Features:
159
 
160
  == Changelog ==
161
 
 
 
 
162
  = 2.5.0 =
163
  * New premium feature: auto set first video; Bug fix: conflict with Enhanced Media Library plugin.
164
 
@@ -579,6 +582,9 @@ was removed. To finish, a Premium version is now been presented.
579
 
580
  == Upgrade Notice ==
581
 
 
 
 
582
  = 2.5.0 =
583
  * New premium feature: auto set first video; Bug fix: conflict with Enhanced Media Library plugin.
584
 
159
 
160
  == Changelog ==
161
 
162
+ = 2.5.1 =
163
+ * New feature: save image dimensions.
164
+
165
  = 2.5.0 =
166
  * New premium feature: auto set first video; Bug fix: conflict with Enhanced Media Library plugin.
167
 
582
 
583
  == Upgrade Notice ==
584
 
585
+ = 2.5.1 =
586
+ * New feature: save image dimensions.
587
+
588
  = 2.5.0 =
589
  * New premium feature: auto set first video; Bug fix: conflict with Enhanced Media Library plugin.
590