PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
← All changes | libraries/cmb2/includes/CMB2_Utils.php +68 -2 6.0.0 → 6.0.3 View file →
@@ -49,9 +49,9 @@
49 49 $query_args = array(
50 50 'post_type' => 'attachment',
51 51 'post_status' => 'inherit',
52 52 'fields' => 'ids',
53 - 'meta_query' => array(
53 + 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to resolve an attachment ID from its file URL; no non-meta alternative.
54 54 array(
55 55 'value' => $file,
56 56 'compare' => 'LIKE',
57 57 'key' => '_wp_attachment_metadata',
@@ -88,8 +88,9 @@
88 88 public static function get_available_image_sizes() {
89 89 global $_wp_additional_image_sizes;
90 90
91 91 $default_image_sizes = array( 'thumbnail', 'medium', 'large' );
92 + $image_sizes = array();
92 93 foreach ( $default_image_sizes as $size ) {
93 94 $image_sizes[ $size ] = array(
94 95 'height' => intval( get_option( "{$size}_size_h" ) ),
95 96 'width' => intval( get_option( "{$size}_size_w" ) ),
@@ -271,9 +272,9 @@
271 272 $divider = (int) '1' . str_repeat( '0', $diff );
272 273 $timestamp = round( $timestamp / $divider );
273 274 }
274 275 } else {
275 - $timestamp = @strtotime( (string) $string );
276 + $timestamp = @strtotime( (string) $string ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Intentionally suppress notices on arbitrary input; false return is the error check.
276 277 }
277 278
278 279 return $timestamp;
279 280 }
@@ -285,8 +286,9 @@
285 286 * @param mixed $date Value to check.
286 287 * @return boolean Whether value is a valid date
287 288 */
288 289 public static function is_valid_date( $date ) {
290 + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Intentionally suppress notices on arbitrary input; the boolean result is the validity check.
289 291 return ( is_string( $date ) && @strtotime( $date ) )
290 292 || self::is_valid_time_stamp( $date );
291 293 }
292 294
@@ -535,8 +537,72 @@
535 537
536 538 $format = preg_replace_callback( '~(?:\\\.)+~', array( __CLASS__, 'wrap_escaped_chars' ), $format );
537 539
538 540 return $format;
541 + }
542 +
543 + /**
544 + * Get a DateTime object from a value.
545 + *
546 + * @since 2.11.0
547 + *
548 + * @param string $value The value to convert to a DateTime object.
549 + *
550 + * @return DateTime|null
551 + */
552 + public static function get_datetime_from_value( $value ) {
553 + return is_serialized( $value )
554 + // Ok, we need to unserialize the value
555 + // -- allows back-compat for older field values with serialized DateTime objects.
556 + ? self::unserialize_datetime( $value )
557 + // Handle new json formatted values.
558 + : self::json_to_datetime( $value );
559 + }
560 +
561 + /**
562 + * Unserialize a datetime value string.
563 + *
564 + * This is a back-compat method for older field values with serialized DateTime objects.
565 + *
566 + * @since 2.11.0
567 + *
568 + * @param string $date_value The serialized datetime value.
569 + *
570 + * @return DateTime|null
571 + */
572 + public static function unserialize_datetime( $date_value ) {
573 + $datetime = @unserialize( trim( $date_value ), array( 'allowed_classes' => array( 'DateTime' ) ) );
574 +
575 + return $datetime && $datetime instanceof DateTime ? $datetime : null;
576 + }
577 +
578 + /**
579 + * Convert a json datetime value string to a DateTime object.
580 + *
581 + * @since 2.11.0
582 + *
583 + * @param string $json_string The json value string.
584 + *
585 + * @return DateTime|null
586 + */
587 + public static function json_to_datetime( $json_string ) {
588 + if ( ! is_string( $json_string ) ) {
589 + return null;
590 + }
591 +
592 + $json = json_decode( $json_string );
593 +
594 + // Check if json decode was successful
595 + if ( json_last_error() !== JSON_ERROR_NONE ) {
596 + return null;
597 + }
598 +
599 + // If so, convert to DateTime object.
600 + return self::unserialize_datetime( str_replace(
601 + 'stdClass',
602 + 'DateTime',
603 + serialize( $json )
604 + ) );
539 605 }
540 606
541 607 /**
542 608 * Helper function for CMB_Utils::php_to_js_dateformat().