/** * Returns an array of PopUp objects that should be displayed for the * current page/user. The PopUps are in the order in which they are defined * in the admin list. * * @since 4.6 * @return array List of all popups that fit the current page. */ protected function find_popups() { $popups = array(); lib2()->array->equip_request('po_id', 'preview'); /** * Allow other modules to provide a single popup ID to display. * The value 0 will use the default logic, which evaluates all active * Popups instead of displaying a single Popup. * * @since 4.8.0.0 */ $popup_id = apply_filters('popup-find-popup-single', absint($_REQUEST['po_id'])); if ($popup_id) { // Check for forced popup. $popup_ids = array($popup_id); } else { $popup_ids = IncPopupDatabase::get_active_ids(); } /** * Filter the list of Popup IDs that will be considered for display. * These Popups will be loaded and their rules evaluated in the next step. * * @since 4.8.0.0 */ $popup_ids = apply_filters('popup-active-popup-ids', $popup_ids, $popup_id, $this); foreach ($popup_ids as $id) { $popup = IncPopupDatabase::get($id); if ($popup_id) { // Forced popup ignores all conditions. $show = true; } else { // Apply the conditions to decide if the popup should be displayed. $show = apply_filters('popup-apply-rules', true, $popup); } // Stop here if the popup failed in some conditions. if (!$show) { continue; } // Stop here if the user did choose to hide the popup. if (!$_REQUEST['preview'] && $this->is_hidden($id)) { continue; } $popups[] = $popup; } return $popups; }
/** * Save the popup data to database * * @since 4.6.0 * @param int $post_id Post ID that was saved/created * @param WP_Post $post Post object that was saved/created * @param bool $update True means the post was updated (not created) */ public static function form_save($post_id, $post, $update) { $popup = IncPopupDatabase::get($post_id); // Make sure the POST collection contains all required fields. if (0 !== lib2()->array->equip_post('popup-nonce', 'post_type', 'po-action')) { return; } // Autosave is not processed. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // The nonce is invalid. if (!wp_verify_nonce($_POST['popup-nonce'], 'save-popup')) { return; } // This save event is for a different post type... ?? if (IncPopupItem::POST_TYPE != $_POST['post_type']) { return; } // Global PopUp modified in a Network-Blog that is not the Main-Blog. if (!IncPopup::correct_level()) { return; } // User does not have permissions for this. if (!current_user_can(IncPopupPosttype::$perms)) { return; } $action = $_POST['po-action']; $status = false; switch ($action) { case 'save': // Don't force a status... break; case 'activate': $status = 'active'; break; case 'deactivate': $status = 'inactive'; break; default: // Unknown action. return; } // Populate the popup. $data = self::prepare_formdata($_POST); $data['id'] = $post_id; $data['order'] = $popup->order; if ($status) { $data['status'] = $status; } $popup->populate($data); // Prevent infinite loop when saving. remove_action('save_post_' . IncPopupItem::POST_TYPE, array('IncPopup', 'form_save'), 10); $popup->save(); add_action('save_post_' . IncPopupItem::POST_TYPE, array('IncPopup', 'form_save'), 10, 3); // Removes the 'message' from the redirect URL. add_filter('redirect_post_location', array('IncPopup', 'form_redirect'), 10, 2); // Update the PopUp object in WP-Cache. IncPopupDatabase::get($post_id, true); }
/** * Returns an array of PopUp objects that should be displayed for the * current page/user. The PopUps are in the order in which they are defined * in the admin list. * * @since 4.6 * @return array List of all popups that fit the current page. */ protected function find_popups() { $popups = array(); WDev()->load_request_fields('po_id', 'preview'); $popup_id = absint($_REQUEST['po_id']); if ($popup_id) { // Check for forced popup. $active_ids = array($popup_id); } else { $active_ids = IncPopupDatabase::get_active_ids(); } foreach ($active_ids as $id) { $popup = IncPopupDatabase::get($id); if ($popup_id) { // Forced popup ignores all conditions. $show = true; } else { // Apply the conditions to decide if the popup should be displayed. $show = apply_filters('popup-apply-rules', true, $popup); } // Stop here if the popup failed in some conditions. if (!$show) { continue; } // Stop here if the user did choose to hide the popup. if (!$_REQUEST['preview'] && $this->is_hidden($id)) { continue; } $popups[] = $popup; } return $popups; }