Support » Plugin: Charitable - Donation Plugin » Extending a Charitable Class

  • rdosza

    (@rdosza)


    Hi Eric,

    I am trying to extend a Charitable class (both in functions.php and in a plugin) without success. My attempt was:

    
    Class Custom_Charitable_Campaign extends Charitable_Campaign {
    	public function get_donation_summary() {
                    //custom get_donation_summary function
    	}
    	public function custom_function() {
                    //my custom function
    	}
    }
    $new_Custom_Charitable_Campaign = new Custom_Charitable_Campaign($post);
    

    Could you tell me what I am doing wrong?

    Thanks in advance!

    • This topic was modified 3 years ago by  rdosza.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Eric Daams

    (@ericdaams)

    The code looks ok to me. Where isn’t this working as you’d expect?

    Cheers,
    Eric

    rdosza

    (@rdosza)

    When I put it into functions.php, changes do not reflect. When I put it in a custom plugin, I receive a fatal error message: “Fatal error: Class ‘Charitable_Campaign’ not found in /…/wp-content/plugins/charitable-custom/charitable-custom.php on line 15”

    For test purpose, I am just changing “donated” for “raised”. Here goes the code:

    
    	Class Custom_Charitable_Campaign extends Charitable_Campaign {
    		public function get_donation_summary() {
    			$currency_helper = charitable_get_currency_helper();
    
    			if ( $this->has_goal() ) {
    				$ret = sprintf( _x( '%s RAISED of %s goal', 'amount donated of goal', 'charitable' ),
    					'<span class="amount">' . $currency_helper->get_monetary_amount( $this->get_donated_amount() ) . '</span>',
    					'<span class="goal-amount">' . $currency_helper->get_monetary_amount( $this->get( 'goal' ) ) . '</span>'
    				);
    			} else {
    				$ret = sprintf( _x( '%s donated', 'amount donated', 'charitable' ),
    					'<span class="amount">' . $currency_helper->get_monetary_amount( $this->get_donated_amount() ) . '</span>'
    				);
    			}
    
    			return apply_filters( 'charitable_donation_summary', $ret, $this );
    		}
    	}
    	$new_Custom_Charitable_Campaign = new Custom_Charitable_Campaign($post);
    
    rdosza

    (@rdosza)

    Sorry, in a plugin the fatal error is due the fact that I forgot the “require_once”. Yet, when fixed, changes also do not reflect.

    Plugin Author Eric Daams

    (@ericdaams)

    Creating this class on its own won’t change the text; you would need to change the class that is used when displaying the text, and that’s a bit more complicated.

    If all you want to do is change the text, I’d recommend using Loco Translate instead: https://en-au.wordpress.org/plugins/loco-translate/

    It’s a translation plugin, but gives you an easy way to change the default phrases/words used in Charitable.

    Cheers,
    Eric

    rdosza

    (@rdosza)

    Thanks but changing text was just an example for testing purpose. Even this particular class serves only as example for testing purposes. I just wanted to try to create some extensions but simply do not understand what I am doing wrong and why I am not able extend Charitable_Campaign class.

    Plugin Author Eric Daams

    (@ericdaams)

    Sorry, I guess I’m struggling to understand what you are trying to achieve. Why do you want to create a subclass of Charitable_Campaign? What do you want to do with it and where do you want to integrate it?

    cheers,
    eric

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Extending a Charitable Class’ is closed to new replies.