• Resolved newCodex

    (@newcodex)


    Hi,
    I have to add a new event criteria in achievement plugin i.e. to award badge to user who has uploaded 25 images. My site have bbpress plugin installed.
    I tried with the following code and did what is written in this links:
    http://wordpress.org/support/topic/adding-more-actions
    http://wordpress.org/support/topic/how-can-i-add-more-events

    My code:

    <?php
    /**
     * Extension for RT Media
     *
     * This file extends Achievements to support actions from RT Media
     *
     * @package Achievements
     * @subpackage ExtensionRTMedia
     */
    
    // Exit if accessed directly
    if ( ! defined( 'ABSPATH' ) ) exit;
    
    /**
     * Extends Achievements to support actions from RT Media.
     *
     * @since Achievements (3.0)
     */
    function dpa_init_rtmedia_extension() {
    
    	achievements()->extensions->rt_media = new DPA_Rt_Media_Extension;
    
    	// Tell the world that the RT Media extension is ready
    	do_action( 'dpa_init_rtmedia_extension' );
    }
    add_action( 'dpa_ready', 'dpa_init_rtmedia_extension' );
    
    /**
     * Extension to add RT Media support to Achievements
     *
     * @since Achievements (3.0)
     */
    class DPA_Rt_Media_Extension extends DPA_Extension {
    	/**
    	 * Constructor
    	 *
    	 * Sets up extension properties. See class phpdoc for details.
    	 *
    	 * @since Achievements (3.0)
    	 */
    	public function __construct() {
    
    		$this->actions = array(
    			'rtmedia_after_add_media' => __( 'Uploaded Photos.', 'dpa' ),
    		);
    
    		$this->contributors = array(
    			array(
    				'name'         => 'Boone Gorges',
    				'gravatar_url' => 'http://www.gravatar.com/avatar/9cf7c4541a582729a5fc7ae484786c0c',
    				'profile_url'  => 'http://profiles.wordpress.org/blackphantom/',
    			),
    			array(
    				'name'         => 'CUNY Academic Commons',
    				'gravatar_url' => 'http://www.gravatar.com/avatar/80c3fc801559bbc7111d5e3f56ac6a4c',
    				'profile_url'  => 'http://profiles.wordpress.org/cuny-academic-commons/',
    			),
    		);
    
    		$this->description     = __( "Makes BuddyPress’s RTMedia features more powerful.", 'dpa' );
    		$this->id              = 'rt-media';
    		$this->image_url       = trailingslashit( achievements()->includes_url ) . 'admin/images/invite-anyone.jpg';
    		$this->name            = __( 'RT Media', 'dpa' );
    		$this->rss_url         = 'http://teleogistic.net/feed/';
    		$this->small_image_url = trailingslashit( achievements()->includes_url ) . 'admin/images/invite-anyone-small.jpg';
    		$this->version         = 1;
    		$this->wporg_url       = 'http://wordpress.org/plugins/invite-anyone/';
    
    		add_filter( 'dpa_handle_event_user_id', array( $this, 'event_user_id' ), 10, 3 );
    	}
    
    	/**
     	 * For the rtmedia_upload_file_upload action from Invite Anyone, get the user ID from the function
     	 * arguments as the user isn't logged in yet.
    	 *
    	 * @param int $user_id
    	 * @param string $action_name
    	 * @param array $action_func_args The action's arguments from func_get_args().
    	 * @return int|false New user ID or false to skip any further processing
    	 * @since Achievements (3.0)
    	 */
    	public function event_user_id( $user_id, $action_name, $action_func_args ) {
    		if ( 'rtmedia_after_add_media' !== $action_name )
    			return $user_id;
    
    		return (int) $action_func_args[0];
    	}
    }

    Also did the changes in the required tables
    @paul Gibbs -pls have a look at it.
    Thanks

    http://wordpress.org/support/plugin/achievements

    http://wordpress.org/plugins/achievements/

Viewing 1 replies (of 1 total)
  • Plugin Author Paul Wong-Gibbs

    (@djpaul)

    Hi

    1) Are you sure that the rtmedia_after_add_media action is triggered? How have you tested/confirmed this?

    2) Does this custom action need the event_user_id() method that you’ve hooked to dpa_handle_event_user_id? If this is left-over copy/paste from the Invite Anyone extension that you’ve copied from, you probably don’t need it unless you know you do, so best to remove it.

Viewing 1 replies (of 1 total)
  • The topic ‘Unable to add new action in achievement plugin’ is closed to new replies.