禁用woocommerce api身份验证? [英] Disable woocommerce api authentication?

查看:41
本文介绍了禁用woocommerce api身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

woocommerce api 对 HTTP 请求采用 oauth1.0,对 HTTPS 请求采用基本 HTTP 身份验证.我的查询很简单.如何简单地删除此身份验证?我做了一些挖掘,发现 woocommerce 插件中有一个类,其构造函数为

The woocommerce api takes oauth1.0 for HTTP requests and basic HTTP authentication for HTTPS requests. My query is simple. How to simply remove this authentication? I did some digging and found there is a class in woocommerce plugin with a constructor as

public function __construct() {

        // To disable authentication, hook into this filter at a later priority and return a valid WP_User
        add_filter( 'woocommerce_api_check_authentication', array( $this, 'authenticate' ), 0 );
    }

我的工作是简单地删除身份验证部分.这里是说在以后的优先级上钩住这个过滤器.如何执行此操作以及如何返回有效的 WP_User?

My job is to simply remove the authentication part. Here it is saying to hook this filter at a later priority. How to do so and how to return a valid WP_User?

推荐答案

创建自己的插件并放置以下代码:

Create your own plugin and place the following code:

function wc_authenticate_alter(){
    //return wp_get_current_user();
    if( 'GET' ==  WC()->api->server->method ){
        return new WP_User( 1 );
    } else {
        throw new Exception( __( 'You dont have permission', 'woocommerce' ), 401 );
    }
}

add_filter( 'woocommerce_api_check_authentication', 'wc_authenticate_alter', 1 );

这将绕过 woocommerce api 身份验证.请自行承担风险.

This will bypass woocommerce api authentication. Use it with your own risk.

(您可以在主题的functions.php 中添加它而不是自己的插件.但未测试.)

(You can add it in theme's functions.php instead of own plugin. But not Tested.)

这篇关于禁用woocommerce api身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆