Skip to content
Draft
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
61 changes: 61 additions & 0 deletions src/Logic/PublishPressHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Logic for working with Publish Press
*/

namespace Newspack\MigrationTools\Logic;

use WP_Error;

/**
* PublishPressHelper migration logic.
*/
class PublishPressHelper {

/**
* Set a post to expire using PublishPress Future / post-expirator plugin.
*
* Set a post to a given status or delete it completely at a future date using PublishPress Future / post-expirator
* plugin. This function will cause PublishPress to add the appropriate postmeta `_expiration-date%` (multiple keys) and
* also add a related action in action-scheduler.
*
* @link https://wordpress.org/plugins/post-expirator/
* @link https://publishpress.com/knowledge-base/programmatically-schedule-actions/

* @param int $post_id Post ID.
* @param string $status Options: draft, trash, or delete.
* @param int $epoch_gmt Expiration date in GMT epoch time.
*
* @return bool|WP_Error True or WP_Error.
*/
public static function set_post_expiration( int $post_id, string $status, int $epoch_gmt ): bool|WP_Error {

return new WP_Error( 'ERROR_PUBLISHPRESS_WIP', 'work in progress...do not use yet...' );

if ( ! defined( 'PUBLISHPRESS_FUTURE_LOADED' ) || ! defined( '\PublishPress\Future\Modules\Expirator\HooksAbstract::ACTION_SCHEDULE_POST_EXPIRATION' ) ) {
return new WP_Error( 'ERROR_PUBLISHPRESS', 'PublishPress Future ( post-expirator ) not loaded.' );
}

$options = [
'id' => $post_id,
];

// status: draft, trash, delete
if ( 'delete' === $status ) {
$options['expireType'] = 'delete';
// newStatus not needed since post will be deleted.
} else {
$options['expireType'] = 'change-status';
$options['newStatus'] = $status;
}

do_action(
\PublishPress\Future\Modules\Expirator\HooksAbstract::ACTION_SCHEDULE_POST_EXPIRATION,
$post_id,
$epoch_gmt,
$options
);

return true;
}
}
5 changes: 2 additions & 3 deletions src/Util/FgHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public function __construct( string $type ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

if ( ! is_plugin_active( "fg-{$this->type}-to-wp-premium/fg-{$this->type}-to-wp-premium.php" ) ) {
if ( ! is_plugin_active( "fg-{$this->type}-to-wp-premium/fg-{$this->type}-to-wp-premium.php" )
&& ! is_plugin_active( "fg-{$this->type}-to-wordpress-premium/fg-{$this->type}-to-wordpress-premium.php" ) ) {
NMT::exit_with_message( "FG {$this->type} to WP Premium plugin not found. Install and activate it before using this class." );
}

$this->type = $type;
}

/**
Expand Down
Loading