forked from DiscipleTools/disciple-tools-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-new-post.php
164 lines (144 loc) · 9 KB
/
template-new-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
declare(strict_types=1);
if ( !defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
dt_please_log_in();
$url = dt_get_url_path();
$dt_post_type = explode( "/", $url )[0];
if ( ! current_user_can( 'create_' . $dt_post_type ) ) {
wp_die( esc_html( "You do not have permission to publish " . $dt_post_type ), "Permission denied", 403 );
}
get_header();
$post_settings = DT_Posts::get_post_settings( $dt_post_type );
$force_type_choice = false;
if ( isset( $post_settings["fields"]["type"] ) && sizeof( $post_settings["fields"]["type"]["default"] ) > 1 ){
$force_type_choice = true;
}
?>
<div id="content" class="template-new-post">
<div id="inner-content" class="grid-x grid-margin-x">
<div class="large-2 medium-12 small-12 cell"></div>
<div class="large-8 medium-12 small-12 cell">
<form class="js-create-post bordered-box display-fields">
<h3 class="section-header">
<?php echo esc_html( sprintf( __( 'New %s', 'disciple_tools' ), $post_settings["label_singular"] ) ) ?>
</h3>
<!-- choose the record type -->
<?php if ( $force_type_choice ){ ?>
<div class="type-control-field" style="margin:20px 0">
<strong>
<?php echo esc_html( sprintf( __( 'Select the %s type:', 'disciple_tools' ), $post_settings["label_singular"] ) ) ?>
</strong>
</div>
<div class="type-options">
<?php if ( isset( $post_settings["fields"]["type"]["default"] ) ) {
uasort( $post_settings["fields"]["type"]["default"], function ( $a, $b ){
return ( $a['order'] ?? 100 ) <=> ( $b['order'] ?? 100 );
});
}
foreach ( $post_settings["fields"]["type"]["default"] as $option_key => $type_option ) {
//order fields alphabetically by Name
if ( empty( $type_option["hidden"] ) ){ ?>
<div class="type-option" id="<?php echo esc_html( $option_key ); ?>">
<div class="type-option-border">
<input type="radio" name="type" value="<?php echo esc_html( $option_key ); ?>" style="display: none">
<div class="type-option-rows">
<div>
<?php if ( isset( $type_option["icon"] ) ) : ?>
<img class="dt-icon" src="<?php echo esc_url( $type_option["icon"] ) ?>">
<?php endif; ?>
<strong class="type-option-title"><?php echo esc_html( $type_option["label"] ); ?></strong>
</div>
<div>
<img class="dt-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/visibility.svg' ) ?>"/>
<?php echo esc_html( $type_option["visibility"] ?? "" ); ?>
</div>
<div>
<img class="dt-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
<?php echo esc_html( $type_option["description"] ?? "" ); ?>
</div>
</div>
</div>
</div>
<?php }
} ?>
</div>
<?php } ?>
<div class="form-fields" <?php echo esc_html( $force_type_choice ? "style=display:none" : "" ); ?>>
<?php foreach ( $post_settings["fields"] as $field_key => $field_settings ) {
if ( !empty( $field_settings["hidden"] ) && empty( $field_settings["custom_display"] ) ){
continue;
}
if ( isset( $field_settings["in_create_form"] ) && $field_settings["in_create_form"] === false ){
continue;
}
if ( !isset( $field_settings["tile"] ) ){
continue;
}
$classes = "";
//add types the field should show up on as classes
if ( !empty( $field_settings['in_create_form'] ) ){
if ( is_array( $field_settings['in_create_form'] ) ){
foreach ( $field_settings['in_create_form'] as $type_key ){
$classes .= $type_key . " ";
}
} elseif ( $field_settings['in_create_form'] === true ){
$classes = "all";
}
} else {
$classes = "other-fields";
}
?>
<!-- hide fields until the post type is chosen. hide the fields that were not selected to be displayed by default in the create form -->
<div <?php echo esc_html( ( $force_type_choice || $classes === "other-fields" ) ? "style=display:none" : "" ); ?>
class="form-field <?php echo esc_html( $classes ); ?>">
<?php
render_field_for_display( $field_key, $post_settings['fields'], [] );
if ( isset( $field_settings["required"] ) && $field_settings["required"] === true ) { ?>
<p class="help-text" id="name-help-text"><?php esc_html_e( "This is required", "disciple_tools" ); ?></p>
<?php } ?>
</div>
<?php } ?>
<div id="show-shield-banner" style="text-align: center; background-color:rgb(236, 245, 252);margin: 3px -15px 15px -15px;">
<a class="button clear" id="show-hidden-fields" style="margin:0;padding:3px 0; width:100%">
<?php esc_html_e( 'Show all fields', 'disciple_tools' ); ?>
</a>
<a class="button clear" id="hide-hidden-fields" style="margin:0;padding:3px 0; width:100%; display: none;">
<?php esc_html_e( 'Hide fields', 'disciple_tools' ); ?>
</a>
</div>
<div style="text-align: center">
<a href="<?php echo esc_html( get_site_url() . "/" . $dt_post_type )?>" class="button small clear"><?php echo esc_html__( 'Cancel', 'disciple_tools' )?></a>
<button class="button loader js-create-post-button dt-green" type="submit" disabled><?php esc_html_e( "Save and continue editing", "disciple_tools" ); ?></button>
</div>
</div>
</form>
</div>
<div class="large-2 medium-12 small-12 cell"></div>
</div>
</div>
<div class="reveal" id="create-tag-modal" data-reveal data-reset-on-close>
<h3><?php esc_html_e( 'Create Tag', 'disciple_tools' )?></h3>
<p><?php esc_html_e( 'Create a tag and apply it to this record.', 'disciple_tools' )?></p>
<form class="js-create-tag">
<label for="title">
<?php esc_html_e( "Tag", "disciple_tools" ); ?>
</label>
<input name="title" id="new-tag" type="text" placeholder="<?php esc_html_e( "Tag", 'disciple_tools' ); ?>" required aria-describedby="name-help-text">
<p class="help-text" id="name-help-text"><?php esc_html_e( "This is required", "disciple_tools" ); ?></p>
</form>
<div class="grid-x">
<button class="button button-cancel clear" data-close aria-label="Close reveal" type="button">
<?php echo esc_html__( 'Cancel', 'disciple_tools' )?>
</button>
<button class="button" data-close type="button" id="create-tag-return">
<?php esc_html_e( 'Create and apply tag', 'disciple_tools' ); ?>
</button>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
<?php
get_footer();