Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
picocodes committed Jan 8, 2025
1 parent 91525e2 commit 6580085
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
35 changes: 32 additions & 3 deletions src/Objects/Generic_Post_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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 ) );
}
}

Expand Down Expand Up @@ -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 ) );
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Objects/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6580085

Please sign in to comment.