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

Fixed imagify pricing modal layout issue #924

Merged
merged 18 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"dangoodman/composer-for-wordpress": true,
"mnsami/composer-custom-directory-installer": true
"mnsami/composer-custom-directory-installer": true,
"phpstan/extension-installer": true
}
},
"support": {
Expand Down
1 change: 1 addition & 0 deletions inc/3rd-party/3rd-party.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require IMAGIFY_PATH . 'inc/3rd-party/wp-rocket/wp-rocket.php';
require IMAGIFY_PATH . 'inc/3rd-party/yoast-seo.php';
require IMAGIFY_PATH . 'inc/3rd-party/WooCommerce/class-woocommerce.php';
require IMAGIFY_PATH . 'inc/3rd-party/gravity-forms.php';

/**
* Hosting.
Expand Down
52 changes: 52 additions & 0 deletions inc/3rd-party/gravity-forms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

/**
* Check if gravity form is active and no-conflict mode is enabled,
* and you're in gravity form page.
*/
if ( is_plugin_active( 'gravityforms/gravityforms.php' )
&& class_exists( 'GFCommon' )
&& get_option( 'gform_enable_noconflict', false )
&& GFForms::is_gravity_page()
) {
add_filter( 'gform_noconflict_styles', 'imagify_gf_noconflict_styles' );
add_filter( 'gform_noconflict_scripts', 'imagify_gf_noconflict_scripts' );
}

/**
* Register imagify styles to gravity forms conflict styles
*
* @param array $styles Array fo registered styles.
*
* @return array
*/
function imagify_gf_noconflict_styles( $styles ) {
$styles[] = 'imagify-admin-bar';
$styles[] = 'imagify-admin';
$styles[] = 'imagify-notices';
$styles[] = 'imagify-pricing-modal';

return $styles;
}

/**
* Register Imagify scripts to gravity forms conflict scripts
*
* @param array $scripts Array fo registered scripts.
*
* @return array
*/
function imagify_gf_noconflict_scripts( $scripts ) {
$scripts[] = 'imagify-admin-bar';
$scripts[] = 'imagify-sweetalert';
$scripts[] = 'imagify-admin';
$scripts[] = 'imagify-notices';
$scripts[] = 'imagify-pricing-modal';

return $scripts;
}
64 changes: 58 additions & 6 deletions inc/classes/class-imagify-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
*/
protected static $_instance;

/**
* Imagify admin bar menu.
*
* @var bool
*/
private $admin_menu_is_present = false;


/** ----------------------------------------------------------------------------------------- */
/** INSTANCE/INIT =========================================================================== */
Expand Down Expand Up @@ -127,6 +134,7 @@
// JS templates in footer.
add_action( 'admin_print_footer_scripts', [ $this, 'print_js_templates' ] );
add_action( 'admin_footer', [ $this, 'print_modal_payment' ] );
add_action( 'wp_before_admin_bar_render', [ $this, 'maybe_print_modal_payment' ] );
}


Expand Down Expand Up @@ -634,16 +642,60 @@
}
}

/**
* Check if menu is present
*
* @return bool
*/
private function admin_menu_is_present(): bool {

Check warning on line 650 in inc/classes/class-imagify-views.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/classes/class-imagify-views.php#L650

Avoid unused private methods such as 'admin_menu_is_present'.
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
global $wp_admin_bar;

$imagify_menu_id = 'imagify';

return $wp_admin_bar && $wp_admin_bar->get_node( $imagify_menu_id );
}

/**
* Get imagify user info
*
* @return bool
*/
private function get_user_info(): bool {
$user = new User();
$unconsumed_quota = $user->get_percent_unconsumed_quota();

return ( ! $user->is_infinite() && $unconsumed_quota <= 20 )
|| ( $user->is_free() && $unconsumed_quota > 20 );
}

/**
* Start print the payment modal process.
*/
public function maybe_print_modal_payment() {
if ( $this->get_user_info() ) {
global $wp_admin_bar;
$this->admin_menu_is_present = $wp_admin_bar && $wp_admin_bar->get_node( 'imagify' );

return;
}

$this->admin_menu_is_present = false;
}

/**
* Print the payment modal.
*
* @return void
*/
public function print_modal_payment() {
$this->print_template(
'modal-payment',
[
'attachments_number' => $this->get_attachments_number_modal(),
]
);
if ( is_admin_bar_showing() && $this->admin_menu_is_present ) {
$this->print_template(
'modal-payment',
[
'attachments_number' => $this->get_attachments_number_modal(),
]
);
}
}

/**
Expand Down
Loading