Skip to content

Commit

Permalink
feature/#639_ACF_Integration_Support (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
richaferry authored Sep 20, 2024
1 parent f2b2b0e commit 1c74652
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 295 deletions.
47 changes: 24 additions & 23 deletions core/Legacy/Module.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package PublishPress\Checklistss
* @author PublishPress <[email protected]>
Expand Down Expand Up @@ -53,9 +54,9 @@ public function clearPostTypesOptions($modulePostTypes = [], $postTypeSupport =
$allPostTypes = array_keys($this->getAllPostTypes());
foreach ($allPostTypes as $postType) {
if ((isset($modulePostTypes[$postType]) && $modulePostTypes[$postType] == 'on') || post_type_supports(
$postType,
$postTypeSupport
)) {
$postType,
$postTypeSupport
)) {
$normalizedPostTypeOptions[$postType] = 'on';
} else {
$normalizedPostTypeOptions[$postType] = 'off';
Expand Down Expand Up @@ -222,8 +223,8 @@ public function printDefaultHeader($current_module, $custom_text = null)

if ($message && isset($current_module->messages[$message])) {
$display_text .= '<div class="is-dismissible notice notice-info"><p>' . esc_html(
$current_module->messages[$message]
) . '</p></div>';
$current_module->messages[$message]
) . '</p></div>';
}

// If there's been an error, let's display it
Expand All @@ -238,31 +239,31 @@ public function printDefaultHeader($current_module, $custom_text = null)
}
if ($error && isset($current_module->messages[$error])) {
$display_text .= '<div class="is-dismissible notice notice-error"><p>' . esc_html(
$current_module->messages[$error]
) . '</p></div>';
$current_module->messages[$error]
) . '</p></div>';
}
?>
?>

<div class="publishpress-checklists-admin pressshack-admin-wrapper wrap">
<header>
<h1 class="wp-heading-inline"><?php echo esc_html($current_module->title); ?></h1>
<header>
<h1 class="wp-heading-inline"><?php echo esc_html($current_module->title); ?></h1>

<?php echo !empty($display_text) ? esc_html($display_text) : ''; ?>
<?php // We keep the H2 tag to keep notices tied to the header
?>
<h2>
<?php echo !empty($display_text) ? esc_html($display_text) : ''; ?>
<?php // We keep the H2 tag to keep notices tied to the header
?>
<h2>

<?php if ($current_module->short_description && empty($custom_text)): ?>
<?php echo esc_html($current_module->short_description); ?>
<?php endif; ?>
<?php if ($current_module->short_description && empty($custom_text)): ?>
<?php echo esc_html($current_module->short_description); ?>
<?php endif; ?>

<?php if (!empty($custom_text)) : ?>
<?php echo esc_html($custom_text); ?>
<?php endif; ?>
</h2>
<?php if (!empty($custom_text)) : ?>
<?php echo esc_html($custom_text); ?>
<?php endif; ?>
</h2>

</header>
<?php
</header>
<?php
}

/**
Expand Down
31 changes: 17 additions & 14 deletions core/Legacy/Util.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package PublishPress\Checklistss
* @author PublishPress <[email protected]>
Expand Down Expand Up @@ -31,9 +32,11 @@ public static function getCurrentPostType()
$post_type = $current_screen->post_type;
} elseif (isset($_REQUEST['post_type'])) {
$post_type = sanitize_key($_REQUEST['post_type']);
} elseif ('post.php' == $pagenow
} elseif (
'post.php' == $pagenow
&& $post_id
&& !empty(get_post($post_id)->post_type)) {
&& !empty(get_post($post_id)->post_type)
) {
$post_type = get_post($post_id)->post_type;
} elseif ('edit.php' == $pagenow && empty($_REQUEST['post_type'])) {
$post_type = 'post';
Expand Down Expand Up @@ -167,7 +170,7 @@ private static function getDirectorySeparator()
*/
public static function ppch_pro_sidebar()
{
?>
?>
<div class="ppch-advertisement-right-sidebar">
<div class="advertisement-box-content postbox ppch-advert">
<div class="postbox-header ppch-advert">
Expand Down Expand Up @@ -222,16 +225,16 @@ class="advert-link" href="https://publishpress.com/docs-category/checklists/" ta
</div>
</div>
</div><?php
}
}

/**
* Check if Checklists Pro active
*/
public static function isChecklistsProActive()
{
if (defined('PPCHPRO_VERSION')) {
return true;
/**
* Check if Checklists Pro active
*/
public static function isChecklistsProActive()
{
if (defined('PPCHPRO_VERSION')) {
return true;
}
return false;
}
}
return false;
}
}
9 changes: 7 additions & 2 deletions modules/checklists/assets/css/admin-pages.css
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,13 @@ textarea.pp-checklists-custom-item-title {
}

.pp-checklists-tabs-wrapper .pp-checklists-tabs ul {
display: none;
padding-top: 0;
margin-top: 0;

&.active {
display: block;
}
}

.pp-checklists-tabs-wrapper .pp-checklists-tabs ul li a {
Expand All @@ -430,7 +435,7 @@ textarea.pp-checklists-custom-item-title {
}

.pp-checklists-tabs-wrapper .pp-checklists-tabs ul li a span {
margin-right: 0.618em;
margin-right: 0.1em;
}

.pp-checklists-tabs-wrapper .pp-checklists-tabs ul li a span.dashicons {
Expand All @@ -440,7 +445,7 @@ textarea.pp-checklists-custom-item-title {
}

.pp-checklists-tabs-wrapper .pp-checklists-tabs {
min-width: 160px;
min-width: 180px;
margin: 0;
line-height: 1em;
padding: 0 0 10px;
Expand Down
27 changes: 19 additions & 8 deletions modules/checklists/assets/js/global-checklists.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,31 @@
* @param {string} post_type
*/
function show_post_type_requirements(post_type) {
// Hide the requirements which are not for the current post type
$('#pp-checklists-requirements tr.pp-checklists-requirement-row').hide();
// Display the correct requirements
$('#pp-checklists-requirements tr.ppch-title-group[data-post-type="' + post_type + '"]').show();
// Mark the filter as selected
$('#pp-checklists-post-type-filter li.nav-tab-active').removeClass('nav-tab-active');
$('#pp-checklists-post-type-filter li.post-type-' + post_type).addClass('nav-tab-active');

$('.pp-checklists-tabs-list li a').removeClass('active');

//remove active class from all tabs
$('.pp-checklists-tabs a').removeClass('active');

$('.pp-checklists-tabs ul').removeClass('active');
$('.pp-checklists-tabs ul#list-' + post_type).addClass('active');

//add active class to title tab
$('.pp-checklists-tabs a[data-tab="title"]').addClass('active');
$('.pp-checklists-tabs li:first-child a').addClass('active');

// Mark the filter as selected
$('#pp-checklists-post-type-filter li.nav-tab-active').removeClass('nav-tab-active');
$('#pp-checklists-post-type-filter li.post-type-' + post_type).addClass('nav-tab-active');
const current_data_tab =
$('#list-' + post_type)
.find('li a.active')
.attr('data-tab') || 'title';
// Hide the requirements which are not for the current post type
$('#pp-checklists-requirements tr.pp-checklists-requirement-row').hide();
// Display the correct requirements
$(
'#pp-checklists-requirements tr.ppch-' + current_data_tab + '-group[data-post-type="' + post_type + '"]',
).show();
}

/**
Expand Down
51 changes: 30 additions & 21 deletions modules/checklists/checklists.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package PublishPress
* @author PublishPress
Expand Down Expand Up @@ -164,7 +165,7 @@ public function migrateLegacyOptions()
if (!(bool)get_option(self::FLAG_OPTIONS_MIGRATED_2_6_0) && function_exists('get_role')) {
//add newly introduced checklist role for roles with manage_options
$all_roles = $wp_roles->roles;
if(is_array($all_roles) && !empty($all_roles)) {
if (is_array($all_roles) && !empty($all_roles)) {
foreach ($all_roles as $role => $details) {
$role = get_role($role);
if ($role->has_cap('manage_options') || $role->name === 'administrator') {
Expand Down Expand Up @@ -358,7 +359,7 @@ public function filter_post_type_requirements($requirements, $post_type)

$taxonomies_map = [
'category' => [
'\\PublishPress\\Checklists\\Core\\Requirement\\Categories_count',
'\\PublishPress\\Checklists\\Core\\Requirement\\Categories_count',
'\\PublishPress\\Checklists\\Core\\Requirement\\Required_categories',
'\\PublishPress\\Checklists\\Core\\Requirement\\Prohibited_categories',
],
Expand Down Expand Up @@ -459,7 +460,7 @@ public function init()
add_filter('publishpress_checklists_rules_list', [$this, 'filterRulesList']);

add_filter('publishpress_checklists_requirement_list', [$this, 'filterRequirementsRule'], 1000);

// Redirect on plugin activation
add_action('admin_init', [$this, 'redirect_on_activate'], 2000);
}
Expand All @@ -469,18 +470,14 @@ public function init()
*
* @since 0.7
*/
public function install()
{
}
public function install() {}

/**
* Upgrade our data in case we need to
*
* @since 0.7
*/
public function upgrade($previous_version)
{
}
public function upgrade($previous_version) {}

/**
* Generate a link to one of the editorial metadata actions
Expand Down Expand Up @@ -781,8 +778,8 @@ public function display_meta_box($post)
'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' ),
'configure_url' => esc_url( $this->get_admin_link() ),
'user_can_manage_options' => current_user_can('manage_options'),
'configure_url' => esc_url($this->get_admin_link()),
]
);

Expand Down Expand Up @@ -872,15 +869,18 @@ public function save_post_meta_box($id, $post)
{
// Authentication checks: make sure data came from our meta box and that the current user is allowed to edit the post
// TODO: switch to using check_admin_referrer? See core (e.g. edit.php) for usage
if (!isset($_POST[self::METADATA_TAXONOMY . "_nonce"])
|| !wp_verify_nonce(sanitize_key($_POST[self::METADATA_TAXONOMY . "_nonce"]), __FILE__)) {
if (
!isset($_POST[self::METADATA_TAXONOMY . "_nonce"])
|| !wp_verify_nonce(sanitize_key($_POST[self::METADATA_TAXONOMY . "_nonce"]), __FILE__)
) {
return $id;
}

if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|| !array_key_exists($post->post_type, $this->getSelectedPostTypes())
|| $post->post_type == 'post' && !current_user_can('edit_post', $id)
|| $post->post_type == 'page' && !current_user_can('edit_page', $id)) {
|| $post->post_type == 'page' && !current_user_can('edit_page', $id)
) {
return $id;
}

Expand Down Expand Up @@ -1151,7 +1151,7 @@ protected function instantiate_custom_items_to_validate_settings($new_options)
}
}
}

if (isset($new_options['openai_items']) && !empty($new_options['openai_items'])) {
foreach ($new_options['openai_items'] as $id) {
if (isset($new_options[$id . '_title'])) {
Expand Down Expand Up @@ -1179,10 +1179,10 @@ protected function sanitize_checklists_options($new_options)

//option value is an array of keys => $value pair
$sanitized_value = [];
foreach($option_value as $option_value_key => $option_value_value){
foreach ($option_value as $option_value_key => $option_value_value) {
$sanitized_value[sanitize_key($option_value_key)] = is_array($option_value_value) ? array_map('sanitize_text_field', $option_value_value) : sanitize_text_field($option_value_value);
}

//unset original option sanitize_key can potentially change key value if they are manipulated ?
unset($new_options[$option_key]);

Expand All @@ -1192,7 +1192,7 @@ protected function sanitize_checklists_options($new_options)

return $new_options;
}

/**
* Rearrange the requirements array by custom order
*
Expand Down Expand Up @@ -1229,7 +1229,7 @@ protected function rearrange_requirement_array($requirements, $is_on_metabox = t

return $new_requirements_array;
}


/**
* Redirect user on plugin activation
Expand All @@ -1242,7 +1242,7 @@ public function redirect_on_activate()
delete_option('ppch_activated');
wp_redirect(admin_url("admin.php?page=ppch-checklists"));
exit;
}
}
}

/**
Expand All @@ -1252,8 +1252,17 @@ public function retrieveFieldTabs()
{
// Get the singleton instance
$fieldsTabs = FieldsTabs::getInstance();
$postTypes = $this->get_post_types();
$allFieldsTabs = $fieldsTabs->getFieldsTabs();
$filteredFieldsTabs = array_filter($allFieldsTabs, function ($_, $key) {
return !in_array($key, ['advanced-custom-fields', 'woocommerce']);
}, ARRAY_FILTER_USE_BOTH);
$result = [];
foreach ($postTypes as $key => $postType) {
$result[$key] = $filteredFieldsTabs;
}

$this->field_tabs = $fieldsTabs->getFieldsTabs();
$this->field_tabs = apply_filters('publishpress_checklists_filter_field_tabs', $result, $allFieldsTabs);
}
}
}
Loading

0 comments on commit 1c74652

Please sign in to comment.