/** * @param null|false|string $search * @return array|null|object */ public function getDataItemList($search = null) { global $wpdb; $this->plugin->ensureDatabaseTableInstalled(); // ensure created in multisite $table = $this->plugin->getTableName(); $orderby = $this->config->getOrderby(); $asc = $this->config->isAsc() ? 'asc' : 'desc'; $numPerPage = $this->config->getNumberPerPage(); $limit = sprintf('%d,%d', ($this->config->getPage() - 1) * $numPerPage, $numPerPage); $sql = "select id, enabled, shortcode, name, capability, description from {$table}"; if ($search) { $param = "%{$search}%"; $sql .= $wpdb->prepare(' where name like %s or description like %s', $param, $param); } $sql .= " order by {$orderby} {$asc} limit {$limit}"; return $wpdb->get_results($sql, ARRAY_A); }
/** * Handle the URL request for the WP dashboard admin page. * Handle any actions indicated in the URL GET parameters */ function handleAdminPageUrl() { $this->plugin->securityCheck(); // set-screen-option callback - does not work // this is the work-around if (isset($_REQUEST['wp_screen_options']) && is_array($_REQUEST['wp_screen_options'])) { AddActionsAndFilters_ViewAdminPage::setScreenOptionCallback($_REQUEST['wp_screen_options']['option'], $_REQUEST['wp_screen_options']['value']); } require_once 'AddActionsAndFilters_DataModelConfig.php'; require_once 'AddActionsAndFilters_DataModel.php'; // Look for Sorting, ordering and searching $config = new AddActionsAndFilters_DataModelConfig(); if (isset($_REQUEST['orderby'])) { $config->setOrderby($_REQUEST['orderby']); } if (isset($_REQUEST['order'])) { $config->setAsc($_REQUEST['order'] != 'desc'); } if (isset($_REQUEST['s'])) { $config->setSearch($_REQUEST['s']); } // Init DataModel and Table $dataModel = new AddActionsAndFilters_DataModel($this->plugin, $config); require_once 'AddActionsAndFilters_CodeListTable.php'; $table = new AddActionsAndFilters_CodeListTable($dataModel); // May be changed if a different page is to be displayed $showAdminPage = true; // Look for actions to be performed $action = $table->current_action(); if ($action && $action != -1) { require_once 'AddActionsAndFilters_AdminPageActions.php'; $actions = new AddActionsAndFilters_AdminPageActions(); $ids = null; if (isset($_REQUEST['cb']) && is_array($_REQUEST['cb'])) { // check nonce which is on the bulk action form only if ($table->verifyBulkNonce($_REQUEST['_wpnonce'])) { $ids = $_REQUEST['cb']; } } else { if (isset($_REQUEST['id'])) { $ids = array($_REQUEST['id']); } else { if (isset($_REQUEST['ids'])) { $ids = explode(',', $_REQUEST['ids']); } } } // Perform Actions if ($action == $actions->getEditKey()) { $item = isset($_REQUEST['id']) ? $dataModel->getDataItem($_REQUEST['id']) : array(); $showAdminPage = false; // show edit page instead $this->plugin->displayEditPage($item); } else { if ($ids) { switch ($action) { case $actions->getActivateKey(): $dataModel->activate($ids, true); break; case $actions->getDeactivateKey(): $dataModel->activate($ids, false); break; case $actions->getDeleteKey(): $dataModel->delete($ids); break; case $actions->getExportKey(): if (!empty($ids)) { require_once 'AddActionsAndFilters_ViewImportExport.php'; $view = new AddActionsAndFilters_ViewImportExport($this->plugin); $view->outputBulkExport($ids); } break; default: break; } } } } // Display Admin Page if ($showAdminPage) { $table->prepare_items(); $this->displayAdminTable($table); } }