Skip to content

Commit

Permalink
Some basic fields should be required when adding a post #1628
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed May 16, 2024
1 parent 7b002f4 commit 03c144e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
10 changes: 9 additions & 1 deletion modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,9 @@ public function content_board_get_post_form($post_type) {
<th>
<label for="publishpress-content-board-field-<?php echo esc_attr($field_key); ?>">
<?php echo esc_html($field_options['label']); ?>
<?php if (!empty($field_options['required'])) : ?>
<span class="required">*</span>
<?php endif; ?>
</label>
</th>
<td>
Expand Down Expand Up @@ -1685,11 +1688,14 @@ class="post_form_taxonomy"
break;

default:
$required_html = !empty($field_options['required']) ? 'required' : '';
?>
<input
type="<?php echo esc_attr($field_options['type']); ?>"
type="<?php echo esc_attr($field_options['type']); ?>"
class="new-post-<?php echo esc_attr($field_key); ?>-field"
name="<?php echo esc_attr($field_key); ?>"
value="<?php echo esc_attr($field_options['value']); ?>"
<?php echo esc_html($required_html); ?>
>
<?php
break;
Expand All @@ -1708,6 +1714,7 @@ class="post_form_taxonomy"
<div class="save-cc-changes save-new-post-form">
<?php echo sprintf(esc_html__('Create %s', 'publishpress'), esc_html($postTypeObject->labels->singular_name)); ?>
</div>
<input type="submit" name="submit" class="form-submit-button" value="<?php esc_html_e('Submit', 'publishpress'); ?>" style="display: none;"/>
</div>
</div>
</form>
Expand Down Expand Up @@ -1741,6 +1748,7 @@ public function getPostTypeFields($postType)
'label' => __('Title', 'publishpress'),
'value' => null,
'type' => 'text',
'required' => 1,
],
'status' => [
'label' => __('Post Status', 'publishpress'),
Expand Down
9 changes: 7 additions & 2 deletions modules/content-board/lib/content-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ jQuery(document).ready(function ($) {

$(document).on('click', '#pp-content-filters .clear-filter', function (e) {
e.preventDefault();
$('#pp-content-filters #post-query-clear').trigger('click');
$('#pp-content-filters-hidden').submit();
});

$(document).on('click', '.pp-content-board-manage .me-mode-action', function (e) {
Expand Down Expand Up @@ -367,7 +367,12 @@ jQuery(document).ready(function ($) {

$(document).on('click', '.co-cc-content .save-cc-changes', function (e) {
e.preventDefault();
$(this).closest('form').trigger('submit');
var button = $(this);
if (button.hasClass('save-new-post-form')) {
button.closest('form').find('.form-submit-button').trigger('click');
} else {
$(button).closest('form').trigger('submit');
}
});

$(document).on('keypress', '.co-cc-content .entry-item input', function (e) {
Expand Down
7 changes: 7 additions & 0 deletions modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,9 @@ public function content_overview_get_post_form($post_type) {
<th>
<label for="publishpress-content-overview-field-<?php echo esc_attr($field_key); ?>">
<?php echo esc_html($field_options['label']); ?>
<?php if (!empty($field_options['required'])) : ?>
<span class="required">*</span>
<?php endif; ?>
</label>
</th>
<td>
Expand Down Expand Up @@ -1663,11 +1666,13 @@ class="post_form_taxonomy"
break;

default:
$required_html = !empty($field_options['required']) ? 'required' : '';
?>
<input
type="<?php echo esc_attr($field_options['type']); ?>"
name="<?php echo esc_attr($field_key); ?>"
value="<?php echo esc_attr($field_options['value']); ?>"
<?php echo esc_html($required_html); ?>
>
<?php
break;
Expand All @@ -1686,6 +1691,7 @@ class="post_form_taxonomy"
<div class="save-cc-changes save-new-post-form">
<?php echo sprintf(esc_html__('Create %s', 'publishpress'), esc_html($postTypeObject->labels->singular_name)); ?>
</div>
<input type="submit" name="submit" class="form-submit-button" value="<?php esc_html_e('Submit', 'publishpress'); ?>" style="display: none;"/>
</div>
</div>
</form>
Expand Down Expand Up @@ -1719,6 +1725,7 @@ public function getPostTypeFields($postType)
'label' => __('Title', 'publishpress'),
'value' => null,
'type' => 'text',
'required' => 1,
],
'status' => [
'label' => __('Post Status', 'publishpress'),
Expand Down
9 changes: 7 additions & 2 deletions modules/content-overview/lib/content-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jQuery(document).ready(function ($) {

$(document).on('click', '#pp-content-filters .clear-filter', function (e) {
e.preventDefault();
$('#pp-content-filters #post-query-clear').trigger('click');
$('#pp-content-filters-hidden').submit();
});

$(document).on('click', '.pp-content-overview-manage .me-mode-action', function (e) {
Expand Down Expand Up @@ -310,7 +310,12 @@ jQuery(document).ready(function ($) {

$(document).on('click', '.co-cc-content .save-cc-changes', function (e) {
e.preventDefault();
$(this).closest('form').trigger('submit');
var button = $(this);
if (button.hasClass('save-new-post-form')) {
button.closest('form').find('.form-submit-button').trigger('click');
} else {
$(button).closest('form').trigger('submit');
}
});

$(document).on('keypress', '.co-cc-content .entry-item input', function (e) {
Expand Down

0 comments on commit 03c144e

Please sign in to comment.