Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要一些PHP帮助来更改wordpress插件组吗_Php_Wordpress - Fatal编程技术网

需要一些PHP帮助来更改wordpress插件组吗

需要一些PHP帮助来更改wordpress插件组吗,php,wordpress,Php,Wordpress,我在这里真的陷入困境。我非常接近启动我的wordpress网站。我有一个相当大的障碍在我的道路上,这应该是一个简单的解决办法。我是初级php,所以我在这方面真的很努力,任何帮助或指导都将非常感谢,因为我已经通过阅读和研究尝试解决这个问题两周了 这就是问题所在,我将尽量详细说明: 我有一个自定义的帖子类型叫做Portfolio 我有一个公文包页面,其中加载了 公文包发布到公文包页面上的网格中。你知道吗 基本的公文包设置,如果你点击它带你去的图片 公文包邮报 使用Groups插件,当我限制访问公文包

我在这里真的陷入困境。我非常接近启动我的wordpress网站。我有一个相当大的障碍在我的道路上,这应该是一个简单的解决办法。我是初级php,所以我在这方面真的很努力,任何帮助或指导都将非常感谢,因为我已经通过阅读和研究尝试解决这个问题两周了

这就是问题所在,我将尽量详细说明:

  • 我有一个自定义的帖子类型叫做Portfolio
  • 我有一个公文包页面,其中加载了 公文包发布到公文包页面上的网格中。你知道吗 基本的公文包设置,如果你点击它带你去的图片 公文包邮报
  • 使用Groups插件,当我限制访问公文包帖子时, 它将从公文包页面网格中删除特征图像。像 非组成员的post不存在
  • 我试图出售访问这些投资组合的职位,所以如果有人是 不是会员,他们不知道那里有什么东西可以买
  • 我不知道如何才能在公文包页面上显示那些特色图片。我需要人们知道他们在那里,但不能访问他们。正如我在支持问题中提到的,我不能为此使用短代码,因为视频是硬编码到我的主题中的。我需要将其添加到自定义插件的代码中,以更改组,使其不从我的公文包页面中删除该特征图像,而不管帖子上的限制

    add_filter( 'posts_where', array( __CLASS__, 'posts_where' ), 10, 2 );
    
    /**
         * Filters out posts that the user should not be able to access.
         * 
         * @param string $where current where conditions
         * @param WP_Query $query current query
         * @return string modified $where
         */
        public static function posts_where( $where, &$query ) {
    
            global $wpdb;
    
            $user_id = get_current_user_id();
    
            // this only applies to logged in users
            if ( $user_id ) {
                // if administrators can override access, don't filter
                if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
                    if ( user_can( $user_id, 'administrator' ) ) {
                        return $where;
                    }
                }
            }
    
            // 1. Get all the capabilities that the user has, including those that are inherited:
            $caps = array();
            if ( $user = new Groups_User( $user_id ) ) {
                $capabilities = $user->capabilities_deep;
                if ( is_array( $capabilities ) ) {
                    foreach ( $capabilities as $capability ) {
                        $caps[] = "'". $capability . "'";
                    }
                }
            }
    
            if ( count( $caps ) > 0 ) {
                $caps = implode( ',', $caps );
            } else {
                $caps = '\'\'';
            }
    
            // 2. Filter the posts that require a capability that the user doesn't
            // have, or in other words: exclude posts that the user must NOT access:
    
            // The following is not correct in that it requires the user to have ALL capabilities:
    //      $where .= sprintf(
    //          " AND {$wpdb->posts}.ID NOT IN (SELECT DISTINCT ID FROM $wpdb->posts LEFT JOIN $wpdb->postmeta on {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->postmeta}.meta_value NOT IN (%s) ) ",
    //          self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
    //          $caps
    //      );
    
            // This allows the user to access posts where the posts are not restricted or where
            // the user has ANY of the capabilities:
            $where .= sprintf(
                " AND {$wpdb->posts}.ID IN " .
                " ( " .
                "   SELECT ID FROM $wpdb->posts WHERE ID NOT IN ( SELECT post_id FROM $wpdb->postmeta WHERE {$wpdb->postmeta}.meta_key = '%s' ) " . // posts without access restriction
                "   UNION ALL " . // we don't care about duplicates here, just make it quick
                "   SELECT post_id AS ID FROM $wpdb->postmeta WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->postmeta}.meta_value IN (%s) " . // posts that require any capability the user has
                " ) ",
                self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
                self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
                $caps
            );
    
            return $where;
        }
    
    add_filter( 'the_posts', array( __CLASS__, "the_posts" ), 1, 2 );
    
    /**
         * Filter posts by access capability.
         * 
         * @param array $posts list of posts
         * @param WP_Query $query
         */
        public static function the_posts( $posts, &$query ) {
            $result = array();
            $user_id = get_current_user_id();
            foreach ( $posts as $post ) {
                if ( self::user_can_read_post( $post->ID, $user_id ) ) {
                    $result[] = $post;
                }
            }
            return $result;
        }
    
    我浏览了一下,找到了控制进入受限岗位的部分。该类是组Post访问。当这两个都从class-groups-access.php中删除时,我可以看到公文包页面上的特色图片,但它也删除了限制实际帖子的功能。我不知道我怎么能告诉插件只返回特色图片,但仍然隐藏对帖子的访问

    add_filter( 'posts_where', array( __CLASS__, 'posts_where' ), 10, 2 );
    
    /**
         * Filters out posts that the user should not be able to access.
         * 
         * @param string $where current where conditions
         * @param WP_Query $query current query
         * @return string modified $where
         */
        public static function posts_where( $where, &$query ) {
    
            global $wpdb;
    
            $user_id = get_current_user_id();
    
            // this only applies to logged in users
            if ( $user_id ) {
                // if administrators can override access, don't filter
                if ( get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT ) ) {
                    if ( user_can( $user_id, 'administrator' ) ) {
                        return $where;
                    }
                }
            }
    
            // 1. Get all the capabilities that the user has, including those that are inherited:
            $caps = array();
            if ( $user = new Groups_User( $user_id ) ) {
                $capabilities = $user->capabilities_deep;
                if ( is_array( $capabilities ) ) {
                    foreach ( $capabilities as $capability ) {
                        $caps[] = "'". $capability . "'";
                    }
                }
            }
    
            if ( count( $caps ) > 0 ) {
                $caps = implode( ',', $caps );
            } else {
                $caps = '\'\'';
            }
    
            // 2. Filter the posts that require a capability that the user doesn't
            // have, or in other words: exclude posts that the user must NOT access:
    
            // The following is not correct in that it requires the user to have ALL capabilities:
    //      $where .= sprintf(
    //          " AND {$wpdb->posts}.ID NOT IN (SELECT DISTINCT ID FROM $wpdb->posts LEFT JOIN $wpdb->postmeta on {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->postmeta}.meta_value NOT IN (%s) ) ",
    //          self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
    //          $caps
    //      );
    
            // This allows the user to access posts where the posts are not restricted or where
            // the user has ANY of the capabilities:
            $where .= sprintf(
                " AND {$wpdb->posts}.ID IN " .
                " ( " .
                "   SELECT ID FROM $wpdb->posts WHERE ID NOT IN ( SELECT post_id FROM $wpdb->postmeta WHERE {$wpdb->postmeta}.meta_key = '%s' ) " . // posts without access restriction
                "   UNION ALL " . // we don't care about duplicates here, just make it quick
                "   SELECT post_id AS ID FROM $wpdb->postmeta WHERE {$wpdb->postmeta}.meta_key = '%s' AND {$wpdb->postmeta}.meta_value IN (%s) " . // posts that require any capability the user has
                " ) ",
                self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
                self::POSTMETA_PREFIX . self::READ_POST_CAPABILITY,
                $caps
            );
    
            return $where;
        }
    
    add_filter( 'the_posts', array( __CLASS__, "the_posts" ), 1, 2 );
    
    /**
         * Filter posts by access capability.
         * 
         * @param array $posts list of posts
         * @param WP_Query $query
         */
        public static function the_posts( $posts, &$query ) {
            $result = array();
            $user_id = get_current_user_id();
            foreach ( $posts as $post ) {
                if ( self::user_can_read_post( $post->ID, $user_id ) ) {
                    $result[] = $post;
                }
            }
            return $result;
        }
    

    如果有人能通过为我的自定义帖子类型创建一个模板,让我更好地理解这里发生的事情,也许是他所指的一个例子,我会非常感激。非常感谢您抽出时间

    这是通过使用wordpress来处理隐藏特定类别与更改实际插件代码来解决的。

    为了提供帮助,我们需要知道:您尝试了什么,错误是什么。老实说,如果你向他们提供了你向我们提供的那么多信息,我并不奇怪他们会帮不上忙。。。插件论坛帖子的链接是什么?谢谢你的回复。我很确定他明白我说他是插件作者的意思。抱歉,有点模糊。我更新了这个问题以包含api中的代码。链接到。我用另一种方式问这个问题,因为有人问了一个类似的问题,他返回了与我相同的答案,没有关于如何进行更改的信息。这就是为什么我在这一页上这样问的原因。