WordPress独立的functions.php(WordPress independent functions.php)

编程入门 行业动态 更新时间:2024-10-28 19:24:03
WordPress独立的functions.php(WordPress independent functions.php)

我在内部服务器上安装了新鲜的WordPress和bbPress。

当我设置bbPress时,我想测试诸如创建论坛,主题等功能。在后端(仪表板)中执行这些操作时,似乎没有任何问题,但是当我从前端 - 我不断得到

ERROR: Are you sure you wanted to do that?

我搜索了一个解决方案,并找到了这个 。

add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 ); function my_bbp_verify_nonce_request_url( $requested_url ) { return 'http://localhost:8888' . $_SERVER['REQUEST_URI']; }

我只是将硬编码的URL更改为我们内部服务器的设置,并解决了问题。


现在我的问题:是否有可能将此解决方案添加到与正在使用的主题无关的functions.php中? 我问这个是因为我有两个问题:

当前主题可能会更新并覆盖该文件

我知道解决这个问题只是创建一个儿童主题,但我的第二个担心阻止了我这样做。

WordPress管理员可能会更改主题,因此主题和子主题上的functions.php文件都将停止工作

我怎样才能添加上面的解决方案,以便我不必担心主题将来会更新和/或替换为新主题? 每次管理员决定更改主题时,我都不想继续添加此解决方案。

I have a fresh WordPress and bbPress installed on an internal server.

While I was setting up bbPress I wanted to test the functionalities like creating a forum, topic, etc. When doing these stuff in the back-end (dashboard) there didn't seem to be any problems but when I did it from the front-end I kept getting

ERROR: Are you sure you wanted to do that?

I searched for a solution and found this.

add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 ); function my_bbp_verify_nonce_request_url( $requested_url ) { return 'http://localhost:8888' . $_SERVER['REQUEST_URI']; }

I simply changed the hard-coded URL to what our internal server is set up to and it fixed the problem.


Now my question: is it possible for me to add this solution to a functions.php that is independent of the theme being used? I asked this because I have 2 concerns:

The current theme might get updated and will overwrite the file

I'm aware that the solution to this is simply create a child theme but my second concern prevents me from doing this.

The WordPress administrator might change themes and so both the functions.php file on the main theme and the child theme will stop working

How could I add the solution above so that I don't have to worry about the theme being updated and/or replaced with a new theme in the future? I don't want to keep adding this solution every time the administrator decides to change themes.

最满意答案

如果你不能把它放在一个主题中,把它放在一个插件。 如果您担心该插件将被停用,请将其设为必要使用插件 。

创建插件非常简单。 创建一个文件plugin-name.php并将其放在一个目录wp-content/plugins/plugin-name/ 。 该文件应该包含以下代码:

<?php /* Plugin Name: Name Of The Plugin Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: The Plugin's Version Number, e.g.: 1.0 Author: Name Of The Plugin Author Author URI: http://URI_Of_The_Plugin_Author License: A "Slug" license name e.g. GPL2 */ add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 ); function my_bbp_verify_nonce_request_url( $requested_url ) { return 'http://localhost:8888' . $_SERVER['REQUEST_URI']; }

如果你希望它是一个必须使用的插件,把它放在wp-content/mu-plugins/而不是wp-content/plugins 。

If you can't put it in a theme, put it in a Plugin. If you're worried that the plugin will get de-activated make it a Must Use Plugin.

It's dead simple to create a plugin. Create a file plugin-name.php and place it in a directory wp-content/plugins/plugin-name/. That file should contain the following code:

<?php /* Plugin Name: Name Of The Plugin Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: The Plugin's Version Number, e.g.: 1.0 Author: Name Of The Plugin Author Author URI: http://URI_Of_The_Plugin_Author License: A "Slug" license name e.g. GPL2 */ add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 ); function my_bbp_verify_nonce_request_url( $requested_url ) { return 'http://localhost:8888' . $_SERVER['REQUEST_URI']; }

If you want it to be a must use plugin, put it in wp-content/mu-plugins/ instead of wp-content/plugins.

更多推荐

本文发布于:2023-08-01 23:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1365699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:独立   WordPress   functions   independent   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!