admin管理员组文章数量:1327988
I'm experimenting with creating a function to write code into htaccess (I understand the security issues associated). I'm currently using the function insert_with_markers() as a starting point however its throwing a 'call to undefined function' error.
I am using it within a function that is only running whilst logged into the Admin Dashboard.
I understand that the function if found in the file: wp-admin/includes/misc.php but I made the assumption that this file is loaded whilst within the Admin Dashboard anyway, so I don't need to include it?
If I manually include the file, the function runs correctly.
My question is: does the wp-admin/includes/misc.php file not get loaded by default when logged in to the Dashboard? Or is it only loaded in certain cirumstances?
I'm experimenting with creating a function to write code into htaccess (I understand the security issues associated). I'm currently using the function insert_with_markers() as a starting point however its throwing a 'call to undefined function' error.
I am using it within a function that is only running whilst logged into the Admin Dashboard.
I understand that the function if found in the file: wp-admin/includes/misc.php but I made the assumption that this file is loaded whilst within the Admin Dashboard anyway, so I don't need to include it?
If I manually include the file, the function runs correctly.
My question is: does the wp-admin/includes/misc.php file not get loaded by default when logged in to the Dashboard? Or is it only loaded in certain cirumstances?
Share Improve this question asked Jul 24, 2020 at 14:26 t2pet2pe 4823 silver badges11 bronze badges2 Answers
Reset to default 4Looks like insert_with_markers()
function becomes available during admin_init
hook. So in order for your code to work, you should do the following:
function do_my_htaccess_stuff_371705() {
//function `insert_with_markers()` is working now
}
add_action('admin_init', 'do_my_htaccess_stuff_371705');
By looking at the source of the latest version, it shows that misc.php
only gets included in one place at wp-admin/includes/admin.php
. The include there is unconditional. That file in turn gets included seemingly unconditionally in wp-admin/admin.php
, and this is required unconditionally as the first line in wp-admin/index.php
.
So it appears that it should be the case that's always available in the admin dashboard. If it's not, I'd suggest looking in more detail at what happens in wp-admin/admin.php
in case something is going on there which bails out early.
EDIT: Note that PHP gives you the require_once()
command which means that it's safe to include the file using require_once more than once, so you don't lose or risk anything going wrong by putting a require_once to that file in your code.
本文标签: wp adminCall to undefined function insertwithmarkers
版权声明:本文标题:wp admin - Call to undefined function insert_with_markers 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742235333a2437975.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论