' . esc_attr__( 'Action failed. Please refresh the page and retry.', 'give' ) . '
'; die(); } /** * Trigger Action. * * Note: action dynamically fire on basis of setting page slug and current tab. * For example: if you register a setting page with give-settings menu slug and general current tab name * then action will be give-settings_save_general * * @since 1.8 */ do_action( self::$setting_filter_prefix . '_save_' . $current_tab ); self::add_message( 'give-setting-updated', __( 'Your settings have been saved.', 'give' ) ); /** * Trigger Action. * * Note: action dynamically fire on basis of setting page slug. * For example: if you register a setting page with give-settings menu slug * then action will be give-settings_saved * * @since 1.8 */ do_action( self::$setting_filter_prefix . '_saved' ); } /** * Add a message. * * @since 1.8 * * @param string $code Message code (Note: This should be unique). * @param string $message Message text. * * @return void */ public static function add_message( $code, $message ) { self::$messages[ $code ] = $message; } /** * Add an error. * * @since 1.8 * * @param string $code Message code (Note: This should be unique). * @param string $message Message text. * * @return void */ public static function add_error( $code, $message ) { self::$errors[ $code ] = $message; } /** * Output messages + errors. * * @since 1.8 * @return void */ public static function show_messages() { $notice_html = ''; $classes = 'give-notice settings-error notice is-dismissible'; self::$errors = apply_filters( self::$setting_filter_prefix . '_error_notices', self::$errors ); self::$messages = apply_filters( self::$setting_filter_prefix . '_update_notices', self::$messages ); if ( 0 < count( self::$errors ) ) { foreach ( self::$errors as $code => $message ) { $notice_html .= sprintf( '', $code, $classes, $message ); } } if ( 0 < count( self::$messages ) ) { foreach ( self::$messages as $code => $message ) { $notice_html .= sprintf( '', $code, $classes, $message ); } } echo $notice_html; } /** * Settings page. * * Handles the display of the main give settings page in admin. * * @since 1.8 * @return bool */ public static function output() { // Get current setting page. self::$setting_filter_prefix = give_get_current_setting_page(); // Bailout: Exit if setting page is not defined. if ( empty( self::$setting_filter_prefix ) ) { return false; } /** * Trigger Action. * * Note: action dynamically fire on basis of setting page slug * For example: if you register a setting page with give-settings menu slug * then action will be give-settings_start * * @since 1.8 */ do_action( self::$setting_filter_prefix . '_start' ); $current_tab = give_get_current_setting_tab(); // Include settings pages. $all_setting = self::get_settings_pages(); /* @var object $current_setting_obj */ $current_setting_obj = new StdClass; foreach ( $all_setting as $setting ) { if ( method_exists( $setting, 'get_id' ) && $current_tab === $setting->get_id() ) { $current_setting_obj = $setting; break; } } // Save settings if data has been posted. if ( isset( $_POST['_give-save-settings'] ) ) { self::save(); } /** * Filter the tabs for current setting page. * * Note: filter dynamically fire on basis of setting page slug. * For example: if you register a setting page with give-settings menu slug and general current tab name * then action will be give-settings_tabs_array * * @since 1.8 */ $tabs = apply_filters( self::$setting_filter_prefix . '_tabs_array', array() ); include 'views/html-admin-settings.php'; return true; } /** * Get a setting from the settings API. * * @since 1.8 * * @param string $option_name Option Name. * @param string $field_id Field ID. * @param mixed $default Default. * * @return string|bool */ public static function get_option( $option_name = '', $field_id = '', $default = false ) { // Bailout. if ( empty( $option_name ) && empty( $field_id ) ) { return false; } if ( ! empty( $field_id ) && ! empty( $option_name ) ) { // Get field value if any. $option_value = get_option( $option_name ); $option_value = ( is_array( $option_value ) && array_key_exists( $field_id, $option_value ) ) ? $option_value[ $field_id ] : $default; } else { // If option name is empty but not field name then this means, setting is direct store to option table under there field name. $option_name = ! $option_name ? $field_id : $option_name; // Get option value if any. $option_value = get_option( $option_name, $default ); } /** * Filter the option value * * @since 2.2.3 * * @param mixed $option_value * @param string $option_name * @param string $field_id * @param mixed $default */ return apply_filters( 'give_admin_field_get_value', $option_value, $option_name, $field_id, $default ); } /** * Output admin fields. * * Loops though the give options array and outputs each field. * * @todo : Refactor this function * @since 1.8 * * @param array $options Opens array to output. * @param string $option_name Opens array to output. * * @return void */ public static function output_fields( $options, $option_name = '' ) { $current_tab = give_get_current_setting_tab(); // Field Default values. $defaults = array( 'id' => '', 'class' => '', 'css' => '', 'default' => '', 'desc' => '', 'table_html' => true, 'repeat' => false, 'repeat_btn_title' => __( 'Add Field', 'give' ), ); foreach ( $options as $value ) { if ( ! isset( $value['type'] ) ) { continue; } // Set title. $defaults['title'] = isset( $value['name'] ) ? $value['name'] : ''; // Set default setting. $value = wp_parse_args( $value, $defaults ); // Colorpicker field. $value['class'] = ( 'colorpicker' === $value['type'] ? trim( $value['class'] ) . ' give-colorpicker' : $value['class'] ); $value['type'] = ( 'colorpicker' === $value['type'] ? 'text' : $value['type'] ); // Custom attribute handling. $custom_attributes = array(); if ( ! empty( $value['attributes'] ) && is_array( $value['attributes'] ) ) { foreach ( $value['attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; } } // Description handling. $description = self::get_field_description( $value ); // Switch based on type. switch ( $value['type'] ) { // Section Titles. case 'title': if ( ! empty( $value['title'] ) || ! empty( $value['desc'] ) ) { ?>/> -
/>