Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions includes/class-convertkit-broadcasts-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
9 changes: 1 addition & 8 deletions includes/class-wp-convertkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}

Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/BroadcastsImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down