简体   繁体   English

WordPress给出错误消息“出了点问题。 使用REMOTE_ADDR变量时,可能尚未保存您的更改。(..)”

[英]Wordpress gives the error “Something went wrong. Your change may not have been saved.(..)” when using the REMOTE_ADDR variable

I'd like to set up the following - accessing a page from a specific IP will show a specific < div > that'd be hidden for anyone else accessing the page from a different IP. 我想进行以下设置-从特定IP访问页面将显示特定的<div>,对于从其他IP访问该页面的其他人来说,该<div>将被隐藏。

Wordpress 5.2.2; WordPress 5.2.2; I've tried a couple of ways to execute the following idea, but the general idea I had was to compare the REMOTE_ADDR with my handpicked address using an if statement, and then echo'ing the style to display the block I wanted (provided the address was the same). 我已经尝试了几种方法来执行以下想法,但是我的总体想法是使用if语句将REMOTE_ADDR与我选择的地址进行比较,然后回显该样式以显示所需的块(地址是相同的)。 I also tried escaping PHP and executing the necessary CSS like that, but I had the same problem. 我也尝试转义PHP并像这样执行必要的CSS,但是我遇到了同样的问题。 I'm not an experienced programmer by any means, so I can only assume I'm making a mistake somewhere. 无论如何我都不是经验丰富的程序员,所以我只能假设我在某个地方犯了错误。

if ($_SERVER['REMOTE_ADDR'] == 'xx.xxx.xx.xxx' ) { echo '<style>.elementor-element-6788e0e{display:block!important;}</style>'; }

It's not necessarily the code that's not working - it actually serves its purpose, and the block is shown only when accessed through that IP. 不一定是代码不起作用-它实际上达到了目的,并且仅在通过该IP访问时才显示该块。 However, as soon as I put anything in between the if statement brackets, Wordpress barely functions. 但是,只要我在if语句之间插入任何内容,Wordpress就几乎无法发挥作用。

"Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP." “出了点问题。您的更改可能尚未保存。请重试。还有机会可能需要手动修复并通过FTP上传文件。” - When saving PHP. -保存PHP时。

"Looks like something's gone wrong. Wait a couple seconds, and then try again." “看起来好像出了点问题。请等待几秒钟,然后重试。” - When saving CSS. -保存CSS时。

Adding menu items doesn't work, etc. 添加菜单项不起作用,等等。

I'm hoping someone can educate me on the cause of these errors, or show me a more correct way of tackling the CSS problem. 我希望有人可以教育我这些错误的原因,或者向我展示解决CSS问题的更正确方法。

Thanks in advance! 提前致谢!

Insert this function to functions.php to remove this div in every post, of couse, you can modify this function as you want: 将此函数插入​​functions.php以在每个帖子中删除此div,当然,您可以根据需要修改此函数:

add_filter( 'the_content', function( $content ) {
  return preg_replace('#<div class="elementor-element-6788e0e">(.*?)</div>#', '', $content);
}, 0);

Or using this in post.php file with only: 或仅在post.php文件中使用此命令:

return preg_replace('#<div class="elementor-element-6788e0e">(.*?)</div>#', '', $content);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM