From 86c342437ae5962b14ca18bb08b0a0130a454e93 Mon Sep 17 00:00:00 2001 From: Dhanendran Rajagopal Date: Fri, 8 Dec 2023 23:36:16 +0530 Subject: [PATCH 1/9] Check return value of get_post_meta --- includes/utils.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/utils.php b/includes/utils.php index 41aa5b8df..8b84204d5 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -435,6 +435,7 @@ function excluded_meta() { function prepare_meta( $post_id ) { update_postmeta_cache( array( $post_id ) ); $meta = get_post_meta( $post_id ); + $meta = is_array( $meta ) ? $meta : array(); $prepared_meta = array(); $excluded_meta = excluded_meta(); From d520ab43051d4de5fcc6356be53131b135dd35c4 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:39:07 +0530 Subject: [PATCH 2/9] Follow react rules of hooks --- assets/js/gutenberg-plugin.js | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 2fe6800c2..e8adfac90 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -153,24 +153,34 @@ 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. 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 -- permission checks are needed. const postStatus = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostAttribute( 'status' ) ); + // eslint-disable-next-line @wordpress/no-unused-vars-before-return + const distributorTopMenu = document.querySelector( + '#wp-admin-bar-distributor' + ); + + // eslint-disable-next-line no-shadow -- permission checks are needed. + 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 && @@ -179,14 +189,6 @@ const DistributorPlugin = () => { return null; } - const distributorTopMenu = document.querySelector( - '#wp-admin-bar-distributor' - ); - - // eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed. - const post = useSelect( ( select ) => - select( 'core/editor' ).getCurrentPost() - ); // Make the post title and status available to the top menu. dt.postTitle = post.title; dt.postStatus = post.status; From a382cfdcd612234476e8dc4b50937f15238010aa Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Thu, 4 Jul 2024 23:53:45 +0530 Subject: [PATCH 3/9] Early return if meta is false --- includes/utils.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/utils.php b/includes/utils.php index 8f604f94d..5b139308e 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -435,6 +435,11 @@ function excluded_meta() { function prepare_meta( $post_id ) { update_postmeta_cache( array( $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(); From 2f6c586a223ecb69330b6ed3f592a542e362c533 Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:23:21 +0530 Subject: [PATCH 4/9] Update includes/utils.php Co-authored-by: Faisal Alvi --- includes/utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utils.php b/includes/utils.php index 5b139308e..607a07985 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -434,7 +434,7 @@ 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(); From c151a3ad79bdecc93b5f786eb1ff1b1444f805bf Mon Sep 17 00:00:00 2001 From: Kirtan Gajjar <8456197+kirtangajjar@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:23:51 +0530 Subject: [PATCH 5/9] Update includes/utils.php Co-authored-by: Faisal Alvi --- includes/utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utils.php b/includes/utils.php index 607a07985..beea76d2e 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -440,7 +440,7 @@ function prepare_meta( $post_id ) { return array(); } - $meta = is_array( $meta ) ? $meta : array(); + $meta = is_array( $meta ) ? $meta : array(); $prepared_meta = array(); $excluded_meta = excluded_meta(); From 58984799c1ac40daeed3dff5d731c951296d843e Mon Sep 17 00:00:00 2001 From: Faisal Alvi Date: Tue, 9 Jul 2024 17:25:39 +0530 Subject: [PATCH 6/9] Update includes/utils.php --- includes/utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utils.php b/includes/utils.php index beea76d2e..607a07985 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -440,7 +440,7 @@ function prepare_meta( $post_id ) { return array(); } - $meta = is_array( $meta ) ? $meta : array(); + $meta = is_array( $meta ) ? $meta : array(); $prepared_meta = array(); $excluded_meta = excluded_meta(); From a03c26fb693c24724e72f79ca20fef340ce158ec Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Sat, 13 Jul 2024 08:43:39 +0530 Subject: [PATCH 7/9] replace get post type with distributable one --- includes/rest-api.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/includes/rest-api.php b/includes/rest-api.php index 41dceed42..c008a18eb 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -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(), From d0bf34a4bb6283cb63f2ab286a9d6c2f2ad75fdb Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Sun, 14 Jul 2024 21:21:45 +0530 Subject: [PATCH 8/9] fix documentation --- assets/js/gutenberg-plugin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index e8adfac90..8b1448222 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -153,12 +153,12 @@ const DistributorIcon = () => ( * Add the Distributor panel to Gutenberg */ const DistributorPlugin = () => { - // 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 -- permission checks are needed. + // eslint-disable-next-line no-shadow const postStatus = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostAttribute( 'status' ) ); @@ -168,12 +168,12 @@ const DistributorPlugin = () => { '#wp-admin-bar-distributor' ); - // eslint-disable-next-line no-shadow -- permission checks are needed. + // eslint-disable-next-line no-shadow const post = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); - // Ensure the user has proper permissions + // Ensure the user has proper permissions. if ( dtGutenberg.noPermissions && 1 === parseInt( dtGutenberg.noPermissions ) @@ -181,7 +181,7 @@ const DistributorPlugin = () => { return null; } - // Ensure we are on a supported post type + // Ensure we are on a supported post type. if ( dtGutenberg.supportedPostTypes && dtGutenberg.supportedPostTypes[ postType ] === undefined @@ -193,7 +193,7 @@ const DistributorPlugin = () => { 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 ) From eecf7a11ba0fb6e5e24d4452222f67a3dfa70369 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 15 Jul 2024 00:33:32 +0530 Subject: [PATCH 9/9] fix undefined array key "id" --- includes/classes/DistributorPost.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/classes/DistributorPost.php b/includes/classes/DistributorPost.php index 17d1d5eb3..fef6d0c18 100644 --- a/includes/classes/DistributorPost.php +++ b/includes/classes/DistributorPost.php @@ -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;