Support » Plugin: CubePoints » Display new image in header with PAID CONTENT

Viewing 5 replies - 1 through 5 (of 5 total)
  • Looking for this type of thing… only if user has purchased post #7 else..

    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';


    Based on the cp_module_pcontent_post() function in the paid content module you could check the database to see if the current user has purchased this post and based on the results do your thing.

    Here is an example of a function you could use, this one requires a post id:

    function current_user_paid_for_post( $post_id = false )
    	if ( !$post_id || !is_user_logged_in() ) return false;
    	global $wpdb;
    	if ( (int) $wpdb->get_var( $wpdb->prepare(
    		"SELECT COUNT(*) FROM %s WHERE uid = %d AND data = %d AND type =%s",
    		$wpdb->base_prefix . 'cp',
    	) ) != 0 || current_user_can( 'read_private_posts' ) )
    		return true;
    	return false;

    and then in your header.php file you could use this i.e:

    if ( is_single() ) {
    	global $post;
    	if ( current_user_paid_for_post( $post->ID ) ) {
    		// Current user has paid for this
    	else {
    		// No payment found

    I’m pretty beginner.. I put the first snippet in my functions.php? Where do I include the post id number?

    can I include the post id in the header.php? different point levels display different content



    The function goes into your functions.php in your themes folder. The second snippet is just one very basic example of how you can use this function and goes anywhere really but in your case the header.php file. In the example I called the post id though the $post global. If you are inside the loop you can also use get_the_ID() instead of $post->ID.

    This function will however only check that the current user has either a) purchased the current post/page or b) can read “private posts” (editors and admins) and returns either true or false. As it is there is no “different point level checks”.

    If you just want to show different icons or images you would use this function in either your header/footer or in single.php.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display new image in header with PAID CONTENT’ is closed to new replies.