/** * Register the custom post-type details. * * @since 4.6 */ private static function setup_posttype() { // Code generated at http://generatewp.com/post-type/ $manage_popups = true == IncPopup::correct_level(); // Register Custom Post Type $labels = array('name' => _x('PopUps', 'Post Type General Name', PO_LANG), 'singular_name' => _x('PopUp', 'Post Type Singular Name', PO_LANG), 'menu_name' => __('PopUp', PO_LANG), 'parent_item_colon' => __('Parent Item:', PO_LANG), 'all_items' => __('PopUps', PO_LANG), 'view_item' => __('View Item', PO_LANG), 'add_new_item' => __('Add New PopUp', PO_LANG), 'add_new' => __('Add New', PO_LANG), 'edit_item' => __('Edit PopUp', PO_LANG), 'update_item' => __('Update PopUp', PO_LANG), 'search_items' => __('Search PopUp', PO_LANG), 'not_found' => __('Not found', PO_LANG), 'not_found_in_trash' => __('No PopUp found in Trash', PO_LANG)); if (IncPopup::use_global()) { $labels['name'] = _x('Global PopUps', 'Post Type General Name', PO_LANG); $labels['singular_name'] = _x('Global PopUp', 'Post Type Singular Name', PO_LANG); $labels['all_items'] = __('Global PopUps', PO_LANG); } $args = array('label' => __('PopUp', PO_LANG), 'description' => __('Display PopUp messages on your website!', PO_LANG), 'labels' => $labels, 'supports' => array(''), 'hierarchical' => false, 'public' => false, 'show_ui' => $manage_popups, 'show_in_menu' => $manage_popups, 'show_in_nav_menus' => false, 'show_in_admin_bar' => $manage_popups, 'menu_position' => self::$menu_pos, 'menu_icon' => PO_IMG_URL . 'icon.png', 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => false, 'rewrite' => false, 'capabilities' => array('edit_post' => self::$perms, 'read_post' => self::$perms, 'delete_posts' => self::$perms, 'edit_posts' => self::$perms, 'edit_others_posts' => self::$perms, 'publish_posts' => self::$perms, 'read_private_posts' => self::$perms)); register_post_type(IncPopupItem::POST_TYPE, $args); }
/** * 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); }