admin管理员组文章数量:1024186
In a plugin, I use ajax to get_option()
which takes much longer than it has to because entire wp gets loaded.
How do I set things up so that it (my ajax) loads only what is needed? (get_option()
)
In a plugin, I use ajax to get_option()
which takes much longer than it has to because entire wp gets loaded.
How do I set things up so that it (my ajax) loads only what is needed? (get_option()
)
2 Answers
Reset to default 5If you're building something for public consumption (a plugin, a theme, etc) use admin-ajax.php
like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose.
Beyond that, the best you MAY be able to do is use the SHORTINIT
constant. Define it in a custom php file, then require wp-load.php
and do what you need to do. SHORTINIT
stops most of the WordPress core from being loaded.
<?php
define('SHORTINIT', true);
require '/path/to/wp-load.php';
// you'll have the basic API here, including `get_option`. Do stuff.
If you do this outside the WP core, you'll have to guess where wp-load.php
may be -- you won't have any ABSPATH
contant to guide you. That's a risky bet unless you're in full control of the system. In other words, if this is a custom, not publicly-released thing, go for it. Otherwise, use admin-ajax.php
.
Another Method is to add this code into functions.php
(or in plugin), without need of require '/path/to/wp-load.php'
... but it will not be as faster as SHORTINIT
:
// EXAMPLE
function MyFuncion(){
if (isset($_POST['mynamee'])) { echo get_option('my_nm');}
}
//===================Then====================
//1) Execute directly
MyFunction();
//========OR=========
//2) Hook into the EARLIEST ACTION:
add_action('muplugins_loaded', 'MyFunction',1);
p.s NEVER FORGET TO GUARD and FILTER THE REQUESTS from HACKING!!!
In a plugin, I use ajax to get_option()
which takes much longer than it has to because entire wp gets loaded.
How do I set things up so that it (my ajax) loads only what is needed? (get_option()
)
In a plugin, I use ajax to get_option()
which takes much longer than it has to because entire wp gets loaded.
How do I set things up so that it (my ajax) loads only what is needed? (get_option()
)
2 Answers
Reset to default 5If you're building something for public consumption (a plugin, a theme, etc) use admin-ajax.php
like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose.
Beyond that, the best you MAY be able to do is use the SHORTINIT
constant. Define it in a custom php file, then require wp-load.php
and do what you need to do. SHORTINIT
stops most of the WordPress core from being loaded.
<?php
define('SHORTINIT', true);
require '/path/to/wp-load.php';
// you'll have the basic API here, including `get_option`. Do stuff.
If you do this outside the WP core, you'll have to guess where wp-load.php
may be -- you won't have any ABSPATH
contant to guide you. That's a risky bet unless you're in full control of the system. In other words, if this is a custom, not publicly-released thing, go for it. Otherwise, use admin-ajax.php
.
Another Method is to add this code into functions.php
(or in plugin), without need of require '/path/to/wp-load.php'
... but it will not be as faster as SHORTINIT
:
// EXAMPLE
function MyFuncion(){
if (isset($_POST['mynamee'])) { echo get_option('my_nm');}
}
//===================Then====================
//1) Execute directly
MyFunction();
//========OR=========
//2) Hook into the EARLIEST ACTION:
add_action('muplugins_loaded', 'MyFunction',1);
p.s NEVER FORGET TO GUARD and FILTER THE REQUESTS from HACKING!!!
本文标签: performanceMinimal WordPress load for only getoption to work (because ajax)
版权声明:本文标题:performance - Minimal WordPress load for only `get_option` to work (because ajax...) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745565197a2156406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论