| 1 |
<?php |
| 2 |
/** |
| 3 |
* WP-Members Email API Functions |
| 4 |
* |
| 5 |
* This file is part of the WP-Members plugin by Chad Butler |
| 6 |
* You can find out more about this plugin at https://rocketgeek.com |
| 7 |
* Copyright (c) 2006-2026 Chad Butler |
| 8 |
* WP-Members(tm) is a trademark of butlerblog.com |
| 9 |
* |
| 10 |
* @package WP-Members |
| 11 |
* @subpackage WP-Members API Functions |
| 12 |
* @author Chad Butler |
| 13 |
* @copyright 2006-2026 |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* Returns the wp_mail from address (if set). |
| 18 |
* |
| 19 |
* @since 2.7 |
| 20 |
* @since 3.1 Converted to use email var in object. |
| 21 |
* |
| 22 |
* @global object $wpmem |
| 23 |
* @return string $wpmem_mail_from|$email |
| 24 |
*/ |
| 25 |
function wpmem_mail_from() { |
| 26 |
global $wpmem; |
| 27 |
return $wpmem->email->from; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns the wp_mail from name (if set). |
| 32 |
* |
| 33 |
* @since 2.7 |
| 34 |
* @since 3.1 Converted to use email var in object. |
| 35 |
* |
| 36 |
* @global object $wpmem |
| 37 |
* @return string $wpmem_mail_from_name|$name |
| 38 |
*/ |
| 39 |
function wpmem_mail_from_name() { |
| 40 |
global $wpmem; |
| 41 |
return $wpmem->email->from_name; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns the wp_mail content type (if set). |
| 46 |
* |
| 47 |
* @since 3.4.0 |
| 48 |
* |
| 49 |
* @global object $wpmem |
| 50 |
* @return string $wpmem_mail_content_type |
| 51 |
* |
| 52 |
* @note Currently checks for existing function. Advanced Options set up for |
| 53 |
* backward compatibility could potentially load first if wp-members directory |
| 54 |
* is named something other than "wp-members". |
| 55 |
*/ |
| 56 |
if ( ! function_exists( 'wpmem_mail_content_type' ) ): |
| 57 |
function wpmem_mail_content_type( $content_type = 'text/plain' ) { |
| 58 |
global $wpmem; |
| 59 |
return $wpmem->email->content_type( $content_type ); |
| 60 |
} |
| 61 |
endif; |
| 62 |
|
| 63 |
/** |
| 64 |
* Builds emails for the user. |
| 65 |
* |
| 66 |
* @since 3.2.3 |
| 67 |
* |
| 68 |
* @global object $wpmem The WP_Members object. |
| 69 |
* @param mixed $args { |
| 70 |
* Settings arguments or The User's ID. |
| 71 |
* |
| 72 |
* @type int $user_id |
| 73 |
* @type string $password Password from the registration process. |
| 74 |
* @type string $tag Indicates the email being sent (newreg|newmod|appmod|repass|getuser). |
| 75 |
* @type array $wpmem_fields Array of the WP-Members fields (deprecated) |
| 76 |
* @type array $fields Array of the registration data |
| 77 |
* @type array $custom { |
| 78 |
* Settings for custom email if used (optional). |
| 79 |
* |
| 80 |
* @type string $subj The email subject. |
| 81 |
* @type string $body The email message body. |
| 82 |
* @type string $tag The email tag. |
| 83 |
* } |
| 84 |
* } |
| 85 |
* @param string $password Password from the registration process. |
| 86 |
* @param string $tag Indicates the email being sent (newreg|newmod|appmod|repass|getuser). |
| 87 |
* @param array $wpmem_fields Array of the WP-Members fields (defaults to false). |
| 88 |
* @param array $fields Array of the registration data (defaults to false). |
| 89 |
* @param array $custom { |
| 90 |
* Array of custom email information (defaults to false). |
| 91 |
* |
| 92 |
* @type string $subj The email subject. |
| 93 |
* @type string $body The email message body. |
| 94 |
* @type string $tag The email tag. |
| 95 |
* } |
| 96 |
* |
| 97 |
* @todo Will probably change the WP_Members_Email::to_user() arguments to just accept the array. |
| 98 |
*/ |
| 99 |
function wpmem_email_to_user( $args, $password = null, $tag = null, $wpmem_fields = null, $field_data = null, $custom = null ) { |
| 100 |
global $wpmem; |
| 101 |
if ( is_array( $args ) ) { |
| 102 |
$user_id = $args['user_id']; |
| 103 |
$tag = $args['tag']; |
| 104 |
$password = ( isset( $args['password'] ) ) ? $args['password'] : ''; |
| 105 |
$wpmem_fields = ( isset( $args['wpmem_fields'] ) ) ? $args['wpmem_fields'] : false; |
| 106 |
$field_data = ( isset( $args['field_data'] ) ) ? $args['field_data'] : false; |
| 107 |
$custom = ( isset( $args['custom'] ) ) ? $args['custom'] : false; |
| 108 |
} else { |
| 109 |
$user_id = $args; |
| 110 |
} |
| 111 |
$wpmem->email->to_user( $user_id, $password, $tag, $wpmem_fields, $field_data, $custom ); |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
if ( ! function_exists( 'wpmem_notify_admin' ) ): |
| 116 |
/** |
| 117 |
* Builds the email for admin notification of new user registration. |
| 118 |
* |
| 119 |
* @since 2.3 |
| 120 |
* @since 3.2.3 Changed inputs. |
| 121 |
* |
| 122 |
* @global object $wpmem The WP_Members object. |
| 123 |
* @param mixed $args Settings arguments or The User's ID. |
| 124 |
* @param array $wpmem_fields Array of the WP-Members fields (defaults to null). |
| 125 |
* @param array $field_data Array of the registration data (defaults to null). |
| 126 |
*/ |
| 127 |
function wpmem_notify_admin( $args, $wpmem_fields = null, $field_data = null ) { |
| 128 |
global $wpmem; |
| 129 |
if ( is_array( $args ) ) { |
| 130 |
$user_id = $args['user_id']; |
| 131 |
$wpmem_fields = $args['wpmem_fields']; |
| 132 |
$field_data = $args['field_data']; |
| 133 |
} else { |
| 134 |
$user_id = $args; |
| 135 |
} |
| 136 |
$wpmem->email->notify_admin( $user_id, $wpmem_fields, $field_data ); |
| 137 |
} |
| 138 |
endif; |
| 139 |
|
| 140 |
/** |
| 141 |
* Checks for default email vals. |
| 142 |
* |
| 143 |
* @since 3.5.0 |
| 144 |
*/ |
| 145 |
function wpmem_get_email_settings( $tag ) { |
| 146 |
global $wpmem; |
| 147 |
// Are there settings for this email? |
| 148 |
$saved_settings = get_option( $tag ); |
| 149 |
return ( $saved_settings ) ? $saved_settings : $wpmem->email->get_default_email( $tag ); |
| 150 |
} |