/www/wp-content/plugins/ithemes-exchange/lib/admin/class.admin.php
PHP | 1915 lines | 1205 code | 221 blank | 489 comment | 265 complexity | 1ecfd93288f0de1f77aae400363241b7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * iThemes Exchange admin class.
- *
- * This class manages the admin side of the plugin
- *
- * @package IT_Exchange
- * @since 0.1.0
- */
- class IT_Exchange_Admin {
- /**
- * @var object $_parent parent class
- * @since 0.1.0
- */
- var $_parent;
- /**
- * @var string $_current_page current page based on $_GET['page']
- * @since 0.3.4
- */
- var $_current_page;
- /**
- * @var string $_current_tab
- * @since 0.3.4
- */
- var $_current_tab;
- /**
- * @var string $status_message informative message for current settings tab
- * @since 0.3.6
- */
- var $status_message;
- /**
- * @var string $error_message error message for current settings tab
- * @since 0.3.6
- */
- var $error_message;
- /**
- * Class constructor
- *
- * @uses add_action()
- * @since 0.1.0
- * @return void
- */
- function IT_Exchange_Admin( &$parent ) {
- // Set parent property
- $this->_parent = $parent;
- // Admin Menu Capability
- $this->admin_menu_capability = apply_filters( 'it_exchange_admin_menu_capability', 'activate_plugins' );
- // Set current properties
- $this->set_current_properties();
- // Open iThemes Exchange menu when on add/edit iThemes Exchange product post type
- add_action( 'parent_file', array( $this, 'open_exchange_menu_on_post_type_views' ) );
- // Add actions for iThemes registration
- add_action( 'admin_notices', array( $this, 'add_wizard_nag' ) );
- add_action( 'admin_menu', array( $this, 'add_exchange_admin_menu' ) );
- add_action( 'admin_menu', array( $this, 'add_lower_priority_items_to_exchange_menu' ), 90 );
- add_action( 'admin_init', array( $this, 'enable_disable_registered_add_on' ) );
- add_action( 'admin_init', array( $this, 'enable_required_add_ons' ) );
- add_filter( 'admin_body_class', array( $this, 'add_exchange_class_to_exchange_pages' ) );
- add_filter( 'upload_mimes', array( $this, 'uploads_mimes_for_products' ) );
- add_filter( 'wp_ajax_ite-country-state-update', array( $this, 'update_country_state_ui_in_general_settings' ) );
- // Admin Product Redirects
- add_action( 'admin_init', array( $this, 'redirect_post_new_to_product_type_selection_screen' ) );
- add_action( 'admin_init', array( $this, 'bounce_user_to_all_products_if_directly_accessing_disabled_product_type' ) );
- // Init our custom add/edit layout interface
- add_action( 'admin_enqueue_scripts', array( $this, 'it_exchange_admin_wp_enqueue_scripts' ), 9 );
- add_action( 'admin_print_styles', array( $this, 'it_exchange_admin_wp_enqueue_styles' ) );
- add_action( 'admin_init', array( $this, 'remove_third_party_metaboxes' ) );
- add_action( 'admin_init', array( $this, 'setup_add_edit_product_screen_layout' ) );
- // Force 2 column view on add / edit products
- add_filter( 'screen_layout_columns', array( $this, 'modify_add_edit_page_layout' ) );
- add_filter( 'get_user_option_screen_layout_it_exchange_prod', array( $this, 'update_user_column_options' ) );
- // Save core settings
- add_action( 'admin_init', array( $this, 'save_core_wizard_settings' ), 9 );
- add_action( 'admin_init', array( $this, 'save_core_general_settings' ) );
- add_action( 'admin_init', array( $this, 'save_core_email_settings' ) );
- add_action( 'admin_init', array( $this, 'save_core_page_settings' ), 9 ); // Priority 9 to catch product rewrites
- // Email settings callback
- add_filter( 'it_exchange_general_settings_tab_callback_email', array( $this, 'register_email_settings_tab_callback' ) );
- add_action( 'it_exchange_print_general_settings_tab_links', array( $this, 'print_email_settings_tab_link' ) );
- // Page settings callback
- add_filter( 'it_exchange_general_settings_tab_callback_pages', array( $this, 'register_pages_settings_tab_callback' ) );
- add_action( 'it_exchange_print_general_settings_tab_links', array( $this, 'print_pages_settings_tab_link' ) );
- // General Settings Defaults
- add_filter( 'it_storage_get_defaults_exchange_settings_general', array( $this, 'set_general_settings_defaults' ) );
- // Email Settings Defaults
- add_filter( 'it_storage_get_defaults_exchange_settings_email', array( $this, 'set_email_settings_defaults' ) );
- // Page Settings Defaults
- add_filter( 'it_storage_get_defaults_exchange_settings_pages', array( $this, 'set_pages_settings_defaults' ) );
- // Add-on Page Filters
- add_action( 'it_exchange_print_add_ons_page_tab_links', array( $this, 'print_enabled_add_ons_tab_link' ) );
- add_action( 'it_exchange_print_add_ons_page_tab_links', array( $this, 'print_disabled_add_ons_tab_link' ) );
- add_filter( 'it_exchange_add_ons_tab_callback_get-more', array( $this, 'register_get_more_add_ons_tab_callback' ) );
- add_action( 'it_exchange_print_add_ons_page_tab_links', array( $this, 'print_get_more_add_ons_tab_link' ) );
- // Update existing nav menu post_type entries when permalink structure is changed
- add_action( 'update_option_permalink_structure', array( $this, 'maybe_update_ghost_pages_in_wp_nav_menus' ) );
- // Remove Quick Edit
- add_filter( 'post_row_actions', array( $this, 'it_exchange_remove_quick_edit' ), 10, 2 );
- add_filter( 'page_row_actions', array( $this, 'it_exchange_remove_quick_edit' ), 10, 2 );
- // User Edit
- add_filter( 'user_row_actions', array( $this, 'it_exchange_user_row_actions' ), 10, 2 );
- add_action( 'all_admin_notices', array( $this, 'it_exchange_user_edit_load' ) );
- add_action( 'show_user_profile', array( $this, 'it_exchange_user_profile' ) );
- add_action( 'edit_user_profile', array( $this, 'it_exchange_user_profile' ) );
- add_action( 'it_exchange_addon_settings_page_top', array( $this, 'return_to_addons' ) );
- add_filter( 'plugin_action_links_ithemes-exchange/init.php', array( $this, 'it_exchange_plugin_row_actions' ), 10, 4 );
- add_filter( 'plugin_row_meta', array( $this, 'it_exchange_plugin_row_meta' ), 10, 4 );
- }
- /**
- * Adds actions to the plugins page for the iThemes Exchange plugin
- *
- * @since 0.4.15
- *
- * @param array $meta Existing meta
- * @param string $plugin_file the wp plugin slug (path)
- * @param array $plugin_data the data WP harvested from the plugin header
- * @param string $context
- * @return array
- */
- function it_exchange_plugin_row_actions( $actions, $plugin_file, $plugin_data, $context ) {
- $actions['quick_setup'] = '<a href="' . get_admin_url( NULL, 'admin.php?page=it-exchange-setup' ) . '">' . __( 'Quick Setup', 'it-l10n-ithemes-exchange' ) . '</a>';
- return $actions;
- }
- /**
- * Adds links to the plugin row meta
- *
- * @since 0.4.18
- *
- * @param array $meta Existing meta
- * @param string $plugin_file the wp plugin slug (path)
- * @param array $plugin_data the data WP harvested from the plugin header
- * @param string $status the plugin activation status
- * @return array
- */
- function it_exchange_plugin_row_meta( $meta, $plugin_file, $plugin_data, $status ) {
- if ( 'ithemes-exchange/init.php' == $plugin_file ) {
- $meta[] = '<a href="http://ithemes.com/codex/page/Exchange" target="_blank">' . __( 'Documentation', 'it-l10n-ithemes-exchange' ) . '</a>';
- $meta[] = '<a href="http://ithemes.com/exchange/support" target="_blank">' . __( 'Support', 'it-l10n-ithemes-exchange' ) . '</a>';
- $meta[] = '<a href="http://ithemes.com/exchange/add-ons" target="_blank">' . __( 'Add-ons', 'it-l10n-ithemes-exchange' ) . '</a>';
- $meta[] = '<a href="http://ithemes.com/codex/page/Exchange_Changelog" target="_blank">' . __( 'Changelog', 'it-l10n-ithemes-exchange' ) . '</a>';
- }
- return $meta;
- }
- /**
- * Adds link to bottom of addons settings pages to return to the addons pages
- *
- * @since 0.4.5
- * @return void
- */
- function return_to_addons() {
- if ( ! empty( $GLOBALS['hook_suffix'] ) && 'exchange_page_it-exchange-addons' == $GLOBALS['hook_suffix'] ) { //only show on add-on-settings pages
- $url = add_query_arg( 'page', 'it-exchange-addons', admin_url( 'admin.php' ) );
- echo '<div class="it-exchange-return-to-addons"><p><a href="' . $url . '">← ' . __( 'Back to Add-ons', 'it-l10n-ithemes-exchange' ) . '</a></p></div>';
- }
- }
- /**
- * Adds iThemes Exchange User row action to users.php row actions
- *
- * @since 0.4.0
- * @return void
- */
- function it_exchange_user_row_actions( $actions, $user_object ) {
- $actions['it_exchange'] = "<a class='it-exchange-cust-info' href='" . esc_url( add_query_arg( array( 'wp_http_referer' => urlencode( stripslashes_deep( $_SERVER['REQUEST_URI'] ) ), 'it_exchange_customer_data' => 1 ), get_edit_user_link( $user_object->ID ) ) ) . "'>" . __( 'Customer Data', 'it-l10n-ithemes-exchange' ) . "</a>";
- return $actions;
- }
- /**
- * Adds iThemes Exchange User Meta page to user-edit.php
- *
- * @since 0.4.0
- * @return void
- */
- function it_exchange_user_profile( $profileuser ) {
- if ( current_user_can('edit_users') )
- include( 'views/admin-user-profile.php' );
- }
- /**
- * Adds iThemes Exchange User Meta page to user-edit.php
- *
- * @since 0.4.0
- * @return void
- */
- function it_exchange_user_edit_load() {
- //A little hacky
- global $pagenow;
- if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php' ) )
- && !empty( $_REQUEST['it_exchange_customer_data'] ) && current_user_can('edit_users') ) {
- add_action( 'it_exchange_print_user_edit_page_tab_links', array( $this, 'print_products_user_edit_tab_link' ) );
- add_action( 'it_exchange_print_user_edit_page_tab_links', array( $this, 'print_transactions_user_edit_tab_link' ) );
- add_action( 'it_exchange_print_user_edit_page_tab_links', array( $this, 'print_info_user_edit_tab_link' ) );
- include( 'views/admin-user-edit.php' );
- include( ABSPATH . 'wp-admin/admin-footer.php');
- die();
- }
- }
- /**
- * Save iThemes Exchange User Meta Options to user-edit.php
- *
- * @since 0.4.0
- * @param int $user_id User ID of meta we're saving
- * @return void
- */
- function it_exchange_edit_user_profile_update( $user_id ) {
- if ( isset( $_REQUEST['it_exchange_customer_note'] ) )
- update_user_meta( $user_id, '_it_exchange_customer_note', $_REQUEST['it_exchange_customer_note'] );
- }
- /**
- * Prints the tabs for the iThemes Exchange Add-ons Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_user_edit_page_tabs() {
- ?>
- <h2 class="nav-tab-wrapper">
- <?php do_action( 'it_exchange_print_user_edit_page_tab_links', $this->_current_tab ); ?>
- </h2>
- <?php
- }
- /**
- * Prints the products tab for the user-edit.php Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_products_user_edit_tab_link( $current_tab ) {
- $active = ( 'products' === $current_tab || false === $current_tab ) ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo add_query_arg( 'tab', 'products' ); ?>#it-exchange-member-options"><?php _e( 'Products', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Prints the transactions tab for the user-edit.php Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_transactions_user_edit_tab_link( $current_tab ) {
- $active = 'transactions' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo add_query_arg( 'tab', 'transactions' ); ?>#it-exchange-member-options"><?php _e( 'Transactions', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Prints the info tab for the user-edit.php Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_info_user_edit_tab_link( $current_tab ) {
- $active = ( 'info' === $current_tab ) ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo add_query_arg( 'tab', 'info' ); ?>#it-exchange-member-options"><?php _e( 'Info', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Sets the _current_page and _current_tab properties
- *
- * @since 0.3.4
- * @return void
- */
- function set_current_properties() {
- $this->_current_page = empty( $_GET['page'] ) ? false : $_GET['page'];
- $this->_current_tab = empty( $_GET['tab'] ) ? false : $_GET['tab'];
- }
- /**
- * Adds the nag to the top of the admin screens if not complete
- *
- * @since 0.4.0
- */
- function add_wizard_nag() {
- if ( ! empty( $_REQUEST['it_exchange_settings-dismiss-wizard-nag'] ) )
- update_option( 'it-exchange-hide-wizard-nag', true );
- if ( isset( $_GET['it-exchange-show-wizard-link'] ) )
- delete_option( 'it-exchange-hide-wizard-nag' );
- if ( true == (boolean) get_option( 'it-exchange-hide-wizard-nag' ) )
- return;
- if ( 'it-exchange-setup' != $this->_current_page )
- include( 'views/admin-wizard-notice.php' );
- }
- /**
- * Adds the main iThemes Exchange menu item to the WP admin menu
- *
- * @since 0.2.0
- * @return void
- */
- function add_exchange_admin_menu() {
- // Add main iThemes Exchange menu item
- add_menu_page( 'iThemes Exchange', 'Exchange', $this->admin_menu_capability, 'it-exchange', array( $this, 'print_exchange_setup_page' ) );
- // Add setup wizard page without menu item unless we're viewing it.
- if ( 'it-exchange-setup' == $this->_current_page )
- add_submenu_page( 'it-exchange', 'iThemes Exchange Setup Wizard', 'Setup Wizard', $this->admin_menu_capability, 'it-exchange-setup', array( $this, 'print_exchange_setup_page' ) );
- // Add the product submenu pages depending on active product add-ons
- $this->add_product_submenus();
- // Add Transactions menu item
- add_submenu_page( 'it-exchange', 'iThemes Exchange ' . __( 'Payments', 'it-l10n-ithemes-exchange' ), __( 'Payments', 'it-l10n-ithemes-exchange' ), $this->admin_menu_capability, 'edit.php?post_type=it_exchange_tran' );
- // Remove default iThemes Exchange sub-menu item created with parent menu item
- remove_submenu_page( 'it-exchange', 'it-exchange' );
- }
- /**
- * Adds the help menu at the bottom of the menu
- *
- * @since 0.4.17
- *
- * @return void
- */
- function add_lower_priority_items_to_exchange_menu() {
- // Add Settings Menu Item
- $settings_callback = array( $this, 'print_exchange_settings_page' );
- if ( 'it-exchange-settings' == $this->_current_page && ! empty( $this->_current_tab ) )
- $settings_callback = apply_filters( 'it_exchange_general_settings_tab_callback_' . $this->_current_tab, $settings_callback );
- add_submenu_page( 'it-exchange', 'iThemes Exchange Settings', 'Settings', $this->admin_menu_capability, 'it-exchange-settings', $settings_callback );
- // Add Add-ons menu item
- $add_ons_callback = array( $this, 'print_exchange_add_ons_page' );
- if ( 'it-exchange-addons' == $this->_current_page && ! empty( $this->_current_tab ) ) {
- $add_ons_callback = apply_filters( 'it_exchange_add_ons_tab_callback_' . $this->_current_tab, $add_ons_callback );
- }
- if ( !empty( $_GET['add-on-settings'] ) && $addon = it_exchange_get_addon( $_GET['add-on-settings'] ) ) {
- if ( ! empty( $addon['options']['settings-callback'] ) && is_callable( $addon['options']['settings-callback'] ) )
- $add_ons_callback = $addon['options']['settings-callback'];
- }
- add_submenu_page( 'it-exchange', 'iThemes Exchange Add-ons', 'Add-ons', $this->admin_menu_capability, 'it-exchange-addons', $add_ons_callback );
- // Help menu
- add_submenu_page( 'it-exchange', __( 'Help', 'it-l10n-ithemes-exchange' ), __( 'Help', 'it-l10n-ithemes-exchange' ), $this->admin_menu_capability, 'it-exchange-help', array( $this, 'print_help_page' ) );
- }
- /**
- * Adds the product submenus based on number of enabled product-type add-ons
- *
- * @since 0.3.0
- * @return void
- */
- function add_product_submenus() {
- // Check for enabled product add-ons. Don't need product pages if we don't have product add-ons enabled
- if ( $enabled_product_types = it_exchange_get_enabled_addons( array( 'category' => array( 'product-type' ) ) ) ) {
- $add_on_count = count( $enabled_product_types );
- add_submenu_page( 'it-exchange', 'All Products', 'All Products', $this->admin_menu_capability, 'edit.php?post_type=it_exchange_prod' );
- if ( 1 == $add_on_count ) {
- // If we only have one product-type enabled, add standard post_type pages
- $product = reset( $enabled_product_types );
- add_submenu_page( 'it-exchange', 'Add Product', 'Add Product', $this->admin_menu_capability, 'post-new.php?post_type=it_exchange_prod&it-exchange-product-type=' . $product['slug'] );
- } else if ( $add_on_count > 1 ) {
- // If we have more than one product type, add them each separately
- foreach( $enabled_product_types as $type => $params ) {
- $name = empty( $params['options']['labels']['singular_name'] ) ? 'Product' : esc_attr( $params['options']['labels']['singular_name'] );
- add_submenu_page( 'it-exchange', 'Add ' . $name, 'Add ' . $name, $this->admin_menu_capability, 'post-new.php?post_type=it_exchange_prod&it-exchange-product-type=' . esc_attr( $params['slug'] ) );
- }
- }
- }
- }
- /**
- * Registers the callback for the email tab
- *
- * @param mixed default callback for general settings.
- * @since 0.3.4
- * @return mixed function or class method name
- */
- function register_email_settings_tab_callback( $default ) {
- return array( $this, 'print_email_settings_page' );
- }
- /**
- * Prints the email tab for general settings
- *
- * @since 0.3.4
- * @param $current_tab the current tab
- * @return void
- */
- function print_email_settings_tab_link( $current_tab ) {
- $active = 'email' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-settings&tab=email' ); ?>"><?php _e( 'Email Settings', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Registers the callback for the pages tab
- *
- * @param mixed default callback for general settings.
- * @since 0.3.7
- * @return mixed function or class method name
- */
- function register_pages_settings_tab_callback( $default ) {
- return array( $this, 'print_pages_settings_page' );
- }
- /**
- * Prints the pages tab for general settings
- *
- * @since 0.3.7
- * @param $current_tab the current tab
- * @return void
- */
- function print_pages_settings_tab_link( $current_tab ) {
- $active = 'pages' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-settings&tab=pages' ); ?>"><?php _e( 'Pages', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Prints the tabs for the iThemes Exchange General Settings
- *
- * @since 0.3.4
- * @return void
- */
- function print_general_settings_tabs() {
- $active = empty( $this->_current_tab ) ? 'nav-tab-active' : '';
- ?>
- <h2 class="nav-tab-wrapper">
- <a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-settings' ); ?>"><?php _e( 'General', 'it-l10n-ithemes-exchange' ); ?></a>
- <?php do_action( 'it_exchange_print_general_settings_tab_links', $this->_current_tab ); ?>
- </h2>
- <?php
- }
- /**
- * Prints the tabs for the iThemes Exchange Add-ons Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_add_ons_page_tabs() {
- $active = ( empty( $this->_current_tab ) || 'all' == $this->_current_tab ) ? 'nav-tab-active' : '';
- ?>
- <h2 class="nav-tab-wrapper">
- <a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-addons' ); ?>"><?php _e( 'All', 'it-l10n-ithemes-exchange' ); ?></a>
- <?php do_action( 'it_exchange_print_add_ons_page_tab_links', $this->_current_tab ); ?>
- </h2>
- <?php
- }
- /**
- * Prints the enabled tab for the Add-ons Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_enabled_add_ons_tab_link( $current_tab ) {
- $active = 'enabled' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-addons&tab=enabled' ); ?>"><?php _e( 'Enabled', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Prints the disabled tab for the Add-ons Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_disabled_add_ons_tab_link( $current_tab ) {
- $active = 'disabled' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-addons&tab=disabled' ); ?>"><?php _e( 'Disabled', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Registers the callback for the get more add-ons tab
- *
- * @param mixed default callback for add-ons page.
- * @since 0.4.0
- * @return mixed function or class method name
- */
- function register_get_more_add_ons_tab_callback( $default ) {
- return array( $this, 'print_get_more_add_ons_page' );
- }
- /**
- * Prints the enabled add ons page for iThemes Exchange
- *
- * @since 0.4.0
- * @return void
- */
- function print_get_more_add_ons_page() {
- $add_on_cats = it_exchange_get_addon_categories();
- $message = empty( $_GET['message'] ) ? false : $_GET['message'];
- if ( 'installed' == $message )
- ITUtility::show_status_message( __( 'Add-on installed.', 'it-l10n-ithemes-exchange' ) );
- $error = empty( $_GET['error'] ) ? false : $_GET['error'];
- if ( 'installed' == $error )
- ITUtility::show_error_message( __( 'Error: Add-on not installed.', 'it-l10n-ithemes-exchange' ) );
- include( 'views/admin-get-more-addons.php' );
- }
- /**
- * Prints the Get More tab for the Add-ons Page
- *
- * @since 0.4.0
- * @return void
- */
- function print_get_more_add_ons_tab_link( $current_tab ) {
- $active = 'get-more' == $current_tab ? 'nav-tab-active' : '';
- ?><a class="nav-tab <?php echo $active; ?>" href="<?php echo admin_url( 'admin.php?page=it-exchange-addons&tab=get-more' ); ?>"><?php _e( 'Get More', 'it-l10n-ithemes-exchange' ); ?></a><?php
- }
- /**
- * Prints the help/support page for iThemes Exchange
- *
- * @since 0.4.14
- * @return void
- */
- function print_help_page() {
- include( 'views/admin-help.php' );
- }
- /**
- * Prints the setup page for iThemes Exchange
- *
- * @since 0.2.0
- * @return void
- */
- function print_exchange_setup_page() {
- $flush_cache = ! empty( $_POST );
- $settings = it_exchange_get_option( 'settings_general', $flush_cache );
- $form_values = empty( $this->error_message ) ? $settings : ITForm::get_post_data();
- $form = new ITForm( $form_values, array( 'prefix' => 'it_exchange_settings' ) );
- $form_options = array(
- 'id' => apply_filters( 'it_exchange_settings_form_id', 'it-exchange-settings' ),
- 'enctype' => apply_filters( 'it_exchange_settings_form_enctype', false ),
- );
- if ( $messages = it_exchange_get_messages( 'notice' ) ) {
- foreach( $messages as $notice ) {
- ITUtility::show_status_message( $notice );
- }
- it_exchange_clear_messages( 'notice' );
- }
- if ( $messages = it_exchange_get_messages( 'error' ) ) {
- foreach( $messages as $error ) {
- ITUtility::show_error_message( $error );
- }
- it_exchange_clear_messages( 'error' );
- }
- include( 'views/admin-wizard.php' );
- }
- /**
- * Sets the general settings default values
- *
- * @since 0.3.7
- * @return array
- */
- function set_general_settings_defaults( $values ) {
- $defaults = array(
- 'company-base-country' => 'US',
- 'company-base-state' => 'OK',
- 'store-product-order-by' => 'date',
- 'store-product-order' => 'DESC',
- 'default-currency' => 'USD',
- 'currency-symbol-position' => 'before',
- 'currency-thousands-separator' => ',',
- 'currency-decimals-separator' => '.',
- 'site-registration' => 'it',
- 'wysiwyg-for-product-description' => '0',
- 'enable-gallery-popup' => '1',
- 'enable-gallery-zoom' => '1',
- 'product-gallery-zoom-action' => 'click',
- 'checkout-reg-form' => 'registration',
- 'company-email' => get_bloginfo( 'admin_email' ),
- 'company-name' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
- 'customer-account-page' => 'Welcome to your account, [it_exchange_customer show="first-name"].<br />Using the links above, you can edit your profile and view your purchases and products.<br />Thanks for being a customer.'
- );
- $values = ITUtility::merge_defaults( $values, $defaults );
- return $values;
- }
- /**
- * Sets the email settings default values
- *
- * static so we can access it from email_notifications w/o loading entire class
- *
- * @since 0.4.0
- * @return array
- */
- static function set_email_settings_defaults( $values ) {
- $defaults = array(
- 'notification-email-address' => esc_attr( get_bloginfo( 'admin_email' ) ),
- 'admin-email-address' => esc_attr( get_bloginfo( 'admin_email' ) ),
- 'admin-email-name' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
- 'admin-email-subject' => sprintf( __( 'You made a sale! Yabba Dabba Doo! %s', 'it-l10n-ithemes-exchange' ), '[it_exchange_email show=receipt_id]' ),
- 'admin-email-template' => sprintf( __( "Your friend %s just bought all this awesomeness from your store!
- Order: %s
- %s", 'it-l10n-ithemes-exchange' ), '[it_exchange_email show=fullname]', '[it_exchange_email show=receipt_id]', '[it_exchange_email show=order_table]' ),
- 'receipt-email-address' => esc_attr( get_bloginfo( 'admin_email' ) ),
- 'receipt-email-name' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
- 'receipt-email-subject' => sprintf( __( 'Receipt for Purchase: %s', 'it-l10n-ithemes-exchange' ), '[it_exchange_email show=receipt_id]' ),
- 'receipt-email-template' => sprintf( __( "Hello %s,
- Thank you for your order. Your order's details are below.
- Order: %s
- %s
- %s", 'it-l10n-ithemes-exchange' ), '[it_exchange_email show=name]', '[it_exchange_email show=receipt_id]', '[it_exchange_email show=order_table options=purchase_message]', '[it_exchange_email show=download_list]' ),
- );
- $values = ITUtility::merge_defaults( $values, $defaults );
- return $values;
- }
- /**
- * Prints the settings page for iThemes Exchange
- *
- * @since 0.3.4
- * @return void
- */
- function print_exchange_settings_page() {
- $flush_cache = ! empty( $_POST );
- $settings = it_exchange_get_option( 'settings_general', $flush_cache );
- $form_values = empty( $this->error_message ) ? $settings : ITForm::get_post_data();
- $form = new ITForm( $form_values, array( 'prefix' => 'it_exchange_settings' ) );
- $form_options = array(
- 'id' => apply_filters( 'it_exchange_settings_form_id', 'it-exchange-settings' ),
- 'enctype' => apply_filters( 'it_exchange_settings_form_enctype', false ),
- );
- if ( ! empty ( $this->status_message ) )
- ITUtility::show_status_message( $this->status_message );
- if ( ! empty( $this->error_message ) )
- ITUtility::show_error_message( $this->error_message );
- include( 'views/admin-settings.php' );
- }
- /**
- * Prints the email page for iThemes Exchange
- *
- * @since 0.3.4
- * @return void
- */
- function print_email_settings_page() {
- $flush_cache = ! empty( $_POST );
- $settings = it_exchange_get_option( 'settings_email', $flush_cache );
- $form_values = empty( $this->error_message ) ? $settings : ITForm::get_post_data();
- $form = new ITForm( $form_values, array( 'prefix' => 'it_exchange_email_settings' ) );
- $form_options = array(
- 'id' => apply_filters( 'it_exchange_email_settings_form_id', 'it-exchange-email-settings' ),
- 'enctype' => apply_filters( 'it_exchange_email_settings_form_enctype', false ),
- 'action' => 'admin.php?page=it-exchange-settings&tab=email',
- );
- if ( ! empty ( $this->status_message ) )
- ITUtility::show_status_message( $this->status_message );
- if ( ! empty( $this->error_message ) )
- ITUtility::show_error_message( $this->error_message );
- include( 'views/admin-email-settings.php' );
- }
- /**
- * Prints the pages page for iThemes Exchange
- *
- * @since 0.3.7
- * @return void
- */
- function print_pages_settings_page() {
- $flush_cache = ! empty( $_POST );
- $pages = it_exchange_get_pages( $flush_cache );
- $settings = array();
- // Setup form field values for each page
- foreach( $pages as $page => $data ) {
- $settings[$page . '-slug'] = it_exchange_get_page_slug( $page );
- $settings[$page . '-name'] = it_exchange_get_page_name( $page );
- $settings[$page . '-type'] = it_exchange_get_page_type( $page );
- $settings[$page . '-wpid'] = it_exchange_get_page_wpid( $page );
- }
- $form_values = empty( $this->error_message ) ? $settings : ITForm::get_post_data();
- $form = new ITForm( $form_values, array( 'prefix' => 'it_exchange_page_settings' ) );
- $form_options = array(
- 'id' => apply_filters( 'it_exchange_page_settings_form_id', 'it-exchange-page-settings' ),
- 'enctype' => apply_filters( 'it_exchange_page_settings_form_enctype', false ),
- 'action' => 'admin.php?page=it-exchange-settings&tab=pages',
- );
- if ( ! empty ( $this->status_message ) )
- ITUtility::show_status_message( $this->status_message );
- if ( ! empty( $this->error_message ) )
- ITUtility::show_error_message( $this->error_message );
- include( 'views/admin-page-settings.php' );
- }
- /**
- * Sets the Pages settings default values
- *
- * @since 0.4.0
- * @return array
- */
- function set_pages_settings_defaults( $values ) {
- $registered = it_exchange_get_registered_pages();
- $defaults = array();
- foreach( $registered as $page => $options ) {
- $defaults[$page . '-name'] = $options['name'];
- $defaults[$page . '-slug'] = $options['slug'];
- $defaults[$page . '-type'] = $options['type'];
- $defaults[$page . '-wpid'] = $options['wpid'];
- }
- $values = ITUtility::merge_defaults( $values, $defaults );
- return $values;
- }
- /**
- * Prints the add-ons page in the admin area
- *
- * @since 0.2.0
- * @return void
- */
- function print_exchange_add_ons_page() {
- $add_on_cats = it_exchange_get_addon_categories();
- $message = empty( $_GET['message'] ) ? false : $_GET['message'];
- if ( 'enabled' == $message ) {
- ITUtility::show_status_message( __( 'Add-on enabled.', 'it-l10n-ithemes-exchange' ) );
- } else if ( 'disabled' == $message ) {
- ITUtility::show_status_message( __( 'Add-on disabled.', 'it-l10n-ithemes-exchange' ) );
- } else if ( 'addon-auto-disabled-' == substr( $message, 0, 20 ) ) {
- $addon_slug = substr( $message, 20 );
- $status_message = __( sprintf( 'iThemes Exchange has automatically disabled an add-on: %s. This is mostly likely due to it being uninstalled or improperlly registered.', $addon_slug ), 'it-l10n-ithemes-exchange' );
- ITUtility::show_status_message( $status_message );
- }
- $error= empty( $_GET['error'] ) ? false : $_GET['error'];
- if ( 'enabled' == $error )
- ITUtility::show_error_message( __( 'Error: Add-on not enabled.', 'it-l10n-ithemes-exchange' ) );
- else if ( 'disabled' == $error )
- ITUtility::show_error_message( __( 'Error: Add-on not disabled.', 'it-l10n-ithemes-exchange' ) );
- include( 'views/admin-add-ons.php' );
- }
- /**
- * Enable all addons tagged as "required"
- *
- * @since 0.4.0
- *
- * @return void
- */
- function enable_required_add_ons() {
- $registered = it_exchange_get_addons();
- $enabled = it_exchange_get_enabled_addons();
- foreach ( $registered as $slug => $params ) {
- if ( !empty( $params['options']['tag'] ) && 'required' === $params['options']['tag'] ) {
- if ( empty( $enabled[$slug] ) ) {
- $enabled_addon = it_exchange_enable_addon( $slug );
- }
- }
- }
- }
- /**
- * Adds the it-exchange-admin CSS class to body on Exchange admin pages
- *
- * @since 0.4.17
- *
- * @param string $classes incoming classes from WP filter
- * @return string
- */
- function add_exchange_class_to_exchange_pages( $classes ) {
- if ( $this->is_exchange_admin_page() ) {
- $classes = explode( ' ', $classes );
- $classes[] = 'it-exchange-admin';
- $classes = implode( ' ', $classes );
- }
- return $classes;
- }
- /**
- * Is this an exchange admin page?
- *
- * @since 0.4.17
- *
- * @return boolean
- */
- function is_exchange_admin_page() {
- $is_exchange_admin = false;
- // Is this an exchange post type?
- $post_types = array(
- 'it_exchange_prod',
- 'it_exchange_tran',
- 'it_exchange_coupon',
- 'it_exchange_download',
- );
- if ( ! empty( $_GET['post_type'] ) && in_array( $_GET['post_type'], (array) apply_filters( 'it_exchange_post_types', $post_types ) ) )
- $is_exchange_admin = true;
- // Are we editing an exchange product type
- if ( ! empty( $_GET['action'] ) && 'edit' == $_GET['action'] && ! empty( $_GET['post'] ) && in_array( get_post_type( $_GET['post'] ), (array) apply_filters( 'it_exchange_post_types', $post_types ) ) )
- $is_exchange_admin = true;
- // Is this an Exchange page
- $pages = array(
- 'it-exchange-settings',
- 'it-exchange-addons',
- 'it-exchange-help',
- 'it-exchange-setup',
- );
- if ( ! empty( $this->_current_page ) && in_array( $this->_current_page, (array) apply_filters( 'it_exchange_admin_pages', $pages ) ) )
- $is_exchange_admin = true;
- return $is_exchange_admin;
- }
- /**
- * Adds a registered Add-on to list of enabled add-ons
- *
- * @since 0.2.0
- */
- function enable_disable_registered_add_on() {
- $enable_addon = empty( $_GET['it-exchange-enable-addon'] ) ? false : $_GET['it-exchange-enable-addon'];
- $disable_addon = empty( $_GET['it-exchange-disable-addon'] ) ? false : $_GET['it-exchange-disable-addon'];
- $tab = empty( $_GET['tab'] ) ? false : $_GET['tab'];
- if ( ! $enable_addon && ! $disable_addon )
- return;
- $registered = it_exchange_get_addons();
- // Enable or Disable addon requested by user
- if ( $enable_addon ) {
- if ( $nonce_valid = wp_verify_nonce( $_GET['_wpnonce'], 'exchange-enable-add-on' ) )
- $enabled = it_exchange_enable_addon( $enable_addon );
- $message = 'enabled';
- } else if ( $disable_addon ) {
- if ( $nonce_valid = wp_verify_nonce( $_GET['_wpnonce'], 'exchange-disable-add-on' ) )
- $enabled = it_exchange_disable_addon( $disable_addon );
- $message = 'disabled';
- }
- // Redirect if nonce not valid
- if ( ! $nonce_valid ) {
- wp_safe_redirect( admin_url( '/admin.php?page=it-exchange-addons&tab=' . $tab . '&error=' . $message ) );
- die();
- }
- // Disable any enabled add-ons that aren't registered any more while we're here.
- $enabled_addons = it_exchange_get_enabled_addons();
- foreach( (array) $enabled_addons as $slug => $params ) {
- if ( empty( $registered[$slug] ) )
- it_exchange_disable_addon( $slug );
- }
- $redirect_to = admin_url( '/admin.php?page=it-exchange-addons&tab=' . $tab . '&message=' . $message );
- // Redirect to settings page on activation if it exists
- if ( $enable_addon ) {
- if ( $enabled = it_exchange_get_addon( $enable_addon ) ) {
- if ( ! empty( $enabled['options']['settings-callback'] ) && is_callable( $enabled['options']['settings-callback'] ) )
- $redirect_to .= '&add-on-settings=' . $enable_addon;
- }
- }
- wp_safe_redirect( $redirect_to );
- die();
- }
- /**
- * Opens the iThemes Exchange Admin Menu when viewing the Add New page
- *
- * @since 0.3.0
- * @return string
- */
- function open_exchange_menu_on_post_type_views( $parent_file, $revert=false ) {
- global $submenu_file, $pagenow, $post;
- if ( 'post-new.php' != $pagenow && 'post.php' != $pagenow )
- return $parent_file;
- if ( empty( $post->post_type ) || ( 'it_exchange_prod' != $post->post_type && 'it_exchange_tran' != $post->post_type ) )
- return $parent_file;
- // Set Add New as bold when on the post-new.php screen
- if ( 'post-new.php' == $pagenow ) {
- if ( ! empty( $_GET['it-exchange-product-type'] ) )
- $submenu_file = "post-new.php?post_type=it_exchange_prod&it-exchange-product-type={$_GET['it-exchange-product-type']}";
- else
- $submenu_file = 'it-exchange-choose-product-type';
- }
- // Return it-exchange as the parent (open) menu when on post-new.php and post.php for it_exchange_prod post_types
- return 'it-exchange';
- }
- /**
- * Redirects post-new.php to it-exchange-choose-product-type when needed
- *
- * If we have landed on post-new.php?post_type=it_exchange_prod without the product_type param
- * and with multiple product-type add-ons enabled.
- *
- * @since 0.3.1
- * @return void
- */
- function redirect_post_new_to_product_type_selection_screen() {
- global $pagenow;
- $product_type_add_ons = it_exchange_get_enabled_addons( array( 'category' => array( 'product-type' ) ) );
- $post_type = empty( $_GET['post_type'] ) ? false : $_GET['post_type'];
- $product_type = empty( $_GET['it-exchange-product-type'] ) ? false : $_GET['it-exchange-product-type'];
- if ( ! empty( $product_type ) )
- return;
- if ( count( $product_type_add_ons ) > 1 && 'post-new.php' == $pagenow && 'it_exchange_prod' == $post_type ) {
- $product_type_add_ons = reset( $product_type_add_ons );
- if ( ! empty( $product_type_add_ons['slug'] ) ) {
- wp_safe_redirect( add_query_arg( 'it-exchange-product-type', $product_type_add_ons['slug'] ) );
- die();
- }
- }
- }
- /**
- * Prints select options for the currency type
- *
- * @since 0.3.6
- * return array
- */
- function get_default_currency_options() {
- $options = array();
- $currency_options = it_exchange_get_data_set( 'currencies' );
- foreach( (array) $currency_options as $cc => $currency ) {
- $options[$cc] = ucwords( $currency['name'] ) . ' (' . $currency['symbol'] . ')';
- }
- return $options;
- }
- /**
- * AJAX callback for general settings country states UI
- *
- * @since 1.2.0
- *
- * @return void
- */
- function update_country_state_ui_in_general_settings() {
- $base_country = empty( $_POST['ite_base_country_ajax'] ) ? 'US' : $_POST['ite_base_country_ajax'];
- $base_state = empty( $_POST['ite_base_state_ajax'] ) ? 'OK' : $_POST['ite_base_state_ajax'];
- $states = it_exchange_get_data_set( 'states', array( 'country' => $base_country ) );
- // Fire off one of the following two functions.
- if ( ! empty( $states ) ) {
- ?>
- <select name="it_exchange_settings-company-base-state" id="company-base-state">
- <?php foreach( $states as $key => $value ) : ?>
- <option value="<?php esc_attr_e( $key ); ?>" <?php selected( $key, $base_state ); ?>><?php esc_attr_e( $value ); ?></option>
- <?php endforeach; ?>
- </select>
- <?php
- die();
- } else {
- ?>
- <input class="small-text" max-length="3" type="text" name="it_exchange_settings-company-base-state" id="company-base-state" value="">
- <p class="description">
- <?php printf( __( 'Please use the 2-3 character %sISO abbreviation%s for country subdivisions', 'it-l10n-ithemes-exchange' ), '<a href="http://en.wikipedia.org/wiki/ISO_3166-2" target="_blank">', '</a>' ); ?>
- </p>
- <?php
- die();
- }
- }
- /**
- * Save core general settings
- *
- * Validates data and saves to options.
- *
- * @since 0.3.4
- *
- * @return void
- */
- function save_core_general_settings() {
- if ( empty( $_POST ) || 'it-exchange-settings' != $this->_current_page || ! empty( $this->_current_tab ) )
- return;
- $settings = wp_parse_args( ITForm::get_post_data(), it_exchange_get_option( 'settings_general' ) );
- // Check nonce
- if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'exchange-general-settings' ) ) {
- $this->error_message = __( 'Error. Please try again', 'it-l10n-ithemes-exchange' );
- return;
- }
- if ( ! empty( $this->error_message ) || $error_msg = $this->general_settings_are_invalid( $settings ) ) {
- if ( ! empty( $error_msg ) )
- $this->error_message = $error_msg;
- } else {
- it_exchange_save_option( 'settings_general', $settings );
- $this->status_message = __( 'Settings Saved.', 'it-l10n-ithemes-exchange' );
- }
- }
- /**
- * Save core general settings from Wizard and performs action for other addons to handle saving
- *
- * Validates data and saves to options.
- *
- * @since 0.3.4
- *
- * @return void
- */
- function save_core_wizard_settings() {
- // Abandon if not saving wizard
- if ( !( isset( $_REQUEST['it_exchange_settings-wizard-submitted'] ) && 'it-exchange-setup' === $this->_current_page ) )
- return;
- if ( empty( $_REQUEST['it-exchange-transaction-methods'] ) ) {
- it_exchange_add_message( 'error', __( 'You must select at least one Payment Method.', 'it-l10n-ithemes-exchange' ) );
- return;
- }
- // Grab general settings
- $general_settings = array();
- $default_wizard_general_settings = apply_filters( 'default_wizard_general_settings', array( 'company-email', 'default-currency' ) );
- foreach( $default_wizard_general_settings as $var ) {
- if ( isset( $_REQUEST['it_exchange_settings-' . $var] ) )
- $general_settings[$var] = $_REQUEST['it_exchange_settings-' . $var];
- }
- $settings = wp_parse_args( $general_settings, it_exchange_get_option( 'settings_general' ) );
- if ( it_exchange_has_messages( 'error' ) || $error_msg = $this->general_settings_are_invalid( $settings ) ) {
- if ( ! empty( $error_msg ) ) {
- it_exchange_add_message( 'error', $error_msg );
- return;
- }
- }
- // Save activated product types
- $product_addons = it_exchange_get_addons( array( 'category' => 'product-type' ) );
- // Filter out simple products
- if ( isset( $product_addons['simple-product-type'] ) )
- unset( $product_addons['simple-product-type'] );
- // Disable all of the product-type addons accept for simple
- foreach( $product_addons as $product_addon_slug => $options ) {
- it_exchange_disable_addon( $product_addon_slug );
- }
- // Loop through selected and renable them.
- if ( ! empty( $_REQUEST['it-exchange-product-types'] ) && is_array( $_REQUEST['it-exchange-product-types'] ) ) {
- foreach( $_REQUEST['it-exchange-product-types'] as $product_addon ) {
- it_exchange_enable_addon( $product_addon );
- }
- }
- // Handle core Simple Shipping addon settings here
- if ( empty( $_REQUEST['it-exchange-shipping-methods'] ) || ( ! in_array( 'simple-shipping-flat-rate', $_REQUEST['it-exchange-shipping-methods'] ) && ! in_array( 'simple-shipping-free', $_REQUEST['it-exchange-shipping-methods'] ) ) ) {
- it_exchange_disable_addon( 'simple-shipping' );
- } else {
- it_exchange_enable_addon( 'simple-shipping' );
- $simple_shipping_options = it_exchange_get_option( 'simple-shipping', true );
- $simple_shipping_options['enable-flat-rate-shipping'] = in_array( 'simple-shipping-flat-rate', $_REQUEST['it-exchange-shipping-methods'] );
- $simple_shipping_options['enable-free-shipping'] = in_array( 'simple-shipping-free', $_REQUEST['it-exchange-shipping-methods'] );
- if ( ! empty( $simple_shipping_options['enable-flat-rate-shipping'] ) ) {
- $flat_rate_default_cost = $_REQUEST['it_exchange_settings-simple-shipping-flat-rate-cost'];
- $simple_shipping_options['flat-rate-shipping-amount'] = $flat_rate_default_cost;
- }
- it_exchange_save_option( 'simple-shipping', $simple_shipping_options );
- }
- // Transaction Methods
- $tx_error_msgs = array();
- $addons = it_exchange_get_addons( array( 'category' => 'transaction-methods', 'show_required' => false ) );
- foreach( $_REQUEST['it-exchange-transaction-methods'] as $add_on ) {
- it_exchange_enable_addon( $add_on );
- unset( $addons[$add_on] );
- $tx_error_msgs = apply_filters( 'it_exchange_save_' . $add_on . '_wizard_settings', $tx_error_msgs );
- }
- foreach ( $addons as $addon ) {
- it_exchange_disable_addon( $addon['slug'] );
- }
- if ( ! empty( $tx_error_msgs ) ) {
- foreach( (array) $tx_error_msgs as $msg ) {
- it_exchange_add_message( 'error', $msg );
- }
- return;
- }
- // Signup for mailchimp if checkbox was checked
- if ( !empty( $_REQUEST['it_exchange_settings-exchange-notifications'] )
- && !empty( $_REQUEST['it_exchange_settings-company-email'] ) ) {
- $this->mail_chimp_signup( $_REQUEST['it_exchange_settings-company-email'] );
- }
- // Auto enable any core add-ons we want enabled on setup.
- $auto_enabled_addons = array(
- 'basic-reporting',
- );
- foreach( $auto_enabled_addons as $addon ) {
- it_exchange_enable_addon( $addon );
- }
- it_exchange_save_option( 'settings_general', $settings );
- do_action( 'it_exchange_enabled_addons_loaded' );
- do_action( 'it_exchange_save_wizard_settings' );
- $settings = it_exchange_get_option( 'settings_general', true );
- $sample_product = empty( $settings['sample-product-id'] ) ? false : it_exchange_get_product( $settings['sample-product-id'] );
- $settings_saved = __( 'Settings Saved. Congrats!', 'it-l10n-ithemes-exchange' );
- $add_product_link = sprintf( __( '%sAdd a Product%s', 'it-l10n-ithemes-exchange' ), '<a href="' . get_admin_url() . 'post-new.php?post_type=it_exchange_prod&it-exchange-product-type=digital-downloads-product-type">', '</a>' );
- $view_addons_link = sprintf( __( '%sEnable Add-ons%s', 'it-l10n-ithemes-exchange' ), '<a href="' . get_admin_url() . 'admin.php?page=it-exchange-addons">', '</a>' );
- $view_sample_link = empty( $sample_product->ID ) ? '' : ' | ' . sprintf( __( '%sView Sample Product%s', 'it-l10n-ithemes-exchange' ), '<a href="' . get_admin_url() . 'post.php?post=' . $sample_product->ID . '&action=edit">', '</a>' );
- it_exchange_add_message( 'notice', $settings_saved . ' ' . $add_product_link . ' | ' . $view_addons_link . $view_sample_link );
- wp_redirect( get_admin_url() . 'admin.php?page=it-exchange-setup&it_exchange_settings-dismiss-wizard-nag=1' );
- die();
- }
- public function mail_chimp_signup( $email ) {
- $email = trim( $email );
- if ( is_email( $email ) ) {
- $mailchimp = 'http://ithemes.us2.list-manage.com/subscribe/post?u=7acf83c7a47b32c740ad94a4e&id=9da0741ac0';
- $query = array(
- 'body' => array(
- 'EMAIL' => $email,
- ),
- );
- wp_remote_post( $mailchimp, $query );
- }
- }
- /**
- * Validate general settings
- *
- * @since 0.3.6
- * @param string $settings submitted settings
- * @return false or error message
- */
- function general_settings_are_invalid( $settings ) {
- $errors = array();
- if ( ! empty( $settings['company-email'] ) && ! is_email( $settings['company-email'] ) )
- $errors[] = __( 'Please provide a valid email address.', 'it-l10n-ithemes-exchange' );
- if ( empty( $settings['currency-thousands-separator'] ) )
- $errors[] = __( 'Thousands Separator cannot be empty', 'it-l10n-ithemes-exchange' );
- if ( empty( $settings['currency-decimals-separator'] ) )
- $errors[] = __( 'Decimals Separator cannot be empty', 'it-l10n-ithemes-exchange' );
- $errors = apply_filters( 'it_exchange_general_settings_validation_errors', $errors );
- if ( ! empty ( $errors ) )
- return implode( '<br />', $errors );
- else
- return false;
- }
- /**
- * Save core email tab settings
- *
- * Validates data and saves to options.
- *
- * @since 0.3.4
- * @return void
- */
- function save_core_email_settings() {
- if ( empty( $_POST ) || 'it-exchange-settings' != $this->_current_page || 'email' != $this->_current_tab )
- return;
- // Check nonce
- if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'exchange-email-settings' ) ) {
- $this->error_message = __( 'Error. Please try again', 'it-l10n-ithemes-exchange' );
- return;
- }
- $settings = wp_parse_args( ITForm::get_post_data(), it_exchange_get_option( 'settings_email' ) );
- if ( ! empty( $this->error_message ) || $error_msg = $this->email_settings_are_invalid( $settings ) ) {
- if ( ! empty( $error_msg ) )
- $this->error_message = $error_msg;
- } else {
- it_exchange_save_option( 'settings_email', $settings );
- $this->status_message = __( 'Settings Saved.', 'it-l10n-ithemes-exchange' );
- }
- }
- /**
- * Validate email settings
- *
- * @since 0.3.6
- * @param string $settings submitted settings
- * @return false or error message
- */
- function email_settings_are_invalid( $settings ) {
- $errors = array();
- if ( empty( $settings['receipt-email-address'] )
- || ( !empty( $settings['receipt-email-address'] ) && ! is_email( $settings['receipt-email-address'] ) ) )
- $errors[] = __( 'Please provide a valid email address.', 'it-l10n-ithemes-exchange' );
- if ( empty( $settings['receipt-email-name'] ) )
- $errors[] = __( 'Email Name cannot be empty', 'it-l10n-ithemes-exchange' );
- if ( empty( $settings['receipt-email-subject'] ) )
- $errors[] = __( 'Email Subject cannot be empty', 'it-l10n-ithemes-exchange' );
- if ( empty( $settings['receipt-email-template'] ) )
- $errors[] = __( 'Email Template cannot be empty', 'it-l10n-ithemes-exchange' );
- if ( !empty( $settings['notification-email-address'] ) ) {
- $emails = explode( ',', $settings['notification-email-address'] );
- foreach( $emails as $email ) {
- if ( !is_email( trim( $email ) ) ) {
- $errors[] = __( 'Invalid email address in Sales Notification Email Address', 'it-l10n-ithemes-exchange' );
- break;
- }
- }
- }
- $errors = apply_filters( 'it_exchange_email_settings_validation_errors', $errors );
- if ( ! empty ( $errors ) )
- return '<p>' . implode( '<br />', $errors ) . '</p>';
- else
- return false;
- }
- /**
- * Save core pages tab settings
- *
- * Validates data and saves to options.
- *
- * @since 0.3.7
- * @return void
- */
- function save_core_page_settings() {
- if ( empty( $_POST ) || 'it-exchange-settings' != $this->_current_page || 'pages' != $this->_current_tab )
- return;
- // Grab page settings from DB
- $existing = it_exchange_get_pages( true );
- $settings = array();
- // Format for settings form
- foreach( $existing as $page => $data ) {
- $settings[$page . '-slug'] = it_exchange_get_page_slug( $page );
- $settings[$page . '-name'] = it_exchange_get_page_name( $page );
- $settings[$page . '-type'] = it_exchange_get_page_type( $page );
- $settings[$page . '-wpid'] = it_exchange_get_page_wpid( $page );
- }
- $settings = wp_parse_args( ITForm::get_post_data(), $settings );
- // If WordPress page is set to 0 somehow, use exchange page
- foreach( $existing as $page => $data ) {
- if ( 'wordpress' == $settings[$page . '-type'] && empty( $settings[$page . '-wpid'] ) )
- $settings[$page . '-type'] = 'exchange';
- }
- // Check nonce
- if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'exchange-page-settings' ) ) {
- $this->error_message = __( 'Error. Please try again', 'it-l10n-ithemes-exchange' );
- return;
- }
- // Trim all slug settings
- foreach( $settings as $key => $value ) {
- if ( 'slug' == substr( $key, -4 ) )
- $settings[$key] = sanitize_title( $value );
- else
- $settings[$key] = trim($value);
- }
- if ( ! empty( $this->error_message ) || $error_msg = $this->…
Large files files are truncated, but you can click here to view the full file