WPCF7_Editor{}CF7 1.0

Хуков нет.

Использование

$WPCF7_Editor = new WPCF7_Editor();
// use class methods

Методы

  1. public __construct( WPCF7_ContactForm $contact_form )
  2. public add_panel( $panel_id, $title, $callback )
  3. public display()

Код WPCF7_Editor{} CF7 6.1.6

class WPCF7_Editor {

	private $contact_form;
	private $panels = array();

	public function __construct( WPCF7_ContactForm $contact_form ) {
		$this->contact_form = $contact_form;
	}

	public function add_panel( $panel_id, $title, $callback ) {
		if ( wpcf7_is_name( $panel_id ) ) {
			$this->panels[$panel_id] = array(
				'title' => $title,
				'callback' => $callback,
			);
		}
	}

	public function display() {
		if ( empty( $this->panels ) ) {
			return;
		}

		$active_panel_id = wpcf7_superglobal_get( 'active-tab' );

		if ( ! array_key_exists( $active_panel_id, $this->panels ) ) {
			$active_panel_id = array_key_first( $this->panels );
		}

		$formatter = new WPCF7_HTMLFormatter();

		$formatter->append_start_tag( 'nav', array(
			'id' => 'contact-form-editor-tabs',
			'role' => 'tablist',
			'aria-label' => __( 'Contact form editor tabs', 'contact-form-7' ),
			'data-active-tab' => absint( array_search(
				$active_panel_id, array_keys( $this->panels ), true
			) ),
		) );

		foreach ( $this->panels as $panel_id => $panel ) {
			$active = $panel_id === $active_panel_id;

			$formatter->append_start_tag( 'button', array(
				'type' => 'button',
				'role' => 'tab',
				'aria-selected' => $active ? 'true' : 'false',
				'aria-controls' => $panel_id,
				'id' => sprintf( '%s-tab', $panel_id ),
				'tabindex' => $active ? '0' : '-1',
			) );

			$formatter->append_preformatted( esc_html( $panel['title'] ) );
		}

		$formatter->end_tag( 'nav' );

		foreach ( $this->panels as $panel_id => $panel ) {
			$active = $panel_id === $active_panel_id;

			$formatter->append_start_tag( 'section', array(
				'role' => 'tabpanel',
				'aria-labelledby' => sprintf( '%s-tab', $panel_id ),
				'id' => $panel_id,
				'class' => 'contact-form-editor-panel',
				'tabindex' => '0',
				'hidden' => ! $active,
			) );

			if ( is_callable( $panel['callback'] ) ) {
				$formatter->call_user_func( $panel['callback'], $this->contact_form );
			}

			$formatter->end_tag( 'section' );
		}

		$formatter->print();
	}
}