From 4b3803c836cc453aa856cac2f56354b8fccd9025 Mon Sep 17 00:00:00 2001 From: Jose Magana Date: Sat, 14 Apr 2018 16:27:44 +0200 Subject: [PATCH] :Output column data for a Posts 2 Posts/Users connection --- extended-cpts.php | 2 +- src/class-extended-cpt-admin.php | 256 ++++++++++++++++++------------- 2 files changed, 148 insertions(+), 110 deletions(-) mode change 100644 => 100755 src/class-extended-cpt-admin.php diff --git a/extended-cpts.php b/extended-cpts.php index 737d438..3454f0d 100755 --- a/extended-cpts.php +++ b/extended-cpts.php @@ -9,7 +9,7 @@ * @link https://github.com/johnbillion/extended-cpts * @copyright 2012-2017 John Blackbourn * @license GPL v2 or later - * @version 4.2.0 + * @version 4.2.1 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/class-extended-cpt-admin.php b/src/class-extended-cpt-admin.php old mode 100644 new mode 100755 index d6eaa4c..4fd17ca --- a/src/class-extended-cpt-admin.php +++ b/src/class-extended-cpt-admin.php @@ -111,15 +111,15 @@ public function admin_head() { ?> args['admin_filters']['m'] ) && ! $this->args['admin_filters']['m'] ) { ?> - - - + #posts-filter select[name="m"] { + display: none; + } + + + cpt->post_type ) ); + ", $filter['meta_key'], $this->cpt->post_type ) ); // @codingStandardsIgnoreEnd } elseif ( is_callable( $filter['options'] ) ) { $filter['options'] = call_user_func( $filter['options'] ); @@ -286,64 +286,64 @@ public function filters() { $v ) { $key = ( $use_key ? $k : $v ); - ?> + ?> - - - + + - - + + labels->all_items; - } + if ( ! isset( $filter['title'] ) ) { + $filter['title'] = $pto->labels->all_items; + } - $selected = wp_unslash( get_query_var( $filter_key ) ); + $selected = wp_unslash( get_query_var( $filter_key ) ); - if ( 1 === count( $filter['meta_exists'] ) ) { + if ( 1 === count( $filter['meta_exists'] ) ) { # Output a checkbox: - foreach ( $filter['meta_exists'] as $v => $t ) { - ?> - - $t ) { + ?> + + - + + $t ) { ?> - - - + + public ) { + if ( $tax->public ) { // https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1096 // @codingStandardsIgnoreStart - $out[] = sprintf( - '%2$s', - esc_url( get_term_link( $term ) ), - esc_html( $term->name ) - ); + $out[] = sprintf( + '%2$s', + esc_url( get_term_link( $term ) ), + esc_html( $term->name ) + ); // @codingStandardsIgnoreEnd - } else { - $out[] = esc_html( $term->name ); - } - break; + } else { + $out[] = esc_html( $term->name ); + } + break; case 'edit': - if ( current_user_can( $tax->cap->edit_terms ) ) { - $out[] = sprintf( - '%2$s', - esc_url( get_edit_term_link( $term, $taxonomy, $post->post_type ) ), - esc_html( $term->name ) - ); - } else { - $out[] = esc_html( $term->name ); - } - break; - case 'list': - $link = add_query_arg( [ - 'post_type' => $post->post_type, - $taxonomy => $term->slug, - ], admin_url( 'edit.php' ) ); + if ( current_user_can( $tax->cap->edit_terms ) ) { $out[] = sprintf( '%2$s', - esc_url( $link ), + esc_url( get_edit_term_link( $term, $taxonomy, $post->post_type ) ), esc_html( $term->name ) ); - break; + } else { + $out[] = esc_html( $term->name ); + } + break; + case 'list': + $link = add_query_arg( [ + 'post_type' => $post->post_type, + $taxonomy => $term->slug, + ], admin_url( 'edit.php' ) ); + $out[] = sprintf( + '%2$s', + esc_url( $link ), + esc_html( $term->name ) + ); + break; } } else { @@ -881,36 +881,36 @@ public function col_post_field( string $field, array $args ) { case 'post_date_gmt': case 'post_modified': case 'post_modified_gmt': - if ( '0000-00-00 00:00:00' !== get_post_field( $field, $post ) ) { - if ( ! isset( $args['date_format'] ) ) { - $args['date_format'] = get_option( 'date_format' ); - } - echo esc_html( mysql2date( $args['date_format'], get_post_field( $field, $post ) ) ); + if ( '0000-00-00 00:00:00' !== get_post_field( $field, $post ) ) { + if ( ! isset( $args['date_format'] ) ) { + $args['date_format'] = get_option( 'date_format' ); } - break; + echo esc_html( mysql2date( $args['date_format'], get_post_field( $field, $post ) ) ); + } + break; case 'post_status': - $status = get_post_status_object( get_post_status( $post ) ); - if ( $status ) { - echo esc_html( $status->label ); - } - break; + $status = get_post_status_object( get_post_status( $post ) ); + if ( $status ) { + echo esc_html( $status->label ); + } + break; case 'post_author': - echo esc_html( get_the_author() ); - break; + echo esc_html( get_the_author() ); + break; case 'post_title': - echo esc_html( get_the_title() ); - break; + echo esc_html( get_the_title() ); + break; case 'post_excerpt': - echo esc_html( get_the_excerpt() ); - break; + echo esc_html( get_the_excerpt() ); + break; default: - echo esc_html( get_post_field( $field, $post ) ); - break; + echo esc_html( get_post_field( $field, $post ) ); + break; } @@ -956,7 +956,7 @@ public function col_featured_image( string $image_size, array $args ) { } /** - * Output column data for a Posts 2 Posts connection. + * Output column data for a Posts 2 Posts/Users connection. * * @param string $connection The ID of the connection type * @param array $args Array of arguments for a given connection type @@ -1009,21 +1009,58 @@ public function col_connection( string $connection, array $args ) { foreach ( $_post->$field as $post ) { setup_postdata( $post ); + //echo "
";var_dump(	$post,__LINE__);echo "
"; + if ( get_class($post) == 'WP_User' ){ + if ( $args['link'] ) { + switch ( $args['link'] ) { + case 'view': + $out[] = esc_html( $post->user_nicename ); + break; + case 'edit': + if ( current_user_can( 'edit_users', $post->ID ) ) { + $out[] = sprintf( + '%2$s', + esc_url(get_edit_user_link( $post->ID ) ), + esc_html( $post->user_nicename ) + ); + } else { + $out[] = esc_html( $post->user_nicename ); + } + break; + case 'list': + $link = add_query_arg( array_merge( [ + 'post_type' => $_post->post_type, + 'connected_type' => $connection, + 'connected_items' => $post->ID, + ], $meta ), admin_url( 'edit.php' ) ); + $out[] = sprintf( + '%2$s', + esc_url( $link ), + esc_html( $post->user_nicename ) + ); + break; + } + } else { - $pto = get_post_type_object( $post->post_type ); - $pso = get_post_status_object( $post->post_status ); + $out[] = esc_html( get_the_title() ); - if ( $pso->protected && ! current_user_can( 'edit_post', $post->ID ) ) { - continue; - } - if ( 'trash' === $post->post_status ) { - continue; - } + } - if ( $args['link'] ) { + }else{ + $pto = get_post_type_object( $post->post_type ); + $pso = get_post_status_object( $post->post_status ); - switch ( $args['link'] ) { - case 'view': + if ( $pso->protected && ! current_user_can( 'edit_post', $post->ID ) ) { + continue; + } + if ( 'trash' === $post->post_status ) { + continue; + } + + if ( $args['link'] ) { + + switch ( $args['link'] ) { + case 'view': if ( $pto->public ) { if ( $pso->protected ) { $out[] = sprintf( @@ -1042,7 +1079,7 @@ public function col_connection( string $connection, array $args ) { $out[] = esc_html( get_the_title() ); } break; - case 'edit': + case 'edit': if ( current_user_can( 'edit_post', $post->ID ) ) { $out[] = sprintf( '%2$s', @@ -1053,7 +1090,7 @@ public function col_connection( string $connection, array $args ) { $out[] = esc_html( get_the_title() ); } break; - case 'list': + case 'list': $link = add_query_arg( array_merge( [ 'post_type' => $_post->post_type, 'connected_type' => $connection, @@ -1065,11 +1102,12 @@ public function col_connection( string $connection, array $args ) { esc_html( get_the_title() ) ); break; - } - } else { + } + } else { - $out[] = esc_html( get_the_title() ); + $out[] = esc_html( get_the_title() ); + } } }