/** * Handles options presetting on first install / activation * @param IfwPsn_Wp_Plugin_Manager $pm */ protected function _presetOptions(IfwPsn_Wp_Plugin_Manager $pm) { if (!$pm->hasOption('selftest_timestamp')) { // on first install (no selftest timestam could be found) $pm->getOptions()->updateOption('psn_ignore_status_inherit', true); } }
/** * @param $statusAfter * @param $statusBefore * @param $post */ public function handlePostStatusTransition($statusAfter, $statusBefore, $post) { /** * Block * check for block setting */ if ($this->isBlockNotifications($post->ID)) { // skip if option to block notifications is set return; } /** * Postponed * check if post should be postponed */ if ($this->_postponedHandler instanceof Psn_Notification_Postponed && $this->_postponedHandler->applies()) { $this->_postponedHandler->add($statusAfter, $statusBefore, $post); return; } $this->_pm->getErrorHandler()->enableErrorReporting(); $this->_statusBefore = $statusBefore; $this->_statusAfter = $statusAfter; // get all active rules $activeRules = IfwPsn_Wp_ORM_Model::factory('Psn_Model_Rule')->filter('active')->find_many(); if (Psn_Model_Rule::hasMax()) { $activeRules = array_slice($activeRules, 0, Psn_Model_Rule::getMax()); } if ($this->isDeferredExecution()) { $deferredHandler = new Psn_Notification_Deferred_Handler(); } /** * @var $rule Psn_Model_Rule */ foreach ($activeRules as $rule) { if ($this->_pm->hasOption('psn_ignore_status_inherit')) { $rule->setIgnoreInherit(true); } // to skip a rulematch return false $doMatch = IfwPsn_Wp_Proxy_Filter::apply('psn_do_match', true, array('rule' => $rule, 'post' => $post, 'status_before' => $statusBefore, 'status_after' => $statusAfter)); if (!is_bool($doMatch)) { // for safety: $doMatch = true; } if ($doMatch && $rule->matches($post, $statusBefore, $statusAfter)) { // rule matches /** * Execute all registered notification services * * @var $service Psn_Notification_Service_Interface */ foreach ($this->getServices() as $service) { if ($this->isDeferredExecution()) { // prepare for deferred execution $deferredContainer = new Psn_Notification_Deferred_Container(); $deferredContainer->setService($service)->setRule($rule)->setPost($post); $deferredHandler->addCotainer($deferredContainer); } else { // execute directly // set the replacer $rule->setReplacer(Psn_Notification_Placeholders::getInstance($post)); $service->execute($rule, $post); } } } } $this->_pm->getErrorHandler()->disableErrorReporting(); }