- Moves hooks setup to wp_load action

- Adds post notification scheduler to all post types
This commit is contained in:
Vlad
2017-01-04 19:58:56 -05:00
parent f5dce907ff
commit 714f81d936
4 changed files with 40 additions and 6 deletions

View File

@ -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
);
}
} }
} }

View File

@ -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();

View 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));
}
}

View File

@ -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();
}
} }