GiveWP Shortcodes

Below, you’ll find a detailed guide on how to add the GiveWP Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Give Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the GiveWP Plugin and the shortcodes it provides:

Plugin Icon
GiveWP – Donation Plugin and Fundraising Platform

"GiveWP – Donation Plugin and Fundraising Platform is a comprehensive solution for managing donations and fundraising campaigns on your WordPress site. Simplify donor management and enhance fundraising efforts with GiveWP."

★★★★☆ (607) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [give_donor_wall]
  • [donation_history]
  • [give_form]
  • [give_goal]
  • [give_login]
  • [give_register]
  • [give_receipt]
  • [give_profile_editor]
  • [give_totals]
  • [give_form_grid]
  • [give_donor_dashboard]

GiveWP [give_donor_wall] Shortcode

The Give Donor Wall shortcode is designed to display a list of donors on your WordPress site. It retrieves donation data and generates an HTML list of donors. This shortcode uses the ‘give_donor_wall’ function to parse attributes, fetch donation data, and render a donor wall. It also includes a ‘load more’ button for pagination.

Shortcode: [give_donor_wall]

Parameters

Here is a list of all possible give_donor_wall shortcode parameters and attributes:

  • form_id – Specifies the ID of the donation form
  • only_donor_html – If set and AJAX is active, returns only donor HTML
  • paged – Used for pagination, increases by 1 with each page load
  • loadmore_text – Customizes the text on the “load more” button
  • columns – Sets the number of columns in the grid layout

Examples and Usage

Basic example – The basic usage of the ‘give_donor_wall’ shortcode involves calling the shortcode with the desired form_id as an attribute. This will render the donor wall associated with the specified form.

[give_donor_wall form_id=1 /]

Advanced examples

Displaying the donor wall with pagination. Here, the ‘paged’ attribute is used to specify the page number of the donations to display, and the ‘per_page’ attribute is used to specify the number of donations to display per page.

[give_donor_wall form_id=1 paged=2 per_page=10 /]

Displaying the donor wall with a ‘load more’ button. In this example, the ‘loadmore_text’ attribute is used to specify the text for the ‘load more’ button, which loads more donations when clicked.

[give_donor_wall form_id=1 loadmore_text="Load More Donations" /]

Displaying the donor wall with a specific number of columns. Here, the ‘columns’ attribute is used to specify the number of columns in which the donations should be displayed.

[give_donor_wall form_id=1 columns=3 /]

Displaying only the donor HTML. In this example, the ‘only_donor_html’ attribute is set to true, which means that only the donor HTML will be returned, without any additional markup.

[give_donor_wall form_id=1 only_donor_html=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_donor_wall] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_donor_wall', [ $this, 'render_shortcode' ] );

Shortcode PHP function:

function render_shortcode( $atts ) {

		$give_settings = give_get_settings();

		$atts      = $this->parse_atts( $atts );

        _give_redirect_form_id($atts['form_id']);

		$donations = $this->get_donation_data( $atts );
		$html      = '';

		if ( $donations ) {

			ob_start();

			foreach ( $donations as $donation ) {
                $donor = new Give_Donor($donation['_give_payment_donor_id']);
                // Give/templates/shortcode-donor-wall.php.
                give_get_template(
                    'shortcode-donor-wall',
                    [
                        $donation,
                        $give_settings,
                        $atts,
                        $donor
                    ]
                );
            }

			$html = ob_get_clean();

			// Return only donor html.
			if (
				isset( $atts['only_donor_html'] )
				&& wp_doing_ajax()
				&& $atts['only_donor_html']
			) {
				return $html;
			}
		}

		$temp_atts          = $atts;
		$temp_atts['paged'] = $atts['paged'] + 1;

		$more_btn_html = sprintf(
			'<input type="hidden" class="give-donor-wall-shortcode-attrs" data-shortcode="%s" data-nonce="%s">',
			rawurlencode( http_build_query( $atts ) ),
            wp_create_nonce( 'givewp-donor-wall-more' )
		);

		if ( $this->has_donations( $temp_atts ) ) {
			$more_btn_html .= sprintf(
				'<button class="give-donor__load_more give-button-with-loader"><span class="give-loading-animation"></span>%1$s</button>',
				$atts['loadmore_text']
			);
		}

		$html = $html
			? sprintf(
				'<div class="give-wrap give-grid-ie-utility"><div class="give-grid give-grid--%1$s">%2$s</div>%3$s</div>',
				esc_attr( $atts['columns'] ),
				$html,
				$more_btn_html
			)
			: '';

		return $html;
	}

Code file location:

give/give/includes/donors/class-give-donor-wall.php

Give [donation_history] Shortcode

The Give Donation History shortcode allows users to view their donation history. It displays details such as the donation ID, date, amount, and a link to the receipt. The shortcode can be customized to hide or display certain details. It also includes a functionality to return to the receipt from the confirmation page. Users must be logged in to view their donation history, and an option for email-based access is also available.

Shortcode: [donation_history]

Parameters

Here is a list of all possible donation_history shortcode parameters and attributes:

  • id – Determines whether to show the unique identifier for each donation.
  • date – Specifies if the date of each donation should be displayed.
  • donor – Controls whether to display the donor’s name for each donation.
  • amount – Decides if the amount of each donation should be shown.
  • status – Defines if the status of each donation is to be displayed.
  • payment_method – Decides whether to show the payment method used for each donation.

Examples and Usage

Basic example – Show the donation history with default parameters.

[donation_history /]

Advanced examples

Display donation history with specific parameters. In this case, the shortcode will display the donation history with the donor and payment method, but without the donation date and status.

[donation_history id=true donor=true amount=true payment_method=true date=false status=false /]

Display donation history with content. This shortcode will display the donation history and the content within the shortcode. The content will be processed by other shortcodes.

[donation_history id=true amount=true]Your custom content here.[/donation_history]

PHP Function Code

In case you have difficulties debugging what causing issues with [donation_history] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'donation_history', 'give_donation_history' );

Shortcode PHP function:

function give_donation_history( $atts, $content = false ) {

	$donation_history_args = shortcode_atts(
		[
			'id'             => true,
			'date'           => true,
			'donor'          => false,
			'amount'         => true,
			'status'         => false,
			'payment_method' => false,
		],
		$atts,
		'donation_history'
	);

	// Always show receipt link.
	$donation_history_args['details'] = true;

	// Set Donation History Shortcode Arguments in session variable.
	Give()->session->set( 'give_donation_history_args', $donation_history_args );

	$get_data = give_clean( filter_input_array( INPUT_GET ) );

	// If payment_key query arg exists, return receipt instead of donation history.
	if (
		! empty( $get_data['donation_id'] ) ||
		(
			! empty( $get_data['action'] ) &&
			'view_in_browser' === $get_data['action']
		)
	) {
		ob_start();

		echo do_shortcode( ShortcodeUtils::getReceiptShortcodeFromConfirmationPage() );

		// Display donation history link only if Receipt Access Session is available.
		if ( give_get_receipt_session() || is_user_logged_in() ) {
			echo sprintf(
				'<a href="%s">%s</a>',
				esc_url($_SERVER['HTTP_REFERER'] ),
				__( '&laquo; Return to All Donations', 'give' )
			);
		}

		return ob_get_clean();
	}

	$email_access = give_get_option( 'email_access' );

	ob_start();

	/**
	 * Determine access
	 *
	 * A. Check if a user is logged in or does a session exists.
	 * B. Does an email-access token exist?
	 */
	if (
		is_user_logged_in()
		|| false !== Give()->session->get_session_expiration()
		|| ( give_is_setting_enabled( $email_access ) && Give()->email_access->token_exists )
		|| true === give_get_history_session()
	) {
		give_get_template_part( 'history', 'donations' );

		if ( ! empty( $content ) ) {
			echo do_shortcode( $content );
		}
	} elseif ( give_is_setting_enabled( $email_access ) ) {
		// Is Email-based access enabled?
		give_get_template_part( 'email', 'login-form' );

	} else {

		echo apply_filters( 'give_donation_history_nonuser_message', Give_Notices::print_frontend_notice( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) );
		echo do_shortcode( '[give_login]' );
	}

	/**
	 * Filter to modify donation history HTMl
	 *
	 * @since 2.1
	 *
	 * @param string HTML content
	 * @param array  $atts
	 * @param string $content content pass between enclose content
	 *
	 * @return string HTML content
	 */
	return apply_filters( 'give_donation_history_shortcode_html', ob_get_clean(), $atts, $content );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_form] Shortcode

The ‘give_form’ shortcode from Give plugin is used to display a donation form. It customizes the form based on attributes like ‘show_title’ and ‘show_goal’. It also allows form customization with ‘display_style’, ‘continue_button_title’, and ‘button_color’. It supports both legacy and iframe views for form display. Shortcode: [give_form_shortcode]

Shortcode: [give_form]

Parameters

Here is a list of all possible give_form shortcode parameters and attributes:

  • id – Unique identifier for the donation form
  • show_title – Control to show or hide the form title
  • show_goal – Toggle to display or hide the donation goal
  • display_style – Determines the style of form display
  • continue_button_title – Customizes the title of the continue button
  • button_color – Sets the color of the donation form button

Examples and Usage

Basic example – A simple implementation of the ‘give_form’ shortcode. It only requires the form id to be specified, which in this case is 1.

[give_form id=1 /]

Advanced examples

Implementing the ‘give_form’ shortcode with additional attributes. Here we are specifying the form id as 1, and also setting the ‘show_title’ and ‘show_goal’ attributes to true. This will display the title and goal of the form on the page.

[give_form id=1 show_title=true show_goal=true /]

Another advanced usage of the ‘give_form’ shortcode. In this example, we are setting the ‘display_style’ attribute to ‘button’, and also specifying the ‘continue_button_title’ and ‘button_color’. This will change the display style of the form to a button, and also change the title and color of the continue button.

[give_form id=1 display_style=button continue_button_title="Donate Now" button_color="#FF0000" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_form', 'give_form_shortcode' );

Shortcode PHP function:

function give_form_shortcode( $atts ) {
	$atts = shortcode_atts( give_get_default_form_shortcode_args(), $atts, 'give_form' );

	// Convert string to bool.
	$atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN );
	$atts['show_goal']  = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN );

	// Set form id.
	$atts['id'] = $atts['id'] ?: FrontendFormTemplateUtils::getFormId();
	$formId     = absint( $atts['id'] );

    _give_redirect_form_id($formId, $atts['id']);

    // Short-circuit the shortcode output if the filter returns a non-empty string.
    $output = apply_filters('givewp_form_shortcode_output', '', $atts);

    if ($output) {
        return $output;
    }

	// Fetch the Give Form.
	ob_start();

	if ( ! FormUtils::isLegacyForm( $formId ) ) {
		$showIframeInModal = 'button' === $atts['display_style'];
		$iframeView        = new IframeView();

		ConfirmDonation::storePostedDataInDonationSession();

		echo $iframeView->setFormId( $formId )
				   ->showInModal( $showIframeInModal )
				   ->setButtonTitle( $atts['continue_button_title'] )
				   ->setButtonColor( $atts['button_color'] )
				   ->render();
	} else {
		give_get_donation_form( $atts );
	}

	$final_output = ob_get_clean();

	return apply_filters( 'give_donate_form', $final_output, $atts );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_goal] Shortcode

The ‘give_goal’ shortcode is designed to display the donation goal progress of a specific GiveWP form. It takes attributes such as ‘id’, ‘show_text’, ‘show_bar’, and ‘color’ to customize the output. It first checks if the form ID is provided and if the form has goals enabled. If these conditions are met, it outputs the goal progress.

Shortcode: [give_goal]

Parameters

Here is a list of all possible give_goal shortcode parameters and attributes:

  • id – Unique identifier of the donation form
  • show_text – Determines if the goal’s text is displayed
  • show_bar – Decides if the progress bar is visible
  • color – Defines the color of the progress bar

Examples and Usage

Basic example – Displays the progress of a donation goal by referencing its ID.

[give_goal id=1 /]

Advanced examples

Shows the progress of a donation goal with its ID, but without the text and progress bar.

[give_goal id=1 show_text=false show_bar=false /]

Displays the progress of a donation goal with its ID and a custom color for the progress bar.

[give_goal id=1 color="#ff0000" /]

Shows the progress of a donation goal by referencing its ID, with the text but without the progress bar, and a custom color.

[give_goal id=1 show_bar=false color="#00ff00" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_goal] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_goal', 'give_goal_shortcode' );

Shortcode PHP function:

function give_goal_shortcode( $atts ) {
	$atts = shortcode_atts(
		[
			'id'        => '',
			'show_text' => true,
			'show_bar'  => true,
			'color'		=> '',
		],
		$atts,
		'give_goal'
	);

    _give_redirect_form_id($atts['id']);

	// get the Give Form.
	ob_start();

	// Sanity check 1: ensure there is an ID Provided.
	if ( empty( $atts['id'] ) ) {
		Give_Notices::print_frontend_notice( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true );
	}

	// Sanity check 2: Check the form even has Goals enabled.
	if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) {

		Give_Notices::print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true );
	} else {
		// Passed all sanity checks: output Goal.
		give_show_goal_progress( $atts['id'], $atts );
	}

	$final_output = ob_get_clean();

	return apply_filters( 'give_goal_shortcode_output', $final_output, $atts );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_login] Shortcode

The ‘give_login’ shortcode is used to create a login form with optional redirect attributes. Upon successful login, the ‘login-redirect’ attribute redirects the user to a specified page. If ‘login-redirect’ isn’t set, it checks the ‘redirect’ attribute. The ‘logout-redirect’ attribute functions similarly post-logout.

Shortcode: [give_login]

Parameters

Here is a list of all possible give_login shortcode parameters and attributes:

  • redirect – specifies the URL to redirect after login
  • login-redirect – URL to redirect after successful login
  • logout-redirect – URL to redirect after successful logout

Examples and Usage

Basic example – A straightforward usage of the ‘give_login’ shortcode without any attributes. This will display the default login form on your page or post.

[give_login /]

Advanced examples

Utilizing the ‘login-redirect’ attribute, you can specify the page to which the user will be redirected after a successful login. In this example, the user will be redirected to a page with the slug ‘dashboard’ after logging in.

[give_login login-redirect="dashboard" /]

Here’s an example where both ‘login-redirect’ and ‘logout-redirect’ attributes are used. After a successful login, the user will be redirected to a page with the slug ‘dashboard’. Similarly, once the user logs out, they will be redirected to a page with the slug ‘homepage’.

[give_login login-redirect="dashboard" logout-redirect="homepage" /]

Lastly, an example using the ‘redirect’ attribute. This attribute provides backward compatibility. If ‘login-redirect’ is not specified, the ‘redirect’ attribute will be used. In this example, the user will be redirected to a page with the slug ‘my-account’ after logging in.

[give_login redirect="my-account" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_login', 'give_login_form_shortcode' );

Shortcode PHP function:

function give_login_form_shortcode( $atts ) {

	$atts = shortcode_atts(
		[
			// Add backward compatibility for redirect attribute.
			'redirect'        => '',
			'login-redirect'  => '',
			'logout-redirect' => '',
		],
		$atts,
		'give_login'
	);

	// Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute.
	$atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect'] ) ? $atts['redirect'] : '' );

	return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_register] Shortcode

The Give Register shortcode is a tool that enables user registration. It uses the ‘give_register_form_shortcode’ function to create a registration form. This shortcode accepts the ‘redirect’ attribute, which determines the page users are directed to after registration. By using ‘give_register_form’, it ensures seamless user registration.

Shortcode: [give_register]

Parameters

Here is a list of all possible give_register shortcode parameters and attributes:

  • redirect – URL where users are sent after successful registration

Examples and Usage

Basic example – Utilize the given shortcode to display the registration form without any redirection after form submission.

[give_register /]

Advanced examples

Embed the registration form with a specific redirection URL after form submission. Replace ‘http://example.com’ with your desired URL.

[give_register redirect='http://example.com' /]

Using the shortcode to display the registration form with a redirection to a relative URL on the same website. Replace ‘/thank-you’ with your desired relative URL.

[give_register redirect='/thank-you' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_register] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_register', 'give_register_form_shortcode' );

Shortcode PHP function:

function give_register_form_shortcode( $atts ) {
	$atts = shortcode_atts(
		[
			'redirect' => '',
		],
		$atts,
		'give_register'
	);

	return give_register_form( $atts['redirect'] );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_receipt] Shortcode

The ‘give_receipt’ shortcode is used to display a donation receipt. It fetches the donation id, donation details, and displays a placeholder while loading the receipt.

Shortcode: [give_receipt]

Parameters

Here is a list of all possible give_receipt shortcode parameters and attributes:

  • error – Message displayed when donation ID is missing.
  • price – Boolean parameter to show/hide donation amount.
  • donor – Boolean parameter to show/hide donor information.
  • date – Boolean parameter to show/hide donation date.
  • payment_method – Boolean parameter to show/hide payment method.
  • payment_id – Boolean parameter to show/hide unique payment ID.
  • payment_status – Boolean parameter to show/hide payment status.
  • company_name – Boolean parameter to show/hide donor’s company name.
  • status_notice – Boolean parameter to show/hide status notice.
  • id – Unique identifier of the donation.

Examples and Usage

Basic example – Display a basic donation receipt with default parameters

[give_receipt /]

Advanced examples

Display a donation receipt with specific parameters such as price, donor, date, and payment method.

[give_receipt price="true" donor="true" date="true" payment_method="true" /]

Display a donation receipt with a custom error message and without showing the company name.

[give_receipt error="Custom error message" company_name="false" /]

Display a donation receipt with specific parameters and also showing the payment status and company name.

[give_receipt price="true" donor="true" date="true" payment_method="true" payment_status="true" company_name="true" /]

Display a donation receipt without showing the status notice.

[give_receipt status_notice="false" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_receipt] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_receipt', 'give_receipt_shortcode' );

Shortcode PHP function:

function give_receipt_shortcode( $atts ) {

	global $give_receipt_args;

	$give_receipt_args = shortcode_atts(
		[
			'error'          => __( 'You are missing the donation id to view this donation receipt.', 'give' ),
			'price'          => true,
			'donor'          => true,
			'date'           => true,
			'payment_method' => true,
			'payment_id'     => true,
			'payment_status' => false,
			'company_name'   => false,
			'status_notice'  => true,
		],
		$atts,
		'give_receipt'
	);

	ob_start();

	$donation_id  = false;
	$receipt_type = false;
	$get_data     = give_clean( filter_input_array( INPUT_GET ) );
	$session      = give_get_purchase_session();

	if ( ! empty( $get_data['donation_id'] ) ) {
		$donation_id = $get_data['donation_id'];
	} elseif ( ! empty( $get_data['action'] ) && 'view_in_browser' === $get_data['action'] ) {
		$receipt_type = 'view_in_browser';
		$donation_id  = $get_data['_give_hash'];
	} elseif ( isset( $session['donation_id'] ) ) {
		$donation_id = $session['donation_id'];
	} elseif ( ! empty( $give_receipt_args['id'] ) ) {
		$donation_id = $give_receipt_args['id'];
	}

	// Display donation receipt placeholder while loading receipt via AJAX.
	if ( ! wp_doing_ajax() ) {
		give_get_template_part( 'receipt/placeholder' );

		return sprintf(
			'<div id="give-receipt" data-shortcode="%1$s" data-receipt-type="%2$s" data-donation-key="%3$s" >%4$s</div>',
			htmlspecialchars( wp_json_encode( $give_receipt_args ) ),
			$receipt_type,
			$donation_id,
			ob_get_clean()
		);
	}

	return give_display_donation_receipt( $atts );
}

Code file location:

give/give/includes/shortcodes.php

Give [give_profile_editor] Shortcode

The Give Profile Editor shortcode is designed to manage user profiles in WordPress. It restricts access if the donor and user profiles are disconnected. This shortcode displays an error message if the donor and user profiles are disconnected, prompting the user to contact the site administrator. It then returns the profile editor template part. This shortcode is particularly useful for websites that have a donation system, ensuring smooth interaction between donors and the website.

Shortcode: [give_profile_editor]

Examples and Usage

Basic example – A standard usage of the ‘give_profile_editor’ shortcode without any additional parameters.

[give_profile_editor /]

Advanced examples

Using the shortcode to display a specific donor’s profile editor by referencing the user’s ID. This usage is useful when you want to display a certain donor’s profile editor on a specific page.

[give_profile_editor id=3 /]

Using the shortcode to display a specific donor’s profile editor by referencing the user’s username. This usage is useful when you want to display a certain donor’s profile editor and you only know their username.

[give_profile_editor username="donor1" /]

Please note that these advanced examples are hypothetical. The actual functionality of the shortcode depends on how the ‘give_profile_editor_shortcode’ function is defined and how it handles attributes.

PHP Function Code

In case you have difficulties debugging what causing issues with [give_profile_editor] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' );

Shortcode PHP function:

function give_profile_editor_shortcode( $atts ) {

	ob_start();

	// Restrict access to donor profile, if donor and user are disconnected.
	$is_donor_disconnected = get_user_meta( get_current_user_id(), '_give_is_donor_disconnected', true );
	if ( is_user_logged_in() && $is_donor_disconnected ) {
		Give_Notices::print_frontend_notice( __( 'Your Donor and User profile are no longer connected. Please contact the site administrator.', 'give' ), true, 'error' );

		return false;
	}

	give_get_template_part( 'shortcode', 'profile-editor' );

	return ob_get_clean();
}

Code file location:

give/give/includes/shortcodes.php

Give [give_totals] Shortcode

The Give Totals shortcode is a powerful tool that provides a summary of total donations raised. It allows customization of the total goal, categories, tags, and the donation message. It also provides an option to include a progress bar and a donation link. This shortcode dynamically calculates the total donations made and displays the results in a user-friendly format.

Shortcode: [give_totals]

Parameters

Here is a list of all possible give_totals shortcode parameters and attributes:

  • total_goal – the total amount you aim to raise
  • ids – identifiers for specific forms to include in the total
  • cats – identifiers for specific categories of forms to include in the total
  • tags – identifiers for specific tags of forms to include in the total
  • message – the message to display, which includes placeholders for the total and total goal
  • link – a URL to direct donors to when they click the ‘Donate Now’ link
  • link_text – the text to display for the ‘Donate Now’ link
  • progress_bar – a boolean value indicating whether to display a progress bar

Examples and Usage

Basic example – Display the total amount raised for a campaign using the ‘give_totals’ shortcode. This will display a message indicating the total amount raised so far.

[give_totals total_goal=10000]

Advanced examples

Displaying the total amount raised for specific forms by referencing their IDs. This example uses the ‘ids’ parameter to specify which forms to include in the total.

[give_totals total_goal=10000 ids="1,2,3"]

Displaying the total amount raised for forms that belong to specific categories or tags. This example uses the ‘cats’ and ‘tags’ parameters to specify which categories or tags to include in the total.

[give_totals total_goal=10000 cats="charity,education" tags="donation,help"]

Displaying the total amount raised with a custom message and a donation link. This example uses the ‘message’ and ‘link’ parameters to customize the message and provide a link for donations.

[give_totals total_goal=10000 message="We have raised {total} towards our goal of {total_goal}. Help us reach our goal!" link="http://example.com/donate" link_text="Donate Now"]

Displaying the total amount raised with a progress bar. This example uses the ‘progress_bar’ parameter to display a progress bar indicating how close the campaign is to reaching its goal.

[give_totals total_goal=10000 progress_bar=true]

PHP Function Code

In case you have difficulties debugging what causing issues with [give_totals] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_totals', 'give_totals_shortcode' );

Shortcode PHP function:

function give_totals_shortcode( $atts ) {
	$total = get_option( 'give_earnings_total', false );

	$message = apply_filters( 'give_totals_message', __( 'Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give' ) );

	$atts = shortcode_atts(
		[
			'total_goal'   => 0, // integer.
			'ids'          => 0, // integer|array.
			'cats'         => 0, // integer|array.
			'tags'         => 0, // integer|array.
			'message'      => $message,
			'link'         => '', // URL.
			'link_text'    => __( 'Donate Now', 'give' ), // string,
			'progress_bar' => true, // boolean.
		],
		$atts,
		'give_totals'
	);

	// Total Goal.
	$total_goal = give_maybe_sanitize_amount( $atts['total_goal'] );

	/**
	 * Give Action fire before the shortcode is rendering is started.
	 *
	 * @since 2.1.4
	 *
	 * @param array $atts shortcode attribute.
	 */
	do_action( 'give_totals_goal_shortcode_before_render', $atts );

	// Build query based on cat, tag and Form ids.
	if ( ! empty( $atts['cats'] ) || ! empty( $atts['tags'] ) || ! empty( $atts['ids'] ) ) {

		$form_ids = [];
		if ( ! empty( $atts['ids'] ) ) {
			$form_ids = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) );
		}

        array_walk($form_ids, '_give_redirect_form_id');

		/**
		 * Filter to modify WP Query for Total Goal.
		 *
		 * @since 2.1.4
		 *
		 * @param array WP query argument for Total Goal.
		 */
		$form_args = [
			'post_type'      => 'give_forms',
			'post_status'    => 'publish',
			'post__in'       => $form_ids,
			'posts_per_page' => - 1,
			'fields'         => 'ids',
			'tax_query'      => [
				'relation' => 'AND',
			],
		];

		if ( ! empty( $atts['cats'] ) ) {
			$cats                     = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) );
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_category',
				'terms'    => $cats,
			];
		}

		if ( ! empty( $atts['tags'] ) ) {
			$tags                     = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) );
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_tag',
				'terms'    => $tags,
			];
		}

		/**
		 * Filter to modify WP Query for Total Goal.
		 *
		 * @since 2.1.4
		 *
		 * @param array $form_args WP query argument for Total Goal.
		 *
		 * @return array $form_args WP query argument for Total Goal.
		 */
		$form_args = (array) apply_filters( 'give_totals_goal_shortcode_query_args', $form_args );

		$forms = new WP_Query( $form_args );

		if ( isset( $forms->posts ) ) {
			$total = 0;
			foreach ( $forms->posts as $post ) {
				$form_earning = give_get_meta( $post, '_give_form_earnings', true );
				$form_earning = ! empty( $form_earning ) ? $form_earning : 0;

				/**
				 * Update Form earnings.
				 *
				 * @since 2.1
				 *
				 * @param int    $post         Form ID.
				 * @param string $form_earning Total earning of Form.
				 * @param array $atts shortcode attributes.
				 */
				$total += apply_filters( 'give_totals_form_earning', $form_earning, $post, $atts );
			}
		}
	} // End if().

	// Append link with text.
	$donate_link = '';
	if ( ! empty( $atts['link'] ) ) {
		$donate_link = sprintf( ' <a class="give-totals-text-link" href="%1$s">%2$s</a>', esc_url( $atts['link'] ), esc_html( $atts['link_text'] ) );
	}

	// Replace {total} in message.
	$message = str_replace(
		'{total}',
		give_currency_filter(
			give_format_amount(
				$total,
				[ 'sanitize' => false ]
			)
		),
		esc_html( $atts['message'] )
	);

	// Replace {total_goal} in message.
	$message = str_replace(
		'{total_goal}',
		give_currency_filter(
			give_format_amount(
				$total_goal,
				[ 'sanitize' => true ]
			)
		),
		$message
	);

	/**
	 * Update Give totals shortcode output.
	 *
	 * @since 2.1
	 *
	 * @param string $message Shortcode Message.
	 * @param array $atts ShortCode attributes.
	 */
	$message = apply_filters( 'give_totals_shortcode_message', $message, $atts );

	ob_start();
	?>
	<div class="give-totals-shortcode-wrap">
		<?php
		// Show Progress Bar if progress_bar set true.
		$show_progress_bar = isset( $atts['progress_bar'] ) ? filter_var( $atts['progress_bar'], FILTER_VALIDATE_BOOLEAN ) : true;
		if ( $show_progress_bar ) {
			give_show_goal_totals_progress( $total, $total_goal );
		}

		echo sprintf( $message ) . $donate_link;
		?>
	</div>
	<?php
	$give_totals_output = ob_get_clean();

	/**
	 * Give Action fire after the total goal shortcode rendering is end.
	 *
	 * @since 2.1.4
	 *
	 * @param array  $atts               shortcode attribute.
	 * @param string $give_totals_output shortcode output.
	 */
	do_action( 'give_totals_goal_shortcode_after_render', $atts, $give_totals_output );

	/**
	 * Give Totals Shortcode output.
	 *
	 * @since 2.1
	 *
	 * @param string $give_totals_output
	 */
	return apply_filters( 'give_totals_shortcode_output', $give_totals_output );

}

Code file location:

give/give/includes/shortcodes.php

Give [give_form_grid] Shortcode

The Give Form Grid shortcode is a powerful tool in WordPress that generates a grid layout of donation forms. It allows customization of the forms displayed per page, order, categories, tags, and more. It also includes options to show the title, goal, excerpt, featured image, and donate button. This shortcode provides a streamlined way to display and manage multiple donation forms on a single page.

Shortcode: [give_form_grid]

Parameters

Here is a list of all possible give_form_grid shortcode parameters and attributes:

  • forms_per_page – sets the number of forms displayed per page
  • paged – enables or disables pagination
  • ids – specifies the forms to be displayed by their IDs
  • exclude – excludes certain forms from being displayed by their IDs
  • orderby – sorts the forms by date, amount donated, number of donations, or closest to goal
  • order – sets the sorting order to ascending or descending
  • cats – filters the forms by their categories
  • tags – filters the forms by their tags
  • columns – sets the number of columns in the form grid
  • show_title – shows or hides the form title
  • show_goal – shows or hides the donation goal
  • show_excerpt – shows or hides the form excerpt
  • show_featured_image – shows or hides the form featured image
  • show_donate_button – shows or hides the donate button
  • donate_button_text – customizes the text of the donate button
  • tag_background_color – sets the background color of the form tags
  • tag_text_color – sets the color of the form tag text
  • donate_button_text_color – sets the color of the donate button text
  • image_size – sets the size of the form featured image
  • image_height – sets the height of the form featured image
  • excerpt_length – sets the length of the form excerpt
  • display_style – sets the display style of the form to modal reveal
  • progress_bar_color – sets the color of the donation progress bar
  • status – filters the forms by their status (open or closed)

Examples and Usage

Basic example – Display a grid of donation forms using the default settings.

[give_form_grid]

For advanced usage, you can customize the shortcode by adding parameters. Here are some examples:

Advanced examples – Display a grid of donation forms with custom settings

Display a grid of 6 donation forms per page, ordered by the amount donated in ascending order.

[give_form_grid forms_per_page="6" orderby="amount_donated" order="ASC"]

Display a grid of donation forms excluding specific form IDs and showing only forms from specific categories.

[give_form_grid exclude="1,2,3" cats="food,education"]

Display a grid of donation forms with the donate button text customized, and the goal progress bar color changed.

[give_form_grid donate_button_text="Support Now" progress_bar_color="#ff0000"]

Display a grid of donation forms with only the title and donate button visible, and the forms displayed in a modal.

[give_form_grid show_goal="false" show_excerpt="false" show_featured_image="false" display_style="modal_reveal"]

These are just a few examples of how you can use the `give_form_grid` shortcode to display a grid of donation forms on your website. You can mix and match the parameters to suit your needs.

PHP Function Code

In case you have difficulties debugging what causing issues with [give_form_grid] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'give_form_grid', 'give_form_grid_shortcode' );

Shortcode PHP function:

function give_form_grid_shortcode( $atts ) {

	$give_settings = give_get_settings();

	$atts = shortcode_atts(
		[
			'forms_per_page'      => 12,
			'paged'               => true,
			'ids'                 => '',
			'exclude'             => '',
			'orderby'             => 'date',
			'order'               => 'DESC',
			'cats'                => '',
			'tags'                => '',
			'columns'             => '1',
			'show_title'          => true,
			'show_goal'           => true,
			'show_excerpt'        => true,
			'show_featured_image' => true,
			'show_donate_button'  => true,
			'donate_button_text'  => '',
			'tag_background_color' => '#69b868',
            'tag_text_color'      => '#333333',
            'donate_button_text_color' => '#000000',
			'image_size'          => 'medium',
			'image_height'        => 'auto',
			'excerpt_length'      => 16,
			'display_style'       => 'modal_reveal',
            'progress_bar_color' => '#69b868',
			'status'              => '', // open or closed.
		],
		$atts
	);

	// Validate integer attributes.
	$atts['forms_per_page'] = intval( $atts['forms_per_page'] );
	$atts['excerpt_length'] = intval( $atts['excerpt_length'] );

	// Validate boolean attributes.
	$boolean_attributes = [
		'paged',
		'show_title',
		'show_goal',
		'show_excerpt',
		'show_featured_image',
	];

	foreach ( $boolean_attributes as $att ) {
		$atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN );
	}

	// Set default form query args.
	$form_args = [
		'post_type'      => 'give_forms',
		'post_status'    => 'publish',
		'posts_per_page' => $atts['forms_per_page'],
		'orderby'        => $atts['orderby'],
		'order'          => $atts['order'],
        'paged'          => $atts['paged'],
		'tax_query'      => [
			'relation' => 'AND',
		],
	];

	// Filter results of form grid based on form status.
	$form_closed_status = trim( $atts['status'] );

	if ( ! empty( $form_closed_status ) ) {
		$form_args['meta_query'] = [
			[
				'key'   => '_give_form_status',
				'value' => $form_closed_status,
			],
		];
	}

	// Maybe add pagination.
	if ( true === $atts['paged'] ) {
		$form_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
	}

	// Maybe filter forms by IDs.
	if ( ! empty( $atts['ids'] ) ) {
		$form_args['post__in'] = array_map('_give_redirect_form_id', array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) ) );
	}

	// Convert comma-separated form IDs into array.
	if ( ! empty( $atts['exclude'] ) ) {
		$form_args['post__not_in'] = array_filter(
			array_map(
				function( $item ) {
					return intval( trim( $item ) );
				},
				explode( ',', $atts['exclude'] )
			)
		);
	}

	// Maybe filter by form category.
	if ( ! empty( $atts['cats'] ) ) {
		$cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) );

		// Backward compatibility for term_ids.
		$term_ids = array_unique( array_filter( $cats, 'is_numeric' ) );
		if ( $term_ids ) {
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_category',
				'terms'    => $term_ids,
			];

		}

		$term_slug = array_unique( array_filter( array_diff( $cats, $term_ids ) ) );
		if ( $term_slug ) {
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_category',
				'field'    => 'slug',
				'terms'    => $term_slug,
			];

		}
	}

	// Maybe filter by form tag.
	if ( ! empty( $atts['tags'] ) ) {
		$tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) );

		// Backward compatibility for term_ids.
		$tag_ids = array_unique( array_filter( $tags, 'is_numeric' ) );
		if ( $tag_ids ) {
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_tag',
				'terms'    => $tag_ids,
			];

		}

		$tag_slug = array_unique( array_filter( array_diff( $tags, $tag_ids ) ) );
		if ( $tag_slug ) {
			$form_args['tax_query'][] = [
				'taxonomy' => 'give_forms_tag',
				'field'    => 'slug',
				'terms'    => $tag_slug,
			];

		}
	}

	/**
	 * Filter to modify WP Query for Total Goal.
	 *
	 * @since 2.1.4
	 *
	 * @param array $form_args WP query argument for Grid.
	 *
	 * @return array $form_args WP query argument for Grid.
	 */
	$form_args = (array) apply_filters( 'give_form_grid_shortcode_query_args', $form_args );

	// Maybe filter by form Amount Donated or Number of Donations.
	switch ( $atts['orderby'] ) {
		case 'amount_donated':
			$form_args['meta_key'] = '_give_form_earnings';
			$form_args['orderby']  = 'meta_value_num';
			break;
		case 'number_donations':
			$form_args['meta_key'] = '_give_form_sales';
			$form_args['orderby']  = 'meta_value_num';
			break;
        case 'random':
            $form_args['orderby']  = 'rand';
            break;
		case 'closest_to_goal':
			if ( give_has_upgrade_completed( 'v240_update_form_goal_progress' ) ) {
				$form_args['meta_key'] = '_give_form_goal_progress';
				$form_args['orderby']  = 'meta_value_num';
			}
			break;
	}

	// Query to output donation forms.
	$form_query = new WP_Query( $form_args );

	if ( $form_query->have_posts() ) {
		ob_start();

		add_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class', 10, 1 );
		add_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class', 10, 1 );
		add_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10, 3 );
		add_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10, 3 );

		echo '<div class="give-wrap">';
		echo '<div class="give-grid give-grid--' . esc_attr( $atts['columns'] ) . '">';

		while ( $form_query->have_posts() ) {
			$form_query->the_post();

			// Give/templates/shortcode-form-grid.php.
			give_get_template( 'shortcode-form-grid', [ $give_settings, $atts ] );

		}

		wp_reset_postdata();

		echo '</div><!-- .give-grid -->';

		remove_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class' );
		remove_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class' );
		remove_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10 );
		remove_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10 );

		if ( false !== $atts['paged'] ) {
			$paginate_args = [
				'current'   => max( 1, get_query_var( 'paged' ) ),
				'total'     => $form_query->max_num_pages,
				'show_all'  => false,
				'end_size'  => 1,
				'mid_size'  => 2,
				'prev_next' => true,
				'prev_text' => __( '&laquo; Previous', 'give' ),
				'next_text' => __( 'Next &raquo;', 'give' ),
				'type'      => 'plain',
				'add_args'  => false,
			];

			printf(
				'<div class="give-page-numbers">%s</div>',
				paginate_links( $paginate_args )
			);
		}
		echo '</div><!-- .give-wrap -->';

		return ob_get_clean();
	} // End if().
}

Code file location:

give/give/includes/shortcodes.php

Give [give_donor_dashboard] Shortcode

The ‘give_donor_dashboard’ shortcode from the Give plugin is designed to render a donor dashboard. This dashboard can be customized with an accent color. The PHP function ‘renderCallback’ takes attributes as an input, with a default accent color of ‘#68bb6c’. The dashboard’s output is then generated based on these attributes.

Shortcode: [give_donor_dashboard]

Parameters

Here is a list of all possible give_donor_dashboard shortcode parameters and attributes:

  • accent_color – The color code to customize the appearance of the donor dashboard.

Examples and Usage

Basic example – This shortcode is used to display the donor dashboard with the default accent color.

[give_donor_dashboard /]

Advanced examples

Modifying the accent color of the donor dashboard. In this example, we’re changing the accent color to red.

[give_donor_dashboard accent_color="#ff0000" /]

Using multiple parameters to customize the donor dashboard. Here, we’re specifying the accent color and adding an additional attribute, ‘display’, to control the visibility of certain elements.

[give_donor_dashboard accent_color="#ff0000" display="true" /]

Note: The ‘display’ attribute is hypothetical and would only work if it’s defined in the ‘renderCallback’ function.

PHP Function Code

In case you have difficulties debugging what causing issues with [give_donor_dashboard] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('give_donor_dashboard', [$this, 'renderCallback']);

Shortcode PHP function:

function renderCallback($attributes)
    {
        $attributes = shortcode_atts(
            [
                'accent_color' => '#68bb6c',
            ],
            $attributes,
            'give_donor_dashboard'
        );

        return $this->donorDashboard->getOutput($attributes);
    }

Code file location:

give/give/src/DonorDashboards/Shortcode.php

Conclusion

Now that you’ve learned how to embed the Give Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *