Skip to content

Commit

Permalink
Merge branch 'develop' into fix/1176-large-networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 authored Aug 2, 2024
2 parents 5603dc4 + 7181cf2 commit 9810d84
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
BRANCH=${GITHUB_REF##*/}
echo $BRANCH
VERSION=${BRANCH#'release/'}
echo ::set-output name=result::"Release: ${VERSION}"
echo "result="Release: ${VERSION}"" >> $GITHUB_OUTPUT
id: title
- name: Create Pull Request
run: gh pr create --draft --title "${{ steps.title.outputs.result }}" --body-file ./.github/release-pull-request-template.md
Expand Down
42 changes: 22 additions & 20 deletions assets/js/gutenberg-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,45 +153,47 @@ const DistributorIcon = () => (
* Add the Distributor panel to Gutenberg
*/
const DistributorPlugin = () => {
// Ensure the user has proper permissions
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const postType = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostType()
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const postStatus = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostAttribute( 'status' )
);

// Ensure we are on a supported post type
if (
dtGutenberg.supportedPostTypes &&
dtGutenberg.supportedPostTypes[ postType ] === undefined
) {
return null;
}

// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const distributorTopMenu = document.querySelector(
'#wp-admin-bar-distributor'
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const post = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPost()
);

// Ensure the user has proper permissions.
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// Ensure we are on a supported post type.
if (
dtGutenberg.supportedPostTypes &&
dtGutenberg.supportedPostTypes[ postType ] === undefined
) {
return null;
}

// Make the post title and status available to the top menu.
dt.postTitle = post.title;
dt.postStatus = post.status;

// If we are on a non-supported post status, change what we show
// If we are on a non-supported post status, change what we show.
if (
dtGutenberg.supportedPostStati &&
! dtGutenberg.supportedPostStati.includes( postStatus )
Expand Down
6 changes: 5 additions & 1 deletion includes/classes/DistributorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,11 @@ protected function parse_blocks_for_attachment_id( $block ) {
}

if ( in_array( $block['blockName'], $block_names, true ) ) {
$media[] = $block['attrs'][ $media_blocks[ $block['blockName'] ] ];
$attribute_key = $media_blocks[ $block['blockName'] ];

if ( isset( $block['attrs'][ $attribute_key ] ) ) {
$media[] = $block['attrs'][ $attribute_key ];
}
}

return $media;
Expand Down
42 changes: 20 additions & 22 deletions includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,14 @@ public function prepare_items() {
/** Process bulk action */
$this->process_bulk_action();

$per_page = $this->get_items_per_page( 'pull_posts_per_page', get_option( 'posts_per_page' ) );

$per_page = $this->get_items_per_page( 'pull_posts_per_page', get_option( 'posts_per_page' ) );
$current_page = $this->get_pagenum();

// Support 'View all' filtering for internal connections.
if ( is_a( $connection_now, '\Distributor\InternalConnections\NetworkSiteConnection' ) ) {
if ( empty( $connection_now->pull_post_type ) || 'all' === $connection_now->pull_post_type ) {
$post_type = wp_list_pluck( $connection_now->pull_post_types, 'slug' );
} else {
$post_type = $connection_now->pull_post_type;
}
if ( empty( $connection_now->pull_post_type ) || 'all' === $connection_now->pull_post_type ) {
$post_type = wp_list_pluck( $connection_now->pull_post_types, 'slug' );
} else {
$post_type = $connection_now->pull_post_type ? $connection_now->pull_post_type : 'post';
$post_type = $connection_now->pull_post_type;
}

$remote_get_args = [
Expand Down Expand Up @@ -527,18 +522,23 @@ public function prepare_items() {
$remote_get_args['paged'] = 1;
}

if ( ! is_array( $remote_get_args['post_type'] ) ) {
$remote_get_args['post_type'] = [ $remote_get_args['post_type'] ];
}

$total_items = 0;
$response_data = array();

// Setup remote connection from the connection object.
$remote_get = $connection_now->remote_get( $remote_get_args );

// Check and throw error if there is one.
if ( is_wp_error( $remote_get ) ) {
$this->pull_error = $remote_get->get_error_messages();

return;
}

// Get total items retrieved from the remote request if not already set.
if ( false === $total_items ) {
$total_items = $remote_get['total_items'];
}
$total_items = $remote_get['total_items'];
$response_data = array_merge( $response_data, array_values( $remote_get['items'] ) );

$this->set_pagination_args(
[
Expand All @@ -547,7 +547,7 @@ public function prepare_items() {
]
);

foreach ( $remote_get['items'] as $item ) {
foreach ( $response_data as $item ) {
$this->items[] = $item;
}
}
Expand Down Expand Up @@ -612,17 +612,15 @@ public function extra_tablenav( $which ) {
$connection_type = 'external';
}

if ( $connection_now && $connection_now->pull_post_types && $connection_now->pull_post_type ) :
if ( $connection_now && $connection_now->pull_post_types ) :
?>

<div class="alignleft actions dt-pull-post-type">
<label for="pull_post_type" class="screen-reader-text">Content to Pull</label>
<select id="pull_post_type" name="pull_post_type">
<?php if ( 'internal' === $connection_type ) : ?>
<option <?php selected( $connection_now->pull_post_type, 'all' ); ?> value="all">
<?php esc_html_e( 'View all', 'distributor' ); ?>
</option>
<?php endif; ?>
<option <?php selected( $connection_now->pull_post_type, 'all' ); ?> value="all">
<?php esc_html_e( 'View all', 'distributor' ); ?>
</option>
<?php foreach ( $connection_now->pull_post_types as $post_type ) : ?>
<option <?php selected( $connection_now->pull_post_type, $post_type['slug'] ); ?> value="<?php echo esc_attr( $post_type['slug'] ); ?>">
<?php echo esc_html( $post_type['name'] ); ?>
Expand Down
16 changes: 9 additions & 7 deletions includes/pull-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,27 +472,29 @@ function dashboard() {
</select>

<?php
$connection_now->pull_post_type = '';
$connection_now->pull_post_types = \Distributor\Utils\available_pull_post_types( $connection_now, $connection_type );

// Ensure we have at least one post type to pull.
$connection_now->pull_post_type = '';
if ( ! empty( $connection_now->pull_post_types ) ) {
$connection_now->pull_post_type = ( 'internal' === $connection_type ) ? 'all' : $connection_now->pull_post_types[0]['slug'];
$connection_now->pull_post_type = 'all';
}

// Set the post type we want to pull (if any)
// This is either from a query param, "post" post type, or the first in the list
foreach ( $connection_now->pull_post_types as $post_type ) {
if ( isset( $_GET['pull_post_type'] ) ) { // @codingStandardsIgnoreLine No nonce needed here.
if ( $_GET['pull_post_type'] === $post_type['slug'] ) { // @codingStandardsIgnoreLine Comparing values, no nonce needed.
$connection_now->pull_post_type = $post_type['slug'];
if ( ! empty( $_GET['pull_post_type'] ) ) {
if ( 'all' === $_GET['pull_post_type'] ) {
$connection_now->pull_post_type = 'all';
break;
}
} else {
if ( 'post' === $post_type['slug'] && 'external' === $connection_type ) {
} elseif ( $_GET['pull_post_type'] === $post_type['slug'] ) {
$connection_now->pull_post_type = $post_type['slug'];
break;
}
} else {
$connection_now->pull_post_type = ! empty( $post_type['slug'] ) ? $post_type['slug'] : 'all';
break;
}
}
?>
Expand Down
12 changes: 4 additions & 8 deletions includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,7 @@ function distributor_meta() {
* Check user permissions for available post types
*/
function check_post_types_permissions() {
$types = get_post_types(
array(
'show_in_rest' => true,
),
'objects'
);
$types = Utils\distributable_post_types( 'objects' );

$response = array(
'can_get' => array(),
Expand Down Expand Up @@ -623,10 +618,11 @@ function check_post_types_permissions() {
* @return \WP_REST_Response|\WP_Error
*/
function get_pull_content_list( $request ) {
$args = [
$post_type = ! empty( $request['post_type'] ) ? $request['post_type'] : array( 'post' );
$args = [
'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20,
'paged' => isset( $request['page'] ) ? $request['page'] : 1,
'post_type' => isset( $request['post_type'] ) ? $request['post_type'] : 'post',
'post_type' => $post_type,
'post_status' => isset( $request['post_status'] ) ? $request['post_status'] : array( 'any' ),
'order' => ! empty( $request['order'] ) ? strtoupper( $request['order'] ) : 'DESC',
];
Expand Down
6 changes: 5 additions & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ function update_notice( $plugin_file, $plugin_data, $status ) {
* @since 1.2
*/
function maybe_notice() {
if ( 0 === strpos( get_current_screen()->parent_base, 'distributor' ) ) {
$parent_base = get_current_screen()->parent_base;
if ( ! $parent_base ) {
return;
}
if ( 0 === strpos( $parent_base, 'distributor' ) ) {
if ( Utils\is_development_version() ) {
?>
<div class="notice notice-warning">
Expand Down
8 changes: 7 additions & 1 deletion includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,13 @@ function excluded_meta() {
*/
function prepare_meta( $post_id ) {
update_postmeta_cache( array( $post_id ) );
$meta = get_post_meta( $post_id );
$meta = get_post_meta( $post_id );

if ( false === $meta ) {
return array();
}

$meta = is_array( $meta ) ? $meta : array();
$prepared_meta = array();
$excluded_meta = excluded_meta();

Expand Down
Loading

0 comments on commit 9810d84

Please sign in to comment.