我正在开发一个简单的插件,它可以判断用户是否点击按钮并在WordPress中设置Cookie.一切正常,但当我try 更新帖子或页面时,我得到"更新失败.响应不是有效的JSON响应".我想不出我怎么才能解决这个问题.此外,我还询问我是否进行了正确的过程来挂接翻译并在Worpress init上显示对话框.
if(!defined('ABSPATH')) {
exit;
}
// ACTION
add_action('wp_enqueue_scripts', 'cp_scripts');
function cp_scripts() {
wp_enqueue_style('cookie-style', plugins_url('style.css', __FILE__));
wp_enqueue_script('cookie-script', plugins_url('script.js', __FILE__));
}
add_action('init', 'my_plugin_show_confirm');
// add_action('init', 'register_pll_translation');
function register_pll_translation() {
if(function_exists('pll_register_string')) {
pll_register_string( 'cp_form_subtitle', "string", 'cp-form', false );
pll_register_string( 'cp_form_age_ok', "string", 'cp-form', false );
}
}
function my_plugin_show_confirm() {
if (!isset($_COOKIE['cp_enter']) && !is_admin() ) {
$current_url = get_the_permalink();
if(isset($_POST['submit'])) {
setcookie('cp_enter', 1 , time() + (60 * 60 * 24 * 30), COOKIEPATH, COOKIE_DOMAIN);
return;
} ?>
<div id="my-plugin-confirm">
<form action="<?php echo $current_url ?>" method="post">
<h2><?php echo esc_html(get_bloginfo('name'));?></h2>
<p><Click to enter</p>
<button type="submit" name="submit">Enter</button>
</form>
</div>
<?php } ?>