Skip to content

Commit

Permalink
add disable publish button option
Browse files Browse the repository at this point in the history
  • Loading branch information
rizaardiyanto1412 committed Aug 8, 2024
1 parent bc49d9e commit f8253ac
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/checklists/assets/js/meta-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,29 @@
});
}

/*---------- Disable publish button ----------*/
// Disable first save button until requirements are meet when "Include pre-publish checklist" is disabled
// @TODO Figure out how to get the status of "Include pre-publish checklist" and add it to the if() below
if (ppChecklists.disable_publish_button) {
$(window).on('load', function () {
if (
PP_Checklists.is_gutenberg_active() &&
((PP_Checklists.is_published() !== true && PP_Checklists.is_pending() !== true) ||
!ppChecklists.disable_published_block_feature)
) {
$(document).on(PP_Checklists.EVENT_TIC, function (event) {
var has_unchecked_block = $('#pp-checklists-req-box').children('.status-no.pp-checklists-block');
if (has_unchecked_block.length > 0) {
wp.data.dispatch('core/editor').lockPostSaving('ppcPublishButton');
} else {
wp.data.dispatch('core/editor').unlockPostSaving('ppcPublishButton');
}
});
}
});
}


/*---------- Featured Image ----------*/

if ($('#pp-checklists-req-featured_image').length > 0) {
Expand Down
1 change: 1 addition & 0 deletions modules/checklists/checklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ public function display_meta_box($post)
'publishpress-checklists'
),
'show_warning_icon_submit' => Base_requirement::VALUE_YES === $legacyPlugin->settings->module->options->show_warning_icon_submit,
'disable_publish_button' => Base_requirement::VALUE_YES === $legacyPlugin->settings->module->options->disable_publish_button,
'title_warning_icon' => esc_html__('One or more items in the checklist are not completed'),
'is_gutenberg_active' => $this->is_gutenberg_active(),
'user_can_manage_options' => current_user_can( 'manage_options' ),
Expand Down
33 changes: 33 additions & 0 deletions modules/settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ public function validate_module_settings($new_options)
$new_options['disable_quick_edit_completely'] = Base_requirement::VALUE_NO;
}

if (!isset($new_options['disable_publish_button'])) {
$new_options['disable_publish_button'] = Base_requirement::VALUE_NO;
}

return $new_options;
}

Expand Down Expand Up @@ -751,6 +755,14 @@ public function register_settings()
$this->module->options_group_name . '_general'
);

add_settings_field(
'disable_publish_button',
__('Disable Publish button:', 'publishpress-checklists'),
[$this, 'settings_disable_publish_button_option'],
$this->module->options_group_name,
$this->module->options_group_name . '_general'
);

add_settings_field(
'openai_api_key',
__('OpenAI API Key:', 'publishpress-checklists'),
Expand Down Expand Up @@ -854,6 +866,27 @@ public function settings_disable_quick_edit_completely_option($args = [])
echo '</label>';
}

/**
* Displays the checkbox to enable or disable quick edit
*
*
* @param array
*/
public function settings_disable_publish_button_option($args = [])
{
$id = $this->module->options_group_name . '_disable_publish_button';
$value = isset($this->module->options->disable_publish_button) ? $this->module->options->disable_publish_button : 'no';

echo '<label for="' . esc_attr($id) . '">';
echo '<input type="checkbox" value="yes" id="' . esc_attr($id) . '" name="' . esc_attr($this->module->options_group_name) . '[disable_publish_button]" '
. checked($value, 'yes', false) . ' />';
echo '&nbsp;&nbsp;&nbsp;' . esc_html__(
'This will disable the Publish button when checklist requirements are not met.',
'publishpress-checklists'
);
echo '</label>';
}

/**
* Displays the openai api key settings
*
Expand Down

0 comments on commit f8253ac

Please sign in to comment.