-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Installs Microsoft Start plugin for MSN feed
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-i18n'), 'version' => '875d270491656edb4746'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-i18n'), 'version' => '6dc543fd09a6e8e837a9'); |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => '4d7276a040d6dd538386'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-i18n'), 'version' => '542c225bcf6cb53cc393'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "microsoft/news", | ||
"description": "", | ||
"license": "", | ||
"keywords": [], | ||
"authors": [], | ||
"require": { | ||
"php": "^7.3|^8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"microsoft_start\\": "" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"microsoft_start\\tests\\": "../microsoft-start-tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
// © Microsoft Corporation. All rights reserved. | ||
|
||
namespace microsoft_start\cron; | ||
|
||
use microsoft_start\infrastructure\Registration; | ||
use microsoft_start\services\Options; | ||
|
||
class BackgroundTasks extends Registration | ||
{ | ||
function register_dependencies() | ||
{ | ||
// 1.6.2: Temporarily disble adding cron job as it has some side effect; will re-enable after PM confirms | ||
return; | ||
|
||
add_action('wp', function () { | ||
if (Options::get_share_past_posts_start_date()) { | ||
if (!wp_next_scheduled('msnPublishTask')) { | ||
wp_schedule_event(time(), 'hourly', 'msnPublishTask'); | ||
} | ||
} | ||
}); | ||
|
||
register_deactivation_hook(__FILE__, function () { | ||
$timestamp = wp_next_scheduled('msnPublishTask'); | ||
wp_unschedule_event($timestamp, 'msnPublishTask'); | ||
}); | ||
|
||
add_action('msnPublishTask', [$this, 'publish_posts']); | ||
} | ||
|
||
function publish_posts() | ||
{ | ||
// 1.6.2: clear the added cron job in previous version | ||
wp_clear_scheduled_hook('msnPublishTask'); | ||
return; | ||
|
||
if (!Options::get_share_past_posts_start_date()) { | ||
return; | ||
} | ||
|
||
$now = gmdate('Y-m-d H:i:00'); | ||
$after = date_parse(Options::get_share_past_posts_start_date()); | ||
|
||
$posts = get_posts([ | ||
'post_type' => 'post', | ||
'post_status' => ['publish', 'future'], | ||
'meta_query' => [ | ||
[ | ||
'key' => 'msn_id', | ||
'compare' => 'NOT EXISTS' | ||
] | ||
], | ||
'date_query' => array( | ||
array( | ||
'after' => $after, | ||
'before' => $now, | ||
'inclusive' => true, | ||
), | ||
), | ||
]); | ||
|
||
foreach ($posts as $post) { | ||
switch ($post->post_status) { | ||
case 'future': | ||
wp_publish_post($post->ID); | ||
break; | ||
case 'publish': | ||
do_action( 'wp_after_insert_post', $post->ID, $post, true, null ); | ||
break; | ||
} | ||
} | ||
} | ||
} |