$post_data Post data being assembled. * @param string $slug Slug value from Kordiam. * * @return array Post data with the slug applied. */ public static function apply( array $post_data, string $slug ): array { $slug = trim( $slug ); if ( '' === $slug ) { return $post_data; } $destination = self::destination(); if ( self::URL_ALIAS === $destination ) { $sanitised = sanitize_title( $slug ); // An empty post_name would make WordPress regenerate the slug from the title. if ( '' !== $sanitised ) { $post_data['post_name'] = $sanitised; } return $post_data; } if ( self::TITLE === $destination ) { return $post_data; } if ( ! isset( $post_data['meta_input'] ) || ! is_array( $post_data['meta_input'] ) ) { $post_data['meta_input'] = array(); } // WordPress does not filter arbitrary meta on the way in. $post_data['meta_input'][ $destination ] = MetaValue::sanitise( $slug ); return $post_data; } }