Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature publishpress statuses integration #1496

Merged
merged 15 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions common/css/publishpress-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ div.pp-icon img {
Status color box */

.pp-status-color {
width: 10px;
height: 10px;
display: inline-block;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-o-border-radius: 3px;
padding: 2px 5px 2px 5px;
}

.pp-status-color + strong {
Expand Down
56 changes: 26 additions & 30 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function module_enabled($slug)
{
global $publishpress;

if ('custom_status' == $slug) {
return class_exists('PublishPress_Statuses');
}

return isset($publishpress->$slug) && $publishpress->$slug->module->options->enabled == 'on';
}

Expand Down Expand Up @@ -180,7 +184,6 @@ public function get_post_types_for_module($module)

/**
* Get all of the currently available post statuses
* This should be used in favor of calling $publishpress->custom_status->get_custom_statuses() directly
*
* @return array $post_statuses All of the post statuses that aren't a published state
*
Expand All @@ -190,11 +193,7 @@ public function get_post_statuses()
{
global $publishpress;

if ($this->module_enabled('custom_status')) {
return $publishpress->custom_status->get_custom_statuses();
} else {
return $this->get_core_post_statuses();
}
return $publishpress->getPostStatuses();
}

/**
Expand All @@ -206,26 +205,22 @@ public function get_post_statuses()
*/
protected function get_core_post_statuses()
{
return [
(object)[
'name' => __('Draft'),
'description' => '',
'slug' => 'draft',
'position' => 1,
],
(object)[
'name' => __('Pending Review'),
'description' => '',
'slug' => 'pending',
'position' => 2,
],
(object)[
'name' => __('Published'),
'description' => '',
'slug' => 'publish',
'position' => 3,
],
];
global $publishpress;

return $publishpress->getCorePostStatuses();
}

/**
* Back compat for existing code calling $publishpress->custom_status->get_custom_status_by()
*
* @return object
*
* @since 4.0
*/
public function get_custom_status_by($field, $value) {
global $publishpres;

return $publishpress->getPostStatusBy($field, $value);
}

/**
Expand Down Expand Up @@ -273,11 +268,12 @@ public function get_post_status_friendly_name($status)
];

// Custom statuses only handles workflow statuses
if ($this->module_enabled('custom_status')
&& !in_array($status, ['publish', 'future', 'private', 'trash'])) {
$status_object = $publishpress->custom_status->get_custom_status_by('slug', $status);
if (!in_array($status, ['publish', 'future', 'private', 'trash'])) {

$status_object = $publishpress->getStatusBy('slug', $status);

if ($status_object && !is_wp_error($status_object)) {
$status_friendly_name = $status_object->name;
$status_friendly_name = $status_object->label;
}
} elseif (array_key_exists($status, $builtin_stati)) {
$status_friendly_name = $builtin_stati[$status];
Expand Down
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', '3.12.2');
define('PUBLISHPRESS_VERSION', '4.0.0-rc');
define('PUBLISHPRESS_BASE_PATH', __DIR__);
define('PUBLISHPRESS_VIEWS_PATH', __DIR__ . '/views');
define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_BASE_PATH . '/publishpress.php');
Expand Down
4 changes: 2 additions & 2 deletions lib/Notifications/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private function get_post_field($post, $field, $attrs)

case 'old_status':
case 'new_status':
$status = $publishpress->custom_status->get_custom_status_by(
$status = $publishpress->getPostStatusBy(
'slug',
$this->event_args['params'][$field]
);
Expand All @@ -437,7 +437,7 @@ private function get_post_field($post, $field, $attrs)
break;
}

$result = $status->name;
$result = $status->label;
break;

case 'content':
Expand Down
36 changes: 9 additions & 27 deletions lib/Notifications/Traits/PublishPress_Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ trait PublishPress_Module
*/
public function get_post_statuses()
{
if ($this->is_module_enabled('custom_status')) {
$publishpress = $this->get_service('publishpress');
$statuses = $publishpress->custom_status->get_custom_statuses();
$publishpress = $this->get_service('publishpress');

return $statuses;
} else {
return $this->get_core_post_statuses();
}
return $publishpress->getPostStatuses();
}

/**
Expand All @@ -36,6 +31,10 @@ public function get_post_statuses()
*/
public function is_module_enabled($slug)
{
if ('custom_status' == $slug) {
return class_exists('PublishPress_Statuses');
}

$publishpress = $this->get_service('publishpress');

if (isset($publishpress->$slug)) {
Expand All @@ -58,26 +57,9 @@ public function is_module_enabled($slug)
*/
protected function get_core_post_statuses()
{
return [
(object)[
'name' => __('Draft'),
'description' => '',
'slug' => 'draft',
'position' => 1,
],
(object)[
'name' => __('Pending Review'),
'description' => '',
'slug' => 'pending',
'position' => 2,
],
(object)[
'name' => __('Published'),
'description' => '',
'slug' => 'publish',
'position' => 3,
],
];
$publishpress = $this->get_service('publishpress');

return $publishpress->getCorePostStatuses();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function get_options($group)
foreach ($statuses as $status) {
$options[] = [
'value' => esc_attr($status->slug),
'label' => esc_html($status->name),
'label' => esc_html($status->label),
'selected' => in_array($status->slug, $metadata[$group]),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ public function filter_action_params_for_log($paramsString, $log)
if ($log->event === static::EVENT_NAME) {
global $publishpress;

$oldStatus = $publishpress->custom_status->get_custom_status_by('slug', $log->oldStatus);
$newStatus = $publishpress->custom_status->get_custom_status_by('slug', $log->newStatus);
$oldStatus = $publishpress->getPostStatusBy('slug', $log->oldStatus);
$newStatus = $publishpress->getPostStatusBy('slug', $log->newStatus);

$paramsString = '';
if (is_object($oldStatus)) {
$paramsString .= '<div>' . sprintf(__('Old post status: %s', 'publishpress'), $oldStatus->name) . '</div>';
$paramsString .= '<div>' . sprintf(__('Old post status: %s', 'publishpress'), $oldStatus->label) . '</div>';
}

if (is_object($newStatus)) {
$paramsString .= '<div>' . sprintf(__('New post status: %s', 'publishpress'), $newStatus->name) . '</div>';
$paramsString .= '<div>' . sprintf(__('New post status: %s', 'publishpress'), $newStatus->label) . '</div>';
}
}

Expand Down
63 changes: 63 additions & 0 deletions lib/vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,67 @@

return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'Sabre\\VObject\\Cli' => $vendorDir . '/sabre/vobject/lib/Cli.php',
'Sabre\\VObject\\Component' => $vendorDir . '/sabre/vobject/lib/Component.php',
'Sabre\\VObject\\Component\\Available' => $vendorDir . '/sabre/vobject/lib/Component/Available.php',
'Sabre\\VObject\\Component\\VAlarm' => $vendorDir . '/sabre/vobject/lib/Component/VAlarm.php',
'Sabre\\VObject\\Component\\VAvailability' => $vendorDir . '/sabre/vobject/lib/Component/VAvailability.php',
'Sabre\\VObject\\Component\\VCalendar' => $vendorDir . '/sabre/vobject/lib/Component/VCalendar.php',
'Sabre\\VObject\\Component\\VCard' => $vendorDir . '/sabre/vobject/lib/Component/VCard.php',
'Sabre\\VObject\\Component\\VEvent' => $vendorDir . '/sabre/vobject/lib/Component/VEvent.php',
'Sabre\\VObject\\Component\\VFreeBusy' => $vendorDir . '/sabre/vobject/lib/Component/VFreeBusy.php',
'Sabre\\VObject\\Component\\VJournal' => $vendorDir . '/sabre/vobject/lib/Component/VJournal.php',
'Sabre\\VObject\\Component\\VTimeZone' => $vendorDir . '/sabre/vobject/lib/Component/VTimeZone.php',
'Sabre\\VObject\\Component\\VTodo' => $vendorDir . '/sabre/vobject/lib/Component/VTodo.php',
'Sabre\\VObject\\DateTimeParser' => $vendorDir . '/sabre/vobject/lib/DateTimeParser.php',
'Sabre\\VObject\\Document' => $vendorDir . '/sabre/vobject/lib/Document.php',
'Sabre\\VObject\\ElementList' => $vendorDir . '/sabre/vobject/lib/ElementList.php',
'Sabre\\VObject\\EofException' => $vendorDir . '/sabre/vobject/lib/EofException.php',
'Sabre\\VObject\\FreeBusyGenerator' => $vendorDir . '/sabre/vobject/lib/FreeBusyGenerator.php',
'Sabre\\VObject\\ITip\\Broker' => $vendorDir . '/sabre/vobject/lib/ITip/Broker.php',
'Sabre\\VObject\\ITip\\ITipException' => $vendorDir . '/sabre/vobject/lib/ITip/ITipException.php',
'Sabre\\VObject\\ITip\\Message' => $vendorDir . '/sabre/vobject/lib/ITip/Message.php',
'Sabre\\VObject\\ITip\\SameOrganizerForAllComponentsException' => $vendorDir . '/sabre/vobject/lib/ITip/SameOrganizerForAllComponentsException.php',
'Sabre\\VObject\\Node' => $vendorDir . '/sabre/vobject/lib/Node.php',
'Sabre\\VObject\\Parameter' => $vendorDir . '/sabre/vobject/lib/Parameter.php',
'Sabre\\VObject\\ParseException' => $vendorDir . '/sabre/vobject/lib/ParseException.php',
'Sabre\\VObject\\Parser\\Json' => $vendorDir . '/sabre/vobject/lib/Parser/Json.php',
'Sabre\\VObject\\Parser\\MimeDir' => $vendorDir . '/sabre/vobject/lib/Parser/MimeDir.php',
'Sabre\\VObject\\Parser\\Parser' => $vendorDir . '/sabre/vobject/lib/Parser/Parser.php',
'Sabre\\VObject\\Property' => $vendorDir . '/sabre/vobject/lib/Property.php',
'Sabre\\VObject\\Property\\Binary' => $vendorDir . '/sabre/vobject/lib/Property/Binary.php',
'Sabre\\VObject\\Property\\Boolean' => $vendorDir . '/sabre/vobject/lib/Property/Boolean.php',
'Sabre\\VObject\\Property\\FlatText' => $vendorDir . '/sabre/vobject/lib/Property/FlatText.php',
'Sabre\\VObject\\Property\\FloatValue' => $vendorDir . '/sabre/vobject/lib/Property/FloatValue.php',
'Sabre\\VObject\\Property\\ICalendar\\CalAddress' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/CalAddress.php',
'Sabre\\VObject\\Property\\ICalendar\\Date' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/Date.php',
'Sabre\\VObject\\Property\\ICalendar\\DateTime' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/DateTime.php',
'Sabre\\VObject\\Property\\ICalendar\\Duration' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/Duration.php',
'Sabre\\VObject\\Property\\ICalendar\\Period' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/Period.php',
'Sabre\\VObject\\Property\\ICalendar\\Recur' => $vendorDir . '/sabre/vobject/lib/Property/ICalendar/Recur.php',
'Sabre\\VObject\\Property\\IntegerValue' => $vendorDir . '/sabre/vobject/lib/Property/IntegerValue.php',
'Sabre\\VObject\\Property\\Text' => $vendorDir . '/sabre/vobject/lib/Property/Text.php',
'Sabre\\VObject\\Property\\Time' => $vendorDir . '/sabre/vobject/lib/Property/Time.php',
'Sabre\\VObject\\Property\\Unknown' => $vendorDir . '/sabre/vobject/lib/Property/Unknown.php',
'Sabre\\VObject\\Property\\Uri' => $vendorDir . '/sabre/vobject/lib/Property/Uri.php',
'Sabre\\VObject\\Property\\UtcOffset' => $vendorDir . '/sabre/vobject/lib/Property/UtcOffset.php',
'Sabre\\VObject\\Property\\VCard\\Date' => $vendorDir . '/sabre/vobject/lib/Property/VCard/Date.php',
'Sabre\\VObject\\Property\\VCard\\DateAndOrTime' => $vendorDir . '/sabre/vobject/lib/Property/VCard/DateAndOrTime.php',
'Sabre\\VObject\\Property\\VCard\\DateTime' => $vendorDir . '/sabre/vobject/lib/Property/VCard/DateTime.php',
'Sabre\\VObject\\Property\\VCard\\LanguageTag' => $vendorDir . '/sabre/vobject/lib/Property/VCard/LanguageTag.php',
'Sabre\\VObject\\Property\\VCard\\TimeStamp' => $vendorDir . '/sabre/vobject/lib/Property/VCard/TimeStamp.php',
'Sabre\\VObject\\Reader' => $vendorDir . '/sabre/vobject/lib/Reader.php',
'Sabre\\VObject\\Recur\\EventIterator' => $vendorDir . '/sabre/vobject/lib/Recur/EventIterator.php',
'Sabre\\VObject\\Recur\\NoInstancesException' => $vendorDir . '/sabre/vobject/lib/Recur/NoInstancesException.php',
'Sabre\\VObject\\Recur\\RDateIterator' => $vendorDir . '/sabre/vobject/lib/Recur/RDateIterator.php',
'Sabre\\VObject\\Recur\\RRuleIterator' => $vendorDir . '/sabre/vobject/lib/Recur/RRuleIterator.php',
'Sabre\\VObject\\RecurrenceIterator' => $vendorDir . '/sabre/vobject/lib/RecurrenceIterator.php',
'Sabre\\VObject\\Splitter\\ICalendar' => $vendorDir . '/sabre/vobject/lib/Splitter/ICalendar.php',
'Sabre\\VObject\\Splitter\\SplitterInterface' => $vendorDir . '/sabre/vobject/lib/Splitter/SplitterInterface.php',
'Sabre\\VObject\\Splitter\\VCard' => $vendorDir . '/sabre/vobject/lib/Splitter/VCard.php',
'Sabre\\VObject\\StringUtil' => $vendorDir . '/sabre/vobject/lib/StringUtil.php',
'Sabre\\VObject\\TimeZoneUtil' => $vendorDir . '/sabre/vobject/lib/TimeZoneUtil.php',
'Sabre\\VObject\\UUIDUtil' => $vendorDir . '/sabre/vobject/lib/UUIDUtil.php',
'Sabre\\VObject\\VCardConverter' => $vendorDir . '/sabre/vobject/lib/VCardConverter.php',
'Sabre\\VObject\\Version' => $vendorDir . '/sabre/vobject/lib/Version.php',
);
Loading
Loading