Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
85d9457
Add categories to pull screen
kirtangajjar Jun 23, 2024
7fee3dd
Merge branch 'develop' into feature/show-category-pull
faisal-alvi Jul 2, 2024
8ef5b57
Add trailing slash to cat urls
kirtangajjar Jul 4, 2024
32c11d0
Add a full stop.
kirtangajjar Jul 4, 2024
d3d6648
Address PR feedback
kirtangajjar Jul 4, 2024
4ad5180
Address PR feedback
kirtangajjar Jul 4, 2024
8d71ce7
Update wp-env
kirtangajjar Jul 4, 2024
0a82a88
Update connection_now object
kirtangajjar Jul 4, 2024
98d6346
Update wp-env version
kirtangajjar Jul 4, 2024
93090a0
Remove initialization file
kirtangajjar Jul 4, 2024
4c249a8
Fix initialize file
kirtangajjar Jul 4, 2024
b1ad11d
Convert all npm run to npx
kirtangajjar Jul 4, 2024
26480c1
Convert all npm run to npx
kirtangajjar Jul 4, 2024
74319fe
Merge branch 'develop' into feature/show-category-pull
kirtangajjar Jul 8, 2024
e31a171
Add plugin version
kirtangajjar Jul 8, 2024
4e8ed85
Update filter doccomment
kirtangajjar Jul 8, 2024
8df0fa9
Merge branch 'develop' into feature/show-category-pull
kirtangajjar Jul 15, 2024
bd2d8eb
Merge remote-tracking branch 'origin/develop' into feature/show-categ…
kirtangajjar Aug 5, 2024
ab0bfc3
Merge branch 'develop' into feature/show-category-pull
Sidsector9 Aug 19, 2024
0850705
Merge branch 'develop' into feature/show-category-pull
jeffpaul Sep 4, 2024
b6431d2
Merge branch 'develop' into feature/show-category-pull
faisal-alvi Sep 6, 2024
90acb95
Merge branch 'develop' into feature/show-category-pull
kirtangajjar Mar 13, 2025
e9678bd
Merge branch 'develop' into feature/show-category-pull
jeffpaul Apr 28, 2025
3708300
Merge branch 'develop' into feature/show-category-pull
jeffpaul May 12, 2025
fb369f5
Merge branch 'develop' into feature/show-category-pull
sanketio Aug 11, 2025
cbdf94f
Revert @since
sanketio Aug 11, 2025
f867c43
Fix category link for the connection
sanketio Aug 11, 2025
e41fd70
Allow taxonomy filter with remote site posts when pulling content
sanketio Aug 12, 2025
bd41e0a
Potential fix for code scanning alert no. 3: DOM text reinterpreted a…
sanketio Aug 12, 2025
0947ec3
Dynamically add columns to the list table for the supported taxonomies
sanketio Aug 12, 2025
49f4a33
Toggle reset button when post type changes
sanketio Aug 13, 2025
ffbafbc
Open taxonomy terms from the remote site in a new tab
sanketio Aug 21, 2025
93efd0d
Merge pull request #1327 from 10up/feature/show-taxonomy-filters
sanketio Sep 5, 2025
93406da
Merge branch 'develop' into feature/show-category-pull
sanketio Sep 5, 2025
8cafad1
Add missing abstract methods for test cases
sanketio Sep 5, 2025
c7809e2
Merge branch 'develop' into feature/show-category-pull
jeffpaul Sep 8, 2025
c5bb1d5
Merge branch 'develop' into feature/show-category-pull
jeffpaul Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Distributor;

use function Distributor\Utils\generate_taxonomy_links;

/**
* List table class for pull screen
*/
Expand Down Expand Up @@ -54,10 +56,11 @@ public function __construct() {
*/
public function get_columns() {
$columns = [
'cb' => '<input type="checkbox" />',
'name' => esc_html__( 'Name', 'distributor' ),
'post_type' => esc_html__( 'Post Type', 'distributor' ),
'date' => esc_html__( 'Date', 'distributor' ),
'cb' => '<input type="checkbox" />',
'name' => esc_html__( 'Name', 'distributor' ),
'post_type' => esc_html__( 'Post Type', 'distributor' ),
'categories' => esc_html__( 'Categories', 'distributor' ),
'date' => esc_html__( 'Date', 'distributor' ),
];

/**
Expand Down Expand Up @@ -247,6 +250,17 @@ public function column_date( $post ) {
}
}

/**
* Output categories column
*
* @param \WP_Post $post Post object.
* @since 0.8
*/
public function column_categories( $post ) {
$categories = $post->terms['category'] ?? [];
echo wp_kses_post( generate_taxonomy_links( 'category', $post, $categories ) );
}

/**
* Output standard table columns.
*
Expand Down
176 changes: 176 additions & 0 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,182 @@ function prepare_meta( $post_id ) {
return $prepared_meta;
}

/**
* Generates taxonomy term links for a given post.
*
* The code is taken from WP_Posts_List_Table::column_default and modified
* lightly to work in our context.
*
* @param string $taxonomy The taxonomy name.
* @param object $post The post object.
* @param array $terms Optional. Array of terms.
* @return string The generated HTML for the taxonomy links.
*/
function generate_taxonomy_links( $taxonomy, $post, $terms = [] ) {
$taxonomy_object = get_taxonomy( $taxonomy );

if ( ! $terms ) {
$terms = get_the_terms( $post, $taxonomy );
}

/**
* Filter the taxonomy terms that should be synced.
*
* @since x.x.x
* @hook dt_syncable_taxonomy_terms
*
* @param {array} $terms Array of terms.
* @param {string} $taxonomy Taxonomy name.
* @param {object} $post Post Object.
*
* @return {array} Array of terms.
*/
$terms = apply_filters( "dt_syncable_{$taxonomy}_terms", $terms, $taxonomy, $post );


/**
* Filter the terms that should be synced.
*
* @since x.x.x
* @hook dt_syncable_terms
*
* @param {array} $terms Array of categories.
* @param {string} $taxonomy Taxonomy name.
* @param {object} $post Post Object.
*
* @return {array} Array of categories.
*/
$terms = apply_filters( 'dt_syncable_terms', $terms, $taxonomy, $post );

if ( is_array( $terms ) ) {
$term_links = array();

foreach ( $terms as $t ) {
if ( is_array( $t ) ) {
$t = (object) $t;
}
$posts_in_term_qv = array();

if ( 'post' !== $post->post_type ) {
$posts_in_term_qv['post_type'] = $post->post_type;
}

if ( $taxonomy_object->query_var ) {
$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
} else {
$posts_in_term_qv['taxonomy'] = $taxonomy;
$posts_in_term_qv['term'] = $t->slug;
}

$label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );

$term_links[] = get_edit_link( $posts_in_term_qv, $label );
}

/**
* Filters the links in `$taxonomy` column of edit.php.
*
* @since x.x.x
* @hook dt_taxonomy_links
*
* @param string[] $term_links Array of term editing links.
* @param string $taxonomy Taxonomy name.
* @param WP_Term[] $terms Array of term objects appearing in the post row.
*/
$term_links = apply_filters( 'dt_taxonomy_links', $term_links, $taxonomy, $terms );

return implode( wp_get_list_item_separator(), $term_links );
} else {
return '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
}
}

/**
* Creates a link to edit.php with params.
*
* The edit link is created in such a way that it will link to source site.
*
* @since x.x.x
*
* @param string[] $args Associative array of URL parameters for the link.
* @param string $link_text Link text.
* @param string $css_class Optional. Class attribute. Default empty string.
* @return string The formatted link string.
*/
function get_edit_link( $args, $link_text, $css_class = '' ) {
$url = '';
if ( is_internal_connection() ) {
$url = add_query_arg( $args, get_admin_url( null, 'edit.php' ) );
} else {
$url = add_query_arg( $args, get_root_url() . 'wp-admin/edit.php' );
}

$class_html = '';
$aria_current = '';

if ( ! empty( $css_class ) ) {
$class_html = sprintf(
' class="%s"',
esc_attr( $css_class )
);

if ( 'current' === $css_class ) {
$aria_current = ' aria-current="page"';
}
}

return sprintf(
'<a href="%s"%s%s>%s</a>',
esc_url( $url ),
$class_html,
$aria_current,
$link_text
);
}

/**
* Is current connection an external connection?
*
* @return boolean
*/
function is_external_connection() {
global $connection_now;
return is_a( $connection_now, '\Distributor\ExternalConnection' );
}

/**
* Is current connection an internal connection?
*
* @return boolean
*/
function is_internal_connection() {
global $connection_now;
return is_a( $connection_now, '\Distributor\InternalConnections\NetworkSiteConnection' );
}

/**
* Get the root URL of the current connection
*
* @return string
*/
function get_root_url() {
$base_url = get_conn_base_url();
return str_replace( '/wp-json', '', $base_url );
}

/**
* Get the base URL of the current connection
*
* @return string
*/
function get_conn_base_url() {
if ( ! is_external_connection() ) {
return get_site_url();
}
global $connection_now;
return $connection_now->base_url;
}

/**
* Format media items for consumption
*
Expand Down