base = $base; parent::__construct( array( 'singular' => 'wpzinc-social-log', // Singular label. 'plural' => 'wpzinc-social-log', // plural label, also this well be one of the table css class. 'ajax' => false, // We won't support Ajax for this table. ) ); } /** * Display dropdowns for Bulk Actions and Filtering. * * @since 3.9.6 * * @param string $which The location of the bulk actions: 'top' or 'bottom'. * This is designated as optional for backward compatibility. */ protected function bulk_actions( $which = '' ) { // Get Bulk Actions. $this->_actions = $this->get_bulk_actions(); // Define _actions as $name => $title ) { ?> base->get_class( 'log' )->get_profile_id_names(); ?> - 'doaction' ) ); $clear_logs_url = add_query_arg( array( 'page' => $this->base->plugin->name . '-log', 'bulk_action3' => 'delete_all', '_wpnonce' => wp_create_nonce( 'bulk-wpzinc-social-log' ), ), admin_url( 'admin.php' ) ); ?> base->get_class( 'common' )->get_log_filters() as $filter ) { $filters_values[ $filter ] = false; } // If a nonce is present, read the request. if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { foreach ( $this->base->get_class( 'common' )->get_log_filters() as $filter ) { if ( ! array_key_exists( $filter, $_REQUEST ) ) { continue; } $filters_values[ $filter ] = sanitize_text_field( wp_unslash( $_REQUEST[ $filter ] ) ); } } $input_id = $input_id . '-search-input'; // Preserve Filters by storing any defined as hidden form values. foreach ( $this->base->get_class( 'common' )->get_log_filters() as $filter ) { if ( $filters_values[ $filter ] !== false ) { ?> '', 'post_id' => __( 'Post ID', 'wp-to-buffer' ), 'request_sent' => __( 'Request Sent', 'wp-to-buffer' ), 'action' => __( 'Action', 'wp-to-buffer' ), 'profile_name' => __( 'Profile', 'wp-to-buffer' ), 'status_text' => __( 'Status Text', 'wp-to-buffer' ), 'result' => __( 'Result', 'wp-to-buffer' ), 'result_message' => __( 'Response', 'wp-to-buffer' ), 'status_created_at' => sprintf( /* translators: Social Media Service Name (Buffer, Hootsuite) */ __( '%s: Status Created At', 'wp-to-buffer' ), $this->base->plugin->account ), 'status_due_at' => sprintf( /* translators: Social Media Service Name (Buffer, Hootsuite) */ __( '%s: Status Scheduled For', 'wp-to-buffer' ), $this->base->plugin->account ), ); } /** * Decide which columns to activate the sorting functionality on * * @since 3.9.6 * * @return array Columns that can be sorted by the user */ public function get_sortable_columns() { return array( 'post_id' => array( 'post_id', true ), 'request_sent' => array( 'request_sent', true ), 'action' => array( 'action', true ), 'profile_name' => array( 'profile_name', true ), 'status_text' => array( 'status_text', true ), 'result' => array( 'result', true ), 'result_message' => array( 'result_message', true ), 'status_created_at' => array( 'status_created_at', true ), 'status_due_at' => array( 'status_due_at', true ), ); } /** * Overrides the list of bulk actions in the select dropdowns above and below the table * * @since 3.9.6 * * @return array Bulk Actions */ public function get_bulk_actions() { return array( 'delete' => __( 'Delete', 'wp-to-buffer' ), ); } /** * Prepare the table with different parameters, pagination, columns and table elements * * @since 3.9.6 */ public function prepare_items() { global $_wp_column_headers; $screen = get_current_screen(); // Get params. $params = $this->get_search_params(); $order_by = $this->get_order_by(); $order = $this->get_order(); $page = $this->get_page(); $per_page = $this->get_items_per_page( $this->base->plugin->filter_name . '_logs_per_page', 20 ); // Get total records for this query. $total = $this->base->get_class( 'log' )->total( $params ); // Define pagination. $this->set_pagination_args( array( 'total_items' => $total, 'total_pages' => (int) ceil( $total / $per_page ), 'per_page' => $per_page, ) ); // Set column headers. $this->_column_headers = $this->get_column_info(); // Set rows. $this->items = $this->base->get_class( 'log' )->search( $order_by, $order, $page, $per_page, $params ); } /** * Generate the table navigation above or below the table * * @since 3.1.0 * * @param string $which The location of the bulk actions: 'top' or 'bottom'. * This is designated as optional for backward compatibility. */ protected function display_tablenav( $which ) { if ( 'top' === $which ) { wp_nonce_field( 'bulk-' . $this->_args['plural'] ); } ?>
bulk_actions( $which ); ?>
extra_tablenav( $which ); $this->pagination( $which ); ?>
base->get_class( 'log' )->build_log_table_output( $this->items, true, $this->_column_headers ), array( 'tr' => array( 'class' => array(), ), 'th' => array( 'scope' => array(), 'class' => array(), ), 'td' => array( 'class' => array(), ), 'a' => array( 'href' => array(), 'target' => array(), ), 'br' => array(), 'input' => array( 'type' => array( 'checkbox', ), 'name' => array(), 'value' => array(), ), ) ); } /** * Get search parameters. * * @since 3.9.6 * * @return array Search Parameters */ private function get_search_params() { // Build search params. $params = array( 'action' => $this->get_action(), 'profile_id' => $this->get_profile_id(), 'result' => $this->get_result(), 'request_sent_start_date' => $this->get_request_sent_start_date(), 'request_sent_end_date' => $this->get_request_sent_end_date(), ); // Return params if freeform search isn't supplied. if ( ! filter_has_var( INPUT_GET, 's' ) ) { return $params; } // Get search. $search = filter_input( INPUT_GET, 's', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // If search is a number, add it as the Post ID and return. if ( is_numeric( $search ) ) { $params['post_id'] = absint( $search ); return $params; } // Add it as the Post Title and return. $params['post_title'] = $search; return $params; } /** * Returns whether a search has been performed on the table. * * @since 3.9.0 * * @return bool Search has been performed. */ public function is_search() { return filter_has_var( INPUT_GET, 's' ); } /** * Get the Search requested by the user * * @since 3.9.0 * * @return string */ public function get_search() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 's', $_REQUEST ) ) { return ''; } return urldecode( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) ); } /** * Get the Action Filter requested by the user * * @since 3.9.7 * * @return string */ private function get_action() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 'action', $_REQUEST ) ) { return ''; } return sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); } /** * Get the Profile ID Filter requested by the user * * @since 3.9.7 * * @return string */ private function get_profile_id() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 'profile_id', $_REQUEST ) ) { return ''; } return sanitize_text_field( wp_unslash( $_REQUEST['profile_id'] ) ); } /** * Get the Status Result Filter requested by the user * * @since 3.9.7 * * @return string */ private function get_result() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 'result', $_REQUEST ) ) { return ''; } return sanitize_text_field( wp_unslash( $_REQUEST['result'] ) ); } /** * Get the Request Sent Start Date Filter requested by the user * * @since 3.9.8 * * @return string */ private function get_request_sent_start_date() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 'request_sent_start_date', $_REQUEST ) ) { return ''; } return sanitize_text_field( wp_unslash( $_REQUEST['request_sent_start_date'] ) ); } /** * Get the Request Sent End Date Filter requested by the user * * @since 3.9.8 * * @return string */ private function get_request_sent_end_date() { // Bail if nonce is not valid. if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-wpzinc-social-log' ) ) { return ''; } if ( ! array_key_exists( 'get_request_sent_end_date', $_REQUEST ) ) { return ''; } return sanitize_text_field( wp_unslash( $_REQUEST['get_request_sent_end_date'] ) ); } /** * Get the Order By requested by the user * * @since 3.9.7 * * @return string */ private function get_order_by() { // Don't nonce check because order by may not include a nonce if no search performed. if ( ! filter_has_var( INPUT_GET, 'orderby' ) ) { return 'request_sent'; } return filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); } /** * Get the Order requested by the user * * @since 3.9.7 * * @return string */ private function get_order() { // Don't nonce check because order may not include a nonce if no search performed. if ( ! filter_has_var( INPUT_GET, 'order' ) ) { return 'DESC'; } return filter_input( INPUT_GET, 'order', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); } /** * Get the Pagination Page requested by the user * * @since 3.9.7 * * @return int */ private function get_page() { // Don't nonce check because pagination may not include a nonce if no search performed. if ( ! filter_has_var( INPUT_GET, 'paged' ) ) { return 1; } return absint( filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ); } }