Form_Edit_Page_Handler::maybe_render_shortcode( WP_Post $post )

Renders a read-only field containing the form shortcode markup for a post if applicable.

Description

Parameters

$post

(WP_Post) (Required) Post object.

Source

File: src/db-objects/forms/form-edit-page-handler.php

	public function maybe_render_shortcode( $post ) {
		$prefix = $this->form_manager->get_prefix();

		if ( $prefix . 'form' !== $post->post_type || 'auto-draft' === $post->post_status ) {
			return;
		}

		$this->form_manager->assets()->enqueue_script( 'clipboard' );
		$this->form_manager->assets()->enqueue_style( 'clipboard' );

		$id_attr = 'form-shortcode-' . $post->ID;

		?>
		<div class="misc-pub-section form-shortcode">
			<label for="<?php echo esc_attr( $id_attr ); ?>"><?php _e( 'Form Shortcode:', 'torro-forms' ); ?></label>
			<input id="<?php echo esc_attr( $id_attr ); ?>" class="clipboard-field" value="<?php echo esc_attr( sprintf( "[{$this->form_manager->get_prefix()}form id=&quot;%d&quot;]", $post->ID ) ); ?>" readonly="readonly" />
			<button type="button" class="clipboard-button button" data-clipboard-target="#<?php echo esc_attr( $id_attr ); ?>">
				<?php $this->form_manager->assets()->render_icon( 'torro-icon-clippy', __( 'Copy to clipboard', 'torro-forms' ) ); ?>
			</button>
		</div>
		<?php
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.