Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • #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 work

    Any ideas?
    Best regards
    Stephan

    #1114986

    What is your code you are trying to include.
    ( Please use code-tag here on board for that to post)

    #1115006

    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='']");

    For example this code. It is not working in plugin context. The shortcode won’t be processed.

    #1115063

    Hi 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,
    Nikko

    #1115067

    Hi 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
    Stephan

    #1115069

    This 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?

    #1115194

    Hi 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,
    Nikko

    #1115243

    Hi,

    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,
    Yigit

    #1115313

    Hi Yigit,
    I’m using 4.5.7

    Best regards
    Stephan

    #1115374

    Hi 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.
    #1115524

    sorry – wrong answer.

    #1115543

    puhhh…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 )

    #1116006

    Hi 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,
    Nikko

    #1116027

    Hi 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 content

    and 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
    Stephan

    #1116888

    Hi 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,
    Nikko

    #1134830

    Hey 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,
    Stephan

    #1134968

    Hi Stephan,

    I apologize for the late notice.
    In the latest version of Enfold (4.6), you can use this hook: avf_shortcode_no_header_request

    Best regards,
    Nikko

    #1135999

    Hey Nikko,

    thank you. Works!

    Best regards
    Stephan

    #1136100

    Hi Stephan,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 19 posts - 1 through 19 (of 19 total)
  • You must be logged in to reply to this topic.