@@ -2,25 +2,25 @@ discard block |
||
| 2 | 2 | class WPS_EAV_Revisions { |
| 3 | 3 | public static $created_revisions = array(); |
| 4 | 4 | public function __construct() { |
| 5 | - add_action( 'save_post', array( $this, 'save_post' ), 100, 2 ); |
|
| 6 | - add_action( 'wp_restore_post_revision', array( $this, 'wp_restore_post_revision' ), 10, 2 ); |
|
| 7 | - add_filter( '_wp_post_revision_fields', array( $this, 'wp_post_revision_fields' ), 10, 2 ); |
|
| 5 | + add_action('save_post', array($this, 'save_post'), 100, 2); |
|
| 6 | + add_action('wp_restore_post_revision', array($this, 'wp_restore_post_revision'), 10, 2); |
|
| 7 | + add_filter('_wp_post_revision_fields', array($this, 'wp_post_revision_fields'), 10, 2); |
|
| 8 | 8 | } |
| 9 | - public function save_post( $post_id, $post ) { |
|
| 10 | - if ( false === wp_is_post_revision( $post_id ) ) { |
|
| 11 | - if ( ( ! isset( self::$created_revisions[ $post_id ] ) || true !== self::$created_revisions[ $post_id ] ) && post_type_supports( $post->post_type, 'revisions' ) ) { |
|
| 12 | - self::$created_revisions[ wp_is_post_revision( $post_id ) ] = true; |
|
| 13 | - add_filter( 'wp_save_post_revision_post_has_changed', array( $this, 'wp_save_post_revision_post_has_changed' ), 10, 3 ); |
|
| 14 | - wp_save_post_revision( $post_id ); |
|
| 9 | + public function save_post($post_id, $post) { |
|
| 10 | + if (false === wp_is_post_revision($post_id)) { |
|
| 11 | + if ((!isset(self::$created_revisions[$post_id]) || true !== self::$created_revisions[$post_id]) && post_type_supports($post->post_type, 'revisions')) { |
|
| 12 | + self::$created_revisions[wp_is_post_revision($post_id)] = true; |
|
| 13 | + add_filter('wp_save_post_revision_post_has_changed', array($this, 'wp_save_post_revision_post_has_changed'), 10, 3); |
|
| 14 | + wp_save_post_revision($post_id); |
|
| 15 | 15 | } |
| 16 | 16 | } else { |
| 17 | - self::$created_revisions[ wp_is_post_revision( $post_id ) ] = true; |
|
| 17 | + self::$created_revisions[wp_is_post_revision($post_id)] = true; |
|
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | - public function wp_save_post_revision_post_has_changed( $post_has_changed, $last_revision, $post ) { |
|
| 20 | + public function wp_save_post_revision_post_has_changed($post_has_changed, $last_revision, $post) { |
|
| 21 | 21 | return true; |
| 22 | 22 | } |
| 23 | - private function product_attributes( $post_id ) { |
|
| 23 | + private function product_attributes($post_id) { |
|
| 24 | 24 | global $wpdb; |
| 25 | 25 | $wpsdb_attribute = WPSHOP_DBT_ATTRIBUTE; |
| 26 | 26 | $wpsdb_attribute_set = WPSHOP_DBT_ATTRIBUTE_DETAILS; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $wpsdb_values_varchar = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; |
| 32 | 32 | $wpsdb_values_text = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; |
| 33 | 33 | $wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
| 34 | - return $wpdb->get_results( $wpdb->prepare( |
|
| 34 | + return $wpdb->get_results($wpdb->prepare( |
|
| 35 | 35 | "SELECT attr.id, |
| 36 | 36 | attr.code, |
| 37 | 37 | attr.frontend_label, |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | WHERE p.ID = %d |
| 62 | 62 | GROUP BY attr.code", |
| 63 | 63 | $post_id |
| 64 | - ), ARRAY_A ); |
|
| 64 | + ), ARRAY_A); |
|
| 65 | 65 | } |
| 66 | - public function wp_restore_post_revision( $post_id, $revision_id ) { |
|
| 66 | + public function wp_restore_post_revision($post_id, $revision_id) { |
|
| 67 | 67 | $product_class = new wpshop_products(); |
| 68 | 68 | $attrs = array(); |
| 69 | - foreach ( $this->product_attributes( $post_id ) as $attr ) { |
|
| 70 | - $attrs[ $attr['data_type'] ][ $attr['code'] ] = $this->wp_post_revision_field( '', $attr['id'], get_post( $revision_id ), '', false ); |
|
| 69 | + foreach ($this->product_attributes($post_id) as $attr) { |
|
| 70 | + $attrs[$attr['data_type']][$attr['code']] = $this->wp_post_revision_field('', $attr['id'], get_post($revision_id), '', false); |
|
| 71 | 71 | } |
| 72 | 72 | $product_class->save_product_custom_informations( |
| 73 | 73 | $post_id, |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | ) |
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | - public function wp_post_revision_fields( $fields, $post ) { |
|
| 84 | - foreach ( $this->product_attributes( $post['ID'] ) as $data ) { |
|
| 85 | - $fields[ $data['id'] ] = $data['frontend_label']; |
|
| 86 | - add_filter( "_wp_post_revision_field_{$data['id']}", array( $this, 'wp_post_revision_field' ), 10, 4 ); |
|
| 83 | + public function wp_post_revision_fields($fields, $post) { |
|
| 84 | + foreach ($this->product_attributes($post['ID']) as $data) { |
|
| 85 | + $fields[$data['id']] = $data['frontend_label']; |
|
| 86 | + add_filter("_wp_post_revision_field_{$data['id']}", array($this, 'wp_post_revision_field'), 10, 4); |
|
| 87 | 87 | } |
| 88 | 88 | return $fields; |
| 89 | 89 | } |
| 90 | - public function wp_post_revision_field( $value, $field, $revision, $fromto, $option_label = true ) { |
|
| 90 | + public function wp_post_revision_field($value, $field, $revision, $fromto, $option_label = true) { |
|
| 91 | 91 | global $wpdb; |
| 92 | 92 | $wpsdb_histo = WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO; |
| 93 | 93 | $wpsdb_values_options = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; |
| 94 | 94 | $result = '0'; |
| 95 | - if ( true === $option_label ) { |
|
| 95 | + if (true === $option_label) { |
|
| 96 | 96 | $select = 'IFNULL( val_opt.label, |
| 97 | 97 | histo.value |
| 98 | 98 | )'; |
| 99 | 99 | } else { |
| 100 | 100 | $select = 'histo.value'; |
| 101 | 101 | } |
| 102 | - $result = $wpdb->get_var( $wpdb->prepare( |
|
| 102 | + $result = $wpdb->get_var($wpdb->prepare( |
|
| 103 | 103 | "SELECT {$select} |
| 104 | 104 | FROM {$wpsdb_histo} histo |
| 105 | 105 | LEFT JOIN {$wpsdb_values_options} val_opt ON val_opt.attribute_id = histo.attribute_id AND val_opt.id = histo.value |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | $revision->post_date, |
| 122 | 122 | $field, |
| 123 | 123 | $revision->post_parent |
| 124 | - ) ); |
|
| 125 | - $result = ( '0' === $result ) ? null : $result; |
|
| 124 | + )); |
|
| 125 | + $result = ('0' === $result) ? null : $result; |
|
| 126 | 126 | return $result; |
| 127 | 127 | } |
| 128 | 128 | } |