• Resolved internetimage

    (@internetimage)


    Hello,

    I try to run in functions.php a tablepress shortcode.
    The shortcode don’t execute and return the string name.
    An example:

    function process_post() {
          echo do_shortcode("[table id=1 /]");
    }
    add_action("init", "process_post");

    I checked if the plugin is enable and loaded. Can you help me?

    Thanks.

    https://www.ads-software.com/plugins/tablepress/

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I’m afraid that your code won’t work like this. You are basically already printing the Shortcode output on the init hook, which is too early, as it hasn’t been registered then, yet.

    Can you maybe elaborate what you are trying to achieve, so that I can make suggestions?

    Regards,
    Tobias

    Thread Starter internetimage

    (@internetimage)

    Thanks for reply.
    I try to print the table in a pdf.
    When I click “print” I process some parameter in the post variable and print the page with the mpdf library.

    Regards

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    but then the Shortcode should already be in the page?!

    I assume that the problem (with the default post/page content) also is that the Shortcode is printed instead of the table? Is the POST request going to the admin area or to the frontend?

    Regards,
    Tobias

    Thread Starter internetimage

    (@internetimage)

    Hi,

    I print shortcode in a frontend.
    Regards

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    then, just use the Shortcode in the post/page content or the TablePress Template Tags in PHP. That’s the best solution for this.

    Regards,
    Tobias

    Thread Starter internetimage

    (@internetimage)

    I did not understand.

    I use the shortcode in template but i render all in the pdf insted in html page.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    the question is how that PDF saving works, i.e. when its request executes, and in which context. What is the URL for the save request?

    Regards,
    Tobias

    Thread Starter internetimage

    (@internetimage)

    I think, the problem is that I process $_POST in the init hook and I use the shortcode. The hook init is too early. What is the good hook for the shortcode?

    Thread Starter internetimage

    (@internetimage)

    I simplify the code for you:

    add_action('init', 'process_post', 21);
    function process_post() {
     if (isset($_GET['output']) && $_GET['output'] == 'pdf') {
    
            if (shortcode_exists('table')) {
                echo "EXIST";
            } else {
                echo "NOT EXIST";
            }
            echo do_shortcode('[table id=1 /]');
            exit();
    }
    }

    The result is : NOT EXIST [table id=1 /]

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ok, and what is the URL that you are calling to see this output?

    Regards,
    Tobias

    Thread Starter internetimage

    (@internetimage)

    Hi,

    I resolve the problem with the function tablepress_print_table(array('id' => $flip[$post_obj->ID]));

    Thanks!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    very nice! Yes, that’s what I meant. The Template Tag Functions are the proper way to go here.

    Best wishes,
    Tobias

    Hi Tobias!

    Similar but different problem:

    I’ve added a function that sends an email to all subscribers when a new post has been published but it does not parse the tablepress shortcodes when I try to use the following:

    add_action('publish_post', 'notify_subscribers_new_post');
    function notify_subscribers_new_post() {
    //email code...
    $emailcontent = do_shortcode(apply_filters('the_content', $post->post_content, false));
    }

    I’m guessing do_shortcode is being called before the plugin knows what to do with it? Anyway around this?

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    you are correct, TablePress does not load its Shortcodes in the admin area (where your code is run).
    To work around that, please try using the code from the post https://www.ads-software.com/support/topic/tablepress-apple-news?replies=16#post-8277314

    Regards,
    Tobias

    Awesome that worked! ??

    I will donate something on your wordpress plugin page in return for spreading the coding love.

    Regards from Rotterdam,

    Balthazar

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘shortcode in functions.php’ is closed to new replies.