| @@ -35,20 +35,43 @@ | ||
| 35 | 35 | /** |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public static function load_admin_hooks() { |
| 39 | - add_action( | |
| 40 | - 'admin_init', | |
| 41 | - function () { | |
| 42 | - self::fix_addon_hooks(); | |
| 43 | - } | |
| 44 | - ); | |
| 39 | + add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron', 10, 2 ); | |
| 45 | 40 | |
| 46 | 41 | if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 47 | 42 | add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' ); |
| 48 | 43 | |
| 49 | - // Exit early, let the Payments submodule handle everything. | |
| 44 | + add_action( 'frm_pay_show_stripe_options', 'FrmStrpLiteActionsController::add_action_options' ); | |
| 45 | + | |
| 46 | + remove_action( 'admin_head', 'FrmTransListsController::add_list_hooks' ); | |
| 47 | + add_action( 'admin_head', 'FrmTransLiteListsController::add_list_hooks' ); | |
| 48 | + | |
| 49 | + self::maybe_set_admin_menu(); | |
| 50 | + | |
| 51 | + add_action( | |
| 52 | + 'init', | |
| 53 | + function () { | |
| 54 | + if ( ! self::on_form_settings_page() ) { | |
| 55 | + return; | |
| 56 | + } | |
| 57 | + | |
| 58 | + $gateways = array_keys( FrmTransLiteAppHelper::get_gateways() ); | |
| 59 | + | |
| 60 | + // If no additional gateways (Like Authorize.Net) are set, hide the Collect Payment action. | |
| 61 | + // Since we have icons for Stripe, Square, and PayPal, we don't need the Collect Payment action. | |
| 62 | + if ( ! array_diff( $gateways, array( 'stripe', 'square', 'paypal' ) ) ) { | |
| 63 | + add_action( 'admin_print_styles', array( self::class, 'hide_collect_payment_action' ) ); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + ); | |
| 67 | + | |
| 68 | + // Exit early, let the Payments submodule handle everything else. | |
| 50 | 69 | return; |
| 70 | + }//end if | |
| 71 | + | |
| 72 | + if ( self::on_form_settings_page() ) { | |
| 73 | + add_action( 'admin_print_styles', array( self::class, 'hide_collect_payment_action' ) ); | |
| 51 | 74 | } |
| 52 | 75 | |
| 53 | 76 | // Actions. |
| 54 | 77 | add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); |
| @@ -67,42 +90,50 @@ | ||
| 67 | 90 | } |
| 68 | 91 | } |
| 69 | 92 | |
| 70 | 93 | /** |
| 71 | - * @return void | |
| 94 | + * @since 6.31 | |
| 95 | + * | |
| 96 | + * @return bool | |
| 72 | 97 | */ |
| 73 | - private static function load_ajax_hooks() { | |
| 74 | - add_action( 'wp_ajax_frm_trans_refund', 'FrmTransLitePaymentsController::refund_payment' ); | |
| 75 | - add_action( 'wp_ajax_frm_trans_cancel', 'FrmTransLiteSubscriptionsController::cancel_subscription' ); | |
| 98 | + private static function on_form_settings_page() { | |
| 99 | + return 'formidable' === FrmAppHelper::simple_get( 'page' ) && 'settings' === FrmAppHelper::simple_get( 'frm_action' ); | |
| 76 | 100 | } |
| 77 | 101 | |
| 78 | 102 | /** |
| 79 | - * Make sure that Payments appear when there are inbox items for all Payments plugins. | |
| 103 | + * Hide the Collect Payment action if there are no additional gateways enabled (like Authorize.Net). | |
| 80 | 104 | * |
| 81 | - * @since 6.17.1 | |
| 105 | + * @since 6.31 | |
| 82 | 106 | * |
| 83 | 107 | * @return void |
| 84 | 108 | */ |
| 85 | - private static function fix_addon_hooks() { | |
| 86 | - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); | |
| 109 | + public static function hide_collect_payment_action() { | |
| 110 | + echo ' | |
| 111 | + <style> | |
| 112 | + li.frm-action:has(.frm_payment_action) { display: none; } | |
| 113 | + </style> | |
| 114 | + '; | |
| 115 | + } | |
| 87 | 116 | |
| 88 | - if ( ! $unread_count ) { | |
| 89 | - // Nothing to fix. | |
| 117 | + /** | |
| 118 | + * @since 6.27 | |
| 119 | + * | |
| 120 | + * @return void | |
| 121 | + */ | |
| 122 | + private static function maybe_set_admin_menu() { | |
| 123 | + if ( in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new', 'bulk_delete' ), true ) ) { | |
| 124 | + // We're still falling back to the Stripe, Authorize.Net, or PayPal add-on to handle these routes. | |
| 90 | 125 | return; |
| 91 | 126 | } |
| 92 | 127 | |
| 93 | - $menu_name = FrmAppHelper::get_menu_name(); | |
| 94 | - $hook_name = 'manage_' . sanitize_title( $menu_name ) . '-' . $unread_count . '_page_formidable-payments_columns'; | |
| 128 | + remove_action( 'admin_menu', 'FrmTransPaymentsController::menu', 25 ); | |
| 129 | + add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); | |
| 130 | + } | |
| 95 | 131 | |
| 96 | - if ( FrmTransLiteAppHelper::should_fallback_to_paypal() && is_callable( 'FrmPaymentsController::payment_columns' ) ) { | |
| 97 | - // Fallback to PayPal add-on. | |
| 98 | - add_filter( $hook_name, 'FrmPaymentsController::payment_columns' ); | |
| 99 | - } elseif ( is_callable( 'FrmTransListsController::payment_columns' ) ) { | |
| 100 | - // Fallback to the Payments submodule. | |
| 101 | - add_filter( $hook_name, 'FrmTransListsController::payment_columns' ); | |
| 102 | - } else { | |
| 103 | - return; | |
| 104 | - } | |
| 105 | - | |
| 106 | - add_filter( 'screen_options_show_screen', 'FrmTransLiteListsController::remove_screen_options', 10, 2 ); | |
| 132 | + /** | |
| 133 | + * @return void | |
| 134 | + */ | |
| 135 | + private static function load_ajax_hooks() { | |
| 136 | + add_action( 'wp_ajax_frm_trans_refund', 'FrmTransLitePaymentsController::refund_payment' ); | |
| 137 | + add_action( 'wp_ajax_frm_trans_cancel', 'FrmTransLiteSubscriptionsController::cancel_subscription' ); | |
| 107 | 138 | } |
| 108 | 139 | } |