$goal) { if ($_REQUEST['goal_status'] == 'active' && $goal['active']) { $goals[$key] = $goal; } elseif ($_REQUEST['goal_status'] == 'inactive' && !$goal['active']) { $goals[$key] = $goal; } } $args['goals'] = $goals; } } // because this isn't hacky, right? lol if (!empty($_GET['action']) && ($_GET['action'] == 'activate' || $_GET['action'] == 'deactivate')) { $_SERVER['REQUEST_URI'] = remove_query_arg(array('id', 'action', '_wpnonce'), $_SERVER['REQUEST_URI']); } parent::__construct($args); } protected function _getCurrentUrl() { return set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } public function ajax_user_can() { return current_user_can('manage_options'); } public function prepare_items() { global $totals, $status; $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->items = $this->_args['goals']; if (!empty($_REQUEST['orderby'])) { $sortOrders = array( 'name' => array('key' => 'name', 'type' => SORT_STRING), 'slot' => array('key' => 'id', 'type' => SORT_NUMERIC), 'value' => array('key' => 'value', 'type' => SORT_NUMERIC), 'created' => array('key' => 'created', 'type' => SORT_STRING), 'updated' => array('key' => 'updated', 'type' => SORT_STRING), ); if (!empty($sortOrders[$_REQUEST['orderby']])) { $sortOrder = array(); foreach($this->items as $item) { $sortOrder[] = strtolower($item[$sortOrders[$_REQUEST['orderby']]['key']]); } array_multisort($sortOrder, (!empty(@$_REQUEST['order']) && $_REQUEST['order'] == 'desc' ? SORT_DESC : SORT_ASC), $sortOrders[$_REQUEST['orderby']]['type'], $this->items); } } $this->set_pagination_args( array( 'total_items' => (@$totals[$status] + 0), 'per_page' => 1000, )); } protected function get_table_classes() { return array('goals', 'widefat', $this->_args['plural'] ); } public function get_columns() { return array( 'cb' => '', 'name' => esc_html__('Name', 'better-analytics'), 'slot' => esc_html__('Slot', 'better-analytics'), 'value' => esc_html__('Value', 'better-analytics'), 'created' => esc_html__('Created', 'better-analytics'), 'updated' => esc_html__('Updated', 'better-analytics'), ); } protected function get_sortable_columns() { return array( 'name' => array('name', false), 'slot' => array('slot', false), 'value' => array('value', true), 'created' => array('created', true), 'updated' => array('updated', true), ); } protected function get_views() { global $totals, $status; $status_links = array(); foreach ($totals as $type => $count) { if (!$count) { continue; } switch ( $type ) { case 'all': /* translators: %1$s = label, %2$s = , %3$s = , %4$u = number */ $text = sprintf(esc_html__('%1$s %2$s(%4$u)%3$s', 'better-analytics'), _n('All', 'All', $count), '', '', $count ); break; case 'active': /* translators: %1$s = label, %2$s = , %3$s = , %4$u = number */ $text = sprintf(esc_html__('%1$s %2$s(%4$u)%3$s', 'better-analytics'), _n('Active', 'Active', $count), '', '', $count ); break; case 'inactive': /* translators: %1$s = label, %2$s = , %3$s = , %4$u = number */ $text = sprintf(esc_html__('%1$s %2$s(%4$u)%3$s', 'better-analytics'), _n('Inactive', 'Inactive', $count), '', '', $count ); } if ( 'search' != $type ) { $status_links[$type] = sprintf( "%s", add_query_arg('goal_status', $type, menu_page_url('better-analytics_goals', false)), ( $type == $status ) ? ' class="current"' : '', sprintf( $text, number_format_i18n( $count ) ) ); } } return $status_links; } protected function get_bulk_actions() { global $status; $actions = array(); if ($status != 'active') { $actions['activate-selected'] = esc_html__('Activate', 'better-analytics'); } if ( $status != 'inactive') { $actions['deactivate-selected'] = esc_html__('Deactivate', 'better-analytics'); } return $actions; } public function single_row($item) { echo '