WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] using wordpress function getblog_info() in external php file (8 posts)

  1. artflutter
    Member
    Posted 5 years ago #

    I am writing a plugin which is a contact form. The action of the form is to call send.php which parses the information and sends an email. In this file I want to use the code
    <?php $fromsite = get_bloginfo('name'); ?>
    but i'm getting a function not recognised error on get_bloginfo. What do I need to do to get this php script to be able to use wordpress' functions?

  2. artflutter
    Member
    Posted 5 years ago #

    I have viewed pretty much all the wordpress contact form but thus far have been unable to figure out how to resolve this problem.

    my contact forms main php file is called myplugin.php, when you click submit it is processed by another php file called send.php. I assume that in my original php file I need to somehow let wordpress know that send.php is also part of the plugin and I want it to be able to use wordpress' functions. But how do I do this?

  3. adamh
    Member
    Posted 5 years ago #

    Instead of using send.php, why not have the contact form post to itsself (myplugin.php). Then in myplugin, have an 'if' statement to see if the form has been posted

    if($_REQUEST['message']) {
    /* send the contact form */
    /if
  4. whooami
    Member
    Posted 5 years ago #

    if youre passing variables from one file to another you need to set the vars as globals.

    (see variable scope posts) >>

    http://wordpress.org/search/scope?forums=1

    wordpress doesnt need to know that file B is part of the plugin, it doesnt care.

    In the above example, this:

    $fromsite = get_bloginfo('name');

    ought to be set in File A, and passed to File B as a global ...

    Or ..

    The most common is to use functions, define the vars within those functions, and then instead of writing a whole big routine into a file, you just call a function - where everything is already defined.

  5. artflutter
    Member
    Posted 5 years ago #

    thanks for the replies, adamh I initially had my contact form within one html file but I had problems implementing the ajax sumbit and the only way I was able to fix it was to seperate the front-end from the back-end.

    In my second file I am accessing the variables using $_POST['varname'] so I can just add to my original form using hidden inputs like

    <input type="hidden" name="blogname" value="$blogname">

    The only problem with using that method is that one of the variables that I want to pass is an email address using get_the_author_email(). Using a hidden input in the form means that anyone can view this email address by viewing the page source. Is there an alternative way to post this variable?

  6. artflutter
    Member
    Posted 5 years ago #

    whooami I was hoping you'd be able to elaborate further on how I can set $fromsite = get_bloginfo('name'); as a global in file a, so I can access it in file b.

    file a is basically a form plus my variable $fromsite.

    <?php $fromsite = get_bloginfo('name'); ?>
    <form name="form" action="fileb.php>
    <input type="submit/>
    </form>

    and lets say in file b I just want to echo the variable
    <?php echo $fromsite ?>

    What code do I need to add to make $fromsite accessible from fileb?

  7. adamh
    Member
    Posted 5 years ago #

    You could just use

    $_SESSION['blogname'] = get_bloginfo('name')

    in file a (assuming session_start() has been called by wp). Then, in file b

    session_start(); \\ at the very top
    echo $_SESSION['blogname'];
  8. artflutter
    Member
    Posted 5 years ago #

    Hi adamh, thanks for the tip but unfortunately it didn't work for me. I'm sure it would be possible to get it working but I think at the moment I'll just leave things as they are.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags