Forum Replies Created

Viewing 15 replies - 1 through 15 (of 15 total)
  • Cool, I commented out…

    public function on_plugins_loaded() {
    do_action( ‘somdn_loaded’ );
    //$this->update_plugin();
    }

    Thanks for responding. Useful plugin ??

    Yup I can edit php files.

    The error is still appearing in the logs ??

    In this function below should it always be calling $this->update_complete() even if no updates were done?

    public function __construct( $version = ”, $setting_name = ”, $fresh_install_setting = ” ) {
    //echo ‘$fresh_install_setting = ‘ . $fresh_install_setting;
    if ( empty( $version ) || empty( $setting_name ) ) {
    return;// bail
    }
    $this->new_version = $this->clean_string( $version );

    $this->setting_name = $this->clean_string( $setting_name );

    $this->old_version = ! empty( get_option( $this->setting_name ) ) ?
    $this->clean_string( get_option( $this->setting_name ) )
    : ‘0.0.1’ ;

    //$this->old_version = ‘0.0.1’;

    if ( ! empty( $fresh_install_setting ) ) {
    $this->fresh_install_setting = $this->clean_string( $fresh_install_setting );
    }

    //$this->fresh_install_setting = ‘somdn_some_setting_name’;

    //echo ‘<p>$this->new_version = ‘ . $this->new_version . ‘</p>’;
    //echo ‘<p>$this->old_version = ‘ . $this->old_version . ‘</p>’;
    //echo ‘<p>$this->fresh_install_setting = ‘ . $this->fresh_install_setting . ‘</p>’;

    if ( $this->do_updates() ) {
    //echo ‘<p>do_updates</p>’;
    $this->init();
    $this->run();
    }

    $this->update_complete();
    //exit;
    }

    I am running caching plugins, yes.

    The logs show no other deadlocks on the options table for any other plugin as far back as I can see.

    I’ve fully removed the plugin and reinstalled it. I’ll see how it goes from now on a fresh install.

    I haven’t had time to look at the code fully, but I think something is a bit funky in class-somdn-db-updater.php that makes the plugin want to update when it doesn’t need to. Maybe users who installed the latest version fresh aren’t affected because the logic that checks version numbers works for them.

    Yes, only for this plugin.

    Thanks for the quick reply. The error seems to disappear when the Free Downloads WooCommerce plugin is disabled.

    Sorry, just posting again so I can tick the ‘notify me’ thing so I get an email when you respond.

    Hi Richard,

    I’m getting the same error. My php_errolog is filling up with…

    WordPress database error Deadlock found when trying to get lock; try restarting transaction for query DELETE FROM g1g1_options WHERE option_name = ‘somdn_woo_plugin_db_version’ made by require_once(‘wp-load.php’), require_once(‘wp-config.php’), require_once(‘wp-settings.php’), do_action(‘plugins_loaded’), WP_Hook->do_action, WP_Hook->apply_filters, SOM_Free_Downloads->on_plugins_loaded, SOM_Free_Downloads->update_plugin, SOMDN_DB_Updater->__construct, SOMDN_DB_Updater->update_complete, delete_option, QM_DB->query

    Is the plugin trying to update when it doesn’t need to?

    Thread Starter chuckra

    (@chuckra)

    It also breaks login links created with wp_login_url( get_permalink() )

    Thread Starter chuckra

    (@chuckra)

    I found a sort of fix…

    It was a conflict with the Relevanssi plugin

    In my functions.php file i added

    remove_action('delete_attachment', 'relevanssi_delete');
    remove_action('add_attachment', 'relevanssi_publish');
    remove_action('edit_attachment', 'relevanssi_edit');

    I don’t index attachments so I think this fix should be fine.

    I had same issue. I solved it by adding this to functions.php…

    add_filter( 'the_content', 'removeThumbs' );
    function removeThumbs($content){
    	$createdByWpuf = get_post_meta(get_the_ID(),'wpuf_order_id', true);
    
    	if(!$createdByWpuf){
    		$content = preg_replace('#<ul class="wpuf-attachments">(.*?)</ul>#', '', $content);
    	}
    
    	return $content;
    }

    It removes the thumbnails from all content not created by wpuf. Wpuf content displays the thumbnails and other attachments.

    Thread Starter chuckra

    (@chuckra)

    ok…

    I added this to functions.php

    add_filter( 'mycred_add', 'my_mycred_track_spending', 10, 3 );
    function my_mycred_track_spending( $reply, $request, $mycred )
    {
    	if ( $request['ref'] == 'buy_content' ) {
    			$oldAmount = get_user_meta($request['user_id'],  'mycred_total_spent', true );
    			update_user_meta( $request['user_id'], 'mycred_total_spent', $oldAmount - $request['amount'] );
    		}
    
    	return $reply;
    }
    
    function getRank($credits){
    	global $wpdb;
    	$mycred = mycred_get_settings();
    
    	$ranks = $wpdb->get_results( "
    				SELECT rank.ID AS ID, rank.post_title AS title, min.meta_value AS min, max.meta_value AS max
    				FROM {$wpdb->posts} rank
    				INNER JOIN {$wpdb->postmeta} min ON ( min.post_id = rank.ID AND min.meta_key = 'mycred_rank_min' )
    				INNER JOIN {$wpdb->postmeta} max ON ( max.post_id = rank.ID AND max.meta_key = 'mycred_rank_max' )
    				WHERE post_type = 'mycred_rank' AND post_status = 'publish';", 'ARRAY_A' );
    
    	// Loop though each rank
    	foreach ( $ranks as $rank ) {
    		// If balance fits break with this ranks details
    		if ( $mycred->number( $rank['min'] ) <= $credits && $mycred->number( $rank['max'] ) >= $credits ) {
    			$rank_id = $rank['ID'];
    			$rank_title = $rank['title'];
    			break;
    		}
    	}
    	unset( $ranks );
    
    	return $rank_title;
    }

    Then whenever you need to show the total credits gained over all time you can do something like this…

    (this is just an example I used in loop-single-reply.php to show the total points earned by the user in each bbPress forum reply)

    $mycred = mycred_get_settings();
    $balance = mycred_get_users_cred($reply_user_id);
    $spentAmount = get_user_meta($reply_user_id,  'mycred_total_spent', true );
    $totalCredits = $balance + $spentAmount;
    
    echo '<div class="user-info-detail">'.$mycred->format_creds($totalCredits).' ['.getRank($totalCredits).']</div>';
    Thread Starter chuckra

    (@chuckra)

    Thanks for replying again. Awesome support ??

    Yes, I knew the edit I did yesterday wasn’t a permanent solution. I was just trying a few things out.

    It would be great if you could make the changes suggested above. It would be nice to have a neat solution all within mycred.

    In the meantime, I came up with a solution that works for me right now. I basically use the standard rank by balance option in mycred. I then added a mycred_add filter to functions.php where I keep track of mycred_total_spent in the user meta table. In bbpress / buddypress or wherever I show the rank I just add the mycred_total_spent to the balance before displaying it. I also added a function to get the mycred rank from the points value so I can get the correct rank for the (balance + mycred_total_spent). Seems to be working how I want it now and no edits to mycred needed which is great.

    Thanks for the great plugin and also responding to my questions. Appreciate your effort.

    Thread Starter chuckra

    (@chuckra)

    Sorry for troubling you again. I edited the code as you suggested but it’s still not behaving how I would expect.

    I was able to get the correct total points to show by editing

    public function get_users_cred( $user_id = '', $type = '' ) {
    			if ( empty( $user_id ) ) return $this->zero();
    
    			if ( empty( $type ) ) $type = $this->get_cred_id();
    		//I added this line
    			$type = 'mycred_default_total';
    			$balance = get_user_meta( $user_id, $type, true );
    			if ( empty( $balance ) ) $balance = $this->zero();
    
    ...

    But then I realised that this will not work because

    – Users can transfer points back and forth between each other as a way of generating free points.

    – When forum posts are trashed, points are not deducted from mycred_default_total which means that users could post lots of junk replies and not lose those points when their posts were trashed.

    – The leaderboard widget seems to use some other function to calculate the balance because even with the edit above it always shows the balance (not total points earned).

    I don’t think it’s a case of only adding the +ve points. In my case to calculate the proper cumulative total, I would need to add up all points (+ve and -ve) apart from points used to pay for content.

    Basically I’m building an educational site where users are rewarded with points for getting involved (forum posts, adding comments, submitting content etc). They can then use those points to access educational resources. I want to show the total points earned so people can see which users have contributed the most to the site.

    Hope this makes sense. Maybe I am misunderstanding something.

    Thread Starter chuckra

    (@chuckra)

    Thanks for getting back to me. I understand that’s how it should work but that’s not what’s happening for me.

    I set up two ranks for testing this out

    0-20 newbie
    21-9999999 fledgling

    I had a user on 26 points. His rank was fledgling which is what I expected. Then I bought access to a post for 20 points. His balance went down to 6 but also his rank changed from fledgling to newbie. If it was working as explained above then surely his rank should have stayed as fledgling?

    I double checked that I have the option ticked for

    “Users are ranked according to the total amount of yebo credits they have accumulated.”

    Does it make any difference if the user above got his points from another user using the transfer widget?

    Sorry to be a nuisance. I know it’s hard to debug without seeing my setup. Any other ideas of things to try?

Viewing 15 replies - 1 through 15 (of 15 total)