Advertisement
mogaj

update errors

Aug 2nd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. add_action( 'user_profile_update_errors', 'validate_sports_data' );
  2.  
  3. function validate_sports_data(&$errors, $update = null, &$user  = null)
  4. {
  5.     foreach ($_POST['sport'] as $sport) {
  6.       if (is_array($sport)) {
  7.         foreach ($sport as $name) {
  8.           if (empty($name)) {
  9.             $errors->add('empty_person_name', "<strong>ERROR</strong>: Name of the player is empty,Please fill the name of the player.");
  10.           }
  11.           else {
  12.             if (!preg_match("/[A-Za-z]/", $name)) {
  13.               $errors->add('splchar_person_name', "<strong>ERROR</strong>: Name of the player should contain only alpahbets.");
  14.            
  15.             }
  16.           }
  17.         }
  18.       }
  19.     }
  20. }
  21.  
  22. /* Update team details for user when saving his own profile */
  23. add_action( 'personal_options_update', 'update_user_teams' );
  24. /* Update team details for admin when saving other users team details */
  25. add_action( 'edit_user_profile_update', 'update_user_teams' );
  26. /* updating team details callback function */
  27. function update_user_teams( $user_id ) {
  28.   if ( current_user_can( 'edit_user', $user_id ) ) {
  29.     global $wpdb;
  30.     global $projectmanager;
  31.     $dataset_meta = $_POST['sport'];
  32.     if ($_POST['team_status'] == 'yes') {
  33.       $project_title = 'Approved User Teams';
  34.       $project_id = $wpdb->get_var($wpdb->prepare("SELECT (id) FROM {$wpdb->projectmanager_projects} WHERE (title) LIKE ('%s')", $project_title));
  35.       $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->projectmanager_dataset} SET `project_id` = (%d) WHERE (user_id) = (%d)", $project_id, $user_id ) );
  36.     }
  37.     else if ($_POST['team_status'] == 'no') {
  38.       $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->projectmanager_datasetmeta} SET `value` = ('%s') WHERE (dataset_id) = (%d)", maybe_serialize($dataset_meta), $_POST['datasetId'] ) );
  39.     }
  40.   }
  41.   return true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement