logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$25
Make cubepoints register points for custom post types! Help!

I completely miscalculated how many things would hate custom post types, and have just spent a whole day moving my community added posts to a Custom-post type (around 12,000 posts), but now people aren't getting their cubepoints for creating them (grrrr).

In my crazed googling I found this, although no idea what it does.

http://code.google.com/p/cubepoints/source/browse/trunk/modules/custom_points.php?spec=svn32&r=32


and this:
http://cubepoints.com/forums/topic/extend-cubepoints-module


And this is in their documentation

Modules System
Using the modules system to integrate with other plugins is easy. Simply add this code into your intergration codes, and your module information will be shown in CubePoints > Modules under WP Admin Panel


<?php
$cp_modules[] = array (
name => 'Module Name',
version => '1.0.0',
url => 'Module URL',
description => 'Module Description',
api_version => '1.0 (Do not change)',
author => 'Module Author',
author_url => 'Author URL'
);
?>


Found here - http://plugins.svn.wordpress.org/cubepoints/tags/2.1.1/docs/docs.html


Anyone have any experience with Cubepoints?The developers seem to believe it's pretty easy to create custom functions, but haven't gotten around to ever properly explaining how :(

Fingers and toes crossed.

This question has been answered.

kateM82 | 07/31/11 at 11:17am Edit

Previous versions of this question: 07/31/11 at 11:22am | 07/31/11 at 11:23am | 07/31/11 at 11:35am | 07/31/11 at 12:10pm | 07/31/11 at 12:10pm

(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    07/31/11
    12:35pm
    Gabriel Merovingi says:

    Hey!

    What version of Cube do you use?

    • 07/31/11 12:38pm

      kateM82 says:

      The most recent one, just updated today :)

    • 07/31/11 1:05pm

      Gabriel Merovingi says:

      Can you paste your code for when you create this custom post type you wish to give points for?

    • 07/31/11 2:28pm

      Gabriel Merovingi says:

      Here is a module that gives 100 points (set on line 92) when someone publishes a post with custom post type "book" (also set on line 92). You can change this to suit your needs.

      I have tried it on my server and it works. Let me know what you think.

      <?php

      /** Custom Points Module */

      cp_module_register(__('Book Points', 'cp') , 'customtype' , '1.0', 'DBM', 'http://www.merovingi.com', 'http://www.merovingi.com' , __('This module gives you the ability to set custom points for custom post type book.', 'cp'), 1);

      if(cp_module_activated('customtype')){

      /* Define the custom box */
      add_action('admin_init', 'cp_module_customtype_add_custom_box', 1);

      /* Do something with the data entered */
      add_action('save_post', 'cp_module_customtype_save_postdata');
      add_action('publish_post', 'cp_module_customtype_publish_postdata');

      /* Adds a box to the main column on the Post and Page edit screens */
      function cp_module_customtype_add_custom_box() {
      add_meta_box( 'cp_module_customtype_set', 'CubePoints - Custom Points', 'cp_module_customtype_box', 'book', 'normal', 'high' );
      }

      /* Prints the box content */
      function cp_module_customtype_box() {

      global $post;

      // Use nonce for verification
      wp_nonce_field( plugin_basename(__FILE__), 'cp_module_customp_nonce' );

      // The actual fields for data entry
      echo '<br /><input type="checkbox" id="cp_module_customp_enable" name="cp_module_customp_enable" value="1" size="25" '.((bool)(get_post_meta($post->ID , 'cp_points_enable', 1))?'checked="yes"':'').' /> ';
      echo '<label for="cp_module_customp_enable">' . __("Set custom points for comments on this page" , 'cp') . '</label> ';
      echo '<br /><br />';
      echo '<label for="cp_module_customp_points">' . __("Number of points per comment" , 'cp') . ':</label> ';
      echo '<input type="text" id= "cp_module_customp_points" name="cp_module_customp_points" value="'.(int)get_post_meta($post->ID , 'cp_points', 1).'" size="25" /><br /><br />';
      }

      /* When the post is saved, saves our custom data */
      function cp_module_customtype_save_postdata( $post_id ) {

      // get post id from the revision id
      if($parent_id = wp_is_post_revision($post_id)){
      $post_id = $parent_id;
      }

      // verify this came from the our screen and with proper authorization,
      // because save_post can be triggered at other times

      if ( !wp_verify_nonce( $_POST['cp_module_customp_nonce'], plugin_basename(__FILE__) )) {
      return $post_id;
      }

      // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
      return $post_id;



      // OK, we're authenticated: we need to find and save the data
      update_post_meta($post_id, 'cp_points_enable', (int)$_POST['cp_module_customp_enable']);
      update_post_meta($post_id, 'cp_points', (int)$_POST['cp_module_customp_points']);

      }
      /* When the post is saved, saves our custom data */
      function cp_module_customtype_publish_postdata( $post_id ) {

      // get post id from the revision id
      if($parent_id = wp_is_post_revision($post_id)){
      $post_id = $parent_id;
      }

      // verify this came from the our screen and with proper authorization,
      // because save_post can be triggered at other times

      if ( !wp_verify_nonce( $_POST['cp_module_customp_nonce'], plugin_basename(__FILE__) )) {
      return $post_id;
      }

      // verify if this is an auto save routine. If it is our form has not been submitted, so we don't want to do anything
      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
      return $post_id;



      // OK, we're authenticated: we need to find and save the data

      $posttype = get_post($post_id);
      $uid = $posttype->post_author;
      global $wpdb;
      $count = (int) $wpdb->get_var("select count(id) from `".CP_DB."` where `type`='post' and `data`=". $pid);
      if($count==0){
      cp_points('book', $uid, '100', $post_id);
      }
      update_post_meta($post_id, 'cp_points_enable', (int)$_POST['cp_module_customp_enable']);
      update_post_meta($post_id, 'cp_points', (int)$_POST['cp_module_customp_points']);

      }

      /* Add CubePoints comment action hook */
      add_action('cp_newComment', 'cp_module_customtype_newComment');
      function cp_module_customtype_newComment($cid) {
      if (is_user_logged_in()) {
      $cdata = get_comment($cid);
      $pid = $cdata->comment_post_ID;
      $customp_enabled = (bool) get_post_meta($pid,'cp_points_enable', 1);
      $customp_points = (int) get_post_meta($pid,'cp_points', 1);
      if( $customp_enabled ){
      add_filter('cp_comment_points',create_function('$points', 'return '.$customp_points.';'),1);
      }
      }
      }

      }

      ?>

    • 07/31/11 2:29pm

      Gabriel Merovingi says:

      Save this as a php file and put it into your module folder of the plugin. Adjust it to suit your needs and don't forget to activate

    • 07/31/11 8:24pm

      kateM82 says:

      Hi Gabriel,

      It's still not adding any points, do I need to change permission of the file/folder or anything like that?

      It appears in the modules admin and I have activated it, but nothing is showing in the logs when I create the custom post?

      Here is what I added (custom post is called 'dshop' , points value is 15)


      <?php



      /** Custom Points Module */



      cp_module_register(__('dSHOP Points', 'cp') , 'customtype' , '1.0', 'DBM', 'http://www.merovingi.com', 'http://www.merovingi.com' , __('This module gives you the ability to set custom points for custom post type dSHOP.', 'cp'), 1);



      if(cp_module_activated('customtype')){



      /* Define the custom box */

      add_action('admin_init', 'cp_module_customtype_add_custom_box', 1);



      /* Do something with the data entered */

      add_action('save_post', 'cp_module_customtype_save_postdata');

      add_action('publish_post', 'cp_module_customtype_publish_postdata');



      /* Adds a box to the main column on the Post and Page edit screens */

      function cp_module_customtype_add_custom_box() {

      add_meta_box( 'cp_module_customtype_set', 'CubePoints - Custom Points', 'cp_module_customtype_box', 'dshop', 'normal', 'high' );

      }



      /* Prints the box content */

      function cp_module_customtype_box() {



      global $post;



      // Use nonce for verification

      wp_nonce_field( plugin_basename(__FILE__), 'cp_module_customp_nonce' );



      // The actual fields for data entry

      echo '<br /><input type="checkbox" id="cp_module_customp_enable" name="cp_module_customp_enable" value="1" size="25" '.((bool)(get_post_meta($post->ID , 'cp_points_enable', 1))?'checked="yes"':'').' /> ';

      echo '<label for="cp_module_customp_enable">' . __("Set custom points for comments on this page" , 'cp') . '</label> ';

      echo '<br /><br />';

      echo '<label for="cp_module_customp_points">' . __("Number of points per comment" , 'cp') . ':</label> ';

      echo '<input type="text" id= "cp_module_customp_points" name="cp_module_customp_points" value="'.(int)get_post_meta($post->ID , 'cp_points', 1).'" size="25" /><br /><br />';

      }



      /* When the post is saved, saves our custom data */

      function cp_module_customtype_save_postdata( $post_id ) {



      // get post id from the revision id

      if($parent_id = wp_is_post_revision($post_id)){

      $post_id = $parent_id;

      }



      // verify this came from the our screen and with proper authorization,

      // because save_post can be triggered at other times



      if ( !wp_verify_nonce( $_POST['cp_module_customp_nonce'], plugin_basename(__FILE__) )) {

      return $post_id;

      }



      // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything

      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )

      return $post_id;







      // OK, we're authenticated: we need to find and save the data

      update_post_meta($post_id, 'cp_points_enable', (int)$_POST['cp_module_customp_enable']);

      update_post_meta($post_id, 'cp_points', (int)$_POST['cp_module_customp_points']);



      }

      /* When the post is saved, saves our custom data */

      function cp_module_customtype_publish_postdata( $post_id ) {



      // get post id from the revision id

      if($parent_id = wp_is_post_revision($post_id)){

      $post_id = $parent_id;

      }



      // verify this came from the our screen and with proper authorization,

      // because save_post can be triggered at other times



      if ( !wp_verify_nonce( $_POST['cp_module_customp_nonce'], plugin_basename(__FILE__) )) {

      return $post_id;

      }



      // verify if this is an auto save routine. If it is our form has not been submitted, so we don't want to do anything

      if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )

      return $post_id;







      // OK, we're authenticated: we need to find and save the data



      $posttype = get_post($post_id);

      $uid = $posttype->post_author;

      global $wpdb;

      $count = (int) $wpdb->get_var("select count(id) from `".CP_DB."` where `type`='post' and `data`=". $pid);

      if($count==0){

      cp_points('dshop', $uid, '15', $post_id);

      }

      update_post_meta($post_id, 'cp_points_enable', (int)$_POST['cp_module_customp_enable']);

      update_post_meta($post_id, 'cp_points', (int)$_POST['cp_module_customp_points']);



      }



      /* Add CubePoints comment action hook */

      add_action('cp_newComment', 'cp_module_customtype_newComment');

      function cp_module_customtype_newComment($cid) {

      if (is_user_logged_in()) {

      $cdata = get_comment($cid);

      $pid = $cdata->comment_post_ID;

      $customp_enabled = (bool) get_post_meta($pid,'cp_points_enable', 1);

      $customp_points = (int) get_post_meta($pid,'cp_points', 1);

      if( $customp_enabled ){

      add_filter('cp_comment_points',create_function('$points', 'return '.$customp_points.';'),1);

      }

      }

      }



      }



      ?>

    • 07/31/11 8:25pm

      kateM82 says:

      Sorry I didn't get onto this earlier, it was 3am my time when I posted it.

    • 07/31/11 10:40pm

      Gabriel Merovingi says:

      Hey!

      Ok here is a new module. Just replace the previous code with this one. It gives you 15 points for publishing "dshop" items. It also adjusts your log (by default it shows blank for custom post types).
      Also i removed the custom points for comments bit. Let me know if you want that feature back.


      <?php

      /** Custom Points Module */

      cp_module_register( __('dSHOP Points', 'cp') , 'customposttypepoints' , '1.0', 'DBM', 'http://www.merovingi.com', 'http://www.merovingi.com' , __('This module awards points when publishing dSHOP items.', 'cp' ), 1 );

      if ( cp_module_activated( 'customposttypepoints' ) ) {

      /* When a item is published we want to add points */
      add_action( 'publish_dshop', 'cp_module_customtype_publish_points' );

      function cp_module_customtype_publish_points( $post_id ) {

      // get post id from the revision id
      if ( $parent_id = wp_is_post_revision( $post_id ) ) {
      $post_id = $parent_id;
      }

      // verify if this is an auto save routine. If it is our form has not been submitted, so we don't want to do anything
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
      return $post_id;

      // Add points and log it.
      $post = get_post( $post_id );
      cp_points( 'dshop', $post->post_author, '15', $post_id );
      }

      /** Adjust log */
      add_action('cp_logs_description','cp_admin_logs_desc_dshop', 5, 4);
      function cp_admin_logs_desc_dshop($type,$uid,$points,$data){
      if($type!='dshop') { return; }
      $post = get_post($data);
      echo __('Points given for dSHOP item:', 'cp') . ' "<a href="'.get_permalink( $post ).'">' . $post->post_title . '</a>"';
      }
      }

      ?>


      Remember to deactivate the module before changing the file! Then re-activate it. Tested it in my sandbox and it works.

    • 07/31/11 11:23pm

      kateM82 says:

      Crashed site. Waiting for host to reboot server and will try again... eek!

    • 07/31/11 11:55pm

      kateM82 says:

      It seems to assign the points twice? Any ideas what would cause this?

    • 08/01/11 12:02am

      kateM82 says:

      It also prevents my users from being able to login and would cause white screen of death if I tried to delete a post.

      Any other suggestions?

    • 08/01/11 2:56am

      Gabriel Merovingi says:

      What version of WordPress do you use?

    • 08/01/11 2:56am

      kateM82 says:

      3.1.2

    • 08/01/11 3:07am

      Gabriel Merovingi says:

      Can you paste the code you use to create this custom post type "dshop"?

    • 08/01/11 3:13am

      kateM82 says:

      Hi Gabriel,

      I used the plugin Custom Post Type UI (http://webdevstudios.com/support/wordpress-plugins/) to create them.

      Attached is a screenshot of the settings.

      Attached Image

    • 08/01/11 3:14am

      kateM82 says:

      here is second part of screen shot

      Attached Image

    • 08/01/11 3:14am

      Gabriel Merovingi says:

      Ah! Your using a plugin to create your custom post type?

    • 08/01/11 3:17am

      Gabriel Merovingi says:

      Never mind my previous post. Was to quick :)

      I don't understand what can be wrong here since this module does nothing but add points when the action "publish_dshop" is used. The question is how the plugin creates the custom post type. Give me a min to check up on this plugin as I never use plugins for post types.

    • 08/01/11 3:27am

      kateM82 says:

      Thanks Gabriel, sorry it's turning out to be more tricky than I thougt!

    • 08/01/11 3:42am

      Gabriel Merovingi says:

      Ok I downloaded version 0.7 and entered your details. Using WP 3.2.1 this module gives me 15 points each time I publish a dSHOP item.

      Can you send me your email so I can send you my module file ziped? You then just un-zip it and place it in your module folder. /cubepoints/modules/

      And delete the old file you used so far.

    • 08/01/11 4:54am

      Gabriel Merovingi says:

      I have made a new version of the module. After some digging into Cubepoints I have added some further functions which seemingly works for me on WP 3.2.1 with CP 3.0.3.

      This code should be saved in cubepoints/modules/ as custom-post-type-points.php (if you use the old code you need to deactivate that module and delete the file).

      Once activated two new settings pop up under Cube Points > Configure. These are:
      - Custom Post Type:
      - Points for new custom post type:

      In this example they are set to:
      - dshop
      - 15

      This way no modifications are needed in the module file!

      Module:


      <?php

      /** Points for Publishing of Custom Post Type Module */

      cp_module_register( __('Custom Post Type Points', 'cp') , 'customposttypepoints' , '1.0', 'DBM', 'http://www.merovingi.com', 'http://www.merovingi.com' , __('This module awards points when publishing a custom post type item.', 'cp' ), 1 );

      if ( cp_module_activated( 'customposttypepoints' ) ) {

      /** Post Type Settings */
      add_action( 'cp_config_form_points', 'cp_customtype_admin_setting' );
      function cp_customtype_admin_setting() {
      echo '
      <tr valign="top">
      <th scope="row"><label for="cp_comment_points">Custom Post Type:</label>
      </th>
      <td valign="middle"><input type="text" id="cp_customtype_used" name="cp_customtype_used" value="' . get_option('cp_customtype_used') . '" size="30" /></td>
      <td></td>
      </tr>
      <tr valign="top">
      <th scope="row"><label for="cp_comment_points">Points for new custom post type:</label>
      </th>
      <td valign="middle"><input type="text" id="cp_customtype_points" name="cp_customtype_points" value="' . get_option('cp_customtype_points') . '" size="30" /></td>
      <td></td>
      </tr>
      ';
      }

      /** Save Settings */
      add_action( 'cp_config_process', 'cp_customtype_save' );
      function cp_customtype_save() {
      $cp_custom_post_type = $_POST['cp_customtype_used'];
      $cp_custom_post_points = (int)$_POST['cp_customtype_points'];

      update_option( 'cp_customtype_used', $cp_custom_post_type );
      update_option( 'cp_customtype_points', $cp_custom_post_points );
      }

      /* When a item is published we want to add points */
      add_action( 'publish_dshop', 'cp_module_customtype_publish_points' );
      function cp_module_customtype_publish_points( $post_id ) {

      // get post id from the revision id
      if ( $parent_id = wp_is_post_revision( $post_id ) ) {
      $post_id = $parent_id;
      }

      // verify if this is an auto save routine. If it is our form has not been submitted, so we don't want to do anything
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
      return $post_id;

      // Add points and log it.
      $post = get_post( $post_id );
      $post_type_used = get_option( 'cp_customtype_used' );
      $post_type_points = get_option( 'cp_customtype_points' );
      cp_points( $post_type_used, $post->post_author, $post_type_points, $post_id );
      }

      /** Adjust the Log */
      add_action('cp_logs_description','cp_admin_logs_desc_customposttype', 10, 4);
      function cp_admin_logs_desc_customposttype( $type, $uid, $points, $data ) {
      if ( $type != 'dshop' ) { return; }
      $post = get_post( $data );
      $obj = get_post_type_object( $type );
      echo 'Points given for ' . $obj->labels->singular_name . ':' . ' "<a href="' . get_permalink( $post ) . '">' . $post->post_title . '</a>"';
      }


      }
      ?>

      Attached Image

    • 08/01/11 7:02am

      kateM82 says:

      ok, that worked (no crashing), but still registering 2 x points.

      It's only when the users submit the posts via Gravity Forms that this happens, it doesn't happen when I submit the post via the back end. Any ideas?

    • 08/01/11 7:08am

      Gabriel Merovingi says:

      Ok we are getting somewhere.

      Can you show me your settings for the Gravity Form used to submit dshop items please?
      The module adds points when "publish_dshop" is called. So double points means your settings for that form calls this action twice.

    • 08/01/11 9:53am

      Gabriel Merovingi says:

      I see I missed a few things in the previous module. All though it works if you change the post type it will stop doing so. You should replace the previous code with this one.

      Module:


      /** Points for Publishing of Custom Post Type Module */
      cp_module_register(
      __( 'Custom Post Type Points', 'cp' ),
      'customposttypepoints',
      '1.1',
      'dbm',
      'http://www.merovingi.com',
      'http://www.merovingi.com',
      __('This module awards points when publishing a custom post type item. Requires WordPress 3.0+', 'cp' ), 1 );

      if ( cp_module_activated( 'customposttypepoints' ) ) {

      /** Module Configuration */
      add_action( 'cp_config_form', 'cp_customtype_admin_setting' );
      function cp_customtype_admin_setting() {
      echo '
      <br />
      <h3>Custom Post Type</h3>
      <table class="form-table">
      <tr valign="top">
      <th scope="row"><label for="cp_customtype_used">Custom Post Type:</label></th>
      <td valign="middle"><input type="text" id="cp_customtype_used" name="cp_customtype_used" value="' . get_option( 'cp_customtype_used' ) . '" size="30" /></td>
      </tr>
      <tr valign="top">
      <th scope="row"><label for="cp_customtype_points">Points for new custom post type:</label></th>
      <td valign="middle"><input type="text" id="cp_customtype_points" name="cp_customtype_points" value="' . get_option( 'cp_customtype_points' ) . '" size="30" /></td>
      </tr>
      </table>' . "\n";
      }

      /** Save Module Congif */
      add_action( 'cp_config_process', 'cp_customtype_save' );
      function cp_customtype_save() {
      update_option( 'cp_customtype_used', $_POST['cp_customtype_used'] );
      update_option( 'cp_customtype_points', (int)$_POST['cp_customtype_points'] );
      }

      /** When a item is published we want to add points */
      add_action( 'publish_' . get_option( 'cp_customtype_used' ), 'cp_module_customtype_publish_points' );
      function cp_module_customtype_publish_points( $post_id ) {

      // get post id from the revision id
      if ( $parent_id = wp_is_post_revision( $post_id ) ) $post_id = $parent_id;

      // verify if this is an auto save routine.
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;

      // verify that we are publishing the custom post type
      // this should never fail since the action should always be 'publish_$post_type'
      if ( get_post_type( $post_id ) != get_option( 'cp_customtype_used' ) ) return $post_id;

      // add points and log it.
      $post = get_post( $post_id );
      cp_points( get_option( 'cp_customtype_used' ), $post->post_author, get_option( 'cp_customtype_points' ), $post_id );
      }

      /** Adjust the Log. Overwrite custom post type entries. */
      add_action( 'cp_logs_description', 'cp_admin_logs_desc_customposttype', 10, 4 );
      function cp_admin_logs_desc_customposttype( $type, $uid, $points, $data ) {
      // Grab details about the post type and the post itself.
      $post = get_post( $data );
      $obj = get_post_type_object( $type );
      // IF the type is not the custom type we set, bail.
      if ( $type != get_option( 'cp_customtype_used' ) )
      return;
      else
      echo 'Points given for ' . $obj->labels->singular_name . ':' . ' "<a href="' . get_permalink( $post ) . '">' . $post->post_title . '</a>"';
      }
      }

      Attached Image

    • 08/01/11 6:41pm

      kateM82 says:

      Hi Gabriel,

      Attached is screen shot of form settings (the only ones I can see) does this help?

      Attached Image

    • 08/01/11 6:42pm

      kateM82 says:

      Also if I need to add a second or third post type what should I do? thanks.

    • 08/01/11 6:59pm

      Gabriel Merovingi says:

      How many post types do you need? Anything else that needs to be included?

    • 08/01/11 7:00pm

      Gabriel Merovingi says:

      With the latest version of the module I posted here, you still having the double points issue? Any other issues?

    • 08/01/11 8:46pm

      kateM82 says:

      Hi Gabriel,

      Originally I was hoping it would just treat the addition of the publishing of all/any custom post type as the same as a regular post.

      But as the code you sent through just addresses one type, I will need to be able to add types to this. I currently have 4 different post types, and may need more in the future.

      And yes the code posted above (haven't seen any others?) still gives the doubdle points. thanks.

    • 08/01/11 10:53pm

      kateM82 says:

      Hi Gabriel,

      I also noticed that when someone edits and then resubmits an item they get the points again. It needs to only be when it's first published, exactly the same as the normal post function, thanks again :)

    • 08/02/11 4:55am

      Gabriel Merovingi says:

      Ok.

      Does all custom post types give the same amount of points? Will there be any difference in the future? Do you want this module to handle all custom post types (except for buildtin types like post, page, attachment etc)?

      Very strange that this does not work for you. For me, it only gives points when an item is published. The end. No points are given when saved or when submitted for aproval or edited, just when you hit that blue Publish button.

    • 08/02/11 6:09am

      kateM82 says:

      Right now, all custom posts can be treated the same, happy to revisit later on. Just need to get it working asap (and it's so, so close!)

      Thanks :)

    • 08/02/11 6:15pm

      Gabriel Merovingi says:

      Ok so here is a new module.

      Installation:
      - De-activate the previous module I posted and delete the file.
      - Create a new file and name is multiple_custom_post_types.php
      - Paste the code bellow and save.
      - Around line 100, you need to insert an action for each of your registered post types. (due to time restraints I have not been able to automate this). In this example you will find that I already added "dshop" but you will need to add all other).
      - Activate the new module called Multiple Custom Post Type Points
      - Under Cubepoints > Config set if you want to give all custom post types the same amount of points or if you want individual points.
      (if you select individual select No and click update. The module will collect all your registered post types and give you the option to give them each a custom number of points)

      Function:
      - Each time a custom post type is published, the module will add points to its author.
      - IF an already published item gets changed to "Pending" or "Draft" the module will deduct points (same amount as given).
      - Once the item gets published again new points are added.
      - When points are removed the log is updated.

      Gravity Forms:
      I have tried to find information on gravity forms and why it gives double points. As you will see this module works with WordPress so if it still gives you double points you will need to talk to someone who actually knows the plugin. Unfortunately I have never used it myself as I tend to write my own code or use other plugins.

      Module:


      <?php

      /** Points for Publishing of Multiple Custom Post Type Module */
      cp_module_register(
      __( 'Multiple Custom Post Type Points', 'cp' ),
      'mulcustomposttypepoints',
      '1.0',
      'dbm',
      'http://www.merovingi.com',
      'http://www.merovingi.com',
      __('This module awards points when publishing a number of custom post type item. Requires WordPress 3.0+', 'cp' ), 1 );

      if ( cp_module_activated( 'mulcustomposttypepoints' ) ) {

      /** Module Configuration */
      add_action( 'cp_config_form', 'cp_multi_customtypes_admin_setting' );
      function cp_multi_customtypes_admin_setting() {

      echo '
      <br />
      <h3>Multiple Post Types</h3>
      <table class="form-table">
      <tr valign="top">
      <th scope="row"><label for="cp_customtype_used">All post types give same points?</label></th>
      <td valign="middle">
      <select id="cp_multi_option" name="cp_multi_option">' . "\n";
      $multiple_types = get_option( 'cp_multi_type' );
      // defaults to yes
      if ( empty( $multiple_types ) ) $multiple_types = 'yes';
      $our_option = array( 'yes', 'no' );
      foreach ( $our_option as $option ) {
      echo '<option value="' . $option . '"';
      if ( $option == $multiple_types ) echo ' selected="selected"';
      echo '> ' . ucfirst( $option ) . '</option>' . "\n";
      }
      echo '
      </select>
      </td>
      </tr>';
      // If all custom post types are given the same points we only want to know one thing, how much.
      if ( $multiple_types == 'yes' || empty( $multiple_types ) ) {
      echo '
      <tr valign="top">
      <th scope="row"><label for="cp_customtype_points">Points for Publishing a custom post type:</label></th>
      <td valign="middle"><input type="text" id="cp_multi_type_points" name="cp_multi_type_points" value="' . get_option( 'cp_multi_type_points' ) . '" size="30" /></td>
      </tr>
      </table>';
      }
      // Otherwise we list all custom post types with its own points
      else {
      $args = array(
      'public' => true,
      '_builtin' => false
      );
      $post_types = get_post_types( $args, 'names', 'and' );
      foreach ( $post_types as $post_type ) {
      echo '
      <tr valign="top">
      <th scope="row"><label for="cp_customtype_points">Points for Publishing ' . $post_type . 's:</label></th>
      <td valign="middle"><input type="text" id="cp_mctype_' . $post_type . '" name="cp_mctype_' . $post_type . '" value="' . get_option( 'cp_mctype_' . $post_type ) . '" size="30" /></td>
      </tr>
      ';
      }
      echo '</table>';
      }
      }

      /** Save Module Congif */
      add_action( 'cp_config_process', 'cp_multi_customtypes_save' );
      function cp_multi_customtypes_save() {
      // If all post types get the same points
      if ( $_POST['cp_multi_option'] == 'yes' ) {
      update_option( 'cp_multi_type', 'yes' );
      update_option( 'cp_multi_type_points', (int)$_POST['cp_multi_type_points'] );
      } else {
      update_option( 'cp_multi_type', 'no' );
      delete_option( 'cp_multi_type_points' );
      }
      // Delete any custom points previously used.
      $args = array(
      'public' => true,
      '_builtin' => false
      );
      $post_types = get_post_types( $args, 'names', 'and' );
      if ( $_POST['cp_multi_option'] == 'yes' ) {
      foreach ( $post_types as $post_type ) {
      delete_option( 'cp_mctype_' . $post_type );
      }
      } else {
      foreach ( $post_types as $post_type ) {
      update_option( 'cp_mctype_' . $post_type, (int)$_POST['cp_mctype_' . $post_type] );
      }
      }
      }

      // Hook for each registered custom post type
      // Add a action for each one of your registered post types.
      // ex. add_action( 'publish_posttype', 'cp_module_multi_type_all_publish_points' );
      add_action( 'publish_book', 'cp_module_multi_type_all_publish_points' );

      // When a published item goes back to "draft" or "pending" we remove points until they get published again.
      // Do not change / add / mod / remove!
      add_action( 'publish_to_draft', 'cp_module_multi_type_remove_points' );
      add_action( 'publish_to_pending', 'cp_module_multi_type_remove_points' );

      // When we add points
      function cp_module_multi_type_all_publish_points( $post_id ) {

      // get post id from the revision id
      if ( $parent_id = wp_is_post_revision( $post_id ) ) $post_id = $parent_id;

      // verify if this is an auto save routine.
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;

      // get the posts post type
      $post_type = get_post_type( $post_id );
      $type_object = get_post_type_object( $post_type );
      // get the post details
      $post = get_post( $post_id );
      // get our settings
      $post_type_rule = get_option( 'cp_multi_type' );
      if ( $post_type_rule == 'yes' ) cp_points( $type_object->name, $post->post_author, (int)get_option( 'cp_multi_type_points' ), $post_id );
      else cp_points( $type_object->name, $post->post_author, (int)get_option( 'cp_mctype_' . $type_object->name ), $post_id );
      }
      // When we remove posts
      function cp_module_multi_type_remove_points( $post ) {

      // get the posts post type
      $post_type = get_post_type( $post->ID );
      // get our setting
      $post_type_rule = get_option( 'cp_multi_type' );
      // grab users points
      $users_points = get_user_meta( $post->post_author, 'cpoints', true );
      // grab how many points we want to remove
      if ( $post_type == 'post' ) {
      $points_to_take = get_option( 'cp_post_points' );
      } else {
      if ( $post_type_rule == 'yes' ) $points_to_take = get_option( 'cp_multi_type_points' );
      else $points_to_take = get_option( 'cp_mctype_' . $post_type );
      }
      $new_points = $users_points - $points_to_take;
      update_user_meta( $post->post_author, 'cpoints', $new_points );
      cp_log( 'negative', $post->post_author, $points_to_take, $post->ID );

      }

      /** Adjust the Log. Overwrite custom post type entries. */
      add_action( 'cp_logs_description', 'cp_admin_logs_desc_multi_customtypes', 15, 4 );
      function cp_admin_logs_desc_multi_customtypes( $type, $uid, $points, $data ) {
      // Grab details about the post type and the post itself.
      $post = get_post( $data );
      $obj = get_post_type_object( $type );
      if ( $post->post_type == $type && $type != 'post' ) {
      echo 'Points given for ' . $obj->labels->singular_name . ': <a href="' . get_permalink( $post ) . '">' . $post->post_title . '</a>';
      }
      elseif ( $type == 'negative' ) {
      echo 'Removed points for: <a href="' . get_permalink( $post ) . '">' . $post->post_title . '</a> for getting drafted or pending.';
      } else {
      return;
      }
      }
      }

      ?>

    • 08/02/11 6:16pm

      Gabriel Merovingi says:

      ups, I see I used "publish_book" instead of "publish_dshop" you need to change this.

    • 08/07/11 12:56am

      kateM82 says:

      Hi Gabriel,

      It's still doing double points.

      Very weird as I would have thought the publish action on a custom post was the same as with a normal post, and there wasn't the double points happening before using the same gravity form etc.. .

      I will get someone else to look at it another time as you've already spent way to much time on it for only $25.

      Thanks for all your help.

      Kate

This question has expired.



kateM82 voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.