Advertisement
Guest User

Untitled

a guest
Sep 27th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.48 KB | None | 0 0
  1. <?php
  2. /* Buddypress Humanity 1.2 */
  3.  
  4. function create_bph_menu() {
  5.     add_submenu_page('bp-general-settings','BP Humanity','BP Humanity','administrator','bph-settings','bph_admin_page');
  6.     add_action('admin_init', 'register_bph_settings');
  7. }
  8. add_action(is_multisite() ? 'network_admin_menu' : 'admin_menu','create_bph_menu');
  9.    
  10. function register_bph_settings() { 
  11.     $input_field_names = array(
  12.     'bph_title',
  13.     'bph_question',
  14.     'bph_answers'
  15.     );
  16. foreach ($input_field_names as $field_name){ register_setting( 'bph_settings', $field_name ); }
  17. }
  18.  
  19. function bph_admin_page(){
  20.     if(isset($_POST['bph_submit'])){
  21.         foreach((array)$_POST['bph_option'] as $key => $value){
  22.             update_option($key,stripcslashes($value));
  23.         }
  24.     }
  25.     //Set Defaults
  26.     $default_title = "Security Question";
  27.     $default_question = 'What is the sum of 4 and 5. Please spell out the answer ~ Ex: seven';
  28.     $default_answers = 'nine';
  29.    
  30.     if(get_option('bph_title') == ''){ update_option('bph_title', $default_title); }
  31.     if(get_option('bph_question') == ''){ update_option('bph_question',$default_question); }
  32.     if(get_option('bph_answers') == ''){ update_option('bph_answers',$default_answers); }
  33.    
  34.     //Variables
  35.     $bph_title = get_option('bph_title');
  36.     $bph_question = get_option('bph_question');
  37.     $bph_answers = get_option('bph_answers');
  38.     ?>
  39.    
  40.     <div class="wrap">
  41.         <h2>Buddpress Humanity Settings</h2>
  42.         <?php if(isset($_POST['bph_submit'])) : ?>
  43.         <div id="message" class="updated fade">
  44.             <p>
  45.                 <?php _e( 'Settings Saved', 'bpt' ) ?>
  46.             </p>
  47.         </div>
  48.         <?php endif; ?>
  49.         <form name="BPHForm" method="post" action="">
  50.             <?php settings_fields('bph_settings'); ?>
  51.             <!-- Title -->
  52.             <p>
  53.                 <label style="font-weight:bold;">Title:</label><br />
  54.                 <input style="overflow:auto;" name="bph_option[bph_title]" value="<?php echo $bph_title ?>"/><br />
  55.                 <span class="help">Enter a title for your security question</span>
  56.             </p>
  57.             <!-- Question -->
  58.             <p>
  59.                 <label style="font-weight:bold;">Question:</label><br />
  60.                 <textarea style="overflow:auto;" name="bph_option[bph_question]" cols="72" rows="2"><?php echo $bph_question ?></textarea><br />
  61.                 <span>Enter your question here</span>
  62.             </p>
  63.             <!-- Answers -->
  64.             <p>
  65.                 <label style="font-weight:bold;">Answers:</label><br />
  66.                 <textarea style="overflow:auto;" name="bph_option[bph_answers]" cols="72" rows="2"><?php echo $bph_answers ?></textarea><br />
  67.                 <span>Enter answers as a comma separated list</span>
  68.             </p>
  69.             <p>
  70.                 <input name="bph_submit" type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  71.             </p>
  72.         </form>
  73.     </div><!--/.wrap-->
  74. <?php
  75. }
  76.  
  77. function bph_field_value(){
  78.     echo get_bph_field_value();
  79. }
  80. function get_bph_field_value(){
  81.     return apply_filters( 'get_bph_field_value', $_POST['bph_field'] );
  82. }
  83.    
  84. function bph_check_validation(){   
  85.     if (defined('SITE_ID_CURRENT_SITE')) switch_to_blog(SITE_ID_CURRENT_SITE);
  86.     global $bp;
  87.     $bph_field_raw = $_POST['bph_field'];
  88.     $bph_field_txt = strtolower($bph_field_raw);
  89.     echo 'TXT=|'.$bph_field_txt.'|<br>';
  90.     $answer_match = false;
  91.     $answer_cs_list_raw = get_option('bph_answers');
  92.     $answer_cs_list = strtolower($answer_cs_list_raw);
  93.     echo 'LIST=|'.$answer_cs_list.'|<br>';
  94.     $accepted_answers = explode(',', $answer_cs_list);
  95.     echo "<PRE>"; print_r($accepted_answers); echo "</PRE>";
  96.    
  97.     foreach ($accepted_answers as $answer){
  98.         echo '|'.$answer.'|vs|'.$bph_field_txt.'|';
  99.         if ($answer == $bph_field_txt){
  100.             $answer_match = true;
  101.         }  
  102.     }
  103.     if($answer_match == false){
  104.         $bp->signup->errors['bph_field'] = __('Sorry, please answer the question again','buddypress');
  105.     }
  106.        
  107.     if (empty($bph_field_txt) || $bph_field_txt == '') {
  108.         $bp->signup->errors['bph_field'] = __('This is a required field','buddypress');
  109.     }
  110.     if (defined('SITE_ID_CURRENT_SITE')) restore_current_blog();
  111.     return;
  112. }
  113. function bph_show_input_field(){
  114.     if (defined('SITE_ID_CURRENT_SITE')) switch_to_blog(SITE_ID_CURRENT_SITE);
  115. ?>
  116. <div style="float:left;clear:left;width:48%;margin:12px 0;" class="bph_container">
  117.     <h4><?php echo get_option('bph_title')?></h4>
  118.     <p style="font-size:14px"><?php echo get_option('bph_question')?></p>
  119.     <?php do_action('bp_bph_field_errors') ?>
  120.     <input type="text" name="bph_field" id="bph_field" value="<?php bph_field_value() ?>" />
  121.     <br />
  122. </div><?php
  123.     if (defined('SITE_ID_CURRENT_SITE')) restore_current_blog();
  124. }
  125.  
  126. add_action('bp_signup_validate', 'bph_check_validation');
  127. add_action('bp_after_signup_profile_fields', 'bph_show_input_field');
  128. ?>
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement