getId($attrs); if ($id === null) { return ''; } $campaign = new Campaign($id); $campaign->loadSettings(); // Don't render the shortcode if the campaign's inactive. if ( ! $campaign->isActive() || $campaign->isScheduled()) { return ''; } // Run campaign's actions if expired. if ($campaign->isRegular() && $campaign->isExpired()) { $actionManager = new ActionManager($campaign); $actionManager->run(); } $template = apply_filters('hurryt_campaign_template', $campaign->buildTemplate()); return $campaign->wrapTemplate($template); } /** * Returns campaign ID if set. * * @param $attrs * * @return int|null */ function getId($attrs) { if ( ! $this->hasId($attrs)) { return null; } $id = intval($attrs['id']); if ( ! $this->campaignExists($id)) { return null; } return $id; } /** * Verify if the given attributes contain the campaign ID. * * @param $attrs * * @return bool */ function hasId($attrs) { return isset($attrs['id']); } /** * Verify if the given campaign exists in database. * * @param $id * * @return boolean */ function campaignExists($id) { return get_post($id) instanceof WP_Post; } }