• 26-12-2021, 03:14:56
    #1
    silin...
  • 26-12-2021, 04:36:10
    #2
    Google Harita Pro
    Bu linki inceleyin hocam.
  • 26-12-2021, 13:49:35
    #4
    EDIT: test edildi, çalışıyor.
    EDIT 2: Tüm yazılarda değil belirlediğiniz yazılarda kullanmak istiyorsanız şu kısımda post id'lerini belirtebilirsiniz. fakat aslında shortcode kullanacağınız için gerek de yok.

    $post_id = 0;

    şu şekilde kullabilirsiniz(functions.php'ye ekleyin):

    // the user may have commented on *any* post
    define( 'CHECK_GLOBAL_FOR_COMMENTS', FALSE);
    
    //
    // some more code
    //
    add_shortcode( 'membervip', 'memberviparea' );
    function memberviparea( $atts, $content = null ) {
    
        $post_id = 0;
    
        // if the user have to left a comment explicit on this post, get the post ID
        if( defined( 'CHECK_GLOBAL_FOR_COMMENTS' ) && FALSE === CHECK_GLOBAL_FOR_COMMENTS ) {
            global $post;
    
            $post_id = ( is_object( $post ) && isset( $post->ID ) ) ?
                $post->ID : 0;
        }
    
        if( is_user_logged_in() && user_has_left_comment( $post_id ) )
            return '<p>' . $content . '</p>';
        else
            return '<p>Bu alanı görmek için yorum yapmalısınız.</p>';
    
    }
    
    /**
     * Check if the user has left a comment
     *
     * If a post ID is set, the function checks if
     * the user has just left a comment in this post.
     * Otherwise it check if the user has left a comment on
     * any post.
     * If no user ID is set, the ID of the current logged in user is used.
     * If no user is currently logged in, the fuction returns null.
     *
     * @param int $post_id ID of the post (optional)
     * @param int $user_id User ID (required)
     * @return null|bool Null if no user is logged in and no user ID is set, else true if the user has left a comment, false if not
     */
    function user_has_left_comment( $post_id = 0, $user_id = 0 ) {
    
        if( ! is_user_logged_in() && 0 === $user_id )
            return NULL;
        elseif( 0 === $user_id )
            $user_id = wp_get_current_user()->ID;
    
        $args = array( 'user_id' => $user_id );
    
        if ( 0 !== $post_id )
            $args['post_id'] = $post_id;
    
        $comments = get_comments( $args );
    
        return ! empty( $comments );
    
    }
    Gizlemek istediğiniz alanı yazı içinde şu şekilde kullanın:

    [membervip]gizlenecek kısım[/membervip]
  • 26-12-2021, 18:30:26
    #5
    PowerKing adlı üyeden alıntı: mesajı görüntüle
    @d3nnis; bu sadece üyeler için geçerli. WP sitemde üyelik kapalı. Normal ziyaretçiler olamaz mı?
    Upps, o ihtimali düşünmemiştim. giriş yapmış sorgusunu yine de silmiyorum, olurda ileride tekrar üyelikleri açmak isterseniz diye. aşağıdaki şekilde şekilde güncelledim:
    ayrıca daha önceki kodda admin için de yorumu zorunlu tutuyordu, onu da düzelttim.

    // the user may have commented on *any* post
    define( 'CHECK_GLOBAL_FOR_COMMENTS', FALSE );
    
    //
    // some more code
    //
    add_shortcode( 'membervip', 'memberviparea' );
    function memberviparea( $atts, $content = null ) {
    
        $post_id = 0;
    
        // if the user have to left a comment explicit on this post, get the post ID
        if( defined( 'CHECK_GLOBAL_FOR_COMMENTS' ) && FALSE === CHECK_GLOBAL_FOR_COMMENTS ) {
            global $post;
    
            $post_id = ( is_object( $post ) && isset( $post->ID ) ) ?
                $post->ID : 0;
        }
    
        if( is_user_logged_in() && user_has_left_comment( $post_id ) || current_user_can( 'administrator' ) )
            return '<p>' . $content . '</p>';
        elseif( !is_user_logged_in() && user_has_left_comment( $post_id ) || current_user_can( 'administrator' ) )
            return '<p>' . $content . '</p>';
        else
            return '<p>Bu alanı görmek için yorum yapmalısınız.</p>';
    
    }
    
    /**
     * Check if the user has left a comment
     *
     * If a post ID is set, the function checks if
     * the user has just left a comment in this post.
     * Otherwise it check if the user has left a comment on
     * any post.
     * If no user ID is set, the ID of the current logged in user is used.
     * If no user is currently logged in, the fuction returns null.
     *
     * @param int $post_id ID of the post (optional)
     * @param int $user_id User ID (required)
     * @return null|bool Null if no user is logged in and no user ID is set, else true if the user has left a comment, false if not
     */
    function user_has_left_comment( $post_id = 0, $user_id = 0 ) {
    
        if( is_user_logged_in() && 0 === $user_id )
            return NULL;
        elseif( 0 === $user_id )
            $user_id = wp_get_current_user()->ID;
    
        $args = array( 'user_id' => $user_id );
    
        if ( 0 !== $post_id )
            $args['post_id'] = $post_id;
    
        $comments = get_comments( $args );
    
        return ! empty( $comments );
    }
  • 26-12-2021, 18:47:57
    #6
    silin...