Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions assets/css/admin-pull-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
padding-left: 10px;
}
}

.pull-taxonomy,
.dt-reset-filters-button {

&.hide {
display: none;
}

&.show {
display: block;
}
}

.dt-reset-filters-button {
margin-left: 6px
}
}

.wp-list-table .disabled {
Expand Down
106 changes: 105 additions & 1 deletion assets/js/admin-pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const escapeURLComponent = ( str ) => {
const chooseConnection = document.getElementById( 'pull_connections' );
const choosePostType = document.getElementById( 'pull_post_type' );
const choosePostTypeBtn = document.getElementById( 'pull_post_type_submit' );
const choosePostTypeReset = document.getElementById( 'pull_post_type_reset' );
const searchField = document.getElementById( 'post-search-input' );
const searchBtn = document.getElementById( 'search-submit' );
const form = document.getElementById( 'posts-filter' );
const asDraftCheckboxes = document.querySelectorAll( '[name=dt_as_draft]' );
const pullLinks = document.querySelectorAll( '.distributor_page_pull .pull a' );
const pullTaxonomies = document.querySelectorAll( '.pull-taxonomy' );

jQuery( chooseConnection ).on( 'change', ( event ) => {
const pullUrlId =
Expand All @@ -39,6 +41,62 @@ jQuery( chooseConnection ).on( 'change', ( event ) => {
} );

if ( chooseConnection && choosePostType && form ) {
/**
* When the post type is changed, show/hide the taxonomy fields based on the post type.
*/
jQuery( choosePostType ).on( 'change', ( event ) => {
let shouldHideResetFiltersButton = false;
const selectedPostType =
event.currentTarget.options[ event.currentTarget.selectedIndex ];
if ( selectedPostType ) {
const dataTaxonomies =
selectedPostType.getAttribute( 'data-taxonomies' );
if ( dataTaxonomies ) {
const supportedTaxonomies = JSON.parse( dataTaxonomies );
if ( supportedTaxonomies.length > 0 ) {
pullTaxonomies.forEach( ( taxonomyField ) => {
if (
supportedTaxonomies.includes(
taxonomyField.id.replace( 'pull_', '' )
)
) {
jQuery( taxonomyField ).addClass( 'show' );
jQuery( taxonomyField ).removeClass( 'hide' );
} else {
jQuery( taxonomyField ).addClass( 'hide' );
jQuery( taxonomyField ).removeClass( 'show' );
}

if (
! shouldHideResetFiltersButton &&
'all' !==
taxonomyField.options[
taxonomyField.selectedIndex
].value
) {
shouldHideResetFiltersButton = true;
}
} );
} else {
pullTaxonomies.forEach( ( taxonomyField ) => {
jQuery( taxonomyField ).addClass( 'hide' );
jQuery( taxonomyField ).removeClass( 'show' );
} );

shouldHideResetFiltersButton = true;
}
}
}

if ( shouldHideResetFiltersButton ) {
jQuery( choosePostTypeReset ).addClass( 'hide' );
jQuery( choosePostTypeReset ).removeClass( 'show' );
} else {
jQuery( choosePostTypeReset ).addClass( 'show' );
jQuery( choosePostTypeReset ).removeClass( 'hide' );
}
} );

if ( choosePostTypeBtn ) {
jQuery( choosePostTypeBtn ).on( 'click', ( event ) => {
event.preventDefault();
Expand All @@ -49,6 +107,35 @@ if ( chooseConnection && choosePostType && form ) {
} );
}

/**
* When the reset filters button is clicked, reset the filters and reload the page.
*/
if ( choosePostTypeReset ) {
jQuery( choosePostTypeReset ).on( 'click', ( event ) => {
event.preventDefault();

const pullUrlId = escapeURLComponent(
chooseConnection.options[
chooseConnection.selectedIndex
].getAttribute( 'data-pull-url-id' )
);

const baseURL = getPullUrl( pullUrlId );
let status = 'new';

if ( -1 < ` ${ form.className } `.indexOf( ' status-skipped ' ) ) {
status = 'skipped';
} else if (
-1 < ` ${ form.className } `.indexOf( ' status-pulled ' )
) {
status = 'pulled';
}

document.location = `${ baseURL }&status=${ status }`;
document.body.className += ' ' + 'dt-loading';
} );
}

if ( searchField && searchBtn ) {
jQuery( searchBtn ).on( 'click', ( event ) => {
event.preventDefault();
Expand Down Expand Up @@ -99,6 +186,23 @@ const getURL = () => {
const postType = escapeURLComponent(
choosePostType.options[ choosePostType.selectedIndex ].value
);

// Build the taxonomies query string.
let taxonomies = '';
if ( pullTaxonomies ) {
pullTaxonomies.forEach( ( taxonomyField ) => {
if ( jQuery( taxonomyField ).hasClass( 'show' ) ) {
taxonomies += `${ taxonomyField.id }=${ escapeURLComponent(
taxonomyField.options[ taxonomyField.selectedIndex ].value
) }&`;
}
} );
}

if ( taxonomies ) {
taxonomies = taxonomies.slice( 0, -1 );
}

const pullUrlId = escapeURLComponent(
chooseConnection.options[ chooseConnection.selectedIndex ].getAttribute(
'data-pull-url-id'
Expand All @@ -113,5 +217,5 @@ const getURL = () => {
status = 'pulled';
}

return `${ baseURL }&pull_post_type=${ postType }&status=${ status }`;
return `${ baseURL }&pull_post_type=${ postType }&status=${ status }&${ taxonomies }`;
};
16 changes: 16 additions & 0 deletions includes/classes/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ abstract public function get_sync_log( $id );
*/
abstract public function get_post_types();

/**
* Get available post type taxonomies from a connection
*
* @param string $post_type Post type.
*
* @return array
*/
abstract public function get_post_type_taxonomies( $post_type );

/**
* Get available taxonomy terms from a connection
*
* @return array
*/
abstract public function get_taxonomy_terms();

/**
* This method is called on every page load. It's helpful for canonicalization
*
Expand Down
138 changes: 138 additions & 0 deletions includes/classes/ExternalConnections/WordPressExternalConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ class WordPressExternalConnection extends ExternalConnection {
*/
public $pull_post_types;

/**
* Default taxonomy term to pull.
*
* @var string
*/
public $pull_taxonomy_term;

/**
* Default taxonomy terms to show in filter.
*
* @var string
*/
public $pull_taxonomy_terms;

/**
* This is a utility function for parsing annoying API link headers returned by the types endpoint
*
Expand Down Expand Up @@ -168,6 +182,11 @@ public function remote_get( $args = array() ) {
}
}

// Add the tax query to the query args.
if ( isset( $args['tax_query'] ) ) {
$query_args['tax_query'] = $args['tax_query']; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
}

// When running a query for the Pull screen, make a POST request instead
if ( empty( $id ) ) {
$query_args['post_type'] = isset( $post_type ) ? $post_type : 'post';
Expand Down Expand Up @@ -682,6 +701,125 @@ public function get_post_types() {
return $types_body_array;
}

/**
* Get the available post type taxonomies.
* The taxonomies with external connection are already available in the post type object.
*
* @param string $post_type Post type.
*
* @return array
*/
public function get_post_type_taxonomies( $post_type ) {
return array();
}

/**
* Get the available taxonomies from the remote connection.
*
* @param array $taxonomies Taxonomies to get.
*
* @return array|\WP_Error Array of taxonomies with rest_base and label, or WP_Error if the request fails.
*/
private function get_remote_taxonomies( $taxonomies = array() ) {

$path = self::$namespace;

$taxonomies_path = untrailingslashit( $this->base_url ) . '/' . $path . '/taxonomies';

$taxonomies_response = Utils\remote_http_request(
$taxonomies_path,
$this->auth_handler->format_get_args( array( 'timeout' => self::$timeout ) )
);

if ( is_wp_error( $taxonomies_response ) ) {
return $taxonomies_response;
}

if ( 404 === wp_remote_retrieve_response_code( $taxonomies_response ) ) {
return new \WP_Error( 'bad-endpoint', esc_html__( 'Could not connect to API endpoint.', 'distributor' ) );
}

$taxonomies_body = wp_remote_retrieve_body( $taxonomies_response );

if ( empty( $taxonomies_body ) ) {
return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) );
}

$taxonomies_body_array = json_decode( $taxonomies_body, true );

$taxonomies_exists = array();
foreach ( $taxonomies as $taxonomy ) {
if ( isset( $taxonomies_body_array[ $taxonomy ] ) ) {
$taxonomies_exists[ $taxonomy ] = array(
'rest_base' => $taxonomies_body_array[ $taxonomy ]['rest_base'],
'label' => $taxonomies_body_array[ $taxonomy ]['name'],
);
}
}

if ( empty( $taxonomies_exists ) ) {
return new \WP_Error( 'no-taxonomies', esc_html__( 'No taxonomies found.', 'distributor' ) );
}

return $taxonomies_exists;
}

/**
* Get the available taxonomy terms.
*
* @param array $taxonomies Taxonomies to get terms for.
*
* @return array|\WP_Error Array of taxonomy terms with items and label, or WP_Error if the request fails.
*/
public function get_taxonomy_terms( $taxonomies = array() ) {

// Get the remote taxonomies, if the request fails, return an empty array.
$remote_taxonomies = $this->get_remote_taxonomies( $taxonomies );
if ( empty( $remote_taxonomies ) || is_wp_error( $remote_taxonomies ) ) {
return array();
}

$path = self::$namespace;

$taxonomy_terms = array();

/**
* Loop through the remote taxonomies and get the terms for each taxonomy.
*/
foreach ( $remote_taxonomies as $taxonomy => $taxonomy_data ) {

$taxonomy_path = untrailingslashit( $this->base_url ) . '/' . $path . '/' . $taxonomy_data['rest_base'];

$taxonomy_response = Utils\remote_http_request(
$taxonomy_path,
$this->auth_handler->format_get_args( array( 'timeout' => self::$timeout ) )
);

if ( is_wp_error( $taxonomy_response ) ) {
continue;
}

if ( 404 === wp_remote_retrieve_response_code( $taxonomy_response ) ) {
continue;
}

$taxonomy_body = wp_remote_retrieve_body( $taxonomy_response );

if ( empty( $taxonomy_body ) ) {
continue;
}

$taxonomy_body_array = json_decode( $taxonomy_body, true );

$taxonomy_terms[ $taxonomy ] = array(
'items' => $taxonomy_body_array,
'label' => $taxonomy_data['label'],
);
}

return $taxonomy_terms;
}

/**
* Check what we can do with a given external connection (push or pull)
*
Expand Down
Loading
Loading