Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/248 - CPT/Taxos: unwind deep integration. #255

Draft
wants to merge 2 commits into
base: release/2.3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sugar-calendar/includes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function enqueue() {
}

// Events Pages
if ( sugar_calendar_admin_is_events_page() ) {
if ( sugar_calendar_admin_is_assets_page() ) {

// General
wp_enqueue_script( 'sugar_calendar_admin_general' );
Expand Down
33 changes: 25 additions & 8 deletions sugar-calendar/includes/admin/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ function sugar_calendar_admin_is_events_page() {

if (

// Add if the event post type
post_type_supports( $screen->post_type, 'events' )

||

// Or if Events pages
// If Events pages
sugar_calendar_get_admin_page_id() === $screen->id
) {
return true;
Expand All @@ -107,7 +102,7 @@ function sugar_calendar_admin_is_taxonomy_page() {
if (

// Add if the event post type
post_type_supports( $screen->post_type, 'events' )
sugar_calendar_is_supported_type( $screen->post_type )

&&

Expand All @@ -117,14 +112,36 @@ function sugar_calendar_admin_is_taxonomy_page() {
&&

// And is supported Taxonomy
in_array( $screen->taxonomy, sugar_calendar_get_object_taxonomies(), true )
$screen->taxonomy === sugar_calendar_get_calendar_taxonomy_id()
) {
return true;
}

return false;
}

/**
* Is this an admin page that requires assets to be enqueued?
*
* @since 2.3.0
*
* @return bool
*/
function sugar_calendar_admin_is_assets_page() {
$screen = get_current_screen();

return
sugar_calendar_admin_is_events_page()

||

sugar_calendar_admin_is_taxonomy_page()

||

sugar_calendar_is_supported_type( $screen->post_type );
}

/**
* Return the base admin-area URL.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ protected function get_views() {
protected function all_query_args( $args = array() ) {

// Maybe add `post` to to object_type's to query for
if ( post_type_supports( $this->get_screen_post_type(), 'events' ) ) {
if ( sugar_calendar_is_supported_type( $this->get_screen_post_type() ) ) {
$args['object_type'] = ! empty( $args['object_type'] )
? array_unshift( $args['object_type'], 'post' )
: array( 'post' );
Expand Down
4 changes: 2 additions & 2 deletions sugar-calendar/includes/admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function fix_menu_highlight() {
global $parent_file, $submenu_file, $pagenow;

// Highlight both, since they're the same thing.
if ( sugar_calendar_admin_is_events_page() ) {
if ( sugar_calendar_admin_is_events_page() || sugar_calendar_admin_is_taxonomy_page() ) {

// Always set the parent file to the main menu
$parent_file = 'sugar-calendar';
Expand Down Expand Up @@ -234,7 +234,7 @@ function calendar_page() {
function body_class( $class = '' ) {

// Add class if in an admin page
if ( sugar_calendar_admin_is_events_page() ) {
if ( sugar_calendar_is_admin() ) {
$class .= ' sugar-calendar';
}

Expand Down
2 changes: 1 addition & 1 deletion sugar-calendar/includes/admin/meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function can_save_meta_box( $object_id = 0, $object = null ) {
$post_type = get_post_type( $object_id );

// Only save event metadata to supported post types
if ( ! post_type_supports( $post_type, 'events' ) ) {
if ( ! sugar_calendar_is_supported_type( $post_type ) ) {
return $retval;
}

Expand Down
2 changes: 1 addition & 1 deletion sugar-calendar/includes/admin/nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function taxonomy_tabs() {

// Get taxonomies
$taxonomy = sanitize_key( $taxnow );
$post_type = sugar_calendar_allowed_post_types();
$post_type = sugar_calendar_get_event_post_type_id();
$taxonomies = sugar_calendar_get_object_taxonomies( $post_type );

// Bail if current taxonomy is not an event taxonomy
Expand Down
4 changes: 2 additions & 2 deletions sugar-calendar/includes/admin/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function updated_messages( $messages = array() ) {
function hide_quick_bulk_edit() {

// Bail if not an event post type
if ( ! post_type_supports( get_current_screen()->post_type, 'events' ) ) {
if ( ! sugar_calendar_is_supported_type( get_current_screen()->post_type ) ) {
return;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ function redirect_old_post_type() {
$args = array();

// Get allowed keys
$taxos = sugar_calendar_get_object_taxonomies();
$taxos = (array) sugar_calendar_get_calendar_taxonomy_id();

// Loop through taxonomies looking for terms
if ( ! empty( $taxos ) ) {
Expand Down
2 changes: 1 addition & 1 deletion sugar-calendar/includes/events/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ function sugar_calendar_clean_events_list_cache( $post_id = 0 ) {
$post_type = get_post_type( $post_id );

// Bail if post-type does not support events
if ( ! post_type_supports( $post_type, 'events' ) ) {
if ( ! sugar_calendar_is_supported_type( $post_type ) ) {
return;
}

Expand Down
13 changes: 13 additions & 0 deletions sugar-calendar/includes/post/types.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ function sugar_calendar_allowed_post_types() {
return apply_filters( 'sugar_calendar_allowed_post_types', $types, $supports );
}

/**
* Does a specific Post Type ID support Events?
*
* @since 2.3.0
*
* @param string $post_type
*
* @return bool
*/
function sugar_calendar_is_supported_type( $post_type = '' ) {
return post_type_supports( $post_type, 'events' );
}

/**
* Register the Event post types
*
Expand Down