PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/code/cake/app/webroot/research/wp-content/plugins/register-plus-redux/register-plus-redux.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 664 lines | 557 code | 61 blank | 46 comment | 135 complexity | 98effd2215e6ac71d3b141bebd51da0e MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. Author: radiok
  4. Plugin Name: Register Plus Redux
  5. Author URI: http://radiok.info/
  6. Plugin URI: http://radiok.info/blog/category/register-plus-redux/
  7. Description: Enhances the user registration process with complete customization and additional administration options.
  8. Version: 3.9.10
  9. Text Domain: register-plus-redux
  10. Domain Path: /languages
  11. */
  12. // NOTE: Debug, no more echoing
  13. // trigger_error( sprintf( 'Register Plus Redux DEBUG: function($parameter=%s) from %s', print_r( $value, TRUE ), $pagenow ) );
  14. // trigger_error( sprintf( 'Register Plus Redux DEBUG: function($parameter=%s)', print_r( $value, TRUE ) ) );
  15. // TODO: meta key could be changed and ruin look ups
  16. // TODO: Disable functionality in wp-signup and wp-admin around rpr_active_for_network
  17. // TODO: Custom messages may not work with Wordpress MS as it uses wpmu_welcome_user_notification not wp_new_user_notification
  18. // TODO: Verify wp_new_user_notification triggers when used in MS due to the $pagenow checks
  19. // TODO: Enhancement- Configuration to set default display_name and/or lockdown display_name
  20. // TODO: Enhancement- Create rpr-signups table and mirror wpms
  21. // TODO: Enhancement- Signups table needs an edit view
  22. // TODO: Enhancement- MS users aren't being linked to a site, this is by design, as a setting to automatically add users at specified level
  23. // TODO: Enhancement- Alter admin pages to match registration/signup
  24. // TODO: Enhancement- Widget is lame/near worthless
  25. define( 'RPR_VERSION', '3.9.9' );
  26. define( 'RPR_ACTIVATION_REQUIRED', '3.9.6' );
  27. if ( !class_exists( 'Register_Plus_Redux' ) ) {
  28. class Register_Plus_Redux {
  29. private /*.array[string]mixed.*/ $options;
  30. public /*.void.*/ function __construct() {
  31. register_activation_hook( __FILE__, array( $this, 'rpr_activation' ) );
  32. register_deactivation_hook( __FILE__, array( 'Register_Plus_Redux', 'rpr_uninstall' ) );
  33. register_uninstall_hook( __FILE__, array( 'Register_Plus_Redux', 'rpr_uninstall' ) );
  34. add_action( 'init', array( $this, 'rpr_i18n_init' ), 10, 1 );
  35. if ( !is_multisite() ) {
  36. add_filter( 'pre_user_login', array( $this, 'rpr_filter_pre_user_login_swp' ), 10, 1 ); // Changes user_login to user_email
  37. }
  38. add_action( 'admin_enqueue_scripts', array( $this, 'rpr_admin_enqueue_scripts' ), 10, 1 );
  39. add_action( 'show_user_profile', array( $this, 'rpr_show_custom_fields' ), 10, 1 ); // Runs near the end of the user profile editing screen.
  40. add_action( 'edit_user_profile', array( $this, 'rpr_show_custom_fields' ), 10, 1 ); // Runs near the end of the user profile editing screen in the admin menus.
  41. add_action( 'profile_update', array( $this, 'rpr_save_custom_fields' ), 10, 1 ); // Runs when a user's profile is updated. Action function argument: user ID.
  42. add_action( 'admin_footer-profile.php', array( $this, 'rpr_admin_footer' ), 10, 0 ); // Runs in the HTML <head> section of the admin panel of a page or a plugin-generated page.
  43. add_action( 'admin_footer-user-edit.php', array( $this, 'rpr_admin_footer' ), 10, 0 ); // Runs in the HTML <head> section of the admin panel of a page or a plugin-generated page.
  44. }
  45. public /*.void.*/ function rpr_activation() {
  46. global $wp_roles;
  47. add_role( 'rpr_unverified', 'Unverified' );
  48. update_option( 'register_plus_redux_last_activated', RPR_ACTIVATION_REQUIRED );
  49. }
  50. public static /*.void.*/ function rpr_uninstall() {
  51. global $wp_roles;
  52. remove_role( 'rpr_unverified' );
  53. delete_option( 'register_plus_redux_last_activated' );
  54. }
  55. public static /*.mixed.*/ function default_options( $option = '' )
  56. {
  57. $blogname = stripslashes( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) );
  58. $options = array(
  59. 'verify_user_email' => is_multisite() ? '1' : '0',
  60. 'message_verify_user_email' => is_multisite() ?
  61. __( "<h2>%user_login% is your new username</h2>\n<p>But, before you can start using your new username, <strong>you must activate it</strong></p>\n<p>Check your inbox at <strong>%user_email%</strong> and click the link given.</p>\n<p>If you do not activate your username within two days, you will have to sign up again.</p>", 'register-plus-redux' ) :
  62. __( 'Please verify your account using the verification link sent to your email address.', 'register-plus-redux' ),
  63. 'verify_user_admin' => '0',
  64. 'message_verify_user_admin' => __( 'Your account will be reviewed by an administrator and you will be notified when it is activated.', 'register-plus-redux' ),
  65. 'delete_unverified_users_after' => is_multisite() ? 0 : 7,
  66. 'autologin_user' => '0',
  67. 'username_is_email' => '0',
  68. 'double_check_email' => '0',
  69. 'user_set_password' => '0',
  70. 'min_password_length' => 6,
  71. 'disable_password_confirmation' => '0',
  72. 'show_password_meter' => '0',
  73. 'message_empty_password' => 'Strength Indicator',
  74. 'message_short_password' => 'Too Short',
  75. 'message_bad_password' => 'Bad Password',
  76. 'message_good_password' => 'Good Password',
  77. 'message_strong_password' => 'Strong Password',
  78. 'message_mismatch_password' => 'Password Mismatch',
  79. 'enable_invitation_code' => '0',
  80. 'require_invitation_code' => '0',
  81. 'invitation_code_case_sensitive' => '0',
  82. 'invitation_code_unique' => '0',
  83. 'enable_invitation_tracking_widget' => '0',
  84. 'show_disclaimer' => '0',
  85. 'message_disclaimer_title' => 'Disclaimer',
  86. 'require_disclaimer_agree' => '1',
  87. 'message_disclaimer_agree' => 'Accept the Disclaimer',
  88. 'show_license' => '0',
  89. 'message_license_title' => 'License Agreement',
  90. 'require_license_agree' => '1',
  91. 'message_license_agree' => 'Accept the License Agreement',
  92. 'show_privacy_policy' => '0',
  93. 'message_privacy_policy_title' => 'Privacy Policy',
  94. 'require_privacy_policy_agree' => '1',
  95. 'message_privacy_policy_agree' => 'Accept the Privacy Policy',
  96. 'default_css' => '1',
  97. 'required_fields_style' => 'border:solid 1px #E6DB55; background-color:#FFFFE0;',
  98. 'required_fields_asterisk' => '0',
  99. 'starting_tabindex' => 0,
  100. /*
  101. 'datepicker_firstdayofweek' => 6,
  102. 'datepicker_dateformat' => 'mm/dd/yyyy',
  103. 'datepicker_startdate' => '',
  104. 'datepicker_calyear' => '',
  105. 'datepicker_calmonth' => 'cur',
  106. */
  107. 'disable_user_message_registered' => '0',
  108. 'disable_user_message_created' => '0',
  109. 'custom_user_message' => '0',
  110. 'user_message_from_email' => get_option( 'admin_email' ),
  111. 'user_message_from_name' => $blogname,
  112. 'user_message_subject' => '[' . $blogname . '] ' . __( 'Your Login Information', 'register-plus-redux' ),
  113. 'user_message_body' => "Username: %user_login%\nPassword: %user_password%\n\n%site_url%\n",
  114. 'send_user_message_in_html' => '0',
  115. 'user_message_newline_as_br' => '0',
  116. 'custom_verification_message' => '0',
  117. 'verification_message_from_email' => get_option( 'admin_email' ),
  118. 'verification_message_from_name' => $blogname,
  119. 'verification_message_subject' => '[' . $blogname . '] ' . __( 'Verify Your Account', 'register-plus-redux' ),
  120. 'verification_message_body' => "Verification URL: %verification_url%\nPlease use the above link to verify your email address and activate your account\n",
  121. 'send_verification_message_in_html' => '0',
  122. 'verification_message_newline_as_br' => '0',
  123. 'disable_admin_message_registered' => '0',
  124. 'disable_admin_message_created' => '0',
  125. 'admin_message_when_verified' => '0',
  126. 'custom_admin_message' => '0',
  127. 'admin_message_from_email' => get_option( 'admin_email' ),
  128. 'admin_message_from_name' => $blogname,
  129. 'admin_message_subject' => '[' . $blogname . '] ' . __( 'New User Registered', 'register-plus-redux' ),
  130. 'admin_message_body' => "New user registered on your site %blogname%\n\nUsername: %user_login%\nE-mail: %user_email%\n",
  131. 'send_admin_message_in_html' => '0',
  132. 'admin_message_newline_as_br' => '0'
  133. );
  134. if ( !empty( $option ) ) {
  135. if ( array_key_exists( $option, $options ) ) {
  136. return $options[$option];
  137. }
  138. else {
  139. //TODO: Trigger event this would be odd
  140. return FALSE;
  141. }
  142. }
  143. return $options;
  144. }
  145. public /*.bool.*/ function rpr_update_options( /*.array[string]mixed.*/ $options ) {
  146. if ( empty( $options ) && empty( $this->options ) ) return FALSE;
  147. if ( !empty( $options ) ) {
  148. update_option( 'register_plus_redux_options', $options );
  149. $this->options = $options;
  150. }
  151. else {
  152. update_option( 'register_plus_redux_options', $this->options );
  153. }
  154. return TRUE;
  155. }
  156. private /*.void.*/ function rpr_load_options( $force_refresh = FALSE ) {
  157. if ( empty( $this->options ) || $force_refresh === TRUE ) {
  158. $this->options = get_option( 'register_plus_redux_options' );
  159. }
  160. if ( empty( $this->options ) ) {
  161. $this->rpr_update_options( Register_Plus_Redux::default_options() );
  162. }
  163. }
  164. public /*.mixed.*/ function rpr_get_option( /*.string.*/ $option ) {
  165. if ( empty( $option ) ) return NULL;
  166. $this->rpr_load_options( FALSE );
  167. if ( array_key_exists( $option, $this->options ) ) {
  168. return $this->options[$option];
  169. }
  170. return NULL;
  171. }
  172. public /*.bool.*/ function rpr_set_option( /*.string.*/ $option, /*.mixed.*/ $value, $save_now = FALSE ) {
  173. if ( empty( $option ) ) return FALSE;
  174. $this->rpr_load_options( FALSE );
  175. $this->options[$option] = $value;
  176. if ( $save_now === TRUE ) {
  177. $this->rpr_update_options( NULL );
  178. }
  179. return TRUE;
  180. }
  181. public /*.bool.*/ function rpr_unset_option( /*.string.*/ $option, $save_now = FALSE ) {
  182. if ( empty( $option ) ) return FALSE;
  183. $this->rpr_load_options( FALSE );
  184. unset( $this->options[$option] );
  185. if ( $save_now === TRUE ) {
  186. $this->rpr_update_options( NULL );
  187. }
  188. return TRUE;
  189. }
  190. public static /*.string.*/ function sanitize_text( /*.string.*/ $text ) {
  191. $text = str_replace( ' ', '_', $text );
  192. $text = strtolower( (string) $text );
  193. return sanitize_html_class( $text );
  194. }
  195. public /*.void.*/ function rpr_update_user_meta( /*.int.*/ $user_id, /*.array[string]mixed.*/ $meta_field, /*.mixed.*/ $meta_value ) {
  196. // convert array to string
  197. if ( is_array( $meta_value ) ) {
  198. foreach ( $meta_value as &$value ) {
  199. $value = sanitize_text_field( $value );
  200. }
  201. $meta_value = implode( ',', $meta_value );
  202. }
  203. // sanitize url
  204. if ( '1' === $meta_field['escape_url'] ) {
  205. $meta_value = esc_url_raw( (string) $meta_value );
  206. $meta_value = preg_match( '/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $meta_value ) > 0 ? (string) $meta_value : 'http://' . (string) $meta_value;
  207. }
  208. $valid_value = TRUE;
  209. if ( 'text' === $meta_field['display'] ) $valid_value = FALSE;
  210. // poor man's way to ensure required fields aren't blanked out, really should have a separate config per field
  211. if ( '1' === $meta_field['require_on_registration'] && empty( $meta_value ) ) $valid_value = FALSE;
  212. // check text field against regex if specified
  213. if ( 'textbox' === $meta_field['display'] && !empty( $meta_field['options'] ) && 1 !== preg_match( (string) $meta_field['options'], $meta_value ) ) $valid_value = FALSE;
  214. if ( 'textarea' !== $meta_field['display'] ) $meta_value = sanitize_text_field( $meta_value );
  215. if ( 'textarea' === $meta_field['display'] ) $meta_value = wp_filter_kses( $meta_value );
  216. if ( $valid_value ) {
  217. update_user_meta( $user_id, $meta_field['meta_key'], $meta_value );
  218. if ( 'terms' === $meta_field['display'] ) update_user_meta( $user_id, $meta_field['meta_key'] . '_date', time() );
  219. }
  220. }
  221. public /*.void.*/ function rpr_i18n_init() {
  222. // Place your language file in the languages subfolder and name it "register-plus-redux-{language}.mo" replace {language} with your language value from wp-config.php
  223. load_plugin_textdomain( 'register-plus-redux', FALSE, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
  224. }
  225. public /*.string.*/ function rpr_filter_pre_user_login_swp( /*.string.*/ $user_login ) {
  226. // TODO: Review, this could be overriding some other stuff
  227. if ( '1' === $this->rpr_get_option( 'username_is_email' ) ) {
  228. if ( isset( $_POST['user_email'] ) ) {
  229. $user_email = stripslashes( (string) $_POST['user_email'] );
  230. $user_email = strtolower( sanitize_user( $user_email ) );
  231. return $user_email;
  232. }
  233. }
  234. return $user_login;
  235. }
  236. public /*.void.*/ function rpr_admin_enqueue_scripts( /*.string.*/ $hook_suffix ) {
  237. if ( 'profile.php' == $hook_suffix || 'user-edit.php' == $hook_suffix ) {
  238. /*.array[]mixed.*/ $redux_usermeta = get_option( 'register_plus_redux_usermeta-rv2' );
  239. if ( is_array( $redux_usermeta ) ) {
  240. foreach ( $redux_usermeta as $meta_field ) {
  241. if ( '1' === $meta_field['show_on_registration'] && '1' === $meta_field['show_datepicker'] ) {
  242. wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/ui-lightness/jquery-ui.css', false );
  243. wp_enqueue_script( 'jquery-ui-datepicker' );
  244. break;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. // $profileuser is a WP_User object
  251. public /*.void.*/ function rpr_show_custom_fields( $profileuser ) {
  252. $additional_fields_exist = FALSE;
  253. $terms_exist = FALSE;
  254. /*.array[]mixed.*/ $redux_usermeta = get_option( 'register_plus_redux_usermeta-rv2' );
  255. if ( '1' === $this->rpr_get_option( 'enable_invitation_code' ) || is_array( $redux_usermeta ) ) {
  256. if ( is_array( $redux_usermeta ) ) {
  257. foreach ( $redux_usermeta as $meta_field ) {
  258. if ( 'terms' !== $meta_field['display'] ) {
  259. $additional_fields_exist = TRUE;
  260. break;
  261. }
  262. else if ( 'terms' === $meta_field['display'] ) { $term_exist = TRUE; }
  263. }
  264. }
  265. if ( '1' === $this->rpr_get_option( 'enable_invitation_code' ) || $additional_fields_exist ) {
  266. echo '<h3>', __( 'Additional Information', 'register-plus-redux' ), '</h3>';
  267. echo '<table class="form-table">';
  268. if ( '1' === $this->rpr_get_option( 'enable_invitation_code' ) ) {
  269. echo "\n", '<tr>';
  270. echo "\n", '<th><label for="invitation_code">', __( 'Invitation Code', 'register-plus-redux' ), '</label></th>';
  271. echo "\n", '<td><input type="text" name="invitation_code" id="invitation_code" value="', esc_attr( $profileuser->invitation_code ), '" class="regular-text" ';
  272. if ( !current_user_can( 'edit_users' ) ) echo 'readonly="readonly" ';
  273. echo '/></td>';
  274. echo "\n", '</tr>';
  275. }
  276. if ( $additional_fields_exist ) {
  277. foreach ( $redux_usermeta as $meta_field ) {
  278. if ( current_user_can( 'edit_users' ) || '1' === $meta_field['show_on_profile'] ) {
  279. if ( 'terms' === $meta_field['display'] ) continue;
  280. $meta_key = (string) esc_attr( $meta_field['meta_key'] );
  281. $meta_value = get_user_meta( $profileuser->ID, $meta_key, TRUE );
  282. $meta_value = (string) get_user_meta( $profileuser->ID, $meta_key, TRUE );
  283. echo "\n", '<tr>';
  284. echo "\n", '<th><label for="', $meta_key, '">', esc_html( $meta_field['label'] );
  285. if ( '1' !== $meta_field['show_on_profile'] ) echo ' <span class="description">(hidden)</span>';
  286. if ( '1' === $meta_field['require_on_registration'] ) echo ' <span class="description">(required)</span>';
  287. echo '</label></th>';
  288. switch ( (string) $meta_field['display'] ) {
  289. case 'textbox':
  290. echo "\n", '<td><input type="text" name="', $meta_key, '" id="', $meta_key, '" ';
  291. if ( '1' === $meta_field['show_datepicker'] ) echo 'class="datepicker" ';
  292. echo 'value="', esc_attr( $meta_value ), '" class="regular-text" /></td>';
  293. break;
  294. case 'select':
  295. echo "\n", '<td>';
  296. echo "\n", '<select name="', $meta_key, '" id="', $meta_key, '" style="width: 15em;">';
  297. /*.array[]string.*/ $field_options = explode( ',', (string) $meta_field['options'] );
  298. foreach ( $field_options as $field_option ) {
  299. echo "\n", '<option value="', esc_attr( $field_option ), '"';
  300. if ( $meta_value === esc_attr( $field_option ) ) echo ' selected="selected"';
  301. echo '>', esc_html( $field_option ), '</option>';
  302. }
  303. echo "\n", '</select>';
  304. echo "\n", '</td>';
  305. break;
  306. case 'checkbox':
  307. echo "\n", '<td>';
  308. /*.array[]string.*/ $field_options = explode( ',', (string) $meta_field['options'] );
  309. /*.array[]string.*/ $meta_values = explode( ',', (string) $meta_value );
  310. foreach ( $field_options as $field_option ) {
  311. echo "\n", '<label><input type="checkbox" name="', $meta_key, '[]" value="', esc_attr( $field_option ), '" ';
  312. if ( in_array( esc_attr( $field_option ), $meta_values ) ) echo 'checked="checked" ';
  313. echo '/>&nbsp;', esc_html( $field_option ), '</label><br />';
  314. }
  315. echo "\n", '</td>';
  316. break;
  317. case 'radio':
  318. echo "\n", '<td>';
  319. /*.array[]string.*/ $field_options = explode( ',', (string) $meta_field['options'] );
  320. foreach ( $field_options as $field_option ) {
  321. echo "\n", '<label><input type="radio" name="', $meta_key, '" value="', esc_attr( $field_option ), '" ';
  322. if ( $meta_value === esc_attr( $field_option ) ) echo 'checked="checked" ';
  323. echo 'class="tog">&nbsp;', esc_html( $field_option ), '</label><br />';
  324. }
  325. echo "\n", '</td>';
  326. break;
  327. case 'textarea':
  328. echo "\n", '<td><textarea name="', $meta_key, '" id="', $meta_key, '" cols="25" rows="5">', esc_textarea( $meta_value ), '</textarea></td>';
  329. break;
  330. case 'hidden':
  331. echo "\n", '<td><input type="text" disabled="disabled" name="', $meta_key, '" id="', $meta_key, '" value="', esc_attr( $meta_value ), '" /></td>';
  332. break;
  333. case 'text':
  334. echo "\n", '<td><span class="description">', esc_html( $meta_field['label'] ), '</span></td>';
  335. break;
  336. default:
  337. }
  338. echo "\n", '</tr>';
  339. }
  340. }
  341. }
  342. echo '</table>';
  343. }
  344. }
  345. if ( is_array( $redux_usermeta ) ) {
  346. if ( !$terms_exist ) {
  347. foreach ( $redux_usermeta as $meta_field ) {
  348. if ( 'terms' === $meta_field['display'] ) {
  349. $terms_exist = TRUE;
  350. break;
  351. }
  352. }
  353. }
  354. if ( $terms_exist ) {
  355. echo '<h3>', __( 'Terms', 'register-plus-redux' ), '</h3>';
  356. echo '<table class="form-table">';
  357. foreach ( $redux_usermeta as $meta_field ) {
  358. if ( 'terms' === $meta_field['display'] ) {
  359. $meta_key = (string) esc_attr( $meta_field['meta_key'] );
  360. $meta_value = (string) get_user_meta( $profileuser->ID, $meta_key, TRUE );
  361. $meta_value = !empty( $meta_value ) ? $meta_value : 'N';
  362. $meta_value_date = (int) get_user_meta( $profileuser->ID, $meta_key . '_date', TRUE );
  363. echo "\n", '<tr>';
  364. echo "\n", '<th>', esc_html( $meta_field['label'] );
  365. if ( '1' === $meta_field['require_on_registration'] ) echo ' <span class="description">(required)</span>';
  366. echo '</label></th>';
  367. echo "\n", '<td>';
  368. echo "\n", nl2br( $meta_field['terms_content'] ), '<br />';
  369. echo "\n", '<span class="description">', __( 'Last Revised:', 'register-plus-redux' ), ' ', date( "m/d/Y", $meta_field['date_revised'] ), '</span><br />';
  370. echo "\n", '<span class="description">', __( 'Accepted:', 'register-plus-redux' ), ' ', esc_html( $meta_value );
  371. if ( 'Y' === $meta_value ) echo ' on ', date( "m/d/Y", $meta_value_date );
  372. echo '</span>';
  373. echo "\n", '</td>';
  374. echo "\n", '</tr>';
  375. }
  376. }
  377. echo '</table>';
  378. }
  379. }
  380. }
  381. public /*.void.*/ function rpr_save_custom_fields( /*.int.*/ $user_id ) {
  382. // TODO: Error check invitation code?
  383. if ( isset( $_POST['invitation_code'] ) ) {
  384. $invitation_code = stripslashes( (string) $_POST['invitation_code'] );
  385. update_user_meta( $user_id, 'invitation_code', sanitize_text_field( $invitation_code ) );
  386. }
  387. /*.array[]mixed.*/ $redux_usermeta = get_option( 'register_plus_redux_usermeta-rv2' );
  388. if ( is_array( $redux_usermeta ) ) {
  389. foreach ( $redux_usermeta as $meta_field ) {
  390. if ( 'text' !== $meta_field['display'] && 'terms' !== $meta_field['display'] ) {
  391. if ( current_user_can( 'edit_users' ) || '1' === $meta_field['show_on_profile'] ) {
  392. if ( 'checkbox' === $meta_field['display'] ) {
  393. $meta_value = isset( $_POST[ (string) $meta_field['meta_key']] ) ? (array) $_POST[ (string) $meta_field['meta_key']] : '';
  394. $meta_value = stripslashes_deep( $meta_value );
  395. }
  396. else {
  397. $meta_value = isset( $_POST[ (string) $meta_field['meta_key']] ) ? (string) $_POST[ (string) $meta_field['meta_key']] : '';
  398. $meta_value = stripslashes( $meta_value );
  399. }
  400. $this->rpr_update_user_meta( $user_id, $meta_field, $meta_value );
  401. }
  402. }
  403. }
  404. }
  405. }
  406. public /*.void.*/ function rpr_admin_footer() {
  407. /*.array[]mixed.*/ $redux_usermeta = get_option( 'register_plus_redux_usermeta-rv2' );
  408. $show_custom_date_fields = FALSE;
  409. if ( is_array( $redux_usermeta ) ) {
  410. foreach ( $redux_usermeta as $meta_field ) {
  411. if ( '1' === $meta_field['show_on_registration'] && '1' === $meta_field['show_datepicker'] ) {
  412. ?>
  413. <script type="text/javascript">
  414. jQuery(document).ready(function() {
  415. jQuery(".datepicker").datepicker();
  416. });
  417. </script>
  418. <?php
  419. break;
  420. }
  421. }
  422. }
  423. }
  424. // $user is a WP_User object
  425. public /*.string.*/ function replace_keywords( /*.mixed.*/ $message, $user, $plaintext_pass = '', $verification_code = '' ) {
  426. global $pagenow;
  427. if ( empty( $message ) ) return '%blogname% %site_url% %http_referer% %http_user_agent% %registered_from_ip% %registered_from_host% %user_login% %user_email% %user_password% %verification_code% %verification_url%';
  428. preg_match_all( '/%=([^%]+)%/', (string) $message, $keys );
  429. if ( is_array( $keys ) && is_array( $keys[1] ) ) {
  430. foreach( $keys[1] as $key ) {
  431. $message = str_replace( "%=$key%", get_user_meta( $user->ID, $key, TRUE ), $message );
  432. }
  433. }
  434. // support renamed keywords for backcompat
  435. $message = str_replace( '%verification_link%', '%verification_url%', $message );
  436. $message = str_replace( '%blogname%', wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $message );
  437. $message = str_replace( '%site_url%', site_url(), $message );
  438. $message = str_replace( '%?pagenow%', $pagenow, $message ); //debug keyword
  439. $message = str_replace( '%?user_info%', print_r( $user, TRUE ), $message ); //debug keyword
  440. $message = str_replace( '%?keys%', print_r( $keys, TRUE ), $message ); //debug keyword
  441. if ( !empty( $_SERVER ) ) {
  442. $message = str_replace( '%http_referer%', isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '', $message );
  443. $message = str_replace( '%http_user_agent%', isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '', $message );
  444. $message = str_replace( '%registered_from_ip%', isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : '', $message );
  445. $message = str_replace( '%registered_from_host%', isset( $_SERVER['REMOTE_ADDR'] ) ? gethostbyaddr( $_SERVER['REMOTE_ADDR'] ) : '', $message );
  446. }
  447. if ( !empty( $user ) ) {
  448. $message = str_replace( '%user_login%', $user->user_login, $message );
  449. $message = str_replace( '%user_email%', $user->user_email, $message );
  450. $message = str_replace( '%stored_user_login%', $user->user_login, $message );
  451. $message = str_replace( '%name%', $user->display_name, $message);
  452. }
  453. if ( !empty( $plaintext_pass ) ) {
  454. $message = str_replace( '%user_password%', $plaintext_pass, $message );
  455. }
  456. if ( !empty( $verification_code ) ) {
  457. $message = str_replace( '%verification_code%', $verification_code, $message );
  458. $message = str_replace( '%verification_url%', wp_login_url() . '?action=verifyemail&verification_code=' . $verification_code, $message );
  459. }
  460. preg_match_all( '/%([^%]+)%/', (string) $message, $keys );
  461. if ( is_array( $keys ) && is_array( $keys[1] ) ) {
  462. foreach( $keys[1] as $key ) {
  463. $message = str_replace( "%$key%", get_user_meta( $user->ID, $key, TRUE ), $message );
  464. }
  465. }
  466. return (string) $message;
  467. }
  468. public static /*.bool.*/ function rpr_active_for_network() {
  469. if ( !is_multisite() ) { return false; }
  470. $plugins = get_site_option( 'active_sitewide_plugins');
  471. if ( isset( $plugins[ plugin_basename( __FILE__ ) ] ) ) { return true; }
  472. return false;
  473. }
  474. public /*.void.*/ function send_verification_mail( /*.int.*/ $user_id, /*.string.*/ $verification_code ) {
  475. $user = get_userdata( $user_id );
  476. $subject = Register_Plus_Redux::default_options( 'verification_message_subject' );
  477. $message = Register_Plus_Redux::default_options( 'verification_message_body' );
  478. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_text' ), 10, 1 );
  479. if ( '1' === $this->rpr_get_option( 'custom_verification_message' ) ) {
  480. $subject = esc_html( $this->rpr_get_option( 'verification_message_subject' ) );
  481. $message = $this->rpr_get_option( 'verification_message_body' );
  482. if ( '1' === $this->rpr_get_option( 'send_verification_message_in_html' ) && '1' === $this->rpr_get_option( 'verification_message_newline_as_br' ) ) {
  483. $message = nl2br( (string) $message );
  484. }
  485. $from_name = $this->rpr_get_option( 'verification_message_from_name' );
  486. if ( !empty( $from_name ) )
  487. add_filter( 'wp_mail_from_name', array( $this, 'rpr_filter_verification_mail_from_name' ), 10, 1 );
  488. if ( FALSE !== is_email( $this->rpr_get_option( 'verification_message_from_email' ) ) )
  489. add_filter( 'wp_mail_from', array( $this, 'rpr_filter_verification_mail_from' ), 10, 1 );
  490. if ( '1' === $this->rpr_get_option( 'send_verification_message_in_html' ) )
  491. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_html' ), 10, 1 );
  492. }
  493. $subject = $this->replace_keywords( $subject, $user );
  494. $message = $this->replace_keywords( $message, $user, '', $verification_code );
  495. wp_mail( $user->user_email, $subject, $message );
  496. }
  497. public /*.void.*/ function send_welcome_user_mail( /*.int.*/ $user_id, /*.string.*/ $plaintext_pass ) {
  498. $user = get_userdata( $user_id );
  499. $subject = Register_Plus_Redux::default_options( 'user_message_subject' );
  500. $message = Register_Plus_Redux::default_options( 'user_message_body' );
  501. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_text' ), 10, 1 );
  502. if ( '1' === $this->rpr_get_option( 'custom_user_message' ) ) {
  503. $subject = esc_html( $this->rpr_get_option( 'user_message_subject' ) );
  504. $message = $this->rpr_get_option( 'user_message_body' );
  505. if ( '1' === $this->rpr_get_option( 'send_user_message_in_html' ) && '1' === $this->rpr_get_option( 'user_message_newline_as_br' ) )
  506. $message = nl2br( (string) $message );
  507. $from_name = $this->rpr_get_option( 'user_message_from_name' );
  508. if ( !empty( $from_name ) )
  509. add_filter( 'wp_mail_from_name', array( $this, 'rpr_filter_welcome_user_mail_from_name' ), 10, 1 );
  510. if ( FALSE !== is_email( $this->rpr_get_option( 'user_message_from_email' ) ) )
  511. add_filter( 'wp_mail_from', array( $this, 'rpr_filter_welcome_user_mail_from' ), 10, 1 );
  512. if ( '1' === $this->rpr_get_option( 'send_user_message_in_html' ) )
  513. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_html' ), 10, 1 );
  514. }
  515. $subject = $this->replace_keywords( $subject, $user );
  516. $message = $this->replace_keywords( $message, $user, $plaintext_pass );
  517. wp_mail( $user->user_email, $subject, $message );
  518. }
  519. public /*.void.*/ function send_admin_mail( /*.int.*/ $user_id, /*.string.*/ $plaintext_pass, $verification_code = '' ) {
  520. $user = get_userdata( $user_id );
  521. $subject = Register_Plus_Redux::default_options( 'admin_message_subject' );
  522. $message = Register_Plus_Redux::default_options( 'admin_message_body' );
  523. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_text' ), 10, 1 );
  524. if ( '1' === $this->rpr_get_option( 'custom_admin_message' ) ) {
  525. $subject = esc_html( $this->rpr_get_option( 'admin_message_subject' ) );
  526. $message = $this->rpr_get_option( 'admin_message_body' );
  527. if ( '1' === $this->rpr_get_option( 'send_admin_message_in_html' ) && '1' === $this->rpr_get_option( 'admin_message_newline_as_br' ) )
  528. $message = nl2br( (string) $message );
  529. $from_name = $this->rpr_get_option( 'admin_message_from_name' );
  530. if ( !empty( $from_name ) )
  531. add_filter( 'wp_mail_from_name', array( $this, 'rpr_filter_admin_mail_from_name' ), 10, 1 );
  532. if ( FALSE !== is_email( $this->rpr_get_option( 'admin_message_from_email' ) ) )
  533. add_filter( 'wp_mail_from', array( $this, 'rpr_filter_admin_mail_from' ), 10, 1 );
  534. if ( '1' === $this->rpr_get_option( 'send_admin_message_in_html' ) )
  535. add_filter( 'wp_mail_content_type', array( $this, 'rpr_filter_mail_content_type_html' ), 10, 1 );
  536. }
  537. $subject = $this->replace_keywords( $subject, $user );
  538. $message = $this->replace_keywords( $message, $user, $plaintext_pass, $verification_code );
  539. wp_mail( get_option( 'admin_email' ), $subject, $message );
  540. }
  541. public /*.string.*/ function rpr_filter_verification_mail_from( /*.string.*/ $from_email ) {
  542. return is_email( $this->rpr_get_option( 'verification_message_from_email' ) );
  543. }
  544. public /*.string.*/ function rpr_filter_verification_mail_from_name( /*.string.*/ $from_name ) {
  545. return esc_html( $this->rpr_get_option( 'verification_message_from_name' ) );
  546. }
  547. public /*.string.*/ function rpr_filter_welcome_user_mail_from( /*.string.*/ $from_email ) {
  548. return is_email( $this->rpr_get_option( 'user_message_from_email' ) );
  549. }
  550. public /*.string.*/ function rpr_filter_welcome_user_mail_from_name( /*.string.*/ $from_name ) {
  551. return esc_html( $this->rpr_get_option( 'user_message_from_name' ) );
  552. }
  553. public /*.string.*/ function rpr_filter_admin_mail_from( /*.string.*/ $from_email ) {
  554. return is_email( $this->rpr_get_option( 'admin_message_from_email' ) );
  555. }
  556. public /*.string.*/ function rpr_filter_admin_mail_from_name( /*.string.*/ $from_name ) {
  557. return esc_html( $this->rpr_get_option( 'admin_message_from_name' ) );
  558. }
  559. public /*.string.*/ function rpr_filter_mail_content_type_text( /*.string.*/ $content_type ) {
  560. return 'text/plain';
  561. }
  562. public /*.string.*/ function rpr_filter_mail_content_type_html( /*.string.*/ $content_type ) {
  563. return 'text/html';
  564. }
  565. }
  566. }
  567. // include secondary php files outside of object otherwise $register_plus_redux will not be an instance yet
  568. if ( class_exists( 'Register_Plus_Redux' ) ) {
  569. //rumor has it this may need to declared global in order to be available at plugin activation
  570. $register_plus_redux = new Register_Plus_Redux();
  571. if ( is_admin() ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-admin.php' );
  572. if ( is_admin() ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-admin-menu.php' );
  573. if ( is_admin() && file_exists( plugin_dir_path( __FILE__ ) . 'rpr-admin-menu-wip.php' ) ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-admin-menu-wip.php' );
  574. $do_include = FALSE;
  575. if ( '1' === $register_plus_redux->rpr_get_option( 'enable_invitation_tracking_widget' ) ) { $do_include = TRUE; }
  576. if ( $do_include && is_admin() ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-dashboard-widget.php' );
  577. //TODO: Determine which features require the following file
  578. $do_include = TRUE;
  579. if ( $do_include ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-login.php' );
  580. //TODO: Determine which features require the following file
  581. $do_include = TRUE;
  582. if ( $do_include & is_multisite() ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-signup.php' );
  583. $do_include = FALSE;
  584. if ( '1' === $register_plus_redux->rpr_get_option( 'verify_user_admin' ) ) { $do_include = TRUE; }
  585. if ( is_array( $register_plus_redux->rpr_get_option( 'show_fields' ) ) ) { $do_include = TRUE; }
  586. if ( is_array( get_option( 'register_plus_redux_usermeta-rv2' ) ) ) { $do_include = TRUE; }
  587. if ( '1' === $register_plus_redux->rpr_get_option( 'enable_invitation_code' ) ) { $do_include = TRUE; }
  588. if ( '1' === $register_plus_redux->rpr_get_option( 'user_set_password' ) ) { $do_include = TRUE; }
  589. if ( '1' === $register_plus_redux->rpr_get_option( 'autologin_user' ) ) { $do_include = TRUE; }
  590. if ( $do_include && is_multisite() && Register_Plus_Redux::rpr_active_for_network() ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-activate.php' );
  591. //NOTE: Requires rpr-admin.php for rpr_new_user_notification_warning make
  592. $do_include = FALSE;
  593. if ( '1' === $register_plus_redux->rpr_get_option( 'verify_user_email' ) ) { $do_include = TRUE; }
  594. if ( '1' === $register_plus_redux->rpr_get_option( 'disable_user_message_registered' ) ) { $do_include = TRUE; }
  595. if ( '1' === $register_plus_redux->rpr_get_option( 'disable_user_message_created' ) ) { $do_include = TRUE; }
  596. if ( '1' === $register_plus_redux->rpr_get_option( 'custom_user_message' ) ) { $do_include = TRUE; }
  597. if ( '1' === $register_plus_redux->rpr_get_option( 'verify_user_admin' ) ) { $do_include = TRUE; }
  598. if ( '1' === $register_plus_redux->rpr_get_option( 'disable_admin_message_registered' ) ) { $do_include = TRUE; }
  599. if ( '1' === $register_plus_redux->rpr_get_option( 'disable_admin_message_created' ) ) { $do_include = TRUE; }
  600. if ( '1' === $register_plus_redux->rpr_get_option( 'custom_admin_message' ) ) { $do_include = TRUE; }
  601. if ( $do_include ) require_once( plugin_dir_path( __FILE__ ) . 'rpr-new-user-notification.php' );
  602. }
  603. ?>