致命错误:调用未定义的函数GET_OPTION()

时间:2014-05-05 作者:Tanvir

当我尝试发送邮件时。。。它显示-

致命错误:在/home/junkie/public\\u html/sub\\u demo/wp content/themes/scroller/includes/contact form中调用未定义的函数get\\u option()。php第9行

我的代码=>联系方式。php

<?php
if($_POST)
{
    //check if its an ajax request, exit if not
    if(!isset($_SERVER[\'HTTP_X_REQUESTED_WITH\']) AND strtolower($_SERVER[\'HTTP_X_REQUESTED_WITH\']) != \'xmlhttprequest\') {
        die();
    } 

    $to_Email       = "[email protected]"; //Replace with recipient email address
    $subject        = \'Ah!! My email from Somebody out there...\'; //Subject line for emails

    //check $_POST vars are set, exit if any missing
    if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userPhone"]) || !isset($_POST["userMessage"]))
    {
        die();
    }

    //Sanitize input data using PHP filter_var().
    $user_Name        = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
    $user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
    $user_Phone       = filter_var($_POST["userPhone"], FILTER_SANITIZE_STRING);
    $user_Message     = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);

    //additional php validation
    if(strlen($user_Name)<4) // If length is less than 4 it will throw an HTTP error.
    {
        header(\'HTTP/1.1 500 Name is too short or empty!\');
        exit();
    }
    if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
    {
        header(\'HTTP/1.1 500 Please enter a valid email!\');
        exit();
    }
    if(!is_numeric($user_Phone)) //check entered data is numbers
    {
        header(\'HTTP/1.1 500 Only numbers allowed in phone field\');
        exit();
    }
    if(strlen($user_Message)<5) //check emtpy message
    {
        header(\'HTTP/1.1 500 Too short message! Please enter something.\');
        exit();
    }

    //proceed with PHP email.
    $headers = \'From: \'.$user_Email.\'\' . "rn" .
    \'Reply-To: \'.$user_Email.\'\' . "rn" .
    \'X-Mailer: PHP/\' . phpversion();

    @$sentMail = mail($to_Email, $subject, $user_Message .\'  -\'.$user_Name, $headers);

    if(!$sentMail)
    {
        header(\'HTTP/1.1 500 Could not send mail! Sorry..\');
        exit();
    }else{
        echo \'Hi \'.$user_Name .\', Thank you for your email! \';
        echo \'Your email has already arrived in my Inbox, all I need to do is Check it.\';
    }
}
?>

2 个回复
SO网友:Petr Cibulka

我没有看到任何get_option() 函数位于第9行或代码中的任何其他位置。

快速搜索之后,我猜你的问题与this question on stackoverflow

按照@Ray在链接问题中的建议进行编辑,将其粘贴到代码中,以检查是否wp-includes/option.php 包括:

$includedStuff = get_included_files();
print_r($includedStuff);
如果不是,请自己填写:

include_once(\'wp-includes\\option.php\');
如果这对你有用,别忘了对Ray的答案投赞成票。

SO网友:Frits

如果您的联系方式。php存在于Wordpress安装之外,您需要确保包含wp负载。代码上方的php文件如下:

<?php include \'../../../wp-load.php\'; ?>
/* The rest of your code here */
上述操作适用于主题文件夹根目录中的文件,但如果您不确定您的位置。php文件可能最终位于目录方案中,您可以始终使用以下脚本made by Frankie Jarret:

$parse_uri = explode( \'wp-content\', $_SERVER[\'SCRIPT_FILENAME\'] );
require_once( $parse_uri[0] . \'wp-load.php\' );
/* The rest of your code here */
<小时>

EDIT:

请注意,可调整WP安装的结构,以便wp-content 文件位于安装树之外,在这种情况下,辅助代码块也无法工作。这种情况很少见,但功能确实存在,因此必须在可能的场景中加以考虑。

还有其他需要考虑的可能性,这将要求您彻底修改代码,以使用操作、过滤器和Wordpress的内置函数,从而避免您在文件中尝试和正确加载依赖项。这将是最好的解决方法,上述解决方案只是快速/廉价的解决方法。

结束

相关推荐

如何创建多个顶级管理菜单页面以将数据提交到Options表?

我试图在wordpress主题中创建多个顶级选项页面。但现在我只能保存一个的数据。如何在不必创建选项卡式面板的情况下为两个人保存数据?// create custom plugin settings menu add_action(\'admin_menu\', \'baw_create_menu\'); function baw_create_menu() { //create new top-level menu add_menu_page(\'B