Posts

How to customize Chiramise

Here is a common list for customizing.

NOTICE: We are working for this! Please wait for documentation complete.

Case1: Change capability

Default capability is read. Let’s suppose that you have forum on your site like BuddyPress and you recognize vigorous users are VIP.

In this case, the question is “who is vigorous?”. Here, define it as “the user who post 10 comments in last 1 week is vigorous”.

The strategy is that, the custom capability is vigorous_contributor and override default capability for Chiramise.

<?php
add_filter('chiramise_capability', function($capability){
    return 'vigorous_contributor';
});

 

Now, Chiramise understand your strategy. But now, no user has capability vigorous_contributor. Let’s assign it with map_meta_cap filter. Suppose that the function is_vigorous_user is already defined.

<?php

add_filter('map_meta_cap', functoin($caps, $cap, $user_id){
    switch( $cap ){
        case 'vigorous_contributor':
            if ( is_vigorous_user( $user_id ) ) {
                 $caps[] = 'read';
            } else {
                 $caps[] = 'do_not_allow';
            }
            break;
    }
    return $caps;
}, 10, 3);

 

Now your VIPs get treated enough for their contribution! This seem to be a detour little bit. But relying on WordPress’ capability system, other plugins could refer to it!

Case2: Show instruction

By default, Chiramise shows nothing despite the content is limited or not. It’s not because that we are lazy but we think the instruction depends on your strategy.

We show you how to display something and what to display is up to you.

There are 2 helpful functions for detecting content and user.

chiramise_should_check( $post ) returns if specified post should be check capability because they have splitters like <!--more--> or <!--nextpage-->.

Next, chiramise_can_read($post, $user) returns if specified user has enough capability to read it.

Both functions are ready for loop. So if you just want to check current user’s capability for current post, you don’t have to pass arguments.

<?php if ( chiramise_should_check() && ! chiramise_can_read() ) : ?>

    <!-- This post is limited but user has no capability. -->
    <p>
        You have to <a href="<?php echo wp_login_url(get_permalink()) ?>">login</a> to read the rest of content.
    </p>

<?php endif; ?>

 

On this site, we display login instruction for non capable user.

If content is limited, we display instruction for login.

If content is limited, we display instruction for login.

If you require your user to buy a ticket on WooCommerce, you should show link for that.