key, $this->key ); } /** * Filter CMB2 URL * * Required for CMB2 to properly load CSS/JS. * * @param $url * * @return mixed */ public function give_update_cmb_meta_box_url( $url ) { // Path to Give's CMB return GIVE_PLUGIN_URL . '/includes/libraries/cmb2'; } /** * Retrieve settings tabs * * @since 1.0 * @return array $tabs */ public function give_get_settings_tabs() { $settings = $this->give_settings( null ); $tabs = array(); $tabs['general'] = __( 'General', 'give' ); $tabs['gateways'] = __( 'Payment Gateways', 'give' ); $tabs['display'] = __( 'Display Options', 'give' ); $tabs['emails'] = __( 'Emails', 'give' ); if ( ! empty( $settings['addons']['fields'] ) ) { $tabs['addons'] = __( 'Add-ons', 'give' ); } if ( ! empty( $settings['licenses']['fields'] ) ) { $tabs['licenses'] = __( 'Licenses', 'give' ); } $tabs['advanced'] = __( 'Advanced', 'give' ); $tabs['api'] = __( 'API', 'give' ); $tabs['system_info'] = __( 'System Info', 'give' ); return apply_filters( 'give_settings_tabs', $tabs ); } /** * Admin page markup. Mostly handled by CMB2 * * @since 1.0 */ public function admin_page_display() { $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $this->give_get_settings_tabs() ) ? $_GET['tab'] : 'general'; ?>
%3$s'; } return $form_format; } /** * Define General Settings Metabox and field configurations. * * Filters are provided for each settings section to allow add-ons and other plugins to add their own settings * * @param $active_tab |string active tab settings; null returns full array * * @return array */ public function give_settings( $active_tab ) { $give_settings = array( /** * General Settings */ 'general' => array( 'id' => 'general_settings', 'give_title' => __( 'General Settings', 'give' ), 'show_on' => array( 'key' => 'options-page', 'value' => array( $this->key ), ), 'fields' => apply_filters( 'give_settings_general', array( array( 'name' => __( 'General Settings', 'give' ), 'desc' => '', 'type' => 'give_title', 'id' => 'give_title_general_settings_1', ), array( 'name' => __( 'Success Page', 'give' ), /* translators: %s: [give_receipt] */ 'desc' => sprintf( __( 'The page donors are sent to after completing their donations. The %s shortcode should be on this page.', 'give' ), '[give_receipt]' ),
'id' => 'success_page',
'type' => 'select',
'options' => give_cmb2_get_post_options(
array(
'post_type' => 'page',
'numberposts' => 999,
)
),
),
array(
'name' => __( 'Failed Donation Page', 'give' ),
'desc' => __( 'The page donors are sent to if their donation is cancelled or fails.', 'give' ),
'id' => 'failure_page',
'type' => 'select',
'options' => give_cmb2_get_post_options(
array(
'post_type' => 'page',
'numberposts' => 999,
)
),
),
array(
'name' => __( 'Donation History Page', 'give' ),
/* translators: %s: [donation_history] */
'desc' => sprintf( __( 'The page showing a complete donation history for the current user. The %s shortcode should be on this page.', 'give' ), '[donation_history]' ),
'id' => 'history_page',
'type' => 'select',
'options' => give_cmb2_get_post_options(
array(
'post_type' => 'page',
'numberposts' => 999,
)
),
),
array(
'name' => __( 'Base Country', 'give' ),
'desc' => __( 'The country your site operates from.', 'give' ),
'id' => 'base_country',
'type' => 'select',
'options' => give_get_country_list(),
),
array(
'name' => __( 'Currency Settings', 'give' ),
'desc' => '',
'type' => 'give_title',
'id' => 'give_title_general_settings_2',
),
array(
'name' => __( 'Currency', 'give' ),
'desc' => __( 'The donation currency. Note that some payment gateways have currency restrictions.', 'give' ),
'id' => 'currency',
'type' => 'select',
'options' => give_get_currencies(),
'default' => 'USD',
),
array(
'name' => __( 'Currency Position', 'give' ),
'desc' => __( 'The position of the currency symbol.', 'give' ),
'id' => 'currency_position',
'type' => 'select',
'options' => array(
/* translators: %s: currency symbol */
'before' => sprintf( __( 'Before - %s10', 'give' ), give_currency_symbol( give_get_currency() ) ),
/* translators: %s: currency symbol */
'after' => sprintf( __( 'After - 10%s', 'give' ), give_currency_symbol( give_get_currency() ) ),
),
'default' => 'before',
),
array(
'name' => __( 'Thousands Separator', 'give' ),
'desc' => __( 'The symbol (usually , or .) to separate thousands.', 'give' ),
'id' => 'thousands_separator',
'type' => 'text_small',
'sanitization_cb' => 'give_sanitize_thousand_separator',
'default' => ',',
),
array(
'name' => __( 'Decimal Separator', 'give' ),
'desc' => __( 'The symbol (usually , or .) to separate decimal points.', 'give' ),
'id' => 'decimal_separator',
'type' => 'text_small',
'default' => '.',
),
array(
'name' => __( 'Number of Decimals', 'give' ),
'desc' => __( 'The number of decimal points displayed in amounts.', 'give' ),
'id' => 'number_decimals',
'type' => 'text_small',
'default' => 2,
'sanitization_cb' => 'give_sanitize_number_decimals',
),
)
),
),
/**
* Payment Gateways
*/
'gateways' => array(
'id' => 'payment_gateways',
'give_title' => __( 'Payment Gateways', 'give' ),
'show_on' => array(
'key' => 'options-page',
'value' => array( $this->key ),
),
'fields' => apply_filters(
'give_settings_gateways', array(
array(
'name' => __( 'Gateways Settings', 'give' ),
'desc' => '',
'id' => 'give_title_gateway_settings_1',
'type' => 'give_title',
),
array(
'name' => __( 'Test Mode', 'give' ),
'desc' => __( 'While in test mode no live donations are processed. To fully use test mode, you must have a sandbox (test) account for the payment gateway you are testing.', 'give' ),
'id' => 'test_mode',
'type' => 'checkbox',
),
array(
'name' => __( 'Enabled Gateways', 'give' ),
'desc' => __( 'Enable your payment gateway. Can be ordered by dragging.', 'give' ),
'id' => 'gateways',
'type' => 'enabled_gateways',
),
array(
'name' => __( 'Default Gateway', 'give' ),
'desc' => __( 'The gateway that will be selected by default.', 'give' ),
'id' => 'default_gateway',
'type' => 'default_gateway',
),
array(
'name' => __( 'PayPal Standard', 'give' ),
'desc' => '',
'type' => 'give_title',
'id' => 'give_title_gateway_settings_2',
),
array(
'name' => __( 'PayPal Email', 'give' ),
'desc' => __( 'Enter your PayPal account\'s email.', 'give' ),
'id' => 'paypal_email',
'type' => 'text_email',
),
array(
'name' => __( 'PayPal Page Style', 'give' ),
'desc' => __( 'Enter the name of the page style to use, or leave blank to use the default.', 'give' ),
'id' => 'paypal_page_style',
'type' => 'text',
),
array(
'name' => __( 'PayPal Transaction Type', 'give' ),
'desc' => __( 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, Give transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.', 'give' ),
'id' => 'paypal_button_type',
'type' => 'radio_inline',
'options' => array(
'donation' => __( 'Donation', 'give' ),
'standard' => __( 'Standard Transaction', 'give' ),
),
'default' => 'donation',
),
array(
'name' => __( 'Disable PayPal IPN Verification', 'give' ),
'desc' => __( 'If donations are not getting marked as complete, use a slightly less secure method of verifying donations.', 'give' ),
'id' => 'disable_paypal_verification',
'type' => 'checkbox',
),
array(
'name' => __( 'Offline Donations', 'give' ),
'desc' => '',
'type' => 'give_title',
'id' => 'give_title_gateway_settings_3',
),
array(
'name' => __( 'Collect Billing Details', 'give' ),
'desc' => __( 'Enable to request billing details for offline donations. Will appear above offline donation instructions. Can be enabled/disabled per form.', 'give' ),
'id' => 'give_offline_donation_enable_billing_fields',
'type' => 'checkbox',
),
array(
'name' => __( 'Offline Donation Instructions', 'give' ),
'desc' => __( 'The following content will appear for all forms when the user selects the offline donation payment option. Note: You may customize the content per form as needed.', 'give' ),
'id' => 'global_offline_donation_content',
'default' => give_get_default_offline_donation_content(),
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => 6,
),
),
array(
'name' => __( 'Offline Donation Email Instructions Subject', 'give' ),
'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
'id' => 'offline_donation_subject',
'default' => esc_attr__( '{donation} - Offline Donation Instructions', 'give' ),
'type' => 'text',
),
array(
'name' => __( 'Offline Donation Email Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want emailed to the donor after they have submitted the donation form. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'id' => 'global_offline_donation_email',
'default' => give_get_default_offline_donation_email_content(),
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => 6,
),
),
)
),
),
/** Display Settings */
'display' => array(
'id' => 'display_settings',
'give_title' => __( 'Display Settings', 'give' ),
'show_on' => array(
'key' => 'options-page',
'value' => array( $this->key ),
),
'fields' => apply_filters(
'give_settings_display', array(
array(
'name' => __( 'Display Settings', 'give' ),
'desc' => '',
'id' => 'give_title_display_settings_1',
'type' => 'give_title',
),
array(
'name' => __( 'Disable CSS', 'give' ),
'desc' => __( 'Enable this option if you would like to disable all of Give\'s included CSS stylesheets.', 'give' ),
'id' => 'disable_css',
'type' => 'checkbox',
),
array(
'name' => __( 'Enable Floating Labels', 'give' ),
/* translators: %s: http://docs.givewp.com/form-floating-labels */
'desc' => sprintf(
wp_kses(
__( 'Enable floating labels in Give\'s donation forms. Note that if the "Disable CSS" option is enabled, you will need to style the floating labels yourself.', 'give' ), array(
'a' => array(
'href' => array(),
'target' => array(),
),
)
), esc_url( 'http://docs.givewp.com/form-floating-labels' )
),
'id' => 'floatlabels',
'type' => 'checkbox',
),
array(
'name' => __( 'Disable Welcome Screen', 'give' ),
/* translators: %s: about page URL */
'desc' => sprintf(
wp_kses(
__( 'Enable this option if you would like to disable the Give Welcome screen every time Give is activated and/or updated.', 'give' ), array(
'a' => array(
'href' => array(),
'target' => array(),
),
)
), esc_url( admin_url( 'index.php?page=give-about' ) )
),
'id' => 'disable_welcome',
'type' => 'checkbox',
),
array(
'name' => __( 'Post Types', 'give' ),
'desc' => '',
'id' => 'give_title_display_settings_2',
'type' => 'give_title',
),
array(
'name' => __( 'Disable Form Single Views', 'give' ),
'desc' => __( 'By default, all forms have single views enabled which create a specific URL on your website for that form. This option disables the singular and archive views from being publicly viewable. Note: you will need to embed forms using a shortcode or widget if enabled.', 'give' ),
'id' => 'disable_forms_singular',
'type' => 'checkbox',
),
array(
'name' => __( 'Disable Form Archives', 'give' ),
'desc' => __( 'Archives pages list all the forms you have created. This option will disable only the form\'s archive page(s). The single form\'s view will remain in place. Note: you will need to refresh your permalinks after this option has been enabled.', 'give' ),
'id' => 'disable_forms_archives',
'type' => 'checkbox',
),
array(
'name' => __( 'Disable Form Excerpts', 'give' ),
'desc' => __( 'The excerpt is an optional summary or description of a donation form; in short, a summary as to why the user should give.', 'give' ),
'id' => 'disable_forms_excerpt',
'type' => 'checkbox',
),
array(
'name' => __( 'Featured Image Size', 'give' ),
'desc' => __( 'The Featured Image is an image that is chosen as the representative image for a donation form. Some themes may have custom featured image sizes. Please select the size you would like to display for your single donation form\'s featured image.', 'give' ),
'id' => 'featured_image_size',
'type' => 'select',
'default' => 'large',
'options' => give_get_featured_image_sizes(),
),
array(
'name' => __( 'Disable Form Featured Image', 'give' ),
'desc' => __( 'If you do not wish to use the featured image functionality you can disable it using this option and it will not be displayed for single donation forms.', 'give' ),
'id' => 'disable_form_featured_img',
'type' => 'checkbox',
),
array(
'name' => __( 'Disable Single Form Sidebar', 'give' ),
'desc' => __( 'The sidebar allows you to add additional widget to the Give single form view. If you don\'t plan on using the sidebar you may disable it with this option.', 'give' ),
'id' => 'disable_form_sidebar',
'type' => 'checkbox',
),
array(
'name' => __( 'Taxonomies', 'give' ),
'desc' => '',
'id' => 'give_title_display_settings_3',
'type' => 'give_title',
),
array(
'name' => __( 'Enable Form Categories', 'give' ),
'desc' => __( 'Enables the "Category" taxonomy for all Give forms.', 'give' ),
'id' => 'categories',
'type' => 'checkbox',
),
array(
'name' => __( 'Enable Form Tags', 'give' ),
'desc' => __( 'Enables the "Tag" taxonomy for all Give forms.', 'give' ),
'id' => 'tags',
'type' => 'checkbox',
),
)
),
),
/**
* Emails Options
*/
'emails' => array(
'id' => 'email_settings',
'give_title' => __( 'Email Settings', 'give' ),
'show_on' => array(
'key' => 'options-page',
'value' => array( $this->key ),
),
'fields' => apply_filters(
'give_settings_emails', array(
array(
'name' => __( 'Email Settings', 'give' ),
'desc' => '',
'id' => 'give_title_email_settings_1',
'type' => 'give_title',
),
array(
'id' => 'email_template',
'name' => __( 'Email Template', 'give' ),
'desc' => __( 'Choose a template. Click "Save Changes" then "Preview Donation Receipt" to see the new template.', 'give' ),
'type' => 'select',
'options' => give_get_email_templates(),
),
array(
'id' => 'email_logo',
'name' => __( 'Logo', 'give' ),
'desc' => __( 'Upload or choose a logo to be displayed at the top of the donation receipt emails. Displayed on HTML emails only.', 'give' ),
'type' => 'file',
),
array(
'id' => 'from_name',
'name' => __( 'From Name', 'give' ),
'desc' => __( 'The name that appears in the "From" field in donation receipt emails.', 'give' ),
'default' => get_bloginfo( 'name' ),
'type' => 'text',
),
array(
'id' => 'from_email',
'name' => __( 'From Email', 'give' ),
'desc' => __( 'Email to send donation receipts from. This will act as the "from" and "reply-to" address.', 'give' ),
'default' => get_bloginfo( 'admin_email' ),
'type' => 'text',
),
array(
'name' => __( 'Donation Receipt', 'give' ),
'desc' => '',
'id' => 'give_title_email_settings_2',
'type' => 'give_title',
),
array(
'id' => 'donation_subject',
'name' => __( 'Donation Email Subject', 'give' ),
'desc' => __( 'Enter the subject line for the donation receipt email.', 'give' ),
'default' => esc_attr__( 'Donation Receipt', 'give' ),
'type' => 'text',
),
array(
'id' => 'donation_receipt',
'name' => __( 'Donation Receipt', 'give' ),
'desc' => sprintf(
/* translators: %s: emails tags list */
__( 'Enter the email that is sent to users after completing a successful donation. HTML is accepted. Available template tags: %s', 'give' ),
'the_content' ),
/* translators: 1: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content 2: the_content */
'desc' => sprintf( __( 'If you are seeing extra social buttons, related posts, or other unwanted elements appearing within your forms then you can disable WordPress\' content filter. Learn more about %2$s filter.', 'give' ), esc_url( 'https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content' ), 'the_content' ),
'id' => 'disable_the_content_filter',
'type' => 'checkbox',
),
array(
'name' => __( 'Script Loading', 'give' ),
'desc' => '',
'id' => 'give_title_script_control',
'type' => 'give_title',
),
array(
'name' => __( 'Load Scripts in Footer?', 'give' ),
'desc' => __( 'Check this box if you would like Give to load all frontend JavaScript files in the footer.', 'give' ),
'id' => 'scripts_footer',
'type' => 'checkbox',
),
)
),
),
/** API Settings */
'api' => array(
'id' => 'api',
'give_title' => __( 'API', 'give' ),
'show_on' => array(
'key' => 'options-page',
'value' => array( $this->key ),
),
'show_names' => false, // Hide field names on the left
'fields' => apply_filters(
'give_settings_system', array(
array(
'id' => 'api',
'name' => __( 'API', 'give' ),
'type' => 'api',
),
)
),
),
/** Licenses Settings */
'system_info' => array(
'id' => 'system_info',
'give_title' => __( 'System Info', 'give' ),
'show_on' => array(
'key' => 'options-page',
'value' => array( $this->key ),
),
'fields' => apply_filters(
'give_settings_system', array(
array(
'id' => 'system-info-textarea',
'name' => __( 'System Info', 'give' ),
'desc' => __( 'Please copy and paste this information in your ticket when contacting support.', 'give' ),
'type' => 'system_info',
),
)
),
),
);
$give_settings = apply_filters( 'give_registered_settings', $give_settings );
// Return all settings array if no active tab
if ( empty( $active_tab ) || ! isset( $give_settings[ $active_tab ] ) ) {
return $give_settings;
}
// Add other tabs and settings fields as needed
return $give_settings[ $active_tab ];
}
/**
* Show Settings Notices
*/
public function settings_notices() {
if ( ! isset( $_POST['give_settings_saved'] ) ) {
return;
}
add_settings_error( 'give-notices', 'global-settings-updated', __( 'Settings updated.', 'give' ), 'updated' );
}
/**
* Public getter method for retrieving protected/private variables
*
* @since 1.0
*
* @param string $field Field to retrieve
*
* @return mixed Field value or exception is thrown.
* @throws Exception Throws an exception if the field is invalid.
*/
public function __get( $field ) {
// Allowed fields to retrieve
if ( in_array( $field, array( 'key', 'fields', 'give_title', 'options_page' ), true ) ) {
return $this->{$field};
}
throw new Exception( sprintf( __( 'Invalid property: %s', 'give' ), $field ) );
}
}
// Get it started
$Give_Settings = new Give_Plugin_Settings();
/**
* Helps get a single option from the give_get_settings() array.
*
* @since 0.1.0
*
* @param string $key Options array key
* @param string|bool $default The default option if the option isn't set
*
* @return mixed Option value
*/
function give_get_option( $key = '', $default = false ) {
$give_options = give_get_settings();
$value = ! empty( $give_options[ $key ] ) ? $give_options[ $key ] : $default;
$value = apply_filters( 'give_get_option', $value, $key, $default );
return apply_filters( "give_get_option_{$key}", $value, $key, $default );
}
/**
* Update an option
*
* Updates an give setting value in both the db and the global variable.
* Warning: Passing in an empty, false or null string value will remove
* the key from the give_options array.
*
* @since 1.0
*
* @param string $key The Key to update
* @param string|bool|int $value The value to set the key to
*
* @return boolean True if updated, false if not.
*/
function give_update_option( $key = '', $value = false ) {
// If no key, exit
if ( empty( $key ) ) {
return false;
}
if ( empty( $value ) ) {
$remove_option = give_delete_option( $key );
return $remove_option;
}
// First let's grab the current settings
$options = get_option( 'give_settings' );
// Let's let devs alter that value coming in
$value = apply_filters( 'give_update_option', $value, $key );
// Next let's try to update the value
$options[ $key ] = $value;
$did_update = update_option( 'give_settings', $options, false );
// If it updated, let's update the global variable
if ( $did_update ) {
global $give_options;
$give_options[ $key ] = $value;
}
return $did_update;
}
/**
* Remove an option
*
* Removes an give setting value in both the db and the global variable.
*
* @since 1.0
*
* @global $give_options
*
* @param string $key The Key to delete
*
* @return boolean True if updated, false if not.
*/
function give_delete_option( $key = '' ) {
// If no key, exit
if ( empty( $key ) ) {
return false;
}
// First let's grab the current settings
$options = get_option( 'give_settings' );
// Next let's try to update the value
if ( isset( $options[ $key ] ) ) {
unset( $options[ $key ] );
}
$did_update = update_option( 'give_settings', $options, false );
// If it updated, let's update the global variable
if ( $did_update ) {
global $give_options;
$give_options = $options;
}
return $did_update;
}
/**
* Get Settings
*
* Retrieves all Give plugin settings
*
* @since 1.0
* @return array Give settings
*/
function give_get_settings() {
$settings = get_option( 'give_settings' );
return (array) apply_filters( 'give_get_settings', $settings );
}
/**
* Give Settings Array Insert.
*
* Allows other Add-ons and plugins to insert Give settings at a desired position.
*
* @since 1.3.5
*
* @param $array
* @param $position |int|string Expects an array key or 'id' of the settings field to appear after
* @param $insert |array a valid array of options to insert
*
* @return array
*/
function give_settings_array_insert( $array, $position, $insert ) {
if ( is_int( $position ) ) {
array_splice( $array, $position, 0, $insert );
} else {
foreach ( $array as $index => $subarray ) {
if ( isset( $subarray['id'] ) && $subarray['id'] == $position ) {
$pos = $index;
}
}
if ( ! isset( $pos ) ) {
return $array;
}
$array = array_merge(
array_slice( $array, 0, $pos ),
$insert,
array_slice( $array, $pos )
);
}
return $array;
}
/**
* Gateways Callback
*
* Renders gateways fields.
*
* @since 1.0
*
* @param array $field_arr
* @param array $saved_values
*
* @return void
*/
function give_enabled_gateways_callback( $field_arr, $saved_values = array() ) {
$saved_values = __give_validate_active_gateways( $saved_values );
$id = $field_arr['id'];
$gateways = give_get_ordered_payment_gateways( give_get_payment_gateways() );
echo '' . $message . '
'; $custom_html .= '