- Moves hooks setup to wp_load action
- Adds post notification scheduler to all post types
This commit is contained in:
@ -169,10 +169,13 @@ class Hooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupPostNotifications() {
|
function setupPostNotifications() {
|
||||||
add_filter(
|
$post_types = get_post_types();
|
||||||
'publish_post',
|
foreach($post_types as $post_type) {
|
||||||
'\MailPoet\Newsletter\Scheduler\Scheduler::schedulePostNotification',
|
add_filter(
|
||||||
10, 1
|
'publish_' . $post_type,
|
||||||
);
|
'\MailPoet\Newsletter\Scheduler\Scheduler::schedulePostNotification',
|
||||||
|
10, 1
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,6 +39,7 @@ class Initializer {
|
|||||||
add_action('plugins_loaded', array($this, 'setup'));
|
add_action('plugins_loaded', array($this, 'setup'));
|
||||||
add_action('init', array($this, 'onInit'));
|
add_action('init', array($this, 'onInit'));
|
||||||
add_action('widgets_init', array($this, 'setupWidget'));
|
add_action('widgets_init', array($this, 'setupWidget'));
|
||||||
|
add_action('wp_loaded', array($this, 'setupHooks'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkRequirements() {
|
function checkRequirements() {
|
||||||
@ -109,7 +110,6 @@ class Initializer {
|
|||||||
$this->setupAnalytics();
|
$this->setupAnalytics();
|
||||||
$this->setupChangelog();
|
$this->setupChangelog();
|
||||||
$this->setupShortcodes();
|
$this->setupShortcodes();
|
||||||
$this->setupHooks();
|
|
||||||
$this->setupImages();
|
$this->setupImages();
|
||||||
$this->setupCronTrigger();
|
$this->setupCronTrigger();
|
||||||
|
|
||||||
|
21
tests/unit/Config/HooksTest.php
Normal file
21
tests/unit/Config/HooksTest.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class HooksTest extends MailPoetTest {
|
||||||
|
function testItHooksSchedulerToMultiplePostTypes() {
|
||||||
|
global $wp_filter;
|
||||||
|
$post_types = get_post_types();
|
||||||
|
$hook_count = 0;
|
||||||
|
foreach($post_types as $post_type) {
|
||||||
|
expect(!empty($wp_filter['publish_' . $post_type]))->true();
|
||||||
|
$filter = $wp_filter['publish_' . $post_type];
|
||||||
|
$is_hooked = false;
|
||||||
|
foreach($filter->callbacks[10] as $name => $hook) {
|
||||||
|
if(!preg_match('/schedulePostNotification/', $name)) continue;
|
||||||
|
$is_hooked = true;
|
||||||
|
$hook_count++;
|
||||||
|
}
|
||||||
|
expect($is_hooked)->true();
|
||||||
|
}
|
||||||
|
expect($hook_count)->equals(count($post_types));
|
||||||
|
}
|
||||||
|
}
|
@ -16,4 +16,14 @@ class InitializerTest extends MailPoetTest {
|
|||||||
// time zone should be set based on WP's time zone
|
// time zone should be set based on WP's time zone
|
||||||
expect($result->time_zone)->equals(Env::$db_timezone_offset);
|
expect($result->time_zone)->equals(Env::$db_timezone_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItConfiguresHooks() {
|
||||||
|
global $wp_filter;
|
||||||
|
$is_hooked = false;
|
||||||
|
// mailpoet should hook to 'wp_loaded' with priority of 10
|
||||||
|
foreach($wp_filter['wp_loaded'][10] as $name => $hook) {
|
||||||
|
if(preg_match('/setupHooks/', $name)) $is_hooked = true;
|
||||||
|
}
|
||||||
|
expect($is_hooked)->true();
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user