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/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 new file mode 100644 index 0000000000..99d42e4c97 --- /dev/null +++ b/includes/plugin-and-theme-hooks/class-gravityview-plugin-hooks-gravity-forms-advanced-post-creation.php @@ -0,0 +1,141 @@ + + * @link http://www.gravitykit.com + * @copyright Copyright 2024, Katz Web Services, Inc. + * + * @since $ver$ + */ + +use GV\View; + +/** + * Add Gravity Forms Advanced Post Creation compatibility. + * @since $ver$ + * @link https://www.gravityforms.com/add-ons/advanced-post-creation/ + */ +final class GravityView_Plugin_Hooks_Gravity_Forms_Advanced_Post_Creation extends GravityView_Plugin_and_Theme_Hooks { + /** + * @inheritDoc + * @since $ver$ + */ + protected $class_name = 'GF_Advanced_Post_Creation'; + + /** + * Updates the connected post. + * @since $ver$ + * + * @param array $form Gravity Forms form array. + * @param string $entry_id Numeric ID of the entry that was updated. + * @param GravityView_Edit_Entry_Render $render The entry renderer. + */ + public function update_post_on_entry_edit( array $form, string $entry_id, GravityView_Edit_Entry_Render $render ): void { + if ( ! $form || ! $entry_id ) { + return; + } + + $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; + } + + // 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 ); + } + } + + /** + * Adds a notice if the form contains a feed for Advanced Post Creation. + * @since $ver$ + * + * @param mixed $_ unused template name. + * @param string $context The context. + * @param int|string $view_id The view post ID. + * @param bool $echo Whether to print the HTML directly instead of returning. + * + * @return string|null The output. + */ + public function add_view_notification( $_, string $context, $view_id, bool $echo = false ): ?string { + if ( 'edit' !== $context ) { + return null; + } + + $view = View::by_id( $view_id ); + if ( ! $view ) { + return null; + } + + $form = $view->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, + // 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' ), + 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 ) ); + + $notification = strtr( $notification, [ + '[link]' => '', + '[/link]' => ' ' . esc_html__( '(This link opens in a new window.)', 'gk-gravityview' ) . '', + ] ); + + if ( $echo ) { + echo $notification; + } + + return $notification; + } + + /** + * @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 ); + add_action( 'gravityview_render_directory_active_areas', [ $this, 'add_view_notification' ], 5, 4 ); + } +} + +new GravityView_Plugin_Hooks_Gravity_Forms_Advanced_Post_Creation; 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.