Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author myCred

    (@designbymerovingi)

    You could do this in 1.6 by adjusting the reference you save the points under.

    So first, we would need to add in the references so we can select them when creating a badge:

    /**
     * Add References
     * @version 1.0
     */
    add_filter( 'mycred_all_references', 'mycred_pro_add_references' );
    function mycred_pro_add_references( $references ) {
    
    	$post_type_args = array(
    		'public'   => true,
    		'_builtin' => false
    	);
    	$post_types = get_post_types( $post_type_args, 'objects', 'and' );
    	foreach ( $post_types as $post_type ) {
    
    		if ( ! array_key_exists( 'publishing_' . $post_type->name, $references ) )
    			$references[ 'publishing_' . $post_type->name ] = 'Publishing ' . $post_type->labels->name;
    
    	}
    
    	return $references;
    
    }

    Now we have a unique reference for each post type. Next we need to make sure this hook saves points in the log base don this new reference setup. Without this, the badge processor will not be able to match badges.

    /**
     * Adjust Reference
     * @version 1.0
     */
    add_filter( 'mycred_run_this', 'mycred_pro_post_type_ref' );
    function mycred_pro_post_type_ref( $request ) {
    
    	// Only applicable to the points for publishing content hook
    	if ( $request['ref'] != 'publishing_content' ) return $request;
    
    	// Save this under a new reference: publishing_{post_type}
    	$new_ref = 'publishing_' . get_post_type( absint( $request['ref_id'] ) );
    	if ( $new_ref != 'publishing_' )
    		$request['ref'] = $new_ref;
    
    	return $request;
    
    }

    The mycred_run_this filter is new in 1.6 and allows you to adjust what myCRED should run. You can change anything about the request like the amount, the user ID, anything.

    Thread Starter Daniel Lemes

    (@daniel_iceman)

    Thank you, I’ll try it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Badge for publish custom type of content’ is closed to new replies.