Skip to content

Start working on new payments global section #2400

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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
61 changes: 61 additions & 0 deletions classes/controllers/FrmSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

class FrmSettingsController {

/**
* @since x.x
*
* @var array
*/
private static $removed_payments_sections = array();

public static function menu() {
// Make sure admins can see the menu items
FrmAppHelper::force_capability( 'frm_change_settings' );
Expand Down Expand Up @@ -63,6 +70,12 @@ private static function get_settings_tabs() {
'name' => __( 'Permissions', 'formidable' ),
'icon' => 'frm_icon_font frm_lock_icon',
),
'payments' => array(
'name' => __( 'Payments', 'formidable' ),
'icon' => 'frm_icon_font frm_simple_cc_icon',
'class' => __CLASS__,
'function' => 'payments_settings',
),
'custom_css' => array(
'class' => 'FrmStylesController',
'function' => 'custom_css',
Expand Down Expand Up @@ -129,6 +142,7 @@ private static function get_settings_tabs() {
* @param array<array> $sections
*/
$sections = apply_filters( 'frm_add_settings_section', $sections );
self::remove_payments_sections( $sections );

$sections['misc'] = array(
'name' => __( 'Miscellaneous', 'formidable' ),
Expand Down Expand Up @@ -164,6 +178,47 @@ private static function get_settings_tabs() {
return $sections;
}

/**
* Remove the payments sections (PayPal, Square, Stripe, Authorize.Net)
* and show them all on the payments section in separate tabs.
*
* @since x.x
*
* @param array $sections
* @return void
*/
private static function remove_payments_sections( &$sections ) {
$payment_section_keys = array( 'paypal', 'square', 'stripe', 'authorize_net' );

foreach ( $sections as $key => $section ) {
if ( in_array( $key, $payment_section_keys, true ) ) {
self::$removed_payments_sections[ $key ] = $section;
unset( $sections[ $key ] );
}
}

uksort( self::$removed_payments_sections, array( __CLASS__, 'payment_sections_sort_callback' ) );
}

/**
* Sort the payments sections (PayPal, Square, Stripe, Authorize.Net)
*
* @since x.x
*
* @param string $a
* @param string $b
* @return int
*/
private static function payment_sections_sort_callback( $a, $b ) {
$order = array( 'stripe', 'square', 'paypal', 'authorize_net' );
$first_key = array_search( $a, $order );
$second_key = array_search( $b, $order );
if ( false === $first_key || false === $second_key ) {
return 0;
}
return $first_key - $second_key;
}

public static function load_settings_tab() {
FrmAppHelper::permission_check( 'frm_change_settings' );
check_ajax_referer( 'frm_ajax', 'nonce' );
Expand Down Expand Up @@ -245,6 +300,12 @@ public static function permission_settings() {
include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/permissions.php';
}

public static function payments_settings() {
$payment_sections = self::$removed_payments_sections;

include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/payments.php';
}

/**
* @since 4.0
*/
Expand Down
60 changes: 60 additions & 0 deletions classes/views/frm-settings/payments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}

?>
<p>
<?php esc_html_e( 'Configure and manage your payment gateways in one place to control transactions, settings, and more.', 'formidable' ); ?>
</p>
<?php

echo '<div class="frm-long-icon-buttons" role="tablist">';
$first = true;
foreach ( $payment_sections as $key => $section ) {
$name = isset( $section['name'] ) ? $section['name'] : ucfirst( $key );
$input_params = array(
'id' => "frm_toggle_{$key}_settings",
'type' => 'radio',
'name' => 'frm_payment_section',
'value' => $key,
'data-frmshow' => "#frm_{$key}_settings_section",
);
if ( $first ) {
$input_params['checked'] = 'checked';
}
$other_sections = array_diff( array_keys( $payment_sections ), array( $key ) );
$input_params['data-frmhide'] = implode( ',', array_map( function( $section ) {
return "#frm_{$section}_settings_section";
}, $other_sections ) );
?>
<input <?php echo FrmAppHelper::array_to_html_params( $input_params, true ); ?> />
<label for="frm_toggle_<?php echo esc_attr( $key ); ?>_settings" class="frm_payment_settings_tab" tabindex="0" role="tab" aria-selected="<?php echo $first ? 'true' : 'false'; ?>">
<?php FrmAppHelper::icon_by_class( 'frm_icon_font frm_' . $key . '_full_icon' ); ?>
<span class="screen-reader-text"><?php echo esc_attr( $name ); ?></span>
</label>
<?php
$first = false;
}
echo '</div>';

$first = true;
foreach ( $payment_sections as $key => $section ) {
$name = isset( $section['name'] ) ? $section['name'] : ucfirst( $key );
$include_h3 = 'authorize_net' !== $key; // Exclude Authorize.Net as the h3 tag is added explicitly.
?>
<div id="frm_<?php echo esc_attr( $key ); ?>_settings_section" class="frm_payments_section <?php if ( ! $first ) { echo 'frm_hidden'; } ?>">
<?php if ( $include_h3 ) { ?>
<h3 style="margin-bottom: 0;"><?php echo esc_html( $name ) . ' ' . esc_html__( 'Settings', 'formidable' ); ?></h3>
<?php } ?>
<?php
if ( isset( $section['class'] ) ) {
call_user_func( array( $section['class'], $section['function'] ) );
} else {
call_user_func( ( isset( $section['function'] ) ? $section['function'] : $section ) );
}
?>
</div>
<?php
$first = false;
}
2 changes: 1 addition & 1 deletion css/frm_admin.css

Large diffs are not rendered by default.

Loading