From 6580085af97ec236e80e489bcdcdd79f49b3743a Mon Sep 17 00:00:00 2001 From: picocodes Date: Wed, 8 Jan 2025 12:28:58 +0300 Subject: [PATCH] temp fix for https://core.trac.wordpress.org/ticket/62786#ticket --- src/Objects/Generic_Post_Type.php | 35 ++++++++++++++++++++++++++++--- src/Objects/Store.php | 6 +++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Objects/Generic_Post_Type.php b/src/Objects/Generic_Post_Type.php index 18c7283f..cc19fcfd 100644 --- a/src/Objects/Generic_Post_Type.php +++ b/src/Objects/Generic_Post_Type.php @@ -400,7 +400,7 @@ public function get_fields() { /* translators: %s: Object type label. */ __( 'Enter a comma-separated list of %1$s %2$s.', 'newsletter-optin-box' ), strtolower( $this->singular_label ), - strtolower( $label ) + false === strpos( strtolower( $label ), strtolower( $this->singular_label ) . ' ' ) ? strtolower( $label ) : str_replace( strtolower( $this->singular_label ) . ' ', '', strtolower( $label ) ) ), 'show_in_meta' => true, ), @@ -626,6 +626,12 @@ protected function prepare_create_post_args( $args ) { if ( $term ) { $prepared[] = (int) $term->term_id; + } else { + $term = get_term_by( 'slug', sanitize_title( $term ), $taxonomy ); + + if ( $term ) { + $prepared[] = (int) $term->term_id; + } } } } @@ -634,7 +640,7 @@ protected function prepare_create_post_args( $args ) { if ( 'category' === $taxonomy ) { $post_info['post_category'] = $prepared; } else { - $post_info['tax_input'][ $taxonomy ] = $prepared; + $post_info['tax_input'][ $taxonomy ] = array_unique( array_filter( $prepared ) ); } } @@ -666,8 +672,31 @@ public function create_post( $args ) { $post = wp_update_post( $post_info, true ); } else { $post = wp_insert_post( $post_info, true ); + } + + if ( ! is_wp_error( $post ) ) { + if ( ! empty( $post_info['tax_input'] ) ) { + foreach ( $post_info['tax_input'] as $taxonomy => $tags ) { + + $taxonomy_obj = get_taxonomy( $taxonomy ); + + if ( $taxonomy_obj ) { + + if ( empty( $tags ) && ! empty( $tax_object->default_term ) ) { + $default_term_id = get_option( 'default_term_' . $taxonomy ); + if ( ! empty( $default_term_id ) ) { + $tags = array( (int) $default_term_id ); + } + } + + if ( ! empty( $tags ) ) { + wp_set_post_terms( $post, $tags, $taxonomy ); + } + } + } + } - if ( ! is_wp_error( $post ) ) { + if ( empty( $post_info['ID'] ) ) { $this->after_create_post( get_post( $post ) ); } } diff --git a/src/Objects/Store.php b/src/Objects/Store.php index 55aa3214..aa4fd83e 100644 --- a/src/Objects/Store.php +++ b/src/Objects/Store.php @@ -236,7 +236,11 @@ public static function handle_field_smart_tag( $args, $field, $config = array() // Convert bools to yes/no. if ( is_bool( $raw_value ) ) { - $raw_value = $raw_value ? 'yes' : 'no'; + if ( ! $raw_value ) { + $raw_value = isset( $field['options'] ) && isset( $field['options']['no'] ) ? 'no' : ''; + } else { + $raw_value = 'yes'; + } } // Convert \DateTime to string.