/app_old/membershipincludes/addons/simple.invitecodes.php

  1. <?php 
  2. /** 
  3. Addon Name: Simple Invites Codes 
  4. Description: Force invite codes for membership signups 
  5. Author: Barry (Incsub) 
  6. Author URI: http://caffeinatedb.com 
  7. */ 
  8.  
  9. function M_AddSimpleInviteOptions() { 
  10.  
  11. $Msi_options = M_get_option('membership_simpleinvite_options', array()); 
  12.  
  13. ?> 
  14. <div class="postbox"> 
  15. <h3 class="hndle" style='cursor:auto;'><span><?php _e('Simple Invite Codes', 'membership'); ?></span></h3> 
  16. <div class="inside"> 
  17. <p class='description'><?php _e('Use the section below to enable and require invitation codes on the registration panel.', 'membership'); ?></p> 
  18.  
  19. <table class="form-table"> 
  20. <tbody> 
  21. <tr valign="top"> 
  22. <th scope="row"><?php _e('Require Invite Codes', 'membership'); ?> 
  23. </em> 
  24. </th> 
  25. <td> 
  26. <?php 
  27. if(!isset($Msi_options['inviterequired'])) { 
  28. $Msi_options['inviterequired'] = ''; 
  29. ?> 
  30. <input type='checkbox' name='inviterequired' id='inviterequired' value='yes' <?php checked('yes', $Msi_options['inviterequired']); ?> /> 
  31. </td> 
  32. </tr> 
  33. <tr valign="top"> 
  34. <th scope="row"><?php _e('Invite Codes', 'membership'); ?><br/> 
  35. <em style='font-size:smaller;'><?php _e("Place each available code on a new line.", 'membership'); ?> 
  36. </em> 
  37. </th> 
  38. <td> 
  39. <?php 
  40. if(!isset($Msi_options['invitecodes'])) { 
  41. $Msi_options['invitecodes'] = ''; 
  42. ?> 
  43. <textarea name='invitecodes' id='invitecodes' rows='15' cols='40'><?php esc_html_e(stripslashes($Msi_options['invitecodes'])); ?></textarea> 
  44. </td> 
  45. </tr> 
  46. <tr valign="top"> 
  47. <th scope="row"><?php _e('Remove Code once used', 'membership'); ?> 
  48. </em> 
  49. </th> 
  50. <td> 
  51. <?php 
  52. if(!isset($Msi_options['inviteremove'])) { 
  53. $Msi_options['inviteremove'] = ''; 
  54. ?> 
  55. <input type='checkbox' name='inviteremove' id='inviteremove' value='yes' <?php checked('yes', $Msi_options['inviteremove']); ?> /> 
  56. </td> 
  57. </tr> 
  58. </tbody> 
  59. </table> 
  60. </div> 
  61. </div> 
  62. <?php 
  63. add_action( 'membership_extrasoptions_page', 'M_AddSimpleInviteOptions', 11 ); 
  64.  
  65. function M_AddSimpleInviteOptionsProcess() { 
  66.  
  67. $Msi_options = M_get_option('membership_simpleinvite_options', array()); 
  68.  
  69. $Msi_options['invitecodes'] = (isset($_POST['invitecodes'])) ? $_POST['invitecodes'] : ''; 
  70. $Msi_options['inviterequired'] = (isset($_POST['inviterequired'])) ? $_POST['inviterequired'] : ''; 
  71. $Msi_options['inviteremove'] = (isset($_POST['inviteremove'])) ? $_POST['inviteremove'] : ''; 
  72.  
  73. M_update_option('membership_simpleinvite_options', $Msi_options); 
  74.  
  75.  
  76. add_action( 'membership_option_menu_process_extras', 'M_AddSimpleInviteOptionsProcess', 11 ); 
  77.  
  78. function M_AddSimpleInviteField() { 
  79.  
  80. $Msi_options = M_get_option('membership_simpleinvite_options', array()); 
  81. if(empty($Msi_options['inviterequired']) || $Msi_options['inviterequired'] != 'yes') { 
  82. return; 
  83.  
  84. ?> 
  85. <div class="form-element"> 
  86. <label class="control-label" for="user_email"><?php _e('Invite Code', 'membership'); ?></label> 
  87. <div class="element"> 
  88. <input type="text" autocomplete="off" class="input-xlarge" name="invitecode"> 
  89. </div> 
  90. </div> 
  91. <?php 
  92. add_action( 'membership_subscription_form_registration_presubmit_content', 'M_AddSimpleInviteField'); 
  93. // Moved on BP to Profile area 
  94. add_action( 'bp_custom_profile_edit_fields', 'M_AddSimpleInviteField'); 
  95.  
  96. function M_AddSimpleInviteFieldProcess( $error ) { 
  97.  
  98. $Msi_options = M_get_option('membership_simpleinvite_options', array()); 
  99. if(empty($Msi_options['inviterequired']) || $Msi_options['inviterequired'] != 'yes') { 
  100. return $error; 
  101.  
  102. $thekey = $_POST['invitecode']; 
  103.  
  104. if(empty($thekey)) { 
  105.  
  106. if(empty($error->errors)) { 
  107. $error = new WP_Error(); 
  108.  
  109. $error->add('enterinvitecode', __('You need to enter an invite code in order to register.', 'membership')); 
  110.  
  111. } else { 
  112.  
  113. $codes = explode("\n", $Msi_options['invitecodes']); 
  114. $codes = array_map('trim', $codes); 
  115.  
  116. if(!in_array( $thekey, $codes )) { 
  117.  
  118. if(empty($error->errors)) { 
  119. $error = new WP_Error(); 
  120.  
  121. $error->add('incorrectinvitecode', __('Sorry, but we do not seem to have that code on file, please try another.', 'membership')); 
  122.  
  123. } else { 
  124. if(empty($error->errors)) { 
  125. if($Msi_options['inviteremove'] == 'yes') { 
  126. $key = array_search( $thekey, $codes); 
  127. if($key !== false) { 
  128. unset($codes[$key]); 
  129. $Msi_options['invitecodes'] = implode("\n", $codes); 
  130.  
  131. M_update_option('membership_simpleinvite_options', $Msi_options); 
  132.  
  133. return $error; 
  134.  
  135. add_filter( 'membership_subscription_form_before_registration_process', 'M_AddSimpleInviteFieldProcess' ); 
  136.  
  137. ?> 
.