WordPress.org

Ready to get started?Download WordPress

Forums

CubePoints
Display new image in header with PAID CONTENT (6 posts)

  1. allinfinite
    Member
    Posted 1 year ago #

    Upon purchasing a new page,
    I would like to change an image link, within my header.php file, from a question mark to an icon and add another question mark icon link. How would I phrase this statement in my code?

    http://wordpress.org/extend/plugins/cubepoints/

  2. allinfinite
    Member
    Posted 1 year ago #

    Looking for this type of thing... only if user has purchased post #7 else..

    <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    }
    ?>
  3. Gabriel
    Member
    Posted 1 year ago #

    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',
    		get_current_user_id(),
    		$post_id,
    		'pcontent'
    	) ) != 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
    	}
    }
  4. allinfinite
    Member
    Posted 1 year ago #

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

  5. allinfinite
    Member
    Posted 1 year ago #

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

  6. Gabriel
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic