atabase abstraction object. * * @param string $column The column to query against. Needs to be pre-validated! * @param string $compare The comparison operator. Needs to be pre-validated! * @param int|null $hour Optional. An hour value (0-23). * @param int|null $minute Optional. A minute value (0-59). * @param int|null $second Optional. A second value (0-59). * @return string|false A query part or false on failure. */ public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) { global $wpdb; // Have to have at least one. if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) { return false; } // Complex combined queries aren't supported for multi-value queries. if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) { $return = array(); $value = $this->build_value( $compare, $hour ); if ( false !== $value ) { $return[] = "HOUR( $column ) $compare $value"; } $value = $this->build_value( $compare, $minute ); if ( false !== $value ) { $return[] = "MINUTE( $column ) $compare $value"; } $value = $this->build_value( $compare, $second ); if ( false !== $value ) { $return[] = "SECOND( $column ) $compare $value"; } return implode( ' AND ', $return ); } // Cases where just one unit is set. if ( isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) { $value = $this->build_value( $compare, $hour ); if ( false !== $value ) { return "HOUR( $column ) $compare $value"; } } elseif ( ! isset( $hour ) && isset( $minute ) && ! isset( $second ) ) { $value = $this->build_value( $compare, $minute ); if ( false !== $value ) { return "MINUTE( $column ) $compare $value"; } } elseif ( ! isset( $hour ) && ! isset( $minute ) && isset( $second ) ) { $value = $this->build_value( $compare, $second ); if ( false !== $value ) { return "SECOND( $column ) $compare $value"; } } // Single units were already handled. Since hour & second isn't allowed, minute must to be set. if ( ! isset( $minute ) ) { return false; } $format = ''; $time = ''; // Hour. if ( null !== $hour ) { $format .= '%H.'; $time .= sprintf( '%02d', $hour ) . '.'; } else { $format .= '0.'; $time .= '0.'; } // Minute. $format .= '%i'; $time .= sprintf( '%02d', $minute ); if ( isset( $second ) ) { $format .= '%s'; $time .= sprintf( '%02d', $second ); } return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time ); } /** * Sanitizes a 'relation' operator. * * @since 6.0.3 * * @param string $relation Raw relation key from the query argument. * @return string Sanitized relation. Either 'AND' or 'OR'. */ public function sanitize_relation( $relation ) { if ( 'OR' === strtoupper( $relation ) ) { return 'OR'; } else { return 'AND'; } } } $from, $to ); } return $keys; } private static function yoast_duplicate_post() { add_filter( 'duplicate_post_excludelist_filter', function( $meta_excludelist ) { $exclude_list = [ Document::TYPE_META_KEY, '_elementor_page_assets', '_elementor_controls_usage', '_elementor_css', '_elementor_screenshot', ]; return array_merge( $meta_excludelist, $exclude_list ); } ); add_action( 'duplicate_post_post_copy', function( $new_post_id, $post ) { $original_template_type = get_post_meta( $post->ID, Document::TYPE_META_KEY, true ); if ( ! empty( $original_template_type ) ) { update_post_meta( $new_post_id, Document::TYPE_META_KEY, $original_template_type ); } }, 10, 2 ); } /** * Process post meta before WP importer. * * Normalize Elementor post meta on import, We need the `wp_slash` in order * to avoid the unslashing during the `add_post_meta`. * * Fired by `wp_import_post_meta` filter. * * @since 1.0.0 * @access public * @static * * @param array $post_meta Post meta. * * @return array Updated post meta. */ public static function on_wp_import_post_meta( $post_meta ) { $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7(); if ( $is_wp_importer_before_0_7 ) { foreach ( $post_meta as &$meta ) { if ( '_elementor_data' === $meta['key'] ) { $meta['value'] = wp_slash( $meta['value'] ); break; } } } return $post_meta; } /** * Is WP Importer Before 0.7 * * Checks if WP Importer is installed, and whether its version is older than 0.7. * * @return bool */ public static function is_wp_importer_before_0_7() { $wp_importer = get_plugins( '/wordpress-importer' ); if ( ! empty( $wp_importer ) ) { $wp_importer_version = $wp_importer['wordpress-importer.php']['Version']; if ( version_compare( $wp_importer_version, '0.7', '<' ) ) { return true; } } return false; } /** * Process post meta before WXR importer. * * Normalize Elementor post meta on import with the new WP_importer, We need * the `wp_slash` in order to avoid the unslashing during the `add_post_meta`. * * Fired by `wxr_importer.pre_process.post_meta` filter. * * @since 1.0.0 * @access public * @static * * @param array $post_meta Post meta. * * @return array Updated post meta. */ public static function on_wxr_importer_pre_process_post_meta( $post_meta ) { $is_wp_importer_before_0_7 = self::is_wp_importer_before_0_7(); if ( $is_wp_importer_before_0_7 ) { if ( '_elementor_data' === $post_meta['key'] ) { $post_meta['value'] = wp_slash( $post_meta['value'] ); } } return $post_meta; } }