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

    (@djpaul)

    Hi Satwinder

    Please can you share with me the code you’ve written, so I can test it out? Thank you.

    Thread Starter Satwinder Rathore

    (@satwinder26890)

    Hi Paul,

    Thanks for reply.

    Here is code I am using.

    function bmr_init_bp_profile_reviews() {
    	achievements()->extensions->bp_profile_reviews = new BP_MEMBER_REVIEW_ACHIEVEMENT;
    
    	do_action( 'bpr_init_bp_profile_reviews' );
    }
    add_action( 'dpa_ready', 'bmr_init_bp_profile_reviews' );
    
    class BP_MEMBER_REVIEW_ACHIEVEMENT extends DPA_Extension {
    
    	public function __construct() {
    
    		$this->actions = array(
    			'bp_member_review_posted_update'	=> __( 'The user get rating.', 'buddypress' ),
    			'bp_member_reviews_top_member'		=> __( 'hit top rating based on users.', 'buddypress' ),
    			'bp_member_review_posted'			=> __( 'The user add review to other user.', 'buddypress' )
    		);
    
    		$this->contributors = array(
    			array(
    				'name'			=> 'Satwinder Rathore',
    				'gravatar_url'	=> 'https://gravatar.com/avatar/7054a208105940b4d162136bb662b940',
    				'profile_url'	=> 'https://profiles.www.ads-software.com/satwinder26890/',
    			),
    		);
    
    		$this->id				= 'reviews';
    		$this->version			= 1;
    		$this->description		= __( 'BP Member Reviews adds a rating section for BuddyPress Members.', 'buddypress' );
    		$this->name				= __( 'BP Member Reviews', 'buddypress' );
    		$this->image_url		= BP_MEMBER_REVIEW_PLUGIN_URL . '/includes/achievement-bp-mem-rev/images/bp-member-reviews.jpg';
    		$this->rss_url			= '#';
    		$this->small_image_url	= BP_MEMBER_REVIEW_PLUGIN_URL . '/includes/achievement-bp-mem-rev/images/bp-member-reviews-small.jpg';
    		$this->wporg_url		= '#';
    	}
    
    }

    I have just copied your example https://gist.github.com/paulgibbs/0e72acf38d59ba111ca5.

    Thread Starter Satwinder Rathore

    (@satwinder26890)

    Thanks Paul for great plugin,

    I figured it out. The problem is when I create actions

    $this->actions = array(
    			'bp_member_review_posted_update'	=> __( 'The user get rating.', 'buddypress' ),
    			'bp_member_reviews_top_member'		=> __( 'hit top rating based on users.', 'buddypress' ),
    			'bp_member_review_posted'			=> __( 'The user add review to other user.', 'buddypress' )
    		);
    

    and save the file it updates the actions in database. But when I update my actions again

    $this->actions = array(
    			'bp_member_review_posted_update'	=> __( 'The user get rating.', 'buddypress' ),
    			'bp_member_reviews_top_member'		=> __( 'hit top rating based on users.', 'buddypress' ),
    			'bp_member_review_posted'			=> __( 'The user add review to other user.', 'buddypress' ),
    			'a_new_action_created'				=> __( 'New actions Description.', 'buddypress' )
    
    		);
    

    they not update in database. The causing problem is there in foreach

    function dpa_maybe_update_extensions() {....
    
    		$id = $extension->get_id();
    		if ( ! isset( $versions[$id] ) ) {
    			$actions = $extension->get_actions();
    
    			// Add the actions to the dpa_event taxonomy
    			foreach ( $actions as $action_name => $action_desc )
    				wp_insert_term( $action_name, dpa_get_event_tax_id(), array( 'description' => $action_desc ) );
    
    			// Record version
    			$versions[$id] = $extension->get_version();
    
    		// Check if an update is available.
    		} elseif ( version_compare( $extension->get_version(), $versions[$id], '>' ) ) {
    			$extension->do_update( $versions[$id] );
    			$versions[$id] = $extension->get_version();
    		}
    	}.....
    

    its not saving data for old $versions[$id] to database so I just add_action in my theme and update it

    function dpa_maybe_update_extensions() {....
    
    		$id = $extension->get_id();
    		if ( ! isset( $versions[$id] ) ) {
    			$actions = $extension->get_actions();
    
    			// Add the actions to the dpa_event taxonomy
    			foreach ( $actions as $action_name => $action_desc )
    				wp_insert_term( $action_name, dpa_get_event_tax_id(), array( 'description' => $action_desc ) );
    
    			// Record version
    			$versions[$id] = $extension->get_version();
    
    		// Check if an update is available.
    		} elseif ( version_compare( $extension->get_version(), $versions[$id], '>' ) ) {
    			$extension->do_update( $versions[$id] );
    			$versions[$id] = $extension->get_version();
    		} else {
    			$actions = $extension->get_actions();
    
    			// Add the actions to the dpa_event taxonomy
    			foreach ( $actions as $action_name => $action_desc )
    				wp_insert_term( $action_name, dpa_get_event_tax_id(), array( 'description' => $action_desc ) );
    
    			// Record version
    			$versions[$id] = $extension->get_version();
    		}
    	}.....
    

    and that’s work fine. Now I add new actions and it update in database.

    Thanks Again

    Satwinder

    Plugin Author Paul Wong-Gibbs

    (@djpaul)

    Yep, you got it. Good research. ??

    This might feel like a bug but it was built this way to make it easy. It doesn’t, however, handle very well for developers building extensions because the next page load will set the version number in the database and Achievements will think the custom extension has already been set up. It does need to be changed though, because it’s a pretty poor developer user experience.

    I am releasing a new version of Achievements this Friday. It won’t have a fix or improvement for this issue, but the next version after that, I will make sure I address this somehow.

    Thank you for your patience and your detailed explanation of what’s happening. It will help me explain the same problem to other developers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Actions not showing in choice drop-down’ is closed to new replies.