notices->register_notice( [ 'id' => 'bulk_action_delete', 'type' => 'updated', 'description' => sprintf( _n( 'Successfully deleted one donation.', 'Successfully deleted %d donations.', $payment_count, 'give' ), $payment_count ), 'show' => true, ] ); break; case 'resend-receipt': Give()->notices->register_notice( [ 'id' => 'bulk_action_resend_receipt', 'type' => 'updated', 'description' => sprintf( _n( 'Successfully sent email receipt to one recipient.', 'Successfully sent email receipts to %d recipients.', $payment_count, 'give' ), $payment_count ), 'show' => true, ] ); break; case 'set-status-publish': case 'set-status-pending': case 'set-status-processing': case 'set-status-refunded': case 'set-status-revoked': case 'set-status-failed': case 'set-status-cancelled': case 'set-status-abandoned': case 'set-status-preapproval': Give()->notices->register_notice( [ 'id' => 'bulk_action_status_change', 'type' => 'updated', 'description' => _n( 'Donation status updated successfully.', 'Donation statuses updated successfully.', $payment_count, 'give' ), 'show' => true, ] ); break; }// End switch(). }// End if(). }// End if(). // Add give message notices. $message_notices = give_get_admin_messages_key(); if ( ! empty( $message_notices ) ) { foreach ( $message_notices as $message_notice ) { // Donation reports errors. if ( current_user_can( 'view_give_reports' ) ) { switch ( $message_notice ) { case 'donation-deleted': Give()->notices->register_notice( [ 'id' => 'give-donation-deleted', 'type' => 'updated', 'description' => __( 'The donation has been deleted.', 'give' ), 'show' => true, ] ); break; case 'email-sent': Give()->notices->register_notice( [ 'id' => 'give-email-sent', 'type' => 'updated', 'description' => __( 'The donation receipt has been resent.', 'give' ), 'show' => true, ] ); break; case 'refreshed-reports': Give()->notices->register_notice( [ 'id' => 'give-refreshed-reports', 'type' => 'updated', 'description' => __( 'The reports cache has been cleared.', 'give' ), 'show' => true, ] ); break; case 'donation-note-deleted': Give()->notices->register_notice( [ 'id' => 'give-donation-note-deleted', 'type' => 'updated', 'description' => __( 'The donation note has been deleted.', 'give' ), 'show' => true, ] ); break; }// End switch(). }// End if(). // Give settings notices and errors. if ( current_user_can( 'manage_give_settings' ) ) { switch ( $message_notice ) { case 'settings-imported': Give()->notices->register_notice( [ 'id' => 'give-settings-imported', 'type' => 'updated', 'description' => __( 'The settings have been imported.', 'give' ), 'show' => true, ] ); break; case 'api-key-generated': Give()->notices->register_notice( [ 'id' => 'give-api-key-generated', 'type' => 'updated', 'description' => __( 'API keys have been generated.', 'give' ), 'show' => true, ] ); break; case 'api-key-exists': Give()->notices->register_notice( [ 'id' => 'give-api-key-exists', 'type' => 'updated', 'description' => __( 'The specified user already has API keys.', 'give' ), 'show' => true, ] ); break; case 'api-key-regenerated': Give()->notices->register_notice( [ 'id' => 'give-api-key-regenerated', 'type' => 'updated', 'description' => __( 'API keys have been regenerated.', 'give' ), 'show' => true, ] ); break; case 'api-key-revoked': Give()->notices->register_notice( [ 'id' => 'give-api-key-revoked', 'type' => 'updated', 'description' => __( 'API keys have been revoked.', 'give' ), 'show' => true, ] ); break; case 'sent-test-email': Give()->notices->register_notice( [ 'id' => 'give-sent-test-email', 'type' => 'updated', 'description' => sprintf( __( 'The test email has been sent to %s.', 'give' ), wp_get_current_user()->user_email ), 'show' => true, ] ); break; case 'matched-success-failure-page': Give()->notices->register_notice( [ 'id' => 'give-matched-success-failure-page', 'type' => 'updated', 'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ), 'show' => true, ] ); break; case 'akismet-deblacklisted-email': Give()->notices->register_notice( [ 'id' => 'give-akismet-deblacklisted-email', 'type' => 'updated', 'description' => __( 'Email de-blacklisted successfully. Now Donor will able to process donation with email flagged as spam', 'give' ), 'show' => true, 'dismissible' => 'auto', ] ); break; }// End switch(). }// End if(). // Payments errors. if ( current_user_can( 'edit_give_payments' ) ) { switch ( $message_notice ) { case 'note-added': Give()->notices->register_notice( [ 'id' => 'give-note-added', 'type' => 'updated', 'description' => __( 'The donation note has been added.', 'give' ), 'show' => true, ] ); break; case 'payment-updated': Give()->notices->register_notice( [ 'id' => 'give-payment-updated', 'type' => 'updated', 'description' => __( 'The donation has been updated.', 'give' ), 'show' => true, ] ); break; }// End switch(). }// End if(). // Donor Notices. if ( current_user_can( 'edit_give_payments' ) ) { switch ( $message_notice ) { case 'donor-deleted': Give()->notices->register_notice( [ 'id' => 'give-donor-deleted', 'type' => 'updated', 'description' => __( 'The selected donor(s) has been deleted.', 'give' ), 'show' => true, ] ); break; case 'donor-donations-deleted': Give()->notices->register_notice( [ 'id' => 'give-donor-donations-deleted', 'type' => 'updated', 'description' => __( 'The selected donor(s) and the associated donation(s) has been deleted.', 'give' ), 'show' => true, ] ); break; case 'confirm-delete-donor': Give()->notices->register_notice( [ 'id' => 'give-confirm-delete-donor', 'type' => 'updated', 'description' => __( 'You must confirm to delete the selected donor(s).', 'give' ), 'show' => true, ] ); break; case 'invalid-donor-id': Give()->notices->register_notice( [ 'id' => 'give-invalid-donor-id', 'type' => 'updated', 'description' => __( 'Invalid Donor ID.', 'give' ), 'show' => true, ] ); break; case 'donor-delete-failed': Give()->notices->register_notice( [ 'id' => 'give-donor-delete-failed', 'type' => 'error', 'description' => __( 'Unable to delete selected donor(s).', 'give' ), 'show' => true, ] ); break; case 'email-added': Give()->notices->register_notice( [ 'id' => 'give-email-added', 'type' => 'updated', 'description' => __( 'Donor email added.', 'give' ), 'show' => true, ] ); break; case 'email-removed': Give()->notices->register_notice( [ 'id' => 'give-email-removed', 'type' => 'updated', 'description' => __( 'Donor email removed.', 'give' ), 'show' => true, ] ); break; case 'email-remove-failed': Give()->notices->register_notice( [ 'id' => 'give-email-remove-failed', 'type' => 'updated', 'description' => __( 'Failed to remove donor email.', 'give' ), 'show' => true, ] ); break; case 'primary-email-updated': Give()->notices->register_notice( [ 'id' => 'give-primary-email-updated', 'type' => 'updated', 'description' => __( 'Primary email updated for donor.', 'give' ), 'show' => true, ] ); break; case 'primary-email-failed': Give()->notices->register_notice( [ 'id' => 'give-primary-email-failed', 'type' => 'updated', 'description' => __( 'Failed to set primary email.', 'give' ), 'show' => true, ] ); break; case 'reconnect-user': Give()->notices->register_notice( [ 'id' => 'give-reconnect-user', 'type' => 'updated', 'description' => __( 'User has been successfully connected with Donor.', 'give' ), 'show' => true, ] ); break; case 'disconnect-user': Give()->notices->register_notice( [ 'id' => 'give-disconnect-user', 'type' => 'updated', 'description' => __( 'User has been successfully disconnected from donor.', 'give' ), 'show' => true, ] ); break; case 'profile-updated': Give()->notices->register_notice( [ 'id' => 'give-profile-updated', 'type' => 'updated', 'description' => __( 'Donor information updated successfully.', 'give' ), 'show' => true, ] ); break; }// End switch(). }// End if(). } } /** * Spam log admin notice */ if ( current_user_can( 'manage_give_settings' ) && give_is_setting_enabled( give_get_option( 'akismet_spam_protection' ) ) ) { global $wpdb; $current_time = current_time( 'timestamp' ); $end_of_current_time_in_gmt = get_gmt_from_date( date( 'Y-m-d H:i:s', strtotime( 'tomorrow', $current_time ) ), 'U' ); $current_time_gmt = get_gmt_from_date( date( 'Y-m-d H:i:s', $current_time ), 'U' ); $spam_count = DB::get_var( DB::prepare( "SELECT COUNT(id) FROM {$wpdb->give_log} WHERE log_type = %s AND date >= CURDATE();", LogType::SPAM ) ); if ( $spam_count && ! Give_Admin_Settings::is_setting_page( 'logs', 'spam' ) ) { Give()->notices->register_notice( [ 'id' => 'give-new-akismet-spam-found', 'type' => 'warning', 'description' => sprintf( __( 'Akismet flagged %1$s %2$s as spam. If you believe %7$s %5$s actual %6$s, you can whitelist %7$s to allow the %6$s to process donations. Click here to review spam logs.', 'give' ), $spam_count, _n( 'donor email', 'donor emails', $spam_count, 'give' ), esc_url( admin_url( 'edit.php?post_type=give_forms&page=give-tools&tab=logs§ion=spam' ) ), __( 'Go to spam log list page', 'give' ), _n( 'was', 'were', $spam_count, 'give' ), _n( 'donor', 'donors', $spam_count, 'give' ), _n( 'this', 'these', $spam_count, 'give' ) ), 'dismissible_type' => 'user', 'dismiss_interval' => 'custom', 'dismiss_interval_time' => $end_of_current_time_in_gmt - $current_time_gmt, ] ); } } } add_action( 'admin_notices', '_give_register_admin_notices', - 1 ); /** * Display admin bar when active. * * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. * * @return bool */ function _give_show_test_mode_notice_in_admin_bar( $wp_admin_bar ) { $is_test_mode = ! empty( $_POST['test_mode'] ) ? give_is_setting_enabled( $_POST['test_mode'] ) : give_is_test_mode(); if ( ! current_user_can( 'view_give_reports' ) || ! $is_test_mode ) { return false; } // Add the main site admin menu item. $wp_admin_bar->add_menu( [ 'id' => 'give-test-notice', 'href' => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ), 'parent' => 'top-secondary', 'title' => __( 'GiveWP Test Mode Active', 'give' ), 'meta' => [ 'class' => 'give-test-mode-active', ], ] ); return true; } add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 ); /** * Outputs the Give admin bar CSS. */ function _give_test_mode_notice_admin_bar_css() { if ( ! give_is_test_mode() ) { return; } ?> disable(); $import_setting = []; $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null; parse_str( $fields, $output ); $import_setting['create_user'] = $output['create_user']; $import_setting['mode'] = $output['mode']; $import_setting['delimiter'] = $output['delimiter']; $import_setting['csv'] = $output['csv']; $import_setting['delete_csv'] = $output['delete_csv']; $import_setting['dry_run'] = $output['dry_run']; // Parent key id. $main_key = give_maybe_safe_unserialize($output['main_key']); $current = absint( $_REQUEST['current'] ); $total_ajax = absint( $_REQUEST['total_ajax'] ); $start = absint( $_REQUEST['start'] ); $end = absint( $_REQUEST['end'] ); $next = absint( $_REQUEST['next'] ); $total = absint( $_REQUEST['total'] ); $per_page = absint( $_REQUEST['per_page'] ); if ( empty( $output['delimiter'] ) ) { $delimiter = ','; } else { $delimiter = $output['delimiter']; } // Processing done here. $raw_data = give_get_donation_data_from_csv( $output['csv'], $start, $end, $delimiter); $raw_key = give_maybe_safe_unserialize($output['mapto']); $import_setting['raw_key'] = $raw_key; if ( ! empty( $output['dry_run'] ) ) { $import_setting['csv_raw_data'] = give_get_donation_data_from_csv( $output['csv'], 1, $end, $delimiter ); $import_setting['donors_list'] = Give()->donors->get_donors( [ 'number' => - 1, 'fields' => [ 'id', 'user_id', 'email' ], ] ); } // Prevent normal emails. remove_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 ); remove_action( 'give_insert_user', 'give_new_user_notification', 10 ); remove_action( 'give_insert_payment', 'give_payment_save_page_data' ); $current_key = $start; foreach ( $raw_data as $row_data ) { $import_setting['donation_key'] = $current_key; $result = give_save_import_donation_to_db( $raw_key, $row_data, $main_key, $import_setting ); if ( is_string( $result ) && ! empty( $result ) ) { if ( empty( $json_data['errors'] ) ) { $json_data['errors'] = []; } $json_data['errors'][] = sprintf( __( 'Row %1$d: %2$s', 'give' ), $current_key, $result ); } $current_key ++; } // Check if function exists or not. if ( function_exists( 'give_payment_save_page_data' ) ) { add_action( 'give_insert_payment', 'give_payment_save_page_data' ); } add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 ); add_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 ); if ( $next == false ) { $json_data = [ 'success' => true, 'message' => __( 'All donation uploaded successfully!', 'give' ), ]; } else { $index_start = $start; $index_end = $end; $last = false; $next = true; if ( $next ) { $index_start = $index_start + $per_page; $index_end = $per_page + ( $index_start - 1 ); } if ( $index_end >= $total ) { $index_end = $total; $last = true; } $json_data = [ 'raw_data' => $raw_data, 'raw_key' => $raw_key, 'next' => $next, 'start' => $index_start, 'end' => $index_end, 'last' => $last, ]; } $url = give_import_page_url( [ 'step' => '4', 'importer-type' => 'import_donations', 'csv' => $output['csv'], 'total' => $total, 'delete_csv' => $import_setting['delete_csv'], 'success' => ( isset( $json_data['success'] ) ? $json_data['success'] : '' ), 'dry_run' => $output['dry_run'], '_wpnonce' => wp_create_nonce( 'give_donation_import_success' ), ] ); $json_data['url'] = $url; $current ++; $json_data['current'] = $current; $percentage = ( 100 / ( $total_ajax + 1 ) ) * $current; $json_data['percentage'] = $percentage; // Enable Give cache Give_Cache::get_instance()->enable(); $json_data = apply_filters( 'give_import_ajax_responces', $json_data, $fields ); wp_die( json_encode( $json_data ) ); } add_action( 'wp_ajax_give_donation_import', 'give_donation_import_callback' ); /** * Load subscription import ajax callback * * @since 4.11.0 */ function give_subscription_import_callback() { check_ajax_referer('give_subscription_import'); if ( ! current_user_can( 'manage_give_settings' ) ) { give_die(); } // Disable Give cache Give_Cache::get_instance()->disable(); $import_setting = []; $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null; parse_str( $fields, $output ); $import_setting['mode'] = $output['mode']; $import_setting['create_user'] = isset($output['create_user']) ? $output['create_user'] : '0'; $import_setting['delimiter'] = $output['delimiter']; $import_setting['csv'] = $output['csv']; $import_setting['delete_csv'] = $output['delete_csv']; $import_setting['dry_run'] = $output['dry_run']; $main_key = give_maybe_safe_unserialize($output['main_key']); $current = absint( $_REQUEST['current'] ); $total_ajax = absint( $_REQUEST['total_ajax'] ); $start = absint( $_REQUEST['start'] ); $end = absint( $_REQUEST['end'] ); $next = absint( $_REQUEST['next'] ); $total = absint( $_REQUEST['total'] ); $per_page = absint( $_REQUEST['per_page'] ); $delimiter = empty( $output['delimiter'] ) ? ',' : $output['delimiter']; // Ensure importer class is loaded for admin-ajax context if ( ! class_exists( 'Give_Import_Subscriptions' ) ) { require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/import/class-give-import-subscriptions.php'; } $importer = \Give_Import_Subscriptions::get_instance(); // Processing $raw_data = $importer->get_subscription_data_from_csv( $output['csv'], $start, $end, $delimiter ); $raw_key = give_maybe_safe_unserialize($output['mapto']); $import_setting['raw_key'] = $raw_key; $current_key = $start; foreach ( $raw_data as $row_data ) { $import_setting['row_key'] = $current_key; $result = $importer->import_row( $raw_key, $row_data, $main_key, $import_setting ); if ( is_string( $result ) && ! empty( $result ) ) { if ( empty( $json_data['errors'] ) ) { $json_data['errors'] = []; } $json_data['errors'][] = sprintf( __( 'Row %1$d: %2$s', 'give' ), $current_key, $result ); } $current_key ++; } if ( $next == false ) { $json_data = [ 'success' => true, 'message' => __( 'All subscriptions uploaded successfully!', 'give' ), ]; } else { $index_start = $start; $index_end = $end; $last = false; $next = true; if ( $next ) { $index_start = $index_start + $per_page; $index_end = $per_page + ( $index_start - 1 ); } if ( $index_end >= $total ) { $index_end = $total; $last = true; } $json_data = [ 'raw_data' => $raw_data, 'raw_key' => $raw_key, 'next' => $next, 'start' => $index_start, 'end' => $index_end, 'last' => $last, ]; } $url = give_import_page_url( [ 'step' => '4', 'importer-type' => 'import_subscriptions', 'csv' => $output['csv'], 'total' => $total, 'delete_csv' => $import_setting['delete_csv'], 'success' => ( isset( $json_data['success'] ) ? $json_data['success'] : '' ), 'dry_run' => $output['dry_run'], '_wpnonce' => wp_create_nonce( 'give_subscription_import_success' ), ] ); $json_data['url'] = $url; $current ++; $json_data['current'] = $current; $percentage = ( 100 / ( $total_ajax + 1 ) ) * $current; $json_data['percentage'] = $percentage; // Enable Give cache Give_Cache::get_instance()->enable(); $json_data = apply_filters( 'give_import_ajax_responces', $json_data, $fields ); wp_die( json_encode( $json_data ) ); } add_action( 'wp_ajax_give_subscription_import', 'give_subscription_import_callback' ); /** * Load core settings import ajax callback * Fire when importing from JSON start * * @since 1.8.17 */ function give_core_settings_import_callback() { check_ajax_referer( 'give_core_settings_import' ); // Bailout. if ( ! current_user_can( 'manage_give_settings' ) ) { give_die(); } $fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null; parse_str( $fields, $fields ); $json_data['success'] = false; /** * Filter to Modify fields that are being pass by the ajax before importing of the core setting start. * * @access public * * @since 1.8.17 * * @param array $fields * * @return array $fields */ $fields = (array) apply_filters( 'give_import_core_settings_fields', $fields ); $file_name = ( ! empty( $fields['file_name'] ) ? give_clean( $fields['file_name'] ) : false ); if ( ! empty( $file_name ) ) { $type = ( ! empty( $fields['type'] ) ? give_clean( $fields['type'] ) : 'merge' ); // Get the json data from the file and then alter it in array format $json_string = give_get_core_settings_json( $file_name ); $json_to_array = json_decode( $json_string, true ); // get the current setting from the options table. $host_give_options = Give_Cache_Setting::get_settings(); // Save old settins for backup. update_option( 'give_settings_old', $host_give_options, false ); /** * Filter to Modify Core Settings that are being going to get import in options table as give settings. * * @access public * * @since 1.8.17 * * @param array $type Type of Import * @param array $host_give_options Setting old setting that used to be in the options table. * @param array $fields Data that is being send from the ajax * * @param array $json_to_array Setting that are being going to get imported * * @return array $json_to_array Setting that are being going to get imported */ $json_to_array = (array) apply_filters( 'give_import_core_settings_data', $json_to_array, $type, $host_give_options, $fields ); update_option( 'give_settings', $json_to_array, false ); $json_data['success'] = true; } $json_data['percentage'] = 100; /** * Filter to Modify core import setting page url * * @access public * * @since 1.8.17 * @return array $url */ $json_data['url'] = give_import_page_url( (array) apply_filters( 'give_import_core_settings_success_url', [ 'step' => ( empty( $json_data['success'] ) ? '1' : '3' ), 'importer-type' => 'import_core_setting', 'success' => ( empty( $json_data['success'] ) ? '0' : '1' ), ] ) ); wp_send_json( $json_data ); } add_action( 'wp_ajax_give_core_settings_import', 'give_core_settings_import_callback' ); /** * Initializes blank slate content if a list table is empty. * * @since 1.8.13 */ function give_blank_slate() { $blank_slate = new Give_Blank_Slate(); $blank_slate->init(); } add_action( 'current_screen', 'give_blank_slate' ); /** * Validate Fields of User Profile * * @since 2.0 * * @param int|bool $update True or False. * @param object $user WP User Data. * * @param object $errors Object of WP Errors. * * @return mixed */ function give_validate_user_profile( $errors, $update, $user ) { if ( ! empty( $_POST['action'] ) && ( 'adduser' === $_POST['action'] || 'createuser' === $_POST['action'] ) ) { return; } if ( ! empty( $user->ID ) ) { $donor = Give()->donors->get_donor_by( 'user_id', $user->ID ); if ( $donor ) { // If Donor is attached with User, then validate first name. if ( empty( $_POST['first_name'] ) ) { $errors->add( 'empty_first_name', sprintf( '%1$s: %2$s', __( 'ERROR', 'give' ), __( 'Please enter your first name.', 'give' ) ) ); } } } } add_action( 'user_profile_update_errors', 'give_validate_user_profile', 10, 3 ); /** * Show Donor Information on User Profile Page. * * @since 2.0 * * @param object $user User Object. * */ function give_donor_information_profile_fields( $user ) { $donor = Give()->donors->get_donor_by( 'user_id', $user->ID ); // Display Donor Information, only if donor is attached with User. if ( ! empty( $donor->user_id ) ) : ?>
%s
%s
%s
%s
%s
%s
%s