• Resolved ldeschenes

    (@ldeschenes)


    Hi, I did activate de debug.log for other reasons and find out that I get PHP errors for Code Snippet.

    Here are the errors :

    [06-Apr-2023 16:38:23 UTC] PHP Notice: Undefined index: profile_privacy in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 23
    [06-Apr-2023 16:38:23 UTC] PHP Notice: Trying to access array offset on value of type null in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 23

    [06-Apr-2023 16:38:23 UTC] PHP Notice: Undefined index: phone_number in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 20
    [06-Apr-2023 16:38:23 UTC] PHP Notice: Trying to access array offset on value of type null in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 20

    [06-Apr-2023 16:38:23 UTC] PHP Notice: Undefined index: notes in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 22
    [06-Apr-2023 16:38:23 UTC] PHP Notice: Trying to access array offset on value of type null in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 22

    [06-Apr-2023 16:38:23 UTC] PHP Notice: Undefined index: mobile_number in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 21
    [06-Apr-2023 16:38:23 UTC] PHP Notice: Trying to access array offset on value of type null in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 21

    And this one which is different :

    [06-Apr-2023 16:38:27 UTC] PHP Notice: Undefined index: id in /home3/lelaurie/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()’d code on line 52

    I believe it is cause by the following snippet. What I am doing wrong ?

    // wpdatatables_filter_excel_array( $parsedArray, $tableId, $filePath )
    
    add_filter('wpdatatables_filter_excel_array','liste_des_residents', 10, 3 );
    
    function liste_des_residents ( $parsedArray, $tableId, $filePath ) {
    
    	$myparsedArray = $parsedArray;
    	if ( $tableId == 44 || $tableId == 45 || $tableId == 46 || $tableId == 80 ) {
    		// Create Resident Array	
    		$Resident = array();
    		$loginuser =  wp_get_current_user();
    		$users = get_users();
    		$i=0;
    		foreach ( $users as $user ) {
    			$UserMeta  = get_user_meta( $user->ID );  
    			$Resident[$i]['Appartement']    = $UserMeta['appartement'][0];    
    			$Resident[$i]['Nom']            = $UserMeta['first_name'][0] . " " . $UserMeta['last_name'][0];
    			$Resident[$i]['Statut']         = $UserMeta['role'][0];
    			$Resident[$i]['Courriel']       = $user->user_email;
    			$Resident[$i]['Téléphone']      = $UserMeta['phone_number'][0];
    			$Resident[$i]['Mobile']         = $UserMeta['mobile_number'][0];
    			$Resident[$i]['InfoSuppl']      = $UserMeta['notes'][0];
    			$Resident[$i]['Privé']          = $UserMeta['profile_privacy'][0];
    			$Resident[$i]['Approbation']    = $UserMeta['account_status'][0];
    			if ( $tableId == 44 || $tableId == 46 || $tableId == 80 ) { $Resident[$i]['Profil'] =
    				   "https://lelaurier.net/user/" . $UserMeta['um_user_profile_url_slug_name'][0] . "||"
    				                                 . '<i class="fas fa-external-link-square-alt"></i>'; }
    //				                                 . '<i class="fas fa-external-link-alt"></i>'; }	
    			if ( $tableId == 45 && $user == $loginuser ) { $Resident[$i]['Profil'] =
    				   "https://lelaurier.net/user/" . $UserMeta['um_user_profile_url_slug_name'][0] . "/?um_action=edit" . "||Modifier"; }	
    			if ( $tableId == 45 && $user != $loginuser ) { $Resident[$i]['Profil'] =
    				   "https://lelaurier.net/user/" . $UserMeta['um_user_profile_url_slug_name'][0] . "||Afficher"; }	
    			$Resident[$i]['ID']             = $user->ID;
    			$Resident[$i]['Registered']     = $user->user_registered;			
    			$i++;
    		}
    		
    		// Sort Array par Appartement
    		$sort_col = array();
    		foreach( $Resident as $key=>$row) {
    		    $sort_col[$key] = $row['Appartement'];
    	    }
    		array_multisort($sort_col, SORT_ASC , $Resident);
    		
    //		if ( $tableId == 44 ) {
    //			// Replace Array by Résidents
    //			$myparsedArray = $Resident;
    //			// echo '<pre>'; print_r($myparsedArray); echo '</pre>';
    //		}
    
    		if ( $tableId == 44 ) {
    			unset( $myparsedArray[0] );
    			$i=0;
    			foreach ( $Resident as $key => $value ) {
    				if ( $value['Appartement'] != "001" && $value['Appartement'] != "999" ) {
    					$myparsedArray[$i] = $Resident[$key];
    					}
    				$i++;
    				}
    		}		
    		
    		
    		if ( $tableId == 45 ) {
    			$appartement = get_user_meta( get_current_user_id(), 'appartement', true );
    			unset( $myparsedArray[0] );
    			$i=0;
    			foreach ( $Resident as $key => $value ) {
    				if ( $value['Appartement'] == $appartement ) {
    					$myparsedArray[$i] = $Resident[$key];
    					}
    				$i++;
    				}
    		}
    		
    		if ( $tableId == 46 ) {
    			unset( $myparsedArray[0] );
    			$i=0;
    			foreach ( $Resident as $key => $value ) {
    				if ( $value['Approbation'] == "awaiting_admin_review" ) {
    					$myparsedArray[$i] = $Resident[$key];
    					}
    				$i++;
    				}
    		}
    
    		if ( $tableId == 80 ) {
    			
    // 			Sort Array par Registered Date
    			$sort_col = array();
    			foreach( $Resident as $key=>$row) {
    		   		 $sort_col[$key] = $row['Registered'];
    	    	}
    			array_multisort($sort_col, SORT_DESC , $Resident);			
    			
    			unset( $myparsedArray[0] );
    			$i=0;
    			foreach ( $Resident as $key => $value ) {
    				if ( $value['Registered'] > date("Y-m-d",strtotime("-1 year")) && $value['Approbation'] <> "awaiting_admin_review" ) {
    					if ( $value['Appartement'] != "001" && $value['Appartement'] != "999" ) {
    					$myparsedArray[$i] = $Resident[$key];
    					}
    					}
    				$i++;
    				}
    		}	
    	
    	}
    	return $myparsedArray;
    }
    
    
Viewing 1 replies (of 1 total)
  • Thread Starter ldeschenes

    (@ldeschenes)

    Problems resolved.

    Some $UserMeta dd not exist for all users.

    Fix by using “If (isset($UserMeta[‘meta-id’][0])) before assigning.

Viewing 1 replies (of 1 total)

The topic ‘PHP errors’ is closed to new replies.