• Resolved Thimo Grauerholz

    (@pr3ss-play)


    Hi,

    I’m writing a plugin which has to access a different api using authentication. So I need the login creditials provided in the shortcode of the plugin.
    The ajax call has to authenticate at the webapi itself with the provided login creditials.

    How to do this without saving the information in a session cookie or in the ajax file call (url) string? (The ajax call is in the same class)
    Do I have to read the shortcode again (how?) or is there another solution?

    Your help is highly appreciated
    Thimo

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You can execute the shortcode again with do_shortcode(). I would think you could setup the authentication call as part of the shortcode handler function, but I’m not privy to what your process is. You could store credentials in user_meta or options, encrypting data as needed. Another possibility is the Transients API if you do not want to leave a permanent record, though it’s permanent if it’s part of the shortcode attributes in any case.

    As far as getting the credentials to to jQuery to do an AJAX call, you really only have two choices. Echo the variable assignments inside <script> tags, or use wp_localize_script().

    Thread Starter Thimo Grauerholz

    (@pr3ss-play)

    Last night I got my first working solution. I read the shortcode again…

    // get the page id
    $pageData = get_page(intval($_GET[‘pageid’]));
    // get the page content
    $pageContent = $pageData->post_content;
    // parse the shortcode again in content
    $sc = shortcode_parse_atts(str_replace(“[SHORTCODE”,”,str_replace(“]”,””,$pageContent)));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Access to shortcode values in separate ajax function call’ is closed to new replies.