'', 'subject' => __( 'Subject', 'flamingo' ), 'from' => __( 'From', 'flamingo' ), 'channel' => __( 'Channel', 'flamingo' ), 'date' => __( 'Date', 'flamingo' ), ); $columns = apply_filters( 'manage_flamingo_inbound_posts_columns', $columns ); return $columns; } public function __construct() { parent::__construct( array( 'singular' => 'post', 'plural' => 'posts', 'ajax' => false, ) ); } public function prepare_items() { $per_page = $this->get_items_per_page( 'flamingo_inbound_messages_per_page' ); $args = array( 'posts_per_page' => $per_page, 'offset' => ( $this->get_pagenum() - 1 ) * $per_page, 'orderby' => 'date', 'order' => 'DESC', ); if ( ! empty( $_REQUEST['s'] ) ) { $args['s'] = $_REQUEST['s']; } if ( ! empty( $_REQUEST['orderby'] ) ) { if ( 'subject' === $_REQUEST['orderby'] ) { $args['meta_key'] = '_subject'; $args['orderby'] = 'meta_value'; } elseif ( 'from' === $_REQUEST['orderby'] ) { $args['meta_key'] = '_from'; $args['orderby'] = 'meta_value'; } } if ( ! empty( $_REQUEST['order'] ) and 'asc' === strtolower( $_REQUEST['order'] ) ) { $args['order'] = 'ASC'; } if ( ! empty( $_REQUEST['m'] ) ) { $args['m'] = $_REQUEST['m']; } if ( ! empty( $_REQUEST['channel_id'] ) ) { $args['channel_id'] = $_REQUEST['channel_id']; } if ( ! empty( $_REQUEST['channel'] ) ) { $args['channel'] = $_REQUEST['channel']; } if ( ! empty( $_REQUEST['post_status'] ) ) { if ( 'trash' === $_REQUEST['post_status'] ) { $args['post_status'] = 'trash'; $this->is_trash = true; } elseif ( 'spam' === $_REQUEST['post_status'] ) { $args['post_status'] = Flamingo_Inbound_Message::spam_status; $this->is_spam = true; } } $this->items = Flamingo_Inbound_Message::find( $args ); $total_items = Flamingo_Inbound_Message::count(); $total_pages = ceil( $total_items / $per_page ); $this->set_pagination_args( array( 'total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page, ) ); } protected function get_views() { $base_url = menu_page_url( 'flamingo_inbound', false ); $link_data = array(); // Inbox Flamingo_Inbound_Message::find( array( 'post_status' => 'any', ) ); $posts_in_inbox = Flamingo_Inbound_Message::count(); $inbox = sprintf( /* translators: %s: Number of items. */ _nx( 'Inbox (%s)', 'Inbox (%s)', $posts_in_inbox, 'posts', 'flamingo' ), number_format_i18n( $posts_in_inbox ) ); $link_data['inbox'] = array( 'url' => $base_url, 'label' => $inbox, 'current' => ! $this->is_trash && ! $this->is_spam, ); // Spam Flamingo_Inbound_Message::find( array( 'post_status' => Flamingo_Inbound_Message::spam_status, ) ); $posts_in_spam = Flamingo_Inbound_Message::count(); $spam = sprintf( /* translators: %s: Number of items. */ _nx( 'Spam (%s)', 'Spam (%s)', $posts_in_spam, 'posts', 'flamingo' ), number_format_i18n( $posts_in_spam ) ); $link_data['spam'] = array( 'url' => add_query_arg( 'post_status', 'spam', $base_url ), 'label' => $spam, 'current' => $this->is_spam, ); // Trash Flamingo_Inbound_Message::find( array( 'post_status' => 'trash', ) ); $posts_in_trash = Flamingo_Inbound_Message::count(); if ( $posts_in_trash ) { $trash = sprintf( /* translators: %s: Number of items. */ _nx( 'Trash (%s)', 'Trash (%s)', $posts_in_trash, 'posts', 'flamingo' ), number_format_i18n( $posts_in_trash ) ); $link_data['trash'] = array( 'url' => add_query_arg( 'post_status', 'trash', $base_url ), 'label' => $trash, 'current' => $this->is_trash, ); } return $this->get_views_links( $link_data ); } public function get_columns() { return get_column_headers( get_current_screen() ); } protected function get_sortable_columns() { $columns = array( 'subject' => array( 'subject', false ), 'from' => array( 'from', false ), 'date' => array( 'date', true ), ); return $columns; } protected function get_bulk_actions() { $actions = array(); if ( $this->is_trash ) { $actions['untrash'] = __( 'Restore', 'flamingo' ); } if ( $this->is_trash or ! EMPTY_TRASH_DAYS ) { $actions['delete'] = __( 'Delete permanently', 'flamingo' ); } else { $actions['trash'] = __( 'Move to trash', 'flamingo' ); } if ( $this->is_spam ) { $actions['unspam'] = __( 'Not spam', 'flamingo' ); } else { $actions['spam'] = __( 'Mark as spam', 'flamingo' ); } return $actions; } protected function extra_tablenav( $which ) { $channel = 0; if ( ! empty( $_REQUEST['channel_id'] ) ) { $term = get_term( $_REQUEST['channel_id'], Flamingo_Inbound_Message::channel_taxonomy ); if ( ! empty( $term ) and ! is_wp_error( $term ) ) { $channel = $term->term_id; } } elseif ( ! empty( $_REQUEST['channel'] ) ) { $term = get_term_by( 'slug', $_REQUEST['channel'], Flamingo_Inbound_Message::channel_taxonomy ); if ( ! empty( $term ) and ! is_wp_error( $term ) ) { $channel = $term->term_id; } } ?>