Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Core Font Installer Notice to selected pages. #1445

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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