WordPress.org

Forums

CubePoints
WP Photo Album Plus (12 posts)

  1. justinh2k
    Member
    Posted 2 years ago #

    is it possible to modify cubepoints for WP Photo Album Plus plugin so when somebody uploads an image and it gets approved they receive a point?

    http://wordpress.org/support/plugin/wp-photo-album-plus

  2. Gabriel
    Member
    Posted 2 years ago #

    No need to modify, you just need to create a custom module that hooks into the plugin and give points.

  3. justinh2k
    Member
    Posted 2 years ago #

    Could you help me with such thing?

  4. Gabriel
    Member
    Posted 2 years ago #

    I have never used that particular plugin so I will have to have a look and see.

  5. justinh2k
    Member
    Posted 2 years ago #

    I read another post with a user using event manager but wasn't sure what I all needed to edit for mine..it already has cube point built in uses it for other stuff..help would be very much appreciated

  6. Gabriel
    Member
    Posted 2 years ago #

    Hey.

    Sorry for the delay but I had to go though this plugin and realized there were no actions of filters one could simply hook into. So the only way for you to add points for approved uploads would require us to modify your plugin files.

    1. First we need to add an action to your wppa-ajax.php file which is located in your wp-photo-album-plus folder. On line 577 in this file you will find the following code:
    echo '||0||'.sprintf(__('<b>%s</b> of photo %s updated', 'wppa'), $itemname, $photo);
    On the next line after this insert the following code:
    do_action( 'wppa_updated_photo', $item, $value, $itemname, $photo );
    This is a custom action our module will be hooking into for awarding points.

    2. Copy the entire code bellow and put it in a file and name it photo_album_points.php (or anything else you want).

    3. Upload this file to your cubepoints/modules/ folder.
    4. Login to your website and activate the module under "CubePoints > Modules". (the module is called "WP Photo Album Points").
    5. Go to your Config page and enter the number of points you want to give uploaded photos and if you want the number of points you want to give to photos that are "featured". If you do not want to give points for anyone of these, just enter zero.

    Done.

    Custom Module Code:

    <?php
    /**
     * Register Custom CubePoints Module
     */
    cp_module_register(
    	__( 'WP Photo Album Points' ),
    	'wp_photo_album_plus_points',
    	'1.0',
    	'dbm',
    	'http://www.merovingi.com',
    	'http://www.merovingi.com',
    	__( 'Gives points for uploaded and approved pictures.' ),
    	1
    );
    /**
     * Setup Module settings on activation
     *
     * @action 'cp_module_highlight_term_points_activate'
     */
    add_action( 'cp_module_wp_photo_album_plus_points_activate', 'wp_photo_album_plus_points_setup' );
    function wp_photo_album_plus_points_setup()
    {
    	update_option( 'wppa_points_for_approval', 0 );
    	update_option( 'wppa_points_for_featured', 0 );
    }
    /**
     * If module is activated
     */
    if ( cp_module_activated( 'wp_photo_album_plus_points' ) ) {
    	/**
    	 * Add Module Settings to Config Page
    	 *
    	 * @action 'cp_config_form'
    	 */
    	add_action( 'cp_config_form', 'cp_module_wp_photo_album_plus_points_config' );
    	function cp_module_wp_photo_album_plus_points_config()
    	{
    		$pp = get_option( 'wppa_points_for_approval' );
    		$fp = get_option( 'wppa_points_for_featured' ); ?>
    
    		<h3>Points for Photo Uploads</h3>
    		<table class="form-table">
    			<tr valign="top">
    				<th scope="row">
    					<label for="points-for-pub-photos">Published Photos:</label>
    				</th>
    				<td valign="middle">
    					<input type="text" id="points-for-pub-photos" name="wppa_pub_photo" value="<?php echo $pp; ?>" class="short-text code" />
    				</td>
    			</tr>
    			<tr valign="top">
    				<th scope="row">
    					<label for="points-for-feat-photos">Featured Photos:</label>
    				</th>
    				<td valign="middle">
    					<input type="text" id="points-for-feat-photos" name="wppa_feat_photo" value="<?php echo $fp; ?>" class="short-text code" />
    				</td>
    			</tr>
    		</table>
    <?php
    	}
    
    	/**
    	 * Process Settings
    	 *
    	 * @action 'cp_config_process'
    	 */
    	add_action( 'cp_config_process', 'cp_module_wp_photo_album_plus_points_process' );
    	function cp_module_wp_photo_album_plus_points_process()
    	{
    		if ( isset( $_POST['wppa_pub_photo'] ) ) {
    			update_option( 'wppa_points_for_approval', (int) abs( $_POST['wppa_pub_photo'] ) );
    		}
    		else {
    			update_option( 'wppa_points_for_approval', 0 );
    		}
    
    		if ( isset( $_POST['wppa_feat_photo'] ) ) {
    			update_option( 'wppa_points_for_featured', (int) abs( $_POST['wppa_feat_photo'] ) );
    		}
    		else {
    			update_option( 'wppa_points_for_featured', 0 );
    		}
    	}
    
    	/**
    	 * Customize CubePoints Log
    	 *
    	 * @action 'cp_logs_description'
    	 */
    	add_action( 'cp_logs_description', 'cp_module_wp_photo_album_plus_points_description', 10, 4 );
    	function cp_module_wp_photo_album_plus_points_description( $type, $user_id, $points, $data )
    	{
    		if ( $type == 'wppa-photo-published' )
    			echo 'Points for uploaded photo';
    		elseif ( $type == 'wppa-photo-featured' )
    			echo 'Points for featured photo';
    		else
    			return;
    	}
    
    	/**
    	 * Checks if a given photo has been given points for a specific status
    	 *
    	 * @param $photo_id (int) required, photo id to check for
    	 * @param $value (string) required, either published or featured
    	 * @version 1.0
    	 */
    	function cp_module_photo_got_points( $photo_id, $value )
    	{
    		global $wpdb;
    
    		if ( $value == 'publish' )
    			$type = 'wppa-photo-published';
    		else
    			$type = 'wppa-photo-featured';
    
    		$check = $wpdb->get_results( $wpdb->prepare( "
    			SELECT *
    			FROM " . CP_DB . "
    			WHERE data = %d AND type = %s ", $photo_id, $type ) );
    
    		if ( $check )
    			return true;
    		else
    			return false;
    
    	}
    
    	/**
    	 * Hook into our custom action
    	 */
    	add_action( 'wppa_updated_photo', 'cp_module_wp_photo_album_plus_points_updated_photo', 10, 4 );
    	function cp_module_wp_photo_album_plus_points_updated_photo( $item, $value, $itemname, $photo )
    	{
    		// Only status updates please and only if we have not awarded points yet
    		if ( $item == 'status' ) {
    
    			// No points is awarded if the status is "pending" or if this photo has already been given points
    			if ( $value == 'pending' || cp_module_photo_got_points( $photo, $value ) ) return;
    
    			global $wpdb;
    
    			// Get the Photo from DB so we can grab the owner
    			$picture = $wpdb->get_row( $wpdb->prepare( "
    				SELECT *
    				FROM " . WPPA_PHOTOS . "
    				WHERE id = %d ", $photo
    			) );
    
    			// If picture was found
    			if ( $picture ) {
    
    				// Get Owner
    				$owner = get_user_by( 'login', $picture->owner );
    
    				// Points
    				if ( $value == 'publish' )
    					$points = get_option( 'wppa_points_for_approval' );
    				else
    					$points = get_option( 'wppa_points_for_featured' );
    
    				// Type
    				if ( $value == 'publish' )
    					$type = 'wppa-photo-published';
    				else
    					$type = 'wppa-photo-featured';
    
    				// Award points if points setting is higher then zero
    				if ( (int) $points > 0 )
    					cp_points( $type, (int) $owner->ID, (int) $points, (int) $photo );
    
    			}
    
    		}
    	}
    }
    ?>

    Tested on CubePoints 3.2.1 and WP 3.5

  7. justinh2k
    Member
    Posted 2 years ago #

    Thank you very much!! One last request...could you make an option to automatically pay a point instead of asking the user to click the button to pay, to access a paid page? If so..look forward to a donation;)

  8. Gabriel
    Member
    Posted 2 years ago #

    I am not sure I understand your request, please remember that I am not very familiar with WP Photo Album Plus.

  9. justinh2k
    Member
    Posted 2 years ago #

    No this would be through your script Cubepoints..when you activate the paid page module and you access a page that you set as paid content, it asks the user to pay with a point in a form of a button to access the page..anyway to make it pay automatically?

  10. Gabriel
    Member
    Posted 2 years ago #

    Ah I see! For the record CubePoints is not my script. I am just a fellow user who happens to know it like the back of my hand. I guess you could do what you are requesting. Create a new support post here so we can keep things separate from this post.

    Also remember that if the module works feel free to mark this as "resolved". Always nice to keep status up :)

  11. justinh2k
    Member
    Posted 2 years ago #

    oh well I learned something...I will do that for sure..do you have a donation set up?..thank you for all your help..and im sure others think the same

  12. Gabriel
    Member
    Posted 2 years ago #

    I do not have a donate link. I try and lend a hand where ever I can, when ever I have the time.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • CubePoints
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.