Skip to content

Commit

Permalink
Update dropdowns in admin screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Dec 17, 2023
1 parent d81b6ce commit 8854459
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
14 changes: 8 additions & 6 deletions includes/class-geo-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ public static function init() {

add_action( 'rest_api_init', array( __CLASS__, 'rest_location' ) );

// Add Dropdown.
add_action( 'restrict_manage_posts', array( __CLASS__, 'geo_posts_dropdown' ), 12, 2 );
add_action( 'restrict_manage_comments', array( __CLASS__, 'geo_comments_dropdown' ), 12 );

// Add the Same Post Type Support JetPack uses.
add_post_type_support( 'post', 'geo-location' );
add_post_type_support( 'page', 'geo-location' );
add_post_type_support( 'attachment', 'geo-location' );

// Add Dropdown.
add_action( 'restrict_manage_posts', array( __CLASS__, 'geo_posts_dropdown' ), 12, 2 );
add_action( 'restrict_manage_comments', array( __CLASS__, 'geo_comments_dropdown' ), 12 );


add_filter( 'bulk_actions-edit-post', array( __CLASS__, 'register_bulk_edit_location' ), 10 );
add_filter( 'handle_bulk_actions-edit-post', array( __CLASS__, 'handle_bulk_edit_location' ), 10, 3 );
add_action( 'admin_notices', array( __CLASS__, 'bulk_action_admin_notices' ) );
Expand Down Expand Up @@ -454,15 +455,16 @@ public static function geo_public_select( $public, $echo = false ) {
* @since 1.0.0
*/
public static function geo_posts_dropdown( $post_type, $which ) {
if ( 'post' !== $post_type ) {
if ( ! post_type_supports( $post_type, 'geo-location' ) ) {
return;
}
$type = get_post_type_object( $post_type );
$selected = 'none';
if ( isset( $_REQUEST['geo'] ) ) {
$selected = sanitize_text_field( $_REQUEST['geo'] );
}
$list = array(
'none' => esc_html__( 'All Posts', 'simple-location' ),
'none' => $type->labels->all_items,
'all' => esc_html__( 'With Location', 'simple-location' ),
'private' => esc_html__( 'Private', 'simple-location' ),
'public' => esc_html__( 'Public', 'simple-location' ),
Expand Down
34 changes: 34 additions & 0 deletions includes/class-location-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function init() {
add_filter( 'manage_edit-location_columns', array( __CLASS__, 'manage_column' ), 10 );
add_filter( 'taxonomy_parent_dropdown_args', array( __CLASS__, 'taxonomy_parent_dropdown_args' ), 10, 3 );
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
add_action( 'restrict_manage_posts', array( __CLASS__, 'location_dropdown' ), 12, 2 );

add_filter( 'get_the_archive_title', array( __CLASS__, 'archive_title' ), 10 );
add_filter( 'get_pages_query_args', array( __CLASS__, 'get_pages_query_args' ), 10, 2 );
Expand Down Expand Up @@ -75,6 +76,39 @@ public static function manage_column_content( $content, $column_name, $term_id )
return $content;
}

/**
* Generates a dropdown
*
* Allows visibility to be filtered on post edit screen.
*
* @param string $post_type The post type slug.
* @param string $which The location of the extra table nav markup:
* 'top' or 'bottom' for WP_Posts_List_Table,
* 'bar' for WP_Media_List_Table.
* @since 1.0.0
*/
public static function location_dropdown( $post_type, $which ) {
if ( ! post_type_supports( $post_type, 'geo-location' ) ) {
return;
}
$type = get_post_type_object( $post_type );
$selected = '';
if ( isset( $_REQUEST['location'] ) ) {
$selected = sanitize_text_field( $_REQUEST['location'] );
}
wp_dropdown_categories(
array(
'name' => 'location',
'id' => 'location',
'show_option_none' => $type->labels->all_items,
'hierarchical' => true,
'taxonomy' => 'location',
'value_field' => 'slug',
'selected' => $selected
)
);
}

/**
* Filters Location in Posts.
*
Expand Down

0 comments on commit 8854459

Please sign in to comment.