public function prepare_items() { // Columns $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); // Pagination $totalItems = $this->dataModel->getNumberOfDataItems(); $perPage = $this->get_items_per_page(AddActionsAndFilters_DataModelConfig::PER_PAGE_OPTION, AddActionsAndFilters_DataModelConfig::PER_PAGE_DEFAULT); $this->dataModel->config->setNumberPerPage($perPage); $this->dataModel->config->setPage($this->get_pagenum()); $this->set_pagination_args(array('total_items' => $totalItems, 'per_page' => $perPage, 'total_pages' => ceil($totalItems / $perPage))); // Data $search = isset($_REQUEST['s']) ? $_REQUEST['s'] : false; $this->items = $this->dataModel->getDataItemList($search); }
/** * Perform actions when upgrading from version X to version Y * See: http://plugin.michael-simpson.com/?page_id=35 * @return void */ public function upgrade() { $upgradeOk = true; $savedVersion = $this->getVersionSaved(); if ($this->isVersionLessThan($savedVersion, '2.0.2')) { // Make these options cached by WP $value = $this->getOption('AllowExecOnLoginPage', 'false', true); $this->addOption('AllowExecOnLoginPage', $value); $value = $this->getOption('DropOnUninstall', 'false', true); $this->addOption('DropOnUninstall', $value); if ($this->isVersionLessThan($savedVersion, '2.0')) { $this->installDatabaseTables(); $code = $this->getOption('code'); if ($code) { // Copy code from old version into new table $codeItem = array(); $codeItem['shortcode'] = false; $codeItem['inadmin'] = true; $codeItem['name'] = 'Code'; $codeItem['description'] = ''; $codeItem['enabled'] = true; $codeItem['code'] = $code; require_once 'AddActionsAndFilters_DataModel.php'; $dataModel = new AddActionsAndFilters_DataModel($this, null); $dataModel->saveItem($codeItem); //$this->deleteOption('code'); // keep it as a backup for now } } } // Post-upgrade, set the current version in the options $codeVersion = $this->getVersion(); if ($upgradeOk && $savedVersion != $codeVersion) { $this->saveInstalledVersion(); } }
public function ajaxSave() { if (current_user_can('manage_options')) { if (ob_get_length()) { // eliminate any debug output from polluting the ajax return value // https://codex.wordpress.org/AJAX_in_Plugins ob_clean(); } if (!headers_sent()) { // Don't let IE cache this request header('Pragma: no-cache'); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); header('Content-type: text/plain'); } require_once 'AddActionsAndFilters_DataModelConfig.php'; require_once 'AddActionsAndFilters_DataModel.php'; $config = new AddActionsAndFilters_DataModelConfig(); $dataModel = new AddActionsAndFilters_DataModel($this->plugin, $config); $id = $dataModel->saveItem($_REQUEST); echo $id; die; } else { die(-1); } }
public function importScepShortCodes() { $dataModel = new AddActionsAndFilters_DataModel($this->plugin, null); foreach ($_REQUEST as $key => $value) { if ($value == 'true') { $shortCode = array(); $shortCode['shortcode'] = true; $shortCode['name'] = $key; $shortCode['description'] = get_option("scep_description_{$key}"); $shortCode['enabled'] = get_option("scep_enabled_{$key}"); $shortCode['buffer'] = get_option("scep_buffer_{$key}"); $shortCode['code'] = get_option("scep_phpcode_{$key}"); $shortCode['inadmin'] = 0; $shortCode['capability'] = ''; //$buffer = get_option("scep_buffer_$key"); //$param = get_option("scep_param_$key"); $id = $dataModel->saveItem($shortCode); $url = $this->plugin->getAdminPageUrl() . "&id={$id}&action=edit"; echo __('Imported', 'add-actions-and-filters') . " <a target='_blank' href='{$url}'>{$key}</a></br>"; // Deactivate SCEP shortcode update_option("scep_enabled_{$key}", 0); } } }