Skip to content

Commit

Permalink
Add "New Post" feature to content overview
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed Apr 3, 2024
1 parent c5fc325 commit a76bc46
Show file tree
Hide file tree
Showing 7 changed files with 607 additions and 152 deletions.
40 changes: 40 additions & 0 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,5 +803,45 @@ public static function isPublishPressModuleEnabled($module_slug)
return isset($publishpress->{$module_slug})
&& $publishpress->{$module_slug}->module->options->enabled === 'on';
}

public function getUserAuthorizedPostStatusOptions($postType)
{
$postStatuses = $this->getPostStatusOptions();

foreach ($postStatuses as $index => $status) {
// Filter publishing posts if the post type is set
if (in_array($status['value'], ['publish', 'future', 'private'])) {
$postTypeObj = get_post_type_object($postType);
if (! current_user_can($postTypeObj->cap->publish_posts)) {
unset($postStatuses[$index]);
}
}
}

return $postStatuses;
}

public function getPostStatusOptions()
{
$postStatuses = [];
$post_statuses_terms = get_terms('post_status', ['hide_empty' => false]);
$post_statuses_terms_slugs = (!is_wp_error($post_statuses_terms)) ? array_column($post_statuses_terms, 'slug') : [];
foreach ($this->get_post_statuses() as $status) {
//add support for capabilities custom statuses
if (defined('PUBLISHPRESS_CAPS_PRO_VERSION')
&& !empty(get_option('cme_custom_status_control'))
&& in_array($status->slug, $post_statuses_terms_slugs)
&& !current_user_can('status_change_' . $status->slug)
) {
continue;
}
$postStatuses[] = [
'value' => esc_attr($status->slug),
'text' => esc_html($status->label),
];
}

return $postStatuses;
}
}
}
2 changes: 1 addition & 1 deletion includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if (! defined('PP_LOADED')) {
if (! defined('PUBLISHPRESS_VERSION')) {
// Define constants
define('PUBLISHPRESS_VERSION', '4.0.4-beta');
define('PUBLISHPRESS_VERSION', '4.0.4-beta.2');
define('PUBLISHPRESS_BASE_PATH', __DIR__);
define('PUBLISHPRESS_VIEWS_PATH', __DIR__ . '/views');
define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_BASE_PATH . '/publishpress.php');
Expand Down
40 changes: 0 additions & 40 deletions modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,46 +529,6 @@ private function currentUserCanViewCalendar()
return current_user_can($this->getViewCapability());
}

protected function getPostStatusOptions()
{
$postStatuses = [];
$post_statuses_terms = get_terms('post_status', ['hide_empty' => false]);
$post_statuses_terms_slugs = (!is_wp_error($post_statuses_terms)) ? array_column($post_statuses_terms, 'slug') : [];
foreach ($this->get_post_statuses() as $status) {
//add support for capabilities custom statuses
if (defined('PUBLISHPRESS_CAPS_PRO_VERSION')
&& !empty(get_option('cme_custom_status_control'))
&& in_array($status->slug, $post_statuses_terms_slugs)
&& !current_user_can('status_change_' . $status->slug)
) {
continue;
}
$postStatuses[] = [
'value' => esc_attr($status->slug),
'text' => esc_html($status->label),
];
}

return $postStatuses;
}

protected function getUserAuthorizedPostStatusOptions($postType)
{
$postStatuses = $this->getPostStatusOptions();

foreach ($postStatuses as $index => $status) {
// Filter publishing posts if the post type is set
if (in_array($status['value'], ['publish', 'future', 'private'])) {
$postTypeObj = get_post_type_object($postType);
if (! current_user_can($postTypeObj->cap->publish_posts)) {
unset($postStatuses[$index]);
}
}
}

return $postStatuses;
}

/**
* Add any necessary JS to the WordPress admin
*
Expand Down
Loading

0 comments on commit a76bc46

Please sign in to comment.