User (extended) pod type – HTML
-
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
-
Hi @seannorton
I’m not sure I fully understand. Did you use
&before this? And where did you use it exactly?Cheers, Jory
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_programand is aRelationshipfield related to aSimple (custom defined list). TheCustom Defined Optionscontains the program/department names at my office. TheSelection TypeisMultiple Selectand the Format isCheckboxes. If one of theCustom Defined Optionshas the & character (not the HTML entity) and I check thatOptionwhen creating aNew Useror editing anExisting User, it does not commit onSave. However, that has not always been the case.For example:
I am adding a new
User, Jack Black. Jack works inAdministration & Financeso I check thatOptionin thestaff_programfield andSave.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 & Financecheckbox selected from thestaff_programfield in a single column. Up until recently, it worked as expected, so userJack Blackwould have displayed.However, the Meta does not commit on save, and if I go back to edit user
Jack Blackit’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 & FinancetoAdministration & 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 theAdministration & Financeoption.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; Financeoption 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.
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
// 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.
Hi @seannorton
I don’t see any reference to the
programargument in there, correct?
Even more, the whole$attsvariable isn’t used at all..Cheers, Jory
@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
programargument and$attsvariable.// 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');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$argscontent before your pass it toget_users()? Is the&sign already converted to something else there?Cheers, Jory
Yes, since I began using this function with Pods as a shortcode, I have used the special character
&in the meta value forstaff_programfield 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
&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 userrolesdefined. I userolesto differentiate between our different levels of management. In the function above, I am looking forget_users()who don’t have a management role and who match a program specified in the shortcode. IE:[TCOG_Program_Staff program="Administration & Finance" columns="1"]will find alluserswithAdministration & Financemeta_value in thestaff_programfield/meta_key. The users will be displayed in 1 column ordered bylast_name.Again, my point is for over two years I have been able to user the special char
&in aCustom Defined Optionfor aSimple (custom defined list)Relationship field. Now whenever I select an option that contains that special char (in my example,Administration & Financeand Save or Update a user, that option does not commit. It now only commits if I change the option in the Pod toAdministration & Finance.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 andget_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
@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
Programand the namestaff_programThe Field Type is
Relationshipand related toSimple (custom defined list). Additional field options are aMultipleSelect Selection Type, with a format ofCheckboxes.I have created a list of Custom Defined Options.
For the sake of example, here are my options:
Administration & Finance Client Services GIS & Planning TransportationWhen I create a new User, if I select
Administration & FinanceorGIS & Planningand 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 selectClient ServicesorTransportationoptions and save the User, those options will save. Furthermore, I can see that existing users who previously had eitherAdministration & FinanceorGIS & Planningoptions selected for thestaff_programfield 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&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
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|TransportationCheers, Jory
Perfect. Tested this and works perfect. Thank you for your assistance, Jory. I will implement your recommendations.
Cheers!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
-
This reply was modified 5 years, 6 months ago by
The topic ‘User (extended) pod type – HTML’ is closed to new replies.