Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The reason for this most likely is that TablePress only registers the Shortcode on the frontend (i.e. when is_admin() is false in the code). The AJAX request probably goes through admin-ajax.php, so that the Shortcode is not registered.
    To change that, please try adding this to the “functions.php” of your theme:

    add_action( 'init', 'load_tablepress_in_the_admin', 11 ) );
    function load_tablepress_in_the_admin() {
      if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
        TablePress::$controller = TablePress::load_controller( 'admin_ajax' );
      }
    }

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Hi Tobias.

    Thanks for your quick response.

    I added the function you gave me but unfortunately the ajax request returns the shortcode: [table id=1 /]

    I have tried different solutions but unfortunately I did not get any results.

    Any idea?

    Thank you again for your reply!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok, that’s strange.
    Have you tried other Shortcodes, to find out if this is maybe some other problem? For example, it might be possible that the AJAX request is simply not evaluating Shortcodes because they are not run through do_shortcodes() (which is usually tied to the the_content filter that is evaluated during a regular page view). This is likely the case if the AJAX request simply returns $post->post_content from the database.

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Yes, I have tried other shortcodes. If the shortcodes are included in the theme are interpreted.

    I tried to install other plugins and inserting the shortcode get the same result

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    with “get the same result”, you mean that the Shortcode is not interpreted, but shown as plain text?
    Then, this is likely an issue in the theme, and you might want to contact the theme developers.

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Hi.

    Only plugins’s shortcodes are displayed as text. The shortcodes’s theme are interpreted correctly.

    The theme I’m using is the wordpress default theme

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok, and how is that AJAX request working then? Are you using a plugin for that?

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Hi.

    Thanks for your patience!

    I installed a fresh copy of wordpress. I’m using twentyfourteen theme.

    This is the code entered in the functions.php file: https://pastebin.com/w7BBgS32

    In the functions.php file I added a simple shortcode.

    This is the javascript code: https://pastebin.com/xSnupVCZ

    I’ve installed tablepress plugin. I created a test table

    I created a test page. I entered my shortcode and shortcode generated by plugin

    When I load page my shortcode is interpreted but the plugin’s shortcode no.

    Need more details?

    Thanks

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, I just noted a mistake in my code… Sorry.
    Please try replacing

    TablePress::$controller = TablePress::load_controller( 'admin_ajax' );

    with

    TablePress::load_controller( 'frontend' );

    exactly like that.

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Thank you! Now it works!

    There is still one small thing: your plugin load javascript in the footer. With ajax javascript are not loaded.

    Is there a way to load javascript with the ajax requests?

    Thank you very much! You are great!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    great to hear that this works! ??

    And the JavaScript is indeed a problem here, but I don’t really see a solution for that. Injecting JavaScript as the result of an AJAX call is tricky (because of security issues that are implied), and I don’t know a standard solution here, sorry.

    Regards,
    Tobias

    Thread Starter surfweb82

    (@surfweb82)

    Thanks for your help!

    For javascript I’ll try to find a solution.

    Have a nice day

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Always glad when I can help!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Run shortcode inside AJAX request’ is closed to new replies.