Skip to content

Commit

Permalink
Merge pull request #837 from publishpress/fix/#504-disable-checklists…
Browse files Browse the repository at this point in the history
…-on-page-builder

fix/#504-disable-checklists-on-page-builder
  • Loading branch information
rizaardiyanto1412 authored Dec 10, 2024
2 parents ef1914e + 29f19d5 commit ae04aad
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 110 deletions.
27 changes: 27 additions & 0 deletions core/Utils/ElementorUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @package PublishPress\Checklists
* @author PublishPress <[email protected]>
* @copyright Copyright (C) 2019 PublishPress. All rights reserved.
* @license GPLv2 or later
* @since 1.0.0
*/

namespace PublishPress\Checklists\Core\Utils;

class ElementorUtils
{
/**
* Check if Elementor is enabled for the current post
*
* @return bool
*/
public static function isElementorEnabled()
{
if (!function_exists('get_post_meta') || !function_exists('get_the_ID')) {
return false;
}

return get_post_meta(get_the_ID(), '_elementor_edit_mode', true) === 'builder';
}
}
104 changes: 55 additions & 49 deletions modules/checklists/assets/js/gutenberg-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PPChecklistsPanel extends Component {

render() {
const { showRequiredLegend, requirements } = this.state;

return (
<Fragment>
<PluginSidebarMoreMenuItem
Expand All @@ -188,55 +188,61 @@ class PPChecklistsPanel extends Component {
title={__("Checklists", "publishpress-checklists")}
>
<div id="pp-checklists-sidebar-content" className="components-panel__body is-opened">
<ul id="pp-checklists-sidebar-req-box">
{requirements.length === 0 ? (
<p>
<em>
{i18n.noTaskLabel}
</em>
</p>
) : (
requirements.map((req, key) => (
<li
key={`pp-checklists-req-panel-${key}`}
className={`pp-checklists-req panel-req pp-checklists-${req.rule} status-${req.status ? 'yes' : 'no'} ${req.is_custom ? 'pp-checklists-custom-item' : ''
}`}
data-id={req.id}
data-type={req.type}
data-extra={req.extra || ''}
data-source={req.source || ''}
onClick={() => {
if (req.is_custom) {
const element = document.querySelector(`#pp-checklists-req-${req.id}` + ' .status-label');
if (element) {
element.click();
}
}
}}
>
{req.is_custom || req.require_button ? (
<input type="hidden" name={`_PPCH_custom_item[${req.id}]`} value={req.status ? 'yes' : 'no'} />
) : null}
<div className={`status-icon dashicons ${req.is_custom ? (req.status ? 'dashicons-yes' : '') : (req.status ? 'dashicons-yes' : 'dashicons-no')}`}></div>
<div className="status-label">
<span className="req-label" dangerouslySetInnerHTML={{ __html: req.label }} />
{req.rule === 'block' ? (
<span className="required">*</span>
) : null}
{req.require_button ? (
<div className="requirement-button-task-wrap">
<button type="button" className="button button-secondary pp-checklists-check-item">
{__("Check Now", "publishpress-checklists")}
<span className="spinner"></span>
</button>
<div className="request-response"></div>
{i18n.isElementorEnabled == "1" ? (
<p><em>{i18n.elementorNotice}</em></p>
) : (
<Fragment>
{requirements.length === 0 ? (
<p>
<em>
{i18n.noTaskLabel}
</em>
</p>
) : (
<ul id="pp-checklists-sidebar-req-box">
{requirements.map((req, key) => (
<li
key={`pp-checklists-req-panel-${key}`}
className={`pp-checklists-req panel-req pp-checklists-${req.rule} status-${req.status ? 'yes' : 'no'} ${req.is_custom ? 'pp-checklists-custom-item' : ''
}`}
data-id={req.id}
data-type={req.type}
data-extra={req.extra || ''}
data-source={req.source || ''}
onClick={() => {
if (req.is_custom) {
const element = document.querySelector(`#pp-checklists-req-${req.id}` + ' .status-label');
if (element) {
element.click();
}
}
}}
>
{req.is_custom || req.require_button ? (
<input type="hidden" name={`_PPCH_custom_item[${req.id}]`} value={req.status ? 'yes' : 'no'} />
) : null}
<div className={`status-icon dashicons ${req.is_custom ? (req.status ? 'dashicons-yes' : '') : (req.status ? 'dashicons-yes' : 'dashicons-no')}`}></div>
<div className="status-label">
<span className="req-label" dangerouslySetInnerHTML={{ __html: req.label }} />
{req.rule === 'block' ? (
<span className="required">*</span>
) : null}
{req.require_button ? (
<div className="requirement-button-task-wrap">
<button type="button" className="button button-secondary pp-checklists-check-item">
{__("Check Now", "publishpress-checklists")}
<span className="spinner"></span>
</button>
<div className="request-response"></div>
</div>
) : null}
</div>
) : null}
</div>
</li>
))
)}
</ul>
</li>
))}
</ul>
)}
</Fragment>
)}
{showRequiredLegend ? (
<em>
(*) {i18n.required}
Expand Down
2 changes: 1 addition & 1 deletion modules/checklists/assets/js/gutenberg-panel.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions modules/checklists/checklists.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use PublishPress\Checklists\Core\Requirement\Custom_item;
use PublishPress\Checklists\Core\Requirement\Openai_item;
use PublishPress\Checklists\Core\Utils\FieldsTabs;
use PublishPress\Checklists\Core\Utils\ElementorUtils;

if (!class_exists('PPCH_Checklists')) {
/**
Expand Down Expand Up @@ -1074,6 +1075,8 @@ public function enqueue_block_editor_assets()
'checklistLabel' => __("Checklists", "publishpress-checklists"),
'noTaskLabel' => __("You don't have to complete any Checklist tasks.", "publishpress-checklists"),
'required' => __("required", "publishpress-checklists"),
'elementorNotice' => __("Checklists tasks are not available in Elementor editors", "publishpress-checklists"),
'isElementorEnabled' => ElementorUtils::isElementorEnabled() ? "1" : "0",
)
);
}
Expand Down
129 changes: 69 additions & 60 deletions modules/checklists/templates/meta-box.php
Original file line number Diff line number Diff line change
@@ -1,71 +1,80 @@
<?php $show_required_legend = false; ?>
<?php
$show_required_legend = false;
use PublishPress\Checklists\Core\Utils\ElementorUtils;
?>

<div id="<?php echo esc_attr($context['metadata_taxonomy']); ?>-meta-box">
<div class="pp-checklists">
<input type="hidden" name="<?php echo esc_attr($context['metadata_taxonomy']); ?>_nonce"
value="<?php echo esc_attr($context['nonce']); ?>"/>

<ul id="pp-checklists-req-box">
<?php if (empty($context['requirements'])) : ?>
<p>
<?php
$message = sprintf(
esc_html($context['lang']['empty_checklist_message']),
'<a href="' . esc_url($context['configure_link']) . '">',
'</a>'
);
?>
<em><?php echo $message;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></em>
</p>
<?php else : ?>
<?php foreach ($context['requirements'] as $key => $req) : ?>
<li
id="pp-checklists-req-<?php echo esc_attr($key); ?>"
class="pp-checklists-req metabox-req pp-checklists-<?php echo esc_attr($req['rule']); ?> status-<?php echo $req['status'] ? 'yes' : 'no'; ?> <?php echo $req['is_custom'] ? 'pp-checklists-custom-item' : ''; ?>"
data-id="<?php echo esc_attr($key); ?>"
data-type="<?php echo esc_attr($req['type']); ?>"
data-source="<?php echo !empty($req['source']) ? esc_attr($req['source']) : ''; ?>"
data-extra="<?php echo isset($req['extra']) ? esc_attr($req['extra']) : ''; ?>">
<?php if (ElementorUtils::isElementorEnabled()) : ?>
<p><em><?php echo esc_html__('Checklists tasks are not available in Elementor editors', 'publishpress-checklists'); ?></em></p>
<?php else : ?>
<div id="<?php echo esc_attr($context['metadata_taxonomy']); ?>-meta-box">
<ul id="pp-checklists-req-box">
<?php if (empty($context['requirements'])) : ?>
<p>
<?php
$message = sprintf(
esc_html($context['lang']['empty_checklist_message']),
'<a href="' . esc_url($context['configure_link']) . '">',
'</a>'
);
?>
<em><?php echo $message;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></em>
</p>
<?php else : ?>
<?php foreach ($context['requirements'] as $key => $req) : ?>
<li
id="pp-checklists-req-<?php echo esc_attr($key); ?>"
class="pp-checklists-req metabox-req pp-checklists-<?php echo esc_attr($req['rule']); ?> status-<?php echo $req['status'] ? 'yes' : 'no'; ?> <?php echo $req['is_custom'] ? 'pp-checklists-custom-item' : ''; ?>"
data-id="<?php echo esc_attr($key); ?>"
data-type="<?php echo esc_attr($req['type']); ?>"
data-source="<?php echo !empty($req['source']) ? esc_attr($req['source']) : ''; ?>"
data-extra="<?php echo isset($req['extra']) ? esc_attr($req['extra']) : ''; ?>">

<?php if (!empty($req['is_custom']) || !empty($req['require_button'])) : ?>
<input type="hidden" name="_PPCH_custom_item[<?php echo esc_attr($req['id']); ?>]"
value="<?php echo $req['status'] ? 'yes' : 'no'; ?>"/>
<?php endif; ?>
<?php if (!empty($req['is_custom']) || !empty($req['require_button'])) : ?>
<input type="hidden" name="_PPCH_custom_item[<?php echo esc_attr($req['id']); ?>]"
value="<?php echo $req['status'] ? 'yes' : 'no'; ?>"/>
<?php endif; ?>

<?php
if ($req['is_custom']) :
$icon_class = $req['status'] ? 'dashicons-yes' : '';
else:
$icon_class = $req['status'] ? 'dashicons-yes' : 'dashicons-no';
endif;
?>
<div class="status-icon dashicons <?php echo esc_attr($icon_class); ?>"></div>
<div class="status-label">
<?php echo wp_kses_post($req['label']); ?>
<?php if ($req['rule'] === 'block') : ?>
<span class="required">*</span>
<?php $show_required_legend = true; ?>
<?php endif; ?>
</div>
<?php if (!empty($req['require_button'])) : ?>
<button type="button" class="button button-secondary pp-checklists-check-item">
<?php echo esc_html($context['lang']['check']); ?>
<span class="spinner"></span>
</button>
<div class="request-response"></div>
<?php endif; ?>
<?php
if ($req['is_custom']) :
$icon_class = $req['status'] ? 'dashicons-yes' : '';
else:
$icon_class = $req['status'] ? 'dashicons-yes' : 'dashicons-no';
endif;
?>
<div class="status-icon dashicons <?php echo esc_attr($icon_class); ?>"></div>
<div class="status-label">
<?php echo wp_kses_post($req['label']); ?>
<?php if ($req['rule'] === 'block') : ?>
<span class="required">*</span>
<?php $show_required_legend = true; ?>
<?php endif; ?>
</div>
<?php if (!empty($req['require_button'])) : ?>
<button type="button" class="button button-secondary pp-checklists-check-item">
<?php echo esc_html($context['lang']['check']); ?>
<span class="spinner"></span>
</button>
<div class="request-response"></div>
<?php endif; ?>

<input type="hidden"
name="ppch_item_<?php echo esc_attr($key); ?>"
class="ppch_item_requirement"
id="ppch_item_<?php echo esc_attr($key); ?>"
value="<?php echo $req['status'] ? 'yes' : 'no'; ?>"/>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<input type="hidden"
name="ppch_item_<?php echo esc_attr($key); ?>"
class="ppch_item_requirement"
id="ppch_item_<?php echo esc_attr($key); ?>"
value="<?php echo $req['status'] ? 'yes' : 'no'; ?>"/>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>

<?php if ($show_required_legend) : ?>
<em>(*) <?php echo esc_html($context['lang']['required']); ?></em>
<?php if ($show_required_legend) : ?>
<em>(*) <?php echo esc_html($context['lang']['required']); ?></em>
<?php endif; ?>
</div>
<?php endif; ?>
</div>

Expand Down

0 comments on commit ae04aad

Please sign in to comment.