我需要將變量(calltoaction)傳遞給函數2.我嘗試過全局,它不會。怎麼做?如何在php插件中的兩個函數之間共享變量?
功能1:
function wp_email_capture_form($calltoactiondesc,$error = 0) {
global $calltoaction;
/*Echo to a Variable*/
ob_start();
echo $calltoactiondesc;
$calltoaction= ob_get_contents();
ob_end_clean();
$url = get_option('home');
$url = addLastCharacter($url);
?>
<div id="wp_email_capture" class="wp-email-capture wp-email-capture-widget wp-email-capture-widget-worldwide">
<form name="wp_email_capture" method="post" action="<?php echo $url; ?>">
<?php if (isset($_GET['wp_email_capture_error'])) {
$error = wp_email_capture_sanitize($_GET['wp_email_capture_error']);
echo "<div class='wp-email-capture-error'>".__('Error:','WPEC'). $error ."</div>";
} ?>
<div class="col-lg-9 col-sm-9 col-xs-9 col-md-9 form-group textbox-group">
<input name="wp-email-capture-email" id="wp-email-capture-email-widget" type="text" class="wp-email-capture-email wp-email-capture-input wp-email-capture-widget-worldwide wp-email-capture-email-widget wp-email-capture-email-input wp-email-capture-email-input-widget form-control input-lg input" title="Email" placeholder="YOUR EMAIL ADDRESS" />
</div>
<div class="col-lg-3 col-sm-3 col-xs-3 col-md-3 form-group textbox-group">
<input type="hidden" name="wp_capture_action" value="1" />
<input name="Submit" type="submit" value="<?php _e('SUBMIT','WPEC'); ?>" class="wp-email-capture-submit wp-email-capture-widget-worldwide subscribe-button" />
</div>
</form>
</div>
<?php
}
注:我只通過功能1.通過變量,當我在下面提交調用和執行所示的「處理」的功能。但是全球變量沒有通過。
function wp_email_capture_process() {
if(isset($_REQUEST['wp_capture_action'])) {
wp_email_capture_signup();
}
......
}
功能2:
function wp_email_capture_signup() {
global $wpdb;
global $calltoaction;
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
$starturl = $_SERVER['HTTP_REFERER'];
if (strpos($starturl, "?") === false) {
$extrastring = "?";
} else {
$extrastring = "&";
}
$email = $_REQUEST['wp-email-capture-email'];
if (!is_email($email)) {
$error = urlencode(__('Not a valid email','WPEC'));
$url = $starturl . $extrastring . "wp_email_capture_error=" . $error;
wp_redirect($url);
die();
}
....
....
}
謝謝。但是,它可以」工作。 – Thangadurai 2014-10-06 11:32:55