function __construct($post_type, $post_parent = null) { global $post_type_object; $this->post_type = $post_type; $this->post_parent = $post_parent; parent::__construct(); $post_type_object = get_post_type_object($this->post_type); }
/** * @ticket 37407 */ function test_category_dropdown_should_not_be_shown_if_there_are_no_posts() { // Set post type to a non-existent one. $this->table->screen->post_type = 'foo'; ob_start(); $this->table->extra_tablenav('top'); $output = ob_get_clean(); $this->assertNotContains('id="cat"', $output); }
function __construct($args = array()) { global $frontend_uploader; $screen = get_current_screen(); if ($screen->post_type == '') { $screen->post_type = 'post'; } add_filter("{$screen->post_type}_row_actions", array($this, '_add_row_actions'), 10, 2); parent::__construct(array('screen' => $screen)); }
function __construct() { global $frontend_uploader; $screen = get_current_screen(); if ($screen->post_type == '') { $screen->post_type = 'post'; } foreach ((array) $frontend_uploader->settings['enabled_post_types'] as $post_type) { add_filter("{$post_type}_row_actions", array($this, '_add_row_actions'), 10, 2); } parent::__construct(array('screen' => $screen)); }
} } if ($post_type_object->public) { if (in_array($post->post_status, array('pending', 'draft', 'future'))) { if ($can_edit_post) { $preview_link = set_url_scheme(get_permalink($post->ID)); /** This filter is documented in wp-admin/includes/meta-boxes.php */ $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_link), $post); $actions['view'] = '<a href="' . esc_url($preview_link) . '" title="' . esc_attr(sprintf(__('Preview “%s”'), $title)) . '" rel="permalink">' . __('Preview') . '</a>'; } } elseif ('trash' != $post->post_status) { $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View “%s”'), $title)) . '" rel="permalink">' . __('View') . '</a>'; } } // invoke row actions $table = new WP_Posts_List_Table(); echo $table->row_actions($actions, true); break; } }, 10, 2); /* | ------- | # Query | ------- */ add_filter('posts_search', 'db_filter_authors_search'); function db_filter_authors_search($posts_search) { // Don't modify the query at all if we're not on the search template // or if the LIKE is empty if (!is_search() || empty($posts_search)) {
/** * Sets team parameters based on actions taken in Team admin UI. * * @link https://developer.wordpress.org/reference/hooks/current_screen/ * * @global $_POST * @global $_GET * * @uses WP_Screen::$post_type * @uses WP_Posts_List_Table::current_action() * @uses WP_Buoy_User_Settings::set() * @uses WP_Buoy_User_Settings::save() * @uses Buoy_Team_Membership_List_Table::current_action() * @uses wp_verify_nonce() * @uses WP_Buoy_Team::remove_member() * @uses WP_Buoy_Team::confirm_member() * * @param WP_Screen $current_screen * * @return void */ public static function processTeamTableActions($current_screen) { $post_type = self::$prefix . '_team'; if ($post_type !== $current_screen->post_type) { return; } if ('post' === $current_screen->base) { // The "My Teams" page. $table = new WP_Posts_List_Table(); if ('make_default' === $table->current_action()) { $team = new WP_Buoy_Team(absint($_GET['post'])); $team->make_default(); $msg = self::$prefix . '-default-team-updated'; wp_safe_redirect(admin_url("edit.php?post_type={$current_screen->post_type}&msg={$msg}")); exit; } } else { if ("{$post_type}_page_{$post_type}_membership") { // The "Team Membership" page. $table = new Buoy_Team_Membership_List_Table($post_type); $teams = array(); if (isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'single-' . $table->_args['plural'])) { $teams[] = $_GET['team_id']; } else { if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'bulk-' . $table->_args['plural'])) { $teams = array_merge($teams, $_POST['teams']); } } if (!empty($teams)) { foreach ($teams as $team_id) { $team = new self($team_id); if ('leave' === $table->current_action()) { $team->remove_member(get_current_user_id()); } if ('join' === $table->current_action()) { $team->confirm_member(get_current_user_id()); } } wp_safe_redirect(admin_url('edit.php?page=' . urlencode($_GET['page']) . '&post_type=' . urlencode($_GET['post_type']))); exit; } } } }
private function get_column_headers($omit_checkbox = true) { if (!empty($this->column_headers)) { $headers = $this->column_headers; } else { // If we're nuking the existing columns, still provide checkboxes if ($this->override) { $headers = array('cb' => '<input type="checkbox" />'); } else { // Cause infinite loops get boring after a while remove_filter('manage_' . $this->post_type . '_posts_columns', array($this, 'column_headers')); $this->load_list_table(); $list = new WP_Posts_List_Table(); $headers = $list->get_columns(); add_filter('manage_' . $this->post_type . '_posts_columns', array($this, 'column_headers')); } foreach ($this->columns as $key => $value) { $headers[$key] = $value['name']; } $this->column_headers = $headers; } if ($omit_checkbox && isset($headers['cb'])) { unset($headers['cb']); } return $headers; }
/** * Get WP default supported admin columns per post type. * * @since 1.0 */ private function get_wp_default_posts_columns($post_type = 'post') { // You can use this filter to add thirdparty columns by hooking into this. See classes/third_party.php for an example. do_action('cpac-get-default-columns-posts', $post_type); // some plugins directly hook into get_column_headers, such as woocommerce $columns = get_column_headers('edit-' . $post_type); // get default columns if (empty($columns)) { // deprecated as of wp3.3 if (file_exists(ABSPATH . 'wp-admin/includes/template.php')) { require_once ABSPATH . 'wp-admin/includes/template.php'; } // introduced since wp3.3 if (file_exists(ABSPATH . 'wp-admin/includes/screen.php')) { require_once ABSPATH . 'wp-admin/includes/screen.php'; } // used for getting columns if (file_exists(ABSPATH . 'wp-admin/includes/class-wp-list-table.php')) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } if (file_exists(ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php')) { require_once ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php'; } // As of WP Release 3.5 we can use the following. if (version_compare(get_bloginfo('version'), '3.4.10', '>=')) { $table = new WP_Posts_List_Table(array('screen' => $post_type)); $columns = $table->get_columns(); } else { // we need to change the current screen... first lets save original $org_current_screen = $current_screen; // prevent php warning if (!isset($current_screen)) { $current_screen = new stdClass(); } // overwrite current_screen global with our post type of choose... $current_screen->post_type = $post_type; // ...so we can get its columns $columns = WP_Posts_List_Table::get_columns(); // reset current screen $current_screen = $org_current_screen; } } if (empty($columns)) { return false; } // change to uniform format $columns = $this->get_uniform_format($columns); // add sorting to some of the default links columns $columns = $this->set_sorting_to_default_posts_columns($columns); return $columns; }
/** * Call this to execute the query and prepare posts for listing */ public function prepare_items() { global $post_type, $post_type_object; // make sure the globals are set correctly $post_type = $this->post_type; $post_type_object = get_post_type_object($post_type); // call parent return parent::prepare_items(); }
/** * Sets object properties and calls parent constructor * * @param int[] $article_ids IDs of articles to display */ function __construct($article_ids) { $this->article_ids = $article_ids; parent::__construct(['screen' => EDW_PRINT_ISSUE_CPT]); }