diff --git a/future/includes/class-gv-core.php b/future/includes/class-gv-core.php index 8f0584b938..cb25eeea37 100644 --- a/future/includes/class-gv-core.php +++ b/future/includes/class-gv-core.php @@ -133,6 +133,13 @@ private function init() { /** More legacy core. @todo Deprecate */ $this->plugin->include_legacy_core(); + /** Register the gravityview post type upon WordPress core init. */ + require_once $this->plugin->dir( 'future/includes/class-gv-view.php' ); + add_action( 'init', array( '\GV\View', 'register_post_type' ) ); + add_action( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) ); + add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 ); + add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) ); + add_action( 'the_content', array( '\GV\View', 'content' ) ); /** * Stop all further functionality from loading if the WordPress * plugin is incompatible with the current environment. @@ -141,16 +148,10 @@ private function init() { */ if ( ! $this->plugin->is_compatible() ) { $this->log->error( 'GravityView 2.0 is not compatible with this environment. Stopped loading.' ); + return; } - /** Register the gravityview post type upon WordPress core init. */ - require_once $this->plugin->dir( 'future/includes/class-gv-view.php' ); - add_action( 'init', array( '\GV\View', 'register_post_type' ) ); - add_action( 'init', array( '\GV\View', 'add_rewrite_endpoint' ) ); - add_filter( 'map_meta_cap', array( '\GV\View', 'restrict' ), 11, 4 ); - add_action( 'template_redirect', array( '\GV\View', 'template_redirect' ) ); - add_action( 'the_content', array( '\GV\View', 'content' ) ); /** Add rewrite endpoint for single-entry URLs. */ require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' ); diff --git a/future/includes/class-gv-view.php b/future/includes/class-gv-view.php index 0e28bfcc8a..b3c1f8315a 100644 --- a/future/includes/class-gv-view.php +++ b/future/includes/class-gv-view.php @@ -4,6 +4,7 @@ use GravityKit\GravityView\Foundation\Helpers\Arr; use GF_Query; +use GravityView_Compatibility; use GravityView_Cache; /** If this file is called directly, abort. */ @@ -122,12 +123,15 @@ public function __construct() { * @return void */ public static function register_post_type() { - /** Register only once */ if ( post_type_exists( 'gravityview' ) ) { return; } + if ( ! gravityview()->plugin->is_compatible() ) { + GravityView_Compatibility::override_post_pages_when_compatibility_fails(); + } + /** * Make GravityView Views hierarchical by returning TRUE. * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox @@ -193,7 +197,7 @@ public static function register_post_type() { * @param int $view_id The ID of the View currently being requested. `0` for general setting */ 'public' => apply_filters( 'gravityview_direct_access', gravityview()->plugin->is_compatible(), 0 ), - 'show_ui' => gravityview()->plugin->is_compatible(), + 'show_ui' => true, 'show_in_menu' => false, // Menu items are added in \GV\Plugin::add_to_gravitykit_admin_menu() 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, @@ -1512,7 +1516,6 @@ private function run_db_query( GF_Query $query ) { * @return void */ public static function template_redirect() { - $is_csv = get_query_var( 'csv' ); $is_tsv = get_query_var( 'tsv' ); diff --git a/includes/class-gravityview-admin-notices.php b/includes/class-gravityview-admin-notices.php index e1875d3793..4e426cd006 100644 --- a/includes/class-gravityview-admin-notices.php +++ b/includes/class-gravityview-admin-notices.php @@ -163,6 +163,8 @@ public function admin_notice() { * Modify the notices displayed in the admin. * * @since 1.12 + * + * @param array $notices Array of notices to display. */ $notices = apply_filters( 'gravityview/admin/notices', self::$admin_notices ); diff --git a/includes/class-gravityview-compatibility.php b/includes/class-gravityview-compatibility.php index 0aed27067d..9791bf61f9 100644 --- a/includes/class-gravityview-compatibility.php +++ b/includes/class-gravityview-compatibility.php @@ -384,6 +384,68 @@ public static function get_plugin_status( $location = '' ) { return 'inactive'; } + + /** + * Displays a notice on the All Views or New View page when the compatibility requirements for the plugin are not met. + * + * @since 2.19.7 + * + * @return void + */ + public static function override_post_pages_when_compatibility_fails() { + global $pagenow; + + if ( ! in_array( $pagenow, array( 'post.php', 'edit.php', 'post-new.php' ) ) ) { + return; + } + + $display_notices = function ( $hook_data ) { + global $post; + + if ( ! $post instanceof \WP_Post || 'gravityview' !== $post->post_type ) { + return $hook_data; + } + + // We only care about GravityView notices :) + remove_all_actions( 'admin_notices' ); + remove_all_actions( 'network_admin_notices' ); + + new GravityView_Admin_Notices(); + + /** + * Make GravityView notices non-dismissible and display them to all users. + * + * @param array $notices Array of notices to display. + */ + add_filter( 'gravityview/admin/notices', function ( $notices ) { + $compat_notices = GravityView_Compatibility::get_notices(); + + foreach ( $compat_notices as &$notice ) { + unset( $notice['dismiss'] ); // Make sure the notice is always displayed and is not dismissible. + unset( $notice['cap'] ); // Display the notice to everyone. + } + + return array_merge( $notices, $compat_notices ); + } ); + + // Hide the "Screen Options" tab. + add_filter( 'screen_options_show_screen', '__return_false' ); + + // Render the wrapper for the page, which will include the notices. + require_once ABSPATH . 'wp-admin/admin-header.php'; + require_once ABSPATH . 'wp-admin/admin-footer.php'; + + exit; + }; + + add_filter( 'bulk_post_updated_messages', $display_notices ); // Fired on All Views page. + + /** + * Fired on New View and Edit View pages. + * Without this in place, other notices, the Post Title, and the Publish metabox will continue to be displayed. + */ + add_filter( 'replace_editor', $display_notices ); + } } GravityView_Compatibility::getInstance(); diff --git a/readme.txt b/readme.txt index bf50529fe7..6ddb7a7ec3 100644 --- a/readme.txt +++ b/readme.txt @@ -25,6 +25,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h * Added: Global and View-specific settings to control caching of View entries * 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 +* Improved: If Gravity Forms is not installed and/or activated, a notice is displayed to alert user when creating new or listing existing Views * Fixed: Deprecation notice in PHP 8.1+ when displaying a View with file upload fields * Fixed: Fatal error when exporting entries to CSV