Skip to content

Commit

Permalink
WIP - Exclude GravityPDF Install font message to Gravity PDF pages only.
Browse files Browse the repository at this point in the history
Add Gravity Form's default error message handler. This will add the message to the current gform_admin_error_messages queue

Rewrite maybe_remove_non_pdf_messages to return false if the current page doesn't belongs to gravity pdf. Add toggle between Helper_Notices and GFCommon on we display the font install message.

Update condition and improve codebase

Update unit test for Test_Action

Revert changes on Helper_Notices

Update Install font notice display, codebase cleanup.

Lint
  • Loading branch information
jestonihpi committed Feb 24, 2023
1 parent f9649f0 commit 172cd15
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/Controller/Controller_Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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( '<div>%s</div>', $message );
}
\GFCommon::add_error_message( $message );

}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/unit-tests/test-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' );
Expand Down

0 comments on commit 172cd15

Please sign in to comment.