WordPress.org

Ready to get started?Download WordPress

Forums

Creating a submission form: accessing user details (4 posts)

  1. Jimbopuppy
    Member
    Posted 8 years ago #

    I have searched for the answer to this for the last hour. I am sure it is here somewhere, I must just not be looking in the right place. I must say here that I am new to wordpress and php.

    I have created a plugin that requires users to enter data, so I have a seperate php file that is called and shows the form, and also processes the submission. The issue is that I need to access the current user name when processing: and I can't figure out how. I am thinking "get_currentuserinfo();", but I can't seem to figure out how to get access to that.

    Thanks for any help you can provide.

    Below is the php file

    br />
    <?php

    if (array_key_exists('_submit_check', $_REQUEST)) {
    $aa = !empty($_REQUEST['a_a']) ? $_REQUEST['a_a'] : '';
    $bb = !empty($_REQUEST['b_b']) ? $_REQUEST['b_b'] : '';
    echo $aa;
    echo $bb;
    } else {
    wp_show_page();
    }

    function wp_show_page()
    {
    global $userdata;
    get_currentuserinfo();

    echo('Username: ' . $userdata->user_login . '\n');
    echo('User level: ' . $userdata->user_level . '\n');
    echo('User ID: ' . $userdata->ID . '\n');
    ?>
    <form name="linkform" id="linkform" class="wrap" method="post" action="/wp-content/plugins/subm.php">
    <input type="hidden" name="_submit_check" value="1"/>
    <div style="float: left; width: 98%; clear: both;" class="top">
    <fieldset class="small"><legend>Add new</legend>
    <table>
    </table>
    </fieldset>
    <input type="submit" name="save" class="button bold" value="Save »" />
    </div>
    <div style="clear:both; height:1px;"> </div>
    </form>
    <?php
    }

    ?>

  2. skippy
    Member
    Posted 8 years ago #

    get_currentuserinfo() sets a number of global variables. You can see them all in the function at line 34 in /wp-includes/pluggable-functions.php

    For your convenience, here they are:
    $user_login = $_COOKIE[USER_COOKIE];
    $userdata = get_userdatabylogin($user_login);
    $user_level = $userdata->user_level;
    $user_ID = $userdata->ID;
    $user_email = $userdata->user_email;
    $user_url = $userdata->user_url;
    $user_pass_md5 = md5($userdata->user_pass);
    $user_identity = $userdata->display_name;

    To use any of these, you must make them global, like this:
    global $user_identity;
    get_currentuserinfo();
    if ('' != $user_identity) {
    echo "Hi there, $user_identity!";
    }

  3. Jimbopuppy
    Member
    Posted 8 years ago #

    I've done that, (as you can see at the top of my function wp_show_page()). But I get "Call to undefined function: get_currentuserinfo()". So I think that I need to get access to the WP context somehow. I imagine it is a require_once statement that I am missing, but requiring various things hasn't worked for me. It can never find the files that I require.

  4. Jimbopuppy
    Member
    Posted 8 years ago #

    I looked at the wp-contact-form, and it specifically says that it doesn't have access to the wp functions. So I am not sure if it is even possible. Anyone have any idea what to do?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags