-
AuthorPosts
-
January 26, 2022 at 11:35 am #1337246
Hi
We have a plugin which generates Enfold shorcodes from a database and put them on a page of a website.The shortcode is generated like this:
[av_one_fourth first min_height="" vertical_alignment="" space="" custom_margin="" margin="0px" padding="0px" border="" border_color="" radius="0px" background_color="" src="" background_position="top left" background_repeat="no-repeat" animation="" mobile_breaking="" mobile_display="" av_uid="av-5ca50s"] [av_team_member name="Aerni Mike" job="" src="/wp-content/uploads/2019/02/aerni-mike.jpg" attachment="11198" attachment_size="portfolio" image_width="" description="blablabla" font_color="custom" custom_title="#cb2323" custom_content="#000000" av_uid="av-55esp8" admin_preview_bg="rgb(241, 241, 241)"] [av_team_icon title="Facebook" link="https://www.facebook.com/MikeAerni" link_target="_blank" icon="ue8f4" font="entypo-fontello" av_uid="av-2it3rg"] [av_team_icon title="Instagram" link="https://www.instagram.com/michael_aerni" link_target="_blank" icon="ue909" font="entypo-fontello" av_uid="av-9ao3o"] [/av_team_member] [/av_one_fourth]
The following attributes of the team member are from the database:
- name
- src
- description
The other stuff is for every entry the same.
Now, I think since the last Enfold update, all entries have the same picture. It’s always the picture of the first entry.
What we can do for that it will work again?
Is it a problem, that this attributes have the same value?- attachment
- av_uid
You find the link of the website in the private content section.
Thanks very much.
Best regards
MikeJanuary 27, 2022 at 5:58 am #1337406Hey Michael,
Thank you for the inquiry.
The plugin is probably applying the same value to the src attribute for every team member shortcode. Unfortunately, we cannot confirm this without checking the plugin. Would you mind directing us to the code in the plugin that generates the team member shortcode?
Best regards,
IsmaelJanuary 27, 2022 at 8:27 am #1337425Hi Ismael
But if that was the problem, it would never have worked, would it?
Here is the code part of the plugin which generates the member shortcodes.$teamMembers = ''; $count = 4; foreach ( $rows as $row ) { $teamMember = ''; if ($count === 4) { $teamMember .= "[av_one_fourth first min_height=\"\" vertical_alignment=\"\" space=\"\" custom_margin=\"\" margin=\"0px\" padding=\"0px\" border=\"\" border_color=\"\" radius=\"0px\" background_color=\"\" src=\"\" background_position=\"top left\" background_repeat=\"no-repeat\" animation=\"\" mobile_breaking=\"\" mobile_display=\"\" av_uid=\"av-5ca50s\"]"; $count = 0; } else { $teamMember .= "[av_one_fourth min_height=\"\" vertical_alignment=\"\" space=\"\" custom_margin=\"\" margin=\"0px\" padding=\"0px\" border=\"\" border_color=\"\" radius=\"0px\" background_color=\"\" src=\"\" background_position=\"top left\" background_repeat=\"no-repeat\" animation=\"\" mobile_breaking=\"\" mobile_display=\"\" av_uid=\"av-5ca50s\"]"; } $teamMember .= "[av_team_member name=\"" . $row["name"] . " " . $row["vorname"] . "\" job=\"\" src=\"" . $row["bild"] . "\" attachment=\"11198\" attachment_size=\"portfolio\" image_width=\"\" description=\""; $teamMember .= "Instrument: " . $row["instrument"] . "<br />"; $teamMember .= "Mitglied seit: " . $row["mitglied_seit"]; $teamMember .= "<br />"; $teamMember .= "\" font_color=\"custom\" custom_title=\"#cb2323\" custom_content=\"#000000\" av_uid=\"av-55esp8\" admin_preview_bg=\"rgb(241, 241, 241)\"]"; if (strlen($row["facebook"]) > 0) { $teamMember .= "[av_team_icon title=\"Facebook\" link=\"https://www.facebook.com/" . $row["facebook"] . "\" link_target=\"_blank\" icon=\"ue8f4\" font=\"entypo-fontello\" av_uid=\"av-2it3rg\"]"; } if (strlen($row["instagram"]) > 0) { $teamMember .= "[av_team_icon title=\"Instagram\" link=\"https://www.instagram.com/" . $row["instagram"] . "/\" link_target=\"_blank\" icon=\"ue909\" font=\"entypo-fontello\" av_uid=\"av-9ao3o\"]"; } $teamMember .= "[/av_team_member]"; $teamMember .= "[/av_one_fourth]"; $teamMembers .= $teamMember; $count = $count + 1; } $content .= do_shortcode($teamMembers); return $content;
Thanks very much.
Best regards
MikeJanuary 27, 2022 at 10:45 am #1337474Hi,
Thank you for the info.
But if that was the problem, it would never have worked, would it?
The element will still render even if they contain the same image. Regarding this line..
foreach ( $rows as $row ) {
Where do you get the value of $rows? Have you tried checking if the “bild” item in each row actually contains a different image or value?
Best regards,
IsmaelJanuary 27, 2022 at 1:30 pm #1337504Hi Ismael
I read this values from an external database.
Yes, this I already tried, every entry has another image (bild).
I just dumped out the values on the website, see it in private content section (data protection).
Best regards
MikeJanuary 27, 2022 at 1:35 pm #1337506Hi Ismael
I just dumped out the real shorcode which but without the command do_shortcode.
As you can see, also there are different images set in the shortcode,see in private content section (data protection).
Perhaps it is a problem between WordPress 5.9 and Enfold?
Best regards
MikeJanuary 27, 2022 at 3:25 pm #1337537Hi Ismael
Just an addition.
We went back from WordPress 5.9 to 5.8.3. This had no effect, the pictures still are not there.
Then we went back from Enfold 4.8.9 to 4.8.8.1. This had an effect- the shorcode worked again!
So it is an Enfold problem.
Just before I also saw other problems with websites where we updated Enfold, For example on the Website mentioned in the private content section, the Slider comes twice instead of once…
So, it seems there are a lot of Problems with the new Enfold version ;-(
Best regards
Mike- This reply was modified 2 years, 9 months ago by YourChoice Informatik GmbH.
January 27, 2022 at 8:20 pm #1337574Hi Ismael
For the problem with the domain mentioned in my last reply I will open a new issue because this is very special ;-(
Best regards
MikeJanuary 28, 2022 at 9:06 am #1337631Hey!
Thank you for the info.
We copied the shortcodes above on our installation and it properly render a different image for each Team Member element. You can check the screenshot in the private field. Can we have access to the plugin? Please send it in a zip file so that we can test it on our installation.
Regards,
IsmaelJanuary 28, 2022 at 9:54 am #1337650Hey Ismael
Yes, shure.
Find the link to the plugin zip file and the database sql in the private content section.
You have to create this database on the same host where the wordpress instance runs.Please replace the image links in the table mitglieder with real image links (i.e. /wp-content/uploads/2022/01/kriesi.jpg)
Then you have to configure the plugin (Settings – YourChoice GCST)
Then you can use this shortcode: [gcst_members type=’TYPE’]
See possible types in the private content section.
Thanks very much.
Best regards
MikeJanuary 28, 2022 at 12:58 pm #1337708Hi,
Thanks for the info.
The issue probably occurs in the gcst_board_members_shortcode_content function within the yc-wp-gcst/yourchoice-gcst.php file, around line 284. The value of the attachment attribute is statically set to “11198”. The value of this attribute should be ID of the image.
$teamMember .= "[av_team_member name=\"" . $row["name"] . " " . $row["vorname"] . "\" job=\"" . $row["funktion"] . "\" src=\"" . $row["bild"] . "\" attachment=\"11198\" attachment_size=\"portfolio\" image_width=\"\" description=\"\" font_color=\"custom\" custom_title=\"#cb2323\" custom_content=\"#cb2323\" av_uid=\"av-5ca50s\" admin_preview_bg=\"rgb(34, 34, 34)\"][/av_team_member]";
Best regards,
IsmaelJanuary 28, 2022 at 1:30 pm #1337714Hi Ismael
Okey, but this code is also in the gcst_members_shortcode_content and it worked with Enfold 4.8.8.1.
But I can test if it works with the dynamic ID of the image… Do you know, how I can get this ID with PHP code?
Thanks very much.
Best regards
MikeJanuary 28, 2022 at 1:42 pm #1337717Hi Ismael
Just another question.
Would it be also better, when we set av_uid dynamically? And if yes, what would you propose how to do this?
Best regards
MikeJanuary 28, 2022 at 2:38 pm #1337731Hi Ismael
I found a code snippet and tested to get the ID of the attachement:global $wpdb; $prefix = $wpdb->prefix; $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM " . $prefix . "posts" . " WHERE guid='" . $image_url . "';")); return $attachment[0];
Unfortunately, it does not return an id for all images… with some images it returns nothing… do you have another method to get that ID?
Is the attribute attachement mandatory? Or what happens, when we use it empty?January 28, 2022 at 5:11 pm #1337776HI Ismael
I found another code snippet which seams to work and returns for every image an ID:$attachment_id = 0; $dir = wp_upload_dir(); if ( false !== strpos( $url, $dir['baseurl'] . '/' ) ) { // Is URL in uploads directory? $file = basename( $url ); $query_args = array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'meta_query' => array( array( 'value' => $file, 'compare' => 'LIKE', 'key' => '_wp_attachment_metadata', ), ) ); $query = new WP_Query( $query_args ); if ( $query->have_posts() ) { foreach ( $query->posts as $post_id ) { $meta = wp_get_attachment_metadata( $post_id ); $original_file = basename( $meta['file'] ); $cropped_image_files = wp_list_pluck( $meta['sizes'], 'file' ); if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) { $attachment_id = $post_id; break; } } } } return $attachment_id;
Now I updated again to Enfod 4.8.9 and it seems to work! Great, thank you very much!
But now, I have some questions:
- Where can I see the mandatory attributes for your shortcodes?
- Can I omit empty attributes?
- I generated the av_team_member with Enfold 4.8.9 and I saw a few new attributes, do I have to add them to my generator code?
- What is with the attribute av_uid? Can I leave this blank? Or do I have to generate a random string?
Thanks very much.
Best regards
Mike- This reply was modified 2 years, 9 months ago by YourChoice Informatik GmbH.
January 31, 2022 at 10:58 am #1338009Hi,
Where can I see the mandatory attributes for your shortcodes? Can I omit empty attributes? I generated the av_team_member with Enfold 4.8.9 and I saw a few new attributes, do I have to add them to my generator code?
There are no mandatory attributes in a shortcode. You can use the av_team_member shortcode without any attributes and it will still work but it will not render anything because there’s no data.
What is with the attribute av_uid?
The builder by default applies a unique id to each elements shortcodes in a page or post, but the element will still render with or without the ID. The ID is generated dynamically using Javascript and is based on the current date, which is then converted to a string and prepended with “av-“.
'av-' + ( new Date().getTime()).toString(36);
Best regards,
IsmaelJanuary 31, 2022 at 8:15 pm #1338083Hi Ismael
Thanks very much. So we will also generate an ID like this for the generated shortcodes. Why you do that with Javascript and noth with PHP?
And what is about my second question? Can we see somewhere, which attributes of a shortcode are mandatory and which are not? Because with new Enfold versions there come always new attributes, but we do not know, if they are needed/mandatory or not…
Thanks very much
Best regards
MikeFebruary 1, 2022 at 9:15 am #1338166Hi,
As I have said earlier, there are no mandatory attributes. The shortcodes should work fine with or without any of the attributes, at least in the case of the Team Member element. Please review my response above.
About the uid, you should be able to convert the Javascript code above to PHP. You can also create your own code to generate a random string. Just make sure that to prepend the text “av-” in front of the generated characters. This function might help.
// https://www.w3schools.com/php/func_string_md5.asp
Best regards,
IsmaelFebruary 1, 2022 at 9:17 am #1338167Hi Ismael
I had overlooked that you wrote that no attribute is mandatory, sorry ;-)
Yes, I already found this PHP function and we will use it…
Thanks very much, you can close this issue.
Best regards
Mike -
AuthorPosts
- The topic ‘Team Member Shortcode does not work anymore’ is closed to new replies.