Commit 187ed252 authored by Rolf Forst's avatar Rolf Forst
Browse files

Add plugin update class

parent 0858505f
...@@ -14,6 +14,9 @@ class Main ...@@ -14,6 +14,9 @@ class Main
add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']); add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts']);
$update = new Update();
$update->update_version();
$settings = new Settings(); $settings = new Settings();
$expiration = new Expiration(); $expiration = new Expiration();
} }
......
<?php
namespace RRZE\PostExpiration;
defined('ABSPATH') || exit;
class Update
{
protected $version_option_name = 'rrze_post_expiration_version';
public function update_version()
{
$version = get_option($this->version_option_name, '0');
if (version_compare($version, '1.4.0', '<')) {
$this->update_expired_posts();
update_option($this->version_option_name, '1.4.0');
}
}
protected function update_expired_posts()
{
global $wpdb;
$current_date = current_time('mysql');
$result = $wpdb->get_results(
$wpdb->prepare(
"SELECT post_id FROM {$wpdb->postmeta} as postmeta
LEFT JOIN {$wpdb->posts} as posts ON postmeta.post_id = posts.ID
WHERE posts.post_status = 'draft' AND (posts.post_type = 'post' OR posts.post_type = 'page')
AND postmeta.meta_key = 'expiration_date'
AND postmeta.meta_value < %s",
$current_date
)
);
if (!empty($result)) {
$plugins = new Plugins();
foreach ($result as $row) {
wp_update_post(['ID' => $row->post_id, 'post_status' => 'expired']);
// rrze cache plugin support
$plugins->flush_rrze_cache(get_permalink($row->post_id));
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment