从WooCommerce成员身份中的PHP类中删除_操作

从WooCommerce成员身份中的PHP类中删除_操作,php,wordpress,woocommerce,hook-woocommerce,woocommerce-memberships,Php,Wordpress,Woocommerce,Hook Woocommerce,Woocommerce Memberships,我以前使用过这里描述的解决方案:用于删除WooCommerce成员插件中的操作 但是,解决方案不再有效,因为WooComemerce已经更改了成员资格插件背后的代码 这就是新代码 Main woocommerce memberships.php public function includes() { // load post types require_once( $this->get_plugin_path() . '/includes/class-wc-member

我以前使用过这里描述的解决方案:用于删除WooCommerce成员插件中的操作

但是,解决方案不再有效,因为WooComemerce已经更改了成员资格插件背后的代码

这就是新代码

Main woocommerce memberships.php

public function includes() {

    // load post types
    require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-post-types.php' );

    // load user messages helper
    require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-user-messages.php' );

    // load helper functions
    require_once( $this->get_plugin_path() . '/includes/functions/wc-memberships-functions.php' );

    // init general classes
    $this->rules            = $this->load_class( '/includes/class-wc-memberships-rules.php',            'WC_Memberships_Rules' );
    $this->plans            = $this->load_class( '/includes/class-wc-memberships-membership-plans.php', 'WC_Memberships_Membership_Plans' );
    $this->emails           = $this->load_class( '/includes/class-wc-memberships-emails.php',           'WC_Memberships_Emails' );
    $this->user_memberships = $this->load_class( '/includes/class-wc-memberships-user-memberships.php', 'WC_Memberships_User_Memberships' );
    $this->capabilities     = $this->load_class( '/includes/class-wc-memberships-capabilities.php',     'WC_Memberships_Capabilities' );
    $this->member_discounts = $this->load_class( '/includes/class-wc-memberships-member-discounts.php', 'WC_Memberships_Member_Discounts' );
    $this->restrictions     = $this->load_class( '/includes/class-wc-memberships-restrictions.php',     'WC_Memberships_Restrictions' );
    public function __construct() {

    // decide whether attempting to access restricted content has to be redirected
    add_action( 'wp', array( $this, 'handle_restriction_modes' ) );

    // restrict the post by filtering the post object and replacing the content with a message and maybe excerpt
    add_action( 'the_post', array( $this, 'restrict_post' ), 0 );
主实例

    function wc_memberships() {
    return WC_Memberships::instance();
}
    /**
 * Returns the general content restrictions handler.
 *
 * @since 1.9.0
 *
 * @return null|\WC_Memberships_Posts_Restrictions
 */
public function get_posts_restrictions_instance() {

    if ( ! $this->posts_restrictions instanceof WC_Memberships_Posts_Restrictions ) {
        $this->posts_restrictions = wc_memberships()->load_class( '/includes/frontend/class-wc-memberships-posts-restrictions.php', 'WC_Memberships_Posts_Restrictions' );
    }

    return $this->posts_restrictions;
}
来自包含的class-wc-memberships-restrictions.php文件

    function wc_memberships() {
    return WC_Memberships::instance();
}
    /**
 * Returns the general content restrictions handler.
 *
 * @since 1.9.0
 *
 * @return null|\WC_Memberships_Posts_Restrictions
 */
public function get_posts_restrictions_instance() {

    if ( ! $this->posts_restrictions instanceof WC_Memberships_Posts_Restrictions ) {
        $this->posts_restrictions = wc_memberships()->load_class( '/includes/frontend/class-wc-memberships-posts-restrictions.php', 'WC_Memberships_Posts_Restrictions' );
    }

    return $this->posts_restrictions;
}
然后类内wc成员资格发布限制。php

public function includes() {

    // load post types
    require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-post-types.php' );

    // load user messages helper
    require_once( $this->get_plugin_path() . '/includes/class-wc-memberships-user-messages.php' );

    // load helper functions
    require_once( $this->get_plugin_path() . '/includes/functions/wc-memberships-functions.php' );

    // init general classes
    $this->rules            = $this->load_class( '/includes/class-wc-memberships-rules.php',            'WC_Memberships_Rules' );
    $this->plans            = $this->load_class( '/includes/class-wc-memberships-membership-plans.php', 'WC_Memberships_Membership_Plans' );
    $this->emails           = $this->load_class( '/includes/class-wc-memberships-emails.php',           'WC_Memberships_Emails' );
    $this->user_memberships = $this->load_class( '/includes/class-wc-memberships-user-memberships.php', 'WC_Memberships_User_Memberships' );
    $this->capabilities     = $this->load_class( '/includes/class-wc-memberships-capabilities.php',     'WC_Memberships_Capabilities' );
    $this->member_discounts = $this->load_class( '/includes/class-wc-memberships-member-discounts.php', 'WC_Memberships_Member_Discounts' );
    $this->restrictions     = $this->load_class( '/includes/class-wc-memberships-restrictions.php',     'WC_Memberships_Restrictions' );
    public function __construct() {

    // decide whether attempting to access restricted content has to be redirected
    add_action( 'wp', array( $this, 'handle_restriction_modes' ) );

    // restrict the post by filtering the post object and replacing the content with a message and maybe excerpt
    add_action( 'the_post', array( $this, 'restrict_post' ), 0 );
如何删除“the_post”操作

到目前为止,我在functions.php主题文件中有以下内容:

  function weteach_remove_actions(){
      if(is_singular( 'post' )) {
         if( function_exists( 'wc_memberships' ) ){
             remove_action( 'the_post', array( wc_memberships()->restrictions, 'restrict_post' ));
         }
      }
      return;
  }
  add_action( 'the_post', 'weteach_remove_actions', 1 );

这给了我一个“空白页”-错误。

你能告诉我们错误信息是什么吗?我的猜测是
restricts
post\u restricts
不是相同的属性,因此在正确的类中找不到
restrict\u post
方法

编辑现在我已经了解了会员资格,这似乎对我很有用:

function so_41431558_remove_membership_post_restrictions(){ 
    if( function_exists( 'wc_memberships' ) && version_compare( WC_Memberships::VERSION, '1.9.0', '>=' ) && is_singular( 'post' ) ){
        remove_action( 'the_post', array( wc_memberships()->get_restrictions_instance()->get_posts_restrictions_instance(), 'restrict_post' ), 0 );
    }
}
add_action( 'wp_head', 'so_41431558_remove_membership_post_restrictions', 1 );
您的
add_操作
尝试发生在优先级1上,这是在函数已经在优先级0上运行Memberships方法之后,因此即使您的其余代码是正确的,也为时已晚

所以1。我想我们需要早点去钓鱼

二,。我认为我们需要使用新方法来访问post restrictions类实例

编辑以添加

三,。我已切换到直接版本比较条件


四,。我误读了
get\u posts\u restrictions\u instance()
方法的位置。。。可以通过
wc\u memberships()->get\u restrictions\u instance()->get\u posts\u restrictions\u instance()

空白页表示站点出现错误,请在WP config中打开WP\u DEBUG以查看您首先遇到的错误并修复该错误。您好,谢谢您的回复。我刚刚打开了WP_调试,但仍然得到一个空白屏幕。我也尝试过“添加动作('wp','weteach_remove_actions',1);”而不是“添加动作('the_post','weteach_remove_actions',1);”还尝试打开
wp_DEBUG_LOG
将错误记录到
wp content/DEBUG.LOG
。虽然我认为我发现这段代码缺少主
woocommerce memberships.php
文件中的
get\u restrictions\u instance()
,所以我没有正确访问
post\u restrictions
。请检查我的编辑。嗨,海尔加特维京,非常感谢!它可以工作:-)但是我确实需要将优先级1添加到add_操作中,如下所示:add_操作('wp_head','so_41431558_remove_membership_post_restrictions',1);让它工作。