llms_merge_code_button( string $target = 'content', boolean $echo = true, array $codes = array() )

Add a “merge code” button that to auto-add merge codes to email & etc.


Description Description

..


Top ↑

Parameters Parameters

$target

(string) (Optional) target to add the merge code to accepts the ID of a tinymce editor a DOM ID (#element-id) and fallback to outputting an alert where the code can be copied from

Default value: 'content'

$echo

(boolean) (Optional) if truthy, echos the HTML, otherwise returns it

Default value: true

$codes

(array) (Optional) array of custom codes to pass in, otherwise the codes are determined what is available for the post type

Default value: array()


Top ↑

Return Return

(void|string)


Top ↑

Source Source

File: includes/admin/llms.functions.admin.php

function llms_merge_code_button( $target = 'content', $echo = true, $codes = array() ) {

	$screen = get_current_screen();

	if ( ! $codes && $screen ) {

		if ( isset( $screen->post_type ) ) {

			switch ( $screen->post_type ) {

				case 'llms_certificate':
					$codes = array(
						'{site_title}'    => __( 'Site Title', 'lifterlms' ),
						'{site_url}'      => __( 'Site URL', 'lifterlms' ),
						'{current_date}'  => __( 'Earned Date', 'lifterlms' ),
						'{first_name}'    => __( 'Student First Name', 'lifterlms' ),
						'{last_name}'     => __( 'Student Last Name', 'lifterlms' ),
						'{email_address}' => __( 'Student Email', 'lifterlms' ),
						'{student_id}'    => __( 'Student User ID', 'lifterlms' ),
						'{user_login}'    => __( 'Student Username', 'lifterlms' ),
					);

					break;

				case 'llms_email':
					$codes = array(
						'{site_title}'    => __( 'Website Title', 'lifterlms' ),
						'{site_url}'      => __( 'Website URL', 'lifterlms' ),
						'{email_address}' => __( 'Student Email Address', 'lifterlms' ),
						'{user_login}'    => __( 'Student Username', 'lifterlms' ),
						'{first_name}'    => __( 'Student First Name', 'lifterlms' ),
						'{last_name}'     => __( 'Student Last Name', 'lifterlms' ),
						'{current_date}'  => __( 'Current Date', 'lifterlms' ),
					);

					break;

				default:
					$codes = array();

			}// End switch().
		}// End if().
	}// End if().

	$codes = apply_filters( 'llms_merge_codes_for_button', $codes, $screen, $target );

	if ( ! $codes ) {
		return;
	}

	ob_start();

	echo '<div class="llms-merge-code-wrapper">';

	echo '<button class="button llms-merge-code-button" type="button"><img alt="LifterLMS" src="' . LLMS()->plugin_url() . '/assets/images/lifterlms-rocket-grey.png">' . __( 'Merge Codes', 'lifterlms' ) . '</button>';

	?>
	<div class="llms-merge-codes" data-target="<?php echo $target; ?>">
		<ul>
		<?php if ( $codes ) : ?>
			<?php foreach ( $codes as $code => $desc ) : ?>
				<li data-code="<?php echo $code; ?>"><?php echo $desc; ?></li>
			<?php endforeach; ?>
		<?php else : ?>
			<li><?php _e( 'No merge codes found.', 'lifterlms' ); ?></li>
		<?php endif; ?>
		</ul>
	</div>
	<?php

	echo '</div><!-- .llms-merge-code-wrapper -->';

	$html = ob_get_clean();

	if ( $echo ) {
		echo $html;
	} else {
		return $html;
	}

}


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.