' . 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'] ) ) { ?>


' . "\n\n"; } if ( ! empty( $value['id'] ) ) { /** * Trigger Action. * * Note: action dynamically fire on basis of field id. * * @since 1.8 */ do_action( 'give_settings_' . sanitize_title( $value['id'] ) ); } break; // Section Ends. case 'sectionend': if ( ! empty( $value['id'] ) ) { /** * Trigger Action. * * Note: action dynamically fire on basis of field id. * * @since 1.8 */ do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_end' ); } if ( $value['table_html'] ) { echo ''; } if ( ! empty( $value['id'] ) ) { /** * Trigger Action. * * Note: action dynamically fire on basis of field id. * * @since 1.8 */ do_action( 'give_settings_' . sanitize_title( $value['id'] ) . '_after' ); } break; // Standard text inputs and subtypes like 'number'. case 'colorpicker': case 'hidden' : $value['wrapper_class'] = empty( $value['wrapper_class'] ) ? 'give-hidden' : trim( $value['wrapper_class'] ) . ' give-hidden'; case 'text': case 'email': case 'number': case 'password' : $type = $value['type']; $option_value = self::get_option( $option_name, $value['id'], $value['default'] ); // Set default value for repeater field if not any value set yet. if ( $value['repeat'] && is_string( $option_value ) ) { $option_value = array( $value['default'] ); } ?> > $field_value ) : ?>

/> -

/> 10, 'cols' => 60 ); $textarea_attributes = isset( $value['attributes'] ) ? $value['attributes'] : array(); ?> > > >
> /> >
>
> > > > /> 0 ) ? array_merge( $value['options'], $option_value ) : $value['options']; ?> > > ' . wp_kses_post( $value ) . ''; } return $description; } /** * Helper function to get the formated title. * Plugins can call this when implementing their own custom settings types. * * @since 1.8 * * @param array $value The form field value array * * @return array The description and tip as a 2 element array */ public static function get_field_title( $value ) { $title = esc_html( $value['title'] ); // If html tag detected then allow them to print. if ( strip_tags( $title ) ) { $title = $value['title']; } return $title; } /** * Save admin fields. * * Loops though the give options array and outputs each field. * * @since 1.8 * * @param array $options Options array to output * @param string $option_name Option name to save output. If empty then option will be store in there own option name i.e option id. * * @return bool */ public static function save_fields( $options, $option_name = '' ) { if ( empty( $_POST ) ) { return false; } // Options to update will be stored here and saved later. $update_options = array(); // Loop options and get values to save. foreach ( $options as $option ) { if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) { continue; } // Get posted value. if ( strstr( $option['id'], '[' ) ) { parse_str( $option['id'], $option_name_array ); $field_option_name = current( array_keys( $option_name_array ) ); $setting_name = key( $option_name_array[ $field_option_name ] ); $raw_value = isset( $_POST[ $field_option_name ][ $setting_name ] ) ? wp_unslash( $_POST[ $field_option_name ][ $setting_name ] ) : null; } else { $field_option_name = $option['id']; $setting_name = ''; $raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null; } // Format the value based on option type. switch ( $option['type'] ) { case 'checkbox' : $value = is_null( $raw_value ) ? '' : 'on'; break; case 'wysiwyg' : case 'textarea' : $value = wp_kses_post( trim( $raw_value ) ); break; case 'multiselect' : case 'chosen' : $value = array_filter( array_map( 'give_clean', (array) $raw_value ) ); break; default : $value = give_clean( $raw_value ); break; } /** * Sanitize the value of an option. * * @since 1.8 */ $value = apply_filters( 'give_admin_settings_sanitize_option', $value, $option, $raw_value ); /** * Sanitize the value of an option by option name. * * @since 1.8 */ $value = apply_filters( "give_admin_settings_sanitize_option_{$field_option_name}", $value, $option, $raw_value ); if ( is_null( $value ) ) { continue; } // Check if option is an array and handle that differently to single values. if ( $field_option_name && $setting_name ) { if ( ! isset( $update_options[ $field_option_name ] ) ) { $update_options[ $field_option_name ] = get_option( $field_option_name, array() ); } if ( ! is_array( $update_options[ $field_option_name ] ) ) { $update_options[ $field_option_name ] = array(); } $update_options[ $field_option_name ][ $setting_name ] = $value; } else { $update_options[ $field_option_name ] = $value; } } // Save all options in our array or there own option name i.e. option id. if ( empty( $option_name ) ) { foreach ( $update_options as $name => $value ) { update_option( $name, $value, false ); /** * Trigger action. * * Note: This is dynamically fire on basis of option name. * * @since 1.8 */ do_action( "give_save_option_{$name}", $value, $name ); } } else { $old_options = ( $old_options = get_option( $option_name ) ) ? $old_options : array(); $update_options = array_merge( $old_options, $update_options ); update_option( $option_name, $update_options, false ); /** * Trigger action. * * Note: This is dynamically fire on basis of setting name. * * @since 1.8 */ do_action( "give_save_settings_{$option_name}", $update_options, $option_name, $old_options ); } return true; } /** * Check if admin saving setting or not. * * @since 1.8.17 * * @return bool */ public static function is_saving_settings() { return self::verify_nonce(); } /** * Verify setting page * * @since 2.0 * @access public * * @param string $tab * @param string $section * * @return bool */ public static function is_setting_page( $tab = '', $section = '' ) { $is_setting_page = false; if( ! is_admin() ) { return $is_setting_page; } // Check fo setting tab. if ( ! empty( $tab ) ) { $is_setting_page = ( $tab === give_get_current_setting_tab() ); } // Check fo setting section. if ( ! empty( $section ) ) { $is_setting_page = ( $section === give_get_current_setting_section() ); } return $is_setting_page; } } endif;