| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class FrmTransLiteHooksController { |
| 7 |
|
| 8 |
/** |
| 9 |
* @return void |
| 10 |
*/ |
| 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. |
| 15 |
if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// Actions. |
| 20 |
add_action( 'frm_payment_cron', 'FrmTransLiteAppController::run_payment_cron' ); |
| 21 |
add_filter( 'frm_registered_form_actions', 'FrmTransLiteActionsController::register_actions' ); |
| 22 |
add_action( 'frm_add_form_option_section', 'FrmTransLiteActionsController::actions_js' ); |
| 23 |
add_action( 'frm_trigger_payment_action', 'FrmTransLiteActionsController::trigger_action', 10, 3 ); |
| 24 |
|
| 25 |
// Filters. |
| 26 |
add_filter( 'frm_action_triggers', 'FrmTransLiteActionsController::add_payment_trigger' ); |
| 27 |
add_filter( 'frm_email_action_options', 'FrmTransLiteActionsController::add_trigger_to_action' ); |
| 28 |
add_filter( 'frm_twilio_action_options', 'FrmTransLiteActionsController::add_trigger_to_action' ); |
| 29 |
add_filter( 'frm_mailchimp_action_options', 'FrmTransLiteActionsController::add_trigger_to_action' ); |
| 30 |
add_filter( 'frm_api_action_options', 'FrmTransLiteActionsController::add_trigger_to_action' ); |
| 31 |
add_filter( 'frm_setup_new_fields_vars', 'FrmTransLiteActionsController::hide_gateway_field_on_front_end', 20, 2 ); |
| 32 |
add_filter( 'frm_setup_edit_fields_vars', 'FrmTransLiteActionsController::hide_gateway_field_on_front_end', 20, 2 ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public static function load_admin_hooks() { |
| 39 |
add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron', 10, 2 ); |
| 40 |
|
| 41 |
if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 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. |
| 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' ) ); |
| 74 |
} |
| 75 |
|
| 76 |
// Actions. |
| 77 |
add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); |
| 78 |
add_action( 'admin_head', 'FrmTransLiteListsController::add_list_hooks' ); |
| 79 |
add_action( 'frm_show_entry_sidebar', 'FrmTransLiteEntriesController::sidebar_list', 9 ); |
| 80 |
add_action( 'frm_after_install', 'FrmTransLiteAppController::on_after_install' ); |
| 81 |
|
| 82 |
// Filters. |
| 83 |
add_filter( 'set-screen-option', 'FrmTransLiteListsController::save_per_page', 10, 3 ); |
| 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 |
|
| 88 |
if ( defined( 'DOING_AJAX' ) ) { |
| 89 |
self::load_ajax_hooks(); |
| 90 |
} |
| 91 |
} |
| 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 |
*/ |
| 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' ); |
| 138 |
} |
| 139 |
} |
| 140 |
|