From 79ec7d8cf54ca547548ee6716ccfb9cd12aba686 Mon Sep 17 00:00:00 2001 From: Doeke Norg Date: Mon, 5 Feb 2024 11:58:21 +0100 Subject: [PATCH 01/11] Add support for Adavnaced Post Creation --- ...s-gravity-forms-advanced-post-creation.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php new file mode 100644 index 0000000000..8e57778cf4 --- /dev/null +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -0,0 +1,67 @@ +get_slug() . '_post_id' ); + if ( ! $created_posts ) { + return; + } + + $feeds = $apc->get_active_feeds( rgar( $form, 'id' ) ); + if ( ! $feeds ) { + return; + } + + // Map feeds on their id for easy access. + $feeds = array_column( $feeds, null, 'id' ); + + foreach ( $created_posts as $created_post ) { + $feed_id = rgar( $created_post, 'feed_id' ); + $feed = rgar( $feeds, $feed_id ); + if ( ! $feed ) { + continue; + } + + $apc->update_post( $created_post['post_id'], $feed, $render->entry, $form ); + } + } + + /** + * @inheritDoc + * @since $ver$ + */ + protected function add_hooks(): void { + parent::add_hooks(); + + add_action( 'gravityview/edit_entry/after_update', [ $this, 'update_post_on_entry_edit' ], 10, 3 ); + } +} + +new GravityView_Plugin_Hooks_Gravity_Forms_Advanced_Post_Creation; From b27e6a85092b302af6ffeacfa4f6a3eaf8010070 Mon Sep 17 00:00:00 2001 From: Doeke Norg Date: Mon, 5 Feb 2024 14:38:00 +0100 Subject: [PATCH 02/11] Add notice when advanced post creation is active --- assets/js/admin-views.js | 2 +- future/includes/class-gv-form.php | 2 +- .../metaboxes/views/view-configuration.php | 4 +- ...s-gravity-forms-advanced-post-creation.php | 54 +++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/assets/js/admin-views.js b/assets/js/admin-views.js index 59d884a2a5..a3592d0224 100644 --- a/assets/js/admin-views.js +++ b/assets/js/admin-views.js @@ -329,7 +329,7 @@ var show_warning = ! dismissed_warning && value.configured === 0; - $( '#' + index + '-fields' ).find( '.notice-warning' ).toggle( show_warning ); + $( '#' + index + '-fields' ).find( '.notice-no-link' ).toggle( show_warning ); $( 'li[aria-controls="' + index + '-view"]' ) .toggleClass( 'tab-not-configured', show_warning ) .find( '.tab-icon' ) diff --git a/future/includes/class-gv-form.php b/future/includes/class-gv-form.php index a5df13e655..49a595b609 100644 --- a/future/includes/class-gv-form.php +++ b/future/includes/class-gv-form.php @@ -24,7 +24,7 @@ abstract class Form extends Source { /** * @var array The backing form. */ - private $form; + protected $form; /** * Construct a \GV\Form instance by ID. diff --git a/includes/admin/metaboxes/views/view-configuration.php b/includes/admin/metaboxes/views/view-configuration.php index 475069d78c..9a6b173948 100644 --- a/includes/admin/metaboxes/views/view-configuration.php +++ b/includes/admin/metaboxes/views/view-configuration.php @@ -62,7 +62,7 @@
-
+ @@ -87,7 +87,7 @@
-
+ diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index 8e57778cf4..4d440d77b6 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -1,5 +1,7 @@ form; + $apc = GF_Advanced_Post_Creation::get_instance(); + $feeds = $apc->get_active_feeds( $form->ID ); + + if ( ! $feeds ) { + return null; + } + + $notification_html = << +
+

%s

+

%s

+
+
+HTML; + + $notification = sprintf( + $notification_html, + esc_html__( 'Caution: Advanced Post Creation is active for this form', 'gk-gravityview' ), + __( 'Editing one of these entries might update a connected post as well. ', 'gk-gravityview' ) + ); + + if ( $echo ) { + echo $notification; + } + + return $notification; + } + /** * @inheritDoc * @since $ver$ @@ -61,6 +114,7 @@ protected function add_hooks(): void { parent::add_hooks(); add_action( 'gravityview/edit_entry/after_update', [ $this, 'update_post_on_entry_edit' ], 10, 3 ); + add_action( 'gravityview_render_directory_active_areas', [ $this, 'add_view_notification' ], 5, 4 ); } } From 9b09bf60e4abdafc076c99ff4c227b55dca24f72 Mon Sep 17 00:00:00 2001 From: Doeke Norg Date: Mon, 5 Feb 2024 14:44:16 +0100 Subject: [PATCH 03/11] Add link to APC + update readme --- ...-plugin-hooks-gravity-forms-advanced-post-creation.php | 8 +++++++- readme.txt | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index 4d440d77b6..c0993f8ace 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -95,10 +95,16 @@ public function add_view_notification( $_, string $context, $view_id, bool $echo $notification = sprintf( $notification_html, - esc_html__( 'Caution: Advanced Post Creation is active for this form', 'gk-gravityview' ), + esc_html__( 'Caution: [link]Advanced Post Creation[/link] is active for this form', 'gk-gravityview' ), __( 'Editing one of these entries might update a connected post as well. ', 'gk-gravityview' ) ); + $apc_feed_link = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&subview=%s&id=%d', $apc->get_slug(), $form->ID ) ); + $notification = strtr( $notification, [ + '[link]' => '', + '[/link]' => '', + ] ); + if ( $echo ) { echo $notification; } diff --git a/readme.txt b/readme.txt index 26ae2b8e7a..65b748096a 100644 --- a/readme.txt +++ b/readme.txt @@ -26,6 +26,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h This release makes it easier to customize search results per-View instead of globally using code. * Added: Ability to send notifications using Gravity Forms when an entry is deleted by selecting the "GravityView - Entry is deleted" event from the event dropdown in Gravity Forms notifications settings +* Added: Support for editing with the Advanced Post Creation add-on * Fixed: Sorting the View by entry ID in ascending and descending order would yield the same result * Fixed: Survey fields without a rating would show a 1-star rating * Fixed: Custom Post Field acting as File Uploads can now be edited on the Edit Entry page From 122729aff17e10aae832ef67d672f484b1fbf62e Mon Sep 17 00:00:00 2001 From: Doeke Norg Date: Tue, 6 Feb 2024 09:22:19 +0100 Subject: [PATCH 04/11] fix unit tests --- future/includes/class-gv-form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/future/includes/class-gv-form.php b/future/includes/class-gv-form.php index 49a595b609..a5df13e655 100644 --- a/future/includes/class-gv-form.php +++ b/future/includes/class-gv-form.php @@ -24,7 +24,7 @@ abstract class Form extends Source { /** * @var array The backing form. */ - protected $form; + private $form; /** * Construct a \GV\Form instance by ID. From 16a1aae879cebea36ac6046d7ac6d02c5b2030ce Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:28:40 -0500 Subject: [PATCH 05/11] Sanitize URL --- ...tyview-plugin-hooks-gravity-forms-advanced-post-creation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index c0993f8ace..7753b6e851 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -101,8 +101,8 @@ public function add_view_notification( $_, string $context, $view_id, bool $echo $apc_feed_link = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&subview=%s&id=%d', $apc->get_slug(), $form->ID ) ); $notification = strtr( $notification, [ - '[link]' => '', '[/link]' => '', + '[link]' => '', ] ); if ( $echo ) { From e367ba01002b0472bafba9bfb18d8ed8bb8ba7f8 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:28:53 -0500 Subject: [PATCH 06/11] Add new window screen reader text --- ...tyview-plugin-hooks-gravity-forms-advanced-post-creation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index 7753b6e851..a6e6893181 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -101,8 +101,8 @@ public function add_view_notification( $_, string $context, $view_id, bool $echo $apc_feed_link = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&subview=%s&id=%d', $apc->get_slug(), $form->ID ) ); $notification = strtr( $notification, [ - '[/link]' => '', '[link]' => '', + '[/link]' => ' ' . esc_html__( '(This link opens in a new window.)', 'gk-gravityview' ) . '', ] ); if ( $echo ) { From d82efea36f6102cbf84c554f2d2e0314e62a6579 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:29:08 -0500 Subject: [PATCH 07/11] Add message for translators --- ...ew-plugin-hooks-gravity-forms-advanced-post-creation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index a6e6893181..9215e9be23 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -95,11 +95,13 @@ public function add_view_notification( $_, string $context, $view_id, bool $echo $notification = sprintf( $notification_html, - esc_html__( 'Caution: [link]Advanced Post Creation[/link] is active for this form', 'gk-gravityview' ), - __( 'Editing one of these entries might update a connected post as well. ', 'gk-gravityview' ) + // translators: Do not translate [link] and [/link]; they are replaced with an anchor tag. + esc_html__( 'Caution: [link]Advanced Post Creation[/link] is active for this form.', 'gk-gravityview' ), + __( 'Editing entries in GravityView may also update a connected post.', 'gk-gravityview' ) ); $apc_feed_link = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&subview=%s&id=%d', $apc->get_slug(), $form->ID ) ); + $notification = strtr( $notification, [ '[link]' => '', '[/link]' => ' ' . esc_html__( '(This link opens in a new window.)', 'gk-gravityview' ) . '', From 49856374e7ffaa9098810d5606ba497a5f6c13f4 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:32:05 -0500 Subject: [PATCH 08/11] Update docblocks --- ...-hooks-gravity-forms-advanced-post-creation.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index 9215e9be23..c93a007399 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -1,4 +1,16 @@ + * @link http://www.gravitykit.com + * @copyright Copyright 2024, Katz Web Services, Inc. + * + * @since $ver$ + */ use GV\View; @@ -27,7 +39,7 @@ public function update_post_on_entry_edit( array $form, string $entry_id, Gravit return; } - // Todo: disable if setting is not activated in Foudation. + // Todo: disable if setting is not activated in Foundation. $apc = GF_Advanced_Post_Creation::get_instance(); From de8d87b86f24ba175758394a3c55d50262b2a9ab Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:44:02 -0500 Subject: [PATCH 09/11] Sanitize output --- ...tyview-plugin-hooks-gravity-forms-advanced-post-creation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index c93a007399..20cf5545b4 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -109,7 +109,7 @@ public function add_view_notification( $_, string $context, $view_id, bool $echo $notification_html, // translators: Do not translate [link] and [/link]; they are replaced with an anchor tag. esc_html__( 'Caution: [link]Advanced Post Creation[/link] is active for this form.', 'gk-gravityview' ), - __( 'Editing entries in GravityView may also update a connected post.', 'gk-gravityview' ) + esc_html__( 'Editing entries in GravityView may also update a connected post.', 'gk-gravityview' ) ); $apc_feed_link = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&subview=%s&id=%d', $apc->get_slug(), $form->ID ) ); From 474362c2c44bb62d10ad7f9c257c2c0c346ec5a5 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:44:20 -0500 Subject: [PATCH 10/11] Remove TODO See conversation here: https://gravitykit.slack.com/archives/C727B06MB/p1707943384346669 --- ...view-plugin-hooks-gravity-forms-advanced-post-creation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php index 20cf5545b4..99d42e4c97 100644 --- a/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -39,16 +39,16 @@ public function update_post_on_entry_edit( array $form, string $entry_id, Gravit return; } - // Todo: disable if setting is not activated in Foundation. - $apc = GF_Advanced_Post_Creation::get_instance(); $created_posts = gform_get_meta( $entry_id, $apc->get_slug() . '_post_id' ); + if ( ! $created_posts ) { return; } $feeds = $apc->get_active_feeds( rgar( $form, 'id' ) ); + if ( ! $feeds ) { return; } From f61403a8ddb9bbe997333d7700adfd5288b24832 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 14 Feb 2024 15:50:21 -0500 Subject: [PATCH 11/11] Restore readme item [ci skip] Removed erroneously on merge 9c9355c4a --- readme.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.txt b/readme.txt index 8cbeddb148..eb5229be88 100644 --- a/readme.txt +++ b/readme.txt @@ -21,6 +21,11 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h == Changelog == += develop = + +* Added: Support for the [Advanced Post Creation Add-On](https://www.gravityforms.com/add-ons/advanced-post-creation/) when editing entries in GravityView's Edit Entry mode + + = 2.19.6 on February 7, 2024 = This update introduces the ability to send notifications using Gravity Forms when an entry is deleted, improves sorting and survey field ratings, and updates key components for better performance and compatibility.