我做了一个插件来创建一个当cookie为FALSE时的。实际上,正在工作,但当我准备创建cookie时,它说我的头已经发送了。
然后,我有了密码add_action(\'init\', \'newsletterSuscriber\');
但它仍然返回了这样一个错误。
警告:call\\u user\\u func\\u array()要求参数1为有效回调,在/PATH/wp includes/plugin中找不到函数“newslettessuscriber”,或函数名无效。php在线503
Plugin code
class Okidoo_Newsletter_Suscriber {
/**
* Initializes the plugin.
*
* To keep the initialization fast, only add filter and action in the constructor.
*/
public function __construct() {
add_shortcode( \'custom-suscribe-form\' , array( $this, \'render_suscribe_form\') );
add_action( \'init\', \'newsletterSuscriber\' );
}
/**
* A shortcode for rendering the login form.
*
* @param array $attributes Shortcode attributes.
* @param array $content The text content for shortcode. Not used.
*
* @return string The shortcode output
*/
public function render_suscribe_form( $attributes, $content = null ) {
// Parse shortcode attributes
$default_attributes = array( \'show_title\' => false );
$attributes = shortcode_atts( $default_attributes, $attributes );
$show_title = $attributes[\'show_title\'];
// Pass the redirect parameter to the WordPress login functionnality : by default,
// don\'t specify a redirect, but if a valid redirect URL has been passed as
// request parameter, use it.
$attributes[\'redirect\'] = \'\';
// Render the login form using an external template.
return $this->get_template_html( \'subscription_form\', $attributes );
}
/**
* Render the contents of the given template to a string and returns it.
* @param string $template_name The name of the template to render (without .php)
* @param array $attributes The PHP variables for the template
*
* @return string The contents of the template.
*/
private function get_template_html( $template_name, $attributes = null ) {
if ( ! $attributes ) {
$attributes = array();
}
ob_start();
do_action( \'personalize_div_before_\' . $template_name );
require( \'templates/\' . $template_name . \'.php\' );
do_action( \'personalize_div_before_\' . $template_name );
$html = ob_get_contents();
ob_end_clean();
return $html;
}
public function newsletterSuscriber() {
if ( ! isset($_COOKIE[\'newsletter_suscriber\'])) {
$path = parse_url(get_option(\'siteurl\'), PHP_URL_PATH);
$host = parse_url(get_option(\'siteurl\'), PHP_URL_HOST);
$expiration = time() + 3600;
setcookie(\'newsletter_suscriber\', \'newsletter_suscriber\', $expiration, $path, $host);
}
}
}
// Initialize the plugin
$initialisation = new Okidoo_Newsletter_Suscriber();
之后,我尝试将add\\u操作放在mey函数上。php文件在模板中,也可以直接在插件文件中。
任何人都可以告诉我是否有可能:
使用init操作执行插件如果第1点为真,我做错了什么锂离子电池