获取Ajax来工作的字preSS所有用户用户、工作、Ajax、preSS

2023-09-11 00:37:29 作者:回忆里的失败者

这是使用Ajax在Word preSS一些插件只有当您登录以管理员或添加这些挂钩工作:

some Plugins that use Ajax in Wordpress only work when you are logged in as admin or added these hooks:

add_action('wp_ajax_my_action', 'my_action_callback'); 
add_action('wp_ajax_nopriv_my_action', 'my_action_callback');

不过我真的具有让一切工作的非管理员用户很难,我想知道如果有一个简单的方法(对于JS / PHP的菜鸟)告诉字preSS在全球范围内启动所有的Ajax功能承滴盘用户,羯羊或没有登录。

But I'm really having a hard time with getting everything to work for non-admin users and I'm wondering if there is a easy way (for js/php noobs) to tell wordpress to globally activate all ajax functions for alls users, wether logged in or not.

我知道这可能是一个非常愚蠢和危险的方式,如果这是可能以某种方式,但请让我知道!?!!?

I know this is probably a very stupid and risky way if that is possible somehow, but please let me know!?!!?

推荐答案

PHP明智的,你击中了要害你的code以上。这需要对每一个AJAX的动作,每个动作当然会调用不同的功能。

PHP wise, you've hit the nail on the head with your code above. This is required for each AJAX action, as each action will of course call a different function.

现在,我让你使用的是默认的Word preSS AJAX调用的假设 -

Now, I'm making the assumption that you are using the default Wordpress AJAX call -

jQuery.post(ajax_object.ajax_url, data, function(response) {

如果这是事实确实如此,对于前端调用它很可能是 ajax_object.ajax_url 未设置。要设置此,以下内容添加到您的的functions.php 文件 -

If that is indeed the case, for front end calls it is likely that ajax_object.ajax_url is not set. To set this, add the following to your functions.php file -

<?php
add_action('wp_head', 'plugin_set_ajax_url');
function plugin_set_ajax_url() {
?>
    <script type="text/javascript">
        var ajax_object = {};
        ajax_object.ajax_url = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
<?php
}
?>
 
精彩推荐
图片推荐