-
AuthorPosts
-
July 1, 2019 at 3:54 pm #1114907
Hello guys,
the do_shortcode function doesn’t work anymore with enfold shortcodes.
I tried to call the function in my plugin but the shortcode isn’t processed. It worked some enfold versions ago. Is there any workaround to process enfold shortcodes in plugins?I tried to call it from theme files – that worked
I tried to call it from enfold child functions.php – didn’t workAny ideas?
Best regards
StephanJuly 2, 2019 at 1:07 am #1114986What is your code you are trying to include.
( Please use code-tag here on board for that to post)July 2, 2019 at 3:53 am #1115006echo do_shortcode("[av_button label='Klick mich' link='' link_target='' size='small' position='center' label_display='' icon_select='yes' icon_hover='' icon='' color='theme-color' custom_bg='#444444' custom_font='#ffffff' av-desktop-hide='' av-medium-hide='' av-small-hide='' av-mini-hide='' av_uid='']");
For example this code. It is not working in plugin context. The shortcode won’t be processed.
July 2, 2019 at 7:36 am #1115063Hi ramotzkie,
Try to set Disabling of template builder elements to Always load all elements in Enfold > Performance.
Let us know if it helps.Best regards,
NikkoJuly 2, 2019 at 7:52 am #1115067Hi Nikko,
doesn’t help :(
I knew it worked some enfold versions ago. I don’t know what changed.What happens if you try to execute the above php code in your child theme functions.php? Does it work?
Best regards
StephanJuly 2, 2019 at 8:04 am #1115069This is my enfold-child/functions.php
<?php /* * Add your own functions here. You can also copy some of the theme functions into this file. * WordPress will use those functions instead of the original functions then. */ echo do_shortcode("[av_button label='Klick mich' link='' link_target='' size='small' position='center' label_display='' icon_select='yes' icon_hover='' icon='' color='theme-color' custom_bg='#444444' custom_font='#ffffff' av-desktop-hide='' av-medium-hide='' av-small-hide='' av-mini-hide='' av_uid='']"); echo do_shortcode('[caption id="attachment_6" align="alignright" width="300"]<img src="https://img-lumas-avensogmbh1.netdna-ssl.com/showimg_dre14_desktop.jpg" alt="Kanagawa" title="The Great Wave" width="300" height="205" class="size-medium wp-image-6" /> The Great Wave[/caption]');
First shortcode isn’t processed. Second shortcode is.
Where is the difference?July 2, 2019 at 3:33 pm #1115194Hi ramotzkie,
The first shortcode is Enfold’s ALB shortcode while the second one is WP shortcode.
I’ll try to ask my colleagues if there’s some workaround for it.Best regards,
NikkoJuly 2, 2019 at 5:09 pm #1115243Hi,
Which version of Enfold are you using? If not the latest 4.5.7, please firstly update Enfold to the latest version as we have fixed a bug with ALB shortcode on non ALB pages in the latest version so it may help. Let us know if it does not!
Best regards,
YigitJuly 3, 2019 at 2:43 am #1115313Hi Yigit,
I’m using 4.5.7Best regards
StephanJuly 3, 2019 at 8:32 am #1115374Hi Stephan,
Regarding to why it wasn’t working in functions.php, it didn’t work because the necessary files for the Enfold (ALB) shortcodes to work isn’t initialized/loaded.
If you use the shortcode inside the body after the necessary files are loaded it should work, for example if I put it in this hook wp_body_open it works fine:function output_content() { echo do_shortcode("[av_button label='Klick mich' link='' link_target='' size='small' position='center' label_display='' icon_select='yes' icon_hover='' icon='' color='theme-color' custom_bg='#444444' custom_font='#ffffff' av-desktop-hide='' av-medium-hide='' av-small-hide='' av-mini-hide='' av_uid='']"); echo do_shortcode(' [caption id="attachment_6" align="alignright" width="300"]<img src="https://img-lumas-avensogmbh1.netdna-ssl.com/showimg_dre14_desktop.jpg" alt="Kanagawa" title="The Great Wave" width="300" height="205" class="size-medium wp-image-6" /> The Great Wave[/caption] '); } add_action( 'wp_body_open', 'output_content', 20 );
As for the plugin, can you give us temporary admin access? so we can try to inspect further on the plugin and try to find out why it’s not working.
Best regards,
Nikko- This reply was modified 5 years, 5 months ago by Nikko.
July 3, 2019 at 5:09 pm #1115524sorry – wrong answer.
July 3, 2019 at 6:49 pm #1115543puhhh…I think I found the problem.
wp_body_open enabled the use of shortcodes in enfold-child/functions.php – that worked
In my plugin I tried to execute a shortcode via ajax call. wp_body_open hadn’t any effect. Ajax calls are always made from backend perspective and the following line killed the shortcode execution:
enfold/config-templatebuilder/avia-template-builder/php/shortcode-template.class.php line 398
if(! is_admin() && ! Avia_Builder()->wp_head_done && ! $no_header_request )
Should ask if there is a ajax call:
if((wp_doing_ajax() || !is_admin()) && ! Avia_Builder()->wp_head_done && ! $no_header_request )
July 5, 2019 at 10:29 am #1116006Hi ramotzkie,
I don’t think you’ll need to check if there’s an ajax call.
Maybe you just need to find the right hook, maybe if you can let us take a look at your plugin maybe we can help better or atleast give you more information that might be helpful.Best regards,
NikkoJuly 5, 2019 at 12:14 pm #1116027Hi Nikko,
Ajax call
(function ($) { $.ajax ({ url: "/wp-admin/admin-ajax.php", type: "GET", dataType: "JSON", data: { action:"add_myfunc", post_id: '.$atts['snippet'][0].', meta_id: '.$atts['snippet'][1].' }, success: function (resp) { if (resp.success) { // success } else { console.log ("Error: " + resp.data) ; } }, error: function (xhr, ajaxOptions, thrownError) { console.log ("Request failed: " + thrownError.message) ; }, }) ; })(jQuery) ;
load shortcode and process it
function load_snippet($post_id, $meta_id) { global $wpdb; $snippet = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."postmeta WHERE post_id = '".$post_id."' AND meta_id = '".$meta_id."'" , OBJECT ); $meta = preg_replace('#\{{{(.*?)\}}}#m', "", $snippet->meta_value); wp_send_json_success (do_shortcode($meta)); }
The shortcode processing is located in shortcode_handler_prepare function in enfold/config-templatebuilder/avia-template-builder/php/shortcode-template.class.php line 341
Please have a look at the function. I can’t find a hook which helps me.
Condition! is_admin()
returns false because ajax request are always made from backend.Later there is a comment in source code:
/**
* In backend we return the shortcode as self closing shortcode only as we might have no reliable info about contentand later another one:
//dont use any shortcodes in backend
Therefore I came to the conclusion that the first part of the function should handle ajax calls as well (but isn’t because of admin context) and the if conditions should be
if((wp_doing_ajax() || !is_admin()) && ! Avia_Builder()->wp_head_done && ! $no_header_request )
If I change the code in that line everything works like expected.
Do you know another way?
Best regards
StephanJuly 9, 2019 at 5:25 am #1116888Hi Stephan,
To be honest, I don’t know if there’s a better way for it, I’ll ask our dev if he knows another way to do it.
Best regards,
NikkoSeptember 6, 2019 at 9:19 am #1134830Hey Nikko,
did you get an answer? I’m still believing that it is unwanted behavior and there should be a check if the call is coming from an ajax call.
Best regards,
StephanSeptember 6, 2019 at 3:46 pm #1134968Hi Stephan,
I apologize for the late notice.
In the latest version of Enfold (4.6), you can use this hook: avf_shortcode_no_header_requestBest regards,
NikkoSeptember 9, 2019 at 1:42 pm #1135999Hey Nikko,
thank you. Works!
Best regards
StephanSeptember 9, 2019 at 4:12 pm #1136100Hi Stephan,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.