0 || $errors['error_count'] > 0 ) ) { return null; } return $date->setTimezone( new \DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' ); } /** * Why a post can't be saved as scheduled for this GMT date, or '' when * it can. * * @param string $date_gmt The date the post would carry, in GMT ('' for none). */ public static function future_error( string $date_gmt ): string { $time = ( '' === $date_gmt || '0000-00-00 00:00:00' === $date_gmt ) ? 0 : (int) strtotime( $date_gmt . ' UTC' ); if ( $time <= 0 ) { return __( 'A scheduled post needs a publish date: pass date_gmt (GMT, Y-m-d H:i:s) at least a minute from now. Without one WordPress would publish it straight away. To publish now, use status "publish".', 'gripmcp' ); } if ( $time - time() < MINUTE_IN_SECONDS ) { return sprintf( /* translators: %s: date in GMT. */ __( 'The date %s (GMT) is not in the future, so WordPress would publish the post straight away instead of scheduling it. Pass a later date_gmt, or use status "publish" to publish now.', 'gripmcp' ), $date_gmt ); } return ''; } /** * A sentence for the result when WordPress stored a different status * from the one asked for, or ''. * * @param string $asked Status asked for ('' when none was). * @param \WP_Post $post The post as saved. */ public static function status_note( string $asked, \WP_Post $post ): string { if ( '' === $asked || $asked === $post->post_status ) { return ''; } if ( 'future' === $post->post_status ) { return sprintf( /* translators: 1: status asked for, 2: date in GMT. */ __( 'WordPress saved it as scheduled rather than "%1$s", because its date is in the future: it goes live at %2$s (GMT).', 'gripmcp' ), $asked, $post->post_date_gmt ); } return sprintf( /* translators: 1: status saved, 2: status asked for. */ __( 'WordPress saved it as "%1$s" rather than "%2$s".', 'gripmcp' ), $post->post_status, $asked ); } }