Plugin Directory

Changeset 2970485


Ignore:
Timestamp:
09/23/2023 06:47:41 AM (2 years ago)
Author:
thanhtd
Message:

Update

Location:
woo-alidropship/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woo-alidropship/trunk/CHANGELOG.txt

    r2968956 r2970485  
     1/**1.1.4 – 2023.09.23*/
     2– Fixed: Duplicate class
     3
    14/**1.1.3 – 2023.09.20*/
    25– Fixed: Missing class
  • woo-alidropship/trunk/includes/ali-product-table.php

    r2968956 r2970485  
    33defined( 'ABSPATH' ) || exit;
    44
    5 class Ali_Product_Table {
    6 
    7     public static function create_table() {
    8         if ( ! function_exists( 'dbDelta' ) ) {
    9             require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    10         }
    11 
    12         global $wpdb;
    13         $max_index_length = 191;
    14         $collate          = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
    15 
    16         $query = "create table if not exists {$wpdb->prefix}ald_posts
     5if ( ! class_exists( 'Ali_Product_Table' ) ) {
     6    class Ali_Product_Table {
     7
     8        public static function create_table() {
     9            if ( ! function_exists( 'dbDelta' ) ) {
     10                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     11            }
     12
     13            global $wpdb;
     14            $max_index_length = 191;
     15            $collate          = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
     16
     17            $query = "create table if not exists {$wpdb->prefix}ald_posts
    1718                (
    1819                    ID                    bigint unsigned auto_increment                primary key,
     
    4546                ) {$collate}";
    4647
    47         $query_meta = "create table if not exists {$wpdb->prefix}ald_postmeta
     48            $query_meta = "create table if not exists {$wpdb->prefix}ald_postmeta
    4849                (
    4950                    meta_id bigint(20) unsigned NOT NULL auto_increment,
     
    5657                ) {$collate}";
    5758
    58         $wpdb->query( $query );
    59         $wpdb->query( $query_meta );
    60 
    61     }
    62 
    63     public static function _add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
    64         return add_metadata( 'ald_post', $post_id, $meta_key, $meta_value, $unique );
    65     }
    66 
    67     public static function _get_post_meta( $post_id, $key = '', $single = false ) {
    68         return get_metadata( 'ald_post', $post_id, $key, $single );
    69     }
    70 
    71     public static function _delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    72         return delete_metadata( 'ald_post', $post_id, $meta_key, $meta_value );
    73     }
    74 
    75     public static function _update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
    76         return update_metadata( 'ald_post', $post_id, $meta_key, $meta_value, $prev_value );
    77     }
    78 
    79     public static function get_post_meta( $post_id, $key = '', $single = false ) {
    80         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    81             ? self::_get_post_meta( $post_id, $key, $single )
    82             : get_post_meta( $post_id, $key, $single );
    83     }
    84 
    85     public static function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
    86         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    87             ? self::_update_post_meta( $post_id, $meta_key, $meta_value, $prev_value )
    88             : update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
    89     }
    90 
    91     public static function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
    92         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    93             ? self::_delete_post_meta( $post_id, $meta_key, $meta_value )
    94             : delete_post_meta( $post_id, $meta_key, $meta_value );
    95     }
    96 
    97     public static function _get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
    98         if ( ! $post ) {
    99             return null;
    100         }
    101 
    102         if ( $post instanceof ALD_Post ) {
    103             $_post = $post;
    104         } elseif ( is_object( $post ) ) {
    105             if ( empty( $post->filter ) ) {
    106                 $_post = sanitize_post( $post, 'raw' );
    107                 $_post = new WP_Post( $_post );
    108             } elseif ( 'raw' === $post->filter ) {
    109                 $_post = new ALD_Post( $post );
     59            $wpdb->query( $query );
     60            $wpdb->query( $query_meta );
     61
     62        }
     63
     64        public static function _add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
     65            return add_metadata( 'ald_post', $post_id, $meta_key, $meta_value, $unique );
     66        }
     67
     68        public static function _get_post_meta( $post_id, $key = '', $single = false ) {
     69            return get_metadata( 'ald_post', $post_id, $key, $single );
     70        }
     71
     72        public static function _delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
     73            return delete_metadata( 'ald_post', $post_id, $meta_key, $meta_value );
     74        }
     75
     76        public static function _update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
     77            return update_metadata( 'ald_post', $post_id, $meta_key, $meta_value, $prev_value );
     78        }
     79
     80        public static function get_post_meta( $post_id, $key = '', $single = false ) {
     81            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     82                ? self::_get_post_meta( $post_id, $key, $single )
     83                : get_post_meta( $post_id, $key, $single );
     84        }
     85
     86        public static function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
     87            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     88                ? self::_update_post_meta( $post_id, $meta_key, $meta_value, $prev_value )
     89                : update_post_meta( $post_id, $meta_key, $meta_value, $prev_value );
     90        }
     91
     92        public static function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
     93            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     94                ? self::_delete_post_meta( $post_id, $meta_key, $meta_value )
     95                : delete_post_meta( $post_id, $meta_key, $meta_value );
     96        }
     97
     98        public static function _get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
     99            if ( ! $post ) {
     100                return null;
     101            }
     102
     103            if ( $post instanceof ALD_Post ) {
     104                $_post = $post;
     105            } elseif ( is_object( $post ) ) {
     106                if ( empty( $post->filter ) ) {
     107                    $_post = sanitize_post( $post, 'raw' );
     108                    $_post = new WP_Post( $_post );
     109                } elseif ( 'raw' === $post->filter ) {
     110                    $_post = new ALD_Post( $post );
     111                } else {
     112                    $_post = ALD_Post::get_instance( $post->ID );
     113                }
    110114            } else {
    111                 $_post = ALD_Post::get_instance( $post->ID );
    112             }
    113         } else {
    114             $_post = ALD_Post::get_instance( $post );
    115         }
    116 
    117         if ( ! $_post ) {
    118             return null;
    119         }
    120 
    121         $_post = $_post->filter( $filter );
    122 
    123         if ( ARRAY_A === $output ) {
    124             return $_post->to_array();
    125         } elseif ( ARRAY_N === $output ) {
    126             return array_values( $_post->to_array() );
    127         }
    128 
    129         return $_post;
    130     }
    131 
    132     public static function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
    133         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::_get_post( $post, $output, $filter ) : get_post( $post, $output, $filter );
    134     }
    135 
    136     public static function insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
    137         global $wpdb;
    138 
    139         // Capture original pre-sanitized array for passing into filters.
    140         $unsanitized_postarr = $postarr;
    141 
    142         $user_id = get_current_user_id();
    143 
    144         $defaults = array(
    145             'post_author'           => $user_id,
    146             'post_content'          => '',
    147             'post_content_filtered' => '',
    148             'post_title'            => '',
    149             'post_excerpt'          => '',
    150             'post_status'           => 'draft',
    151             'post_type'             => 'post',
    152             'comment_status'        => '',
    153             'ping_status'           => '',
    154             'post_password'         => '',
    155             'to_ping'               => '',
    156             'pinged'                => '',
    157             'post_parent'           => 0,
    158             'menu_order'            => 0,
    159             'guid'                  => '',
    160             'import_id'             => 0,
    161             'context'               => '',
    162             'post_date'             => '',
    163             'post_date_gmt'         => '',
    164         );
    165 
    166         $postarr = wp_parse_args( $postarr, $defaults );
    167 
    168         unset( $postarr['filter'] );
    169 
    170         $postarr = sanitize_post( $postarr, 'db' );
    171 
    172         // Are we updating or creating?
    173         $post_id = 0;
    174         $update  = false;
    175         $guid    = $postarr['guid'];
    176 
    177         if ( ! empty( $postarr['ID'] ) ) {
    178             $update = true;
    179 
    180             // Get the post ID and GUID.
    181             $post_id     = $postarr['ID'];
    182             $post_before = self::_get_post( $post_id );
    183 
    184             if ( is_null( $post_before ) ) {
     115                $_post = ALD_Post::get_instance( $post );
     116            }
     117
     118            if ( ! $_post ) {
     119                return null;
     120            }
     121
     122            $_post = $_post->filter( $filter );
     123
     124            if ( ARRAY_A === $output ) {
     125                return $_post->to_array();
     126            } elseif ( ARRAY_N === $output ) {
     127                return array_values( $_post->to_array() );
     128            }
     129
     130            return $_post;
     131        }
     132
     133        public static function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
     134            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::_get_post( $post, $output, $filter ) : get_post( $post, $output, $filter );
     135        }
     136
     137        public static function insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
     138            global $wpdb;
     139
     140            // Capture original pre-sanitized array for passing into filters.
     141            $unsanitized_postarr = $postarr;
     142
     143            $user_id = get_current_user_id();
     144
     145            $defaults = array(
     146                'post_author'           => $user_id,
     147                'post_content'          => '',
     148                'post_content_filtered' => '',
     149                'post_title'            => '',
     150                'post_excerpt'          => '',
     151                'post_status'           => 'draft',
     152                'post_type'             => 'post',
     153                'comment_status'        => '',
     154                'ping_status'           => '',
     155                'post_password'         => '',
     156                'to_ping'               => '',
     157                'pinged'                => '',
     158                'post_parent'           => 0,
     159                'menu_order'            => 0,
     160                'guid'                  => '',
     161                'import_id'             => 0,
     162                'context'               => '',
     163                'post_date'             => '',
     164                'post_date_gmt'         => '',
     165            );
     166
     167            $postarr = wp_parse_args( $postarr, $defaults );
     168
     169            unset( $postarr['filter'] );
     170
     171            $postarr = sanitize_post( $postarr, 'db' );
     172
     173            // Are we updating or creating?
     174            $post_id = 0;
     175            $update  = false;
     176            $guid    = $postarr['guid'];
     177
     178            if ( ! empty( $postarr['ID'] ) ) {
     179                $update = true;
     180
     181                // Get the post ID and GUID.
     182                $post_id     = $postarr['ID'];
     183                $post_before = self::_get_post( $post_id );
     184
     185                if ( is_null( $post_before ) ) {
     186                    if ( $wp_error ) {
     187                        return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
     188                    }
     189
     190                    return 0;
     191                }
     192
     193                $guid            = self::get_post_field( 'guid', $post_id );
     194                $previous_status = self::get_post_field( 'post_status', $post_id );
     195            } else {
     196                $previous_status = 'new';
     197                $post_before     = null;
     198            }
     199
     200            $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
     201
     202            $post_title   = $postarr['post_title'];
     203            $post_content = $postarr['post_content'];
     204            $post_excerpt = $postarr['post_excerpt'];
     205
     206            if ( isset( $postarr['post_name'] ) ) {
     207                $post_name = $postarr['post_name'];
     208            } elseif ( $update ) {
     209                // For an update, don't modify the post_name if it wasn't supplied as an argument.
     210                $post_name = $post_before->post_name;
     211            }
     212
     213            $maybe_empty = 'attachment' !== $post_type && ! $post_content && ! $post_title && ! $post_excerpt;
     214
     215            if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
     216                return $wp_error ? new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ) : 0;
     217            }
     218
     219            $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
     220
     221            if ( ! empty( $postarr['post_category'] ) ) {
     222                // Filter out empty terms.
     223                $post_category = array_filter( $postarr['post_category'] );
     224            } elseif ( $update && ! isset( $postarr['post_category'] ) ) {
     225                $post_category = $post_before->post_category;
     226            }
     227
     228            // Make sure we set a valid category.
     229            if ( empty( $post_category ) || 0 === count( $post_category ) || ! is_array( $post_category ) ) {
     230                // 'post' requires at least one category.
     231                if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
     232                    $post_category = array( get_option( 'default_category' ) );
     233                } else {
     234                    $post_category = array();
     235                }
     236            }
     237
     238            if ( 'pending' === $post_status ) { //wait
     239                $post_type_object = get_post_type_object( $post_type );
     240
     241                if ( ! $update && $post_type_object && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
     242                    $post_name = '';
     243                } elseif ( $update && ! current_user_can( 'publish_post', $post_id ) ) {
     244                    $post_name = '';
     245                }
     246            }
     247
     248            /*
     249             * Create a valid post name. Drafts and pending posts are allowed to have
     250             * an empty post name.
     251             */
     252            if ( empty( $post_name ) ) {
     253                if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) ) {
     254                    $post_name = sanitize_title( $post_title );
     255                } else {
     256                    $post_name = '';
     257                }
     258            } else {
     259                // On updates, we need to check to see if it's using the old, fixed sanitization context.
     260                $check_name = sanitize_title( $post_name, '', 'old-save' );
     261
     262                if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && self::get_post_field( 'post_name', $post_id ) == $check_name ) {
     263                    $post_name = $check_name;
     264                } else { // New post, or slug has changed.
     265                    $post_name = sanitize_title( $post_name );
     266                }
     267            }
     268            /*
     269             * Resolve the post date from any provided post date or post date GMT strings;
     270             * if none are provided, the date will be set to now.
     271             */
     272
     273            $post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] );
     274
     275            if ( ! $post_date ) {
    185276                if ( $wp_error ) {
    186                     return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
    187                 }
    188 
    189                 return 0;
    190             }
    191 
    192             $guid            = self::get_post_field( 'guid', $post_id );
    193             $previous_status = self::get_post_field( 'post_status', $post_id );
    194         } else {
    195             $previous_status = 'new';
    196             $post_before     = null;
    197         }
    198 
    199         $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
    200 
    201         $post_title   = $postarr['post_title'];
    202         $post_content = $postarr['post_content'];
    203         $post_excerpt = $postarr['post_excerpt'];
    204 
    205         if ( isset( $postarr['post_name'] ) ) {
    206             $post_name = $postarr['post_name'];
    207         } elseif ( $update ) {
    208             // For an update, don't modify the post_name if it wasn't supplied as an argument.
    209             $post_name = $post_before->post_name;
    210         }
    211 
    212         $maybe_empty = 'attachment' !== $post_type && ! $post_content && ! $post_title && ! $post_excerpt;
    213 
    214         if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
    215             return $wp_error ? new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ) : 0;
    216         }
    217 
    218         $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
    219 
    220         if ( ! empty( $postarr['post_category'] ) ) {
    221             // Filter out empty terms.
    222             $post_category = array_filter( $postarr['post_category'] );
    223         } elseif ( $update && ! isset( $postarr['post_category'] ) ) {
    224             $post_category = $post_before->post_category;
    225         }
    226 
    227         // Make sure we set a valid category.
    228         if ( empty( $post_category ) || 0 === count( $post_category ) || ! is_array( $post_category ) ) {
    229             // 'post' requires at least one category.
    230             if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
    231                 $post_category = array( get_option( 'default_category' ) );
     277                    return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
     278                } else {
     279                    return 0;
     280                }
     281            }
     282
     283            if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
     284                if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) {
     285                    $post_date_gmt = get_gmt_from_date( $post_date );
     286                } else {
     287                    $post_date_gmt = '0000-00-00 00:00:00';
     288                }
    232289            } else {
    233                 $post_category = array();
    234             }
    235         }
    236 
    237         if ( 'pending' === $post_status ) { //wait
    238             $post_type_object = get_post_type_object( $post_type );
    239 
    240             if ( ! $update && $post_type_object && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
    241                 $post_name = '';
    242             } elseif ( $update && ! current_user_can( 'publish_post', $post_id ) ) {
    243                 $post_name = '';
    244             }
    245         }
    246 
    247         /*
    248          * Create a valid post name. Drafts and pending posts are allowed to have
    249          * an empty post name.
    250          */
    251         if ( empty( $post_name ) ) {
    252             if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true ) ) {
    253                 $post_name = sanitize_title( $post_title );
     290                $post_date_gmt = $postarr['post_date_gmt'];
     291            }
     292
     293            if ( $update || '0000-00-00 00:00:00' === $post_date ) {
     294                $post_modified     = current_time( 'mysql' );
     295                $post_modified_gmt = current_time( 'mysql', 1 );
    254296            } else {
    255                 $post_name = '';
    256             }
    257         } else {
    258             // On updates, we need to check to see if it's using the old, fixed sanitization context.
    259             $check_name = sanitize_title( $post_name, '', 'old-save' );
    260 
    261             if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && self::get_post_field( 'post_name', $post_id ) == $check_name ) {
    262                 $post_name = $check_name;
    263             } else { // New post, or slug has changed.
    264                 $post_name = sanitize_title( $post_name );
    265             }
    266         }
    267         /*
    268          * Resolve the post date from any provided post date or post date GMT strings;
    269          * if none are provided, the date will be set to now.
    270          */
    271 
    272         $post_date = wp_resolve_post_date( $postarr['post_date'], $postarr['post_date_gmt'] );
    273 
    274         if ( ! $post_date ) {
    275             if ( $wp_error ) {
    276                 return new WP_Error( 'invalid_date', __( 'Invalid date.' ) );
     297                $post_modified     = $post_date;
     298                $post_modified_gmt = $post_date_gmt;
     299            }
     300
     301            if ( 'attachment' !== $post_type ) {
     302                $now = gmdate( 'Y-m-d H:i:s' );
     303
     304                if ( 'publish' === $post_status ) {
     305                    if ( strtotime( $post_date_gmt ) - strtotime( $now ) >= MINUTE_IN_SECONDS ) {
     306                        $post_status = 'future';
     307                    }
     308                } elseif ( 'future' === $post_status ) {
     309                    if ( strtotime( $post_date_gmt ) - strtotime( $now ) < MINUTE_IN_SECONDS ) {
     310                        $post_status = 'publish';
     311                    }
     312                }
     313            }
     314
     315            // Comment status.
     316            if ( empty( $postarr['comment_status'] ) ) {
     317                if ( $update ) {
     318                    $comment_status = 'closed';
     319                } else {
     320                    $comment_status = get_default_comment_status( $post_type );
     321                }
    277322            } else {
    278                 return 0;
    279             }
    280         }
    281 
    282         if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' === $postarr['post_date_gmt'] ) {
    283             if ( ! in_array( $post_status, get_post_stati( array( 'date_floating' => true ) ), true ) ) {
    284                 $post_date_gmt = get_gmt_from_date( $post_date );
    285             } else {
    286                 $post_date_gmt = '0000-00-00 00:00:00';
    287             }
    288         } else {
    289             $post_date_gmt = $postarr['post_date_gmt'];
    290         }
    291 
    292         if ( $update || '0000-00-00 00:00:00' === $post_date ) {
    293             $post_modified     = current_time( 'mysql' );
    294             $post_modified_gmt = current_time( 'mysql', 1 );
    295         } else {
    296             $post_modified     = $post_date;
    297             $post_modified_gmt = $post_date_gmt;
    298         }
    299 
    300         if ( 'attachment' !== $post_type ) {
    301             $now = gmdate( 'Y-m-d H:i:s' );
    302 
    303             if ( 'publish' === $post_status ) {
    304                 if ( strtotime( $post_date_gmt ) - strtotime( $now ) >= MINUTE_IN_SECONDS ) {
    305                     $post_status = 'future';
    306                 }
    307             } elseif ( 'future' === $post_status ) {
    308                 if ( strtotime( $post_date_gmt ) - strtotime( $now ) < MINUTE_IN_SECONDS ) {
    309                     $post_status = 'publish';
    310                 }
    311             }
    312         }
    313 
    314         // Comment status.
    315         if ( empty( $postarr['comment_status'] ) ) {
    316             if ( $update ) {
    317                 $comment_status = 'closed';
    318             } else {
    319                 $comment_status = get_default_comment_status( $post_type );
    320             }
    321         } else {
    322             $comment_status = $postarr['comment_status'];
    323         }
    324 
    325         // These variables are needed by compact() later.
    326         $post_content_filtered = $postarr['post_content_filtered'];
    327         $post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
    328         $ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    329         $to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    330         $pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
    331         $import_id             = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
    332         $menu_order            = $postarr['menu_order'] ? (int) $postarr['menu_order'] : 0;
    333 
    334         $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
    335         if ( 'private' === $post_status ) {
    336             $post_password = '';
    337         }
    338 
    339         $post_parent = isset( $postarr['post_parent'] ) ? (int) $postarr['post_parent'] : 0;
    340 
    341         $new_postarr = array_merge(
    342             array( 'ID' => $post_id ),
    343             compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
    344         );
    345 
    346         $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_id, $new_postarr, $postarr );
    347 
    348         if ( 'trash' === $previous_status && 'trash' !== $post_status ) {
    349             $desired_post_slug = self::_get_post_meta( $post_id, '_wp_desired_post_slug', true );
    350 
    351             if ( $desired_post_slug ) {
    352                 self::_delete_post_meta( $post_id, '_wp_desired_post_slug' );
    353                 $post_name = $desired_post_slug;
    354             }
    355         }
    356 
    357         // If a trashed post has the desired slug, change it and let this post have it.
    358         if ( 'trash' !== $post_status && $post_name ) {
    359             /**
    360              * Filters whether or not to add a `__trashed` suffix to trashed posts that match the name of the updated post.
    361              *
    362              * @param bool $add_trashed_suffix Whether to attempt to add the suffix.
    363              * @param string $post_name The name of the post being updated.
    364              * @param int $post_id Post ID.
    365              *
    366              * @since 5.4.0
    367              *
    368              */
    369             $add_trashed_suffix = apply_filters( 'add_trashed_suffix_to_trashed_posts', true, $post_name, $post_id );
    370 
    371             if ( $add_trashed_suffix ) {
     323                $comment_status = $postarr['comment_status'];
     324            }
     325
     326            // These variables are needed by compact() later.
     327            $post_content_filtered = $postarr['post_content_filtered'];
     328            $post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
     329            $ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
     330            $to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
     331            $pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
     332            $import_id             = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
     333            $menu_order            = $postarr['menu_order'] ? (int) $postarr['menu_order'] : 0;
     334
     335            $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
     336            if ( 'private' === $post_status ) {
     337                $post_password = '';
     338            }
     339
     340            $post_parent = isset( $postarr['post_parent'] ) ? (int) $postarr['post_parent'] : 0;
     341
     342            $new_postarr = array_merge(
     343                array( 'ID' => $post_id ),
     344                compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
     345            );
     346
     347            $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_id, $new_postarr, $postarr );
     348
     349            if ( 'trash' === $previous_status && 'trash' !== $post_status ) {
     350                $desired_post_slug = self::_get_post_meta( $post_id, '_wp_desired_post_slug', true );
     351
     352                if ( $desired_post_slug ) {
     353                    self::_delete_post_meta( $post_id, '_wp_desired_post_slug' );
     354                    $post_name = $desired_post_slug;
     355                }
     356            }
     357
     358            // If a trashed post has the desired slug, change it and let this post have it.
     359            if ( 'trash' !== $post_status && $post_name ) {
     360                /**
     361                 * Filters whether or not to add a `__trashed` suffix to trashed posts that match the name of the updated post.
     362                 *
     363                 * @param bool $add_trashed_suffix Whether to attempt to add the suffix.
     364                 * @param string $post_name The name of the post being updated.
     365                 * @param int $post_id Post ID.
     366                 *
     367                 * @since 5.4.0
     368                 *
     369                 */
     370                $add_trashed_suffix = apply_filters( 'add_trashed_suffix_to_trashed_posts', true, $post_name, $post_id );
     371
     372                if ( $add_trashed_suffix ) {
    372373//              wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_id );
    373             }
    374         }
    375 
    376         // When trashing an existing post, change its slug to allow non-trashed posts to use it.
    377         if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) {
     374                }
     375            }
     376
     377            // When trashing an existing post, change its slug to allow non-trashed posts to use it.
     378            if ( 'trash' === $post_status && 'trash' !== $previous_status && 'new' !== $previous_status ) {
    378379//          $post_name = wp_add_trashed_suffix_to_post_name_for_post( $post_id );
    379         }
     380            }
    380381
    381382//      $post_name = wp_unique_post_slug( $post_name, $post_id, $post_status, $post_type, $post_parent );
    382383
    383         // Don't unslash.
    384         $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
    385 
    386         // Expected_slashed (everything!).
    387         $data = compact(
    388             'post_author',
    389             'post_date',
    390             'post_date_gmt',
    391             'post_content',
    392             'post_content_filtered',
    393             'post_title',
    394             'post_excerpt',
    395             'post_status',
    396             'post_type',
    397             'comment_status',
    398             'ping_status',
    399             'post_password',
    400             'post_name',
    401             'to_ping',
    402             'pinged',
    403             'post_modified',
    404             'post_modified_gmt',
    405             'post_parent',
    406             'menu_order',
    407             'post_mime_type',
    408             'guid'
    409         );
    410 
    411         $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' );
     384            // Don't unslash.
     385            $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
     386
     387            // Expected_slashed (everything!).
     388            $data = compact(
     389                'post_author',
     390                'post_date',
     391                'post_date_gmt',
     392                'post_content',
     393                'post_content_filtered',
     394                'post_title',
     395                'post_excerpt',
     396                'post_status',
     397                'post_type',
     398                'comment_status',
     399                'ping_status',
     400                'post_password',
     401                'post_name',
     402                'to_ping',
     403                'pinged',
     404                'post_modified',
     405                'post_modified_gmt',
     406                'post_parent',
     407                'menu_order',
     408                'post_mime_type',
     409                'guid'
     410            );
     411
     412            $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' );
    412413
    413414//      foreach ( $emoji_fields as $emoji_field ) {
     
    422423
    423424
    424         $data  = wp_unslash( $data );
    425         $where = array( 'ID' => $post_id );
    426 
    427         if ( $update ) {
    428             /**
    429             * Fires immediately before an existing post is updated in the database.
    430             *
    431             * @param int $post_id Post ID.
    432             * @param array $data Array of unslashed post data.
    433             *
    434             * @since 2.5.0
    435             *
    436             */
     425            $data  = wp_unslash( $data );
     426            $where = array( 'ID' => $post_id );
     427
     428            if ( $update ) {
     429                /**
     430                * Fires immediately before an existing post is updated in the database.
     431                *
     432                * @param int $post_id Post ID.
     433                * @param array $data Array of unslashed post data.
     434                *
     435                * @since 2.5.0
     436                *
     437                */
    437438//          do_action( 'pre_post_update', $post_id, $data );
    438439
    439             if ( false === $wpdb->update( $wpdb->prefix . 'ald_posts', $data, $where ) ) {
    440                 return $wp_error ? new WP_Error( 'ald_db_update_error', __( 'Could not update post in the database.' ), $wpdb->last_error ) : 0;
    441             }
    442         } else {
    443             // If there is a suggested ID, use it if not already present.
    444             if ( ! empty( $import_id ) ) {
    445                 $import_id = (int) $import_id;
    446 
    447                 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->ald_posts WHERE ID = %d", $import_id ) ) ) {
    448                     $data['ID'] = $import_id;
    449                 }
    450             }
    451 
    452             if ( false === $wpdb->insert( $wpdb->prefix . 'ald_posts', $data ) ) {
    453                 return $wp_error ? new WP_Error( 'ald_db_update_error', __( 'Could not insert post into the database.' ), $wpdb->last_error ) : 0;
    454             }
    455 
    456             $post_id = (int) $wpdb->insert_id;
    457 
    458             // Use the newly generated $post_id.
    459             $where = array( 'ID' => $post_id );
    460         }
    461 
    462         if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) {
     440                if ( false === $wpdb->update( $wpdb->prefix . 'ald_posts', $data, $where ) ) {
     441                    return $wp_error ? new WP_Error( 'ald_db_update_error', __( 'Could not update post in the database.' ), $wpdb->last_error ) : 0;
     442                }
     443            } else {
     444                // If there is a suggested ID, use it if not already present.
     445                if ( ! empty( $import_id ) ) {
     446                    $import_id = (int) $import_id;
     447
     448                    if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->ald_posts WHERE ID = %d", $import_id ) ) ) {
     449                        $data['ID'] = $import_id;
     450                    }
     451                }
     452
     453                if ( false === $wpdb->insert( $wpdb->prefix . 'ald_posts', $data ) ) {
     454                    return $wp_error ? new WP_Error( 'ald_db_update_error', __( 'Could not insert post into the database.' ), $wpdb->last_error ) : 0;
     455                }
     456
     457                $post_id = (int) $wpdb->insert_id;
     458
     459                // Use the newly generated $post_id.
     460                $where = array( 'ID' => $post_id );
     461            }
     462
     463            if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ), true ) ) {
    463464//          $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_id ), $post_id, $data['post_status'], $post_type, $post_parent );
    464             $data['post_name'] = sanitize_title( $data['post_title'], $post_id );
    465 
    466             $wpdb->update( $wpdb->prefix . 'ald_posts', array( 'post_name' => $data['post_name'] ), $where );
     465                $data['post_name'] = sanitize_title( $data['post_title'], $post_id );
     466
     467                $wpdb->update( $wpdb->prefix . 'ald_posts', array( 'post_name' => $data['post_name'] ), $where );
    467468//          clean_post_cache( $post_id );
    468         }
     469            }
    469470
    470471//      if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
     
    476477//      }
    477478
    478         // Add default term for all associated custom taxonomies.
     479            // Add default term for all associated custom taxonomies.
    479480//      if ( 'auto-draft' !== $post_status ) {
    480481//          foreach ( get_object_taxonomies( $post_type, 'object' ) as $taxonomy => $tax_object ) {
     
    503504//      }
    504505
    505         // New-style support for all custom taxonomies.
     506            // New-style support for all custom taxonomies.
    506507//      if ( ! empty( $postarr['tax_input'] ) ) {
    507508//          foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
     
    525526//      }
    526527
    527         if ( ! empty( $postarr['meta_input'] ) ) {
    528             foreach ( $postarr['meta_input'] as $field => $value ) {
    529                 self::_update_post_meta( $post_id, $field, $value );
    530             }
    531         }
    532 
    533 
    534         // Set or remove featured image.
     528            if ( ! empty( $postarr['meta_input'] ) ) {
     529                foreach ( $postarr['meta_input'] as $field => $value ) {
     530                    self::_update_post_meta( $post_id, $field, $value );
     531                }
     532            }
     533
     534
     535            // Set or remove featured image.
    535536//      if ( isset( $postarr['_thumbnail_id'] ) ) {
    536537//          $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
     
    556557//      clean_post_cache( $post_id );
    557558
    558         $post = self::_get_post( $post_id );
    559 
    560         if ( ! empty( $postarr['page_template'] ) ) {
    561             $post->page_template = $postarr['page_template'];
    562             $page_templates      = wp_get_theme()->get_page_templates( $post );
    563 
    564             if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
     559            $post = self::_get_post( $post_id );
     560
     561            if ( ! empty( $postarr['page_template'] ) ) {
     562                $post->page_template = $postarr['page_template'];
     563                $page_templates      = wp_get_theme()->get_page_templates( $post );
     564
     565                if ( 'default' !== $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
     566                    if ( $wp_error ) {
     567                        return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
     568                    }
     569
     570                    self::_update_post_meta( $post_id, '_wp_page_template', 'default' );
     571                } else {
     572                    self::_update_post_meta( $post_id, '_wp_page_template', $postarr['page_template'] );
     573                }
     574            }
     575
     576            return $post_id;
     577        }
     578
     579        public static function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
     580            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::insert_post( $postarr, $wp_error, $fire_after_hooks ) : wp_insert_post( $postarr, $wp_error, $fire_after_hooks );
     581        }
     582
     583        public static function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
     584            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     585                ? self::update_post( $postarr, $wp_error, $fire_after_hooks )
     586                : wp_update_post( $postarr, $wp_error, $fire_after_hooks );
     587        }
     588
     589        public static function wp_delete_post( $postid = 0, $force_delete = false ) {
     590            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     591                ? self::delete_post( $postid, $force_delete )
     592                : wp_delete_post( $postid, $force_delete );
     593        }
     594
     595        public static function update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
     596            if ( is_object( $postarr ) ) {
     597                // Non-escaped post was passed.
     598                $postarr = get_object_vars( $postarr );
     599                $postarr = wp_slash( $postarr );
     600            }
     601
     602            // First, get all of the original fields.
     603            $post = self::get_post( $postarr['ID'], ARRAY_A );
     604
     605            if ( is_null( $post ) ) {
    565606                if ( $wp_error ) {
    566                     return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
    567                 }
    568 
    569                 self::_update_post_meta( $post_id, '_wp_page_template', 'default' );
     607                    return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
     608                }
     609
     610                return 0;
     611            }
     612
     613            // Escape data pulled from DB.
     614            $post = wp_slash( $post );
     615
     616            // Drafts shouldn't be assigned a date unless explicitly done so by the user.
     617            if ( isset( $post['post_status'] )
     618                 && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true )
     619                 && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] )
     620            ) {
     621                $clear_date = true;
    570622            } else {
    571                 self::_update_post_meta( $post_id, '_wp_page_template', $postarr['page_template'] );
    572             }
    573         }
    574 
    575         return $post_id;
    576     }
    577 
    578     public static function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true ) {
    579         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::insert_post( $postarr, $wp_error, $fire_after_hooks ) : wp_insert_post( $postarr, $wp_error, $fire_after_hooks );
    580     }
    581 
    582     public static function wp_update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
    583         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    584             ? self::update_post( $postarr, $wp_error, $fire_after_hooks )
    585             : wp_update_post( $postarr, $wp_error, $fire_after_hooks );
    586     }
    587 
    588     public static function wp_delete_post( $postid = 0, $force_delete = false ) {
    589         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    590             ? self::delete_post( $postid, $force_delete )
    591             : wp_delete_post( $postid, $force_delete );
    592     }
    593 
    594     public static function update_post( $postarr = array(), $wp_error = false, $fire_after_hooks = true ) {
    595         if ( is_object( $postarr ) ) {
    596             // Non-escaped post was passed.
    597             $postarr = get_object_vars( $postarr );
    598             $postarr = wp_slash( $postarr );
    599         }
    600 
    601         // First, get all of the original fields.
    602         $post = self::get_post( $postarr['ID'], ARRAY_A );
    603 
    604         if ( is_null( $post ) ) {
    605             if ( $wp_error ) {
    606                 return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
    607             }
    608 
    609             return 0;
    610         }
    611 
    612         // Escape data pulled from DB.
    613         $post = wp_slash( $post );
    614 
    615         // Drafts shouldn't be assigned a date unless explicitly done so by the user.
    616         if ( isset( $post['post_status'] )
    617              && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ), true )
    618              && empty( $postarr['edit_date'] ) && ( '0000-00-00 00:00:00' === $post['post_date_gmt'] )
    619         ) {
    620             $clear_date = true;
    621         } else {
    622             $clear_date = false;
    623         }
    624 
    625         // Merge old and new fields with new fields overwriting old ones.
    626         $postarr = array_merge( $post, $postarr );
    627         if ( $clear_date ) {
    628             $postarr['post_date']     = current_time( 'mysql' );
    629             $postarr['post_date_gmt'] = '';
    630         }
    631 
    632         return self::insert_post( $postarr, $wp_error, $fire_after_hooks );
    633     }
    634 
    635     public static function delete_post( $postid = 0, $force_delete = false ) {
    636         global $wpdb;
    637 
    638         $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->ald_posts} WHERE ID = %d", $postid ) );
    639 
    640         if ( ! $post ) {
    641             return $post;
    642         }
    643 
    644         $post = self::_get_post( $post );
     623                $clear_date = false;
     624            }
     625
     626            // Merge old and new fields with new fields overwriting old ones.
     627            $postarr = array_merge( $post, $postarr );
     628            if ( $clear_date ) {
     629                $postarr['post_date']     = current_time( 'mysql' );
     630                $postarr['post_date_gmt'] = '';
     631            }
     632
     633            return self::insert_post( $postarr, $wp_error, $fire_after_hooks );
     634        }
     635
     636        public static function delete_post( $postid = 0, $force_delete = false ) {
     637            global $wpdb;
     638
     639            $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->ald_posts} WHERE ID = %d", $postid ) );
     640
     641            if ( ! $post ) {
     642                return $post;
     643            }
     644
     645            $post = self::_get_post( $post );
    645646
    646647//      if ( ! $force_delete && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) {
     
    648649//      }
    649650
    650         $check = apply_filters( 'pre_delete_post', null, $post, $force_delete );
    651         if ( null !== $check ) {
    652             return $check;
    653         }
     651            $check = apply_filters( 'pre_delete_post', null, $post, $force_delete );
     652            if ( null !== $check ) {
     653                return $check;
     654            }
    654655
    655656//      do_action( 'before_delete_post', $postid, $post );
    656657
    657         self::_delete_post_meta( $postid, '_wp_trash_meta_status' );
    658         self::_delete_post_meta( $postid, '_wp_trash_meta_time' );
    659 
    660         $parent_data  = array( 'post_parent' => $post->post_parent );
    661         $parent_where = array( 'post_parent' => $postid );
    662 
    663         if ( is_post_type_hierarchical( $post->post_type ) ) {
    664             // Point children of this page to its parent, also clean the cache of affected children.
    665             $children_query = $wpdb->prepare( "SELECT * FROM {$wpdb->ald_posts} WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
    666             $children       = $wpdb->get_results( $children_query );
    667             if ( $children ) {
    668                 $wpdb->update( $wpdb->ald_posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
    669             }
    670         }
    671 
    672         // Point all attachments to this post up one level.
    673         $wpdb->update( $wpdb->ald_posts, $parent_data, $parent_where );
    674 
    675         $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->ald_postmeta} WHERE ald_post_id = %d ", $postid ) );
    676         foreach ( $post_meta_ids as $mid ) {
    677             delete_metadata_by_mid( 'ald_post', $mid );
    678         }
     658            self::_delete_post_meta( $postid, '_wp_trash_meta_status' );
     659            self::_delete_post_meta( $postid, '_wp_trash_meta_time' );
     660
     661            $parent_data  = array( 'post_parent' => $post->post_parent );
     662            $parent_where = array( 'post_parent' => $postid );
     663
     664            if ( is_post_type_hierarchical( $post->post_type ) ) {
     665                // Point children of this page to its parent, also clean the cache of affected children.
     666                $children_query = $wpdb->prepare( "SELECT * FROM {$wpdb->ald_posts} WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
     667                $children       = $wpdb->get_results( $children_query );
     668                if ( $children ) {
     669                    $wpdb->update( $wpdb->ald_posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
     670                }
     671            }
     672
     673            // Point all attachments to this post up one level.
     674            $wpdb->update( $wpdb->ald_posts, $parent_data, $parent_where );
     675
     676            $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->ald_postmeta} WHERE ald_post_id = %d ", $postid ) );
     677            foreach ( $post_meta_ids as $mid ) {
     678                delete_metadata_by_mid( 'ald_post', $mid );
     679            }
    679680
    680681//      do_action( 'delete_post', $postid, $post );
    681682
    682         $result = $wpdb->delete( $wpdb->ald_posts, array( 'ID' => $postid ) );
    683         if ( ! $result ) {
    684             return false;
    685         }
     683            $result = $wpdb->delete( $wpdb->ald_posts, array( 'ID' => $postid ) );
     684            if ( ! $result ) {
     685                return false;
     686            }
    686687
    687688//      do_action( 'deleted_post', $postid, $post );
     
    689690//      clean_post_cache( $post );
    690691
    691         if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
    692             foreach ( $children as $child ) {
     692            if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
     693                foreach ( $children as $child ) {
    693694//              clean_post_cache( $child );
    694             }
    695         }
    696 
    697         wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) );
     695                }
     696            }
     697
     698            wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) );
    698699
    699700//      do_action( 'after_delete_post', $postid, $post );
    700701
    701         return $post;
    702     }
    703 
    704     public static function wp_trash_post( $post_id = 0 ) {
    705         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::trash_post( $post_id ) : wp_trash_post( $post_id );
    706     }
    707 
    708     public static function trash_post( $post_id = 0 ) {
    709         if ( ! EMPTY_TRASH_DAYS ) {
    710             return self::delete_post( $post_id, true );
    711         }
    712 
    713         $post = self::_get_post( $post_id );
    714 
    715         if ( ! $post ) {
    716702            return $post;
    717703        }
    718704
    719         if ( 'trash' === $post->post_status ) {
    720             return false;
    721         }
    722 
    723         $check = apply_filters( 'pre_trash_post', null, $post );
    724 
    725         if ( null !== $check ) {
    726             return $check;
    727         }
    728 
    729         self::_add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
    730         self::_add_post_meta( $post_id, '_wp_trash_meta_time', time() );
    731 
    732         $post_updated = self::update_post(
    733             array(
    734                 'ID'          => $post_id,
    735                 'post_status' => 'trash',
    736             )
    737         );
    738 
    739         if ( ! $post_updated ) {
    740             return false;
    741         }
     705        public static function wp_trash_post( $post_id = 0 ) {
     706            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::trash_post( $post_id ) : wp_trash_post( $post_id );
     707        }
     708
     709        public static function trash_post( $post_id = 0 ) {
     710            if ( ! EMPTY_TRASH_DAYS ) {
     711                return self::delete_post( $post_id, true );
     712            }
     713
     714            $post = self::_get_post( $post_id );
     715
     716            if ( ! $post ) {
     717                return $post;
     718            }
     719
     720            if ( 'trash' === $post->post_status ) {
     721                return false;
     722            }
     723
     724            $check = apply_filters( 'pre_trash_post', null, $post );
     725
     726            if ( null !== $check ) {
     727                return $check;
     728            }
     729
     730            self::_add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
     731            self::_add_post_meta( $post_id, '_wp_trash_meta_time', time() );
     732
     733            $post_updated = self::update_post(
     734                array(
     735                    'ID'          => $post_id,
     736                    'post_status' => 'trash',
     737                )
     738            );
     739
     740            if ( ! $post_updated ) {
     741                return false;
     742            }
    742743
    743744//      do_action( 'trashed_post', $post_id );
    744745
    745         return $post;
    746     }
    747 
    748     public static function get_post_field( $field, $post = null, $context = 'display' ) {
    749         $post = self::_get_post( $post );
    750 
    751         if ( ! $post ) {
    752             return '';
    753         }
    754 
    755         if ( ! isset( $post->$field ) ) {
    756             return '';
    757         }
    758 
    759         return sanitize_post_field( $field, $post->$field, $post->ID, $context );
    760     }
    761 
    762     public static function wp_count_posts( $type = 'post', $perm = '' ) {
    763         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    764             ? self::count_posts( $type, $perm )
    765             : wp_count_posts( $type, $perm );
    766     }
    767 
    768     public static function count_posts( $type = 'post', $perm = '' ) {
    769         global $wpdb;
     746            return $post;
     747        }
     748
     749        public static function get_post_field( $field, $post = null, $context = 'display' ) {
     750            $post = self::_get_post( $post );
     751
     752            if ( ! $post ) {
     753                return '';
     754            }
     755
     756            if ( ! isset( $post->$field ) ) {
     757                return '';
     758            }
     759
     760            return sanitize_post_field( $field, $post->$field, $post->ID, $context );
     761        }
     762
     763        public static function wp_count_posts( $type = 'post', $perm = '' ) {
     764            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     765                ? self::count_posts( $type, $perm )
     766                : wp_count_posts( $type, $perm );
     767        }
     768
     769        public static function count_posts( $type = 'post', $perm = '' ) {
     770            global $wpdb;
    770771
    771772//      if ( ! post_type_exists( $type ) ) {
     
    773774//      }
    774775
    775         $cache_key = _count_posts_cache_key( $type, $perm );
    776 
    777         $counts = wp_cache_get( $cache_key, 'ald_counts' );
    778 
    779         if ( false !== $counts ) {
    780             // We may have cached this before every status was registered.
    781             foreach ( get_post_stati() as $status ) {
    782                 if ( ! isset( $counts->{$status} ) ) {
    783                     $counts->{$status} = 0;
    784                 }
    785             }
    786 
    787             /** This filter is documented in wp-includes/post.php */
     776            $cache_key = _count_posts_cache_key( $type, $perm );
     777
     778            $counts = wp_cache_get( $cache_key, 'ald_counts' );
     779
     780            if ( false !== $counts ) {
     781                // We may have cached this before every status was registered.
     782                foreach ( get_post_stati() as $status ) {
     783                    if ( ! isset( $counts->{$status} ) ) {
     784                        $counts->{$status} = 0;
     785                    }
     786                }
     787
     788                /** This filter is documented in wp-includes/post.php */
     789                return apply_filters( 'wp_count_posts', $counts, $type, $perm );
     790            }
     791
     792            $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->ald_posts} WHERE post_type = %s";
     793
     794            if ( 'readable' === $perm && is_user_logged_in() ) {
     795                if ( ! current_user_can( 'read_private_posts' ) ) {
     796                    $query .= $wpdb->prepare(
     797                        " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
     798                        get_current_user_id()
     799                    );
     800                }
     801            }
     802
     803            $query .= ' GROUP BY post_status';
     804
     805            $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
     806            $counts  = array_fill_keys( get_post_stati(), 0 );
     807
     808            foreach ( $results as $row ) {
     809                $counts[ $row['post_status'] ] = $row['num_posts'];
     810            }
     811
     812            $counts = (object) $counts;
     813            wp_cache_set( $cache_key, $counts, 'ald_counts' );
     814
     815            /**
     816             * Filters the post counts by status for the current post type.
     817             *
     818             * @param stdClass $counts An object containing the current post_type's post
     819             *                         counts by status.
     820             * @param string $type Post type.
     821             * @param string $perm The permission to determine if the posts are 'readable'
     822             *                         by the current user.
     823             *
     824             * @since 3.7.0
     825             *
     826             */
    788827            return apply_filters( 'wp_count_posts', $counts, $type, $perm );
    789828        }
    790829
    791         $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->ald_posts} WHERE post_type = %s";
    792 
    793         if ( 'readable' === $perm && is_user_logged_in() ) {
    794             if ( ! current_user_can( 'read_private_posts' ) ) {
    795                 $query .= $wpdb->prepare(
    796                     " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
    797                     get_current_user_id()
    798                 );
    799             }
    800         }
    801 
    802         $query .= ' GROUP BY post_status';
    803 
    804         $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    805         $counts  = array_fill_keys( get_post_stati(), 0 );
    806 
    807         foreach ( $results as $row ) {
    808             $counts[ $row['post_status'] ] = $row['num_posts'];
    809         }
    810 
    811         $counts = (object) $counts;
    812         wp_cache_set( $cache_key, $counts, 'ald_counts' );
    813 
    814         /**
    815          * Filters the post counts by status for the current post type.
    816          *
    817          * @param stdClass $counts An object containing the current post_type's post
    818          *                         counts by status.
    819          * @param string $type Post type.
    820          * @param string $perm The permission to determine if the posts are 'readable'
    821          *                         by the current user.
    822          *
    823          * @since 3.7.0
    824          *
    825          */
    826         return apply_filters( 'wp_count_posts', $counts, $type, $perm );
    827     }
    828 
    829     public static function get_post_status( $post = null ) {
    830         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
    831             ? self::_get_post_status( $post )
    832             : get_post_status( $post );
    833     }
    834 
    835     public static function _get_post_status( $post = null ) {
    836         $post = self::_get_post( $post );
    837 
    838         if ( ! is_object( $post ) ) {
    839             return false;
    840         }
    841 
    842         $post_status = $post->post_status;
    843 
    844         return apply_filters( 'ald_get_post_status', $post_status, $post );
    845     }
    846 
    847     public static function wp_publish_post( $post ) {
    848         VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::publish_post( $post ) : wp_publish_post( $post );
    849     }
    850 
    851     public static function publish_post( $post ) {
    852         global $wpdb;
    853 
    854         $post = self::_get_post( $post );
    855 
    856         if ( ! $post ) {
    857             return;
    858         }
    859 
    860         if ( 'publish' === $post->post_status ) {
    861             return;
    862         }
     830        public static function get_post_status( $post = null ) {
     831            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table()
     832                ? self::_get_post_status( $post )
     833                : get_post_status( $post );
     834        }
     835
     836        public static function _get_post_status( $post = null ) {
     837            $post = self::_get_post( $post );
     838
     839            if ( ! is_object( $post ) ) {
     840                return false;
     841            }
     842
     843            $post_status = $post->post_status;
     844
     845            return apply_filters( 'ald_get_post_status', $post_status, $post );
     846        }
     847
     848        public static function wp_publish_post( $post ) {
     849            VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? self::publish_post( $post ) : wp_publish_post( $post );
     850        }
     851
     852        public static function publish_post( $post ) {
     853            global $wpdb;
     854
     855            $post = self::_get_post( $post );
     856
     857            if ( ! $post ) {
     858                return;
     859            }
     860
     861            if ( 'publish' === $post->post_status ) {
     862                return;
     863            }
    863864
    864865//      $post_before = self::_get_post( $post->ID );
    865866
    866867
    867         $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
     868            $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
    868869
    869870//      clean_post_cache( $post->ID );
     
    889890//
    890891//      wp_after_insert_post( $post, true, $post_before );
     892        }
     893
     894        public static function wp_query( $args ) {
     895            return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? new Ali_Product_Query( $args ) : new WP_Query( $args );
     896        }
     897
     898        public static function get_posts( $args = null ) {
     899            if ( VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ) {
     900                $defaults = array(
     901                    'numberposts'      => 5,
     902                    'category'         => 0,
     903                    'orderby'          => 'date',
     904                    'order'            => 'DESC',
     905                    'include'          => array(),
     906                    'exclude'          => array(),
     907                    'meta_key'         => '',
     908                    'meta_value'       => '',
     909                    'post_type'        => 'post',
     910                    'suppress_filters' => true,
     911                );
     912
     913                $parsed_args = wp_parse_args( $args, $defaults );
     914                if ( empty( $parsed_args['post_status'] ) ) {
     915                    $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish';
     916                }
     917                if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
     918                    $parsed_args['posts_per_page'] = $parsed_args['numberposts'];
     919                }
     920                if ( ! empty( $parsed_args['category'] ) ) {
     921                    $parsed_args['cat'] = $parsed_args['category'];
     922                }
     923                if ( ! empty( $parsed_args['include'] ) ) {
     924                    $incposts                      = wp_parse_id_list( $parsed_args['include'] );
     925                    $parsed_args['posts_per_page'] = count( $incposts );  // Only the number of posts included.
     926                    $parsed_args['post__in']       = $incposts;
     927                } elseif ( ! empty( $parsed_args['exclude'] ) ) {
     928                    $parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] );
     929                }
     930
     931                $parsed_args['ignore_sticky_posts'] = true;
     932                $parsed_args['no_found_rows']       = true;
     933
     934                $get_posts = new Ali_Product_Query();
     935
     936                return $get_posts->query( $parsed_args );
     937            } else {
     938                return get_posts( $args );
     939            }
     940        }
     941
    891942    }
    892 
    893     public static function wp_query( $args ) {
    894         return VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? new Ali_Product_Query( $args ) : new WP_Query( $args );
    895     }
    896 
    897     public static function get_posts( $args = null ) {
    898         if ( VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ) {
    899             $defaults = array(
    900                 'numberposts'      => 5,
    901                 'category'         => 0,
    902                 'orderby'          => 'date',
    903                 'order'            => 'DESC',
    904                 'include'          => array(),
    905                 'exclude'          => array(),
    906                 'meta_key'         => '',
    907                 'meta_value'       => '',
    908                 'post_type'        => 'post',
    909                 'suppress_filters' => true,
    910             );
    911 
    912             $parsed_args = wp_parse_args( $args, $defaults );
    913             if ( empty( $parsed_args['post_status'] ) ) {
    914                 $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish';
    915             }
    916             if ( ! empty( $parsed_args['numberposts'] ) && empty( $parsed_args['posts_per_page'] ) ) {
    917                 $parsed_args['posts_per_page'] = $parsed_args['numberposts'];
    918             }
    919             if ( ! empty( $parsed_args['category'] ) ) {
    920                 $parsed_args['cat'] = $parsed_args['category'];
    921             }
    922             if ( ! empty( $parsed_args['include'] ) ) {
    923                 $incposts                      = wp_parse_id_list( $parsed_args['include'] );
    924                 $parsed_args['posts_per_page'] = count( $incposts );  // Only the number of posts included.
    925                 $parsed_args['post__in']       = $incposts;
    926             } elseif ( ! empty( $parsed_args['exclude'] ) ) {
    927                 $parsed_args['post__not_in'] = wp_parse_id_list( $parsed_args['exclude'] );
    928             }
    929 
    930             $parsed_args['ignore_sticky_posts'] = true;
    931             $parsed_args['no_found_rows']       = true;
    932 
    933             $get_posts = new Ali_Product_Query();
    934 
    935             return $get_posts->query( $parsed_args );
    936         } else {
    937             return get_posts( $args );
    938         }
    939     }
    940 
    941943}
  • woo-alidropship/trunk/readme.txt

    r2968650 r2970485  
    316316
    317317== Changelog ==
     318/**1.1.4 – 2023.09.23*/
     319– Fixed: Duplicate class
     320
     321/**1.1.3 – 2023.09.20*/
     322– Fixed: Missing class
     323
    318324/**1.1.2 – 2023.09.19*/
    319325– Fixed: Get shipping from AliExpress when import product
  • woo-alidropship/trunk/woo-alidropship.php

    r2968956 r2970485  
    44 * Plugin URI: https://villatheme.com/extensions/aliexpress-dropshipping-and-fulfillment-for-woocommerce/
    55 * Description: Transfer data from AliExpress products to WooCommerce effortlessly and fulfill WooCommerce orders to AliExpress automatically.
    6  * Version: 1.1.3
     6 * Version: 1.1.4
    77 * Author: VillaTheme(villatheme.com)
    88 * Author URI: http://villatheme.com
     
    1818}
    1919
    20 define( 'VI_WOO_ALIDROPSHIP_VERSION', '1.1.3' );
     20define( 'VI_WOO_ALIDROPSHIP_VERSION', '1.1.4' );
    2121define( 'VI_WOO_ALIDROPSHIP_DIR', plugin_dir_path( __FILE__ ) );
    2222define( 'VI_WOO_ALIDROPSHIP_INCLUDES', VI_WOO_ALIDROPSHIP_DIR . "includes" . DIRECTORY_SEPARATOR );
Note: See TracChangeset for help on using the changeset viewer.