| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
use Elementor\Core\Base\Document; |
| 5 |
use Elementor\TemplateLibrary\Forms\New_Template_Form; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly |
| 9 |
} |
| 10 |
$new_template_control_form = new New_Template_Form( [ 'id' => 'form' ] ); |
| 11 |
$document_types = Plugin::$instance->documents->get_document_types(); |
| 12 |
|
| 13 |
$types = []; |
| 14 |
$lock_configs = []; |
| 15 |
|
| 16 |
$selected = get_query_var( 'elementor_library_type' ); |
| 17 |
|
| 18 |
foreach ( $document_types as $document_type ) { |
| 19 |
if ( $document_type::get_property( 'show_in_library' ) ) { |
| 20 |
/** |
| 21 |
* @var Document $instance |
| 22 |
*/ |
| 23 |
$instance = new $document_type(); |
| 24 |
$lock_behavior = $document_type::get_lock_behavior_v2(); |
| 25 |
|
| 26 |
$types[ $instance->get_name() ] = $document_type::get_title(); |
| 27 |
$lock_configs[ $instance->get_name() ] = empty( $lock_behavior ) |
| 28 |
? (object) [] |
| 29 |
: $lock_behavior->get_config(); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Create new template library dialog types. |
| 35 |
* |
| 36 |
* Filters the dialog types when printing new template dialog. |
| 37 |
* |
| 38 |
* @since 2.0.0 |
| 39 |
* |
| 40 |
* @param array $types Types data. |
| 41 |
* @param Document $document_types Document types. |
| 42 |
*/ |
| 43 |
$types = apply_filters( 'elementor/template-library/create_new_dialog_types', $types, $document_types ); |
| 44 |
ksort( $types ); |
| 45 |
|
| 46 |
?> |
| 47 |
<script type="text/template" id="tmpl-elementor-new-template"> |
| 48 |
<div id="elementor-new-template__description"> |
| 49 |
<div id="elementor-new-template__description__title"><?php |
| 50 |
printf( |
| 51 |
/* translators: %1$s Span open tag, %2$s: Span close tag. */ |
| 52 |
esc_html__( 'Templates Help You %1$sWork Efficiently%2$s', 'elementor' ), |
| 53 |
'<span>', |
| 54 |
'</span>' |
| 55 |
); |
| 56 |
?></div> |
| 57 |
<div id="elementor-new-template__description__content"><?php echo esc_html__( 'Use templates to create the different pieces of your site, and reuse them with one click whenever needed.', 'elementor' ); ?></div> |
| 58 |
</div> |
| 59 |
<form id="elementor-new-template__form" action="<?php esc_url( admin_url( '/edit.php' ) ); ?>"> |
| 60 |
<input type="hidden" name="post_type" value="elementor_library"> |
| 61 |
<input type="hidden" name="action" value="elementor_new_post"> |
| 62 |
<?php // PHPCS - a nonce doesn't have to be escaped. ?> |
| 63 |
<input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'elementor_action_new_post' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"> |
| 64 |
<div id="elementor-new-template__form__title"><?php echo esc_html__( 'Choose Template Type', 'elementor' ); ?></div> |
| 65 |
<div id="elementor-new-template__form__template-type__wrapper" class="elementor-form-field"> |
| 66 |
<label for="elementor-new-template__form__template-type" class="elementor-form-field__label"><?php echo esc_html__( 'Select the type of template you want to work on', 'elementor' ); ?></label> |
| 67 |
<div class="elementor-form-field__select__wrapper"> |
| 68 |
<?php // Badge will be filled from js. ?> |
| 69 |
<span id="elementor-new-template__form__template-type-badge" class="e-hidden"> |
| 70 |
<i id="elementor-new-template__form__template-type-badge__icon"></i> |
| 71 |
<span id="elementor-new-template__form__template-type-badge__text"></span> |
| 72 |
</span> |
| 73 |
|
| 74 |
<select id="elementor-new-template__form__template-type" class="elementor-form-field__select" name="template_type" required> |
| 75 |
<option value=""><?php echo esc_html__( 'Select', 'elementor' ); ?>...</option> |
| 76 |
<?php |
| 77 |
foreach ( $types as $value => $type_title ) { |
| 78 |
printf( |
| 79 |
'<option value="%1$s" data-lock=\'%2$s\' %3$s>%4$s</option>', |
| 80 |
esc_attr( $value ), |
| 81 |
wp_json_encode( $lock_configs[ $value ] ?? (object) [] ), |
| 82 |
selected( $selected, $value, false ), |
| 83 |
esc_html( $type_title ) |
| 84 |
); |
| 85 |
} |
| 86 |
?> |
| 87 |
</select> |
| 88 |
</div> |
| 89 |
</div> |
| 90 |
<?php |
| 91 |
/** |
| 92 |
* Template library dialog fields. |
| 93 |
* |
| 94 |
* Fires after Elementor template library dialog fields are displayed. |
| 95 |
* |
| 96 |
* @since 2.0.0 |
| 97 |
*/ |
| 98 |
do_action( 'elementor/template-library/create_new_dialog_fields', $new_template_control_form ); |
| 99 |
|
| 100 |
$additional_controls = $new_template_control_form->get_controls(); |
| 101 |
if ( $additional_controls ) { |
| 102 |
wp_add_inline_script( 'elementor-admin', 'const elementor_new_template_form_controls = ' . wp_json_encode( $additional_controls ) . ';' ); |
| 103 |
$new_template_control_form->render(); |
| 104 |
} |
| 105 |
?> |
| 106 |
|
| 107 |
<div id="elementor-new-template__form__post-title__wrapper" class="elementor-form-field"> |
| 108 |
<label for="elementor-new-template__form__post-title" class="elementor-form-field__label"> |
| 109 |
<?php echo esc_html__( 'Name your template', 'elementor' ); ?> |
| 110 |
</label> |
| 111 |
<div class="elementor-form-field__text__wrapper"> |
| 112 |
<input type="text" placeholder="<?php echo esc_attr__( 'Enter template name (optional)', 'elementor' ); ?>" id="elementor-new-template__form__post-title" class="elementor-form-field__text" name="post_data[post_title]"> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
<button id="elementor-new-template__form__submit" class="elementor-button e-primary"><?php echo esc_html__( 'Create Template', 'elementor' ); ?></button> |
| 116 |
<a id="elementor-new-template__form__lock_button" class="elementor-button e-accent e-hidden" target="_blank"><?php // Will be filled from js. ?></a> |
| 117 |
</form> |
| 118 |
</script> |
| 119 |
|