Version Description
- Improved the performance of the Image field.
Download this release
Release Info
| Developer | christianglingener |
| Plugin | |
| Version | 2.2.12 |
| Comparing to | |
| See all releases | |
Code changes from version 2.2.11 to 2.2.12
- library/toolset/toolset-common/changelog.md +3 -0
- library/toolset/toolset-common/inc/controller/admin/notices.php +0 -18
- library/toolset/toolset-common/loader.php +1 -1
- library/toolset/toolset-common/templates/admin/notice/only-types-installed/layouts-support-available.phtml +0 -44
- library/toolset/toolset-common/toolset-common-loader.php +2 -2
- library/toolset/types/embedded/includes/fields/image.php +288 -5
- readme.txt +5 -2
- wpcf.php +3 -3
library/toolset/toolset-common/changelog.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
# Toolset Common Library
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
## 2.4.1
|
| 4 |
- Removed notices, to push users to activate Layouts theme integration plugins based on the current theme
|
| 5 |
- Added filter to remove/add automatic notices on demand
|
| 1 |
# Toolset Common Library
|
| 2 |
|
| 3 |
+
## 2.4.2
|
| 4 |
+
- Removed notices, which leads to documentation of integration between Layouts and 3rd party themes
|
| 5 |
+
|
| 6 |
## 2.4.1
|
| 7 |
- Removed notices, to push users to activate Layouts theme integration plugins based on the current theme
|
| 8 |
- Added filter to remove/add automatic notices on demand
|
library/toolset/toolset-common/inc/controller/admin/notices.php
CHANGED
|
@@ -205,10 +205,6 @@ class Toolset_Controller_Admin_Notices {
|
|
| 205 |
*/
|
| 206 |
protected function notices_compilation_introduction() {
|
| 207 |
if( $this->only_types_active() ) {
|
| 208 |
-
// notice: theme we have an integration plugin for
|
| 209 |
-
$this->notice_customize_page_with_toolset();
|
| 210 |
-
|
| 211 |
-
// notice: theme we have no integration plugin for
|
| 212 |
$this->notice_how_to_design_with_toolset();
|
| 213 |
|
| 214 |
// notice: theme has native layout support
|
|
@@ -244,19 +240,6 @@ class Toolset_Controller_Admin_Notices {
|
|
| 244 |
return true;
|
| 245 |
}
|
| 246 |
|
| 247 |
-
/**
|
| 248 |
-
* @return Toolset_Admin_Notice_Dismissible
|
| 249 |
-
*/
|
| 250 |
-
protected function notice_customize_page_with_toolset() {
|
| 251 |
-
$notice = new Toolset_Admin_Notice_Dismissible( 'customize-page-with-toolset' );
|
| 252 |
-
$notice->set_content( $this->tpl_path . '/only-types-installed/layouts-support-available.phtml' );
|
| 253 |
-
$notice->add_condition( new Toolset_Condition_Theme_Layouts_Support_Native_Missing() );
|
| 254 |
-
$notice->add_condition( new Toolset_Condition_Theme_Layouts_Support_Plugin_Available() );
|
| 255 |
-
Toolset_Admin_Notices_Manager::add_notice( $notice );
|
| 256 |
-
|
| 257 |
-
return $notice;
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
/**
|
| 261 |
* @return Toolset_Admin_Notice_Dismissible
|
| 262 |
*/
|
|
@@ -264,7 +247,6 @@ class Toolset_Controller_Admin_Notices {
|
|
| 264 |
$notice = new Toolset_Admin_Notice_Dismissible( 'how-to-design-with-toolset' );
|
| 265 |
$notice->set_content( $this->tpl_path . '/only-types-installed/layouts-support-missing.phtml' );
|
| 266 |
$notice->add_condition( new Toolset_Condition_Theme_Layouts_Support_Native_Missing() );
|
| 267 |
-
$notice->add_condition( new Toolset_Condition_Theme_Layouts_Support_Plugin_Missing() );
|
| 268 |
Toolset_Admin_Notices_Manager::add_notice( $notice );
|
| 269 |
|
| 270 |
return $notice;
|
| 205 |
*/
|
| 206 |
protected function notices_compilation_introduction() {
|
| 207 |
if( $this->only_types_active() ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
$this->notice_how_to_design_with_toolset();
|
| 209 |
|
| 210 |
// notice: theme has native layout support
|
| 240 |
return true;
|
| 241 |
}
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
/**
|
| 244 |
* @return Toolset_Admin_Notice_Dismissible
|
| 245 |
*/
|
| 247 |
$notice = new Toolset_Admin_Notice_Dismissible( 'how-to-design-with-toolset' );
|
| 248 |
$notice->set_content( $this->tpl_path . '/only-types-installed/layouts-support-missing.phtml' );
|
| 249 |
$notice->add_condition( new Toolset_Condition_Theme_Layouts_Support_Native_Missing() );
|
|
|
|
| 250 |
Toolset_Admin_Notices_Manager::add_notice( $notice );
|
| 251 |
|
| 252 |
return $notice;
|
library/toolset/toolset-common/loader.php
CHANGED
|
@@ -30,7 +30,7 @@
|
|
| 30 |
* Now that we have a unique version for all plugins
|
| 31 |
* we define the version here
|
| 32 |
*/
|
| 33 |
-
$toolset_common_version =
|
| 34 |
|
| 35 |
|
| 36 |
// ----------------------------------------------------------------------//
|
| 30 |
* Now that we have a unique version for all plugins
|
| 31 |
* we define the version here
|
| 32 |
*/
|
| 33 |
+
$toolset_common_version = 242000;
|
| 34 |
|
| 35 |
|
| 36 |
// ----------------------------------------------------------------------//
|
library/toolset/toolset-common/templates/admin/notice/only-types-installed/layouts-support-available.phtml
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
<?php
|
| 2 |
-
/**
|
| 3 |
-
* Template File
|
| 4 |
-
* This file is only build for classes which implements Toolset_Admin_Notice_Interface
|
| 5 |
-
*
|
| 6 |
-
* @var Toolset_Admin_Notice_Interface $this
|
| 7 |
-
*
|
| 8 |
-
* @since 2.3.0 First release
|
| 9 |
-
*/
|
| 10 |
-
|
| 11 |
-
$condition = new Toolset_Condition_Theme_Layouts_Support_Plugin_Available();
|
| 12 |
-
if( ! $integration_plugin = $condition->get_supported_plugin_integration() ) {
|
| 13 |
-
// shouldn't happen, expect this messages is used without applying the condition to the notice
|
| 14 |
-
return;
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
if( ! array_key_exists( 'theme_name', $integration_plugin )
|
| 18 |
-
|| ! array_key_exists( 'doc_link', $integration_plugin ) ) {
|
| 19 |
-
// missing data
|
| 20 |
-
return;
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
@include( 'layouts-support-missing.phtml' );
|
| 24 |
-
?>
|
| 25 |
-
<p class="toolset-new-subject">
|
| 26 |
-
<?php printf(
|
| 27 |
-
__( 'And, you can easily customize everything in %s ' .
|
| 28 |
-
'using the full Toolset package, without writing PHP.', 'wpv-views' ),
|
| 29 |
-
esc_attr( $integration_plugin['theme_name'] )
|
| 30 |
-
);
|
| 31 |
-
echo '<br />';
|
| 32 |
-
echo Toolset_Admin_Notices_Manager::tpl_link(
|
| 33 |
-
sprintf(
|
| 34 |
-
__( 'Learn about customizing %s with Toolset', 'wpv-views' ),
|
| 35 |
-
esc_attr( $integration_plugin['theme_name'] )
|
| 36 |
-
),
|
| 37 |
-
esc_url( $integration_plugin['doc_link'] ),
|
| 38 |
-
true
|
| 39 |
-
);
|
| 40 |
-
?>
|
| 41 |
-
</p>
|
| 42 |
-
|
| 43 |
-
<?php
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library/toolset/toolset-common/toolset-common-loader.php
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
if( !defined('TOOLSET_VERSION') ){
|
| 4 |
-
define('TOOLSET_VERSION', '2.4.
|
| 5 |
}
|
| 6 |
|
| 7 |
if ( ! defined('TOOLSET_COMMON_VERSION' ) ) {
|
| 8 |
-
define( 'TOOLSET_COMMON_VERSION', '2.4.
|
| 9 |
}
|
| 10 |
|
| 11 |
if ( ! defined('TOOLSET_COMMON_PATH' ) ) {
|
| 1 |
<?php
|
| 2 |
|
| 3 |
if( !defined('TOOLSET_VERSION') ){
|
| 4 |
+
define('TOOLSET_VERSION', '2.4.2');
|
| 5 |
}
|
| 6 |
|
| 7 |
if ( ! defined('TOOLSET_COMMON_VERSION' ) ) {
|
| 8 |
+
define( 'TOOLSET_COMMON_VERSION', '2.4.2' );
|
| 9 |
}
|
| 10 |
|
| 11 |
if ( ! defined('TOOLSET_COMMON_PATH' ) ) {
|
library/toolset/types/embedded/includes/fields/image.php
CHANGED
|
@@ -302,9 +302,13 @@ function wpcf_fields_image_view( $params ) {
|
|
| 302 |
|
| 303 |
// Pre-configured size (use WP function) IF NOT CROPPED
|
| 304 |
if ( $resize == 'crop' && $image_data['is_attachment'] && !empty( $params['size'] ) ) {
|
| 305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
if ( isset( $params['url'] ) && $params['url'] == 'true' ) {
|
| 307 |
-
//print_r('is_url');
|
| 308 |
$image_url = wp_get_attachment_image_src( $image_data['is_attachment'], $params['size'] );
|
| 309 |
if ( !empty( $image_url[0] ) ) {
|
| 310 |
$output = $image_url[0];
|
|
@@ -387,8 +391,9 @@ function wpcf_fields_image_view( $params ) {
|
|
| 387 |
} else {
|
| 388 |
$resized_image = $__resized_image->url;
|
| 389 |
$image_abspath = $__resized_image->path;
|
|
|
|
| 390 |
if ( wpcf_get_settings( 'add_resized_images_to_library' )
|
| 391 |
-
&& !
|
| 392 |
&& $image_data['is_in_upload_path'] ) {
|
| 393 |
global $post;
|
| 394 |
wpcf_image_add_to_library( $post, $image_abspath );
|
|
@@ -404,6 +409,10 @@ function wpcf_fields_image_view( $params ) {
|
|
| 404 |
return $resized_image;
|
| 405 |
}
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
$output = sprintf( '<img alt="%s" ', $output .= $alt !== false ? wpcf_attachment_placeholder( $image_data['is_attachment'], $alt ) : '');
|
| 408 |
if ( $title !== false ) {
|
| 409 |
$output .= sprintf(' title="%s"', wpcf_attachment_placeholder( $image_data['is_attachment'], $title ));
|
|
@@ -1079,6 +1088,263 @@ function wpcf_image_add_to_library( $post, $abspath ){
|
|
| 1079 |
}
|
| 1080 |
}
|
| 1081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1082 |
/**
|
| 1083 |
* Checks if image is attachment.
|
| 1084 |
*
|
|
@@ -1087,13 +1353,30 @@ function wpcf_image_add_to_library( $post, $abspath ){
|
|
| 1087 |
* @return type
|
| 1088 |
*/
|
| 1089 |
function wpcf_image_is_attachment( $guid ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1090 |
global $wpdb;
|
| 1091 |
-
|
| 1092 |
$wpdb->prepare(
|
| 1093 |
-
"SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s",
|
| 1094 |
$guid
|
| 1095 |
)
|
| 1096 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1097 |
}
|
| 1098 |
|
| 1099 |
/**
|
| 302 |
|
| 303 |
// Pre-configured size (use WP function) IF NOT CROPPED
|
| 304 |
if ( $resize == 'crop' && $image_data['is_attachment'] && !empty( $params['size'] ) ) {
|
| 305 |
+
|
| 306 |
+
// for this case we need to get the attachment id
|
| 307 |
+
if( $image_data['is_attachment'] === true ) {
|
| 308 |
+
$image_data['is_attachment'] = wpcf_image_is_attachment( $image_data['fullrelpath'] );
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
if ( isset( $params['url'] ) && $params['url'] == 'true' ) {
|
|
|
|
| 312 |
$image_url = wp_get_attachment_image_src( $image_data['is_attachment'], $params['size'] );
|
| 313 |
if ( !empty( $image_url[0] ) ) {
|
| 314 |
$output = $image_url[0];
|
| 391 |
} else {
|
| 392 |
$resized_image = $__resized_image->url;
|
| 393 |
$image_abspath = $__resized_image->path;
|
| 394 |
+
$id_by_guid = wpcf_image_is_attachment( $__resized_image->url );
|
| 395 |
if ( wpcf_get_settings( 'add_resized_images_to_library' )
|
| 396 |
+
&& ! $id_by_guid
|
| 397 |
&& $image_data['is_in_upload_path'] ) {
|
| 398 |
global $post;
|
| 399 |
wpcf_image_add_to_library( $post, $image_abspath );
|
| 409 |
return $resized_image;
|
| 410 |
}
|
| 411 |
|
| 412 |
+
if( ! isset( $image_data['is_attachment'] ) || $image_data['is_attachment'] == 0 ) {
|
| 413 |
+
$image_data['is_attachment'] = wpcf_image_is_attachment( $resized_image );
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
$output = sprintf( '<img alt="%s" ', $output .= $alt !== false ? wpcf_attachment_placeholder( $image_data['is_attachment'], $alt ) : '');
|
| 417 |
if ( $title !== false ) {
|
| 418 |
$output .= sprintf(' title="%s"', wpcf_attachment_placeholder( $image_data['is_attachment'], $title ));
|
| 1088 |
}
|
| 1089 |
}
|
| 1090 |
|
| 1091 |
+
/**
|
| 1092 |
+
* Class WPCF_Guid_Id
|
| 1093 |
+
*
|
| 1094 |
+
* @since 2.2.12 Temporary solution to speed up image fields
|
| 1095 |
+
*/
|
| 1096 |
+
class WPCF_Guid_Id {
|
| 1097 |
+
/**
|
| 1098 |
+
* @var WPCF_Guid_Id
|
| 1099 |
+
*/
|
| 1100 |
+
private static $instance;
|
| 1101 |
+
|
| 1102 |
+
/**
|
| 1103 |
+
* @var string
|
| 1104 |
+
*/
|
| 1105 |
+
private $table_name = 'toolset_post_guid_id';
|
| 1106 |
+
|
| 1107 |
+
/**
|
| 1108 |
+
* @var wpdb
|
| 1109 |
+
*/
|
| 1110 |
+
private $wpdb;
|
| 1111 |
+
|
| 1112 |
+
/**
|
| 1113 |
+
* @var bool
|
| 1114 |
+
*/
|
| 1115 |
+
private $is_table_available = false;
|
| 1116 |
+
|
| 1117 |
+
/**
|
| 1118 |
+
* Temporary singleton until other parts of image fields are refactored
|
| 1119 |
+
*
|
| 1120 |
+
* @param wpdb $wpdb
|
| 1121 |
+
*/
|
| 1122 |
+
private function __construct( wpdb $wpdb) {
|
| 1123 |
+
$this->wpdb = $wpdb;
|
| 1124 |
+
$this->is_table_available = $this->create_table_if_not_exist();
|
| 1125 |
+
|
| 1126 |
+
if( $this->is_table_available ) {
|
| 1127 |
+
add_action( 'add_attachment', array( $this, 'on_attachment_save' ) );
|
| 1128 |
+
add_action( 'edit_attachment', array( $this, 'on_attachment_save' ) );
|
| 1129 |
+
add_action( 'delete_attachment', array( $this, 'delete_by_post_id' ) );
|
| 1130 |
+
};
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
/**
|
| 1134 |
+
* @return WPCF_Guid_Id
|
| 1135 |
+
*/
|
| 1136 |
+
public static function get_instance() {
|
| 1137 |
+
if( self::$instance === null ) {
|
| 1138 |
+
global $wpdb;
|
| 1139 |
+
|
| 1140 |
+
if( is_object( $wpdb ) ) {
|
| 1141 |
+
self::$instance = new self( $wpdb );
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
return self::$instance;
|
| 1146 |
+
}
|
| 1147 |
+
|
| 1148 |
+
/**
|
| 1149 |
+
* @return string
|
| 1150 |
+
*/
|
| 1151 |
+
public function get_table_name() {
|
| 1152 |
+
return $this->wpdb->prefix . $this->table_name;
|
| 1153 |
+
}
|
| 1154 |
+
|
| 1155 |
+
/**
|
| 1156 |
+
* @param $guid
|
| 1157 |
+
* @param $post_id
|
| 1158 |
+
*
|
| 1159 |
+
* @return bool
|
| 1160 |
+
*/
|
| 1161 |
+
public function insert( $guid, $post_id ) {
|
| 1162 |
+
if( ! $this->is_table_available ) {
|
| 1163 |
+
return false;
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
$table_guid_id = $this->get_table_name();
|
| 1167 |
+
|
| 1168 |
+
$this->wpdb->query(
|
| 1169 |
+
$this->wpdb->prepare(
|
| 1170 |
+
"INSERT INTO $table_guid_id (guid,post_id) VALUES (%s,%d)",
|
| 1171 |
+
$guid, $post_id
|
| 1172 |
+
)
|
| 1173 |
+
);
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
/**
|
| 1177 |
+
* @param $guid
|
| 1178 |
+
* @param $post_id
|
| 1179 |
+
*
|
| 1180 |
+
* @return bool
|
| 1181 |
+
*/
|
| 1182 |
+
public function update( $guid, $post_id ) {
|
| 1183 |
+
if( ! $this->is_table_available ) {
|
| 1184 |
+
return false;
|
| 1185 |
+
}
|
| 1186 |
+
|
| 1187 |
+
$table_guid_id = $this->get_table_name();
|
| 1188 |
+
|
| 1189 |
+
$this->wpdb->query(
|
| 1190 |
+
$this->wpdb->prepare(
|
| 1191 |
+
"UPDATE $table_guid_id SET post_id=%d WHERE guid=%s",
|
| 1192 |
+
$post_id, $guid
|
| 1193 |
+
)
|
| 1194 |
+
);
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
/**
|
| 1198 |
+
* Delete a relationship by passing post id
|
| 1199 |
+
*
|
| 1200 |
+
* @param $post_id
|
| 1201 |
+
*
|
| 1202 |
+
* @return bool
|
| 1203 |
+
*/
|
| 1204 |
+
public function delete_by_post_id( $post_id ) {
|
| 1205 |
+
if( ! $this->is_table_available ) {
|
| 1206 |
+
return false;
|
| 1207 |
+
}
|
| 1208 |
+
|
| 1209 |
+
$table_guid_id = $this->get_table_name();
|
| 1210 |
+
|
| 1211 |
+
$this->wpdb->query(
|
| 1212 |
+
$this->wpdb->prepare(
|
| 1213 |
+
"DELETE FROM $table_guid_id WHERE post_id=%d",
|
| 1214 |
+
$post_id
|
| 1215 |
+
)
|
| 1216 |
+
);
|
| 1217 |
+
}
|
| 1218 |
+
|
| 1219 |
+
/**
|
| 1220 |
+
* Get post_id by guid
|
| 1221 |
+
* @param $guid
|
| 1222 |
+
*
|
| 1223 |
+
* @return null|string
|
| 1224 |
+
*/
|
| 1225 |
+
public function get_id_by_guid( $guid ) {
|
| 1226 |
+
if( ! $this->is_table_available ) {
|
| 1227 |
+
return false;
|
| 1228 |
+
}
|
| 1229 |
+
|
| 1230 |
+
$table_guid_id = $this->get_table_name();
|
| 1231 |
+
|
| 1232 |
+
return $this->wpdb->get_var(
|
| 1233 |
+
$this->wpdb->prepare(
|
| 1234 |
+
"SELECT post_id FROM $table_guid_id WHERE guid=%s LIMIT 1",
|
| 1235 |
+
$guid
|
| 1236 |
+
)
|
| 1237 |
+
);
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
/**
|
| 1241 |
+
* Get guid by post_id
|
| 1242 |
+
* @param $post_id
|
| 1243 |
+
*
|
| 1244 |
+
* @return null|string
|
| 1245 |
+
*/
|
| 1246 |
+
public function get_guid_by_id( $post_id ) {
|
| 1247 |
+
if( ! $this->is_table_available ) {
|
| 1248 |
+
return false;
|
| 1249 |
+
}
|
| 1250 |
+
|
| 1251 |
+
$table_guid_id = $this->get_table_name();
|
| 1252 |
+
|
| 1253 |
+
return $this->wpdb->get_var(
|
| 1254 |
+
$this->wpdb->prepare(
|
| 1255 |
+
"SELECT guid FROM $table_guid_id WHERE post_id=%d LIMIT 1",
|
| 1256 |
+
$post_id
|
| 1257 |
+
)
|
| 1258 |
+
);
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
/**
|
| 1262 |
+
* Hooked to 'post_save'
|
| 1263 |
+
*
|
| 1264 |
+
* @param $post_id
|
| 1265 |
+
*
|
| 1266 |
+
* @return bool|void
|
| 1267 |
+
*/
|
| 1268 |
+
public function on_attachment_save( $post_id ) {
|
| 1269 |
+
if( ! $this->is_table_available ) {
|
| 1270 |
+
return false;
|
| 1271 |
+
}
|
| 1272 |
+
|
| 1273 |
+
if( ! $post = get_post( $post_id ) ) {
|
| 1274 |
+
// no post found
|
| 1275 |
+
return;
|
| 1276 |
+
};
|
| 1277 |
+
|
| 1278 |
+
if( $post->post_type != 'attachment' ) {
|
| 1279 |
+
// only store for attachments
|
| 1280 |
+
return;
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
$post_id = $this->get_id_by_guid( $post->guid );
|
| 1284 |
+
|
| 1285 |
+
if( $post_id && $post_id == $post->ID ) {
|
| 1286 |
+
// already stored with same guid and id
|
| 1287 |
+
return;
|
| 1288 |
+
}
|
| 1289 |
+
|
| 1290 |
+
if( $post_id ) {
|
| 1291 |
+
// entry for guid already exists, but Post->ID has changed (shouldn't really happen, but who knows -> 3rd party plugins)
|
| 1292 |
+
return $this->update( $post->guid, $post->ID );
|
| 1293 |
+
}
|
| 1294 |
+
|
| 1295 |
+
if( $guid = $this->get_guid_by_id( $post->ID ) ) {
|
| 1296 |
+
// there is an entry for the post_id, but guid differs -> update the guid
|
| 1297 |
+
return $this->update( $post->guid, $post->ID );
|
| 1298 |
+
}
|
| 1299 |
+
|
| 1300 |
+
// create entry for guid
|
| 1301 |
+
$this->insert( $post->guid, $post->ID );
|
| 1302 |
+
}
|
| 1303 |
+
|
| 1304 |
+
/**
|
| 1305 |
+
* @return array|void
|
| 1306 |
+
*/
|
| 1307 |
+
private function create_table_if_not_exist() {
|
| 1308 |
+
$table_guid_id = $this->get_table_name();
|
| 1309 |
+
$option_key_table_could_not_be_created = '_types-error-on-create-table-' . $table_guid_id;
|
| 1310 |
+
|
| 1311 |
+
if( $this->wpdb->get_var( "SHOW TABLES LIKE '$table_guid_id'" ) == $table_guid_id) {
|
| 1312 |
+
// table already exists
|
| 1313 |
+
return true;
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
if( get_option( $option_key_table_could_not_be_created, false ) ) {
|
| 1317 |
+
// we already tried to create the table before, but without success
|
| 1318 |
+
return false;
|
| 1319 |
+
}
|
| 1320 |
+
|
| 1321 |
+
$query = "CREATE TABLE {$table_guid_id} (
|
| 1322 |
+
`guid` varchar(190) NOT NULL DEFAULT '',
|
| 1323 |
+
`post_id` bigint(20) NOT NULL,
|
| 1324 |
+
UNIQUE KEY `post_id` (`post_id`),
|
| 1325 |
+
KEY `guid` (`guid`)
|
| 1326 |
+
) " . $this->wpdb->get_charset_collate() . ";";
|
| 1327 |
+
|
| 1328 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
| 1329 |
+
ob_start(); // prevent any error output
|
| 1330 |
+
@dbDelta( $query ); // error on dbDelta not catchable
|
| 1331 |
+
ob_end_clean();
|
| 1332 |
+
|
| 1333 |
+
if( $this->wpdb->get_var( "SHOW TABLES LIKE '$table_guid_id'" ) == $table_guid_id) {
|
| 1334 |
+
// table successfully created
|
| 1335 |
+
return true;
|
| 1336 |
+
}
|
| 1337 |
+
|
| 1338 |
+
// for some reason the table could not be created - save result
|
| 1339 |
+
update_option( $option_key_table_could_not_be_created, '1' );
|
| 1340 |
+
|
| 1341 |
+
return false;
|
| 1342 |
+
}
|
| 1343 |
+
}
|
| 1344 |
+
|
| 1345 |
+
// make sure hooks are loaded
|
| 1346 |
+
WPCF_Guid_Id::get_instance();
|
| 1347 |
+
|
| 1348 |
/**
|
| 1349 |
* Checks if image is attachment.
|
| 1350 |
*
|
| 1353 |
* @return type
|
| 1354 |
*/
|
| 1355 |
function wpcf_image_is_attachment( $guid ) {
|
| 1356 |
+
$wpcf_guid_id = WPCF_Guid_Id::get_instance();
|
| 1357 |
+
|
| 1358 |
+
// fetch id by using our toolset_post_guid_id table
|
| 1359 |
+
if( $post_id = $wpcf_guid_id->get_id_by_guid( $guid ) ) {
|
| 1360 |
+
return $post_id;
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
+
// fetching id by using the wp_post table
|
| 1364 |
global $wpdb;
|
| 1365 |
+
$post_id = $wpdb->get_var(
|
| 1366 |
$wpdb->prepare(
|
| 1367 |
+
"SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s LIMIT 1",
|
| 1368 |
$guid
|
| 1369 |
)
|
| 1370 |
);
|
| 1371 |
+
|
| 1372 |
+
if( ! $post_id ) {
|
| 1373 |
+
return null;
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
// store guid->id to our toolset_post_guid_id table
|
| 1377 |
+
$wpcf_guid_id->insert( $guid, $post_id );
|
| 1378 |
+
|
| 1379 |
+
return $post_id;
|
| 1380 |
}
|
| 1381 |
|
| 1382 |
/**
|
readme.txt
CHANGED
|
@@ -6,8 +6,8 @@ Text Domain: wpcf
|
|
| 6 |
Domain Path: /embedded/locale
|
| 7 |
License: GPLv2
|
| 8 |
Requires at least: 3.7
|
| 9 |
-
Tested up to: 4.
|
| 10 |
-
Stable tag: 2.2.
|
| 11 |
|
| 12 |
The complete and reliable plugin for managing custom post types, custom taxonomies and custom fields.
|
| 13 |
|
|
@@ -158,6 +158,9 @@ Additionally, Types is the only plugin that lets you define parent/child relatio
|
|
| 158 |
|
| 159 |
== Changelog ==
|
| 160 |
|
|
|
|
|
|
|
|
|
|
| 161 |
= 2.2.11 =
|
| 162 |
* Removed notices, to push users to activate Layouts theme integration plugins based on the current theme
|
| 163 |
* Added filter to remove/add automatic notices on demand
|
| 6 |
Domain Path: /embedded/locale
|
| 7 |
License: GPLv2
|
| 8 |
Requires at least: 3.7
|
| 9 |
+
Tested up to: 4.8
|
| 10 |
+
Stable tag: 2.2.12
|
| 11 |
|
| 12 |
The complete and reliable plugin for managing custom post types, custom taxonomies and custom fields.
|
| 13 |
|
| 158 |
|
| 159 |
== Changelog ==
|
| 160 |
|
| 161 |
+
= 2.2.12 =
|
| 162 |
+
* Improved the performance of the Image field.
|
| 163 |
+
|
| 164 |
= 2.2.11 =
|
| 165 |
* Removed notices, to push users to activate Layouts theme integration plugins based on the current theme
|
| 166 |
* Added filter to remove/add automatic notices on demand
|
wpcf.php
CHANGED
|
@@ -5,7 +5,7 @@ Plugin URI: http://wordpress.org/extend/plugins/types/
|
|
| 5 |
Description: Toolset Types defines custom content in WordPress. Easily create custom post types, fields and taxonomy and connect everything together.
|
| 6 |
Author: OnTheGoSystems
|
| 7 |
Author URI: http://www.onthegosystems.com
|
| 8 |
-
Version: 2.2.
|
| 9 |
License: GPLv2 or later
|
| 10 |
|
| 11 |
Types is free software: you can redistribute it and/or modify
|
|
@@ -28,7 +28,7 @@ if( !function_exists( 'add_action' ) )
|
|
| 28 |
|
| 29 |
// version
|
| 30 |
if( ! defined( 'TYPES_VERSION' ) )
|
| 31 |
-
define( 'TYPES_VERSION', '2.2.
|
| 32 |
|
| 33 |
// backward compatibility
|
| 34 |
if ( ! defined( 'WPCF_VERSION' ) )
|
|
@@ -37,7 +37,7 @@ if ( ! defined( 'WPCF_VERSION' ) )
|
|
| 37 |
// release notes
|
| 38 |
if( ! defined( 'TYPES_RELEASE_NOTES' ) )
|
| 39 |
// Mind the end of the URL string, it contains the plugin version.
|
| 40 |
-
define( 'TYPES_RELEASE_NOTES', 'https://wp-types.com/version/types-2-2-
|
| 41 |
|
| 42 |
/*
|
| 43 |
* Path Constants
|
| 5 |
Description: Toolset Types defines custom content in WordPress. Easily create custom post types, fields and taxonomy and connect everything together.
|
| 6 |
Author: OnTheGoSystems
|
| 7 |
Author URI: http://www.onthegosystems.com
|
| 8 |
+
Version: 2.2.12
|
| 9 |
License: GPLv2 or later
|
| 10 |
|
| 11 |
Types is free software: you can redistribute it and/or modify
|
| 28 |
|
| 29 |
// version
|
| 30 |
if( ! defined( 'TYPES_VERSION' ) )
|
| 31 |
+
define( 'TYPES_VERSION', '2.2.12' );
|
| 32 |
|
| 33 |
// backward compatibility
|
| 34 |
if ( ! defined( 'WPCF_VERSION' ) )
|
| 37 |
// release notes
|
| 38 |
if( ! defined( 'TYPES_RELEASE_NOTES' ) )
|
| 39 |
// Mind the end of the URL string, it contains the plugin version.
|
| 40 |
+
define( 'TYPES_RELEASE_NOTES', 'https://wp-types.com/version/types-2-2-12/?utm_source=typesplugin&utm_campaign=types&utm_medium=release-notes-admin-notice&utm_term=Types%202.2.12%20release%20notes' );
|
| 41 |
|
| 42 |
/*
|
| 43 |
* Path Constants
|
