| @@ -8,16 +8,18 @@ | ||
| 8 | 8 | /** |
| 9 | 9 | * @return void |
| 10 | 10 | */ |
| 11 | 11 | public static function load_hooks() { |
| 12 | + add_action( 'frm_add_form_option_section', 'FrmSquareLiteActionsController::actions_js' ); | |
| 13 | + | |
| 14 | + // Exit early, let the Payments submodule handle everything. | |
| 12 | 15 | if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 13 | - // Exit early, let the Payments submodule handle everything. | |
| 14 | 16 | return; |
| 15 | 17 | } |
| 16 | 18 | |
| 17 | 19 | // Actions. |
| 18 | 20 | add_action( 'frm_payment_cron', 'FrmTransLiteAppController::run_payment_cron' ); |
| 19 | - add_action( 'frm_registered_form_actions', 'FrmTransLiteActionsController::register_actions' ); | |
| 21 | + add_filter( 'frm_registered_form_actions', 'FrmTransLiteActionsController::register_actions' ); | |
| 20 | 22 | add_action( 'frm_add_form_option_section', 'FrmTransLiteActionsController::actions_js' ); |
| 21 | 23 | add_action( 'frm_trigger_payment_action', 'FrmTransLiteActionsController::trigger_action', 10, 3 ); |
| 22 | 24 | |
| 23 | 25 | // Filters. |
| @@ -33,11 +35,43 @@ | ||
| 33 | 35 | /** |
| 34 | 36 | * @return void |
| 35 | 37 | */ |
| 36 | 38 | public static function load_admin_hooks() { |
| 39 | + add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron', 10, 2 ); | |
| 40 | + | |
| 37 | 41 | if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 38 | - // Exit early, let the Payments submodule handle everything. | |
| 42 | + add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' ); | |
| 43 | + | |
| 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. | |
| 39 | 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' ) ); | |
| 40 | 74 | } |
| 41 | 75 | |
| 42 | 76 | // Actions. |
| 43 | 77 | add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); |
| @@ -42,17 +76,63 @@ | ||
| 42 | 76 | // Actions. |
| 43 | 77 | add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); |
| 44 | 78 | add_action( 'admin_head', 'FrmTransLiteListsController::add_list_hooks' ); |
| 45 | 79 | add_action( 'frm_show_entry_sidebar', 'FrmTransLiteEntriesController::sidebar_list', 9 ); |
| 80 | + add_action( 'frm_after_install', 'FrmTransLiteAppController::on_after_install' ); | |
| 46 | 81 | |
| 47 | - // Filters | |
| 82 | + // Filters. | |
| 48 | 83 | add_filter( 'set-screen-option', 'FrmTransLiteListsController::save_per_page', 10, 3 ); |
| 49 | 84 | |
| 85 | + // Use 9 to run before the Stripe Lite and Square Lite code. | |
| 86 | + add_filter( 'frm_before_save_payment_action', 'FrmTransLiteActionsController::before_save_settings', 9, 2 ); | |
| 87 | + | |
| 50 | 88 | if ( defined( 'DOING_AJAX' ) ) { |
| 51 | 89 | self::load_ajax_hooks(); |
| 52 | 90 | } |
| 53 | 91 | } |
| 54 | 92 | |
| 93 | + /** | |
| 94 | + * @since 6.31 | |
| 95 | + * | |
| 96 | + * @return bool | |
| 97 | + */ | |
| 98 | + private static function on_form_settings_page() { | |
| 99 | + return 'formidable' === FrmAppHelper::simple_get( 'page' ) && 'settings' === FrmAppHelper::simple_get( 'frm_action' ); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Hide the Collect Payment action if there are no additional gateways enabled (like Authorize.Net). | |
| 104 | + * | |
| 105 | + * @since 6.31 | |
| 106 | + * | |
| 107 | + * @return void | |
| 108 | + */ | |
| 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 | + } | |
| 116 | + | |
| 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. | |
| 125 | + return; | |
| 126 | + } | |
| 127 | + | |
| 128 | + remove_action( 'admin_menu', 'FrmTransPaymentsController::menu', 25 ); | |
| 129 | + add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * @return void | |
| 134 | + */ | |
| 55 | 135 | private static function load_ajax_hooks() { |
| 56 | 136 | add_action( 'wp_ajax_frm_trans_refund', 'FrmTransLitePaymentsController::refund_payment' ); |
| 57 | 137 | add_action( 'wp_ajax_frm_trans_cancel', 'FrmTransLiteSubscriptionsController::cancel_subscription' ); |
| 58 | 138 | } |