Skip to content

Commit 36c89e1

Browse files
authored
Merge pull request #824 from Kit/use-wp-doing-cron-method
Use `wp_doing_cron` method
2 parents 8c7830d + 14d9b67 commit 36c89e1

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

includes/class-convertkit-broadcasts-importer.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ private function build_post_args( $broadcast, $author_id, $category_id = false )
341341
'post_excerpt' => ( ! is_null( $broadcast['description'] ) ? $broadcast['description'] : '' ),
342342
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', strtotime( $broadcast['published_at'] ) ),
343343
'post_author' => $author_id,
344+
'post_name' => $this->generate_permalink( $broadcast['title'] ),
344345
);
345346

346347
// 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 )
374375

375376
}
376377

378+
/**
379+
* Removes emojis from the given string.
380+
*
381+
* @since 2.8.2
382+
*
383+
* @param string $title Broadcast Title.
384+
* @return string
385+
*/
386+
public function generate_permalink( $title ) {
387+
388+
// Remove emojis.
389+
$title = preg_replace( '/[^\p{L}\p{N}\p{P}\s]+/u', '', $title );
390+
391+
// Return the Permalink.
392+
return sanitize_title( $title );
393+
394+
}
395+
377396
/**
378397
* Parses the given Broadcast's content, removing unnecessary HTML tags and styles.
379398
*

includes/class-wp-convertkit.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,7 @@ public function is_cli() {
363363
*/
364364
public function is_cron() {
365365

366-
if ( ! defined( 'DOING_CRON' ) ) {
367-
return false;
368-
}
369-
if ( ! DOING_CRON ) {
370-
return false;
371-
}
372-
373-
return true;
366+
return wp_doing_cron();
374367

375368
}
376369

tests/Integration/BroadcastsImportTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ public function testImportBroadcastWithDisableStylesEnabled()
306306
$this->assertPostAuthorIDEquals(1, $post);
307307
}
308308

309+
/**
310+
* Test that the generate_permalink() function strips emojis, and runs the string
311+
* through the WordPress sanitize_title() function, which will convert the string
312+
* to lowercase and replace spaces with hyphens.
313+
*
314+
* @since 2.8.2
315+
*/
316+
public function testGeneratePermalinkFunction()
317+
{
318+
$this->assertEquals('hello-world-123', $this->importer->generate_permalink('Hello World 123 🌍'));
319+
$this->assertEquals('hello-123-world', $this->importer->generate_permalink('Hello ❤️‍🩹 123 ❤️ World'));
320+
$this->assertEquals('123-hello-world', $this->importer->generate_permalink('🩹 123 👍🏿 Hello World'));
321+
$this->assertEquals('cafe-deja-vu', $this->importer->generate_permalink('🩹 Café déjà-vu! 👍🏿'));
322+
$this->assertEquals('cafe-deja-vu', $this->importer->generate_permalink('Café déjà-vu!'));
323+
}
324+
309325
/**
310326
* Assert that the created Post's content is valid.
311327
*

0 commit comments

Comments
 (0)