如果为true,则调用wordpress中定义的变量require_once文件,否则需要不同的文件

时间:2015-12-18 05:02:06

标签: php wordpress variables gravity-forms-plugin

我正在尝试在wordpress中的页面模板上定义开发模式但是当我尝试在functions.php中调用它时,我可以让它返回真或假的罚款,但我希望它包含一个特定的PHP脚本文件是真还是假,没有发生。

 define('development', true);

然后调用functions.php

function developmentMode() {

if(defined('development')){ 
    echo "dev mode.<br />\n"; 
    require_once( get_template_directory() . '/function-includes/dev.php');     
}else{ 
    echo "live mode.<br />\n"; 
    require_once( get_template_directory() . '/function-includes/live.php');
}

 }
 add_action( 'wp_footer', 'developmentMode' );

我可以让echo在每个页面上正常工作。我只是无法运行自定义.php脚本。

脚本是重力表单的专用钩子,需要在发送表单后运行。

我需要有一个测试文件和一个基于我设置的实时文件,或者一个变量可能更好。

任何帮助非常感谢

继承人尝试添加

的包含文件
<?php
add_action('init', 'register_my_session');
  function register_my_session()
  {
   if( !session_id() )
   {
     session_start();
     }
   }
  //add_action("gform_register_init_scripts`", "add_hit", 10, 0);
 //add_action("wp_loaded", "add_hit", 10, 0);
 add_action( 'wp_ajax_add_hit', 'add_hit' );
 add_action( 'wp_ajax_nopriv_add_hit', 'add_hit' );
function add_hit(){

 $page_id = $_GET["campaignid"] ? $_GET["campaignid"] : '';
 $source_id = $_GET["sourceid"] ? $_GET["sourceid"] : '';
 $gcl_id = $_GET["gclid"] ? $_GET["gclid"] : ''; //don't know what this is used for
 $ip_address = $_SERVER["REMOTE_ADDR"] ? $_SERVER["REMOTE_ADDR"] : '';
 $host_name = $_SERVER["REMOTE_ADDR"] ? $_SERVER["REMOTE_ADDR"] : '';
 $referrer = $_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"] : '';
 $destination_url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 $destination_url = $destination_url ? $destination_url : '';
 $result = $client->__soapCall("AddWebsiteHit", array(
                "AddWebsiteHit" => array(
                    "SecurityGUID"  => $security_guid,
                    "PageId"           => $page_id,
                    "LeadSourceId"           => $source_id,
                    "IpAddress"           => $ip_address,
                    "HostName"           => $host_name,
                    "Referrer"           => $referrer,
                    "DestinationURL"           => $destination_url
                )
            ), NULL, NULL);
 $file = 'output.txt';
 date_default_timezone_set('Australia/Sydney');
 file_put_contents($file, "------------------------------------------\n",FILE_APPEND);
 file_put_contents($file, "Date Time: ".date('d/m/Y h:i:s a', time())."\n",FILE_APPEND);
 file_put_contents($file, "Request: ".$client->__getLastRequest()."\n",FILE_APPEND);
 file_put_contents($file, "Response: ".print_r($result, true)."\n",FILE_APPEND);
 $_SESSION["hits"] = $result->AddWebsiteHitResult;
 $_SESSION["campaignid"] = $page_id;
 $_SESSION["sourceid"] = $source_id;
 $_SESSION["gclid"] = $gcl_id;
 file_put_contents($file, "Session Contents: ".print_r($_SESSION, true)."\n",FILE_APPEND);
 file_put_contents($file, "------------------------------------------\n",FILE_APPEND);
 echo "Date Time: ".date('d/m/Y h:i:s a', time())."\n"."Request: ".$client->__getLastRequest()."\n"."Response: ".print_r($result, true)."\n"."Session Contents: ".print_r($_SESSION, true)."\n";
}

add_action("gform_after_submission", "add_lead", 10, 2);
 function add_lead($entry, $form){
 $name = $entry["1"];
 $phone = $entry["2"];
 $postcode = $entry["3"];
 $email = $entry["4"];

 $result = $client->__soapCall("AddLead", array(
                "AddLead" => array(
                    "SecurityGUID"  => $security_guid,
                    "XML"           => $xml_lead
                )
            ), NULL, NULL);
 $file = 'output.txt';
 file_put_contents($file, $client->__getLastRequest(),FILE_APPEND);
 file_put_contents($file, print_r($result, true),FILE_APPEND);
 file_put_contents($file, print_r($_SESSION, true),FILE_APPEND);
 }

0 个答案:

没有答案