diff --git a/includes/class-convertkit-broadcasts-importer.php b/includes/class-convertkit-broadcasts-importer.php index 51df4f8ef..c8ebdaff2 100644 --- a/includes/class-convertkit-broadcasts-importer.php +++ b/includes/class-convertkit-broadcasts-importer.php @@ -341,6 +341,7 @@ private function build_post_args( $broadcast, $author_id, $category_id = false ) 'post_excerpt' => ( ! is_null( $broadcast['description'] ) ? $broadcast['description'] : '' ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( $broadcast['published_at'] ) ), 'post_author' => $author_id, + 'post_name' => $this->generate_permalink( $broadcast['title'] ), ); // If a Category was supplied, assign the Post to the given Category ID when created. @@ -374,6 +375,24 @@ private function build_post_args( $broadcast, $author_id, $category_id = false ) } + /** + * Removes emojis from the given string. + * + * @since 2.8.2 + * + * @param string $title Broadcast Title. + * @return string + */ + public function generate_permalink( $title ) { + + // Remove emojis. + $title = preg_replace( '/[^\p{L}\p{N}\p{P}\s]+/u', '', $title ); + + // Return the Permalink. + return sanitize_title( $title ); + + } + /** * Parses the given Broadcast's content, removing unnecessary HTML tags and styles. * diff --git a/includes/class-wp-convertkit.php b/includes/class-wp-convertkit.php index 08023c381..18501764e 100644 --- a/includes/class-wp-convertkit.php +++ b/includes/class-wp-convertkit.php @@ -363,14 +363,7 @@ public function is_cli() { */ public function is_cron() { - if ( ! defined( 'DOING_CRON' ) ) { - return false; - } - if ( ! DOING_CRON ) { - return false; - } - - return true; + return wp_doing_cron(); } diff --git a/tests/Integration/BroadcastsImportTest.php b/tests/Integration/BroadcastsImportTest.php index 1c5d40d9a..96e8e08a4 100644 --- a/tests/Integration/BroadcastsImportTest.php +++ b/tests/Integration/BroadcastsImportTest.php @@ -306,6 +306,22 @@ public function testImportBroadcastWithDisableStylesEnabled() $this->assertPostAuthorIDEquals(1, $post); } + /** + * Test that the generate_permalink() function strips emojis, and runs the string + * through the WordPress sanitize_title() function, which will convert the string + * to lowercase and replace spaces with hyphens. + * + * @since 2.8.2 + */ + public function testGeneratePermalinkFunction() + { + $this->assertEquals('hello-world-123', $this->importer->generate_permalink('Hello World 123 🌍')); + $this->assertEquals('hello-123-world', $this->importer->generate_permalink('Hello ❤️‍🩹 123 ❤️ World')); + $this->assertEquals('123-hello-world', $this->importer->generate_permalink('🩹 123 👍🏿 Hello World')); + $this->assertEquals('cafe-deja-vu', $this->importer->generate_permalink('🩹 Café déjà-vu! 👍🏿')); + $this->assertEquals('cafe-deja-vu', $this->importer->generate_permalink('Café déjà-vu!')); + } + /** * Assert that the created Post's content is valid. *