diff --git a/src/Controller/Controller_Actions.php b/src/Controller/Controller_Actions.php index 37a10f53c..0fdc4863f 100644 --- a/src/Controller/Controller_Actions.php +++ b/src/Controller/Controller_Actions.php @@ -151,10 +151,17 @@ public function get_routes() { */ public function route_notices() { + global $pagenow; /* Prevent actions being displayed on our welcome pages */ - if ( ! is_admin() || - ( rgget( 'page' ) === 'gfpdf-getting-started' ) || ( rgget( 'page' ) === 'gfpdf-update' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) - ) { + $register_routes = false; + $is_gfpdf_page = \GPDFAPI::get_misc_class()->is_gfpdf_page(); + $is_gf_page = \GFForms::is_gravity_page(); + + if ( ! wp_doing_ajax() && is_admin() && ( $pagenow === 'plugins.php' || $is_gfpdf_page || $is_gf_page ) ) { + $register_routes = true; + } + + if ( ! $register_routes ) { return null; } @@ -173,8 +180,20 @@ public function route_notices() { ] ); - $class = ( isset( $route['view_class'] ) ) ? $route['view_class'] : ''; - $this->notices->add_notice( call_user_func( $route['view'], $route['action'], $route['action_text'] ), $class ); + $message = call_user_func( $route['view'], $route['action'], $route['action_text'] ); + /* Lets load the Install Core font message to Helper_Notice if the current page belongs to Gravity PDF or the plugin directory. */ + if ( $is_gfpdf_page || $pagenow === 'plugins.php' ) { + $class = ( isset( $route['view_class'] ) ) ? $route['view_class'] : ''; + $this->notices->add_notice( $message, $class ); + + } else { + /* Add Install Core font message GFCommon if it doesn't. Remove the font styling to match with the generic add-on error message. */ + if ( ! empty( \GFCommon::$errors ) ) { + $message = sprintf( '
%s
', $message ); + } + \GFCommon::add_error_message( $message ); + + } } } } diff --git a/tests/phpunit/unit-tests/test-actions.php b/tests/phpunit/unit-tests/test-actions.php index 442e14b17..711beeed6 100644 --- a/tests/phpunit/unit-tests/test-actions.php +++ b/tests/phpunit/unit-tests/test-actions.php @@ -138,6 +138,8 @@ function( $routes ) { $user_id = $this->factory->user->create( [ 'role' => 'administrator' ] ); $this->assertIsInt( $user_id ); wp_set_current_user( $user_id ); + /* Check if Helper_Notice class will trigger on GravityPDF page */ + $_GET['subview'] = 'PDF'; /* Verify notice now present */ $this->controller->route_notices(); @@ -147,6 +149,16 @@ function( $routes ) { /* Cleanup notices */ $gfpdf->notices->clear(); + unset( $_GET['subview'] ); + + /* Check if GFCommon class will trigger on Gravity page */ + $_GET['page'] = 'gf_edit_forms'; + + /* Verify notice now present */ + $this->controller->route_notices(); + + /* Verify GravityForm's default error messages now exists */ + $this->assertNotEmpty( \GFCommon::$errors ); /* Check routes aren't handled when not in admin area */ set_current_screen( 'front' );