diff --git a/assets/images/svg/close.svg b/assets/src/images/close.svg similarity index 100% rename from assets/images/svg/close.svg rename to assets/src/images/close.svg diff --git a/assets/src/js/admin/admin-scripts.js b/assets/src/js/admin/admin-scripts.js index 29f1716603..349acfe17b 100644 --- a/assets/src/js/admin/admin-scripts.js +++ b/assets/src/js/admin/admin-scripts.js @@ -1071,7 +1071,7 @@ var give_setting_edit = false; self.process_step(parseInt(response.step), data, self); } - if (true === reset_form) { + if ( true === reset_form && $( '#give-tools-recount-form' ).length > 0 ) { // Reset the form for preventing multiple ajax request. $('#give-tools-recount-form')[0].reset(); $('#give-tools-recount-form .tools-form-dropdown').hide(); diff --git a/includes/actions.php b/includes/actions.php index 1bc1632bbc..d8bad22ae0 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -332,6 +332,4 @@ function give_update_log_form_id( $args ) { Give()->logs->delete_cache(); } -add_action( 'give_update_log_form_id', 'give_update_log_form_id' ); - - +add_action( 'give_update_log_form_id', 'give_update_log_form_id' ); \ No newline at end of file diff --git a/includes/admin/class-addon-activation-banner.php b/includes/admin/class-addon-activation-banner.php index a41202361c..7d42bf16af 100644 --- a/includes/admin/class-addon-activation-banner.php +++ b/includes/admin/class-addon-activation-banner.php @@ -4,7 +4,6 @@ * * @author WordImpress * @version 1.0 - * https://github.com/WordImpress/plugin-activation-banner-demo */ // Exit if accessed directly. @@ -12,8 +11,12 @@ exit; } +global $give_addons; + /** * Class Give_Addon_Activation_Banner + * + * @since 2.0.7 Added pleasing interface when multiple add-ons are activated. */ class Give_Addon_Activation_Banner { @@ -33,22 +36,38 @@ class Give_Addon_Activation_Banner { * } */ function __construct( $_banner_details ) { - $current_user = wp_get_current_user(); + global $give_addons; - $this->plugin_activate_by = 0; - $this->banner_details = $_banner_details; - $this->test_mode = ( $this->banner_details['testing'] == 'true' ) ? true : false; - $this->nag_meta_key = 'give_addon_activation_ignore_' . sanitize_title( $this->banner_details['name'] ); - $this->activate_by_meta_key = 'give_addon_' . sanitize_title( $this->banner_details['name'] ) . '_active_by_user'; + // Append add-on information to the global variable. + $give_addons[] = $_banner_details; + + // Get the current user. + $current_user = wp_get_current_user(); //Get current user $this->user_id = $current_user->ID; - // Set up hooks. - $this->init(); + // Only if single add-on activated. + if ( 1 === count( $give_addons ) ) { + + $this->plugin_activate_by = 0; + $this->banner_details = $_banner_details; + $this->test_mode = ( $this->banner_details['testing'] == 'true' ) ? true : false; + $this->nag_meta_key = 'give_addon_activation_ignore_' . sanitize_title( $this->banner_details['name'] ); + $this->activate_by_meta_key = 'give_addon_' . sanitize_title( $this->banner_details['name'] ) . '_active_by_user'; + + // Set up hooks. + $this->init(); - // Store user id who activate plugin. - $this->add_addon_activate_meta(); + // Store user id who activated plugin. + $this->add_addon_activate_meta(); + } + + // Check if notice callback is already hooked. + if ( ! $this->is_banner_notice_hooked() ) { + // If multiple add-on are activated then show activation banner in tab view. + add_action( 'admin_notices', array( $this, 'addon_activation_banner_notices' ), 10 ); + } } /** @@ -61,14 +80,13 @@ function __construct( $_banner_details ) { */ public function init() { - //Testing? + // Testing? if ( $this->test_mode ) { delete_user_meta( $this->user_id, $this->nag_meta_key ); } - //Get the current page to add the notice to + // Get the current page to add the notice to add_action( 'current_screen', array( $this, 'give_addon_notice_ignore' ) ); - add_action( 'admin_notices', array( $this, 'give_addon_activation_admin_notice' ) ); // File path of addon must be included in banner detail other addon activate meta will not delete. $file_name = $this->get_plugin_file_name(); @@ -78,106 +96,193 @@ public function init() { } } + /** + * Get plugin file name. + * + * @since 1.8 + * @access private + * @return mixed + */ + private function get_plugin_file_name() { + $active_plugins = get_option( 'active_plugins' ); + $file_name = ''; + + try { + + // Check addon file path. + if ( ! empty( $this->banner_details['file'] ) ) { + $file_name = ''; + if ( $file_path = explode( '/plugins/', $this->banner_details['file'] ) ) { + $file_path = array_pop( $file_path ); + $file_name = current( explode( '/', $file_path ) ); + } + + if ( empty( $file_name ) ) { + return false; + } + + foreach ( $active_plugins as $plugin ) { + if ( false !== strpos( $plugin, $file_name ) ) { + $file_name = $plugin; + break; + } + } + } elseif ( WP_DEBUG ) { + throw new Exception( __( "File path must be added within the {$this->banner_details['name']} add-on in the banner details.", 'give' ) ); + } + + // Check plugin path calculated by addon file path. + if ( empty( $file_name ) && WP_DEBUG ) { + throw new Exception( __( "Empty add-on plugin path for {$this->banner_details['name']} add-on.", 'give' ) ); + } + + } catch ( Exception $e ) { + echo $e->getMessage(); + } + + return $file_name; + } /** - * Check if current page is plugin page or not. + * Setup user id to option * * @since 1.8 * @access private - * @return bool */ - private function is_plugin_page() { - $screen = get_current_screen(); + private function add_addon_activate_meta() { + $user_id = get_option( $this->activate_by_meta_key ); + $this->plugin_activate_by = (int) $user_id; - return ( $screen->parent_file === 'plugins.php' ); + if ( ! $user_id ) { + add_option( $this->activate_by_meta_key, $this->user_id, '', 'no' ); + $this->plugin_activate_by = (int) $this->user_id; + } } + /** + * Check if the addon_activation_banner_notices function has already been hooked to admin_notice. + * + * @since 2.0.7 + * + * @return bool + */ + public function is_banner_notice_hooked() { + global $wp_filter; + $notice_already_hooked = false; + + if ( isset( $wp_filter['admin_notices']->callbacks[10] ) ) { + + // Get all of the hooks. + $admin_notice_callbacks = array_keys( $wp_filter['admin_notices']->callbacks[10] ); + + foreach ( $admin_notice_callbacks as $key ) { + //If the key is found in your string, set $found to true + if ( false !== strpos( $key, 'addon_activation_banner_notices' ) ) { + $notice_already_hooked = true; + } + } + } + + return $notice_already_hooked; + } /** - * Give Addon Activation Banner + * Get the add-on banner notices. * - * @since 1.0 - * @access public + * @since 2.0.7 */ - public function give_addon_activation_admin_notice() { + public function addon_activation_banner_notices() { + global $pagenow, $give_addons; // Bailout. - if ( ! $this->is_plugin_page() || $this->user_id !== $this->plugin_activate_by ) { - return; + if ( 'plugins.php' !== $pagenow || $this->user_id !== $this->plugin_activate_by ) { + return false; } - // If the user hasn't already dismissed the alert, output activation banner. - if ( ! get_user_meta( $this->user_id, $this->nag_meta_key ) ) { + // Store the add-ons of which activation banner should be shown. + $addon_to_display = array(); - $this->print_css(); + // Go through each of the give add-on. + foreach ( $give_addons as $addon ) { + $add_on_state = get_user_meta( $this->user_id, 'give_addon_activation_ignore_' . sanitize_title( $addon['name'] ), true ); - // Output inline styles here because there's no reason - // to enqueued them after the alert is dismissed. + // If add-on were never dismissed. + if ( 'true' !== $add_on_state ) { + $addon_to_display[] = $addon; + } + } - ob_start(); - ?> + if ( empty( $addon_to_display ) ) { + return false; + } - + // Output inline styles here because there's no reason + // to enqueued them after the alert is dismissed. + $this->print_css_js(); + ob_start(); + ?> +
+ +
+
+
    + +
  • + +
  • + +
+
+
+ +
+ nag_meta_key + : 'give_addon_activation_ignore_all'; + + $this->render_single_addon_banner( $banner, $meta_key ); + ?> +
+ +
+
+ render_single_addon_banner( $addon_to_display[0] ); + } + ?> +
notices->register_notice( array( - 'id' => 'give_' . sanitize_title( $this->banner_details['name'] ) . '_notice', + 'id' => 'give_add_on_activation_notice', 'type' => 'updated', 'description_html' => $notice_html, 'show' => true, @@ -185,87 +290,380 @@ class="dashicons dashicons-dismiss"> } } + /** + * Get the notice dismiss meta key. + * + * @since 2.0.7 + */ + public function get_notice_dismiss_meta_key() { + global $give_addons; + + // Get the notice meta key. + $notice_meta_key = ( 1 === count( $give_addons ) ) + ? $this->nag_meta_key + : 'give_addon_activation_ignore_all'; + + // Return meta key. + return $notice_meta_key; + } /** - * Add activation banner css. + * Add activation banner css and js . * * @since 1.8.16 + * @since 2.0.7 Added JS code for multiple add-on. * @access private */ - private function print_css() { + private function print_css_js() { ?> - + + + + + $addon ) { + if ( isset( $banner_arr['name'] ) && strpos( $addon['Name'], $banner_arr['name'] ) !== false ) { + $plugin_file = WP_PLUGIN_DIR . '/' . $main_file; } + } - div.give-addon-alert .dismiss:hover { - color: #333; - } - + // Get the add-on details. + $plugin_data = get_plugin_data( $plugin_file ); + ?> + +
+

+ ' . $banner_arr['name'] . '' + ); + ?> +

+ nag_meta_key : $meta_key; + $nag_admin_dismiss_url = admin_url( 'plugins.php?' . $meta_key . '=0' ); + ?> + + + +
+ +
+ + + + + + + + + + + + +
+
nag_meta_key + : 'give_addon_activation_ignore_all'; /** * If user clicks to ignore the notice, add that to their user meta the banner then checks whether this tag exists already or not. * See here: http://codex.wordpress.org/Function_Reference/add_user_meta */ - if ( isset( $_GET[ $this->nag_meta_key ] ) && '0' == $_GET[ $this->nag_meta_key ] ) { + if ( isset( $_GET[ $notice_meta_key ] ) && '0' === $_GET[ $notice_meta_key ] ) { //Get the global user $current_user = wp_get_current_user(); $user_id = $current_user->ID; - add_user_meta( $user_id, $this->nag_meta_key, 'true', true ); - } - } - - /** - * Setup user id to option - * - * @since 1.8 - * @access private - */ - private function add_addon_activate_meta() { - $user_id = get_option( $this->activate_by_meta_key ); - $this->plugin_activate_by = (int) $user_id; - - if ( ! $user_id ) { - add_option( $this->activate_by_meta_key, $this->user_id, '', 'no' ); - $this->plugin_activate_by = (int) $this->user_id; + if ( 'give_addon_activation_ignore_all' === $notice_meta_key ) { + foreach ( $give_addons as $give_addon ) { + $meta_key = 'give_addon_activation_ignore_' . sanitize_title( $give_addon['name'] ); + add_user_meta( $user_id, $meta_key, 'true', true ); + } + } + add_user_meta( $user_id, $notice_meta_key, 'true', true ); } } - /** * Delete user id from option if plugin deactivated. * @@ -320,53 +713,4 @@ public function remove_addon_activate_meta() { delete_option( $this->activate_by_meta_key ); } } - - - /** - * Get plugin file name. - * - * @since 1.8 - * @access private - * @return mixed - */ - private function get_plugin_file_name() { - $active_plugins = get_option( 'active_plugins' ); - $file_name = ''; - - try { - - // Check addon file path. - if ( ! empty( $this->banner_details['file'] ) ) { - $file_name = ''; - if ( $file_path = explode( '/plugins/', $this->banner_details['file'] ) ) { - $file_path = array_pop( $file_path ); - $file_name = current( explode( '/', $file_path ) ); - } - - if ( empty( $file_name ) ) { - return false; - } - - foreach ( $active_plugins as $plugin ) { - if ( false !== strpos( $plugin, $file_name ) ) { - $file_name = $plugin; - break; - } - } - } elseif ( WP_DEBUG ) { - throw new Exception( sprintf( __( 'File path must be added within the %s add-on in the banner details.', 'give' ), $this->banner_details['name'] ) ); - } - - // Check plugin path calculated by addon file path. - if ( empty( $file_name ) && WP_DEBUG ) { - throw new Exception( sprintf( __( 'Empty add-on plugin path for %s add-on.', 'give' ), $this->banner_details['name'] ) ); - } - - } catch ( Exception $e ) { - echo $e->getMessage(); - } - - return $file_name; - } - } diff --git a/includes/admin/donors/donors.php b/includes/admin/donors/donors.php index 9d708c6234..9092447b7a 100644 --- a/includes/admin/donors/donors.php +++ b/includes/admin/donors/donors.php @@ -427,6 +427,21 @@ class="button info-item editable donor-edit-link"> + + get_meta( '_give_donor_company', true ); + + if ( ! empty( $donor_company ) ) { + ?> + + + + + + + diff --git a/includes/admin/emails/class-email-setting-field.php b/includes/admin/emails/class-email-setting-field.php index fcd0ca2a0f..12229f0d52 100755 --- a/includes/admin/emails/class-email-setting-field.php +++ b/includes/admin/emails/class-email-setting-field.php @@ -25,10 +25,7 @@ public static function get_setting_fields( Give_Email_Notification $email, $form $setting_fields = self::get_default_setting_fields( $email, $form_id ); // Recipient field. - if ( Give_Email_Notification_Util::has_recipient_field( $email ) ) { - $setting_fields[] = self::get_recipient_setting_field( $email, $form_id ); - } - + $setting_fields[] = self::get_recipient_setting_field( $email, $form_id, Give_Email_Notification_Util::has_recipient_field( $email ) ); // Add extra setting field. if ( $extra_setting_field = $email->get_extra_setting_fields( $form_id ) ) { @@ -133,10 +130,10 @@ public static function get_default_setting_fields( Give_Email_Notification $emai $settings[] = self::get_notification_status_field( $email, $form_id ); if ( ! Give_Email_Notification_Util::is_notification_status_editable( $email ) ) { - if( $form_id || give_is_add_new_form_page() ){ + if ( $form_id || give_is_add_new_form_page() ) { // Do not allow admin to disable notification on perform basis. unset( $settings[1]['options']['disabled'] ); - } else{ + } else { // Do not allow admin to edit notification status globally. unset( $settings[1] ); } @@ -145,7 +142,7 @@ public static function get_default_setting_fields( Give_Email_Notification $emai $settings[] = self::get_email_subject_field( $email, $form_id ); $settings[] = self::get_email_message_field( $email, $form_id ); - if( Give_Email_Notification_Util::is_content_type_editable( $email ) ) { + if ( Give_Email_Notification_Util::is_content_type_editable( $email ) ) { $settings[] = self::get_email_content_type_field( $email, $form_id ); } @@ -182,7 +179,7 @@ public static function get_notification_status_field( Give_Email_Notification $e $default_value = 'global'; } - $description = isset($_GET['page']) && 'give-settings' === $_GET['page'] ? __('Choose whether you want this email enabled or not.', 'give') : sprintf( __( 'Global Options are set in Give settings. You may override them for this form here.', 'give' ), admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails' ) ); + $description = isset( $_GET['page'] ) && 'give-settings' === $_GET['page'] ? __( 'Choose whether you want this email enabled or not.', 'give' ) : sprintf( __( 'Global Options are set in Give settings. You may override them for this form here.', 'give' ), admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=emails' ) ); return array( 'name' => esc_html__( 'Notification', 'give' ), @@ -238,7 +235,7 @@ public static function get_email_message_field( Give_Email_Notification $email, $email_tag_list, sprintf( '
%2$s %3$s', - esc_url('http://docs.givewp.com/meta-email-tags'), + esc_url( 'http://docs.givewp.com/meta-email-tags' ), __( 'See our documentation', 'give' ), __( 'for examples of how to use custom meta email tags to output additional donor or donation information in your Give emails.', 'give' ) ) @@ -285,16 +282,17 @@ public static function get_email_content_type_field( Give_Email_Notification $em * Get recipient setting field. * * @since 2.0 - * @access static - * @todo check this field in form metabox setting after form api merge. + * @access public + * @todo check this field in form metabox setting after form api merge. * * @param Give_Email_Notification $email * @param int $form_id + * @param bool $edit_recipient * * @return array */ - public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null ) { - $recipient = array( + public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = null, $edit_recipient = true ) { + $recipient = array( 'id' => self::get_prefix( $email, $form_id ) . 'recipient', 'name' => esc_html__( 'Email Recipients', 'give' ), 'desc' => __( 'Enter the email address(es) that should receive a notification.', 'give' ), @@ -324,6 +322,20 @@ public static function get_recipient_setting_field( Give_Email_Notification $ema ); } + // Disable field if email donor has recipient field. + // @see https://github.com/WordImpress/Give/issues/2657 + if ( ! $edit_recipient ) { + if ( 'group' == $recipient['type'] ) { + $recipient = current( $recipient['fields'] ); + $recipient['type'] = 'text'; + } + + $recipient['attributes']['disabled'] = 'disabled'; + $recipient['value'] = $recipient['default'] = '{donor_email}'; + $recipient['repeat'] = false; + $recipient['desc'] = __( 'This email is sent to the Donor and the recipients cannot be customized.', 'give' ); + } + return $recipient; } @@ -360,10 +372,10 @@ public static function get_preview_setting_field( Give_Email_Notification $email * * @return string */ - public static function get_prefix( Give_Email_Notification $email, $form_id = null ) { + public static function get_prefix( Give_Email_Notification $email, $form_id = null ) { $meta_key = "{$email->config['id']}_"; - if( $form_id || give_is_add_new_form_page() ) { + if ( $form_id || give_is_add_new_form_page() ) { $meta_key = "_give_{$email->config['id']}_"; } diff --git a/includes/admin/forms/class-metabox-form-data.php b/includes/admin/forms/class-metabox-form-data.php index b3f4e31970..1f8dca22cd 100644 --- a/includes/admin/forms/class-metabox-form-data.php +++ b/includes/admin/forms/class-metabox-form-data.php @@ -279,6 +279,20 @@ function get_settings() { 'id' => $prefix . 'default_gateway', 'type' => 'default_gateway', ), + array( + 'name' => __( 'Company Donations', 'give' ), + 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ), + 'id' => $prefix . 'company_field', + 'type' => 'radio_inline', + 'default' => 'global', + 'options' => array( + 'global' => __( 'Global Option', 'give' ), + 'required' => __( 'Required', 'give' ), + 'optional' => __( 'Optional', 'give' ), + 'disabled' => __( 'Disabled', 'give' ), + + ), + ), array( 'name' => __( 'Guest Donations', 'give' ), 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ), diff --git a/includes/admin/payments/view-payment-details.php b/includes/admin/payments/view-payment-details.php index 5a2b79c7c2..2856255d9f 100644 --- a/includes/admin/payments/view-payment-details.php +++ b/includes/admin/payments/view-payment-details.php @@ -42,8 +42,10 @@ wp_die( __( 'The specified ID does not belong to a donation. Please try again.', 'give' ), __( 'Error', 'give' ), array( 'response' => 400 ) ); } -$number = $payment->number; -$payment_meta = $payment->get_meta(); +$number = $payment->number; +$payment_meta = $payment->get_meta(); + +$company_name = ! empty( $payment_meta['_give_donation_company'] ) ? esc_attr( $payment_meta['_give_donation_company'] ) : ''; $transaction_id = esc_attr( $payment->transaction_id ); $user_id = $payment->user_id; $donor_id = $payment->customer_id; @@ -442,6 +444,7 @@

+

+ ()


@@ -569,7 +573,12 @@ ?>

- + +
+

@@ -603,7 +612,6 @@

- ID, 'give_addon_activation_ignore_all' ); + } +} + +add_action( 'activated_plugin', 'give_remove_activation_dismissed_flag', 10, 1 ); + + /** * Create new menu in plugin section that include all the add-on * diff --git a/includes/admin/settings/class-settings-display.php b/includes/admin/settings/class-settings-display.php index 1f466beeea..f805365cab 100644 --- a/includes/admin/settings/class-settings-display.php +++ b/includes/admin/settings/class-settings-display.php @@ -97,6 +97,18 @@ public function get_settings() { 'disabled' => __( 'Disabled', 'give' ), ), ), + array( + 'name' => __( 'Company Donations', 'give' ), + 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ), + 'id' => 'company_field', + 'type' => 'radio_inline', + 'default' => 'disabled', + 'options' => array( + 'disabled' => __( 'Disabled', 'give' ), + 'required' => __( 'Required', 'give' ), + 'optional' => __( 'Optional', 'give' ), + ), + ), array( 'name' => __( 'Display Settings Docs Link', 'give' ), 'id' => 'display_settings_docs_link', diff --git a/includes/admin/shortcodes/shortcode-give-totals.php b/includes/admin/shortcodes/shortcode-give-totals.php index 653052a080..ff2d58b0dd 100644 --- a/includes/admin/shortcodes/shortcode-give-totals.php +++ b/includes/admin/shortcodes/shortcode-give-totals.php @@ -80,14 +80,10 @@ public function define_fields() { 'html' => sprintf( '

%s

', __( 'Shortcode Configuration', 'give' ) ), ), array( - 'type' => 'post', - 'query_args' => array( - 'post_type' => 'give_forms', - ), + 'type' => 'textbox', 'name' => 'ids', - 'label' => __( 'Select a Donation Form:', 'give' ), - 'tooltip' => __( 'Select a Donation Form', 'give' ), - 'placeholder' => '- ' . __( 'Select a Donation Form', 'give' ) . ' -', + 'label' => __( 'Donation Form IDs:', 'give' ), + 'tooltip' => __( 'Enter the IDs separated by commas for the donation forms you would like to combine within the totals.', 'give' ), ), $category_lists, $tag_lists, @@ -95,13 +91,13 @@ public function define_fields() { 'type' => 'textbox', 'name' => 'total_goal', 'label' => __( 'Total Goal:', 'give' ), - 'tooltip' => __( 'Enter the total goal amount.', 'give' ), + 'tooltip' => __( 'Enter the total goal amount that you would like to display.', 'give' ), ), array( 'type' => 'textbox', 'name' => 'message', 'label' => __( 'Message:', 'give' ), - 'tooltip' => __( 'Enter the message.', 'give' ), + 'tooltip' => __( 'Enter a message to display encouraging donors to support the goal.', 'give' ), 'value' => apply_filters( 'give_totals_message', __( 'Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give' ) ), 'multiline' => true, 'minWidth' => 300, @@ -111,20 +107,20 @@ public function define_fields() { 'type' => 'textbox', 'name' => 'link', 'label' => __( 'Link:', 'give' ), - 'tooltip' => __( 'Enter a link of campaign.', 'give' ), + 'tooltip' => __( 'Enter a link to the main campaign donation form.', 'give' ), ), array( 'type' => 'textbox', 'name' => 'link_text', 'label' => __( 'Link Text:', 'give' ), - 'tooltip' => __( 'Enter a text for the Link.', 'give' ), + 'tooltip' => __( 'Enter hyperlink text for the link to the main campaign donation form.', 'give' ), 'value' => __( 'Donate!', 'give' ), ), array( 'type' => 'listbox', 'name' => 'progress_bar', 'label' => __( 'Show Progress Bar:', 'give' ), - 'tooltip' => __( 'Choose Option to show Progress Bar or not with a message.', 'give' ), + 'tooltip' => __( 'Select whether you would like to show a goal progress bar.', 'give' ), 'options' => array( 'true' => __( 'Show', 'give' ), 'false' => __( 'Hide', 'give' ), @@ -136,4 +132,4 @@ public function define_fields() { } } -new Give_Shortcode_Totals; \ No newline at end of file +new Give_Shortcode_Totals; diff --git a/includes/admin/tools/export/class-batch-export-payments.php b/includes/admin/tools/export/class-batch-export-payments.php index 75ed06448d..625e98f58c 100644 --- a/includes/admin/tools/export/class-batch-export-payments.php +++ b/includes/admin/tools/export/class-batch-export-payments.php @@ -39,26 +39,27 @@ class Give_Batch_Payments_Export extends Give_Batch_Export { */ public function csv_cols() { $cols = array( - 'id' => __( 'ID', 'give' ), // unaltered payment ID (use for querying). - 'seq_id' => __( 'Payment Number', 'give' ), // sequential payment ID. - 'email' => __( 'Email', 'give' ), - 'first' => __( 'First Name', 'give' ), - 'last' => __( 'Last Name', 'give' ), - 'address1' => __( 'Address 1', 'give' ), - 'address2' => __( 'Address 2', 'give' ), - 'city' => __( 'City', 'give' ), - 'state' => __( 'State', 'give' ), - 'country' => __( 'Country', 'give' ), - 'zip' => __( 'Zip / Postal Code', 'give' ), - 'form_id' => __( 'Form ID', 'give' ), - 'form_name' => __( 'Form Name', 'give' ), - 'amount' => __( 'Amount', 'give' ) . ' (' . give_currency_symbol( '', true ) . ')', - 'gateway' => __( 'Payment Method', 'give' ), - 'trans_id' => __( 'Transaction ID', 'give' ), - 'key' => __( 'Key', 'give' ), - 'date' => __( 'Date', 'give' ), - 'user' => __( 'User', 'give' ), - 'status' => __( 'Status', 'give' ) + 'id' => __( 'ID', 'give' ), // unaltered payment ID (use for querying). + 'seq_id' => __( 'Payment Number', 'give' ), // sequential payment ID. + 'email' => __( 'Email', 'give' ), + 'first' => __( 'First Name', 'give' ), + 'last' => __( 'Last Name', 'give' ), + 'company_name' => __( 'Company', 'give' ), + 'address1' => __( 'Address 1', 'give' ), + 'address2' => __( 'Address 2', 'give' ), + 'city' => __( 'City', 'give' ), + 'state' => __( 'State', 'give' ), + 'country' => __( 'Country', 'give' ), + 'zip' => __( 'Zip / Postal Code', 'give' ), + 'form_id' => __( 'Form ID', 'give' ), + 'form_name' => __( 'Form Name', 'give' ), + 'amount' => __( 'Amount', 'give' ) . ' (' . give_currency_symbol( '', true ) . ')', + 'gateway' => __( 'Payment Method', 'give' ), + 'trans_id' => __( 'Transaction ID', 'give' ), + 'key' => __( 'Key', 'give' ), + 'date' => __( 'Date', 'give' ), + 'user' => __( 'User', 'give' ), + 'status' => __( 'Status', 'give' ) ); if ( ! give_is_setting_enabled( give_get_option( 'sequential-ordering_status', 'enabled' ) ) ) { @@ -156,6 +157,7 @@ public function get_data() { 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], + 'company_name' => $payment_meta['_give_donation_company'], 'address1' => isset( $user_info['address']['line1'] ) ? $user_info['address']['line1'] : '', 'address2' => isset( $user_info['address']['line2'] ) ? $user_info['address']['line2'] : '', 'city' => isset( $user_info['address']['city'] ) ? $user_info['address']['city'] : '', diff --git a/includes/class-give-cache.php b/includes/class-give-cache.php index f53b785d97..135e5c8cc3 100644 --- a/includes/class-give-cache.php +++ b/includes/class-give-cache.php @@ -543,7 +543,7 @@ public static function delete_group( $ids, $group = '', $expire = 0 ) { // Delete single or multiple cache items from cache. if ( ! is_array( $ids ) ) { - $status = wp_cache_delete( $ids, $group, $expire ); + $status = wp_cache_delete( $ids, $group ); self::$instance->get_incrementer( true ); /** @@ -559,7 +559,7 @@ public static function delete_group( $ids, $group = '', $expire = 0 ) { } else { foreach ( $ids as $id ) { - $status = wp_cache_delete( $id, $group, $expire ); + $status = wp_cache_delete( $id, $group ); self::$instance->get_incrementer( true ); /** @@ -749,7 +749,7 @@ private function filter_group_name( $group ) { if ( ! empty( $group ) ) { $incrementer = self::$instance->get_incrementer( false, 'give-cache-incrementer' ); - if ( 'give-db-queries' === $group ) { + if ( false !== strpos( $group, 'give-db-queries' ) ) { $incrementer = self::$instance->get_incrementer(); } diff --git a/includes/class-give-donor.php b/includes/class-give-donor.php index fd239171ae..a7b0834b49 100644 --- a/includes/class-give-donor.php +++ b/includes/class-give-donor.php @@ -1565,4 +1565,17 @@ public function get_last_name() { return ( $last_name ) ? $last_name : ''; } + + /** + * Retrieves company name of donor + * + * @since 2.0.7 + * + * @return string $company_name Donor Company Name + */ + public function get_company_name() { + $company_name = $this->get_meta( '_give_donor_company' ); + + return $company_name; + } } diff --git a/includes/class-notices.php b/includes/class-notices.php index 929cb984c7..4df53fbc37 100644 --- a/includes/class-notices.php +++ b/includes/class-notices.php @@ -626,7 +626,7 @@ public static function print_frontend_notice( $message, $echo = true, $notice_ty $close_icon = 'manual' === $notice_args['dismiss_type'] ? sprintf( '', - esc_url( GIVE_PLUGIN_URL . 'assets/images/svg/close.svg' ) + esc_url( GIVE_PLUGIN_URL . 'assets/dist/images/close.svg' ) ) : ''; @@ -699,4 +699,4 @@ public function print_admin_notices( $notice_args = array() ) { echo $output; } -} \ No newline at end of file +} diff --git a/includes/emails/class-give-email-tags.php b/includes/emails/class-give-email-tags.php index d8ff88e3da..606bdcc4d7 100644 --- a/includes/emails/class-give-email-tags.php +++ b/includes/emails/class-give-email-tags.php @@ -408,6 +408,12 @@ function give_setup_email_tags() { 'function' => 'give_email_tag_username', 'context' => 'donor', ), + array( + 'tag' => 'company_name', + 'description' => esc_html__( 'Company name.', 'give' ), + 'function' => 'give_email_tag_company_name', + 'context' => 'donation', + ), array( 'tag' => 'user_email', 'description' => esc_html__( 'The donor\'s email address.', 'give' ), @@ -949,6 +955,43 @@ function give_email_tag_form_title( $tag_args ) { ); } +/** + * Email template tag: {company_name} + * Output the donation form company name filed. + * + * @since 2.0.7 + * + * @param array $tag_args + * + * @return string $company_name + */ +function give_email_tag_company_name( $tag_args ) { + $company_name = ''; + + // Backward compatibility. + $tag_args = __give_20_bc_str_type_email_tag_param( $tag_args ); + + switch ( true ) { + case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): + $company_name = give_get_payment_meta( $tag_args['payment_id'], '_give_donation_company', true ); + break; + } + + /** + * Filter the {company_name} email template tag output. + * + * @since 2.0.7 + * + * @param string $company_name + * @param array $tag_args + */ + return apply_filters( + 'give_email_tag_company_name', + $company_name, + $tag_args + ); +} + /** * Email template tag: {payment_method} * diff --git a/includes/forms/functions.php b/includes/forms/functions.php index 0b870b805e..473ee5d9dc 100644 --- a/includes/forms/functions.php +++ b/includes/forms/functions.php @@ -1092,7 +1092,9 @@ function _give_get_prefill_form_field_values( $form_id ) { if ( is_user_logged_in() ) : $donor_data = get_userdata( get_current_user_id() ); + $donor = new Give_Donor( get_current_user_id(), true ); $donor_address = give_get_donor_address( get_current_user_id() ); + $company_name = $donor->get_company_name(); $logged_in_donor_info = array( // First name. @@ -1101,6 +1103,9 @@ function _give_get_prefill_form_field_values( $form_id ) { // Last name. 'give_last' => $donor_data->last_name, + // Company name. + 'company_name' => $company_name, + // Email. 'give_email' => $donor_data->user_email, @@ -1143,4 +1148,4 @@ function _give_get_prefill_form_field_values( $form_id ) { // Output. return wp_parse_args( $give_donor_info_in_session, $logged_in_donor_info ); -} +} \ No newline at end of file diff --git a/includes/forms/template.php b/includes/forms/template.php index 12a383ac51..134e520ad9 100644 --- a/includes/forms/template.php +++ b/includes/forms/template.php @@ -678,6 +678,30 @@ class="give-input

+ + +

+ + + + /> + +

+ + array( + __( 'Company Name', 'give' ), + __( 'Donor Company Name', 'give' ), + __( 'Donor Company', 'give' ), + __( 'Company', 'give' ), + ), 'line1' => array( __( 'Address 1', 'give' ), __( 'Address', 'give' ), @@ -619,6 +625,18 @@ function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array 'mode' => ( ! empty( $data['mode'] ) ? ( 'true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live' ) : ( isset( $import_setting['mode'] ) ? ( true == (bool) $import_setting['mode'] ? 'test' : 'live' ) : ( give_is_test_mode() ? 'test' : 'live' ) ) ), ); + /** + * Filter to modify payment Data before getting imported. + * + * @since 2.0.7 + * + * @param array $payment_data payment data + * @param array $payment_data donation data + * @param array $donor_data donor data + * @param object $donor_data form object + * + * @return array $payment_data payment data + */ $payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form ); // Get the report @@ -650,6 +668,12 @@ function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array update_post_meta( $payment, '_give_payment_import_id', $import_setting['csv'] ); } + // Insert Company Name. + if ( ! empty( $data['company_name'] ) ) { + update_post_meta( $payment, '_give_donation_company', $data['company_name'] ); + $donor_data->update_meta( '_give_donor_company', $data['company_name'] ); + } + // Insert Notes. if ( ! empty( $data['notes'] ) ) { give_insert_payment_note( $payment, $data['notes'] ); @@ -666,6 +690,19 @@ function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array } else { $report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 ); } + + /** + * Fire after payment is imported and payment meta is also being imported. + * + * @since 2.0.7 + * + * @param int $payment payment id + * @param array $payment_data payment data + * @param array $payment_data donation data + * @param array $donor_data donor data + * @param object $donor_data form object + */ + do_action( 'give_import_after_import_payment', $payment, $payment_data, $data, $donor_data, $form ); } // update the report diff --git a/includes/misc-functions.php b/includes/misc-functions.php index 81d5f493fc..aaf79828de 100644 --- a/includes/misc-functions.php +++ b/includes/misc-functions.php @@ -1003,7 +1003,6 @@ function give_get_plugins() { return $plugins; } - /** * Check if terms enabled or not for form. * @@ -1030,7 +1029,6 @@ function give_is_terms_enabled( $form_id ) { } } - /** * Delete donation stats cache. * @@ -1810,3 +1808,34 @@ function give_time_do_tags( $string, $timestamp = 0 ) { */ return apply_filters( 'give_time_do_tags', $formatted_string, $string, $timestamp ); } + + +/** + * Check if Company field enabled or not for form or globally. + * + * @since 2.0.7 + * + * @param $form_id + * + * @return bool + */ +function give_is_company_field_enabled( $form_id ) { + $form_setting_val = give_get_meta( $form_id, '_give_company_field', true ); + $global_setting_val = give_get_option( 'company_field' ); + + if ( ! empty( $form_setting_val ) ) { + if( give_is_setting_enabled( $form_setting_val, array( 'required', 'optional' ) ) ) { + return true; + } elseif ( 'global' === $form_setting_val && give_is_setting_enabled( $global_setting_val, array( 'required', 'optional' ) ) ) { + return true; + } else{ + return false; + } + + } elseif ( give_is_setting_enabled( $global_setting_val, array( 'required', 'optional' ) ) ) { + return true; + + } else { + return false; + } +} \ No newline at end of file diff --git a/includes/payments/class-give-payment.php b/includes/payments/class-give-payment.php index 7aa6afdcd5..af20412dd0 100644 --- a/includes/payments/class-give-payment.php +++ b/includes/payments/class-give-payment.php @@ -745,6 +745,18 @@ private function insert_payment() { $this->update_meta( '_give_payment_meta', array_map( 'maybe_unserialize', $custom_payment_meta ) ); } + $give_company = ( ! empty( $_REQUEST['give_company_name'] ) ? give_clean( $_REQUEST['give_company_name'] ) : '' ); + + // Check $page_url is not empty. + if ( $give_company ) { + give_update_meta( $payment_id, '_give_donation_company', $give_company ); + + $donor_id = absint( $donor->id ); + if ( ! empty( $donor_id ) ) { + Give()->donor_meta->update_meta( $donor_id, '_give_donor_company', $give_company ); + } + } + $this->new = true; }// End if(). diff --git a/includes/process-donation.php b/includes/process-donation.php index 901b832da6..15641958ff 100644 --- a/includes/process-donation.php +++ b/includes/process-donation.php @@ -546,6 +546,31 @@ function give_get_required_fields( $form_id ) { } } + if ( give_is_company_field_enabled( $form_id ) ) { + $form_option = give_get_meta( $form_id, '_give_company_field', true ); + $global_setting = give_get_option( 'company_field' ); + + $is_company_field_required = false; + + if ( ! empty( $form_option ) && give_is_setting_enabled( $form_option, array( 'required' ) ) ) { + $is_company_field_required = true; + + } elseif ( 'global' === $form_option && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) { + $is_company_field_required = true; + + } elseif ( empty( $form_option ) && give_is_setting_enabled( $global_setting, array( 'required' ) ) ) { + $is_company_field_required = true; + + } + + if( $is_company_field_required ) { + $required_fields['give_company_name'] = array( + 'error_id' => 'invalid_company', + 'error_message' => __( 'Please enter Company Name.', 'give' ), + ); + } + } + /** * Filters the donation form required field. * diff --git a/includes/shortcodes.php b/includes/shortcodes.php index d0f4b9840d..7692401771 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -251,6 +251,7 @@ function give_receipt_shortcode( $atts ) { 'payment_method' => true, 'payment_id' => true, 'payment_status' => false, + 'company_name' => false, 'status_notice' => true, ), $atts, 'give_receipt' ); @@ -396,11 +397,13 @@ function give_process_profile_editor_updates( $data ) { $old_user_data = get_userdata( $user_id ); /* @var Give_Donor $donor */ - $donor = new Give_Donor( $user_id, true ); + $donor = new Give_Donor( $user_id, true ); + $old_company_name = $donor->get_company_name(); $display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name; $first_name = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name; $last_name = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name; + $company_name = ! empty( $data['give_company_name'] ) ? sanitize_text_field( $data['give_company_name'] ) : $old_company_name; $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email; $password = ! empty( $data['give_new_user_pass1'] ) ? $data['give_new_user_pass1'] : ''; $confirm_password = ! empty( $data['give_new_user_pass2'] ) ? $data['give_new_user_pass2'] : ''; @@ -412,6 +415,7 @@ function give_process_profile_editor_updates( $data ) { 'display_name' => $display_name, 'user_email' => $email, 'user_pass' => $password, + 'company_name' => $company_name, ); /** @@ -466,6 +470,7 @@ function give_process_profile_editor_updates( $data ) { ) ); Give()->donor_meta->update_meta( $donor->id, '_give_donor_first_name', $first_name ); Give()->donor_meta->update_meta( $donor->id, '_give_donor_last_name', $last_name ); + Give()->donor_meta->update_meta( $donor->id, '_give_donor_company', $company_name ); $current_user = wp_get_current_user(); @@ -474,6 +479,7 @@ function give_process_profile_editor_updates( $data ) { $display_name_update = ( $display_name !== $current_user->display_name ) ? true : false; $first_name_update = ( $first_name !== $current_user->first_name ) ? true : false; $last_name_update = ( $last_name !== $current_user->last_name ) ? true : false; + $company_name_update = ( $company_name !== $old_company_name ) ? true : false; $update_code = 0; /** @@ -481,7 +487,7 @@ function give_process_profile_editor_updates( $data ) { * * @var boolean */ - $profile_update = ( $email_update || $display_name_update || $first_name_update || $last_name_update ); + $profile_update = ( $email_update || $display_name_update || $first_name_update || $last_name_update || $company_name_update ); /** * True if password fields are filled. diff --git a/templates/shortcode-profile-editor.php b/templates/shortcode-profile-editor.php index b1ef3beb78..2a47ad8933 100644 --- a/templates/shortcode-profile-editor.php +++ b/templates/shortcode-profile-editor.php @@ -10,21 +10,25 @@ $current_user = wp_get_current_user(); if ( is_user_logged_in() ) : - $user_id = get_current_user_id(); + $user_id = get_current_user_id(); $first_name = get_user_meta( $user_id, 'first_name', true ); $last_name = get_user_meta( $user_id, 'last_name', true ); + $last_name = get_user_meta( $user_id, 'last_name', true ); $display_name = $current_user->display_name; $address = give_get_donor_address( $user_id, array( 'address_type' => 'personal' ) ); + $donor = new Give_Donor( $user_id, true ); + $company_name = $donor->get_meta( '_give_donor_company', true ); + if ( isset( $_GET['updated'] ) && 'true' === $_GET['updated'] && ! give_get_errors() ) : if ( isset( $_GET['update_code'] ) ) :?> - %1$s %2$s

', esc_html__( 'Success:', 'give' ), esc_html__( 'Your profile has been updated.', 'give' ) ); - break; - } - ?> + %1$s %2$s

', esc_html__( 'Success:', 'give' ), esc_html__( 'Your profile has been updated.', 'give' ) ); + break; + } + ?>

@@ -42,39 +46,56 @@ do_action( 'give_profile_editor_before' ); ?> -
+
-

+

- +

- +

+ +

+ + +

+ +

* - + -

+

- +

- +

- + - - + +

@@ -188,7 +216,7 @@ do_action( 'give_profile_editor_after' ); ?> - ID; +$donation_id = $payment->ID; $donation_number = Give()->seq_donation_number->get_serial_code( $payment->ID ); -$form_id = give_get_payment_meta( $donation_id, '_give_payment_form_id', true ); -$meta = give_get_payment_meta( $donation_id ); -$donation = give_get_donation_form_title( $donation_id ); -$user = give_get_payment_meta_user_info( $donation_id ); -$email = give_get_payment_user_email( $donation_id ); -$status = $payment->post_status; -$status_label = give_get_payment_status( $payment, true ); +$form_id = give_get_payment_meta( $donation_id, '_give_payment_form_id', true ); +$meta = give_get_payment_meta( $donation_id ); +$donation = give_get_donation_form_title( $donation_id ); +$user = give_get_payment_meta_user_info( $donation_id ); +$email = give_get_payment_user_email( $donation_id ); +$status = $payment->post_status; +$status_label = give_get_payment_status( $payment, true ); +$company_name = give_get_payment_meta( $donation_id, '_give_donation_company', true ); /** * Generate Donation Receipt Arguments. @@ -41,6 +42,21 @@ 'display' => $give_receipt_args['donor'], ); +/** + * Show Company name on Donation receipt Page + * + * @since 2.0.7 + * + * @param bool show/hide company name in donation receipt page. + * + * @return bool show/hide company name in donation receipt page. + */ +$give_receipt_args['donation_receipt']['company_name'] = array( + 'name' => __( 'Company Name', 'give' ), + 'value' => esc_attr( $company_name ), + 'display' => $give_receipt_args['company_name'], +); + $give_receipt_args['donation_receipt']['date'] = array( 'name' => __( 'Date', 'give' ), 'value' => date_i18n( give_date_format(), strtotime( $meta['date'] ) ),