Tips For Writing Custom Code For Charitable

One reason Charitable is one of the best WordPress plugins to run campaigns and accept donations is it’s flexibility and ability to allow others to customize various key aspects of the experience – including emails, campaign details, and the donation form. Some of this flexibility exists in the “hooks and filters” that Charitable has in it’s code that are available to WordPress developers. Through these, a developer can customize a site to:

— Display a custom field on the donation field via the Donations Field API.
— Add new email tags or modify existing ones with the Email Fields API.
— Customizations to addons such as the Ambassador addon and the Annual Receipts addon.

Code for a WordPress plugin can be written in a number of ways and in different places: some code can be placed in the “functions.php” file of the active WordPress theme, some are written into a plugin (that can be activated and deactivated even if the user keeps the same theme), and (what is becoming increasing popular) code can be hosted in a code snippets plugin.

No matter where the code lives, there are best practices that WordPress developers and coders should be using to ensure the website it’s running in stays secure and doesn’t fall to errors. The following isn’t a complete nor in depth guide, but general reminders for those writing code OR accepting code from developers to insert into their website – especially if that code relies on a third party plugin (like Charitable). 

Plugin File Preferred

If possible try to place custom code in it’s OWN WordPress plugin. This makes it easier to keep the code in place if you switch your WordPress theme and it also allows you to easily turn the plugin containing the customizations on/off for debugging purposes. There are many posts and tutorials on the web about creating a simple WordPress plugin such as this one.

Don’t Assume, Always Check

It’s important for any custom code NOT TO ASSUME CHARITABLE IS ACTIVATED AND RUNNING ON YOUR WEBSITE. Why? Because if it attempts to call a function in Charitable’s core code – and the code isn’t there – an error can occur… an error that could bring down your website! Sometimes WordPress is able to put your site in “Recovery Mode” and send the site administrator an email to notify them about this error, but this isn’t always the case. Therefore, ANY code written for Charitable – regardless of it’s purpose or where the code is located – should “check” to make sure Charitable is activated and/or the function they are attempting to call exists.

Notice our first (bad!) example:

👎🏻 BAD EXAMPLE:

// Bad Example :-( Of Hooking Into Charitable

function charitable_add_donation_gateway_email_tag() {
    charitable()->donation_fields()->get_field( 'gateway_label' )->email_tag = true;
}
add_action( 'init', 'charitable_add_donation_gateway_email_tag' );

The purpose of this block of code is to make the “gateway label” something that can be added as a dynamic tag into Charitable emails. The developer above is “hooking” the function that does this WordPress’s “init” which is run every time a page is loaded on the website – no matter if it’s in the admin or the front end. Notice the function uses “charitable()”… but if this doesn’t exist PHP will throw a “fatal error” – and since the above code is loading on ANY and EVERY page load, the entire site will most likely crash without ability to log in as an admin, etc.

Again, it’s a good practice to never assume a function exists if that function is part of a plugin or theme (in other words if it’s not a part of WordPress core). Assuming the “charitable()” class exists means assuming the Charitable plugin will ALWAYS be there – but if the plugin is deactivated (by a human or by another plugin) or if the plugin is being updated… the function will not be found, and a (possible “fatal”) error would be encountered. Here’s the same function but with a simple addition:

👍🏻 GOOD EXAMPLE:

// Good Example :-) Of Hooking Into Charitable
// Checking To See If The Class Exists!

function charitable_add_donation_gateway_email_tag() {
    if ( class_exists('charitable') ) : // check for class
       charitable()->donation_fields()->get_field( 'gateway_label' )->email_tag = true;
    endif;
}
add_action( 'init', 'mysite_charitable_add_donation_gateway_email_tag' );

Notice the “if” statement that checks if the class of “charitable” exists – this is a way in PHP to safely check if the class exists (in this case it will only if Charitable is actively running on the website). If it doesn’t exist, then the code isn’t run and everyone is safe. It’s common for PHP developers to make checks like class_exists and function_exists for quick ways to ensure the code they are about to run won’t run into serious errors because something they are assuming exists doesn’t exist.

Use Unique Names For Functions

As noted in the above examples, never give your functions generic names like “update_email” because if another plugin uses that same name (current plugins or future ones you might install) then your website might suffer problems. When creating a function always start with “mywebsite_charitable_” (like the example above, replacing “mywebsite” with a reasonable length string of your website name) to ensure that you have likely created a custom name that isn’t repeated (you can also use the same “does this already exist logic” in the above step if you want to go the extra mile).

Enable WordPress Debugging and Debug Logs

For anything beyond a simple script, WordPress developers commonly like to document and log PHP warnings and errors to “catch” problems (especially if they aren’t apparently visible on the website). Charitable Support team recommends the base WP_DEBUG and WP_DEBUG_LOG functions as mentioned here in the WordPress documentation.

Using A Code Snippet Plugin?

Everything said above is applicable also to code inserted into code snippet plugins. If you have a problem with Charitable and know you are running custom code in a code snippet, you should be able to deactivate the code snippet plugin to see if this resolves the issue or helps you further troubleshoot.

Don’t Test On Production

Finally, it’s a good idea to test custom code on a staging or development environment and not live on your website. If you deactivate Charitable here as a test it’s a good “final” way to determine if your website might experience significant problems. This keeps your production environment safe and still able to accept donations. 


Remember that if you are unsure about the code you are adding to your theme, your own plugin, or code snippet plugin – consult with a developer. If you have some general questions feel free to reach out to our support team who will be happy to answer questions about any code you might be adding to your website to extend Charitable. We are here for you and to support you in extending your website to meet your needs!

We hope sharing these suggestions will give you the confidence and ensure your customizations to Charitable will continue to operate well for years to come.

Erhalten Sie kostenlose Tipps und Ressourcen direkt in Ihren Posteingang, zusammen mit über 60.000 anderen

Abonnieren Sie unseren Newsletter

Wir werden Sie nicht spammen. Wir senden nur eine E-Mail, wenn wir glauben, dass sie Ihnen wirklich hilft. Abmeldung jederzeit möglich!

Video der Woche:

Sehen Sie sich weitere Videos auf unserem YouTube-Kanal an.

Was ist neu bei Charitable

Die neuesten Updates anzeigen
🔔 Abonnieren Sie, um unsere neuesten Updates zu erhalten
📧 E-Mails abonnieren

E-Mail-Abonnement

Abonnieren Sie unseren Newsletter

Wir werden Sie nicht spammen. Wir senden nur eine E-Mail, wenn wir glauben, dass sie Ihnen wirklich hilft. Abmeldung jederzeit möglich!

GiveWP Migrationen Neu

White Glove Migrationsservice für GiveWP

Erwägen Sie den Wechsel Ihrer Spendenplattform von GiveWP zu Charitable, möchten aber nicht riskieren, Ihre Daten zu verlieren oder eine komplexe technische Einrichtung selbst vorzunehmen? Der White Glove Migrationsservice von Charitable bietet:

👥 Makellose Spenderzuordnung: Übertragen Sie Ihre gesamte Unterstützerdatenbank sicher und ohne Datenverlust.

📊 Vollständige Finanzhistorie: Bewahren Sie sorgfältig jede historische Transaktion für eine kontinuierliche, genaue Berichterstattung auf.

🔄 Nahtlose wiederkehrende Spenden: Übertragen Sie aktive Dauerabonnements sicher, ohne Ihre Einnahmen zu unterbrechen oder Ihre Spender zu zwingen, ihre Informationen zu aktualisieren.

💳 Keine Gateway-Unterbrechungen: Nutzen Sie weiterhin Stripe, PayPal oder jeden anderen mit GiveWP kompatiblen Prozessor, den Sie bereits lieben.

🚀 Experten-Technik-Setup: Lehnen Sie sich zurück, während unser Team die schwere Arbeit übernimmt, Ihre Formulare zu installieren und zu konfigurieren – außerdem erhalten qualifizierte Benutzer ein ganzes Jahr lang kostenloses Charitable Pro.

Besuchen Sie diese Seite, um mehr zu erfahren.

Automatisierung Verbesserung

📢 Neue Funktion: Automation Connect 2.0 ist da! 🚀

Sie möchten Ihre Spenden-Daten mit Tools wie Mailchimp, Slack oder Google Sheets verbinden, aber keinen Entwickler einstellen oder benutzerdefinierten Code schreiben? Charitalbes neues Automatisierungs-Addon bietet:

⚡ 17 Event-Trigger: Lösen Sie sofort Webhooks für die erste Spende eines Spenders, wiederkehrende Zahlungen oder erreichte Kampagnenmeilensteine aus.

🎯 Intelligente bedingte Logik: Verwenden Sie leistungsstarke UND/ODER-Logik über 11 Felder hinweg, um Daten nur dann zu senden, wenn sie Ihren genauen Kriterien entsprechen, z. B. Newsletter-Opt-ins.

📊 Benutzerdefinierte Payload-Steuerung: Wählen Sie aus über 80 sauberen Datenfeldern für Spender-, Spenden- und Kampagnenmetadaten, damit Ihre Apps genau das erhalten, was sie benötigen.

🚀 Vorkonfigurierte Plattform-Vorlagen: Überspringen Sie die Einrichtung von Grund auf mit fertigen Vorlagen für Zapier, Make.com, n8n, HubSpot und Slack.

🛡️ Zuverlässige Entwickler-Tools: Steuern Sie Ihre Workflows mit signierten HMAC-SHA256-Payloads, vollständigen WordPress-Filtern und automatischen Wiederholungsprotokollen.

Automatisierung Verbesserung

🔌 Charitable trifft Zapier: Verbinden Sie sich mit über 7.000 Apps und automatisieren Sie Ihre Spendenaktionen

Müde vom manuellen Kopieren von Spendeninformationen in Buchhaltungsbögen oder vom Nachverfolgen neuer Spenderanmeldungen? Bringen Sie Ihre Verwaltungsaufgaben auf Autopilot. Charitable ist jetzt offiziell auf Zapier verfügbar und bietet Ihnen eine leistungsstarke No-Code-Möglichkeit, Ihre Spendenaktionen direkt mit dem Rest Ihrer bevorzugten Tools zu verbinden.

Jede Spende, jede Spenderanmeldung und jeder Kampagnenmeilenstein kann jetzt nahtlos einen automatisierten Workflow auslösen.

Was ist neu:

♾️ Verbinden Sie sich mit über 7.000 Apps: Verknüpfen Sie Ihre Charitable-Kampagnen mit alltäglichen Softwareanwendungen wie Google Sheets, QuickBooks, Slack, Mailchimp, HubSpot, Notion, Airtable und Tausenden mehr.

⚡ 12 leistungsstarke Trigger: Erstellen Sie tiefgreifende Workflows mit intelligenten Automatisierungs-Triggern, die den gesamten Spendenlebenszyklus abdecken – einschließlich Neue Spende, Neuer Spender, Abonnement gekündigt und Kampagnenziel erreicht.

📋 Vorkonfigurierte Aktionsvorlagen: Beginnen Sie in drei Minuten oder weniger mit unseren vorgefertigten Vorlagenkombinationen, wie z. B. dem automatischen Protokollieren neuer Spenden direkt in ein Google Sheet oder dem Auslösen benutzerdefinierter Spender-Willkommens-E-Mails über Gmail.

🚫 Kein Code erforderlich: Keine komplexen Webhooks oder benutzerdefinierten PHP-Skripte erforderlich. Wählen Sie einfach Ihren Trigger, wählen Sie Ihre App, ordnen Sie Ihre Felder zu und lassen Sie Zapier die Hauptarbeit erledigen.

Bereit, Stunden an Verwaltungszeit zu sparen? Holen Sie sich Charitable Pro mit dem Automation Connect Addon noch heute und starten Sie Ihren ersten Zap!

Verbesserung Zahlungen

🚀 Einführung von PayPal Commerce: Eine Verbindung, sechs Spendenmöglichkeiten

Spender erwarten moderne, flexible Zahlungsoptionen, wenn sie eine Sache unterstützen. Wenn sie ihre bevorzugte Methode nicht auf ihrem Spendenformular sehen, verschwinden sie oft ohne ein Wort. Mit PayPal Commerce bringen wir ein komplett modernisiertes Checkout-Erlebnis direkt in Ihre Kampagnen.

Genießen Sie eine einzige Integration, die Ihre Formulare verbessert, das Spenden nahtlos gestaltet und Ihnen hilft, jede einzelne Spende zu erfassen.

Was ist neu:

🔌 Ein-Klick-Verbindung: Überspringen Sie unübersichtliche API-Schlüssel und Entwicklerdokumentationen. Klicken Sie einfach auf „Mit PayPal verbinden“, melden Sie sich bei Ihrem Geschäftskonto an und Ihr modernes Formular ist in weniger als fünf Minuten live.

💳 Sechs Spendenmöglichkeiten: Bieten Sie Ihren Unterstützern sofortigen Zugriff auf PayPal-Guthaben, Venmo (US), „Später bezahlen“-Finanzierung, wichtige Kredit-/Debitkarten, Apple Pay (Safari) und Google Pay (Chrome) – alles über dasselbe Formular.

🔄 Flexible wiederkehrende Spenden: Unterstützt vollständig monatliche Spenden. Wählen Sie zwischen der PayPal-Abonnement-API (automatisch von PayPal verwaltet) oder Vault + Cron (sicher direkt auf Ihrer Website verwaltet).

💬 Freundliche Fehlerbehebung: Keine verwirrenden Browser-Warnungen mehr. Wenn eine Zahlung abgelehnt wird, sehen Spender klare, Inline-Nachrichten, die sie anleiten, wie sie das Problem beheben und ihre Spende abschließen können.

Bereit für PayPal, modernisiert? Aktualisieren Sie auf Charitable Pro 1.8.15+ (oder Charitable Lite 1.8.11+) und verbinden Sie Ihr Konto noch heute!

Kampagnen Neu

⏳ Kampagnen-Countdown: Steigern Sie die Dringlichkeit und erhöhen Sie die Spenden

Dringlichkeit ist eines der mächtigsten Werkzeuge im Fundraising! Lernen Sie den Kampagnen-Countdown kennen – einen Live-Echtzeit-Timer, der Prokrastination in sofortige Großzügigkeit umwandelt.

campaign_countdown_animation

Was ist neu:

⏱️ Live-Echtzeit-Dringlichkeit: Verfolgen Sie Tage, Stunden, Minuten und Sekunden bis zur Frist Ihrer Kampagne mit live aktualisierten visuellen Countdowns.

🎨 Auf Ihren Look zugeschnitten: Wählen Sie zwischen umrandeten Kacheln im Box-Stil oder einer sauberen, einzeiligen Inline-Anzeige. Passen Sie Ihr Design sofort mit Schriftart- und tiefen Farbkontrollen an.

🛠️ Platzieren Sie es überall: Fügen Sie den Countdown überall ein, wo Sie möchten, mit dem Kampagnen-Builder-Feld, einem dedizierten Gutenberg-Block oder einem einfachen Shortcode.

🚨 Intelligente Ablaufaktionen: Volle Kontrolle über den Endzustand – wählen Sie, ob der Timer automatisch durch eine benutzerdefinierte Nachricht ersetzt, auf Null eingefroren und mehr werden soll.