• Resolved Sean

    (@seannorton)


    I use Pods with users to create a directory on the front end of my staff. I’ve added a Simple (custom defined list) (Custom) field to assign a program that each staff member works in. Then I use a shortcode to display the list of users assigned to that program on the respective webpage. I’ve not had any issues until I added a new user recently.

    Several of my programs have ampersands (ie. Administration & Finance). When assigning this new user to a program with an ampersand, the save does not commit. I did some troubleshooting, and found that I now have to use the HTML entity & in the list but never had a problem with this before. It’s not a huge deal as I simply adjusted that item in the list and made a subsequent change to the shortcode, but want to know if this was a deliberate function update?

    Pods – Custom Content Types and Fields: 2.7.24

    WordPress Version: 5.5.3

    PHP Version: 7.0.18

    MySQL Version: 5.7.18

    Server Software: Apache

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    I’m not sure I fully understand. Did you use & before this? And where did you use it exactly?

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    Thanks for the response, @keraweb

    Allow me to clarify:

    I use Pods to extend my Users so I can add additional fields for the purpose of displaying that data in a staff directory on the front end of my website through a custom shortcode I wrote. One of the Fields is called staff_program and is a Relationship field related to a Simple (custom defined list). The Custom Defined Options contains the program/department names at my office. The Selection Type is Multiple Select and the Format is Checkboxes. If one of the Custom Defined Options has the & character (not the HTML entity) and I check that Option when creating a New User or editing an Existing User, it does not commit on Save. However, that has not always been the case.

    For example:

    I am adding a new User, Jack Black. Jack works in Administration & Finance so I check that Option in the staff_program field and Save.

    I use a custom shortcode to output all users on the front-end of the website, filtered by the staff_program (see below):

    [TCOG_Program_Staff program="Administration & Finance" columns="1"]

    This shortcode should list all Users with the Administration & Finance checkbox selected from the staff_program field in a single column. Up until recently, it worked as expected, so user Jack Black would have displayed.

    However, the Meta does not commit on save, and if I go back to edit user Jack Black it’s like I never checked the box. If I selected a different option that doesn’t contain the ampersand and then saved, it works.

    In troubleshooting, I changed the option from Administration & Finance to Administration & amp; Finance (without the space in the HTML entity for ampersand), saved those changes and the meta was retained. But on the front end of the website in the directory, Jack Black still isn’t displayed with other existing users in the directory who I had previously assigned to the Administration & Finance option.

    So I updated my custom shortcode to be:

    [TCOG_Program_Staff program="Administration & amp; Finance" columns="1"]

    and now ‘Jack Black’ appears in the directory on the front end but the others don’t. I’ve gone back in, re-added the Administration & amp; Finance option to the existing users and everyone appears as designed in the output on the front end.

    ===

    So I’m assuming there was an update to the plugin’s code at some point fairly recently which does not like non-HTML ampersands in the options of a Custom Defined List relationship field.

    Happy to try to re-explain again, lol.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    Ah now I get it!
    Since you use a custom shortcode, could you share how you process the shortcode param?
    Or even better, could you share the function attached to that shortcode?
    It will give me a better understanding on how you to reproduce this case.

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    // Displaying TCOG General Staff
    
    function display_tcog_general_staff($atts) {
    	$args = array(
    		'role' => 'general_staff',
    		'meta_key' => 'last_name',
    		'orderby' => 'meta_value',
    		'order' => 'ASC',
    );
    	$users = get_users($args);
    	$current_col = 0;
    	$colnums = 3; // Number of Columns (we want four per row)
    	$v = '<div class="mfn_heading heading_lines align_center"><h4 class="title" style="color:#3a80f1;"><span class="line line_l" style="background:#000;"></span>Program Staff<span class="line line_r" style="background:#000;"></span></h4></div>';
    	foreach ($users as $user) {
    		// Let's make variables
        	$staff_name = esc_attr($user->user_firstname) . ' ' . esc_attr($user->user_lastname);
        	$staff_id = esc_attr($user->ID);
        	$staff_nickname = esc_attr($user->user_login);
        	$staff_email = esc_attr($user->user_email);
        	$staff_phone = esc_attr($user->staff_phone);
        	$staff_title = esc_attr($user->staff_title);
        	$staff_program = esc_attr($user->staff_program);
        	$staff_department = esc_attr($user->staff_department);
    		$staff_role = esc_attr(array_shift($user->roles));
    	//  $staff_bio = esc_attr($user->user_description); //User biography 
    	if('' != pods_image($user->staff_picture, 'thumbnail')){
    		$staff_avatar = pods_image_url($user->staff_picture, array(400,400), $default, true);}
    	else {
    		$staff_avatar = '[URL TO DEFAULT AVATAR REMOVED]';};
    		$staff_department = esc_attr($user->staff_department);
    
    		// Let's start displaying staff
    			if($current_col == 0) {
    					$v .= '<div class="wrap mcb-wrap one valign-top clearfix">';
    			}
    			$v .= do_shortcode('<div class="column mcb-column one-fourth">[our_team image="' . $staff_avatar . '" title="' . $staff_name . '" subtitle="' . $staff_title . '" email="' . $staff_email . '" phone="' . $staff_phone . '" style="circle"][/our_team]</div>');
    			if ($current_col == $colnums) {
    				$current_col = 0;
    				$v .='</div><div class="column mcb-column one column_divider "><hr class="no_line"></div>';
    			}
    			else {
    				$current_col += 1;
    			}
    		}
    $v .='</div>';		
    return $v;
    }
    add_shortcode('TCOG_General_Staff','display_tcog_general_staff');

    Here’s the function for the shortcode.

    • This reply was modified 5 years, 6 months ago by Sean.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    I don’t see any reference to the program argument in there, correct?
    Even more, the whole $atts variable isn’t used at all..

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    @keraweb sorry for the delayed response as I have been out of office over the last week.

    Oops! I pasted the wrong function. The below code includes the program argument and $atts variable.

    // Displaying TCOG Program Staff in # columns based on program parameter [TCOG_Program_Staff program="Program Name" columns="#"]
    
    function display_tcog_program_staff($atts) {
    	extract( shortcode_atts( array('program'=>'program','columns'=>'columns'), $atts) );
    	// $program = esc_attr($program);
    	$column_count = esc_attr($columns);
    	$col_class = $column_count;
    	switch ($col_class) {
    		default:
    			$col_class = 'one-third';
    		case '1':
    			$col_class = 'one';
    			break;
    		case '2':
    			$col_class = 'one-second';
    			break;
    		case '3':
    			$col_class = 'one-third';
    			break;
    		case '4':
    			$col_class = 'one-fourth';
    			break;
    		case '5':
    			$col_class = 'one-fifth';
    			break;
    		case '6':
    			$col_class = 'one-sixth';
    			break;
    	}
    	$args = array(
    		'role__not_in' => array( 'senior_leadership', 'program_manager', 'executive_director' ),
    		'meta_key' => 'staff_program',
    		'meta_value' => $program,
    		'meta_query' => array( 'lastname' => array('key' => 'last_name') ),
    		'orderby' => 'lastname',
    		'order' => 'ASC',
    );
    	$users = get_users($args);
    	$current_col = 0;
    	$colnums = $column_count - 1; // Number of Columns
    	// $column_count += 1;
    	$v = '<div class="mfn_heading heading_lines align_center"><h4 class="title" style="color:#3a80f1;"><span class="line line_l" style="background:#000;"></span>Program Staff<span class="line line_r" style="background:#000;"></span></h4></div>';
    	foreach ($users as $user) {
    		// Let's make variables
        	$staff_name = esc_attr($user->user_firstname) . ' ' . esc_attr($user->user_lastname);
        	$staff_id = esc_attr($user->ID);
        	$staff_nickname = esc_attr($user->user_login);
        	$staff_email = esc_attr($user->user_email);
        	$staff_phone = esc_attr($user->staff_phone);
        	$staff_title = esc_attr($user->staff_title);
        	$staff_program = esc_attr($user->staff_program);
        	$staff_department = esc_attr($user->staff_department);
    		$staff_role = esc_attr(array_shift($user->roles));
    	    $staff_bio = esc_attr($user->user_description); //User biography 
    	if('' != pods_image($user->staff_picture, 'thumbnail')){
    		$staff_avatar = pods_image_url($user->staff_picture, array(400,400), $default, true);}
    	else {
    		$staff_avatar = '[URL TO DEFAULT AVATAR REMOVED]';};
    		$staff_department = esc_attr($user->staff_department);
    
    		// Let's start displaying staff
    			if($current_col == 0) {
    					$v .= '';
    			}
    			$v .= do_shortcode('<div class="column mcb-column ' . $col_class . '">[our_team image="' . $staff_avatar . '" title="' . $staff_name . '" subtitle="' . $staff_title . '" email="' . $staff_email . '" phone="' . $staff_phone . '" style="circle"]<p>' . $staff_bio . '</p>[/our_team]</div>');
    			if ($current_col == $colnums) {
    				$current_col = 0;
    				$v .='<div class="column mcb-column one column_divider"><hr class="no_line"></div>';
    			}
    			else {
    				$current_col += 1;
    			}
    		}
    return $v;
    }
    add_shortcode('TCOG_Program_Staff','display_tcog_program_staff');
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    Ah right, so you are using these special chars in the actual meta values?
    Though for stability I would discourage this, it should work. It might be needed to decode HTML entities to be sure.
    What is the actual $args content before your pass it to get_users()? Is the & sign already converted to something else there?

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    Yes, since I began using this function with Pods as a shortcode, I have used the special character & in the meta value for staff_program field as well as in the shortcode to display program staff. I’ve never converted it. As mentioned, now if the ampersand character is an option in the choice field the value does not save when I update a user.

    It now only works if I use the encoded HTML entity &amp; on both the user entry side and the display side on the front end. (If you suggest I should always be using the encoded entity rather than the special char please let me know, PHP is not my native language, lol).

    For the $args, I have several custom user roles defined. I use roles to differentiate between our different levels of management. In the function above, I am looking for get_users() who don’t have a management role and who match a program specified in the shortcode. IE: [TCOG_Program_Staff program="Administration &amp; Finance" columns="1"] will find all users with Administration &amp; Finance meta_value in the staff_program field/meta_key. The users will be displayed in 1 column ordered by last_name.

    Thread Starter Sean

    (@seannorton)

    Again, my point is for over two years I have been able to user the special char & in a Custom Defined Option for a Simple (custom defined list) Relationship field. Now whenever I select an option that contains that special char (in my example, Administration & Finance and Save or Update a user, that option does not commit. It now only commits if I change the option in the Pod to Administration &amp; Finance.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    I’m not 100% sure but this sounds like it might have something to do with a WordPress update, not with a Pods update.
    The parsing of shortcode parameters and get_users() arguments is all WordPress core, not Pods.

    So, in short, you’ll have to debug what is actually being passed on to the database and what is actually stored in the database. Compare that, and find a way to properly fix this comparison.

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    @keraweb I totally appreciate that and will definitely investigate/debug on my end regarding the shortcode. However, the part of the issue which is relevant to you is not the shortcode, but an issue with the Pods plugin itself. (Admittedly, we went on a tangent when discussing the shortcode).

    As mentioned, I have a User (extended) Pod Type. The purpose of this Pod is to add additional fields to my Users.

    One of the fields I created has the label Program and the name staff_program

    The Field Type is Relationship and related to Simple (custom defined list). Additional field options are a Multiple Select Selection Type, with a format of Checkboxes.

    I have created a list of Custom Defined Options.

    For the sake of example, here are my options:

    Administration & Finance
    Client Services
    GIS & Planning
    Transportation

    When I create a new User, if I select Administration & Finance or GIS & Planning and save the User, the option does not save. I never had an issue with this Pod before. I’ve always been able to choose one of those options for a User and the value is stored when I save. If I select Client Services or Transportation options and save the User, those options will save. Furthermore, I can see that existing users who previously had either Administration & Finance or GIS & Planning options selected for the staff_program field still have that meta stored but if I were to uncheck that option, save, and then re-check it and save it does not get stored. So this new issue affects not only new users but also existing users if they get edited.

    After troubleshooting, I can say with confidence that the & character causes this problem. If I used the encoded ampersand &amp; the problem goes away. That leads me to believe there was a change in the Pods plugin that created this issue. I just want to know if that’s a bug because I certainly can’t believe I am the only one who uses an ampersand in options.

    You see, the solution to this problem is what I desire. Please disregard everything else about the shortcode, Jory.

    PS. Thank you for this plugin and the continued development over the years. It is a great plugin with a quality build.

    • This reply was modified 5 years, 6 months ago by Sean. Reason: Added troubleshooting info near end of reply
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @seannorton

    Ah, thanks for getting the topic back on track haha.
    I’ve tested this locally and could reproduce this.

    I’ve created a patch here: https://github.com/pods-framework/pods/pull/5895

    Keep in mind though that while I did create a patch for backwards compatibility.. I do personally think this is incorrect usage of the database. HTML entities should be avoided for storage in all cases, especially if they are used for filtering.

    It’s best to define values and labels separately, example:

    administration|Administration & Finance
    client|Client Services
    planning|GIS & Planning
    transportation|Transportation

    Cheers, Jory

    Thread Starter Sean

    (@seannorton)

    Perfect. Tested this and works perfect. Thank you for your assistance, Jory. I will implement your recommendations.
    Cheers!

    Plugin Author Jory Hogeveen

    (@keraweb)

    You’re welcome! The best way to say thanks is to leave a 5 star review at https://ww.wp.xz.cn/plugins/pods/ and (if you’re feeling especially generous) become a Friend of Pods at https://friends.pods.io/

    Cheers, Jory

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘User (extended) pod type – HTML’ is closed to new replies.