diff --git a/admin-settings.php b/admin-settings.php index 19a32a7..ee20a8d 100644 --- a/admin-settings.php +++ b/admin-settings.php @@ -77,7 +77,7 @@ protected function __construct() { } // Will show thickbox of network site information - $this->thickbox_network_sites = $this->is_network_admin ? ( ' ' . __( 'View Network Site Information', 'cpt-onomies' ) . '' ) : NULL; + $this->thickbox_network_sites = $this->is_network_admin ? ( ' ' . __( 'View Network Site Information', 'cpt-onomies' ) . '' ) : null; // Adds a settings link to the plugins page add_filter( 'network_admin_plugin_action_links_' . CPT_ONOMIES_PLUGIN_FILE, array( $this, 'add_plugin_action_links' ), 10, 4 ); @@ -213,7 +213,7 @@ private function delete_conflicting_taxonomy_terms( $post_type ) { // First, we need terms info for this particular taxonomy if ( $terms_info = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE taxonomy = '{$post_type}'" ) ) { - foreach( $terms_info as $term ) { + foreach ( $terms_info as $term ) { // Delete the term $wpdb->delete( $wpdb->terms, array( 'term_id' => $term->term_id ), array( '%d' ) ); @@ -266,7 +266,7 @@ private function detect_settings_page_variables() { if ( $edit = ( ! $new && isset( $_REQUEST[ 'edit' ] ) ) ? strtolower( $_REQUEST[ 'edit' ] ) : false ) { // Check to see if CPT exists in settings - foreach( array( 'edit' ) as $cpt_key_to_check ) { + foreach ( array( 'edit' ) as $cpt_key_to_check ) { if ( ${$cpt_key_to_check} ) { // For network settings @@ -380,9 +380,9 @@ private function detect_custom_post_type_message_variables( $post_type, $CPT, $o */ public function get_network_sites() { global $wpdb; - $network_blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $wpdb->blogs . " WHERE archived IN ( 0, '0' ) ORDER BY blog_id", NULL ) ); + $network_blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $wpdb->blogs . " WHERE archived IN ( 0, '0' ) ORDER BY blog_id", null ) ); $network_blogs_details = array(); - foreach( $network_blogs as $this_blog_id ) { + foreach ( $network_blogs as $this_blog_id ) { $network_blogs_details[ $this_blog_id ] = get_blog_details( $this_blog_id ); } return $network_blogs_details; @@ -397,7 +397,7 @@ public function ajax_print_network_sites() { $network_blogs = $this->get_network_sites(); if ( ! is_multisite() ) { ?>

- +

', '' ); ?>

@@ -409,7 +409,7 @@ public function ajax_print_network_sites() { $this_blog ) { + foreach ( $network_blogs as $this_blog_id => $this_blog ) { ?> @@ -441,8 +441,8 @@ public function ajax_validate_plugin_options_if_post_type_exists() { // Get post type info $custom_post_type_onomies_is_network_admin = ( isset( $_POST[ 'custom_post_type_onomies_is_network_admin' ] ) && $_POST[ 'custom_post_type_onomies_is_network_admin' ] ) ? true : false; - $original_custom_post_type_name = ( isset( $_POST[ 'original_custom_post_type_onomies_cpt_name' ] ) && ! empty( $_POST[ 'original_custom_post_type_onomies_cpt_name' ] ) ) ? $_POST[ 'original_custom_post_type_onomies_cpt_name' ] : NULL; - $custom_post_type_name = ( isset( $_POST[ 'custom_post_type_onomies_cpt_name' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_cpt_name' ] ) ) ? $_POST[ 'custom_post_type_onomies_cpt_name' ] : NULL; + $original_custom_post_type_name = ( isset( $_POST[ 'original_custom_post_type_onomies_cpt_name' ] ) && ! empty( $_POST[ 'original_custom_post_type_onomies_cpt_name' ] ) ) ? $_POST[ 'original_custom_post_type_onomies_cpt_name' ] : null; + $custom_post_type_name = ( isset( $_POST[ 'custom_post_type_onomies_cpt_name' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_cpt_name' ] ) ) ? $_POST[ 'custom_post_type_onomies_cpt_name' ] : null; if ( ( ( ! empty( $original_custom_post_type_name ) && ! empty( $custom_post_type_name ) && $custom_post_type_name != $original_custom_post_type_name ) || ( empty( $original_custom_post_type_name ) && ! empty( $custom_post_type_name ) ) ) && ( ( $custom_post_type_onomies_is_network_admin && array_key_exists( $custom_post_type_name, $cpt_onomies_manager->user_settings[ 'network_custom_post_types' ] ) ) || ( ! $custom_post_type_onomies_is_network_admin && ( ( post_type_exists( $custom_post_type_name ) && ( ! $cpt_onomies_manager->is_registered_network_cpt( $custom_post_type_name ) ) ) || array_key_exists( $custom_post_type_name, $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) ) ) ) { echo false; @@ -467,7 +467,7 @@ public function ajax_update_plugin_options_edit_custom_post_type_closed_edit_tab global $user_ID; // Get the table we're editing - $edit_table = ( isset( $_POST[ 'custom_post_type_onomies_edit_table' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_edit_table' ] ) ) ? $_POST[ 'custom_post_type_onomies_edit_table' ] : NULL; + $edit_table = ( isset( $_POST[ 'custom_post_type_onomies_edit_table' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_edit_table' ] ) ) ? $_POST[ 'custom_post_type_onomies_edit_table' ] : null; if ( $edit_table ) { $show = $_POST[ 'custom_post_type_onomies_edit_table_show' ]; @@ -491,9 +491,9 @@ public function ajax_update_plugin_options_edit_custom_post_type_closed_edit_tab } // We need to make sure its removed from the array - else if ( ! empty( $saved_option ) && in_array( $edit_table, $saved_option ) ) { + elseif ( ! empty( $saved_option ) && in_array( $edit_table, $saved_option ) ) { - foreach( $saved_option as $key => $value ) { + foreach ( $saved_option as $key => $value ) { if ( $value == $edit_table ) { unset( $saved_option[ $key ] ); } @@ -517,7 +517,7 @@ public function ajax_update_plugin_options_edit_custom_post_type_closed_edit_tab */ public function ajax_update_plugin_options_edit_custom_post_type_closed_dismiss() { global $user_ID; - $dismiss_id = ( isset( $_POST[ 'custom_post_type_onomies_dismiss_id' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_dismiss_id' ] ) ) ? $_POST[ 'custom_post_type_onomies_dismiss_id' ] : NULL; + $dismiss_id = ( isset( $_POST[ 'custom_post_type_onomies_dismiss_id' ] ) && ! empty( $_POST[ 'custom_post_type_onomies_dismiss_id' ] ) ) ? $_POST[ 'custom_post_type_onomies_dismiss_id' ] : null; if ( $dismiss_id ) { // Get set option @@ -648,12 +648,12 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ if ( current_user_can( $this->manage_options_capability ) && ! empty( $custom_post_types ) ) { // If set, will redirect settings page to show specified custom post type - $redirect_cpt = NULL; + $redirect_cpt = null; - foreach( $custom_post_types as $cpt_key => $cpt ) { + foreach ( $custom_post_types as $cpt_key => $cpt ) { // Sanitize the data - foreach( $cpt as $key => $data ) { + foreach ( $cpt as $key => $data ) { if ( ! is_array( $data ) ) { $cpt[ $key ] = strip_tags( $data ); } @@ -662,9 +662,9 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ // Maximum is 20 characters. Can only contain lowercase, alphanumeric characters and underscores $valid_name_preg_test = '/([^a-z0-9\_])/i'; - $original_name = ( isset( $cpt[ 'original_name' ] ) && ! empty( $cpt[ 'original_name' ] ) && strlen( $cpt[ 'original_name' ] ) <= 20 && ! preg_match( $valid_name_preg_test, $cpt[ 'original_name' ] ) ) ? strtolower( $cpt[ 'original_name' ] ) : NULL; - $new_name = ( isset( $cpt[ 'name' ] ) && ! empty( $cpt[ 'name' ] ) && strlen( $cpt[ 'name' ] ) <= 20 && ! preg_match( $valid_name_preg_test, $cpt[ 'name' ] ) ) ? strtolower( $cpt[ 'name' ] ) : NULL; - $label = ( isset( $cpt[ 'label' ] ) && ! empty( $cpt[ 'label' ] ) ) ? $cpt[ 'label' ] : NULL; + $original_name = ( isset( $cpt[ 'original_name' ] ) && ! empty( $cpt[ 'original_name' ] ) && strlen( $cpt[ 'original_name' ] ) <= 20 && ! preg_match( $valid_name_preg_test, $cpt[ 'original_name' ] ) ) ? strtolower( $cpt[ 'original_name' ] ) : null; + $new_name = ( isset( $cpt[ 'name' ] ) && ! empty( $cpt[ 'name' ] ) && strlen( $cpt[ 'name' ] ) <= 20 && ! preg_match( $valid_name_preg_test, $cpt[ 'name' ] ) ) ? strtolower( $cpt[ 'name' ] ) : null; + $label = ( isset( $cpt[ 'label' ] ) && ! empty( $cpt[ 'label' ] ) ) ? $cpt[ 'label' ] : null; // If no valid name or label, why bother so remove the data if ( empty( $original_name ) && empty( $new_name ) && empty( $label ) ) { @@ -690,7 +690,7 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ } // Will be the name and key for storing data - $store_name = NULL; + $store_name = null; /** * If no original name (new) and new name is empty @@ -716,7 +716,7 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ } // The name was empty so we made one up - else if ( empty( $new_name ) ) { + elseif ( empty( $new_name ) ) { add_settings_error( CPT_ONOMIES_OPTIONS_PAGE . '-custom-post-types', 'custom-post-type-onomies-custom-post-types-error', sprintf( __( 'You did not provide a "name" for your custom post type so %1$s just made one up. If "%2$s" doesn\'t work for you, then make sure you edit the name property below.', 'cpt-onomies' ), 'CPT-onomies', $store_name ), 'error' ); } @@ -734,13 +734,13 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ } // If no new name and original name exists then save under original name - else if ( empty( $new_name ) && ! empty( $original_name ) ) { + elseif ( empty( $new_name ) && ! empty( $original_name ) ) { $store_name = $original_name; } // If both original and new name exist and new is different from original // BUT new name already exists elsewhere - else if ( ! empty( $original_name ) && ! empty( $new_name ) && $new_name != $original_name && array_key_exists( $new_name, $saved_custom_post_types ) ) { + elseif ( ! empty( $original_name ) && ! empty( $new_name ) && $new_name != $original_name && array_key_exists( $new_name, $saved_custom_post_types ) ) { // Store under original name $store_name = $original_name; @@ -755,7 +755,7 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ * different from original then remove info with * original name and save under new name. */ - else if ( ! empty( $original_name ) && ! empty( $new_name ) && $new_name != $original_name ) { + elseif ( ! empty( $original_name ) && ! empty( $new_name ) && $new_name != $original_name ) { // Remove original name if ( array_key_exists( $original_name, $saved_custom_post_types ) ) { @@ -802,7 +802,7 @@ public function validate_plugin_options_custom_post_types( $custom_post_types, $ // Must be numeric if ( isset( $cpt[ 'menu_position' ] ) && ! empty( $cpt[ 'menu_position' ] ) && is_numeric( $cpt[ 'menu_position' ] ) ) { $cpt['menu_position'] = intval( $cpt['menu_position'] ); - } else if ( isset( $cpt[ 'menu_position' ] ) && ! empty( $cpt[ 'menu_position' ] ) ) { + } elseif ( isset( $cpt[ 'menu_position' ] ) && ! empty( $cpt[ 'menu_position' ] ) ) { unset( $cpt['menu_position'] ); } @@ -856,13 +856,13 @@ public function update_validate_plugin_options_other_custom_post_types( $other_c // Save information if ( ! empty( $other_custom_post_types ) ) { - foreach( $other_custom_post_types as $cpt_key => $cpt ) { + foreach ( $other_custom_post_types as $cpt_key => $cpt ) { $saved_other_post_types[ $cpt_key ] = $cpt; } } // Post types that no longer exist are removed from the settings - foreach( $saved_other_post_types as $cpt_key => $cpt ) { + foreach ( $saved_other_post_types as $cpt_key => $cpt ) { $post_type_exists = post_type_exists( $cpt_key ); if ( ! $post_type_exists || ( $post_type_exists && ( $cpt_onomies_manager->is_registered_cpt( $cpt_key ) ) ) ) { unset( $saved_other_post_types[ $cpt_key ] ); @@ -899,14 +899,14 @@ public function update_validate_plugin_options_other_custom_post_types( $other_c * * @since 1.0 * @uses $cpt_onomies_manager - * @param string $post_type_being_edited - the custom post type that's being edited. NULL if creating a new custom post type. + * @param string $post_type_being_edited - the custom post type that's being edited. null if creating a new custom post type. * @return object - the custom post type properties * @filters 'custom_post_type_onomies_attach_to_post_type_property_include_post_type' - $post_type_to_include, $post_type_being_edited * 'custom_post_type_onomies_taxonomies_property_include_taxonomy' - $taxonomy, $post_type_being_edited * 'custom_post_type_onomies_restrict_user_capabilities_property_include_user_role' - $user_role, $post_type_being_edited * 'custom_post_type_onomies_supports_property_include_support' - $support, $post_type_being_edited */ - public function get_plugin_options_page_cpt_properties( $post_type_being_edited = NULL ) { + public function get_plugin_options_page_cpt_properties( $post_type_being_edited = null ) { global $cpt_onomies_manager; if ( current_user_can( $this->manage_options_capability ) ) { @@ -919,7 +919,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited $saved_custom_post_type_data = $cpt_onomies_manager->user_settings['network_custom_post_types']; } - } else if ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { + } elseif ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { $saved_custom_post_type_data = $cpt_onomies_manager->user_settings['custom_post_types']; } @@ -936,7 +936,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited if ( $this->is_network_admin ) { // Combine saved custom post type data with remaining builtin post types (posts and pages) - foreach( array_merge( get_post_types( array( '_builtin' => true ), 'objects' ), $saved_custom_post_type_data ) as $cpt_key => $cpt ) { + foreach ( array_merge( get_post_types( array( '_builtin' => true ), 'objects' ), $saved_custom_post_type_data ) as $cpt_key => $cpt ) { $cpt = (object) $cpt; if ( ! empty( $cpt_key ) && ! in_array( $cpt_key, $do_not_add_to_post_type_data ) ) { @@ -946,10 +946,10 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited } // Make sure label exists - $label = NULL; + $label = null; if ( isset( $cpt->labels ) && isset( $cpt->labels->name ) && ! empty( $cpt->labels->name ) ) { $label = $cpt->labels->name; - } else if ( isset( $cpt->label ) && ! empty( $cpt->label ) ) { + } elseif ( isset( $cpt->label ) && ! empty( $cpt->label ) ) { $label = $cpt->label; } @@ -966,7 +966,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited } else { - foreach( get_post_types( array(), 'objects' ) as $cpt_key => $cpt ) { + foreach ( get_post_types( array(), 'objects' ) as $cpt_key => $cpt ) { if ( ! empty( $cpt_key ) && ! in_array( $cpt_key, $do_not_add_to_post_type_data ) && ! empty( $cpt->labels->name ) ) { $attach_to_post_type_data[ $cpt_key ] = (object) array( @@ -980,7 +980,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited } // Get deactivated post types created by plugin - foreach( $saved_custom_post_type_data as $cpt_key => $cpt ) { + foreach ( $saved_custom_post_type_data as $cpt_key => $cpt ) { if ( isset( $cpt[ 'deactivate' ] ) && $cpt[ 'deactivate' ] ) { if ( ! array_key_exists( $cpt_key, $attach_to_post_type_data ) ) { $attach_to_post_type_data[ $cpt_key ] = (object) array( @@ -996,12 +996,12 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited $stored_attach_to_post_type = array(); if ( isset( $saved_custom_post_type_data ) && array_key_exists( $post_type_being_edited, $saved_custom_post_type_data ) && isset( $saved_custom_post_type_data[ $post_type_being_edited ][ 'attach_to_post_type' ] ) ) { $stored_attach_to_post_type = $saved_custom_post_type_data[ $post_type_being_edited ]['attach_to_post_type']; - } else if ( ! $this->is_network_admin && isset( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && array_key_exists( $post_type_being_edited, $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && isset( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ][ $post_type_being_edited ][ 'attach_to_post_type' ] ) ) { + } elseif ( ! $this->is_network_admin && isset( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && array_key_exists( $post_type_being_edited, $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && isset( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ][ $post_type_being_edited ][ 'attach_to_post_type' ] ) ) { $stored_attach_to_post_type = $cpt_onomies_manager->user_settings['other_custom_post_types'][ $post_type_being_edited ]['attach_to_post_type']; } if ( ! empty( $stored_attach_to_post_type ) ) { - foreach( $stored_attach_to_post_type as $cpt_key ) { + foreach ( $stored_attach_to_post_type as $cpt_key ) { if ( ! array_key_exists( $cpt_key, $attach_to_post_type_data ) ) { $attach_to_post_type_data[ $cpt_key ] = (object) array( 'label' => sprintf( __( '%1$s %2$snot registered%3$s', 'cpt-onomies' ), "'" . $cpt_key . "'", '(', ')' ), @@ -1013,8 +1013,8 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited } // This filter allows you to remove particular post types from the list - foreach( $attach_to_post_type_data as $cpt_key => $cpt ) { - if ( ! apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : NULL ) . 'attach_to_post_type_property_include_post_type', true, $cpt_key, $post_type_being_edited ) ) { + foreach ( $attach_to_post_type_data as $cpt_key => $cpt ) { + if ( ! apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : null ) . 'attach_to_post_type_property_include_post_type', true, $cpt_key, $post_type_being_edited ) ) { unset( $attach_to_post_type_data[ $cpt_key ] ); } } @@ -1024,7 +1024,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited // Gather taxonomy data to use in properties $taxonomy_data = array(); - foreach( get_taxonomies( array(), 'objects' ) as $value => $tax ) { + foreach ( get_taxonomies( array(), 'objects' ) as $value => $tax ) { // Do not include link categories or nav menu stuff if ( ! empty( $value ) && apply_filters( 'custom_post_type_onomies_taxonomies_property_include_taxonomy', true, $value, $post_type_being_edited ) && ! in_array( $value, array( 'link_category', 'nav_menu' ) ) && ! $cpt_onomies_manager->is_registered_cpt_onomy( $value ) && ! empty( $tax->labels->name ) ) { @@ -1087,8 +1087,8 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited ), ); - foreach( $cpt_supports_data as $support => $support_info ) { - if ( ! apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : NULL ) . 'supports_property_include_support', true, $support, $post_type_being_edited ) ) { + foreach ( $cpt_supports_data as $support => $support_info ) { + if ( ! apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : null ) . 'supports_property_include_support', true, $support, $post_type_being_edited ) ) { unset( $cpt_supports_data[ $support ] ); } } @@ -1135,7 +1135,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited 'attach_to_post_type' => (object) array( 'label' => __( 'Attach to Post Types', 'cpt-onomies' ), 'type' => 'checkbox', - 'description' => sprintf( __( 'This setting allows you to use your custom post type in the same manner as a taxonomy, using your post titles as the terms. This is what we call a "%1$s". You can attach this %2$s to to any post type and assign posts just as you would assign taxonomy terms.', 'cpt-onomies' ), 'CPT-onomy', 'CPT-onomy' ) . ( $this->is_network_admin ? ' This will register the CPT-onomy on each individual site and not across the network.' : NULL ) . ' ' . sprintf( __( 'A post type must be checked in order to register this custom post type as a %s.', 'cpt-onomies' ), 'CPT-onomy' ) . '', + 'description' => sprintf( __( 'This setting allows you to use your custom post type in the same manner as a taxonomy, using your post titles as the terms. This is what we call a "%1$s". You can attach this %2$s to to any post type and assign posts just as you would assign taxonomy terms.', 'cpt-onomies' ), 'CPT-onomy', 'CPT-onomy' ) . ( $this->is_network_admin ? ' This will register the CPT-onomy on each individual site and not across the network.' : null ) . ' ' . sprintf( __( 'A post type must be checked in order to register this custom post type as a %s.', 'cpt-onomies' ), 'CPT-onomy' ) . '', 'data' => $attach_to_post_type_data ), 'meta_box_title' => (object) array( @@ -1189,10 +1189,10 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited 'message' => $this->is_network_admin ? array( 'dismiss' => 'restrict_user_capabilities_network_message', 'text' => '' . __( 'This setting is a little trickier in the network admin to allow for maximum customization.', 'cpt-onomies' ) . ' ' . sprintf( __( 'If you want to define user roles network wide, just enter the user roles separated by a comma: %1$s. If you want to define user roles for a specific site, prefix the user roles with the blog ID: %2$s. For multiple sites, separate each site definition with a semicolon: %3$s. To combine network and site definitions, simply separate with a semicolon: %4$s. In this scenario, the site definitions will not overwrite, but merge with, the network definition. If you would like the site definition to overwrite the network definition, add %5$s to the end of your site definition: %6$s.', 'cpt-onomies' ), 'administrator, editor', '2: administrator, editor', '2: administrator, editor; 3: administrator', 'administrator; 2: author, editor; 3: contributor', '":overwrite"', 'administrator; 2: author, editor: overwrite; 3: contributor' ) . $this->thickbox_network_sites - ) : NULL, - 'description' => sprintf( __( 'This setting allows you to grant specific user roles the capability, or permission, to assign term relationships for this %s.', 'cpt-onomies' ), 'CPT-onomy' ) . ( ( $this->is_network_admin ) ? ' ' . __( 'Visit the "Help" tab for instructions.', 'cpt-onomies' ) . '' : NULL ) . ' ' . __( 'If no user roles are defined, then all user roles will have permission.', 'cpt-onomies' ) . '', + ) : null, + 'description' => sprintf( __( 'This setting allows you to grant specific user roles the capability, or permission, to assign term relationships for this %s.', 'cpt-onomies' ), 'CPT-onomy' ) . ( ( $this->is_network_admin ) ? ' ' . __( 'Visit the "Help" tab for instructions.', 'cpt-onomies' ) . '' : null ) . ' ' . __( 'If no user roles are defined, then all user roles will have permission.', 'cpt-onomies' ) . '', 'default' => $this->is_network_admin ? 'administrator, editor, author' : array( 'administrator', 'editor', 'author' ), - 'data' => $this->is_network_admin ? NULL : $user_data + 'data' => $this->is_network_admin ? null : $user_data ), ), ), @@ -1305,9 +1305,9 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited 'message' => $this->is_network_admin ? array( 'dismiss' => 'taxonomies_network_message', 'text' => '' . __( 'This setting is a little trickier in the network admin to allow for maximum customization.', 'cpt-onomies' ) . ' ' . sprintf( __( 'If you want to define taxonomies network wide, just enter the taxonomy names separated by a comma: %1$s. If you want to define taxonomies for a specific site, prefix the taxonomy names with the blog ID: %2$s. For multiple sites, separate each site definition with a semicolon: %3$s. To combine network and site definitions, simply separate with a semicolon: %4$s. In this scenario, the site definitions will not overwrite, but merge with, the network definition. If you would like the site definition to overwrite the network definition, add %5$s to the end of your site definition: %6$s.', 'cpt-onomies' ), 'category, post_tag', '2: category, post_tag', '2: category, post_tag; 3: category', 'category; 2: post_tag; 3: post_format', '":overwrite"', 'category; 2: post_tag: overwrite; 3: post_tag, post_format' ) . $this->thickbox_network_sites - ) : NULL, - 'description' => sprintf( __( 'This setting allows you to add support for pre-existing, registered %s taxonomies.', 'cpt-onomies' ), 'non-CPT-onomy' ) . ( ( $this->is_network_admin ) ? ' ' . __( 'Visit the "Help" tab for instructions.', 'cpt-onomies' ) . '' : NULL ), - 'data' => $this->is_network_admin ? NULL : $taxonomy_data + ) : null, + 'description' => sprintf( __( 'This setting allows you to add support for pre-existing, registered %s taxonomies.', 'cpt-onomies' ), 'non-CPT-onomy' ) . ( ( $this->is_network_admin ) ? ' ' . __( 'Visit the "Help" tab for instructions.', 'cpt-onomies' ) . '' : null ), + 'data' => $this->is_network_admin ? null : $taxonomy_data ), 'show_ui' => (object) array( 'label' => __( 'Show UI', 'cpt-onomies' ), @@ -1536,7 +1536,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited $network_blogs = $this->get_network_sites(); $network_blogs_data = array(); - foreach( $network_blogs as $this_blog_id => $this_blog ) { + foreach ( $network_blogs as $this_blog_id => $this_blog ) { $network_blogs_data[ $this_blog_id ] = (object) array( 'label' => $this_blog->blogname, ); @@ -1568,7 +1568,7 @@ public function get_plugin_options_page_cpt_properties( $post_type_being_edited * @since 1.0 */ public function add_plugin_options_styles() { - wp_enqueue_style( 'custom-post-type-onomies-admin-options', plugins_url( 'assets/css/admin-options.min.css', __FILE__ ), array( 'thickbox' ), NULL ); + wp_enqueue_style( 'custom-post-type-onomies-admin-options', plugins_url( 'assets/css/admin-options.min.css', __FILE__ ), array( 'thickbox' ), null ); } /** @@ -1581,8 +1581,8 @@ public function add_plugin_options_styles() { public function add_plugin_options_scripts() { // Plugin scripts - wp_enqueue_script( 'custom-post-type-onomies-admin-options', plugins_url( 'assets/js/admin-options.min.js', __FILE__ ), array( 'jquery', 'thickbox' ), NULL, true ); - wp_enqueue_script( 'custom-post-type-onomies-admin-options-validate', plugins_url( 'assets/js/admin-options-validate.min.js', __FILE__ ), array( 'jquery', 'jquery-form-validation' ), NULL, true ); + wp_enqueue_script( 'custom-post-type-onomies-admin-options', plugins_url( 'assets/js/admin-options.min.js', __FILE__ ), array( 'jquery', 'thickbox' ), null, true ); + wp_enqueue_script( 'custom-post-type-onomies-admin-options-validate', plugins_url( 'assets/js/admin-options-validate.min.js', __FILE__ ), array( 'jquery', 'jquery-form-validation' ), null, true ); // Need this script for the metaboxes to work correctly wp_enqueue_script( 'post' ); @@ -1645,7 +1645,7 @@ public function add_plugin_options_help_tab() { return; } - } else if ( $screen->id != $this->options_page ) { + } elseif ( $screen->id != $this->options_page ) { return; } @@ -1911,7 +1911,7 @@ public function manage_plugin_options_actions() { } - } else if ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && array_key_exists( $CPT, $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { + } elseif ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && array_key_exists( $CPT, $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { // Remove the setting unset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $CPT ][ 'deactivate' ] ); @@ -1933,7 +1933,7 @@ public function manage_plugin_options_actions() { } // Delete the CPT - } else if ( isset( $_REQUEST[ 'delete' ] ) ) { + } elseif ( isset( $_REQUEST[ 'delete' ] ) ) { $CPT = $_REQUEST[ 'delete' ]; @@ -1957,7 +1957,7 @@ public function manage_plugin_options_actions() { } - } else if ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && array_key_exists( $CPT, $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { + } elseif ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && array_key_exists( $CPT, $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) ) { // Remove from settings unset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $CPT ] ); @@ -1981,7 +1981,7 @@ public function manage_plugin_options_actions() { } // Delete "conflicting" taxonomy terms - else if ( isset( $_REQUEST[ 'delete_conflicting_terms' ] ) ) { + elseif ( isset( $_REQUEST[ 'delete_conflicting_terms' ] ) ) { // Which taxonomy's terms are we deleting? $taxonomy = $_REQUEST[ 'delete_conflicting_terms' ]; @@ -1998,7 +1998,7 @@ public function manage_plugin_options_actions() { } // Build the redirect URL - $redirect_url = add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $taxonomy, 'other' => ( isset( $_REQUEST[ 'other' ] ) && $_REQUEST[ 'other' ] ? '1' : NULL ) ), $this->admin_url ); + $redirect_url = add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $taxonomy, 'other' => ( isset( $_REQUEST[ 'other' ] ) && $_REQUEST[ 'other' ] ? '1' : null ) ), $this->admin_url ); if ( $delete_success ) { $redirect_url = add_query_arg( array( 'deleted_conflicting_terms' => '1' ), $redirect_url ); @@ -2145,7 +2145,7 @@ public function print_plugin_options_page() { // Create the properties tab $tabs[ 'properties' ] = (object) array( 'title' => __( 'Custom Post Type Properties', 'cpt-onomies' ), - 'link' => esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => ( $new ? 'new' : $edit ), 'other' => ( $other ? '1' : NULL ) ), $this->admin_url ) ), + 'link' => esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => ( $new ? 'new' : $edit ), 'other' => ( $other ? '1' : null ) ), $this->admin_url ) ), 'active' => true ); @@ -2176,7 +2176,7 @@ public function print_plugin_options_page() { if ( $new || $edit ) { // Define the label - $label = NULL; + $label = null; if ( $new ) { $label = __( 'Creating a New Custom Post Type', 'cpt-onomies' ); @@ -2194,7 +2194,7 @@ public function print_plugin_options_page() { if ( $other && ( $post_type_object_label = get_post_type_object( $cpt_key_to_check )->label ) ) { $label = $post_type_object_label; - } else if ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $cpt_key_to_check ] ) && isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $cpt_key_to_check ][ 'label' ] ) ) { + } elseif ( isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ] ) && isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $cpt_key_to_check ] ) && isset( $cpt_onomies_manager->user_settings[ 'custom_post_types' ][ $cpt_key_to_check ][ 'label' ] ) ) { $label = $cpt_onomies_manager->user_settings['custom_post_types'][ $cpt_key_to_check ]['label']; } @@ -2213,7 +2213,7 @@ public function print_plugin_options_page() { } // Don't include tab name in URL, for now, considering there's only one tab - foreach( $tabs as $tab_key => $this_tab ) { + foreach ( $tabs as $tab_key => $this_tab ) { ?>title; ?>is_network_admin ) { if ( isset( $cpt_onomies_manager->user_settings[ 'network_custom_post_types' ] ) && array_key_exists( $activated_cpt, $cpt_onomies_manager->user_settings[ 'network_custom_post_types' ] ) && isset( $cpt_onomies_manager->user_settings[ 'network_custom_post_types' ][ $activated_cpt ][ 'label' ] ) ) { @@ -2265,10 +2265,10 @@ public function print_plugin_options_page() { } // Add "delete conflicting terms" error message - else if ( isset( $_REQUEST[ 'delete_conflicting_terms_error' ] ) ) { + elseif ( isset( $_REQUEST[ 'delete_conflicting_terms_error' ] ) ) { // Build the refresh URL - $refresh_url = add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $edit, 'other' => ( $other ? '1' : NULL ) ), $this->admin_url ); + $refresh_url = add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $edit, 'other' => ( $other ? '1' : null ) ), $this->admin_url ); // Build the message $message = sprintf( __( 'There seems to have been an error deleting the conflicting taxonomy terms. Please %1$srefresh the page%2$s and try again. If the problem persists, %3$sthe %4$s documentation%5$s might help.', 'cpt-onomies' ), '', '', '', 'CPT-onomies', '' ); @@ -2279,7 +2279,7 @@ public function print_plugin_options_page() { } // Add "deleted conflicting terms" message - else if ( isset( $_REQUEST[ 'deleted_conflicting_terms' ] ) ) { + elseif ( isset( $_REQUEST[ 'deleted_conflicting_terms' ] ) ) { $message = __( 'The conflicting taxonomy terms have been deleted!', 'cpt-onomies' ); } @@ -2395,7 +2395,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( current_user_can( $this->manage_options_capability ) ) { - switch( $metabox[ 'args' ] ) { + switch ( $metabox[ 'args' ] ) { // Add New CPT Meta Box case 'add_new_custom_post_type': @@ -2489,14 +2489,14 @@ public function print_plugin_options_meta_box( $post, $metabox ) { // Get the post type information $post_type_objects = get_post_types( array( '_builtin' => false ), 'objects' ); - foreach( $post_type_objects as $post_type => $CPT ) { + foreach ( $post_type_objects as $post_type => $CPT ) { if ( $cpt_onomies_manager->is_registered_cpt( $post_type ) ) { unset( $post_type_objects[ $post_type ] ); } // Gather the plugin settings - else if ( is_array( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && array_key_exists( $post_type, $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) ) { + elseif ( is_array( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) && array_key_exists( $post_type, $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) ) { if ( isset( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ][ $post_type ][ 'attach_to_post_type' ] ) && ! empty( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ][ $post_type ][ 'attach_to_post_type' ] ) ) { $post_type_objects[ $post_type ]->attach_to_post_type = $cpt_onomies_manager->user_settings['other_custom_post_types'][ $post_type ]['attach_to_post_type']; @@ -2558,7 +2558,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { $CPT ) { + foreach ( $post_type_objects as $post_type => $CPT ) { if ( ! is_object( $CPT ) ) { $CPT = (object) $CPT; @@ -2566,7 +2566,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( ! empty( $post_type ) && ( ! isset( $CPT->name ) || empty( $CPT->name ) ) ) { $CPT->name = $post_type; - } else if ( empty( $post_type ) && isset( $CPT->name ) && ! empty( $CPT->name ) ) { + } elseif ( empty( $post_type ) && isset( $CPT->name ) && ! empty( $CPT->name ) ) { $post_type = $CPT->name; } @@ -2584,14 +2584,14 @@ public function print_plugin_options_meta_box( $post, $metabox ) { // Check to see if attached post types exist $attach_to_post_type_not_exist = array(); if ( ! empty( $CPT->attach_to_post_type ) ) { - foreach( $CPT->attach_to_post_type as $attached ) { + foreach ( $CPT->attach_to_post_type as $attached ) { if ( ! post_type_exists( $attached ) ) { $attach_to_post_type_not_exist[] = $attached; } } } - $message = NULL; + $message = null; if ( $attention_cpt ) { // Builtin conflict @@ -2604,7 +2604,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { $message = sprintf( esc_attr__( 'The custom post type, "%s", is not registered because another custom post type with the same name already exists. This other custom post type is probably setup in your theme or another plugin. Check out the \'Manage Your Other Custom Post Types\' section to see what else has been registered.', 'cpt-onomies' ), $CPT->label ); } - } else if ( ! $is_registered_cpt_onomy && $should_be_cpt_onomy ) { + } elseif ( ! $is_registered_cpt_onomy && $should_be_cpt_onomy ) { if ( taxonomy_exists( $post_type ) ) { $message = sprintf( esc_attr__( 'This custom post type\'s %1$s is not registered because another taxonomy with the same name already exists. If you would like this %2$s to work, please remove the conflicting taxonomy.', 'cpt-onomies' ), 'CPT-onomy', 'CPT-onomy' ); @@ -2615,16 +2615,16 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } // This means this CPT-onomy is registered but not for ALL of its assigned custom post types - else if ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) { + elseif ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) { if ( count( $attach_to_post_type_not_exist ) > 1 ) { - $attach_to_post_type_not_exist_string = NULL; + $attach_to_post_type_not_exist_string = null; - foreach( $attach_to_post_type_not_exist as $not_exist_index => $not_exist ) { + foreach ( $attach_to_post_type_not_exist as $not_exist_index => $not_exist ) { if ( $not_exist_index == ( count( $attach_to_post_type_not_exist ) - 1 ) ) { $attach_to_post_type_not_exist_string .= ' and '; - } else if ( $not_exist_index > 0 ) { + } elseif ( $not_exist_index > 0 ) { $attach_to_post_type_not_exist_string .= ', '; } @@ -2646,7 +2646,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( $inactive_cpt ) { $tr_classes[] = 'inactive'; - } else if ( $attention_cpt ) { + } elseif ( $attention_cpt ) { $tr_classes[] = 'attention'; } @@ -2655,7 +2655,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) {
blog_id; ?> blogname; ?>
CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $post_type, 'other' => ( $other ? '1' : NULL ) ), $this->admin_url ) ); + $edit_url = esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $post_type, 'other' => ( $other ? '1' : null ) ), $this->admin_url ) ); // Activate url $activate_url = esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'activate' => $post_type, '_wpnonce' => wp_create_nonce( 'activate-cpt-' . $post_type ) ), $this->admin_url ), 'activate-cpt-' . $post_type ); @@ -2664,7 +2664,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { $delete_url = esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'delete' => $post_type, '_wpnonce' => wp_create_nonce( 'delete-cpt-' . $post_type ) ), $this->admin_url ), 'delete-cpt-' . $post_type ); // View url - $view_url = ! $this->is_network_admin ? esc_url( add_query_arg( array( 'post_type' => $post_type ), admin_url( 'edit.php' ) ) ) : NULL; + $view_url = ! $this->is_network_admin ? esc_url( add_query_arg( array( 'post_type' => $post_type ), admin_url( 'edit.php' ) ) ) : null; ?>label; ?>
@@ -2687,7 +2687,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { echo '' . __( 'Find out why this CPT is not registered.', 'cpt-onomies' ) . ''; } - else if ( $overwrote_network_cpt ) { + elseif ( $overwrote_network_cpt ) { echo '' . __( 'This site-wide custom post type is overwriting a custom post type registered by your network admin.', 'cpt-onomies' ) . ''; } @@ -2704,9 +2704,9 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( $attention_cpt && $attention_cpt_onomy ) { $td_registered_classes[] = 'attention'; - } else if ( $attention_cpt_onomy ) { + } elseif ( $attention_cpt_onomy ) { $td_registered_classes[] = 'error'; - } else if ( $is_registered_cpt_onomy ) { + } elseif ( $is_registered_cpt_onomy ) { $td_registered_classes[] = 'working'; } @@ -2716,7 +2716,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( $inactive_cpt ) { echo sprintf( __( 'No, because this %s is inactive.', 'cpt-onomies' ), 'CPT' ) . '
' . __( 'Activate this CPT', 'cpt-onomies' ) . ''; - } else if ( $attention_cpt ) { + } elseif ( $attention_cpt ) { echo sprintf( __( 'No, because this %s is not registered.', 'cpt-onomies' ), 'CPT' ) . '
' . __( 'Find out why', 'cpt-onomies' ) . ''; } else { @@ -2731,14 +2731,14 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } // This means this CPT-onomy is registered but not for ALL of its assigned custom post types - else if ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) { + elseif ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) { echo sprintf( __( 'Yes, but there is a post type conflict.', 'cpt-onomies' ), 'CPT-onomy' ) . '
' . __( 'Find out why', 'cpt-onomies' ) . ''; } // If the CPT-onomy is registered... - else if ( $is_registered_cpt_onomy ) { + elseif ( $is_registered_cpt_onomy ) { // This means there might be a conflict with conflicting taxonomy terms if ( ! $this->is_network_admin @@ -2750,7 +2750,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } // This means the CPT-onomy was registered outside the plugin - else if ( $programmatic_cpt_onomy ) { + elseif ( $programmatic_cpt_onomy ) { _e( 'Yes', 'cpt-onomies' ); echo '
' . sprintf( __( 'This %1$s is %2$sprogrammatically registered%3$s.', 'cpt-onomies' ), 'CPT-onomy', '', '' ) . ''; @@ -2771,12 +2771,12 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } ?>
is_network_admin ) { if ( isset( $CPT->attach_to_post_type ) ) { - foreach( $CPT->attach_to_post_type as $attached ) { + foreach ( $CPT->attach_to_post_type as $attached ) { - $label = NULL; + $label = null; if ( array_key_exists( $attached, $post_type_objects ) ) { // Don't show deactivated post types @@ -2788,7 +2788,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { $label = $post_type_objects[ $attached ]['label']; } - } else if ( array_key_exists( $attached, $builtin ) ) { + } elseif ( array_key_exists( $attached, $builtin ) ) { if ( isset( $builtin[ $attached ]->label ) ) { $label = $builtin[ $attached ]->label; @@ -2809,7 +2809,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { if ( ( $tax = get_taxonomy( $post_type ) ) && isset( $tax->object_type ) ) { - foreach( $tax->object_type as $attached ) { + foreach ( $tax->object_type as $attached ) { if ( post_type_exists( $attached ) ) { $text .= '' . get_post_type_object( $attached )->label . '
'; @@ -2835,7 +2835,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { ?>
attach_to_post_type ) ) { - foreach( $CPT->attach_to_post_type as $attached ) { + foreach ( $CPT->attach_to_post_type as $attached ) { if ( ! post_type_exists( $attached ) ) { $attach_to_post_type_not_exist[] = $attached; } @@ -2987,7 +2987,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { ?>
is_network_admin ) { if ( $overwrote_network_cpt ) { $information = __( 'This site-wide custom post type is overwriting a custom post type registered by your network admin.', 'cpt-onomies' ); - } else if ( $other ) { + } elseif ( $other ) { $information = sprintf( __( 'This custom post type is probably setup in your theme, or another plugin, but you can still register it for use as a %s. You cannot, however, manage the actual custom post type. Sorry, but that\'s up to the plugin and/or theme.', 'cpt-onomies' ), 'CPT-onomy' ); } } // Print the header - ?>
> + ?>
> @@ -3029,19 +3029,19 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } // Or if it needs attention... - else if ( $attention_cpt || $attention_cpt_onomy || ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) || ( $is_registered_cpt_onomy && $programmatic_cpt_onomy ) ) { + elseif ( $attention_cpt || $attention_cpt_onomy || ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) || ( $is_registered_cpt_onomy && $programmatic_cpt_onomy ) ) { $edit_message_class[] = ' attention'; } - ?>
>
>

true ), 'objects' ); @@ -3057,7 +3057,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } - } else if ( ! $is_registered_cpt_onomy && $should_be_cpt_onomy ) { + } elseif ( ! $is_registered_cpt_onomy && $should_be_cpt_onomy ) { if ( taxonomy_exists( $edit ) ) { ?>

attach_to_post_type ) ) { + } elseif ( $is_registered_cpt_onomy && $attach_to_post_type_not_exist && count( $attach_to_post_type_not_exist ) != count( $CPT->attach_to_post_type ) ) { if ( count( $attach_to_post_type_not_exist ) > 1 ) { - $attach_to_post_type_not_exist_string = NULL; - foreach( $attach_to_post_type_not_exist as $not_exist_index => $not_exist ) { + $attach_to_post_type_not_exist_string = null; + foreach ( $attach_to_post_type_not_exist as $not_exist_index => $not_exist ) { if ( $not_exist_index == ( count( $attach_to_post_type_not_exist ) - 1 ) ) { $attach_to_post_type_not_exist_string .= ' and '; - } else if ( $not_exist_index > 0 ) { + } elseif ( $not_exist_index > 0 ) { $attach_to_post_type_not_exist_string .= ', '; } @@ -3092,16 +3092,16 @@ public function print_plugin_options_meta_box( $post, $metabox ) { } // This means we have conflicting taxonomy terms for our CPT-onomy - } else if ( ! $this->is_network_admin + } elseif ( ! $this->is_network_admin && $attention_cpt_onomy && ( $conflicting_terms_count = $this->get_conflicting_taxonomy_terms_count( $edit ) ) ) { // "Delete conflicting terms" url - $delete_conflicting_terms_url = esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $edit, 'other' => ( $other ? '1' : NULL ), 'delete_conflicting_terms' => $edit, '_wpnonce' => wp_create_nonce( 'delete-conflicting-terms-' . $edit ) ), $this->admin_url ), 'delete-conflicting-terms-' . $edit ); + $delete_conflicting_terms_url = esc_url( add_query_arg( array( 'page' => CPT_ONOMIES_OPTIONS_PAGE, 'edit' => $edit, 'other' => ( $other ? '1' : null ), 'delete_conflicting_terms' => $edit, '_wpnonce' => wp_create_nonce( 'delete-conflicting-terms-' . $edit ) ), $this->admin_url ), 'delete-conflicting-terms-' . $edit ); ?>

', 'CPT-onomy', '' ); ?>

get_plugin_options_page_cpt_properties( $edit && ! empty( $edit ) ? $edit : NULL ); + $cpt_properties = $this->get_plugin_options_page_cpt_properties( $edit && ! empty( $edit ) ? $edit : null ); - foreach( $cpt_properties as $section => $section_properties ) { + foreach ( $cpt_properties as $section => $section_properties ) { // Only show "other" sections on "other" tables if ( ! $other || ( $other && isset( $section_properties->other ) && $section_properties->other ) ) { - ?> + ?>
type ) && $section_properties->type == 'group' && isset( $section_properties->data ) ) { ?>
label; ?> - data as $property_key => $property ) { ?> + data as $property_key => $property ) { ?> @@ -3168,7 +3168,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { $property ) { + foreach ( $section_properties as $property_key => $property ) { ?> @@ -3208,7 +3208,7 @@ public function print_plugin_options_meta_box( $post, $metabox ) { * @param string $property_parent_key - allows for pulling property info from within an array. * @filters 'custom_post_type_onomies_default_property_value' - $property_key, $property_parent_key */ - public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT, $property, $property_key, $property_parent_key=NULL ) { + public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT, $property, $property_key, $property_parent_key=null ) { global $cpt_onomies_manager; if ( current_user_can( $this->manage_options_capability ) ) { @@ -3232,12 +3232,12 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT $field_name .= '[' . $property_key . ']'; - switch( $property->type ) { + switch ( $property->type ) { case 'group': if ( isset( $property->data ) ) { ?>
label; ?> print_plugin_options_edit_custom_post_type_field( $edit, $CPT, $property, $property_key ); ?>
label; ?> print_plugin_options_edit_custom_post_type_field( $edit, $CPT, $property, $property_key ); ?>
- data as $subproperty_key => $subproperty ) { ?> + data as $subproperty_key => $subproperty ) { ?> @@ -3251,7 +3251,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT case 'textarea': // Get saved value - $saved_property_value = NULL; + $saved_property_value = null; if ( ! $new ) { @@ -3262,20 +3262,20 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT $saved_property_value = $property_parent[ $property_key ]; } - } else if ( isset( $CPT->$property_key ) ) { + } elseif ( isset( $CPT->$property_key ) ) { $saved_property_value = $CPT->$property_key; } } else { // Allows you to set default values for the properties - $saved_property_value = apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : NULL ) . 'default_property_value', isset( $property->default ) ? $property->default : NULL, $property_key, $property_parent_key ); + $saved_property_value = apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : null ) . 'default_property_value', isset( $property->default ) ? $property->default : null, $property_key, $property_parent_key ); } if ( is_array( $saved_property_value ) && ! empty( $saved_property_value ) ) { $saved_property_value = esc_attr( strip_tags( implode( ', ', $saved_property_value ) ) ); - } else if ( ! empty( $saved_property_value ) ) { + } elseif ( ! empty( $saved_property_value ) ) { $saved_property_value = esc_attr( strip_tags( $saved_property_value ) ); } @@ -3289,7 +3289,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT ?>fieldid ) ) ? ' id="' . $property->fieldid . '"' : ''; ?>validation ) ) ? ' class="' . $property->validation . '"' : ''; ?> type="text" name="" value=""readonly ) && $property->readonly ) ? ' readonly="readonly"' : ''; ?> />type == 'textarea' ) { + } elseif ( $property->type == 'textarea' ) { ?>fieldid ) ) ? ' id="' . $property->fieldid . '"' : ''; ?>validation ) ) ? ' class="' . $property->validation . '"' : ''; ?> name="">data as $data_name => $data ) { + foreach ( $property->data as $data_name => $data ) { if ( $data_name == 'true' ) { $data_name = 1; - } else if ( $data_name == 'false' ) { + } elseif ( $data_name == 'false' ) { $data_name = 0; } @@ -3349,7 +3349,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT } // Allows you to set default values for the properties - $default_value = apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : NULL ) . 'default_property_value', isset( $property->default ) ? $property->default : NULL, $property_key, $property_parent_key ); + $default_value = apply_filters( 'custom_post_type_onomies_' . ( $this->is_network_admin ? 'network_admin_' : null ) . 'default_property_value', isset( $property->default ) ? $property->default : null, $property_key, $property_parent_key ); // Make sure value is clean if ( $property->type == 'checkbox' && isset( $default_value ) && ! is_array( $default_value ) ) { @@ -3363,7 +3363,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT } // If default value is not an array - else if ( isset( $default_value ) && $data_name == $default_value ) { + elseif ( isset( $default_value ) && $data_name == $default_value ) { $is_default = true; } @@ -3378,24 +3378,24 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT $is_set = true; - } else if ( isset( $property_parent[ $property_key ] ) && $data_name == $property_parent[ $property_key ] ) { + } elseif ( isset( $property_parent[ $property_key ] ) && $data_name == $property_parent[ $property_key ] ) { $is_set = true; } - } else if ( isset( $CPT->$property_key ) && is_array( $CPT->$property_key ) && in_array( $data_name, $CPT->$property_key ) ) { + } elseif ( isset( $CPT->$property_key ) && is_array( $CPT->$property_key ) && in_array( $data_name, $CPT->$property_key ) ) { $is_set = true; - } else if ( isset( $CPT->$property_key ) && $data_name == $CPT->$property_key ) { + } elseif ( isset( $CPT->$property_key ) && $data_name == $CPT->$property_key ) { $is_set = true; } // If property is not set, then set to default - else if ( ! isset( $CPT->other ) && ! isset( $CPT->$property_key ) && $is_default ) { + elseif ( ! isset( $CPT->other ) && ! isset( $CPT->$property_key ) && $is_default ) { $is_set = true; @@ -3408,7 +3408,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT * If "other" custom post type has no settings in the database, * then its settings have not been "saved" and should therefore show the defaults. */ - else if ( isset( $CPT->other ) && ! isset( $CPT->$property_key ) && $is_default ) { + elseif ( isset( $CPT->other ) && ! isset( $CPT->$property_key ) && $is_default ) { if ( empty( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ] ) || empty( $cpt_onomies_manager->user_settings[ 'other_custom_post_types' ][ $cpt_key ] ) ) { $is_set = true; @@ -3417,7 +3417,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT } // Set the defaults - } else if ( $is_default ) { + } elseif ( $is_default ) { $is_set = true; } @@ -3455,7 +3455,7 @@ public function print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT if ( $td == 1 ) { $td = 2; - } else if ( $td == 2 ) { + } elseif ( $td == 2 ) { $td = 1; echo ''; } diff --git a/admin.php b/admin.php index 92fc702..d28ace8 100644 --- a/admin.php +++ b/admin.php @@ -132,19 +132,19 @@ public function admin_register_styles_and_scripts( $page ) { global $current_screen; // Several pages in the admin need this script - wp_register_script( 'jquery-form-validation', plugins_url( 'assets/js/jquery.validate.min.js', __FILE__ ), array( 'jquery' ), NULL, true ); + wp_register_script( 'jquery-form-validation', plugins_url( 'assets/js/jquery.validate.min.js', __FILE__ ), array( 'jquery' ), null, true ); // Enqueue scripts depending on page - switch( $page ) { + switch ( $page ) { case 'edit.php': - wp_enqueue_script( 'custom-post-type-onomies-admin-edit', plugins_url( 'assets/js/admin-edit.min.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), NULL, true ); + wp_enqueue_script( 'custom-post-type-onomies-admin-edit', plugins_url( 'assets/js/admin-edit.min.js', __FILE__ ), array( 'jquery', 'inline-edit-post' ), null, true ); break; case 'post.php': case 'post-new.php': - wp_enqueue_style( 'custom-post-type-onomies-admin-post', plugins_url( 'assets/css/admin-post.min.css', __FILE__ ), false, NULL ); - wp_enqueue_script( 'custom-post-type-onomies-admin-post', plugins_url( 'assets/js/admin-post.min.js', __FILE__ ), array( 'jquery', 'post', 'jquery-ui-autocomplete' ), NULL, true ); + wp_enqueue_style( 'custom-post-type-onomies-admin-post', plugins_url( 'assets/css/admin-post.min.css', __FILE__ ), false, null ); + wp_enqueue_script( 'custom-post-type-onomies-admin-post', plugins_url( 'assets/js/admin-post.min.js', __FILE__ ), array( 'jquery', 'post', 'jquery-ui-autocomplete' ), null, true ); // Our localized info $cpt_onomies_admin_post_data = array(); @@ -161,7 +161,7 @@ public function admin_register_styles_and_scripts( $page ) { * We need to know if the user has permission to edit specific * taxonomies AND we'll get the label name while we're at it. */ - foreach( get_object_taxonomies( $current_screen->post_type, 'objects' ) as $taxonomy => $tax ) { + foreach ( get_object_taxonomies( $current_screen->post_type, 'objects' ) as $taxonomy => $tax ) { // Get the permission $cpt_onomies_admin_post_data['can_assign_terms'][ $taxonomy ] = current_user_can( $tax->cap->assign_terms ); @@ -192,7 +192,7 @@ public function ajax_get_cpt_onomy_terms_include_term_ids() { // Get the taxonomy and post type info $taxonomy = ( isset( $_POST['custom_post_type_onomies_taxonomy'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomy'] ) ) ? $_POST['custom_post_type_onomies_taxonomy'] : array(); - $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : NULL; + $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : null; $post_id = ( isset( $_POST['custom_post_type_onomies_post_id'] ) && ! empty( $_POST['custom_post_type_onomies_post_id'] ) ) ? $_POST['custom_post_type_onomies_post_id'] : 0; $include_term_ids = array(); @@ -230,7 +230,7 @@ public function ajax_get_cpt_onomy_terms_include_term_ids() { * @return array - the ids for the included cpt_onomy terms * @filters 'custom_post_type_onomies_assigning_cpt_onomy_terms_include_term_ids' - $taxonomy, $post_type, $post_id */ - public function get_cpt_onomy_terms_include_term_ids( $taxonomy = NULL, $post_type = NULL, $post_id = 0 ) { + public function get_cpt_onomy_terms_include_term_ids( $taxonomy = null, $post_type = null, $post_id = 0 ) { $include_term_ids = apply_filters( 'custom_post_type_onomies_assigning_cpt_onomy_terms_include_term_ids', array(), $taxonomy, $post_type, $post_id ); // Make sure its an array @@ -241,7 +241,7 @@ public function get_cpt_onomy_terms_include_term_ids( $taxonomy = NULL, $post_ty // Make sure the 'include' does not include the current post ID if ( in_array( $post_id, $include_term_ids ) ) { - foreach( $include_term_ids as $term_id_index => $term_id ) { + foreach ( $include_term_ids as $term_id_index => $term_id ) { if ( $post_id == $term_id ) { unset( $include_term_ids[ $term_id_index ] ); } @@ -263,11 +263,11 @@ public function ajax_get_cpt_onomy_terms_exclude_term_ids() { // Get taxonomy and post type info $taxonomies = ( isset( $_POST['custom_post_type_onomies_taxonomies'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomies'] ) ) ? $_POST['custom_post_type_onomies_taxonomies'] : array(); - $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : NULL; + $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : null; $post_id = ( isset( $_POST['custom_post_type_onomies_post_id'] ) && ! empty( $_POST['custom_post_type_onomies_post_id'] ) ) ? $_POST['custom_post_type_onomies_post_id'] : 0; $exclude_term_ids = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { $taxonomy_exclude_term_ids = $this->get_cpt_onomy_terms_exclude_term_ids( $taxonomy, $post_type, $post_id ); if ( ! empty( $taxonomy_exclude_term_ids ) ) { $exclude_term_ids = array_merge( $exclude_term_ids, $taxonomy_exclude_term_ids ); @@ -296,7 +296,7 @@ public function ajax_get_cpt_onomy_terms_exclude_term_ids() { * @return array - the ids for the excluded cpt_onomy terms * @filters 'custom_post_type_onomies_assigning_cpt_onomy_terms_exclude_term_ids' - $taxonomy, $post_type, $post_id */ - public function get_cpt_onomy_terms_exclude_term_ids( $taxonomy = NULL, $post_type = NULL, $post_id = 0 ) { + public function get_cpt_onomy_terms_exclude_term_ids( $taxonomy = null, $post_type = null, $post_id = 0 ) { $exclude_term_ids = apply_filters( 'custom_post_type_onomies_assigning_cpt_onomy_terms_exclude_term_ids', array(), $taxonomy, $post_type, $post_id ); // Make sure its an array @@ -359,7 +359,7 @@ public function ajax_get_wp_object_terms() { $post_ids = ( isset( $_POST['custom_post_type_onomies_post_ids'] ) && ! empty( $_POST['custom_post_type_onomies_post_ids'] ) ) ? $_POST['custom_post_type_onomies_post_ids'] : array(); $taxonomies = ( isset( $_POST['custom_post_type_onomies_taxonomies'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomies'] ) ) ? $_POST['custom_post_type_onomies_taxonomies'] : array(); $get_parent_title = ( isset( $_POST['custom_post_type_onomies_get_parent_title'] ) && ! empty( $_POST['custom_post_type_onomies_get_parent_title'] ) ) ? true : false; - $terms_fields = ( isset( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] ) && ! empty( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] ) && in_array( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'], array( 'ids' ) ) ) ? $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] : NULL; + $terms_fields = ( isset( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] ) && ! empty( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] ) && in_array( $_POST['custom_post_type_onomies_wp_get_object_terms_fields'], array( 'ids' ) ) ) ? $_POST['custom_post_type_onomies_wp_get_object_terms_fields'] : null; if ( ! empty( $post_ids ) && ! empty( $taxonomies ) ) { if ( ! is_array( $post_ids ) ) { @@ -382,7 +382,7 @@ public function ajax_get_wp_object_terms() { // Get parent title, if desired AND if post type is hierarchical if ( $get_parent_title ) { - foreach( $terms as $term_index => $term ) { + foreach ( $terms as $term_index => $term ) { $terms[ $term_index ]->parent = ( is_post_type_hierarchical( $term->taxonomy ) ) ? $this->build_term_parent_title_with_csv( $term->parent ) : ''; } } @@ -428,11 +428,11 @@ public function ajax_check_if_term_exists() { echo json_encode( array() ); } - else if ( is_numeric( $term_exists ) ) { + elseif ( is_numeric( $term_exists ) ) { echo json_encode( (object) array( 'term_id' => $term_exists ) ); } - else if ( is_object( $term_exists ) || is_array( $term_exists ) ) { + elseif ( is_object( $term_exists ) || is_array( $term_exists ) ) { // Get parent title, if desired if ( $get_parent_title ) { @@ -479,8 +479,8 @@ public function ajax_meta_box_autocomplete_callback() { global $wpdb; // Get the taxonomy and post type info - $taxonomy = ( isset( $_POST['custom_post_type_onomies_taxonomy'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomy'] ) ) ? $_POST['custom_post_type_onomies_taxonomy'] : NULL; - $term = ( isset( $_POST['custom_post_type_onomies_term'] ) && ! empty( $_POST['custom_post_type_onomies_term'] ) ) ? $_POST['custom_post_type_onomies_term'] : NULL; + $taxonomy = ( isset( $_POST['custom_post_type_onomies_taxonomy'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomy'] ) ) ? $_POST['custom_post_type_onomies_taxonomy'] : null; + $term = ( isset( $_POST['custom_post_type_onomies_term'] ) && ! empty( $_POST['custom_post_type_onomies_term'] ) ) ? $_POST['custom_post_type_onomies_term'] : null; $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : 0; $post_id = ( isset( $_POST['custom_post_type_onomies_post_id'] ) && ! empty( $_POST['custom_post_type_onomies_post_id'] ) ) ? $_POST['custom_post_type_onomies_post_id'] : 0; @@ -512,7 +512,7 @@ public function ajax_meta_box_autocomplete_callback() { $exclude_term_ids = $this->get_cpt_onomy_terms_exclude_term_ids( $taxonomy, $post_type, $post_id ); $results = array(); - foreach( $available_terms as $this_term ) { + foreach ( $available_terms as $this_term ) { // Whether or not we want the element displayed $add_term_to_results = true; @@ -522,13 +522,13 @@ public function ajax_meta_box_autocomplete_callback() { $add_term_to_results = false; } - if( $exclude_term_ids && in_array( $this_term->ID, $exclude_term_ids ) ) { + if ( $exclude_term_ids && in_array( $this_term->ID, $exclude_term_ids ) ) { $add_term_to_results = false; } // We don't want to display children of terms we filtered out if ( $this_term->parent ) { - foreach( get_post_ancestors( $this_term->ID ) as $ancestor ) { + foreach ( get_post_ancestors( $this_term->ID ) as $ancestor ) { if ( in_array( $ancestor, $exclude_term_ids ) ) { $add_term_to_results = false; break; @@ -588,7 +588,7 @@ public function add_cpt_onomy_meta_boxes( $post_type, $post ) { global $cpt_onomies_manager; // Loop through all the taxonomies tied to this post type - foreach( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { + foreach ( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { // Make sure its a registered CPT-onomy if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { @@ -647,8 +647,8 @@ public function print_cpt_onomy_meta_box( $post, $metabox ) { wp_nonce_field( 'assigning_custom_post_type_onomies_taxonomy_relationships', 'custom_post_type_onomies_nonce' ); // Define variables - $post_type = ( isset( $post->post_type ) && ! empty( $post->post_type ) && post_type_exists( $post->post_type ) ) ? $post->post_type : NULL; - $taxonomy = ( isset( $metabox['args']['taxonomy'] ) && ! empty( $metabox['args']['taxonomy'] ) && taxonomy_exists( $metabox['args']['taxonomy'] ) ) ? $metabox['args']['taxonomy'] : NULL; + $post_type = ( isset( $post->post_type ) && ! empty( $post->post_type ) && post_type_exists( $post->post_type ) ) ? $post->post_type : null; + $taxonomy = ( isset( $metabox['args']['taxonomy'] ) && ! empty( $metabox['args']['taxonomy'] ) && taxonomy_exists( $metabox['args']['taxonomy'] ) ) ? $metabox['args']['taxonomy'] : null; if ( $post_type && $taxonomy ) { @@ -656,7 +656,7 @@ public function print_cpt_onomy_meta_box( $post, $metabox ) { $tax = get_taxonomy( $taxonomy ); // If 'meta_box_format' is not defined, use default WordPress setting - if ( ! ( $format = ( isset( $tax->meta_box_format ) && ! empty( $tax->meta_box_format ) ) ? $tax->meta_box_format : NULL ) ) { + if ( ! ( $format = ( isset( $tax->meta_box_format ) && ! empty( $tax->meta_box_format ) ) ? $tax->meta_box_format : null ) ) { $format = is_post_type_hierarchical( $taxonomy ) ? 'checklist' : 'autocomplete'; } @@ -690,7 +690,7 @@ public function print_cpt_onomy_meta_box( $post, $metabox ) { // Add field for testing "editability" when we save the information ?> false, 'fields' => 'ids' ) ) as $term_id ) { + foreach ( get_terms( $taxonomy, array( 'hide_empty' => false, 'fields' => 'ids' ) ) as $term_id ) { if ( ! in_array( $term_id, $include_term_ids ) ) { $dropdown_exclude_term_ids[] = $term_id; } @@ -840,7 +840,7 @@ public function save_post( $post_id, $post ) { } // Check CPT-onomies - foreach( get_object_taxonomies( $post->post_type, 'objects' ) as $taxonomy => $tax ) { + foreach ( get_object_taxonomies( $post->post_type, 'objects' ) as $taxonomy => $tax ) { /** * Make sure cpt-onomy was visible, otherwise we might be @@ -933,7 +933,7 @@ public function bulk_quick_edit_custom_box( $column_name, $post_type ) { $taxonomy, 'walker' => new CPTonomy_Walker_Terms_Checklist(), )); @@ -963,7 +963,7 @@ public function ajax_save_bulk_edit() { // Get taxonomy and post type info $post_ids = ( isset( $_POST['custom_post_type_onomies_post_ids'] ) && ! empty( $_POST['custom_post_type_onomies_post_ids'] ) ) ? $_POST['custom_post_type_onomies_post_ids'] : array(); - $taxonomy = ( isset( $_POST['custom_post_type_onomies_taxonomy'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomy'] ) ) ? $_POST['custom_post_type_onomies_taxonomy'] : NULL; + $taxonomy = ( isset( $_POST['custom_post_type_onomies_taxonomy'] ) && ! empty( $_POST['custom_post_type_onomies_taxonomy'] ) ) ? $_POST['custom_post_type_onomies_taxonomy'] : null; $checked_ids = ( isset( $_POST['custom_post_type_onomies_checked_ids'] ) && ! empty( $_POST['custom_post_type_onomies_checked_ids'] ) ) ? $_POST['custom_post_type_onomies_checked_ids'] : array(); if ( ! empty( $post_ids ) && ! empty( $taxonomy ) ) { @@ -971,7 +971,7 @@ public function ajax_save_bulk_edit() { // Check permissions if ( current_user_can( $tax->cap->assign_terms ) ) { - foreach( $post_ids as $post_id ) { + foreach ( $post_ids as $post_id ) { /** * Set object terms. @@ -1003,8 +1003,8 @@ public function ajax_quick_edit_populate_custom_columns() { // Get taxonomy and post type info $post_id = ( isset( $_POST['custom_post_type_onomies_post_id'] ) && ! empty( $_POST['custom_post_type_onomies_post_id'] ) && is_numeric( $_POST['custom_post_type_onomies_post_id'] ) ) ? $_POST['custom_post_type_onomies_post_id'] : 0; - $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : NULL; - $column_name = ( isset( $_POST['custom_post_type_onomies_column_name'] ) && ! empty( $_POST['custom_post_type_onomies_column_name'] ) ) ? $_POST['custom_post_type_onomies_column_name'] : NULL; + $post_type = ( isset( $_POST['custom_post_type_onomies_post_type'] ) && ! empty( $_POST['custom_post_type_onomies_post_type'] ) ) ? $_POST['custom_post_type_onomies_post_type'] : null; + $column_name = ( isset( $_POST['custom_post_type_onomies_column_name'] ) && ! empty( $_POST['custom_post_type_onomies_column_name'] ) ) ? $_POST['custom_post_type_onomies_column_name'] : null; if ( $post_id && ! empty( $post_type ) && ! empty( $column_name ) ) { @@ -1058,7 +1058,7 @@ public function restrict_manage_posts() { global $cpt_onomy, $cpt_onomies_manager, $wp_list_table, $post_type; list( $columns, $hidden ) = $wp_list_table->get_column_info(); - foreach( $columns as $column_name => $column_display_name ) { + foreach ( $columns as $column_name => $column_display_name ) { /** * The filter drop down is added if you have the column added @@ -1082,7 +1082,7 @@ public function restrict_manage_posts() { $post_type_object = get_post_type_object( $taxonomy ); // Get selected term - $selected = ( isset( $_REQUEST[ $taxonomy ] ) ) ? $_REQUEST[ $taxonomy ] : NULL; + $selected = ( isset( $_REQUEST[ $taxonomy ] ) ) ? $_REQUEST[ $taxonomy ] : null; // If slug, then get term id if ( ! is_numeric( $selected ) ) { @@ -1144,7 +1144,7 @@ public function add_cpt_onomy_admin_column( $columns, $post_type='page' ) { global $cpt_onomies_manager; // Process each taxonomy assigned to the current post type - foreach( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { + foreach ( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { // Make sure its a registered CPT-onomy if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { @@ -1226,14 +1226,14 @@ public function add_cpt_onomy_admin_sortable_columns( $sortable_columns ) { global $cpt_onomies_manager, $current_screen; // Get the current post type - if ( $post_type = isset( $current_screen->post_type ) ? $current_screen->post_type : NULL ) { + if ( $post_type = isset( $current_screen->post_type ) ? $current_screen->post_type : null ) { // Process each taxonomy assigned to the current post type - foreach( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { + foreach ( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy => $tax ) { // Make sure its a registered CPT-onomy and get the taxonomy's query variable if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) - && ( $query_var = isset( $tax->query_var ) ? $tax->query_var : NULL ) ) { + && ( $query_var = isset( $tax->query_var ) ? $tax->query_var : null ) ) { // This filter allows you to remove the column by returning false // All CPT-onomy admin columns are default-ly added as sortable @@ -1321,7 +1321,7 @@ function display_element( $element, &$children_elements, $max_depth, $depth=0, $ // Descend only when the depth is right and there are childrens for this element if ( ( $max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[ $id ] ) ) { - foreach( $children_elements[ $id ] as $child ) { + foreach ( $children_elements[ $id ] as $child ) { if ( ! isset( $newlevel ) ) { $newlevel = true; diff --git a/cpt-onomies.php b/cpt-onomies.php index 91e7d66..0b6a48b 100644 --- a/cpt-onomies.php +++ b/cpt-onomies.php @@ -24,18 +24,18 @@ define( 'CPT_ONOMIES_OPTIONS_PAGE', 'custom-post-type-onomies' ); // @TODO remove when we create admin class define( 'CPT_ONOMIES_POSTMETA_KEY', '_custom_post_type_onomies_relationship' ); // @TODO remove when we create admin class -// If we build them, they will load +// If we build them, they will load. require_once plugin_dir_path( __FILE__ ) . 'cpt-onomy.php'; require_once plugin_dir_path( __FILE__ ) . 'manager.php'; require_once plugin_dir_path( __FILE__ ) . 'widgets.php'; -// We only need these in the admin +// We only need these in the admin. if ( is_admin() ) { require_once plugin_dir_path( __FILE__ ) . 'admin.php'; require_once plugin_dir_path( __FILE__ ) . 'admin-settings.php'; } -// Extend all the things +// Extend all the things. require_once plugin_dir_path( __FILE__ ) . 'extend/gravity-forms-custom-post-types.php'; /** @@ -127,7 +127,7 @@ private function __wakeup() {} */ public function install() { - /** + /* * Rewrite rules can be a pain in the ass * so let's flush them out and start fresh. */ @@ -149,7 +149,7 @@ public function install() { */ public function upgrader_process_complete( $upgrader, $upgrade_info ) { - /** + /* * For some reason I find myself having to flush my * rewrite rules whenever I upgrade WordPress so just * helping everyone out by taking care of this automatically @@ -158,7 +158,7 @@ public function upgrader_process_complete( $upgrader, $upgrade_info ) { } - /** + /* * Internationalization FTW. * Load our textdomain. * @@ -171,7 +171,7 @@ public function textdomain() { } -/** +/* * Returns the instance of our main CPT_onomies class. * * Will come in handy when we need to access the @@ -186,4 +186,4 @@ function cpt_onomies() { } // Let's get this show on the road. -cpt_onomies(); \ No newline at end of file +cpt_onomies(); diff --git a/cpt-onomy.php b/cpt-onomy.php index 42f272c..d5d3c87 100644 --- a/cpt-onomy.php +++ b/cpt-onomy.php @@ -10,25 +10,24 @@ * @since 1.0 */ class CPT_TAXONOMY { - + /** * Adds WordPress hooks (actions and filters). * * @since 1.0 */ public function __construct() { - - // Function filters + + // Function filters. add_filter( 'get_terms', array( $this, 'get_terms' ), 1, 3 ); add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 1, 4 ); - - // Other filters + + // Other filters. add_filter( 'get_terms_args', array( $this, 'adjust_get_terms_args' ), 1, 2 ); add_filter( 'get_the_terms', array( $this, 'get_the_terms' ), 1, 3 ); - + } - public function CPT_TAXONOMY() { $this->__construct(); } - + /** * This function takes an object's information and creates a term object. * @@ -45,57 +44,56 @@ public function CPT_TAXONOMY() { $this->__construct(); } */ private function convert_object_to_cpt_onomy_term( $object, $get_count = true ) { global $cpt_onomies_manager; - - // If its empty, then there's no point + + // If its empty, then there's no point. if ( empty( $object ) ) { return $object; } - - // Make sure the term is an object + + // Make sure the term is an object. $term = (object) $object; - - // Make sure its a CPT-onomy + + // Make sure its a CPT-onomy. if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $term->post_type ) ) { return $object; } - - /** + + /* * sanitize_term_field() lets you apply the 'term_description' * or '{$taxonomy}_description' filter to tweak the description, * if desired. Maybe you want the description to be a custom field? * or the post content. Just return that info in the filter! */ $term = array( - 'term_id' => $term->ID, - 'name' => apply_filters( 'the_title', $term->post_title, $term->ID ), - 'slug' => $term->post_name, - 'term_group' => $term->post_parent, - 'term_taxonomy_id' => 0, - 'taxonomy' => $term->post_type, - 'description' => sanitize_term_field( 'description', '', $term->ID, $term->post_type, 'display' ), - 'parent' => $term->post_parent + 'term_id' => $term->ID, + 'name' => apply_filters( 'the_title', $term->post_title, $term->ID ), + 'slug' => $term->post_name, + 'term_group' => $term->post_parent, + 'term_taxonomy_id' => 0, + 'taxonomy' => $term->post_type, + 'description' => sanitize_term_field( 'description', '', $term->ID, $term->post_type, 'display' ), + 'parent' => $term->post_parent, ); - + if ( $get_count ) { $term['count'] = $this->get_term_count( $term['term_id'], $term['taxonomy'] ); } - + if ( is_object( $object ) ) { return (object) $term; } - + return $term; - } - + /** * Since setting the argument 'fields' to 'count' will not work with CPT-onomies, * this gets rid of that field and adds a custom count argument that's applied * in our get_terms() filter function. This allows the WP function wp_count_terms() - * to work with CPT-onomies. + * to work with CPT-onomies. * * This function is applied to the filter 'get_terms_args'. - * The filter 'get_terms_args' was not added to get_terms() until 3.1 so this + * The filter 'get_terms_args' was not added to get_terms() until 3.1 so this * function will not work before WordPress version 3.1. * * @since 1.0.2 @@ -106,32 +104,30 @@ private function convert_object_to_cpt_onomy_term( $object, $get_count = true ) */ public function adjust_get_terms_args( $args, $taxonomies ) { global $cpt_onomies_manager; - - // This function only filters registered CPT-onomies + + // This function only filters registered CPT-onomies. $cpt_taxonomies = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { $cpt_taxonomies[] = $taxonomy; } } - - // This means there are no CPT-onomies so wrap things up + + // This means there are no CPT-onomies so wrap things up. if ( empty( $cpt_taxonomies ) ) { return $args; } - - // Change 'fields' to 'ids' and add a custom count argument - if ( isset( $args[ 'fields' ] ) && $args[ 'fields' ] == 'count' ) { - $args[ 'fields' ] = 'ids'; - $args[ 'cpt_onomy_get_count' ] = true; + + // Change 'fields' to 'ids' and add a custom count argument. + if ( isset( $args['fields'] ) && 'count' == $args['fields'] ) { + $args['fields'] = 'ids'; + $args['cpt_onomy_get_count'] = true; } - + return $args; - } /** - * * Whenever get_the_terms() is called, we need to * clear the cache that WordPress stores. * @@ -143,12 +139,12 @@ public function adjust_get_terms_args( $args, $taxonomies ) { */ public function get_the_terms( $terms, $post_id, $taxonomy ) { - // Clear the cache that WordPress adds + // Clear the cache that WordPress adds. wp_cache_delete( $post_id, "{$taxonomy}_relationships" ); return $terms; } - + /** * This function mimics the WordPress function get_term() * because we cannot hook into the function without receiving errors. @@ -165,25 +161,25 @@ public function get_the_terms( $terms, $post_id, $taxonomy ) { public function get_term( $term, $taxonomy, $output = OBJECT, $filter = 'raw' ) { global $cpt_onomies_manager; $null = null; - + if ( empty( $term ) ) { $error = new WP_Error( 'invalid_term', __( 'Empty Term', 'cpt-onomies' ) ); return $error; } - + if ( ! taxonomy_exists( $taxonomy ) ) { $error = new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy', 'cpt-onomies' ) ); return $error; } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_term( $term, $taxonomy, $output, $filter ); } - + if ( is_object( $term ) && empty( $term->filter ) ) { wp_cache_add( $term->term_id, $term, $taxonomy ); $_term = $term; @@ -202,25 +198,24 @@ public function get_term( $term, $taxonomy, $output = OBJECT, $filter = 'raw' ) wp_cache_add( $term, $_term, $taxonomy ); } } - + $_term = apply_filters( 'get_term', $_term, $taxonomy ); $_term = apply_filters( "get_$taxonomy", $_term, $taxonomy ); $_term = sanitize_term( $_term, $taxonomy, $filter ); - - if ( $output == OBJECT ) { + + if ( OBJECT == $output ) { return $_term; - } elseif ( $output == ARRAY_A ) { + } elseif ( ARRAY_A == $output ) { $__term = get_object_vars( $_term ); return $__term; - } elseif ( $output == ARRAY_N ) { + } elseif ( ARRAY_N == $output ) { $__term = array_values( get_object_vars( $_term ) ); return $__term; } else { return $_term; } - } - + /** * This function mimics the WordPress function get_term_by() * because we cannot hook into the function without receiving errors. @@ -237,117 +232,116 @@ public function get_term( $term, $taxonomy, $output = OBJECT, $filter = 'raw' ) */ public function get_term_by( $field, $value, $taxonomy, $output = OBJECT, $filter = 'raw', $parent = 0 ) { global $wpdb, $cpt_onomies_manager; - + if ( ! taxonomy_exists( $taxonomy ) ) { return false; } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_term_by( $field, $value, $taxonomy, $output, $filter ); } - + if ( $parent > 0 ) { - $parent = " AND wpposts.post_parent = " . $parent; + $parent = " AND wpposts.post_parent = {$parent}"; } else { $parent = null; } - + if ( 'slug' == $field ) { - + $value = sanitize_title( $value ); - + if ( empty( $value ) ) { return false; } - + // Get eligible post types $eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : array(); - + // Find term and term count $query = "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpcountposts ON wpcountposts.ID = wpcountmeta.post_id AND wpcountposts.post_status = 'publish' AND wpcountposts.post_type IN ('" . implode( "','", $eligible_post_types ) . "') WHERE wpcountmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND wpcountmeta.meta_value = wpposts.ID) AS count, wpposts.* FROM {$wpdb->posts} wpposts WHERE wpposts.post_type = '{$taxonomy}' AND wpposts.post_name = '{$value}' and wpposts.post_status = 'publish'" . $parent; - - } else if ( 'name' == $field ) { - + + } elseif ( 'name' == $field ) { + // Assume already escaped $value = stripslashes( $value ); - + // Get eligible post types $eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : array(); - + // Find term and term count $query = "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpcountposts ON wpcountposts.ID = wpcountmeta.post_id AND wpcountposts.post_status = 'publish' AND wpcountposts.post_type IN ('" . implode( "','", $eligible_post_types ) . "') WHERE wpcountmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND wpcountmeta.meta_value = wpposts.ID) AS count, wpposts.* FROM {$wpdb->posts} wpposts WHERE wpposts.post_type = '{$taxonomy}' AND wpposts.post_title = '{$value}' and wpposts.post_status = 'publish'" . $parent; - + } else { - + $term = $this->get_term( (int) $value, $taxonomy, $output, $filter ); - + if ( is_wp_error( $term ) ) { return false; } - + return $term; - + } - + // Get the term $term = $wpdb->get_row( $query ); - + if ( ! $term ) { return false; } - + // Save the term count and remove from $term before conversion $term_count = $term->count; unset( $term->count ); - + // Dont get the count, we'll add from before $term = $this->convert_object_to_cpt_onomy_term( $term, false ); - + if ( ! $term ) { return false; } - + // Add count $term->count = $term_count; - + wp_cache_add( $term->term_id, $term, $taxonomy ); - + $term = apply_filters( 'get_term', $term, $taxonomy ); $term = apply_filters( "get_$taxonomy", $term, $taxonomy ); $term = sanitize_term( $term, $taxonomy, $filter ); - - if ( $output == OBJECT ) { + + if ( OBJECT == $output ) { return $term; - } elseif ( $output == ARRAY_A ) { + } elseif ( ARRAY_A == $output ) { return get_object_vars( $term ); - } elseif ( $output == ARRAY_N ) { + } elseif ( ARRAY_N == $output ) { return array_values( get_object_vars( $term ) ); } - + return $term; - } - + /** * As of 1.0.2, wp_count_terms() works with CPT-onomies so this * function is now deprecated and will send you to the WordPress function. * * As of version 1.0.3, the WordPress minimum version is 3.1 and the filter - * 'get_terms_args' that allows CPT-onomies to work with wp_count_terms() was + * 'get_terms_args' that allows CPT-onomies to work with wp_count_terms() was * added in 3.1 so everyone is sent to the WordPress function. - * + * * @param string $taxonomy Taxonomy name * @param array|string $args Overwrite defaults. See get_terms() * @return int How many terms are in $taxonomy */ public function wp_count_terms( $taxonomy, $args = array() ) { - return wp_count_terms( $taxonomy, $args ); + return wp_count_terms( $taxonomy, $args ); } - + /** * Returns an array of term counts for a specific * CPT-onomy indexed by the term ID. @@ -360,100 +354,96 @@ public function wp_count_terms( $taxonomy, $args = array() ) { * @param csv|array - $term_ids - you can pass specific term IDs instead of all terms (will not use cache though) * @return array|false - array of term counts indexed by term ID or false if error */ - private function get_terms_count( $taxonomies, $term_ids = NULL ) { + private function get_terms_count( $taxonomies, $term_ids = null ) { global $cpt_onomies_manager, $wpdb; - + // Make sure the taxonomies is an array if ( ! empty( $taxonomies ) && ! is_array( $taxonomies ) ) { $taxonomies = explode( ',', $taxonomies ); } - + // Make sure they are valid CPT-onomies - foreach( $taxonomies as $index => $taxonomy ) { - + foreach ( $taxonomies as $index => $taxonomy ) { + // If it's not a valid CPT-onomy... if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { - + // Remove this taxonomy unset( $taxonomies[ $index ] ); - + } - } - + // If we have no valid taxonomies then there's no point in continuing if ( ! $taxonomies ) { return false; } - + // We're gonna store the term counts in an array indexed by term ID $terms_count = array(); - + // Make sure term IDs is an array if ( ! empty( $term_ids ) && ! is_array( $term_ids ) ) { $term_ids = explode( ',', $term_ids ); } - + // This will hold taxonomies that need to be queried $taxonomies_to_query = array(); - + // First, see if we can get from the cache - foreach( $taxonomies as $taxonomy ) { - + foreach ( $taxonomies as $taxonomy ) { + // Checking the cache... if ( ( $terms_count_from_cache = wp_cache_get( $taxonomy, 'cpt_onomies_terms_count' ) ) - && $terms_count_from_cache !== false + && false !== $terms_count_from_cache && is_array( $terms_count_from_cache ) ) { - + // If we only want specific term IDs... if ( ! empty( $term_ids ) ) { - + // Then only get specific term IDs from the cache - foreach( $terms_count_from_cache as $term_id => $term_id_count ) { + foreach ( $terms_count_from_cache as $term_id => $term_id_count ) { if ( ! in_array( $term_id, $term_ids ) ) { unset( $terms_count_from_cache[ $term_id ] ); } } - } - + // Add the counts from the cache $terms_count += $terms_count_from_cache; - + } else { - + // We need to query this taxonomy $taxonomies_to_query[] = $taxonomy; - + } - } - + // These taxonomies weren't cached so we need to query the database if ( $taxonomies_to_query ) { - + // Build an array of eligible post types for these CPT-onomies $eligible_post_types = array(); - + // Get eligible post types for each taxonomy - foreach( $taxonomies_to_query as $index => $taxonomy ) { - + foreach ( $taxonomies_to_query as $index => $taxonomy ) { + // Get eligible post types - $tax_eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : NULL; - + $tax_eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : null; + // If we have some, then merge with the array if ( $tax_eligible_post_types ) { $eligible_post_types = array_merge( $eligible_post_types, $tax_eligible_post_types ); } - } - + // Make sure the eligible post types are unique $eligible_post_types = array_unique( $eligible_post_types ); - + // If we have no eligible post types then there's no point in continuing if ( $eligible_post_types ) { - + // Build the terms count query $terms_count_query = "SELECT meta.meta_value AS ID, terms.post_type AS taxonomy, COUNT(meta.meta_value) AS count @@ -463,67 +453,63 @@ private function get_terms_count( $taxonomies, $term_ids = NULL ) { ON objects.ID = meta.post_id AND objects.post_type IN ( '" . implode( "','", $eligible_post_types ) . "' ) AND objects.post_status = 'publish'"; - - // If we have no specific term IDs then we have to join the posts table to match taxonomy/post type - if ( empty( $term_ids ) ) { - - $terms_count_query .= " INNER JOIN {$wpdb->posts} terms - ON terms.ID = meta.meta_value - AND terms.post_type IN ( '" . implode( "','", $taxonomies_to_query ) . "' ) - AND objects.post_status = 'publish'"; - - } - - $terms_count_query .= " WHERE meta.meta_key = %s"; - - // If we have term IDs - if ( ! empty( $term_ids ) ) - $terms_count_query .= " AND meta.meta_value IN ( '" . implode( "','", $term_ids ) . "' )"; - - $terms_count_query .= " GROUP BY meta.meta_value"; - + + // If we have no specific term IDs then we have to join the posts table to match taxonomy/post type + if ( empty( $term_ids ) ) { + + $terms_count_query .= " INNER JOIN {$wpdb->posts} terms + ON terms.ID = meta.meta_value + AND terms.post_type IN ( '" . implode( "','", $taxonomies_to_query ) . "' ) + AND objects.post_status = 'publish'"; + + } + + $terms_count_query .= ' WHERE meta.meta_key = %s'; + + // If we have term IDs + if ( ! empty( $term_ids ) ) { + $terms_count_query .= " AND meta.meta_value IN ( '" . implode( "','", $term_ids ) . "' )"; + } + + $terms_count_query .= ' GROUP BY meta.meta_value'; + // Get term count from the database if ( $terms_count_from_db = $wpdb->get_results( $wpdb->prepare( $terms_count_query, CPT_ONOMIES_POSTMETA_KEY ) ) ) { - + // If no specific term IDs, separate count by taxonomy for the cache $terms_count_by_taxonomy = array(); - + // If we have a posts count, we need to rearrange the array - foreach( $terms_count_from_db as $terms_count_index => $terms_count_item ) { - + foreach ( $terms_count_from_db as $terms_count_index => $terms_count_item ) { + // Get the term count $term_count = isset( $terms_count_item->count ) && $terms_count_item->count > 0 ? $terms_count_item->count : 0; - + // Store count by term ID $terms_count[ $terms_count_item->ID ] = $term_count; - + // Store count by taxonomy and term ID $terms_count_by_taxonomy[ $terms_count_item->taxonomy ][ $terms_count_item->ID ] = $term_count; - + } - + // If no specific term IDs, set the cache if ( empty( $term_ids ) && ! empty( $terms_count_by_taxonomy ) ) { - - foreach( $terms_count_by_taxonomy as $taxonomy => $taxonomy_terms_count ) { - + + foreach ( $terms_count_by_taxonomy as $taxonomy => $taxonomy_terms_count ) { + // Store the terms count for this taxonomy wp_cache_set( $taxonomy, $taxonomy_terms_count, 'cpt_onomies_terms_count' ); - + } - } - } - } - } - + return $terms_count; - } - + /** * This function determines how many times a term has been assigned to an object. * @@ -535,30 +521,29 @@ private function get_terms_count( $taxonomies, $term_ids = NULL ) { */ public function get_term_count( $term_id, $taxonomy ) { global $wpdb, $cpt_onomies_manager; - + // Must have a term ID and be a CPT-onomy if ( is_numeric( $term_id ) && $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { - + // We're only counting the posts who are supposed to be associated with this taxonomy if ( ( $eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : array() ) && ! empty( $eligible_post_types ) ) { - + return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpposts_object ON wpposts_object.ID = wpcountmeta.post_id AND wpposts_object.post_status = 'publish' AND wpposts_object.post_type IN ( '" . implode( "','", $eligible_post_types ) . "' ) INNER JOIN {$wpdb->posts} wpposts_term ON wpposts_term.ID = wpcountmeta.meta_value AND wpposts_term.post_status = 'publish' AND wpposts_term.post_type = %s WHERE wpcountmeta.meta_key = %s AND wpcountmeta.meta_value = %d", $taxonomy, CPT_ONOMIES_POSTMETA_KEY, $term_id ) ); + } - } - + return 0; - } - + /** * This function mimics the WordPress function get_term_children() * because we cannot hook into the function without receiving errors. * * As of WordPress 3.3.2, CPT-onomies will work with get_term_children() - * but I'm not a fan of how WordPress stores the children ids in an option. - * + * but I'm not a fan of how WordPress stores the children ids in an option. + * * @since 1.0 * @uses $wpdb, $cpt_onomies_manager * @param string $term_id ID of Term to get children @@ -571,29 +556,28 @@ public function get_term_children( $term_id, $taxonomy ) { if ( ! taxonomy_exists( $taxonomy ) ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy', 'cpt-onomies' ) ); } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_term_children( $term_id, $taxonomy ); } - + $term_id = intval( $term_id ); - - $children = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_parent = %d AND post_status = 'publish' AND post_type = %s", $term_id, $taxonomy ) ); - + + $children = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status = 'publish' AND post_type = %s", $term_id, $taxonomy ) ); + if ( empty( $children ) ) { return array(); } - + foreach ( $children as $child_id ) { - $children = array_merge( $children, $this->get_term_children( $child_id, $taxonomy ) ); + $children = array_merge( $children, $this->get_term_children( $child_id, $taxonomy ) ); } - + return $children; - } /** @@ -607,12 +591,12 @@ public function get_term_children( $term_id, $taxonomy ) { */ public function get_term_ancestors( $term_id = 0, $taxonomy = '' ) { global $cpt_onomies_manager; - + if ( ! taxonomy_exists( $taxonomy ) ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy', 'cpt-onomies' ) ); } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ @@ -621,13 +605,13 @@ public function get_term_ancestors( $term_id = 0, $taxonomy = '' ) { } $term_id = (int) $term_id; - + $ancestors = array(); - + if ( empty( $term_id ) ) { return apply_filters( 'get_ancestors', $ancestors, $term_id, $taxonomy ); } - + if ( is_taxonomy_hierarchical( $taxonomy ) ) { $term = $this->get_term( $term_id, $taxonomy ); while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { @@ -635,11 +619,10 @@ public function get_term_ancestors( $term_id = 0, $taxonomy = '' ) { $term = $this->get_term( $term->parent, $taxonomy ); } } - + return apply_filters( 'get_ancestors', $ancestors, $term_id, $taxonomy ); - } - + /** * This function mimics the WordPress function term_exists() * because we cannot hook into the function without receiving errors. @@ -653,57 +636,53 @@ public function get_term_ancestors( $term_id = 0, $taxonomy = '' ) { */ public function term_exists( $term, $taxonomy = '', $parent = 0 ) { global $wpdb, $cpt_onomies_manager; - + if ( is_int( $term ) ) { - + if ( 0 == $term ) { return 0; } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! empty( $taxonomy ) && ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return term_exists( $term, $taxonomy, $parent ); - } - - else if ( ! empty( $taxonomy ) ) { + } elseif ( ! empty( $taxonomy ) ) { return $this->get_term( $term, $taxonomy ); } - + // Get term info and convert - $term = $this->convert_object_to_cpt_onomy_term( $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE ID = %d AND post_status = 'publish'", $term ) ) ); - + $term = $this->convert_object_to_cpt_onomy_term( $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE ID = %d AND post_status = 'publish'", $term ) ) ); + if ( ! $term ) { return 0; } - + // Make sure this term belongs to a CPT-onomy if ( $cpt_onomies_manager->is_registered_cpt_onomy( $term->taxonomy ) ) { return $term; } - + return 0; - + } - + $term = trim( stripslashes( $term ) ); - - if ( '' === $slug = sanitize_title($term) ) { + + if ( '' === ( $slug = sanitize_title( $term ) ) ) { return 0; } - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! empty( $taxonomy ) && ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return term_exists( $term, $taxonomy, $parent ); - } - - else if ( ! empty( $taxonomy ) ) { - + } elseif ( ! empty( $taxonomy ) ) { + // Check for parent $parent = (int) $parent; if ( $parent > 0 ) { @@ -711,43 +690,51 @@ public function term_exists( $term, $taxonomy = '', $parent = 0 ) { } else { $parent = null; } - - // Get CPT-onomy's eligible post types + + // Get CPT-onomy's eligible post types. $eligible_post_types = ( $tax = get_taxonomy( $taxonomy ) ) && isset( $tax->object_type ) ? $tax->object_type : array(); - - // Check for name first - // Get term info and term count + + /* + * Check for name first. + * + * Get term info and term count. + */ $result = $wpdb->get_row( $wpdb->prepare( "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wp_count_meta INNER JOIN {$wpdb->posts} wp_count_posts ON wp_count_posts.ID = wp_count_meta.post_id AND wp_count_posts.post_type IN ('" . implode( "','", $eligible_post_types ) . "') AND wp_count_posts.post_status = 'publish' WHERE wp_count_meta.meta_value = wp_posts.ID) AS count, wp_posts.* FROM {$wpdb->posts} wp_posts WHERE wp_posts.post_title = %s AND wp_posts.post_status = 'publish'" . $parent . " AND wp_posts.post_type = %s AND wp_posts.post_status = 'publish'", $term, $taxonomy ) ); - - // Check for slug - // Get term info and term count + + /* + * Check for slug. + * + * Get term info and term count. + */ if ( empty( $result ) ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wp_count_meta INNER JOIN {$wpdb->posts} wp_count_posts ON wp_count_posts.ID = wp_count_meta.post_id AND wp_count_posts.post_type IN ('" . implode( "','", $eligible_post_types ) . "') AND wp_count_posts.post_status = 'publish' WHERE wp_count_meta.meta_value = wp_posts.ID) AS count, wp_posts.* FROM {$wpdb->posts} wp_posts WHERE wp_posts.post_name = %s" . $parent . " AND wp_posts.post_type = %s AND wp_posts.post_status = 'publish'", $term, $taxonomy ) ); } - + if ( ! empty( $result ) && $cpt_onomies_manager->is_registered_cpt_onomy( $result->post_type ) ) { - + // Save count and remove from term for conversion $term_count = $result->count; unset( $result->count ); - - // Convert term - // Dont get count, we'll add it back + + /* + * Convert term. + * + * Dont get count, we'll add it back. + */ $term = $this->convert_object_to_cpt_onomy_term( $result, false ); - + if ( ! $term ) { return 0; } - + // Add count $term->count = $term_count; - + return $term; - + } - } else { - + // Check for parent $parent = (int) $parent; if ( $parent > 0 ) { @@ -755,24 +742,23 @@ public function term_exists( $term, $taxonomy = '', $parent = 0 ) { } else { $parent = null; } - + // Check for name first - $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE post_title = %s" . $parent . " AND post_status = 'publish'", $term ) ); - + $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_title = %s {$parent} AND post_status = 'publish'", $term ) ); + // Check for slug if ( empty( $result ) ) { - $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->posts . " WHERE post_name = %s" . $parent . " AND post_status = 'publish'", $term ) ); + $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_name = %s {$parent} AND post_status = 'publish'", $term ) ); } - + if ( ! empty( $result ) && $cpt_onomies_manager->is_registered_cpt_onomy( $result->post_type ) ) { return $this->convert_object_to_cpt_onomy_term( $result ); } - } - + return 0; } - + /** * This function mimics the WordPress function get_term_link() * because we cannot hook into the function without receiving errors @@ -788,15 +774,15 @@ public function term_exists( $term, $taxonomy = '', $parent = 0 ) { */ public function get_term_link( $term, $taxonomy ) { global $wp_rewrite, $cpt_onomies_manager; - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_term_link( $term, $taxonomy ); } - + if ( ! is_object( $term ) ) { if ( is_int( $term ) ) { $term = $this->get_term( $term, $taxonomy ); @@ -804,64 +790,67 @@ public function get_term_link( $term, $taxonomy ) { $term = $this->get_term_by( 'slug', $term, $taxonomy ); } } - + if ( ! is_object( $term ) ) { $term = new WP_Error( 'invalid_term', __( 'Empty Term', 'cpt-onomies' ) ); } - + if ( is_wp_error( $term ) ) { return $term; } - + $taxonomy = $term->taxonomy; - - $termlink = NULL; + + $termlink = null; $slug = $term->slug; - $t = get_taxonomy( $taxonomy ); - - // Link to CPT-onomy archive page + $t = get_taxonomy( $taxonomy ); + + /* + * Link to CPT-onomy archive page. + * + * If no archive page, link to CPT post. + */ if ( isset( $t->cpt_onomy_archive_slug ) && ! empty( $t->cpt_onomy_archive_slug ) ) { - + $termlink = $t->cpt_onomy_archive_slug; - + if ( $t->hierarchical ) { + $hierarchical_slugs = array(); $ancestors = get_ancestors( $term->term_id, $taxonomy ); - foreach ( (array)$ancestors as $ancestor ) { + + foreach ( (array) $ancestors as $ancestor ) { $ancestor_term = $this->get_term( $ancestor, $taxonomy ); $hierarchical_slugs[] = $ancestor_term->slug; } + $hierarchical_slugs = array_reverse( $hierarchical_slugs ); $hierarchical_slugs[] = $slug; // Replace the variables ($post_type and $term) $slug = implode( '/', $hierarchical_slugs ); - + } - + // Replace the variables ($post_type and $term) $termlink = str_replace( array( '$post_type', '$term_slug', '$term_id' ), array( $taxonomy, $slug, $term->term_id ), $termlink ); - + $termlink = home_url( user_trailingslashit( $termlink, 'category' ) ); - - } - - // If no archive page, link to CPT post - else { + + } else { $termlink = get_permalink( $term->term_id ); } - + // Back Compat filters. if ( 'post_tag' == $taxonomy ) { $termlink = apply_filters( 'tag_link', $termlink, $term->term_id ); - } else if ( 'category' == $taxonomy ) { + } elseif ( 'category' == $taxonomy ) { $termlink = apply_filters( 'category_link', $termlink, $term->term_id ); } - + return apply_filters( 'term_link', $termlink, $term, $taxonomy ); - } - + /** * This function mimics the WordPress function get_edit_term_link() * because we cannot hook into the function without receiving errors. @@ -874,48 +863,47 @@ public function get_term_link( $term, $taxonomy ) { * @return string */ public function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { - global $cpt_onomies_manager; - - /** + global $cpt_onomies_manager; + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_edit_term_link( $term_id, $taxonomy, $object_type ); } - + $post_type = get_post_type_object( $taxonomy ); if ( ! current_user_can( $post_type->cap->edit_posts ) ) { return; } - + $term = $this->get_term( $term_id, $taxonomy ); - + if ( ! $term ) { return; } - + $args = array( - 'post' => $term->term_id, - 'action' => 'edit' + 'post' => $term->term_id, + 'action' => 'edit', ); - + if ( $object_type ) { $args['post_type'] = $object_type; } - + $location = add_query_arg( $args, admin_url( 'post.php' ) ); - + return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); - } - + /** * This function mimics the WordPress function previous_post_link() * because we cannot use that function properly. * * In the WordPress function, previous_post_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -926,7 +914,7 @@ public function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { * @param array|string $excluded_term_ids Optional. Array or comma-separated list of excluded term IDs. * @param string $cpt_onomy - name of the CPT-onomy for $in_same_cpt_onomy */ - function previous_post_link( $format='« %link', $link='%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $cpt_onomy = '' ) { + function previous_post_link( $format = '« %link', $link = '%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $cpt_onomy = '' ) { global $cpt_onomies_manager; if ( empty( $format ) ) { @@ -938,15 +926,14 @@ function previous_post_link( $format='« %link', $link='%title', $in_same_c } else { $this->adjacent_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids, true, $cpt_onomy ); } - } - + /** * This function mimics the WordPress function next_post_link() * because we cannot use that function properly. * * In the WordPress function, next_post_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -957,29 +944,28 @@ function previous_post_link( $format='« %link', $link='%title', $in_same_c * @param array|string $excluded_term_ids Optional. Array or comma-separated list of excluded term IDs. * @param string $cpt_onomy - name of the CPT-onomy for $in_same_cpt_onomy */ - function next_post_link( $format='%link »', $link='%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $cpt_onomy = '' ) { + function next_post_link( $format = '%link »', $link = '%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $cpt_onomy = '' ) { global $cpt_onomies_manager; - + // Make sure we have a format if ( empty( $format ) ) { $format = '%link »'; } - + // If it's empty or not a valid CPT-onomy, then run the default WordPress function if ( empty( $cpt_onomy ) || ! $cpt_onomies_manager->is_registered_cpt_onomy( $cpt_onomy ) ) { next_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids ); } else { $this->adjacent_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids, false, $cpt_onomy ); } - } - + /** * This function mimics the WordPress function adjacent_post_link() * because we cannot use that function properly. * * In the WordPress function, adjacent_post_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -993,54 +979,54 @@ function next_post_link( $format='%link »', $link='%title', $in_same_cpt_o */ function adjacent_post_link( $format, $link, $in_same_cpt_onomy = false, $excluded_term_ids = '', $previous = true, $cpt_onomy = '' ) { global $cpt_onomies_manager; - + // If it's empty or not a valid CPT-onomy, then run the default WordPress function if ( empty( $cpt_onomy ) || ! $cpt_onomies_manager->is_registered_cpt_onomy( $cpt_onomy ) ) { - + adjacent_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids, $previous ); - + } else { - + if ( $previous && is_attachment() ) { $post = &get_post( $GLOBALS['post']->post_parent ); } else { $post = $this->get_adjacent_post( $in_same_cpt_onomy, $excluded_term_ids, $previous, $cpt_onomy ); } - + if ( ! $post ) { return; } - + $title = $post->post_title; - + if ( empty( $post->post_title ) ) { $title = $previous ? __( 'Previous Post', 'cpt-onomies' ) : __( 'Next Post', 'cpt-onomies' ); } - + $title = apply_filters( 'the_title', $title, $post->ID ); $date = mysql2date( get_option( 'date_format' ), $post->post_date ); $rel = $previous ? 'prev' : 'next'; - - $string = ''; - $link = str_replace('%title', $title, $link); - $link = str_replace('%date', $date, $link); + + $string = ''; + $link = str_replace( '%title', $title, $link ); + $link = str_replace( '%date', $date, $link ); $link = $string . $link . ''; - - $format = str_replace('%link', $link, $format); - + + $format = str_replace( '%link', $link, $format ); + $adjacent = $previous ? 'previous' : 'next'; - + echo apply_filters( "{$adjacent}_post_link", $format, $link ); - + } } - + /** * This function mimics the WordPress function prev_post_rel_link() * because we cannot use that function properly. * * In the WordPress function, prev_post_rel_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -1057,13 +1043,13 @@ function prev_post_rel_link( $title = '%title', $in_same_cpt_onomy = false, $exc } echo $this->get_adjacent_post_rel_link( $title, $in_same_cpt_onomy, $excluded_term_ids, true, $cpt_onomy ); } - + /** * This function mimics the WordPress function next_post_rel_link() * because we cannot use that function properly. * * In the WordPress function, next_post_rel_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -1081,13 +1067,13 @@ function next_post_rel_link( $title = '%title', $in_same_cpt_onomy = false, $exc echo $this->get_adjacent_post_rel_link( $title, $in_same_cpt_onomy, $excluded_term_ids, false, $cpt_onomy ); } } - + /** * This function mimics the WordPress function get_adjacent_post_rel_link() * because we cannot use that function properly. * * In the WordPress function, get_adjacent_post_rel_link(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -1101,45 +1087,45 @@ function next_post_rel_link( $title = '%title', $in_same_cpt_onomy = false, $exc */ function get_adjacent_post_rel_link( $title = '%title', $in_same_cpt_onomy = false, $excluded_term_ids = '', $previous = true, $cpt_onomy = '' ) { global $cpt_onomies_manager; - + if ( empty( $cpt_onomy ) || ! $cpt_onomies_manager->is_registered_cpt_onomy( $cpt_onomy ) ) { return get_adjacent_post_rel_link( $title, $in_same_cpt_onomy, $excluded_term_ids, $previous ); } - - if ( $previous && is_attachment() && is_object( $GLOBALS[ 'post' ] ) ) { + + if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) { $post = &get_post( $GLOBALS['post']->post_parent ); } else { $post = $this->get_adjacent_post( $in_same_cpt_onomy, $excluded_term_ids, $previous, $cpt_onomy ); } - + if ( empty( $post ) ) { return; } - + if ( empty( $post->post_title ) ) { $post->post_title = $previous ? __( 'Previous Post', 'cpt-onomies' ) : __( 'Next Post', 'cpt-onomies' ); } - - $date = mysql2date(get_option('date_format'), $post->post_date); - + + $date = mysql2date( get_option( 'date_format' ), $post->post_date ); + $title = str_replace( '%title', $post->post_title, $title ); $title = str_replace( '%date', $date, $title ); $title = apply_filters( 'the_title', $title, $post->ID ); - + $link = $previous ? "\n"; - + $link .= "' href='" . get_permalink( $post ) . "' />\n"; + $adjacent = $previous ? 'previous' : 'next'; return apply_filters( "{$adjacent}_post_rel_link", $link ); } - + /** * This function mimics the WordPress function get_adjacent_post() * because we cannot use that function properly. * * In the WordPress function, get_adjacent_post(), you are only allowed - * to use 'category' for your taxonomy but this function adds a new parameter that + * to use 'category' for your taxonomy but this function adds a new parameter that * allows you to designate which CPT-onomy you would like to use. * * @since 1.0.2 @@ -1152,30 +1138,30 @@ function get_adjacent_post_rel_link( $title = '%title', $in_same_cpt_onomy = fal */ function get_adjacent_post( $in_same_cpt_onomy = false, $excluded_term_ids = '', $previous = true, $cpt_onomy = '' ) { global $post, $wpdb, $cpt_onomies_manager; - + if ( empty( $post ) ) { return null; } - + if ( empty( $cpt_onomy ) || ! $cpt_onomies_manager->is_registered_cpt_onomy( $cpt_onomy ) ) { return get_adjacent_post( $in_same_cpt_onomy, $excluded_term_ids, $previous ); } - + $current_post_date = $post->post_date; $join = ''; $posts_in_ex_terms_sql = ''; - + if ( $in_same_cpt_onomy || ! empty( $excluded_term_ids ) ) { - + $join = " INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id AND pm.meta_key ='" . CPT_ONOMIES_POSTMETA_KEY . "' INNER JOIN {$wpdb->posts} AS p2 ON pm.meta_value = p2.ID AND p2.post_type = '" . $cpt_onomy . "'"; - + if ( $in_same_cpt_onomy ) { $join .= " AND pm.meta_value IN ( '" . implode( "','", wp_get_object_terms( $post->ID, $cpt_onomy, array( 'fields' => 'ids' ) ) ) . "' )"; } - + if ( ! empty( $excluded_term_ids ) ) { - + if ( ! is_array( $excluded_term_ids ) ) { // Back-compat, $excluded_term_ids used to be IDs separated by " and " @@ -1185,46 +1171,42 @@ function get_adjacent_post( $in_same_cpt_onomy = false, $excluded_term_ids = '', } else { $excluded_term_ids = explode( ',', $excluded_term_ids ); } - } - + $excluded_term_ids = array_map( 'intval', $excluded_term_ids ); - + if ( ! empty( $excluded_term_ids ) ) { - $posts_in_ex_terms_sql = " AND ( SELECT COUNT(*) FROM {$wpdb->postmeta} pm2 WHERE pm2.post_id = p.ID AND pm2.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND pm2.meta_value NOT IN (" . implode(',', $excluded_term_ids) . ") ) = ( SELECT COUNT(*) FROM {$wpdb->postmeta} pm2 WHERE pm2.post_id = p.ID AND pm.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' )"; + $posts_in_ex_terms_sql = " AND ( SELECT COUNT(*) FROM {$wpdb->postmeta} pm2 WHERE pm2.post_id = p.ID AND pm2.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND pm2.meta_value NOT IN (" . implode( ',', $excluded_term_ids ) . ") ) = ( SELECT COUNT(*) FROM {$wpdb->postmeta} pm2 WHERE pm2.post_id = p.ID AND pm.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' )"; } - } - } - + $adjacent = $previous ? 'previous' : 'next'; $op = $previous ? '<' : '>'; $order = $previous ? 'DESC' : 'ASC'; - + $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cpt_onomy, $excluded_term_ids ); - $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_terms_sql", $current_post_date, $post->post_type), $in_same_cpt_onomy, $excluded_term_ids ); + $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_terms_sql", $current_post_date, $post->post_type ), $in_same_cpt_onomy, $excluded_term_ids ); $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); - + $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; - $query_key = 'adjacent_post_' . md5($query); - $result = wp_cache_get($query_key, 'counts'); + $query_key = 'adjacent_post_' . md5( $query ); + $result = wp_cache_get( $query_key, 'counts' ); if ( false !== $result ) { return $result; } - + $result = $wpdb->get_row( "SELECT p.* FROM $wpdb->posts AS p $join $where $sort" ); if ( null === $result ) { $result = ''; } - - wp_cache_set($query_key, $result, 'counts'); - + + wp_cache_set( $query_key, $result, 'counts' ); + return $result; - } - + /** * This function mimics the WordPress function get_the_term_list() * because we cannot hook into the function because get_the_term_list() @@ -1241,25 +1223,25 @@ function get_adjacent_post( $in_same_cpt_onomy = false, $excluded_term_ids = '', */ public function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', $after = '' ) { global $cpt_onomies_manager; - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return get_the_term_list( $id, $taxonomy, $before, $sep, $after ); } - + $terms = get_the_terms( $id, $taxonomy ); - + if ( is_wp_error( $terms ) ) { return $terms; } - + if ( empty( $terms ) ) { return false; } - + foreach ( $terms as $term ) { $link = $this->get_term_link( $term, $taxonomy ); if ( is_wp_error( $link ) ) { @@ -1267,12 +1249,12 @@ public function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', } $term_links[] = ''; } - + $term_links = apply_filters( "term_links-$taxonomy", $term_links ); - + return $before . join( $sep, $term_links ) . $after; } - + /** * This function mimics the WordPress function the_terms() * because we cannot hook into the function without receiving errors. @@ -1288,30 +1270,30 @@ public function get_the_term_list( $id = 0, $taxonomy, $before = '', $sep = '', */ public function the_terms( $id = 0, $taxonomy, $before = '', $sep = ', ', $after = '' ) { global $cpt_onomies_manager; - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return the_terms( $id, $taxonomy, $before, $sep, $after ); } - + $term_list = $this->get_the_term_list( $id, $taxonomy, $before, $sep, $after ); - + if ( is_wp_error( $term_list ) ) { return false; } - + echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after ); - + } - + /** * This function hooks into WordPress get_terms() and allows the plugin * to change what terms are retrieved. This function is invoked in numerous places * and is called whenever the WordPress function get_terms() is used. - * + * * This function is applied to the filter 'get_terms'. * * Do not call this function on its own, instead use the core WordPress function: get_terms(). @@ -1322,23 +1304,23 @@ public function the_terms( $id = 0, $taxonomy, $before = '', $sep = ', ', $after * @param string|array $taxonomies - the taxonomies we're pulling terms from * @param array $args - arguments used to customize which terms are returned (!! means its not supported... yet) 'orderby' Default is 'name'. Can be name, count, term_group, slug or nothing - (will use term_id), Passing a custom value other than these will cause + (will use term_id), Passing a custom value other than these will cause it to order based on the custom value. 'order' Default is ASC. Can use DESC. - 'hide_empty' Default is true. Will not return empty terms, which means terms whose + 'hide_empty' Default is true. Will not return empty terms, which means terms whose count is 0 according to the given taxonomy. - 'exclude' Default is an empty array. An array, comma- or space-delimited string - of term ids to exclude from the return array. If 'include' is non-empty, + 'exclude' Default is an empty array. An array, comma- or space-delimited string + of term ids to exclude from the return array. If 'include' is non-empty, 'exclude' is ignored. - !! 'exclude_tree' Default is an empty array. An array, comma- or space-delimited string - of term ids to exclude from the return array, along with all of their + !! 'exclude_tree' Default is an empty array. An array, comma- or space-delimited string + of term ids to exclude from the return array, along with all of their descendant terms according to the primary taxonomy. If 'include' is non-empty, 'exclude_tree' is ignored. - 'include' Default is an empty array. An array, comma- or space-delimited string of + 'include' Default is an empty array. An array, comma- or space-delimited string of term ids to include in the return array. 'number' The maximum number of terms to return. Default is to return them all. 'offset' The number by which to offset the terms query. Default is 0. - 'fields' Default is 'all', which returns an array of term objects. If 'fields' is + 'fields' Default is 'all', which returns an array of term objects. If 'fields' is 'ids' or 'names', returns an array of integers or strings, respectively. 'slug' Returns terms whose "slug" matches this value. Default is empty string. !! 'hierarchical' Default is true. Whether to include terms that have non-empty descendants (even if 'hide_empty' is set to true). @@ -1346,26 +1328,26 @@ public function the_terms( $id = 0, $taxonomy, $before = '', $sep = ', ', $after !! 'name__like' Returned terms' names will begin with the value of 'name__like', case-insensitive. Default is empty string. 'pad_counts' Default is false. If set to true will include the quantity of a term's children in the quantity of each term's "count" object variable. !! 'get' If set to 'all' instead of its default empty string, returns terms regardless of ancestry or whether the terms are empty. - !! 'child_of' When used should be set to the integer of a term ID. Its default is 0. If set to a non-zero value, all returned terms - will be descendants of that term according to the given taxonomy. Hence 'child_of' is set to 0 if more than one taxonomy + !! 'child_of' When used should be set to the integer of a term ID. Its default is 0. If set to a non-zero value, all returned terms + will be descendants of that term according to the given taxonomy. Hence 'child_of' is set to 0 if more than one taxonomy is passed in $taxonomies, because multiple taxonomies make term ancestry ambiguous. - !! 'parent' When used should be set to the integer of a term ID. Its default is the empty string '', which has a different meaning - from the integer 0. If set to an integer value, all returned terms will have as an immediate ancestor the term whose ID is - specified by that integer according to the given taxonomy. The 'parent' argument is different from 'child_of' in that a + !! 'parent' When used should be set to the integer of a term ID. Its default is the empty string '', which has a different meaning + from the integer 0. If set to an integer value, all returned terms will have as an immediate ancestor the term whose ID is + specified by that integer according to the given taxonomy. The 'parent' argument is different from 'child_of' in that a term X is considered a 'parent' of term Y only if term X is the father of term Y, not its grandfather or great-grandfather, etc. * @return array - the terms after they have been filtered */ public function get_terms( $terms, $taxonomies, $args ) { global $cpt_onomies_manager, $current_screen, $post, $wpdb; - + // If taxonomy name is string, convert to array if ( ! is_array( $taxonomies ) ) { $taxonomies = array( $taxonomies ); } - + // This function only filters registered CPT-onomies $cpt_taxonomies = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { $cpt_taxonomies[] = $taxonomy; } @@ -1375,69 +1357,69 @@ public function get_terms( $terms, $taxonomies, $args ) { if ( empty( $cpt_taxonomies ) ) { return $terms; } - - /** + + /* * Since these parameters are not included in get_terms(), * we have to make sure they're included in our filter. */ $defaults = array( 'show_count' => false ); $args = wp_parse_args( $args, $defaults ); - - /** + + /* * Since 'fields' = 'count' will cause get_terms to 'return' * before we can filter, the adjust_get_terms_args() filter * changes 'count' to 'ids' and adds a custom count argument. * This is included here as a backup. */ - if ( isset( $args[ 'fields' ] ) && $args[ 'fields' ] == 'count' ) { - $args[ 'fields' ] = 'ids'; - $args[ 'cpt_onomy_get_count' ] = true; + if ( isset( $args['fields'] ) && 'count' == $args['fields'] ) { + $args['fields'] = 'ids'; + $args['cpt_onomy_get_count'] = true; } - + extract( $args, EXTR_SKIP ); - + // Fix arguments for get_posts vs. get_terms - + // WordPress supported orderby - 'count', 'name', 'slug', 'none', 'id' - (still need to add support for 'term_group') if ( strtolower( $orderby ) == 'none' || strtolower( $orderby ) == 'id' ) { $orderby = 'id'; - } else if ( ! in_array( strtolower( $orderby ), array( 'count', 'slug', 'term_group' ) ) ) { + } elseif ( ! in_array( strtolower( $orderby ), array( 'count', 'slug', 'term_group' ) ) ) { $orderby = 'title'; //Default is 'name'/'title' } - + // WordPress supported order - 'asc' and 'desc' (default is asc) $order = ( isset( $order ) && ( in_array( strtolower( $order ), array( 'asc', 'desc' ) ) ) ) ? strtolower( $order ) : 'asc'; - + // Default is -1 $numberposts = ( isset( $number ) && is_numeric( $number ) && ( $number > 0 ) ) ? $number : -1; - + // Default is 0 $offset = ( isset( $offset ) && is_numeric( $offset ) && ( $offset > 0 ) ) ? $offset : 0; - + // WordPress supported fields - 'all', 'ids', 'names' (default is all) if ( in_array( strtolower( $fields ), array( 'ids', 'names', 'id=>parent' ) ) ) { $fields = strtolower( $fields ); } else { $fields = 'all'; } - - /** + + /* * Clear out any existing terms and start over. * This is helpful if, somehow, some actual terms got assigned to the taxonomy. */ - if ( ! empty( $terms ) && $fields != 'id=>parent' ) { + if ( ! empty( $terms ) && 'id=>parent' != $fields ) { $new_terms = array(); - foreach( $terms as $term ) { + foreach ( $terms as $term ) { if ( ! isset( $term->taxonomy ) || ! in_array( $term->taxonomy, $cpt_taxonomies ) ) { $new_terms[] = $term; } } $terms = $new_terms; } - + // Get terms for each CPT-onomy - foreach( $cpt_taxonomies as $taxonomy ) { - + foreach ( $cpt_taxonomies as $taxonomy ) { + // Get the custom post type posts (which are the terms) $cpt_posts = get_posts( array( 'get_cpt_onomy_terms' => true, @@ -1450,38 +1432,46 @@ public function get_terms( $terms, $taxonomies, $args ) { 'exclude' => $exclude, 'include' => $include, 'name' => $slug, - 's' => $search + 's' => $search, ) ); - + // If we have posts, then we have terms if ( ! empty( $cpt_posts ) ) { - + // We don't want to show the current "term" if on the edit post screen in the admin - $current = ( is_admin() && $current_screen && $current_screen->base == 'post' && $current_screen->parent_base == 'edit' && $current_screen->post_type == $taxonomy && isset( $post->ID ) ) ? $post->ID : NULL; - + $current = null; + if ( is_admin() + && $current_screen + && 'post' == $current_screen->base + && 'edit' == $current_screen->parent_base + && $current_screen->post_type == $taxonomy + && isset( $post->ID ) ) { + $current = $post->ID; + } + // Store the count for the CPT-onomy's terms $cpt_posts_count = $this->get_terms_count( $taxonomy ); - + // Loop through the posts and setup the terms foreach ( $cpt_posts as $this_post ) { - + // Dont show current "term" if ( empty( $current ) || ( ! empty( $current ) && $current != $this_post->ID ) ) { - + // Dont get count when converting because we'll set it next $this_term = $this->convert_object_to_cpt_onomy_term( $this_post, false ); - + // If no term, then continue to next post if ( ! $this_term ) { continue; } - + // Assign count $this_term->count = isset( $cpt_posts_count[ $this_post->ID ] ) && $cpt_posts_count[ $this_post->ID ] > 0 ? $cpt_posts_count[ $this_post->ID ] : 0; - + if ( ! $hide_empty || ( $hide_empty && isset( $this_term->count ) && $this_term->count > 0 ) ) { - - switch( $fields ) { + + switch ( $fields ) { case 'ids': $this_term = $this_term->term_id; break; @@ -1489,62 +1479,57 @@ public function get_terms( $terms, $taxonomies, $args ) { $this_term = $this_term->name; break; } - + // 'id=>parent' is a beast all its own - if ( $fields == 'id=>parent' ) { + if ( 'id=>parent' == $fields ) { $terms[ $this_term->term_id ] = $this_term->parent; } else { $terms[] = $this_term; } - } - } - } - } - } - - /** + + /* * They just want the count. * This argument is defined in $this->adjust_get_terms_args(). */ if ( isset( $cpt_onomy_get_count ) && $cpt_onomy_get_count ) { return count( $terms ); } - - /** + + /* * If true, we have to do manual sorting. * if false, it's already taken care of. */ $manual_sort = false; - - // This means we have a mixture of taxonomies and CPT-onomies + + /* + * This means we have a mixture of taxonomies and CPT-onomies. + * + * Otherwise, we have to manual sort certain $orderby parameters + * because they do not work in get_posts(). + */ if ( ! empty( $cpt_taxonomies ) && ( count( $taxonomies ) > 1 || $taxonomies != $cpt_taxonomies ) ) { $manual_sort = true; - } - - // We have to manual sort certain $orderby parameters because they do not work in get_posts() - else if ( in_array( $orderby, array( 'count', 'slug', 'term_group' ) ) ) { + } elseif ( in_array( $orderby, array( 'count', 'slug', 'term_group' ) ) ) { $manual_sort = true; } - + // 'id=>parent' is a beast all its own - if ( $manual_sort && $fields != 'id=>parent' ) { - - /** + if ( $manual_sort && 'id=>parent' != $fields ) { + + /* * Sort orderby. * If 'ids' or 'names', then we have a simpler sort. */ if ( in_array( $fields, array( 'ids', 'names' ) ) ) { - natcasesort( $terms ); - } else { - switch( $orderby ) { + switch ( $orderby ) { case 'id': usort( $terms, 'cpt_onomies_sort_cpt_onomy_term_by_term_id' ); break; @@ -1561,33 +1546,30 @@ public function get_terms( $terms, $taxonomies, $args ) { case 'term_group': break; } - } - + // Sort order if ( strtolower( $order ) == 'desc' ) { $terms = array_reverse( $terms ); } - } - + // Offset if ( $offset > 0 ) { $terms = array_slice( $terms, $offset ); } - - /** + + /* * Number of posts. * Don't limit when hierarchical. */ if ( $numberposts > 0 ) { $terms = array_slice( $terms, 0, $numberposts ); } - + return $terms; - } - + /** * This function mimics the WordPress function get_objects_in_term() * because we cannot use that function properly. @@ -1602,18 +1584,18 @@ public function get_terms( $terms, $taxonomies, $args ) { */ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { global $wpdb, $cpt_onomies_manager; - + if ( ! is_array( $term_ids ) ) { $term_ids = array( $term_ids ); } - + if ( ! is_array( $taxonomies ) ) { $taxonomies = array( $taxonomies ); } - + // This function only filters registered CPT-onomies $cpt_taxonomies = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { $cpt_taxonomies[] = $taxonomy; } @@ -1625,25 +1607,24 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { } else { $taxonomies = $cpt_taxonomies; } - + $defaults = array( 'order' => 'ASC' ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); - + $order = ( 'desc' == strtolower( $order ) ) ? 'DESC' : 'ASC'; - + $term_ids = array_map( 'intval', $term_ids ); - + $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT {$wpdb->postmeta}.post_id FROM {$wpdb->postmeta} INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.meta_value AND {$wpdb->posts}.post_type IN ('" . implode( "','", $taxonomies ) . "') WHERE {$wpdb->postmeta}.meta_key = %s AND {$wpdb->postmeta}.meta_value IN ('" . implode( "','", $term_ids ) . "') ORDER BY {$wpdb->postmeta}.post_id " . $order, CPT_ONOMIES_POSTMETA_KEY ) ); - + if ( ! $object_ids ) { return array(); } - + return $object_ids; - } - + /** * This function hooks into WordPress get_object_terms() and allows the plugin * to change what terms are retrieved for a particular object. This function is invoked @@ -1673,20 +1654,20 @@ function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { */ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { global $wpdb, $cpt_onomies_manager; - - /** + + /* * When bulk edit, we don't want to return CPT-onomy terms * because bulk edit will add them as regular taxonomy information. */ - if ( isset( $_REQUEST[ 'is_bulk_quick_edit' ] ) && isset( $_REQUEST[ 'bulk_edit' ] ) && 'Update' == $_REQUEST[ 'bulk_edit' ] ) { + if ( isset( $_REQUEST['is_bulk_quick_edit'] ) && isset( $_REQUEST['bulk_edit'] ) && 'Update' == $_REQUEST['bulk_edit'] ) { return $terms; } - - /** + + /* * Does not support $fields = 'tt_ids' since our CPT-onomies * are not actual taxonomies and dont have taxonomy term ids. */ - if ( 'tt_ids' == $args[ 'fields' ] ) { + if ( 'tt_ids' == $args['fields'] ) { return $terms; } @@ -1700,15 +1681,15 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { if ( empty( $object_ids ) || empty( $taxonomies ) ) { return $terms; } - + // If taxonomy name is string, convert to array if ( ! is_array( $taxonomies ) ) { $taxonomies = array( $taxonomies ); } - + // This function only filters registered CPT-onomies $cpt_taxonomies = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { $cpt_taxonomies[] = $taxonomy; } @@ -1721,24 +1702,24 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { // Designate the defaults $defaults = array( - 'orderby' => 'name', - 'order' => 'ASC', - 'fields' => 'all', - 'parent' => '', + 'orderby' => 'name', + 'order' => 'ASC', + 'fields' => 'all', + 'parent' => '', 'update_term_meta_cache' => true, - 'meta_query'=> '', + 'meta_query' => '', ); // Parse arguments with the defaults $args = wp_parse_args( $args, $defaults ); - - /** + + /* * Clear out any existing terms and start over. * This is helpful if, somehow, some actual terms got assigned to the taxonomy. */ if ( ! empty( $terms ) ) { $new_terms = array(); - foreach( $terms as $term ) { + foreach ( $terms as $term ) { if ( ! isset( $term->taxonomy ) || ! in_array( $term->taxonomy, $cpt_taxonomies ) ) { $new_terms[] = $term; } @@ -1748,30 +1729,28 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { // I'm not sure why this runs but is pulled from wp_get_object_terms() if ( count( $taxonomies ) > 1 ) { - + foreach ( $taxonomies as $index => $taxonomy ) { $t = get_taxonomy( $taxonomy ); - if ( isset( $t->args ) && is_array( $t->args ) && $args != array_merge( $args, $t->args ) ) { + if ( isset( $t->args ) && is_array( $t->args ) && array_merge( $args, $t->args ) != $args ) { unset( $taxonomies[ $index ] ); $terms = array_merge( $terms, wp_get_object_terms( $object_ids, $taxonomy, array_merge( $args, $t->args ) ) ); } } - } else { - + $t = get_taxonomy( $taxonomies[0] ); if ( isset( $t->args ) && is_array( $t->args ) ) { $args = array_merge( $args, $t->args ); } - } - + // If there are terms to 'exclude', clean up the parameters - $exclude = ( isset( $args[ 'exclude' ] ) ) ? wp_parse_id_list( $args[ 'exclude' ] ) : array(); - + $exclude = ( isset( $args['exclude'] ) ) ? wp_parse_id_list( $args['exclude'] ) : array(); + // Get the terms - switch( $args['fields'] ) { - + switch ( $args['fields'] ) { + case 'ids': // Get IDs @@ -1781,19 +1760,18 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { wpposts.ID = wpmeta.meta_value AND wpposts.post_type IN ('" . implode( "','", $cpt_taxonomies ) . "') AND wpposts.post_status = 'publish' - WHERE wpmeta.post_id IN (" . implode( ',', $object_ids ) . ") AND wpmeta.meta_key = %s", CPT_ONOMIES_POSTMETA_KEY ) ); + WHERE wpmeta.post_id IN (" . implode( ',', $object_ids ) . ') AND wpmeta.meta_key = %s', CPT_ONOMIES_POSTMETA_KEY ) ); // Process each ID - foreach( $cpt_ids as $cpt_id ) { + foreach ( $cpt_ids as $cpt_id ) { // Don't add if already stored OR if set in $exclude if ( ! in_array( $cpt_id, $terms ) && ! in_array( $cpt_id, $exclude ) ) { $terms[] = $cpt_id; } - } break; - + case 'names': // Get the posts @@ -1812,10 +1790,9 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { if ( ! in_array( $filtered_name, $terms ) ) { $terms[] = $filtered_name; } - } break; - + case 'slugs': // Get slugs @@ -1828,32 +1805,35 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { WHERE wpposts.post_type IN ('" . implode( "','", $cpt_taxonomies ) . "') AND wpposts.post_status = 'publish'", CPT_ONOMIES_POSTMETA_KEY ) ); // Process each slug - foreach( $cpt_slugs as $cpt_slug ) { + foreach ( $cpt_slugs as $cpt_slug ) { if ( ! in_array( $cpt_slug, $terms ) ) { $terms[] = $cpt_slug; } } break; - + case 'all_with_object_id': - - // Build the query - // Get object ID, term count and post info + + /* + * Build the query. + * + * Get object ID, term count and post info. + */ $cpt_posts_query = "SELECT meta.post_id AS object_id, terms.* FROM {$wpdb->postmeta} meta INNER JOIN {$wpdb->posts} terms ON terms.ID = meta.meta_value AND terms.post_type IN ('" . implode( "','", $cpt_taxonomies ) . "') AND terms.post_status = 'publish'"; - - // Exclude certain "terms" - if ( ! empty( $exclude ) ) { - $cpt_posts_query .= " AND terms.ID NOT IN ( " . implode( ',', $exclude ) . " )"; - } - - $cpt_posts_query .= " WHERE meta.meta_key = %s AND meta.post_id IN (" . implode( ',', $object_ids ) . ")"; - + + // Exclude certain "terms" + if ( ! empty( $exclude ) ) { + $cpt_posts_query .= ' AND terms.ID NOT IN ( ' . implode( ',', $exclude ) . ' )'; + } + + $cpt_posts_query .= ' WHERE meta.meta_key = %s AND meta.post_id IN (' . implode( ',', $object_ids ) . ')'; + // Get the posts $cpt_posts = $wpdb->get_results( $wpdb->prepare( $cpt_posts_query, CPT_ONOMIES_POSTMETA_KEY ) ); @@ -1862,99 +1842,104 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { // Get the count for all of the CPT-onomy terms $cpt_posts_count = $this->get_terms_count( $cpt_taxonomies ); - + // Loop through each post and setup the term foreach ( $cpt_posts as $this_post ) { - + if ( ! empty( $this_post ) ) { - + // Save object ID and remove before conversion $object_id = $this_post->object_id; unset( $this_post->object_id ); - - // Convert to term - // Don't need count because we're adding it next + + /* + * Convert to term. + * + * Don't need count because we're adding it next. + */ $term = $this->convert_object_to_cpt_onomy_term( $this_post, false ); - + // If no term then continue to next post if ( ! $term ) { continue; } - + // Add object ID back to the mix $term->object_id = $object_id; - + // Add term count $term->count = isset( $cpt_posts_count[ $this_post->ID ] ) && $cpt_posts_count[ $this_post->ID ] > 0 ? $cpt_posts_count[ $this_post->ID ] : 0; - + // Add to terms $terms[] = $term; - + } - } - } - + break; - + case 'all': default: - - // Build the query - // Get term count and post info + + /* + * Build the query. + * + * Get term count and post info. + */ $cpt_posts_query = "SELECT (SELECT COUNT(*) FROM {$wpdb->postmeta} wpcountmeta INNER JOIN {$wpdb->posts} wpcountmetaposts ON wpcountmetaposts.ID = wpcountmeta.post_id AND wpcountmetaposts.post_status = 'publish' WHERE wpcountmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND wpcountmeta.meta_value = wpposts.ID) AS count, wpposts.* FROM {$wpdb->posts} wpposts INNER JOIN {$wpdb->postmeta} wpmeta ON wpmeta.meta_value = wpposts.ID AND wpmeta.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' AND - wpmeta.post_id IN (" . implode( ',', $object_ids ) . ")"; - - // Exclude certain "terms" - if ( ! empty( $exclude ) ) { - $cpt_posts_query .= " AND wpposts.ID NOT IN ( " . implode( ',', $exclude ) . " )"; - } - - $cpt_posts_query .= " WHERE wpposts.post_type IN ('" . implode( "','", $cpt_taxonomies ) . "') AND wpposts.post_status = 'publish'"; - + wpmeta.post_id IN (" . implode( ',', $object_ids ) . ')'; + + // Exclude certain "terms" + if ( ! empty( $exclude ) ) { + $cpt_posts_query .= ' AND wpposts.ID NOT IN ( ' . implode( ',', $exclude ) . ' )'; + } + + $cpt_posts_query .= " WHERE wpposts.post_type IN ('" . implode( "','", $cpt_taxonomies ) . "') AND wpposts.post_status = 'publish'"; + // Get the posts $cpt_posts = $wpdb->get_results( $cpt_posts_query ); - + if ( ! empty( $cpt_posts ) ) { - + foreach ( $cpt_posts as $this_post ) { - + if ( ! empty( $this_post ) ) { - + // Save count and remove before conversion $term_count = $this_post->count; unset( $this_post->count ); - - // Convert to term - // Don't need count because we're adding it next + + /* + * Convert to term. + * + * Don't need count because we're adding it next. + */ $term = $this->convert_object_to_cpt_onomy_term( $this_post, false ); - + // If no term then continue to next post if ( ! $term ) { continue; } - + // Add count back to the mix $term->count = $term_count; - + // Add to terms $terms[] = $term; - + } - } - } - break; - + break; + } - - /** + + /* * Sort orderby. * If 'ids' or 'names', then we have a simpler sort. */ @@ -1962,7 +1947,7 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { sort( $terms ); } else { - switch( $args['orderby'] ) { + switch ( $args['orderby'] ) { case 'id': usort( $terms, 'cpt_onomies_sort_cpt_onomy_term_by_term_id' ); @@ -1987,21 +1972,20 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { case 'term_order': break; } - } - + // Sort order if ( 'desc' == strtolower( $args['order'] ) ) { $terms = array_reverse( $terms ); } - + if ( ! $terms ) { $terms = array(); } - + return $terms; } - + /** * This function sets the terms for a post. * @@ -2020,25 +2004,25 @@ function get_object_terms( $terms, $object_ids, $taxonomies, $args = array() ) { */ public function wp_set_post_terms( $post_id, $terms, $taxonomy, $append = false ) { global $cpt_onomies_manager; - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); } - + $post_id = (int) $post_id; - + if ( ! $post_id ) { return false; } - + if ( empty( $terms ) ) { $terms = array(); } - + if ( ! is_array( $terms ) ) { $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) { @@ -2046,18 +2030,18 @@ public function wp_set_post_terms( $post_id, $terms, $taxonomy, $append = false } $terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); } - - /** + + /* * Hierarchical taxonomies must always pass IDs rather than names * so that children with the same names but different parents aren't confused. */ if ( is_taxonomy_hierarchical( $taxonomy ) ) { $terms = array_unique( array_map( 'intval', $terms ) ); } - + return $this->wp_set_object_terms( $post_id, $terms, $taxonomy, $append ); } - + /** * This function creates a relationship between an object and a CPT-onomy term. * @@ -2091,19 +2075,19 @@ public function wp_set_post_terms( $post_id, $terms, $taxonomy, $append = false */ public function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { global $wpdb, $cpt_onomies_manager; - - /** + + /* * This function only processes registered CPT-onomies. * If this is a normal taxonomy, then use the WordPress function. */ if ( ! $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { return wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); } - + if ( ! taxonomy_exists( $taxonomy ) ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy', 'cpt-onomies' ) ); } - + /* * current_user_can() doesn't work when running CRON jobs because * wp_get_current_user() doesn't appear to work with CRON and therefore @@ -2113,134 +2097,130 @@ public function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = fa if ( ! defined( 'DOING_CRON' ) && ! current_user_can( $tax->cap->assign_terms ) ) { return new WP_Error( $tax->cap->assign_terms, __( 'You are not allowed to assign terms for this taxonomy.', 'cpt-onomies' ) ); } - + $object_id = (int) $object_id; $object_post_type = get_post_type( $object_id ); - - // Make sure these posts are allowed to have a relationship + + // Make sure these posts are allowed to have a relationship. if ( ! is_object_in_taxonomy( $object_post_type, $taxonomy ) ) { return new WP_Error( 'taxonomy_relationship', __( 'This post type object and taxonomy are not allowed to have a relationship.', 'cpt-onomies' ) ); } - + // Make sure terms is an array if ( ! is_array( $terms ) ) { $terms = str_replace( ' ', ',', str_replace( ', ', ',', $terms ) ); $terms = explode( ',', $terms ); } - - /** + + /* * Allows you to designate that you only want specific term IDs to be assigned. * Can be array, space-separated or comma separated string. */ $include_term_ids = apply_filters( 'custom_post_type_onomies_assigning_cpt_onomy_terms_include_term_ids', array(), $taxonomy, $object_post_type, $object_id ); - + // Make sure $include_term_ids is an array if ( ! is_array( $include_term_ids ) ) { $include_term_ids = str_replace( ' ', ',', str_replace( ', ', ',', $include_term_ids ) ); $include_term_ids = explode( ',', $include_term_ids ); } - - // Make sure the 'include' does not include the current object ID + + // Make sure the 'include' does not include the current object ID. if ( in_array( $object_id, $include_term_ids ) ) { - foreach( $include_term_ids as $term_id_index => $term_id ) { + foreach ( $include_term_ids as $term_id_index => $term_id ) { if ( $object_id == $term_id ) { unset( $include_term_ids[ $term_id_index ] ); } } } - - /** + + /* * Allows you to exclude term IDs from being assigned. * Can be array, space-separated or comma separated string. */ $exclude_term_ids = apply_filters( 'custom_post_type_onomies_assigning_cpt_onomy_terms_exclude_term_ids', array(), $taxonomy, $object_post_type, $object_id ); - - // Make sure $exclude_term_ids is an array + + // Make sure $exclude_term_ids is an array. if ( ! is_array( $exclude_term_ids ) ) { $exclude_term_ids = str_replace( ' ', ',', str_replace( ', ', ',', $exclude_term_ids ) ); $exclude_term_ids = explode( ',', $exclude_term_ids ); } - - // Make sure the 'excludes' includes the current object ID + + // Make sure the 'excludes' includes the current object ID. if ( ! in_array( $object_id, $exclude_term_ids ) ) { $exclude_term_ids[] = $object_id; } - - // We need the term IDs for $append logic at the end + + // We need the term IDs for $append logic at the end. $term_ids = array(); - + foreach ( (array) $terms as $term ) { - + if ( ! strlen( trim( $term ) ) ) { continue; } - + if ( is_numeric( $term ) ) { $term = (int) $term; } - + if ( ! $term_info = $this->term_exists( $term, $taxonomy ) ) { - + // Skip if a non-existent term ID is passed. if ( is_int( $term ) ) { continue; } - } - + if ( is_wp_error( $term_info ) ) { return $term_info; } - + // Only assign included terms if ( $include_term_ids && ! in_array( $term_info->term_id, $include_term_ids ) ) { continue; } - + // Do not assign excluded terms - if( $exclude_term_ids && in_array( $term_info->term_id, $exclude_term_ids ) ) { + if ( $exclude_term_ids && in_array( $term_info->term_id, $exclude_term_ids ) ) { continue; } - + // Keep track of all the term IDs for $append logic at the end $term_ids[] = $term_info->term_id; - - // Make sure the relationship doesn't already exist + + // Make sure the relationship doesn't already exist. if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $object_id, CPT_ONOMIES_POSTMETA_KEY, $term_info->term_id ) ) ) { continue; } - - /** + + /* * Create object/term relationship. * Call action that allows user to run code when relationships are set. */ if ( add_post_meta( $object_id, CPT_ONOMIES_POSTMETA_KEY, $term_info->term_id, false ) ) { do_action( 'cpt_onomy_created_object_term_relationship', $term_info->term_id, $taxonomy, $object_id, $object_post_type ); } - } - + // Delete all pre-existing term relationships if ( ! $append ) { - - /** + + /* * We don't have to retrieve 'all' of the term info here because * we're only dealing with CPT-onomies and not mingling with taxonomies. */ $old_term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'id' ) ); - + $delete_terms = array_diff( $old_term_ids, $term_ids ); if ( $delete_terms ) { - foreach( $delete_terms as $delete_term_id ) { + foreach ( $delete_terms as $delete_term_id ) { $this->wp_delete_object_term_relationship( $object_id, $delete_term_id ); } } - } - return $term_ids; } - + /** * This function deletes a relationship between an object and a CPT-onomy term. * @@ -2263,29 +2243,29 @@ public function wp_delete_object_term_relationship( $object_id, $term_id ) { $object_id = (int) $object_id; $term_id = (int) $term_id; $taxonomy = get_post_type( $term_id ); - + // Make sure this is a CPT-onomy if ( $object_id && $term_id && $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { - + // Make sure the relationship exists if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $object_id, CPT_ONOMIES_POSTMETA_KEY, $term_id ) ) ) { return false; } - - /** + + /* * Delete object/term relationship. * Call action that allows user to run code when relationships are deleted. */ if ( delete_post_meta( $object_id, CPT_ONOMIES_POSTMETA_KEY, $term_id ) ) { + do_action( 'cpt_onomy_deleted_object_term_relationship', $term_id, $taxonomy, $object_id, get_post_type( $object_id ) ); + return true; } - } - return false; } - + /** * This function mimics the WordPress function wp_delete_object_term_relationships() * because we cannot hook into the function without receiving errors. @@ -2301,99 +2281,103 @@ public function wp_delete_object_term_relationship( $object_id, $term_id ) { * @return boolean|WP_Error - true if relationships are deleted, otherwise false * @filters 'cpt_onomy_deleted_object_term_relationship' - $term_id, $taxonomy, $object_id, $object_post_type */ - public function wp_delete_object_term_relationships( $object_id, $taxonomies = NULL ) { + public function wp_delete_object_term_relationships( $object_id, $taxonomies = null ) { global $wpdb, $cpt_onomies_manager; - + $object_id = (int) $object_id; - - // Delete ALL relationships + + // Delete ALL relationships. if ( empty( $taxonomies ) ) { return delete_post_meta( $object_id, CPT_ONOMIES_POSTMETA_KEY ); - } - - else { - + } else { + if ( ! is_array( $taxonomies ) ) { $taxonomies = array( $taxonomies ); } - - // This function only filters registered CPT-onomies + + // This function only filters registered CPT-onomies. $cpt_taxonomies = array(); - foreach( $taxonomies as $taxonomy ) { + foreach ( $taxonomies as $taxonomy ) { if ( $cpt_onomies_manager->is_registered_cpt_onomy( $taxonomy ) ) { $cpt_taxonomies[] = $taxonomy; } } - - // This means there are no CPT-onomies so wrap things up + + // This means there are no CPT-onomies so wrap things up. if ( empty( $cpt_taxonomies ) ) { return wp_delete_object_term_relationships( $object_id, $taxonomies ); } else { $taxonomies = $cpt_taxonomies; } - - // Add "quotes" - foreach( $taxonomies as $index => $taxonomy ) { + + // Add "quotes". + foreach ( $taxonomies as $index => $taxonomy ) { $taxonomies[ $index ] = "'" . $taxonomy . "'"; } $taxonomies = implode( ',', $taxonomies ); - - // Get IDs of terms being deleted to use for 'cpt_onomy_deleted_object_term_relationship' action - if ( $term_ids_being_deleted = $wpdb->get_col( $wpdb->prepare( "SELECT wpmeta.meta_value FROM {$wpdb->postmeta} wpmeta INNER JOIN {$wpdb->posts} wpp ON wpp.ID = wpmeta.meta_value WHERE wpp.post_type IN (" . $taxonomies . ") AND wpmeta.post_id = %d AND wpmeta.meta_key = %s", $object_id, CPT_ONOMIES_POSTMETA_KEY ) ) ) { - - // Delete object relationships with specific taxonomies - if ( $wpdb->query( $wpdb->prepare( "DELETE wpmeta.* FROM {$wpdb->postmeta} wpmeta INNER JOIN {$wpdb->posts} wpp ON wpp.ID = wpmeta.meta_value WHERE wpp.post_type IN (" . $taxonomies . ") AND wpmeta.post_id = %d AND wpmeta.meta_key = %s", $object_id, CPT_ONOMIES_POSTMETA_KEY ) ) ) { - - // Action allows user to run code when relationships are deleted - foreach( $term_ids_being_deleted as $deleted_term_id ) { + + // Get IDs of terms being deleted to use for 'cpt_onomy_deleted_object_term_relationship' action. + if ( $term_ids_being_deleted = $wpdb->get_col( $wpdb->prepare( "SELECT wpmeta.meta_value FROM {$wpdb->postmeta} wpmeta INNER JOIN {$wpdb->posts} wpp ON wpp.ID = wpmeta.meta_value WHERE wpp.post_type IN (" . $taxonomies . ') AND wpmeta.post_id = %d AND wpmeta.meta_key = %s', $object_id, CPT_ONOMIES_POSTMETA_KEY ) ) ) { + + // Delete object relationships with specific taxonomies. + if ( $wpdb->query( $wpdb->prepare( "DELETE wpmeta.* FROM {$wpdb->postmeta} wpmeta INNER JOIN {$wpdb->posts} wpp ON wpp.ID = wpmeta.meta_value WHERE wpp.post_type IN (" . $taxonomies . ') AND wpmeta.post_id = %d AND wpmeta.meta_key = %s', $object_id, CPT_ONOMIES_POSTMETA_KEY ) ) ) { + + // Action allows user to run code when relationships are deleted. + foreach ( $term_ids_being_deleted as $deleted_term_id ) { do_action( 'cpt_onomy_deleted_object_term_relationship', $deleted_term_id, get_post_type( $deleted_term_id ), $object_id, get_post_type( $object_id ) ); - } - + } + return true; - - } - + } } - return false; - } - } - + /** * This function mimics the WordPress function wp_tag_cloud() * because we cannot hook into the function without receiving errors. * * As of 1.1, you can define 'link' as 'cpt_post' if you want the term's * link to take you to the CPT's post page instead of the term archive. - * + * * @since 1.0 * @uses $cpt_onomy * @param array|string $args Optional. Override default arguments. - * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. + * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. */ - public function wp_tag_cloud( $args = NULL ) { + public function wp_tag_cloud( $args = null ) { global $cpt_onomy; $defaults = array( - 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, - 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', - 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true + 'smallest' => 8, + 'largest' => 22, + 'unit' => 'pt', + 'number' => 45, + 'format' => 'flat', + 'separator' => '\n', + 'orderby' => 'name', + 'order' => 'ASC', + 'exclude' => '', + 'include' => '', + 'link' => 'view', + 'taxonomy' => 'post_tag', + 'echo' => true, ); + $args = wp_parse_args( $args, $defaults ); - $tags = get_terms( $args[ 'taxonomy' ], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags - + $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags + if ( empty( $tags ) || is_wp_error( $tags ) ) { return; } - + foreach ( $tags as $key => $tag ) { - if ( 'edit' == $args[ 'link' ] ) { + if ( 'edit' == $args['link'] ) { $link = $cpt_onomy->get_edit_term_link( $tag->term_id, $tag->taxonomy ); - } elseif ( 'cpt_post' == $args[ 'link' ] ) { + } elseif ( 'cpt_post' == $args['link'] ) { $link = get_permalink( $tag->term_id ); } else { $link = $cpt_onomy->get_term_link( intval( $tag->term_id ), $tag->taxonomy ); @@ -2402,23 +2386,23 @@ public function wp_tag_cloud( $args = NULL ) { if ( is_wp_error( $link ) ) { return false; } - + $tags[ $key ]->link = $link; $tags[ $key ]->id = $tag->term_id; } - + $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args - + $return = apply_filters( 'wp_tag_cloud', $return, $args ); - - if ( 'array' == $args[ 'format' ] || empty( $args[ 'echo' ] ) ) { + + if ( 'array' == $args['format'] || empty( $args['echo'] ) ) { return $return; } - + echo $return; - + } - + } /** @@ -2449,4 +2433,4 @@ function cpt_onomies_sort_cpt_onomy_term_by_slug( $a, $b ) { return 0; } return ( strtolower( $a->slug ) < strtolower( $b->slug ) ) ? -1 : 1; -} \ No newline at end of file +} diff --git a/manager.php b/manager.php index b0944bc..4690711 100644 --- a/manager.php +++ b/manager.php @@ -23,13 +23,13 @@ function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { * @since 1.0 */ class CPT_ONOMIES_MANAGER { - + public $user_settings = array( 'network_custom_post_types' => array(), 'custom_post_types' => array(), 'other_custom_post_types' => array(), ); - + /** * Retrieves the user's plugin options and defines $user_settings. * Registers the custom post types and taxonomies. @@ -39,49 +39,47 @@ class CPT_ONOMIES_MANAGER { * @since 1.0 */ public function __construct() { - - /** + + /* * Get network user settings (only if multisite AND plugin is network activated) * Had to take code from is_plugin_active_for_network() because the function is not loaded in time */ if ( is_multisite() && ( $plugins = get_site_option( 'active_sitewide_plugins' ) ) && isset( $plugins[ CPT_ONOMIES_PLUGIN_FILE ] ) ) { - + // Store network custom post types if ( $network_custom_post_types = get_site_option( 'custom_post_type_onomies_custom_post_types' ) ) { $this->user_settings['network_custom_post_types'] = $network_custom_post_types; } - } - - // Get site user settings - $this->user_settings[ 'custom_post_types' ] = ( $custom_post_types = get_option( 'custom_post_type_onomies_custom_post_types' ) ) ? $custom_post_types : array(); - $this->user_settings[ 'other_custom_post_types' ] = ( $other_custom_post_types = get_option( 'custom_post_type_onomies_other_custom_post_types' ) ) ? $other_custom_post_types : array(); - - // Register custom query vars + + // Get site user settings. + $this->user_settings['custom_post_types'] = ( $custom_post_types = get_option( 'custom_post_type_onomies_custom_post_types' ) ) ? $custom_post_types : array(); + $this->user_settings['other_custom_post_types'] = ( $other_custom_post_types = get_option( 'custom_post_type_onomies_other_custom_post_types' ) ) ? $other_custom_post_types : array(); + + // Register custom query vars. add_filter( 'query_vars', array( $this, 'register_custom_query_vars' ) ); - - // Revert the query vars + + // Revert the query vars. add_action( 'parse_request', array( $this, 'revert_query_vars' ), 100 ); - - // Manage user capabilities + + // Manage user capabilities. add_filter( 'user_has_cap', array( $this, 'user_has_term_capabilities' ), 10, 3 ); - - // Tweak the query + + // Tweak the query. add_filter( 'request', array( $this, 'change_query_vars' ) ); add_action( 'pre_get_posts', array( $this, 'add_cpt_onomy_term_queried_object' ), 1 ); add_filter( 'posts_clauses', array( $this, 'posts_clauses' ), 100, 2 ); - - // Clean up the query + + // Clean up the query. add_action( 'pre_get_posts', array( $this, 'clean_get_posts_terms_query' ), 100 ); - - // Register custom post types and taxonomies + + // Register custom post types and taxonomies. add_action( 'init', array( $this, 'register_custom_post_types_and_taxonomies' ), 100 ); - + } - public function CPT_ONOMIES_MANAGER() { $this->__construct(); } - + /** * Adds the custom query variable 'cpt_onomy_archive' to WordPress's * WP_Query class which allows the plugin to create custom rewrites and queries. @@ -96,11 +94,11 @@ public function register_custom_query_vars( $vars ) { array_push( $vars, 'cpt_onomy_archive' ); return $vars; } - + /** * As of version 1.0.3, this function cleans up queries for front and back end tax queries. * - * For front-end CPT-onomy archive pages, it removes 'name' so WordPress does not think this + * For front-end CPT-onomy archive pages, it removes 'name' so WordPress does not think this * is a single post AND it defines which post types to show, i.e. which post types are attached * to the CPT-onomy. * @@ -108,7 +106,7 @@ public function register_custom_query_vars( $vars ) { * It removes 'name' so WordPress does not think we are looking for a post with that 'name'. * * This function is applied to the filter 'request'. - * + * * @since 1.0 * @uses $cpt_onomy, $pagenow, $post_type * @param array $query - the query variables already created by WordPress @@ -117,20 +115,20 @@ public function register_custom_query_vars( $vars ) { public function change_query_vars( $query ) { global $cpt_onomy, $pagenow, $post_type; - if ( isset( $query[ 'cpt_onomy_archive' ] ) && $query[ 'cpt_onomy_archive' ] ) { - - // Make sure CPT-onomy AND term exists, otherwise, why bother + if ( isset( $query['cpt_onomy_archive'] ) && $query['cpt_onomy_archive'] ) { + + // Make sure CPT-onomy AND term exists, otherwise, why bother. $change_query_vars = false; - foreach( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { + foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { if ( isset( $query[ $taxonomy ] ) && ! empty( $query[ $taxonomy ] ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { - - // Make sure the term exists - $cpt_onomy_term_var = explode( "/", $query[ $taxonomy ] ); - - // Get parent + + // Make sure the term exists. + $cpt_onomy_term_var = explode( '/', $query[ $taxonomy ] ); + + // Get parent. $parent_term_id = $parent_term = 0; if ( count( $cpt_onomy_term_var ) > 1 ) { - foreach( $cpt_onomy_term_var as $index => $term_var ) { + foreach ( $cpt_onomy_term_var as $index => $term_var ) { if ( $index > 0 ) { $parent_term = $cpt_onomy->get_term_by( 'slug', $cpt_onomy_term_var[ $index - 1 ], $taxonomy, OBJECT, 'raw', ( isset( $parent_term ) && isset( $parent_term->term_id ) ) ? $parent_term->term_id : 0 ); @@ -138,69 +136,60 @@ public function change_query_vars( $query ) { if ( isset( $parent_term->term_id ) ) { $parent_term_id = $parent_term->term_id; } - - } + } } } - + // If term id, then we need to get the term by id $get_term_by = 'slug'; if ( is_numeric( $cpt_onomy_term_var[ count( $cpt_onomy_term_var ) - 1 ] ) ) { $get_term_by = 'id'; } - + // If the term doesn't exist, we're not going to change the query vars - if ( $cpt_onomy_term = $cpt_onomy->get_term_by( $get_term_by, $cpt_onomy_term_var[ count( $cpt_onomy_term_var ) - 1 ], $taxonomy, NULL, NULL, $parent_term_id ) ) { - + if ( $cpt_onomy_term = $cpt_onomy->get_term_by( $get_term_by, $cpt_onomy_term_var[ count( $cpt_onomy_term_var ) - 1 ], $taxonomy, null, null, $parent_term_id ) ) { + // We're going to want to change the query vars $change_query_vars = true; - + // To avoid confusion with other children of the same name, change term to term id if ( $cpt_onomy_term->parent ) { $query[ $taxonomy ] = $cpt_onomy_term->term_id; } - } else { $change_query_vars = false; break; } - - } + } } - + if ( $change_query_vars ) { - + // The 'name' variable makes WordPress think this is a single post with the assigned 'name' - unset( $query[ 'name' ] ); - + unset( $query['name'] ); + } - - } + } elseif ( is_admin() && 'edit.php' == $pagenow && isset( $post_type ) ) { - // For filtering by CPT-onomy on admin edit posts screen - else if ( is_admin() && 'edit.php' == $pagenow && isset( $post_type ) ) { + foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { + if ( isset( $_REQUEST[ $taxonomy ] ) && ! empty( $_REQUEST[ $taxonomy ] ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { - foreach( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { - if ( isset( $_REQUEST[ $taxonomy ] ) && ! empty( $_REQUEST[ $taxonomy ] ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { - if ( is_numeric( $_REQUEST[ $taxonomy ] ) ) { $cpt_onomy_term = $cpt_onomy->get_term( (int) $_REQUEST[ $taxonomy ], $taxonomy ); } else { $cpt_onomy_term = $cpt_onomy->get_term_by( 'slug', $_REQUEST[ $taxonomy ], $taxonomy ); } - + // The 'name' variable makes WordPress think we are looking for a post with that 'name' if ( ! empty( $cpt_onomy_term ) ) { unset( $query['name'] ); } - } } - - } + } return $query; } - + /** * This function is used to revert any query variables that WordPress * might have changed, if we deem necessary. @@ -214,54 +203,56 @@ public function change_query_vars( $query ) { * query the post types our CPT-onomes are "attached" to. * * This function is applied to the action 'parse_request'. - * + * * @since 1.2 * @param array $query - the query variables already created by WordPress - */ + */ public function revert_query_vars( $query ) { - if ( isset( $query->query_vars[ 'cpt_onomy_archive' ] ) && $query->query_vars[ 'cpt_onomy_archive' ] && ( isset( $query->matched_query ) && ( $matched_query = $query->matched_query ) ) ) { + if ( isset( $query->query_vars['cpt_onomy_archive'] ) && $query->query_vars['cpt_onomy_archive'] && ( isset( $query->matched_query ) && ( $matched_query = $query->matched_query ) ) ) { - /** + /* * We want the post type objects that all queried * CPT-onomies have in common we also want to store * which CPT-onomies are actually being queried. */ $cpt_onomy_objects = $queried_cpt_onomies = array(); $cpt_onomy_index = 0; - foreach( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { + foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { // Only want the CPT-onomies that are being queried if ( array_key_exists( $taxonomy, $query->query_vars ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { $queried_cpt_onomies[ $taxonomy ] = $tax; - // Get array started - if ( $cpt_onomy_index == 0 ) { + /* + * Get array started. + * + * Otherwise, intersect the arrays. + */ + if ( 0 == $cpt_onomy_index ) { $cpt_onomy_objects = array_merge( $cpt_onomy_objects, $tax->object_type ); - } - - // Intersect the arrays - else { + } else { $cpt_onomy_objects = array_intersect( $cpt_onomy_objects, $tax->object_type ); } - + $cpt_onomy_index++; } } if ( $cpt_onomy_index > 0 ) { - // If only one CPT-onomy is being queried, then we want to use its post types + /* + * If only one CPT-onomy is being queried, then we want to use its post types. + * + * Otherwise, we'll use the ones our multiple CPT-onomies have in common. + */ if ( count( $queried_cpt_onomies ) == 1 && isset( $queried_cpt_onomies[0]->object_type ) ) { $custom_post_type = $queried_cpt_onomies[0]->object_type; - } - - // Otherwise, we'll use the ones our multiple CPT-onomies have in common - else { + } else { $custom_post_type = ! empty( $cpt_onomy_objects ) ? $cpt_onomy_objects : null; } // If our custom query/rewrite defines a 'post_type', it overwrites the rest - foreach( explode( '&', $matched_query ) as $parameter ) { + foreach ( explode( '&', $matched_query ) as $parameter ) { $parameter = explode( '=', $parameter ); if ( isset( $parameter[0] ) && strtolower( $parameter[0] ) == 'post_type' && isset( $parameter[1] ) && ( $set_post_type = $parameter[1] ) ) { @@ -273,7 +264,7 @@ public function revert_query_vars( $query ) { } } - /** + /* * Convert to array for testing * want to remove any post types who are not publicy queryable */ @@ -281,7 +272,7 @@ public function revert_query_vars( $query ) { $custom_post_type = array( $custom_post_type ); } - foreach( $custom_post_type as $post_type_index => $post_type ) { + foreach ( $custom_post_type as $post_type_index => $post_type ) { $post_type_exists = post_type_exists( $post_type ); if ( ! $post_type_exists || ( $post_type_exists && get_post_type_object( $post_type )->exclude_from_search ) ) { unset( $custom_post_type[ $post_type_index ] ); @@ -293,24 +284,25 @@ public function revert_query_vars( $query ) { $custom_post_type = array_shift( $custom_post_type ); } - // Re-assign the 'post_type' query variable + /* + * Re-assign the 'post_type' query variable. + * + * Otherwise, there are no post types that + * are searchable and attached so kill the query. + */ if ( isset( $custom_post_type ) && ! empty( $custom_post_type ) ) { $query->query_vars['post_type'] = $custom_post_type; - } - - // There are no post types that are searchable and attached so kill the query - else { + } else { $query->query_vars['cpt_onomies_kill_query'] = true; } - - } + } } } - + /** * This function is used for CPT-onomy archive pages (on the front-end of the site) * in order to trick WordPress into thinking this is a legit taxonomy archive page. - * + * * This function was created because we cannot hook into WordPress get_term_by(), without receiving an error. * get_term_by() is responsible for passing the term's information to the query, which tells * WordPress this is a taxonomy archive page, so this function creates the term information and @@ -320,7 +312,7 @@ public function revert_query_vars( $query ) { * other aspects of the page that use the queried object information, i.e. the page title. * * This function is applied to the action 'pre_get_posts'. - * + * * @since 1.0 * @uses $cpt_onomy * @param array $query - the query variables already created by WordPress @@ -328,44 +320,43 @@ public function revert_query_vars( $query ) { public function add_cpt_onomy_term_queried_object( $query ) { global $cpt_onomy; - // For CPT-onomy archive page on front-end - if ( isset( $query->query[ 'cpt_onomy_archive' ] ) && ! empty( $query->query[ 'cpt_onomy_archive' ] ) ) { + // For CPT-onomy archive page on front-end. + if ( isset( $query->query['cpt_onomy_archive'] ) && ! empty( $query->query['cpt_onomy_archive'] ) ) { // Make sure CPT-onomy AND term exists, otherwise, why bother - foreach( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { + foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $tax ) { if ( isset( $query->query[ $taxonomy ] ) && ! empty( $query->query[ $taxonomy ] ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { - + // Make sure the term exists if ( is_numeric( $query->query[ $taxonomy ] ) ) { $cpt_onomy_term = $cpt_onomy->get_term( $query->query[ $taxonomy ], $taxonomy ); } else { $cpt_onomy_term = $cpt_onomy->get_term_by( 'slug', $query->query[ $taxonomy ], $taxonomy ); } - + if ( ! empty( $cpt_onomy_term ) ) { - + // Make sure WordPress knows this is not a post type archive $query->is_post_type_archive = false; - + // Add queried object and queried object ID $query->queried_object = $cpt_onomy_term; $query->queried_object_id = $cpt_onomy_term->term_id; - + break; - + } - - } - } + } + } } } - + /** * As of version 1.0.3, this function detects tax queries in the front and back end and * adjusts the posts query accordingly. * * This function is invoked by the filter 'posts_clauses'. - * + * * @since 1.0.3 * @uses $wpdb, $cpt_onomy * @param array $clauses - the clauses variables already created by WordPress @@ -374,122 +365,113 @@ public function add_cpt_onomy_term_queried_object( $query ) { */ public function posts_clauses( $clauses, $query ) { global $wpdb, $cpt_onomy; - - // Then kill the query and return the clauses - if ( isset( $query->query[ 'cpt_onomies_kill_query' ] ) && $query->query[ 'cpt_onomies_kill_query' ] ) { - $clauses[ 'where' ] .= " AND 0=1"; + + // Then kill the query and return the clauses. + if ( isset( $query->query['cpt_onomies_kill_query'] ) && $query->query['cpt_onomies_kill_query'] ) { + $clauses['where'] .= ' AND 0=1'; return $clauses; } - - // If ordering by a CPT-onomy + + // If ordering by a CPT-onomy. if ( ( $taxonomies = $query->get( 'orderby' ) ) && ( $post_type = $query->get( 'post_type' ) ) ) { - - /** + + /* * First, validate the CPT-onomy - could be multiple as array. * Make sure everyone is an array. */ if ( ! is_array( $taxonomies ) ) { $taxonomies = explode( ',', $taxonomies ); } - - // Holds valid CPT-onomies + + // Holds valid CPT-onomies. $valid_cpt_onomies = array(); - - // Validate each taxonomy - foreach( $taxonomies as $taxonomy ) { - + + // Validate each taxonomy. + foreach ( $taxonomies as $taxonomy ) { + // If just one post type... if ( ! is_array( $post_type ) ) { - - // Check against post type + + // Check against post type. if ( $this->is_registered_cpt_onomy( $taxonomy, $post_type ) ) { - $valid_cpt_onomies[] = $taxonomy; continue; - } - } else { - - /** + + /* * Check against each post type. * Let it through if it passes at least one test. */ - foreach( $post_type as $pt ) { - - // Check against post type + foreach ( $post_type as $pt ) { + + // Check against post type. if ( $this->is_registered_cpt_onomy( $taxonomy, $pt ) ) { - $valid_cpt_onomies[] = $taxonomy; break; - } - } - } - } - - // If we have valid CPT-onomies, then go for it + + // If we have valid CPT-onomies, then go for it. if ( $valid_cpt_onomies ) { - - // Build our new orderby - $new_orderby = NULL; - - // Loop through each taxonomy - foreach( $valid_cpt_onomies as $tax_index => $taxonomy ) { - - // Join each CPT-onomy's meta - $clauses[ 'join' ] .= " LEFT OUTER JOIN {$wpdb->postmeta} cpt_onomy_order_{$tax_index}_pm ON cpt_onomy_order_{$tax_index}_pm.post_id = {$wpdb->posts}.ID + + // Build our new orderby. + $new_orderby = null; + + // Loop through each taxonomy. + foreach ( $valid_cpt_onomies as $tax_index => $taxonomy ) { + + // Join each CPT-onomy's meta. + $clauses['join'] .= " LEFT OUTER JOIN {$wpdb->postmeta} cpt_onomy_order_{$tax_index}_pm ON cpt_onomy_order_{$tax_index}_pm.post_id = {$wpdb->posts}.ID AND cpt_onomy_order_{$tax_index}_pm.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' LEFT OUTER JOIN {$wpdb->posts} cpt_onomy_order_{$tax_index}_posts ON cpt_onomy_order_{$tax_index}_posts.ID = cpt_onomy_order_{$tax_index}_pm.meta_value AND cpt_onomy_order_{$tax_index}_posts.post_type = '{$taxonomy}'"; - - // Order by each CPT-onomy + + // Order by each CPT-onomy. if ( $new_orderby ) { $new_orderby .= ', '; } - $new_orderby .= "GROUP_CONCAT( cpt_onomy_order_{$tax_index}_posts.post_title ORDER BY cpt_onomy_order_{$tax_index}_posts.post_title ASC )" . ( ( isset( $query->query[ 'order' ] ) && strcasecmp( $query->query[ 'order' ], 'desc' ) == 0 ) ? ' DESC' : ' ASC' ) . ( ! empty( $clauses[ 'orderby' ] ) ? ', ' : ' ' ) . $clauses[ 'orderby' ]; - + $new_orderby .= "GROUP_CONCAT( cpt_onomy_order_{$tax_index}_posts.post_title ORDER BY cpt_onomy_order_{$tax_index}_posts.post_title ASC )" . ( ( isset( $query->query['order'] ) && strcasecmp( $query->query['order'], 'desc' ) == 0 ) ? ' DESC' : ' ASC' ) . ( ! empty( $clauses['orderby'] ) ? ', ' : ' ' ) . $clauses['orderby']; + } - - // If defined, set the orderby + + // If defined, set the orderby. if ( $new_orderby ) { $clauses['orderby'] = $new_orderby; } - - // Group by the post's ID - $clauses[ 'groupby' ] = "{$wpdb->posts}.ID"; - + + // Group by the post's ID. + $clauses['groupby'] = "{$wpdb->posts}.ID"; + } - } - - // If running a tax query + + // If running a tax query. if ( isset( $query->tax_query ) ) { $is_registered_cpt_onomy = false; $taxonomies = array( 'join' => '', 'where' => array() ); $new_where = array(); $c = $t = 1; - - // Get tax queries count for replacing 0 = 1 - do not include 'NOT IN' relationships + + // Get tax queries count for replacing 0 = 1 - do not include 'NOT IN' relationships. $tax_queries_count = 0; - + foreach ( $query->tax_query->queries as $this_query_key => $this_query ) { - - // Get the taxonomy + + // Get the taxonomy. $taxonomy = isset( $this_query['taxonomy'] ) ? $this_query['taxonomy'] : null; - // Make sure the taxonomy exists + // Make sure the taxonomy exists. if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { continue; } - - /** + + /* * @TODO This used to skip for non-CPT-onomies but that caused a bug * * Now we let them through. Does this need to be fixed? @@ -498,333 +480,330 @@ public function posts_clauses( $clauses, $query ) { continue; }*/ $is_registered_cpt_onomy = $this->is_registered_cpt_onomy( $taxonomy ); - - $this_query[ 'terms' ] = array_unique( (array) $this_query[ 'terms' ] ); - - if ( empty( $this_query[ 'terms' ] ) ) { + + $this_query['terms'] = array_unique( (array) $this_query['terms'] ); + + if ( empty( $this_query['terms'] ) ) { continue; } - - // If terms are ID, change field - foreach ( $this_query[ 'terms' ] as $term ) { + + // If terms are ID, change field. + foreach ( $this_query['terms'] as $term ) { if ( is_numeric( $term ) ) { - $this_query[ 'field' ] = 'id'; + $this_query['field'] = 'id'; break; } } - - // CPT-onomies + + /* + * First, CPT-onomies. + * + * Then, normal taxonomies. + */ if ( $is_registered_cpt_onomy ) { - switch ( $this_query[ 'field' ] ) { + switch ( $this_query['field'] ) { case 'slug': - case 'name': - $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $this_query[ 'terms' ] ) ) . "'"; - $terms = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE " . ( ( strtolower( $this_query[ 'field' ] ) == 'slug' ) ? 'post_name' : 'post_title' ) . " IN ($terms) AND post_type = '{$this_query[ 'taxonomy' ]}'" ); - break; + case 'name': + $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $this_query['terms'] ) ) . "'"; + $terms = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE " . ( ( 'slug' == strtolower( $this_query['field'] ) ) ? 'post_name' : 'post_title' ) . " IN ({$terms}) AND post_type = %s", $this_query['taxonomy'] ) ); + break; default: - $terms = array_map( 'intval', $this_query[ 'terms' ] ); + $terms = array_map( 'intval', $this_query['terms'] ); + break; } - } - - // Taxonomies - else { + } else { - switch ( $this_query[ 'field' ] ) { + switch ( $this_query['field'] ) { case 'slug': case 'name': - $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $this_query[ 'terms' ] ) ) . "'"; - $terms = $wpdb->get_col( " - SELECT $wpdb->term_taxonomy.term_taxonomy_id - FROM $wpdb->term_taxonomy - INNER JOIN $wpdb->terms USING (term_id) - WHERE taxonomy = '{$taxonomy}' - AND $wpdb->terms.{$this_query[ 'field' ]} IN ($terms) - " ); + $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $this_query['terms'] ) ) . "'"; + $terms = $wpdb->get_col( $wpdb->prepare( "SELECT term_tax.term_taxonomy_id FROM {$wpdb->term_taxonomy} term_tax INNER JOIN {$wpdb->terms} terms USING (term_id) WHERE term_tax.taxonomy = %s AND terms.{$this_query['field']} IN ({$terms})", $taxonomy ) ); break; default: - $terms = implode( ',', array_map( 'intval', $this_query[ 'terms' ] ) ); - $terms = $wpdb->get_col( " - SELECT term_taxonomy_id - FROM $wpdb->term_taxonomy - WHERE taxonomy = '{$taxonomy}' - AND term_id IN ($terms) - " ); + $terms = implode( ',', array_map( 'intval', $this_query['terms'] ) ); + $terms = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE taxonomy = %s AND term_id IN ({$terms})", $taxonomy ) ); } - } - - if ( 'AND' == $this_query[ 'operator' ] && count( $terms ) < count( $this_query[ 'terms' ] ) ) { + + if ( 'AND' == $this_query['operator'] && count( $terms ) < count( $this_query['terms'] ) ) { return; } - - $this_query[ 'terms' ] = $terms; - - if ( is_taxonomy_hierarchical( $taxonomy ) && $this_query[ 'include_children' ] ) { - + + $this_query['terms'] = $terms; + + if ( is_taxonomy_hierarchical( $taxonomy ) && $this_query['include_children'] ) { + $children = array(); - foreach ( $this_query[ 'terms' ] as $term ) { - - // For hierarchical CPT-onomies + foreach ( $this_query['terms'] as $term ) { + + /* + * First, hierarchical CPT-onomies. + * + * Then, normal hierarchical taxonomies. + */ if ( $is_registered_cpt_onomy ) { $children = array_merge( $children, $cpt_onomy->get_term_children( $term, $taxonomy ) ); - } - - // For taxonomies - else { + } else { $children = array_merge( $children, get_term_children( $term, $this_query['taxonomy'] ) ); } - + $children[] = $term; + } - $this_query[ 'terms' ] = $children; - + + $this_query['terms'] = $children; + } - + extract( $this_query ); - + $primary_table = $wpdb->posts; $primary_id_column = 'ID'; - + sort( $terms ); - + if ( 'IN' == $operator ) { - + if ( empty( $terms ) ) { continue; } - + $terms = implode( ',', $terms ); - - // CPT-onomies + + /* + * First, CPT-onomies. + * + * Then, normal taxonomies. + */ if ( $is_registered_cpt_onomy ) { - + $alias = $c ? 'cpt_onomy_pm' . $c : $wpdb->postmeta; - - $clauses[ 'join' ] .= " INNER JOIN $wpdb->postmeta"; - $clauses[ 'join' ] .= $c ? " AS $alias" : ''; - $clauses[ 'join' ] .= " ON ($wpdb->posts.ID = $alias.post_id AND $alias.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "')"; - - $new_where[] = "$alias.meta_value $operator ($terms)"; - + + $clauses['join'] .= " INNER JOIN $wpdb->postmeta"; + $clauses['join'] .= $c ? " AS $alias" : ''; + $clauses['join'] .= " ON ($wpdb->posts.ID = $alias.post_id AND $alias.meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "')"; + + $new_where[] = "{$alias}.meta_value {$operator} ({$terms})"; + $c++; - - } - // Taxonomies - else { - + } else { + $alias = $t ? 'cpt_onomy_tt' . $t : $wpdb->term_relationships; - $taxonomies[ 'join' ] .= " INNER JOIN $wpdb->term_relationships"; - $taxonomies[ 'join' ] .= $t ? " AS $alias" : ''; - $taxonomies[ 'join' ] .= " ON ($primary_table.$primary_id_column = $alias.object_id)"; - - $new_where[] = $taxonomies[ 'where' ][] = "$alias.term_taxonomy_id $operator ($terms)"; - + $taxonomies['join'] .= " INNER JOIN $wpdb->term_relationships"; + $taxonomies['join'] .= $t ? " AS $alias" : ''; + $taxonomies['join'] .= " ON ($primary_table.$primary_id_column = $alias.object_id)"; + + $new_where[] = $taxonomies['where'][] = "{$alias}.term_taxonomy_id {$operator} ({$terms})"; + $t++; - + } - - // Add to tax queries count for replacing 0 = 1 - do not include 'NOT IN' relationships + + // Add to tax queries count for replacing 0 = 1 - do not include 'NOT IN' relationships. $tax_queries_count++; - + } elseif ( 'NOT IN' == $operator ) { - + if ( empty( $terms ) ) { continue; } - + $terms = implode( ',', $terms ); - - // CPT-onomies + + /* + * First, CPT-onomies. + * + * Then, normal taxonomies. + */ if ( $is_registered_cpt_onomy ) { - - $new_where[] = "$wpdb->posts.ID NOT IN ( + + $new_where[] = "{$wpdb->posts}.ID NOT IN ( SELECT post_id - FROM $wpdb->postmeta + FROM {$wpdb->postmeta} WHERE meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' - AND meta_value IN ($terms) + AND meta_value IN ({$terms}) )"; - - } - // Taxonomies - else { - - $new_where[] = $taxonomies[ 'where' ][] = "$primary_table.$primary_id_column NOT IN ( + } else { + + $new_where[] = $taxonomies['where'][] = "{$primary_table}.{$primary_id_column} NOT IN ( SELECT object_id - FROM $wpdb->term_relationships - WHERE term_taxonomy_id IN ($terms) + FROM {$wpdb->term_relationships} + WHERE term_taxonomy_id IN ({$terms}) )"; - + } - } elseif ( 'AND' == $operator ) { - + if ( empty( $terms ) ) { continue; } - + $num_terms = count( $terms ); - + $terms = implode( ',', $terms ); - - // CPT-onomies + + /* + * First, CPT-onomies. + * + * Then, normal taxonomies. + */ if ( $is_registered_cpt_onomy ) { - + $new_where[] = "( SELECT COUNT(1) - FROM $wpdb->postmeta + FROM {$wpdb->postmeta} WHERE meta_key = '" . CPT_ONOMIES_POSTMETA_KEY . "' - AND meta_value IN ($terms) - AND post_id = $wpdb->posts.ID + AND meta_value IN ({$terms}) + AND post_id = {$wpdb->posts}.ID ) = $num_terms"; - - } - // Taxonomies - else { - - $new_where[] = $taxonomies[ 'where' ][] = "( + } else { + + $new_where[] = $taxonomies['where'][] = "( SELECT COUNT(1) - FROM $wpdb->term_relationships - WHERE term_taxonomy_id IN ($terms) - AND object_id = $primary_table.$primary_id_column - ) = $num_terms"; - + FROM {$wpdb->term_relationships} + WHERE term_taxonomy_id IN ({$terms}) + AND object_id = {$primary_table}.{$primary_id_column} + ) = {$num_terms}"; + } - + // Add to tax queries count for replacing 0 = 1 - do not include 'NOT IN' relationships $tax_queries_count++; - + } - } - + // Only add taxonomies 'join' if it doesn't already exist - if ( $clauses[ 'join' ] && $taxonomies[ 'join' ] && strpos( $clauses[ 'join' ], $taxonomies[ 'join' ] ) === false ) { + if ( $clauses['join'] && $taxonomies['join'] && strpos( $clauses['join'], $taxonomies['join'] ) === false ) { $clauses['join'] .= $taxonomies['join']; } - - // Remove old taxonomies 'where' so we can add new 'where' - if ( $taxonomies[ 'where' ] ) { - - $tax_where = " AND ( "; - foreach ( $taxonomies[ 'where' ] as $where_index => $add_where ) { - if ( $where_index > 0 ) - $tax_where .= " " . $query->tax_query->relation . " "; - $tax_where .= $add_where; + + // Remove old taxonomies 'where' so we can add new 'where'. + if ( $taxonomies['where'] ) { + + $tax_where = ' AND ( '; + + foreach ( $taxonomies['where'] as $where_index => $add_where ) { + if ( $where_index > 0 ) { + $tax_where .= ' ' . $query->tax_query->relation . ' '; } - $tax_where .= " )"; - - $clauses[ 'where' ] = str_replace( $tax_where, '', $clauses[ 'where' ] ); - + $tax_where .= $add_where; + } + + $tax_where .= ' )'; + + $clauses['where'] = str_replace( $tax_where, '', $clauses['where'] ); + } - - if ( ! empty( $new_where ) ) { - + + if ( ! empty( $new_where ) ) { + // Remove the post_name (WP adds this if the post type is hierarhical. I'm not sure why) - $clauses[ 'where' ] = preg_replace( '/wp\_posts\.post\_name\s=\s\'([^\']*)\'\sAND\s/i', '', $clauses[ 'where' ] ); - - /** + $clauses['where'] = preg_replace( '/wp\_posts\.post\_name\s=\s\'([^\']*)\'\sAND\s/i', '', $clauses['where'] ); + + /* * Remove 0 = 1. * Build the replace string. */ - $preg_replace_str = NULL; - - // We have to set it up for each tax query + $preg_replace_str = null; + + // We have to set it up for each tax query. for ( $p = 0; $p < $tax_queries_count; $p++ ) { - - // Add relation separator + + // Add relation separator. if ( $p > 0 ) { $preg_replace_str .= '[\s]+' . $query->tax_query->relation; } - + $preg_replace_str .= '[\s]+0[\s]+\=[\s]+1'; - + } - - // Wrap them all in an AND + + // Wrap them all in an AND. $preg_replace_str = 'AND[\s]+\(' . $preg_replace_str . '[\s]+\)'; - - // Replace the 0 = 1 in the 'where' clause - $clauses[ 'where' ] = preg_replace( '/' . $preg_replace_str . '/i', '', $clauses[ 'where' ] ); - - // Find singular 0 = 1 to replace - $clauses[ 'where' ] = preg_replace( '/AND[\s]+0[\s]+\=[\s]+1/i', '', $clauses[ 'where' ] ); - - // Make sure it removes the AND at the end as well - $clauses[ 'where' ] = preg_replace( '/0[\s]+\=[\s]+1[\s]+AND/i', '', $clauses[ 'where' ] ); - - $clauses[ 'where' ] .= " AND ( "; - foreach ( $new_where as $where_index => $add_where ) { - if ( $where_index > 0 ) - $clauses[ 'where' ] .= " " . $query->tax_query->relation . " "; - $clauses[ 'where' ] .= $add_where; + + // Replace the 0 = 1 in the 'where' clause. + $clauses['where'] = preg_replace( '/' . $preg_replace_str . '/i', '', $clauses['where'] ); + + // Find singular 0 = 1 to replace. + $clauses['where'] = preg_replace( '/AND[\s]+0[\s]+\=[\s]+1/i', '', $clauses['where'] ); + + // Make sure it removes the AND at the end as well. + $clauses['where'] = preg_replace( '/0[\s]+\=[\s]+1[\s]+AND/i', '', $clauses['where'] ); + + $clauses['where'] .= ' AND ( '; + + foreach ( $new_where as $where_index => $add_where ) { + if ( $where_index > 0 ) { + $clauses['where'] .= ' ' . $query->tax_query->relation . ' '; } - $clauses[ 'where' ] .= " )"; - + $clauses['where'] .= $add_where; + } + + $clauses['where'] .= ' )'; + } - } - + return $clauses; - } - + /** * Because retrieving CPT-onomy terms involves get_posts(), we have to set some * measures in place to remove any filters or queries that might affect retrieving * the CPT-onomy terms. * - * It detects the query variable 'get_cpt_onomy_terms' before editing the query. + * It detects the query variable 'get_cpt_onomy_terms' before editing the query. * * This function is applied to the action 'pre_get_posts'. - * + * * @since 1.0.3 * @param array $query - the query variables already created by WordPress */ public function clean_get_posts_terms_query( $query ) { - if ( isset( $query->query_vars[ 'get_cpt_onomy_terms' ] ) ) { - - // Remove all tax queries - $query->set( 'taxonomy', NULL ); - $query->set( 'term', NULL ); + if ( isset( $query->query_vars['get_cpt_onomy_terms'] ) ) { + + // Remove all tax queries. + $query->set( 'taxonomy', null ); + $query->set( 'term', null ); if ( isset( $query->tax_query ) ) { $query->tax_query = null; } - if ( isset( $query->query[ 'taxonomy' ] ) ) { + if ( isset( $query->query['taxonomy'] ) ) { $query->query_vars['taxonomy'] = null; } - if ( isset( $query->query[ 'term' ] ) ) { + if ( isset( $query->query['term'] ) ) { $query->query['term'] = null; } - - // Remove all meta queries - $query->set( 'meta_key', NULL ); - $query->set( 'meta_value', NULL ); + + // Remove all meta queries. + $query->set( 'meta_key', null ); + $query->set( 'meta_value', null ); if ( isset( $query->meta_query ) ) { $query->meta_query = null; } - if ( isset( $query->query[ 'meta_key' ] ) ) { + if ( isset( $query->query['meta_key'] ) ) { $query->query_vars['meta_key'] = null; } - if ( isset( $query->query[ 'meta_value' ] ) ) { + if ( isset( $query->query['meta_value'] ) ) { $query->query['meta_value'] = null; } - } } - + /** * This function hooks into WordPress current_user_can() whenever WordPress - * is checking that the user can 'assign_cpt_onomy_$taxonomy_terms', 'manage_cpt_onomy_$taxonomy_terms', + * is checking that the user can 'assign_cpt_onomy_$taxonomy_terms', 'manage_cpt_onomy_$taxonomy_terms', * 'edit_cpt_onomy_$taxonomy_terms' or 'delete_cpt_onomy_$taxonomy_terms'. * * If assign, it checks user settings to see if user role has permission to assign. @@ -839,83 +818,79 @@ public function clean_get_posts_terms_query( $query ) { * @return array - the filtered $allcaps */ public function user_has_term_capabilities( $allcaps, $caps, $args ) { - + // No one can manage, edit, or delete CPT-onomy terms - foreach( $caps as $this_cap ) { - - // If user has capability manually assigned, then allow - // Otherwise, check user settings + foreach ( $caps as $this_cap ) { + + /* + * If user has capability manually assigned, then allow. + * + * Otherwise, check user settings. + * NO ONE is allowed to manage, edit or delete. + */ if ( preg_match( '/assign\_cpt\_onomy\_([a-z\_]+)\_terms/i', $this_cap ) && ! isset( $allcaps[ $this_cap ] ) ) { - + // Get taxonomy $taxonomy = preg_replace( '/assign\_cpt\_onomy\_([a-z\_]+)\_terms/i', '\1', $this_cap ); - - // If registered CPT-onomy + + // If registered CPT-onomy. if ( taxonomy_exists( $taxonomy ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { - + // Get taxonomy info $tax = get_taxonomy( $taxonomy ); - + // Default $allow = false; - - // No capabilities are assigned so everyone has permission + + /* + * No capabilities are assigned so everyone has permission. + * + * Otherwise, the capability is restricted to specific roles. + */ if ( ! isset( $tax->restrict_user_capabilities ) || empty( $tax->restrict_user_capabilities ) ) { - $allow = true; - - } + } else { - // The capability is restricted to specific roles - else { - - // Get user roles to see if user has capability to assign taxonomy - // $args contains the user id + /* + * Get user roles to see if user has capability to assign taxonomy. + * $args contains the user id. + */ $user = new WP_User( $args[1] ); foreach ( $user->roles as $role ) { - - // Test to see if role is selected + + // Test to see if role is selected. if ( in_array( $role, $tax->restrict_user_capabilities ) ) { $allow = true; break; } - } - } - + // Assign the required capability if ( $allow ) { $allcaps[ $this_cap ] = 1; } else { unset( $allcaps[ $this_cap ] ); } - } - - } + } elseif ( preg_match( '/(manage|edit|delete)\_cpt\_onomy\_([a-z\_]+)\_terms/i', $this_cap ) ) { - // NO ONE is allowed to manage, edit or delete - else if ( preg_match( '/(manage|edit|delete)\_cpt\_onomy\_([a-z\_]+)\_terms/i', $this_cap ) ) { - // Get taxonomy $taxonomy = preg_replace( '/(manage|edit|delete)\_cpt\_onomy\_([a-z\_]+)\_terms/i', '\2', $this_cap ); - + // If registered CPT-onomy if ( taxonomy_exists( $taxonomy ) && $this->is_registered_cpt_onomy( $taxonomy ) ) { unset( $allcaps[ $this_cap ] ); } - } - } return $allcaps; } - + /** * Detects if a custom post type is overwriting a * network-registered post type registered by this plugin. - * + * * @since 1.3 * @uses $blog_id * @param string $cpt_key - the key, or alias, for the custom post type you are checking @@ -923,24 +898,22 @@ public function user_has_term_capabilities( $allcaps, $caps, $args ) { */ public function overwrote_network_cpt( $cpt_key ) { global $blog_id; - if ( isset( $this->user_settings[ 'network_custom_post_types' ] ) ) { - - $network_cpts = $this->user_settings[ 'network_custom_post_types' ]; - + if ( isset( $this->user_settings['network_custom_post_types'] ) ) { + + $network_cpts = $this->user_settings['network_custom_post_types']; + if ( isset( $network_cpts[ $cpt_key ] ) - && ( ( ! isset( $network_cpts[ $cpt_key ][ 'site_registration' ] ) || ( isset( $network_cpts[ $cpt_key ][ 'site_registration' ] ) && empty( $network_cpts[ $cpt_key ][ 'site_registration' ] ) ) ) - || ( isset( $network_cpts[ $cpt_key ][ 'site_registration' ] ) && in_array( $blog_id, $network_cpts[ $cpt_key ][ 'site_registration' ] ) ) ) ) { - + && ( ( ! isset( $network_cpts[ $cpt_key ]['site_registration'] ) || ( isset( $network_cpts[ $cpt_key ]['site_registration'] ) && empty( $network_cpts[ $cpt_key ]['site_registration'] ) ) ) + || ( isset( $network_cpts[ $cpt_key ]['site_registration'] ) && in_array( $blog_id, $network_cpts[ $cpt_key ]['site_registration'] ) ) ) ) { + if ( $this->is_registered_cpt( $cpt_key ) && ! $this->is_registered_network_cpt( $cpt_key ) ) { return true; } - } - } return false; } - + /** * This functions checks to see if a custom post type is a network-registered * custom post type registered by this plugin. When this plugin registers @@ -959,7 +932,7 @@ public function is_registered_network_cpt( $cpt_key ) { } return false; } - + /** * This functions checks to see if a custom post type is a custom post type * registered by this plugin. When this plugin registers a custom post type, @@ -976,7 +949,7 @@ public function is_registered_cpt( $cpt_key ) { } return false; } - + /** * This functions checks to see if a taxonomy is a CPT-onomy * registered by this plugin. When this plugin registers a CPT-onomy, @@ -984,36 +957,35 @@ public function is_registered_cpt( $cpt_key ) { * * As of version 1.3.2, the function also allows you to test * if the CPT-onomy is registered to a specific post type. - * + * * @since 1.0 * @param string $tax - the key, or alias, for the taxonomy you are checking * @param string $post_type - if set, checks to see is CPT-onomy AND is registered to set post type * @return boolean - whether this taxonomy is a CPT-onomy registered by this plugin (and, if post type set, registered to a specific post type) */ - public function is_registered_cpt_onomy( $taxonomy, $post_type = NULL ) { + public function is_registered_cpt_onomy( $taxonomy, $post_type = null ) { if ( taxonomy_exists( $taxonomy ) ) { // Get the taxonomy object $tax = get_taxonomy( $taxonomy ); - - /** + + /* * If post type is set, then checks to see if it's a * CPT-onomy AND is registered to a specific post type. * Otherwise, simply checks if it's a CPT-onomy. */ if ( ( empty( $post_type ) || ( ! empty( $post_type ) && post_type_exists( $post_type ) && in_array( $taxonomy, get_object_taxonomies( $post_type, 'names' ) ) ) ) - && isset( $tax->cpt_onomy ) && $tax->cpt_onomy == true ) { + && isset( $tax->cpt_onomy ) && true == $tax->cpt_onomy ) { return true; } - } return false; } - + /** * * Registers the user's custom post type as a CPT-onomy. - * The custom post type must already be registered in order + * The custom post type must already be registered in order * to register the CPT-onomy. * * Because custom post types and taxonomies with the same name share @@ -1022,7 +994,7 @@ public function is_registered_cpt_onomy( $taxonomy, $post_type = NULL ) { * Instead, we add our own rewrite rule to display the CPT-onomy archive page. * * As of 1.1, users can define their own CPT-onomy archive page slug. - * + * * @since 1.1 * @author Rachel Carden (@bamadesigner) * @author Travis Smith (@wp_smith) - Thanks for your help Travis!! @@ -1047,8 +1019,8 @@ public function is_registered_cpt_onomy( $taxonomy, $post_type = NULL ) { * @return null - Returns early if taxonomy already exists or if post type does not exist */ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { - - /** + + /* * If taxonomy already exists (and is not a CPT-onomy) * OR matching post type doesn't exist, this allows you * to overwrite your CPT-onomy registered by the plugin, if desired. @@ -1056,15 +1028,15 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { if ( ( taxonomy_exists( $taxonomy ) && ! $this->is_registered_cpt_onomy( $taxonomy ) ) || ! post_type_exists( $taxonomy ) ) { return; } - + // Make sure $object_type is an array if ( ! is_array( $object_type ) ) { $object_type = array_unique( array( $object_type ) ); } - + // Check to make sure the object types exist if ( ! empty( $object_type ) ) { - foreach( $object_type as $object_type_index => $type ) { + foreach ( $object_type as $object_type_index => $type ) { if ( ! post_type_exists( $type ) ) { unset( $object_type[ $object_type_index ] ); } @@ -1075,16 +1047,16 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { if ( empty( $object_type ) ) { return; } - + // Get the matching custom post type info $custom_post_type = get_post_type_object( $taxonomy ); - + // Define the CPT-onomy label $cpt_onomy_label = strip_tags( $custom_post_type->label ); - + // What is the singular name? $cpt_onomy_singular_name = isset( $custom_post_type->labels ) && isset( $custom_post_type->labels->singular_name ) ? $custom_post_type->labels->singular_name : $cpt_onomy_label; - + // Define the CPT-onomy labels $cpt_onomy_labels = array( 'name' => $cpt_onomy_label, @@ -1104,28 +1076,28 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'cpt-onomies' ), strtolower( $cpt_onomy_label ) ), 'not_found' => sprintf( __( 'No %s found.', 'cpt-onomies' ), strtolower( $cpt_onomy_label ) ), ); - + // Filter the labels $cpt_onomy_labels = apply_filters( 'custom_post_type_onomies_cpt_onomy_labels', $cpt_onomy_labels, $taxonomy, $custom_post_type ); - + // Define the CPT-onomy defaults $cpt_onomy_defaults = array( - 'label' => $cpt_onomy_label, - 'labels' => $cpt_onomy_labels, - 'public' => $custom_post_type->public, - 'meta_box_format' => NULL, - 'meta_box_title' => NULL, - 'show_admin_column' => true, - 'admin_column_title' => NULL, - 'has_cpt_onomy_archive' => true, - 'cpt_onomy_archive_slug' => '$post_type/tax/$term_slug', - 'restrict_user_capabilities'=> array( 'administrator', 'editor', 'author' ) + 'label' => $cpt_onomy_label, + 'labels' => $cpt_onomy_labels, + 'public' => $custom_post_type->public, + 'meta_box_format' => null, + 'meta_box_title' => null, + 'show_admin_column' => true, + 'admin_column_title' => null, + 'has_cpt_onomy_archive' => true, + 'cpt_onomy_archive_slug' => '$post_type/tax/$term_slug', + 'restrict_user_capabilities' => array( 'administrator', 'editor', 'author' ), ); - + // Merge defaults with incoming $args then extract extract( wp_parse_args( $args, $cpt_onomy_defaults ) ); - - /** + + /* * Clean up the arguments for registering * Some CPT-onomy arguments MUST have a set value, * no room for customization right now we have to @@ -1136,30 +1108,30 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { * for the CPT-onomy archive page. */ $cpt_onomy_args = array( - 'cpt_onomy' => true, - 'created_by_cpt_onomies' => isset( $created_by_cpt_onomies ) ? $created_by_cpt_onomies : false, - 'label' => $label, - 'labels' => $labels, - 'public' => $public, - 'hierarchical' => $custom_post_type->hierarchical, - 'show_in_nav_menus' => false, - 'show_ui' => false, - 'show_tagcloud' => false, - 'show_admin_column' => $show_admin_column, - 'admin_column_title' => $admin_column_title, - 'rewrite' => false, - 'meta_box_format' => $meta_box_format, - 'meta_box_title' => $meta_box_title, - 'restrict_user_capabilities'=> $restrict_user_capabilities, - 'capabilities' => array( + 'cpt_onomy' => true, + 'created_by_cpt_onomies' => isset( $created_by_cpt_onomies ) ? $created_by_cpt_onomies : false, + 'label' => $label, + 'labels' => $labels, + 'public' => $public, + 'hierarchical' => $custom_post_type->hierarchical, + 'show_in_nav_menus' => false, + 'show_ui' => false, + 'show_tagcloud' => false, + 'show_admin_column' => $show_admin_column, + 'admin_column_title' => $admin_column_title, + 'rewrite' => false, + 'meta_box_format' => $meta_box_format, + 'meta_box_title' => $meta_box_title, + 'restrict_user_capabilities' => $restrict_user_capabilities, + 'capabilities' => array( 'manage_terms' => 'manage_cpt_onomy_' . $taxonomy . '_terms', 'edit_terms' => 'edit_cpt_onomy_' . $taxonomy . '_terms', 'delete_terms' => 'delete_cpt_onomy_' . $taxonomy . '_terms', 'assign_terms' => 'assign_cpt_onomy_' . $taxonomy . '_terms', - ) + ), ); - - /** + + /* * Add rewrite rule (default is true) to display CPT-onomy * archive page - default is '{post type}/tax/{term slug}' * we must add our own rewrite rule instead of defining the @@ -1168,43 +1140,43 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { * post types must win the rewrite war. */ if ( ! ( isset( $has_cpt_onomy_archive ) && ! $has_cpt_onomy_archive ) ) { - + // Make sure we have a slug if ( ! isset( $cpt_onomy_archive_slug ) || empty( $cpt_onomy_archive_slug ) ) { $cpt_onomy_archive_slug = $cpt_onomy_defaults['cpt_onomy_archive_slug']; } - - /** + + /* * Add the slug to the CPT-onomy arguments so it will be * added to $wp_taxonomies throughout website, if this * parameter is set, then "show CPT-onomy archive page" is also set. */ - $cpt_onomy_args[ 'cpt_onomy_archive_slug' ] = $cpt_onomy_archive_slug; - + $cpt_onomy_args['cpt_onomy_archive_slug'] = $cpt_onomy_archive_slug; + // Replace the variables ($post_type and $term) $cpt_onomy_archive_slug = str_replace( array( '$post_type', '$term_slug', '$term_id' ), array( $taxonomy, '([^/]+)', '([^/]+)' ), $cpt_onomy_archive_slug ); - + // Get rid of any slashes at the beginning AND end $cpt_onomy_archive_slug = preg_replace( '/^([\/]+)/', '', $cpt_onomy_archive_slug ); $cpt_onomy_archive_slug = preg_replace( '/([\/]+)$/', '', $cpt_onomy_archive_slug ); - + // Add feeds rewrite - add_rewrite_rule( $cpt_onomy_archive_slug . '/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$taxonomy . '=$matches[1]&feed=$matches[2]&cpt_onomy_archive=1', 'top' ); - add_rewrite_rule( $cpt_onomy_archive_slug . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?'.$taxonomy . '=$matches[1]&feed=$matches[2]&cpt_onomy_archive=1', 'top' ); - + add_rewrite_rule( $cpt_onomy_archive_slug . '/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $taxonomy . '=$matches[1]&feed=$matches[2]&cpt_onomy_archive=1', 'top' ); + add_rewrite_rule( $cpt_onomy_archive_slug . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?' . $taxonomy . '=$matches[1]&feed=$matches[2]&cpt_onomy_archive=1', 'top' ); + // Adding pagination rewrite - add_rewrite_rule( $cpt_onomy_archive_slug . '/page/?([0-9]{1,})/?$', 'index.php?'.$taxonomy . '=$matches[1]&paged=$matches[2]&cpt_onomy_archive=1', 'top' ); - + add_rewrite_rule( $cpt_onomy_archive_slug . '/page/?([0-9]{1,})/?$', 'index.php?' . $taxonomy . '=$matches[1]&paged=$matches[2]&cpt_onomy_archive=1', 'top' ); + // Add base URL rewrite - add_rewrite_rule( $cpt_onomy_archive_slug . '/?$', 'index.php?'.$taxonomy . '=$matches[1]&cpt_onomy_archive=1', 'top' ); - + add_rewrite_rule( $cpt_onomy_archive_slug . '/?$', 'index.php?' . $taxonomy . '=$matches[1]&cpt_onomy_archive=1', 'top' ); + } - + // Go for launch! register_taxonomy( $taxonomy, $object_type, $cpt_onomy_args ); - + } - + /** * This function takes your custom post type arguments from the settings * and prepares them for registration. @@ -1216,77 +1188,77 @@ public function register_cpt_onomy( $taxonomy, $object_type, $args = array() ) { * @return array of custom post type arguments, ready for registration */ public function create_custom_post_type_arguments_for_registration( $cpt_key, $cpt = array(), $args = array() ) { - + // Create main label. If no label, set to 'Posts'. - $args[ 'label' ] = isset( $cpt[ 'label' ] ) ? strip_tags( $cpt[ 'label' ] ) : 'Posts'; - + $args['label'] = isset( $cpt['label'] ) ? strip_tags( $cpt['label'] ) : 'Posts'; + // Create all labels - $labels = array( 'name' => $args[ 'label' ] ); + $labels = array( 'name' => $args['label'] ); - if ( isset( $cpt[ 'singular_name' ] ) && ! empty( $cpt[ 'singular_name' ] ) ) { + if ( isset( $cpt['singular_name'] ) && ! empty( $cpt['singular_name'] ) ) { $labels['singular_name'] = strip_tags( $cpt['singular_name'] ); } - if ( isset( $cpt[ 'add_new' ] ) && ! empty( $cpt[ 'add_new' ] ) ) { + if ( isset( $cpt['add_new'] ) && ! empty( $cpt['add_new'] ) ) { $labels['add_new'] = ( $cpt['add_new'] ); } - if ( isset( $cpt[ 'add_new_item' ] ) && ! empty( $cpt[ 'add_new_item' ] ) ) { + if ( isset( $cpt['add_new_item'] ) && ! empty( $cpt['add_new_item'] ) ) { $labels['add_new_item'] = strip_tags( $cpt['add_new_item'] ); } - if ( isset( $cpt[ 'edit_item' ] ) && ! empty( $cpt[ 'edit_item' ] ) ) { + if ( isset( $cpt['edit_item'] ) && ! empty( $cpt['edit_item'] ) ) { $labels['edit_item'] = strip_tags( $cpt['edit_item'] ); } - if ( isset( $cpt[ 'new_item' ] ) && ! empty( $cpt[ 'new_item' ] ) ) { + if ( isset( $cpt['new_item'] ) && ! empty( $cpt['new_item'] ) ) { $labels['new_item'] = strip_tags( $cpt['new_item'] ); } - if ( isset( $cpt[ 'all_items' ] ) && ! empty( $cpt[ 'all_items' ] ) ) { + if ( isset( $cpt['all_items'] ) && ! empty( $cpt['all_items'] ) ) { $labels['all_items'] = strip_tags( $cpt['all_items'] ); } - if ( isset( $cpt[ 'view_item' ] ) && ! empty( $cpt[ 'view_item' ] ) ) { + if ( isset( $cpt['view_item'] ) && ! empty( $cpt['view_item'] ) ) { $labels['view_item'] = strip_tags( $cpt['view_item'] ); } - if ( isset( $cpt[ 'search_items' ] ) && ! empty( $cpt[ 'search_items' ] ) ) { + if ( isset( $cpt['search_items'] ) && ! empty( $cpt['search_items'] ) ) { $labels['search_items'] = strip_tags( $cpt['search_items'] ); } - if ( isset( $cpt[ 'not_found' ] ) && ! empty( $cpt[ 'not_found' ] ) ) { + if ( isset( $cpt['not_found'] ) && ! empty( $cpt['not_found'] ) ) { $labels['not_found'] = strip_tags( $cpt['not_found'] ); } - if ( isset( $cpt[ 'not_found_in_trash' ] ) && ! empty( $cpt[ 'not_found_in_trash' ] ) ) { + if ( isset( $cpt['not_found_in_trash'] ) && ! empty( $cpt['not_found_in_trash'] ) ) { $labels['not_found_in_trash'] = strip_tags( $cpt['not_found_in_trash'] ); } - if ( isset( $cpt[ 'parent_item_colon' ] ) && ! empty( $cpt[ 'parent_item_colon' ] ) ) { + if ( isset( $cpt['parent_item_colon'] ) && ! empty( $cpt['parent_item_colon'] ) ) { $labels['parent_item_colon'] = strip_tags( $cpt['parent_item_colon'] ); } - if ( isset( $cpt[ 'menu_name' ] ) && ! empty( $cpt[ 'menu_name' ] ) ) { + if ( isset( $cpt['menu_name'] ) && ! empty( $cpt['menu_name'] ) ) { $labels['menu_name'] = strip_tags( $cpt['menu_name'] ); } - if ( isset( $cpt[ 'name_admin_bar' ] ) && ! empty( $cpt[ 'name_admin_bar' ] ) ) { + if ( isset( $cpt['name_admin_bar'] ) && ! empty( $cpt['name_admin_bar'] ) ) { $labels['name_admin_bar'] = strip_tags( $cpt['name_admin_bar'] ); } - + // Define the labels - $args[ 'labels' ] = $labels; - + $args['labels'] = $labels; + // WP default = false, plugin default = true - $args[ 'public' ] = ( isset( $cpt[ 'public' ] ) && ! $cpt[ 'public' ] ) ? false : true; - - /** + $args['public'] = ( isset( $cpt['public'] ) && ! $cpt['public'] ) ? false : true; + + /* * boolean (optional) default = false * This must be defined for use with register_taxonomy(). */ - $args[ 'hierarchical' ] = ( isset( $cpt[ 'hierarchical' ] ) && $cpt[ 'hierarchical' ] ) ? true : false; - + $args['hierarchical'] = ( isset( $cpt['hierarchical'] ) && $cpt['hierarchical'] ) ? true : false; + /* * array (optional) default = array( 'title', 'editor' ) * @@ -1297,171 +1269,170 @@ public function create_custom_post_type_arguments_for_registration( $cpt_key, $c * so the post type will actually support nothing instead * of applying the default behavior. */ - if ( isset( $cpt[ 'supports' ] ) && ! empty( $cpt[ 'supports' ] ) ) { + if ( isset( $cpt['supports'] ) && ! empty( $cpt['supports'] ) ) { $args['supports'] = $cpt['supports']; } else { $args['supports'] = false; } - + // Array (optional) no default - if ( isset( $cpt[ 'taxonomies' ] ) && ! empty( $cpt[ 'taxonomies' ] ) ) { - if ( ! is_array( $cpt[ 'taxonomies' ] ) ) { + if ( isset( $cpt['taxonomies'] ) && ! empty( $cpt['taxonomies'] ) ) { + if ( ! is_array( $cpt['taxonomies'] ) ) { $cpt['taxonomies'] = array( $cpt['taxonomies'] ); } - $args[ 'taxonomies' ] = $cpt[ 'taxonomies' ]; + $args['taxonomies'] = $cpt['taxonomies']; } - + // Boolean (optional) default = public - if ( isset( $cpt[ 'show_ui' ] ) ) { + if ( isset( $cpt['show_ui'] ) ) { $args['show_ui'] = ( ! $cpt['show_ui'] ) ? false : true; } - + // Boolean (optional) default = public - if ( isset( $cpt[ 'show_in_nav_menus' ] ) ) { + if ( isset( $cpt['show_in_nav_menus'] ) ) { $args['show_in_nav_menus'] = ( ! $cpt['show_in_nav_menus'] ) ? false : true; } - + // Boolean (optional) default = show_in_menu - if ( isset( $cpt[ 'show_in_admin_bar' ] ) ) { + if ( isset( $cpt['show_in_admin_bar'] ) ) { $args['show_in_admin_bar'] = ( ! $cpt['show_in_admin_bar'] ) ? false : true; } - + // Boolean (optional) default = public - if ( isset( $cpt[ 'publicly_queryable' ] ) ) { + if ( isset( $cpt['publicly_queryable'] ) ) { $args['publicly_queryable'] = ( ! $cpt['publicly_queryable'] ) ? false : true; } - + // Boolean (optional) default = opposite of public - if ( isset( $cpt[ 'exclude_from_search' ] ) ) { + if ( isset( $cpt['exclude_from_search'] ) ) { $args['exclude_from_search'] = ( $cpt['exclude_from_search'] ) ? true : false; } - + // Boolean (optional) default = false - if ( isset( $cpt[ 'map_meta_cap' ] ) ) { + if ( isset( $cpt['map_meta_cap'] ) ) { $args['map_meta_cap'] = ( $cpt['map_meta_cap'] ) ? true : false; } - + // Boolean (optional) default = true - if ( isset( $cpt[ 'can_export' ] ) ) { + if ( isset( $cpt['can_export'] ) ) { $args['can_export'] = ( ! $cpt['can_export'] ) ? false : true; } - + // Boolean (optional) default = null - if ( isset( $cpt[ 'delete_with_user' ] ) ) { + if ( isset( $cpt['delete_with_user'] ) ) { $args['delete_with_user'] = ( ! $cpt['delete_with_user'] ) ? false : true; } - - // Integer (optional) default = NULL - if ( isset( $cpt[ 'menu_position' ] ) && ! empty( $cpt[ 'menu_position' ] ) && is_numeric( $cpt[ 'menu_position' ] ) ) { + + // Integer (optional) default = null + if ( isset( $cpt['menu_position'] ) && ! empty( $cpt['menu_position'] ) && is_numeric( $cpt['menu_position'] ) ) { $args['menu_position'] = intval( $cpt['menu_position'] ); } - + // String (optional) default is blank - if ( isset( $cpt[ 'description' ] ) && ! empty( $cpt[ 'description' ] ) ) { + if ( isset( $cpt['description'] ) && ! empty( $cpt['description'] ) ) { $args['description'] = strip_tags( $cpt['description'] ); } - // String (optional) default = NULL - if ( isset( $cpt[ 'menu_icon' ] ) && ! empty( $cpt[ 'menu_icon' ] ) ) { + // String (optional) default = null + if ( isset( $cpt['menu_icon'] ) && ! empty( $cpt['menu_icon'] ) ) { $args['menu_icon'] = $cpt['menu_icon']; } // String (optional) no default - if ( isset( $cpt[ 'register_meta_box_cb' ] ) && ! empty( $cpt[ 'register_meta_box_cb' ] ) ) { + if ( isset( $cpt['register_meta_box_cb'] ) && ! empty( $cpt['register_meta_box_cb'] ) ) { $args['register_meta_box_cb'] = $cpt['register_meta_box_cb']; } // String (optional) default = EP_PERMALINK - if ( isset( $cpt[ 'permalink_epmask' ] ) && ! empty( $cpt[ 'permalink_epmask' ] ) ) { + if ( isset( $cpt['permalink_epmask'] ) && ! empty( $cpt['permalink_epmask'] ) ) { $args['permalink_epmask'] = $cpt['permalink_epmask']; } - + // String or array (optional) default = "post" - if ( isset( $cpt[ 'capability_type' ] ) && ! empty( $cpt[ 'capability_type' ] ) ) { + if ( isset( $cpt['capability_type'] ) && ! empty( $cpt['capability_type'] ) ) { $args['capability_type'] = $cpt['capability_type']; } - - /** + + /* * Boolean or string (optional) * Default = true (which is opposite of WP default so we must include the setting) * If set to string 'true', then store as true * Else if not set to false, store string */ - if ( isset( $cpt[ 'has_archive' ] ) && ! empty( $cpt[ 'has_archive' ] ) && strtolower( $cpt[ 'has_archive' ] ) != 'true' ) { - if ( strtolower( $cpt[ 'has_archive' ] ) == 'false' ) { - $args[ 'has_archive' ] = false; - } else if ( strtolower( $cpt[ 'has_archive' ] ) != 'true' ) { - $args[ 'has_archive' ] = $cpt[ 'has_archive' ]; + if ( isset( $cpt['has_archive'] ) && ! empty( $cpt['has_archive'] ) && strtolower( $cpt['has_archive'] ) != 'true' ) { + if ( strtolower( $cpt['has_archive'] ) == 'false' ) { + $args['has_archive'] = false; + } elseif ( strtolower( $cpt['has_archive'] ) != 'true' ) { + $args['has_archive'] = $cpt['has_archive']; } } else { $args['has_archive'] = true; } - - /** + + /* * Boolean or string (optional) default = true * If set to string 'false', then store as false * Else if set to true, store string */ - if ( isset( $cpt[ 'query_var' ] ) && ! empty( $cpt[ 'query_var' ] ) ) { - if ( strtolower( $cpt[ 'query_var' ] ) == 'false' ) { - $args[ 'query_var' ] = false; - } else if ( strtolower( $cpt[ 'query_var' ] ) != 'true' ) { - $args[ 'query_var' ] = $cpt[ 'query_var' ]; + if ( isset( $cpt['query_var'] ) && ! empty( $cpt['query_var'] ) ) { + if ( strtolower( $cpt['query_var'] ) == 'false' ) { + $args['query_var'] = false; + } elseif ( strtolower( $cpt['query_var'] ) != 'true' ) { + $args['query_var'] = $cpt['query_var']; } - } - - /** - * Boolean or string (optional) default = NULL + } + + /* + * Boolean or string (optional) default = null * If set to string 'false', then store as false * If set to string 'true', then store as true * If set to another string, store string */ - if ( isset( $cpt[ 'show_in_menu' ] ) && ! empty( $cpt[ 'show_in_menu' ] ) ) { - if ( strtolower( $cpt[ 'show_in_menu' ] ) == 'false' ) { - $args[ 'show_in_menu' ] = false; - } else if ( strtolower( $cpt[ 'show_in_menu' ] ) == 'true' ) { - $args[ 'show_in_menu' ] = true; + if ( isset( $cpt['show_in_menu'] ) && ! empty( $cpt['show_in_menu'] ) ) { + if ( strtolower( $cpt['show_in_menu'] ) == 'false' ) { + $args['show_in_menu'] = false; + } elseif ( strtolower( $cpt['show_in_menu'] ) == 'true' ) { + $args['show_in_menu'] = true; } else { - $args[ 'show_in_menu' ] = $cpt[ 'show_in_menu' ]; + $args['show_in_menu'] = $cpt['show_in_menu']; } } - - /** + + /* * Array (optional) default = capability_type is used to construct * If you include blank capabilities, it messes up that capability */ - if ( isset( $cpt[ 'capabilities' ] ) && ! empty( $cpt[ 'capabilities' ] ) ) { - foreach( $cpt[ 'capabilities' ] as $capability_key => $capability ) { + if ( isset( $cpt['capabilities'] ) && ! empty( $cpt['capabilities'] ) ) { + foreach ( $cpt['capabilities'] as $capability_key => $capability ) { if ( ! empty( $capability ) ) { - $args[ 'capabilities' ][ $capability_key ] = $capability; + $args['capabilities'][ $capability_key ] = $capability; } } } - - // Boolean or array (optional) default = true and use post type as slug - if ( isset( $cpt[ 'rewrite' ] ) && ! empty( $cpt[ 'rewrite' ] ) ) { - if ( isset( $cpt[ 'rewrite' ][ 'enable_rewrite' ] ) && ! $cpt[ 'rewrite' ][ 'enable_rewrite' ] ) { + + // Boolean or array (optional) default = true and use post type as slug. + if ( isset( $cpt['rewrite'] ) && ! empty( $cpt['rewrite'] ) ) { + + if ( isset( $cpt['rewrite']['enable_rewrite'] ) && ! $cpt['rewrite']['enable_rewrite'] ) { $args['rewrite'] = false; } else { - // Remove "enable rewrite" and include the rest - unset( $cpt[ 'rewrite' ][ 'enable_rewrite' ] ); + // Remove "enable rewrite" and include the rest. + unset( $cpt['rewrite']['enable_rewrite'] ); - if ( isset( $cpt[ 'rewrite' ] ) && ! empty( $cpt[ 'rewrite' ] ) ) { + if ( isset( $cpt['rewrite'] ) && ! empty( $cpt['rewrite'] ) ) { $args['rewrite'] = $cpt['rewrite']; } - } } - + return $args; - } - + /** * If your custom post type is created in the network admin, some settings * have to use a serialized string to help set/combine network and site definitions. - * + * * As of 1.3., those settings include the CPT-onomy "Restrict User's Capability to * Assign Term Relationships" setting and the CPT "Taxonomies" setting. * @@ -1475,70 +1446,66 @@ public function create_custom_post_type_arguments_for_registration( $cpt_key, $c */ private function unserialize_network_custom_post_type_argument( $argument ) { global $blog_id; - + // If it's already an array, there's no point if ( is_array( $argument ) ) { return $argument; } - + // Remove any and all white space $argument = preg_replace( '/\s/i', '', $argument ); - + // Divide by ';' which separates site definitions $argument = explode( ';', $argument ); - + // Going to need to store some info $network_property = $site_property = $overwrite = array(); - + // Separate network/site definitions - foreach( $argument as $user_role ) { - + foreach ( $argument as $user_role ) { + // See if there is a blog id $site_definition = explode( ':', $user_role ); - - // Network definition + + /* + * Network definition. + * + * Otherwise, site definition. + */ if ( count( $site_definition ) == 1 ) { $network_property = array_merge( $network_property, explode( ',', array_shift( $site_definition ) ) ); - } - - // Site definition - else { - + } else { + if ( ( $site_blog_id = array_shift( $site_definition ) ) && $site_blog_id > 0 ) { - + $site_property[ $site_blog_id ] = explode( ',', array_shift( $site_definition ) ); - - // Figure out if this is supposed to overwrite the network definition + + // Figure out if this is supposed to overwrite the network definition. if ( isset( $site_definition ) && ! empty( $site_definition ) && ( $site_definition = array_shift( $site_definition ) ) && 'overwrite' == $site_definition ) { $overwrite[ $site_blog_id ] = true; } - } - } - - } - - // If there is a site definition for the current blog + + // If there is a site definition for the current blog. if ( isset( $site_property[ $blog_id ] ) ) { - - // Site definition takes precedence + + /* + * Site definition takes precedence. + * + * Otherwise, merge site and network definitions. + */ if ( isset( $overwrite ) && isset( $overwrite[ $blog_id ] ) && $overwrite[ $blog_id ] ) { $network_property = $site_property[ $blog_id ]; - } - - // Merge site and network definitions - else { + } else { $network_property = array_merge( $network_property, $site_property[ $blog_id ] ); } - } - + return $network_property; - } - + /** * Registers the user's custom post types. * @@ -1553,193 +1520,190 @@ private function unserialize_network_custom_post_type_argument( $argument ) { */ public function register_custom_post_types_and_taxonomies() { global $blog_id; - - /** + + /* * Going to save register CPT-onomy info so we * can register all the CPT-onomies at the same time, * after the CPTs are registered. */ $register_cpt_onomies = array(); - - // Register Network CPTs - if ( isset( $this->user_settings[ 'network_custom_post_types' ] ) ) { - - // Take this one CPT at a time - foreach( $this->user_settings[ 'network_custom_post_types' ] as $cpt_key => $cpt ) { - if ( ( ! isset( $cpt[ 'site_registration' ] ) || ( isset( $cpt[ 'site_registration' ] ) && empty( $cpt[ 'site_registration' ] ) ) ) - || ( isset( $cpt[ 'site_registration' ] ) && in_array( $blog_id, $cpt[ 'site_registration' ] ) ) ) { - - /** + + // Register network CPTs. + if ( isset( $this->user_settings['network_custom_post_types'] ) ) { + + // Take this one CPT at a time. + foreach ( $this->user_settings['network_custom_post_types'] as $cpt_key => $cpt ) { + if ( ( ! isset( $cpt['site_registration'] ) || ( isset( $cpt['site_registration'] ) && empty( $cpt['site_registration'] ) ) ) + || ( isset( $cpt['site_registration'] ) && in_array( $blog_id, $cpt['site_registration'] ) ) ) { + + /* * In previous versions, we had to register the post type * last in order for it to win the rewrite war As of 1.1, * the post type must be registered first in order to register * the CPT-onomy and the post type will still win the rewrite war. */ - + // Make sure post type is not deactivated and does not already exist - if ( ! isset( $cpt[ 'deactivate' ] ) && ! post_type_exists( $cpt_key ) ) { - - /** + if ( ! isset( $cpt['deactivate'] ) && ! post_type_exists( $cpt_key ) ) { + + /* * unserialize 'taxonomies' for network settings, since they * are a text input site property is an array of checkboxes * and doesn't need to be tampered with. */ - if ( isset( $cpt[ 'taxonomies' ] ) && ! empty( $cpt[ 'taxonomies' ] ) - && ! is_array( $cpt[ 'taxonomies' ] ) ) { + if ( isset( $cpt['taxonomies'] ) && ! empty( $cpt['taxonomies'] ) + && ! is_array( $cpt['taxonomies'] ) ) { $cpt['taxonomies'] = $this->unserialize_network_custom_post_type_argument( $cpt['taxonomies'] ); } - - // Create the arguments + + // Create the arguments. if ( $args = $this->create_custom_post_type_arguments_for_registration( $cpt_key, $cpt, array( 'created_by_cpt_onomies' => true, 'cpt_onomies_network_cpt' => true ) ) ) { - - // Register this puppy + + // Register this puppy. register_post_type( $cpt_key, $args ); - - // If designated, register CPT-onomy - if ( isset( $cpt[ 'attach_to_post_type' ] ) && ! empty( $cpt[ 'attach_to_post_type' ] ) ) { - - /** + + // If designated, register CPT-onomy. + if ( isset( $cpt['attach_to_post_type'] ) && ! empty( $cpt['attach_to_post_type'] ) ) { + + /* * unserialize 'restrict_user_capabilities' * for network settings, since they are a text input * site property is an array of checkboxes and doesn't * need to be tampered with. */ - if ( isset( $cpt[ 'restrict_user_capabilities' ] ) && ! empty( $cpt[ 'restrict_user_capabilities' ] ) - && ! is_array( $cpt[ 'restrict_user_capabilities' ] ) ) { + if ( isset( $cpt['restrict_user_capabilities'] ) && ! empty( $cpt['restrict_user_capabilities'] ) + && ! is_array( $cpt['restrict_user_capabilities'] ) ) { $cpt['restrict_user_capabilities'] = $this->unserialize_network_custom_post_type_argument( $cpt['restrict_user_capabilities'] ); } - + $register_cpt_onomies[ $cpt_key ] = array( - 'attach_to_post_type' => $cpt[ 'attach_to_post_type' ], + 'attach_to_post_type' => $cpt['attach_to_post_type'], 'cpt_onomy_args' => array( - 'label' => isset( $args[ 'labels' ][ 'name' ] ) ? strip_tags( $args[ 'labels' ][ 'name' ] ) : 'Posts', - 'public' => isset( $args[ 'public' ] ) ? $args[ 'public' ] : true, - 'meta_box_format' => ( isset( $cpt[ 'meta_box_format' ] ) && ! empty( $cpt[ 'meta_box_format' ] ) ) ? $cpt[ 'meta_box_format' ] : NULL, - 'meta_box_title' => ( isset( $cpt[ 'meta_box_title' ] ) && ! empty( $cpt[ 'meta_box_title' ] ) ) ? $cpt[ 'meta_box_title' ] : NULL, - 'show_admin_column' => ( isset( $cpt[ 'show_admin_column' ] ) && ! $cpt[ 'show_admin_column' ] ) ? false : true, - 'admin_column_title' => ( isset( $cpt[ 'admin_column_title' ] ) && ! empty( $cpt[ 'admin_column_title' ] ) ) ? $cpt[ 'admin_column_title' ] : NULL, - 'has_cpt_onomy_archive' => ( isset( $cpt[ 'has_cpt_onomy_archive' ] ) && ! $cpt[ 'has_cpt_onomy_archive' ] ) ? false : true, - 'cpt_onomy_archive_slug' => ( isset( $cpt[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt[ 'cpt_onomy_archive_slug' ] : NULL, - 'restrict_user_capabilities' => ( isset( $cpt[ 'restrict_user_capabilities' ] ) && ! empty( $cpt[ 'restrict_user_capabilities' ] ) ) ? $cpt[ 'restrict_user_capabilities' ] : array(), - 'created_by_cpt_onomies' => true - ) + 'label' => isset( $args['labels']['name'] ) ? strip_tags( $args['labels']['name'] ) : 'Posts', + 'public' => isset( $args['public'] ) ? $args['public'] : true, + 'meta_box_format' => ( isset( $cpt['meta_box_format'] ) && ! empty( $cpt['meta_box_format'] ) ) ? $cpt['meta_box_format'] : null, + 'meta_box_title' => ( isset( $cpt['meta_box_title'] ) && ! empty( $cpt['meta_box_title'] ) ) ? $cpt['meta_box_title'] : null, + 'show_admin_column' => ( isset( $cpt['show_admin_column'] ) && ! $cpt['show_admin_column'] ) ? false : true, + 'admin_column_title' => ( isset( $cpt['admin_column_title'] ) && ! empty( $cpt['admin_column_title'] ) ) ? $cpt['admin_column_title'] : null, + 'has_cpt_onomy_archive' => ( isset( $cpt['has_cpt_onomy_archive'] ) && ! $cpt['has_cpt_onomy_archive'] ) ? false : true, + 'cpt_onomy_archive_slug' => ( isset( $cpt['cpt_onomy_archive_slug'] ) && ! empty( $cpt['cpt_onomy_archive_slug'] ) ) ? $cpt['cpt_onomy_archive_slug'] : null, + 'restrict_user_capabilities' => ( isset( $cpt['restrict_user_capabilities'] ) && ! empty( $cpt['restrict_user_capabilities'] ) ) ? $cpt['restrict_user_capabilities'] : array(), + 'created_by_cpt_onomies' => true, + ), ); - + } - } - } - } } - } - + // Register Site CPTs - if ( isset( $this->user_settings[ 'custom_post_types' ] ) ) { - - // Take this one CPT at a time - foreach( $this->user_settings[ 'custom_post_types' ] as $cpt_key => $cpt ) { - - /** + if ( isset( $this->user_settings['custom_post_types'] ) ) { + + // Take this one CPT at a time. + foreach ( $this->user_settings['custom_post_types'] as $cpt_key => $cpt ) { + + /* * In previous versions, we had to register the post type last * in order for it to win the rewrite war. As of 1.1, the post type * must be registered first in order to register the CPT-onomy and * the post type will still win the rewrite war. */ - - // Make sure post type is not deactivated - if ( ! isset( $cpt[ 'deactivate' ] ) ) { - - // Make sure the CPT does not already exist - // (unless its a network-registered CPT, which you're allowed to overwrite on a site level) + + // Make sure post type is not deactivated. + if ( ! isset( $cpt['deactivate'] ) ) { + + /* + * Make sure the CPT does not already exist. + * + * Unless its a network-registered CPT, which + * you're allowed to overwrite on a site level. + */ $post_type_exists = post_type_exists( $cpt_key ); if ( ! $post_type_exists || ( $post_type_exists && $this->is_registered_network_cpt( $cpt_key ) ) ) { - + // Create the arguments if ( $args = $this->create_custom_post_type_arguments_for_registration( $cpt_key, $cpt, array( 'created_by_cpt_onomies' => true ) ) ) { - + // Register this puppy register_post_type( $cpt_key, $args ); - - // If designated, register CPT-onomy - if ( isset( $cpt[ 'attach_to_post_type' ] ) && ! empty( $cpt[ 'attach_to_post_type' ] ) ) { - + + /* + * If designated, register CPT-onomy. + * + * Otherwise, overwriting network CPT + * so we have to remove existing CPT-onomy + * + */ + if ( isset( $cpt['attach_to_post_type'] ) && ! empty( $cpt['attach_to_post_type'] ) ) { + $register_cpt_onomies[ $cpt_key ] = array( - 'attach_to_post_type' => $cpt[ 'attach_to_post_type' ], + 'attach_to_post_type' => $cpt['attach_to_post_type'], 'cpt_onomy_args' => array( - 'label' => isset( $args[ 'labels' ][ 'name' ] ) ? strip_tags( $args[ 'labels' ][ 'name' ] ) : 'Posts', - 'public' => isset( $args[ 'public' ] ) ? $args[ 'public' ] : true, - 'meta_box_format' => ( isset( $cpt[ 'meta_box_format' ] ) && ! empty( $cpt[ 'meta_box_format' ] ) ) ? $cpt[ 'meta_box_format' ] : NULL, - 'meta_box_title' => ( isset( $cpt[ 'meta_box_title' ] ) && ! empty( $cpt[ 'meta_box_title' ] ) ) ? $cpt[ 'meta_box_title' ] : NULL, - 'show_admin_column' => ( isset( $cpt[ 'show_admin_column' ] ) && ! $cpt[ 'show_admin_column' ] ) ? false : true, - 'admin_column_title' => ( isset( $cpt[ 'admin_column_title' ] ) && ! empty( $cpt[ 'admin_column_title' ] ) ) ? $cpt[ 'admin_column_title' ] : NULL, - 'has_cpt_onomy_archive' => ( isset( $cpt[ 'has_cpt_onomy_archive' ] ) && ! $cpt[ 'has_cpt_onomy_archive' ] ) ? false : true, - 'cpt_onomy_archive_slug' => ( isset( $cpt[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt[ 'cpt_onomy_archive_slug' ] : NULL, - 'restrict_user_capabilities' => ( isset( $cpt[ 'restrict_user_capabilities' ] ) && ! empty( $cpt[ 'restrict_user_capabilities' ] ) ) ? $cpt[ 'restrict_user_capabilities' ] : array(), - 'created_by_cpt_onomies' => true - ) + 'label' => isset( $args['labels']['name'] ) ? strip_tags( $args['labels']['name'] ) : 'Posts', + 'public' => isset( $args['public'] ) ? $args['public'] : true, + 'meta_box_format' => ( isset( $cpt['meta_box_format'] ) && ! empty( $cpt['meta_box_format'] ) ) ? $cpt['meta_box_format'] : null, + 'meta_box_title' => ( isset( $cpt['meta_box_title'] ) && ! empty( $cpt['meta_box_title'] ) ) ? $cpt['meta_box_title'] : null, + 'show_admin_column' => ( isset( $cpt['show_admin_column'] ) && ! $cpt['show_admin_column'] ) ? false : true, + 'admin_column_title' => ( isset( $cpt['admin_column_title'] ) && ! empty( $cpt['admin_column_title'] ) ) ? $cpt['admin_column_title'] : null, + 'has_cpt_onomy_archive' => ( isset( $cpt['has_cpt_onomy_archive'] ) && ! $cpt['has_cpt_onomy_archive'] ) ? false : true, + 'cpt_onomy_archive_slug' => ( isset( $cpt['cpt_onomy_archive_slug'] ) && ! empty( $cpt['cpt_onomy_archive_slug'] ) ) ? $cpt['cpt_onomy_archive_slug'] : null, + 'restrict_user_capabilities' => ( isset( $cpt['restrict_user_capabilities'] ) && ! empty( $cpt['restrict_user_capabilities'] ) ) ? $cpt['restrict_user_capabilities'] : array(), + 'created_by_cpt_onomies' => true, + ), ); - - } - // Overwriting network CPT so we have to remove existing CPT-onomy - else if ( isset( $register_cpt_onomies[ $cpt_key ] ) && $this->overwrote_network_cpt( $cpt_key ) ) { + + } elseif ( isset( $register_cpt_onomies[ $cpt_key ] ) && $this->overwrote_network_cpt( $cpt_key ) ) { unset( $register_cpt_onomies[ $cpt_key ] ); } - } - } - } - } - } - + // Register CPT-onomies AFTER all CPTs are registered - foreach( $register_cpt_onomies as $cpt_key => $cpt_onomy_info ) { - + foreach ( $register_cpt_onomies as $cpt_key => $cpt_onomy_info ) { + // Let's get this sucker registered! - $this->register_cpt_onomy( $cpt_key, $cpt_onomy_info[ 'attach_to_post_type' ], $cpt_onomy_info[ 'cpt_onomy_args' ] ); - + $this->register_cpt_onomy( $cpt_key, $cpt_onomy_info['attach_to_post_type'], $cpt_onomy_info['cpt_onomy_args'] ); + } - - // Register OTHER CPTs as CPT-onomies - if ( ! empty( $this->user_settings[ 'other_custom_post_types' ] ) ) { - foreach( $this->user_settings[ 'other_custom_post_types' ] as $cpt_key => $cpt_settings ) { - - // If designated, register CPT-onomy + + // Register OTHER CPTs as CPT-onomies. + if ( ! empty( $this->user_settings['other_custom_post_types'] ) ) { + foreach ( $this->user_settings['other_custom_post_types'] as $cpt_key => $cpt_settings ) { + + // If designated, register CPT-onomy. if ( post_type_exists( $cpt_key ) && ! $this->is_registered_cpt( $cpt_key ) - && isset( $cpt_settings[ 'attach_to_post_type' ] ) && ! empty( $cpt_settings[ 'attach_to_post_type' ] ) ) { - - // Get post type object + && isset( $cpt_settings['attach_to_post_type'] ) && ! empty( $cpt_settings['attach_to_post_type'] ) ) { + + // Get post type object. $custom_post_type = get_post_type_object( $cpt_key ); - - // Create the arguments + + // Create the arguments. $cpt_onomy_args = array( 'label' => strip_tags( $custom_post_type->label ), 'public' => $custom_post_type->public, - 'meta_box_format' => ( isset( $cpt_settings[ 'meta_box_format' ] ) && ! empty( $cpt_settings[ 'meta_box_format' ] ) ) ? $cpt_settings[ 'meta_box_format' ] : NULL, - 'meta_box_title' => ( isset( $cpt_settings[ 'meta_box_title' ] ) && ! empty( $cpt_settings[ 'meta_box_title' ] ) ) ? $cpt_settings[ 'meta_box_title' ] : NULL, - 'show_admin_column' => ( isset( $cpt_settings[ 'show_admin_column' ] ) && ! $cpt_settings[ 'show_admin_column' ] ) ? false : true, - 'admin_column_title' => ( isset( $cpt_settings[ 'admin_column_title' ] ) && ! empty( $cpt_settings[ 'admin_column_title' ] ) ) ? $cpt_settings[ 'admin_column_title' ] : NULL, - 'has_cpt_onomy_archive' => ( isset( $cpt_settings[ 'has_cpt_onomy_archive' ] ) && ! $cpt_settings[ 'has_cpt_onomy_archive' ] ) ? false : true, - 'cpt_onomy_archive_slug' => ( isset( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) && ! empty( $cpt_settings[ 'cpt_onomy_archive_slug' ] ) ) ? $cpt_settings[ 'cpt_onomy_archive_slug' ] : NULL, - 'restrict_user_capabilities' => ( isset( $cpt_settings[ 'restrict_user_capabilities' ] ) && ! empty( $cpt_settings[ 'restrict_user_capabilities' ] ) ) ? $cpt_settings[ 'restrict_user_capabilities' ] : array(), - 'created_by_cpt_onomies' => true + 'meta_box_format' => ( isset( $cpt_settings['meta_box_format'] ) && ! empty( $cpt_settings['meta_box_format'] ) ) ? $cpt_settings['meta_box_format'] : null, + 'meta_box_title' => ( isset( $cpt_settings['meta_box_title'] ) && ! empty( $cpt_settings['meta_box_title'] ) ) ? $cpt_settings['meta_box_title'] : null, + 'show_admin_column' => ( isset( $cpt_settings['show_admin_column'] ) && ! $cpt_settings['show_admin_column'] ) ? false : true, + 'admin_column_title' => ( isset( $cpt_settings['admin_column_title'] ) && ! empty( $cpt_settings['admin_column_title'] ) ) ? $cpt_settings['admin_column_title'] : null, + 'has_cpt_onomy_archive' => ( isset( $cpt_settings['has_cpt_onomy_archive'] ) && ! $cpt_settings['has_cpt_onomy_archive'] ) ? false : true, + 'cpt_onomy_archive_slug' => ( isset( $cpt_settings['cpt_onomy_archive_slug'] ) && ! empty( $cpt_settings['cpt_onomy_archive_slug'] ) ) ? $cpt_settings['cpt_onomy_archive_slug'] : null, + 'restrict_user_capabilities' => ( isset( $cpt_settings['restrict_user_capabilities'] ) && ! empty( $cpt_settings['restrict_user_capabilities'] ) ) ? $cpt_settings['restrict_user_capabilities'] : array(), + 'created_by_cpt_onomies' => true, ); - + // Let's get this sucker registered! - $this->register_cpt_onomy( $cpt_key, $cpt_settings[ 'attach_to_post_type' ], $cpt_onomy_args ); - + $this->register_cpt_onomy( $cpt_key, $cpt_settings['attach_to_post_type'], $cpt_onomy_args ); + } - } } - } - -} \ No newline at end of file + +} diff --git a/uninstall.php b/uninstall.php index 31e57e4..d09d823 100644 --- a/uninstall.php +++ b/uninstall.php @@ -2,29 +2,29 @@ global $wpdb; -// If uninstall not called from the WordPress exit +// If uninstall not called from the WordPress exit. if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit(); } - -// Delete individual site options and postmeta -$blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $wpdb->blogs . " ORDER BY blog_id", NULL ) ); -foreach( $blogs as $this_blog_id ) { - // Set blog id so $wpdb will know which table to tweak +// Delete individual site options and postmeta. +$blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->blogs} ORDER BY blog_id", null ) ); +foreach ( $blogs as $this_blog_id ) { + + // Set blog id so $wpdb will know which table to tweak. $wpdb->set_blog_id( $this_blog_id ); - - // Delete site options + + // Delete site options. $wpdb->delete( $wpdb->options, array( 'option_name' => 'custom_post_type_onomies_custom_post_types' ) ); $wpdb->delete( $wpdb->options, array( 'option_name' => 'custom_post_type_onomies_other_custom_post_types' ) ); - - // Delete post meta + + // Delete post meta. $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_custom_post_type_onomies_relationship' ) ); - + } // Delete network options delete_site_option( 'custom_post_type_onomies_custom_post_types' ); // Delete user options -$wpdb->query( $wpdb->prepare( "DELETE FROM " . $wpdb->usermeta . " WHERE meta_key IN ( 'custom_post_type_onomies_dismiss', 'wp_custom_post_type_onomies_show_edit_tables', 'custom_post_type_onomies_show_edit_tables' )", NULL ) ); \ No newline at end of file +$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'custom_post_type_onomies_dismiss', 'wp_custom_post_type_onomies_show_edit_tables', 'custom_post_type_onomies_show_edit_tables' )", null ) ); diff --git a/widgets.php b/widgets.php index a3a8b2a..ec3ec28 100644 --- a/widgets.php +++ b/widgets.php @@ -4,12 +4,12 @@ * Registers the plugin's widgets. * * @since 1.0 - */ -add_action( 'widgets_init', 'cpt_onomies_register_widgets' ); + */ function cpt_onomies_register_widgets() { register_widget( 'WP_Widget_CPTonomy_Tag_Cloud' ); } - +add_action( 'widgets_init', 'cpt_onomies_register_widgets' ); + /** * CPT-onomy tag cloud widget class * @@ -21,18 +21,18 @@ function cpt_onomies_register_widgets() { * @since 1.0 */ class WP_Widget_CPTonomy_Tag_Cloud extends WP_Widget { - + function __construct() { $widget_ops = array( 'description' => sprintf( __( 'If you are using a custom post type as a taxonomy, a.k.a %s, this will show your most used tags in cloud format.' ), 'cpt-onomies' ), '"CPT-onomy"' ); parent::__construct( 'cpt_onomy_tag_cloud', sprintf( __( '%s Tag Cloud', 'cpt-onomies' ), 'CPT-onomy' ), $widget_ops ); } - + /** * This function creates and prints the widget's HTML for the front-end. * * As of 1.1, you are allowed to select whether you want the * term to link to the archive page or the actual post. - * + * * @since 1.0 * @uses $cpt_onomies_manager, $cpt_onomy * @param array $args - arguments to customize the widget @@ -41,71 +41,69 @@ function __construct() { function widget( $args, $instance ) { global $cpt_onomies_manager, $cpt_onomy; - extract( $args ); + if ( isset( $instance['taxonomy'] ) ) { - if ( isset( $instance[ 'taxonomy' ] ) ) { - $current_taxonomy = $instance[ 'taxonomy' ]; + $current_taxonomy = $instance['taxonomy']; if ( $cpt_onomies_manager->is_registered_cpt_onomy( $current_taxonomy ) ) { - - // Get tag cloud + + // Get tag cloud. $tag_cloud = $cpt_onomy->wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => $current_taxonomy, 'echo' => false, - 'link' => ( isset( $instance[ 'term_link' ] ) && $instance[ 'term_link' ] == 'cpt_post' ) ? 'cpt_post' : 'view' + 'link' => ( isset( $instance['term_link'] ) && 'cpt_post' == $instance['term_link'] ) ? 'cpt_post' : 'view', ) )); - - // If empty, and they dont' want to show if empty, then don't show - if ( $instance[ 'show_if_empty' ] || ( ! $instance[ 'show_if_empty' ] && ! empty( $tag_cloud ) ) ) { - - if ( ! empty( $instance[ 'title' ] ) ) { + + // If empty, and they dont' want to show if empty, then don't show. + if ( $instance['show_if_empty'] || ( ! $instance['show_if_empty'] && ! empty( $tag_cloud ) ) ) { + + if ( ! empty( $instance['title'] ) ) { $title = $instance['title']; } else { $tax = get_taxonomy( $current_taxonomy ); $title = $tax->labels->name; - } + } $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); - - echo $before_widget; + + echo $args['before_widget']; if ( $title ) { - echo $before_title . $title . $after_title; + echo $args['before_title'] . $title . $args['after_title']; } echo '
' . $tag_cloud . "
\n"; - echo $after_widget; - + echo $args['after_widget']; + } - } - } } /** * This function updates the widget's settings. - * + * * @since 1.0 - * @param array $new_instance - new settings to overwrite old settings - * @param array $old_instance - old settings + * @param array $new_instance - new settings to overwrite old settings. + * @param array $old_instance - old settings. + * @return array - the updated instance. */ function update( $new_instance, $old_instance ) { - $instance[ 'title' ] = strip_tags( stripslashes( $new_instance[ 'title' ] ) ); - $instance[ 'taxonomy' ] = stripslashes( $new_instance[ 'taxonomy' ] ); - $instance[ 'show_if_empty' ] = stripslashes( $new_instance[ 'show_if_empty' ] ); - $instance[ 'term_link' ] = stripslashes( $new_instance[ 'term_link' ] ); + $instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) ); + $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] ); + $instance['show_if_empty'] = stripslashes( $new_instance['show_if_empty'] ); + $instance['term_link'] = stripslashes( $new_instance['term_link'] ); return $instance; } - + /** * This function prints the widget's form in the admin. * * As of 1.1, you are allowed to select whether you want the * term to link to the archive page or the actual post. - * + * * @since 1.0 * @uses $cpt_onomies_manager * @param $instance - widget settings @@ -113,32 +111,47 @@ function update( $new_instance, $old_instance ) { function form( $instance ) { global $cpt_onomies_manager; - $defaults = array( 'show_if_empty' => 1, 'term_link' => 'view' ); + $defaults = array( + 'show_if_empty' => 1, + 'term_link' => 'view', + ); $instance = wp_parse_args( $instance, $defaults ); - $current_taxonomy = ( ! empty( $instance[ 'taxonomy' ] ) && $cpt_onomies_manager->is_registered_cpt_onomy( $instance[ 'taxonomy' ] ) ) ? $instance[ 'taxonomy' ] : NULL; + $current_taxonomy = ( ! empty( $instance['taxonomy'] ) && $cpt_onomies_manager->is_registered_cpt_onomy( $instance['taxonomy'] ) ) ? $instance['taxonomy'] : null; ?>

-

+

+

-

+

-

+

label; ?> print_plugin_options_edit_custom_post_type_field( $cpt_key, $CPT, $subproperty, $subproperty_key, $property_key ); ?>