| 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( |
| 40 |
'admin_init', |
| 41 |
function () { |
| 42 |
self::fix_addon_hooks(); |
| 43 |
} |
| 44 |
); |
| 45 |
|
| 46 |
if ( class_exists( 'FrmTransHooksController', false ) ) { |
| 47 |
add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' ); |
| 48 |
|
| 49 |
// Exit early, let the Payments submodule handle everything. |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
// Actions. |
| 54 |
add_action( 'admin_menu', 'FrmTransLitePaymentsController::menu', 25 ); |
| 55 |
add_action( 'admin_head', 'FrmTransLiteListsController::add_list_hooks' ); |
| 56 |
add_action( 'frm_show_entry_sidebar', 'FrmTransLiteEntriesController::sidebar_list', 9 ); |
| 57 |
add_action( 'frm_after_install', 'FrmTransLiteAppController::on_after_install' ); |
| 58 |
|
| 59 |
// Filters. |
| 60 |
add_filter( 'set-screen-option', 'FrmTransLiteListsController::save_per_page', 10, 3 ); |
| 61 |
|
| 62 |
// Use 9 to run before the Stripe Lite and Square Lite code. |
| 63 |
add_filter( 'frm_before_save_payment_action', 'FrmTransLiteActionsController::before_save_settings', 9, 2 ); |
| 64 |
|
| 65 |
if ( defined( 'DOING_AJAX' ) ) { |
| 66 |
self::load_ajax_hooks(); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* @return void |
| 72 |
*/ |
| 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' ); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Make sure that Payments appear when there are inbox items for all Payments plugins. |
| 80 |
* |
| 81 |
* @since 6.17.1 |
| 82 |
* |
| 83 |
* @return void |
| 84 |
*/ |
| 85 |
private static function fix_addon_hooks() { |
| 86 |
$unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); |
| 87 |
|
| 88 |
if ( ! $unread_count ) { |
| 89 |
// Nothing to fix. |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
$menu_name = FrmAppHelper::get_menu_name(); |
| 94 |
$hook_name = 'manage_' . sanitize_title( $menu_name ) . '-' . $unread_count . '_page_formidable-payments_columns'; |
| 95 |
|
| 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 ); |
| 107 |
} |
| 108 |
} |
| 109 |
|