简体   繁体   中英

PHP and capturing current user from wordpress site

So I have a PHP page that I am calling from a WordPress page so that I can run a php INSERT. The problem is, the PHP template will not define the current user id when I call wp_get_current_user(); below. I have a form and want to insert what the current user enters to insert into the db for that user's bio. Does this mean I need to pass this variable to this php template from the wordpress page URL link I have to this form? If so, not sure of the formatting/code to do so. But ideally, if this template could somehow get the current user without needing to send it that would be huge!

<?php
    //connect
    }
    mysql_select_db("i80_wp1",$con);

    // Get the current user's info 
    $current_user = wp_get_current_user();


    if(isset($_POST['update'])) { 
        $UpdateQuery = 
            "UPDATE wp_usermeta SET author_bio='".$_POST['author_bio']."'WHERE
            user_id=$current_user and author_bio='".$_POST['hidden']."'";
            mysql_query($UpdateQuery, $con);

to access the wordpress functions in any external php file, copy the below two line of code at the top of your php file.

<?php $blogheader = explode("wp-content",$_SERVER["SCRIPT_FILENAME"]);
include $blogheader[0]."wp-blog-header.php"; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM