PUM_Shortcode::register_shortcode_ui()

Register this shortcode in shortcake ui.


Description Description


Source Source

File: classes/Shortcode.php

	public function register_shortcode_ui() {

		if ( ! is_admin() || ! function_exists( 'shortcode_ui_register_for_shortcode' ) ) {
			return;
		}

		$shortcode_ui_args = array(
			'label'         => $this->label(),
			'listItemImage' => $this->icon(),
			'post_type'     => apply_filters( 'pum_shortcode_post_types', $this->post_types(), $this ),
			'attrs'         => array(),
		);

		/**
		 * Register UI for the "inner content" of the shortcode. Optional.
		 * If no UI is registered for the inner content, then any inner content
		 * data present will be backed up during editing.
		 */
		if ( $this->has_content ) {
			$shortcode_ui_args['inner_content'] = $this->inner_content_labels();
		}

		$fields = PUM_Admin_Helpers::flatten_fields_array( $this->_fields() );

		if ( count( $fields ) ) {
			foreach ( $fields as $field_id => $field ) {

				// Don't register inner content fields.
				if ( '_inner_content' == $field_id ) {
					continue;
				}

				//text, checkbox, textarea, radio, select, email, url, number, date, attachment, color, post_select
				switch ( $field['type'] ) {
					case 'select':
						$shortcode_ui_args['attrs'][] = array(
							'label'   => esc_html( $field['label'] ),
							'attr'    => $field_id,
							'type'    => 'select',
							'options' => $field['options'],
						);
						break;

					case 'postselect':
					case 'objectselect':
						if ( empty( $field['post_type'] ) ) {
							break;
						}
						$shortcode_ui_args['attrs'][] = array(
							'label'   => esc_html( $field['label'] ),
							'attr'    => $field_id,
							'type'    => 'post_select',
							'options' => isset( $field['options'] ) ? $field['options'] : array(),
							'query'   => array( 'post_type' => $field['post_type'] ),
						);
						break;

					case 'taxonomyselect':
						break;

					case 'text';
					default:
						$shortcode_ui_args['attrs'][] = array(
							'label' => $field['label'],
							'attr'  => $field_id,
							'type'  => 'text',
							'value' => ! empty( $field['std'] ) ? $field['std'] : '',
							//'encode' => true,
							'meta'  => array(
								'placeholder' => $field['placeholder'],
							),
						);
						break;
				}
			}
		}

		/**
		 * Register UI for your shortcode
		 *
		 * @param string $shortcode_tag
		 * @param array  $ui_args
		 */
		shortcode_ui_register_for_shortcode( $this->tag(), $shortcode_ui_args );
	}


Top ↑

User Contributed Notes User Contributed Notes

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