partials
1 month ago
class-strong-testimonials-forms.php
1 month ago
class-strong-testimonials-general-settings-react.php
6 days ago
class-strong-testimonials-settings-form.php
1 month ago
class-strong-testimonials-forms.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class Strong_Testimonials_Settings |
| 4 | */ |
| 5 | class Strong_Testimonials_Forms { |
| 6 | |
| 7 | const DEFAULT_TAB = 'fields'; |
| 8 | |
| 9 | public static $callbacks; |
| 10 | |
| 11 | /** |
| 12 | * Strong_Testimonials_Settings constructor. |
| 13 | */ |
| 14 | public function __construct() {} |
| 15 | |
| 16 | /** |
| 17 | * Initialize. |
| 18 | */ |
| 19 | public static function init() { |
| 20 | self::add_actions(); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Add actions and filters. |
| 25 | */ |
| 26 | public static function add_actions() { |
| 27 | add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Register settings |
| 32 | */ |
| 33 | public static function register_settings() { |
| 34 | self::$callbacks = apply_filters( 'wpmtst_form_callbacks', array() ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Settings page |
| 39 | */ |
| 40 | public static function settings_page() { |
| 41 | if ( ! current_user_can( 'strong_testimonials_options' ) ) { |
| 42 | wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'strong-testimonials' ) ); |
| 43 | } |
| 44 | $tab = self::get_tab(); |
| 45 | $url = admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-fields' ); |
| 46 | |
| 47 | if ( isset( $_GET['settings-updated'] ) ) { |
| 48 | $notice = array( |
| 49 | 'title' => esc_html__( 'Settings saved', 'strong-testimonials' ), |
| 50 | 'message' => esc_html__( 'Form settings successfully saved.', 'strong-testimonials' ), |
| 51 | 'status' => 'success', |
| 52 | 'source' => array( |
| 53 | 'slug' => 'strong-testimonials', |
| 54 | 'name' => 'Strong Testimonials', |
| 55 | ), |
| 56 | 'timed' => 5000, |
| 57 | 'dismiss' => true, |
| 58 | ); |
| 59 | |
| 60 | WPChill_Notifications::add_notification( 'wpmtst-form-settings-saved', $notice ); |
| 61 | } |
| 62 | ?> |
| 63 | <div class="wrap wpmtst"> |
| 64 | |
| 65 | <h1><?php echo wp_kses_post( apply_filters( 'wpmtst_cpt_singular_name', esc_html__( 'Form', 'strong-testimonials' ) ) ); ?></h1> |
| 66 | <?php do_action( 'wpmtst_testimonials_settings' ); ?> |
| 67 | <h2 class="nav-tab-wrapper"> |
| 68 | <?php do_action( 'wpmtst_form_tabs', $tab, $url ); ?> |
| 69 | </h2> |
| 70 | <?php if ( 'fields' !== $tab ) : ?> |
| 71 | <div class="wpmts-settings-columns"> |
| 72 | <form id="<?php echo esc_attr( $tab ); ?>-form" method="post" action="options.php" enctype="multipart/form-data"> |
| 73 | <?php |
| 74 | if ( isset( self::$callbacks[ $tab ] ) && wpmtst_callback_exists( self::$callbacks[ $tab ] ) ) { |
| 75 | call_user_func( self::$callbacks[ $tab ] ); |
| 76 | } else { |
| 77 | call_user_func( self::$callbacks[ self::DEFAULT_TAB ] ); |
| 78 | } |
| 79 | |
| 80 | echo '<p class="submit-buttons">'; |
| 81 | submit_button( '', 'primary', 'submit-form', false ); |
| 82 | echo '</p>'; |
| 83 | ?> |
| 84 | </form> |
| 85 | <?php do_action( 'wpmtst_admin_after_settings_form' ); ?> |
| 86 | </div> |
| 87 | <?php |
| 88 | else : |
| 89 | if ( isset( self::$callbacks[ $tab ] ) && wpmtst_callback_exists( self::$callbacks[ $tab ] ) ) { |
| 90 | call_user_func( self::$callbacks[ $tab ] ); |
| 91 | } else { |
| 92 | call_user_func( self::$callbacks[ self::DEFAULT_TAB ] ); |
| 93 | } |
| 94 | endif; |
| 95 | ?> |
| 96 | |
| 97 | </div><!-- .wrap --> |
| 98 | <?php |
| 99 | } |
| 100 | |
| 101 | private static function get_tab() { |
| 102 | return ( isset( $_GET['tab'] ) && sanitize_text_field( wp_unslash( $_GET['tab'] ) ) ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : self::DEFAULT_TAB; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | Strong_Testimonials_Forms::init(); |
| 107 |