Skip to content

Commit

Permalink
Added v1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayan Datta committed Jul 5, 2023
1 parent b6caf23 commit e07b742
Show file tree
Hide file tree
Showing 80 changed files with 1,423 additions and 6,762 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.5.1
Release Date: 5th July, 2023

### Premium Version
* Improved: URL support for Twitter OAuth.
* Improved: Applied RevivePress namespace to composer packages to avoid potential conflicts.
* Fixed: Twitter API v2 Issues.
* And all Free Version Improvements and Fixes.

### Free Version
* Updated: PHP Composer Libraries.
* Updated: Freemius SDK to v2.5.10.
* Updated: Action Schedular Library to v3.6.1.
* Improved: Added high priority to execute action events properly along with other plugins.
* Improved: Auto Regenerate republish events on deletion of the action scheduler events.
* Tweak: Reduced republish batch interval to 10 seconds from 15 seconds.
* Fixed: Action Schedular menu item link.
* Fixed: Some non-translated strings.
* Compatibility with WordPress v6.3.

## 1.5.0
Release Date: 20th April, 2023

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"RevivePress\\": "./includes"
"RevivePress\\": "includes/"
},
"files": [
"vendor/woocommerce/action-scheduler/action-scheduler.php",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions includes/Base/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function menu_items() {
public function do_footer() { ?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
let rvpTaskItem = $( "ul#adminmenu a[href*='revivepress-scheduled-tasks']" );
let rvpTaskItem = $( "ul#adminmenu .toplevel_page_revivepress ul.wp-submenu li a[href*='revivepress-scheduled-tasks']" );
rvpTaskItem.attr( { target: '_blank', href: rvpTaskItem.attr( 'href' ) + '&status=pending&s=wpar' } );
} );
</script>
Expand All @@ -99,7 +99,7 @@ public function meta_links( $links, $file ) {
public function admin_footer( $content ) {
$current_screen = get_current_screen();
if ( 'toplevel_page_revivepress' === $current_screen->id ) {
$content = sprintf( __( 'Thank you for using <a href="%s" target="_blank" style="font-weight: 500;">RevivePress</a>', 'wp-auto-republish' ), 'https://wprevivepress.com/' );
$content = __( 'Thank you for using', 'wp-auto-republish' ) . ' <a href="https://wprevivepress.com/" target="_blank" style="font-weight: 500;">RevivePress</a>';
$content .= ' &bull; <a href="https://wordpress.org/support/plugin/wp-auto-republish/reviews/?filter=5#new-post" target="_blank" style="font-weight: 500;">' . __( 'Rate it', 'wp-auto-republish' ) . '</a> (<span style="color:#ffa000;">★★★★★</span>) on WordPress.org, if you like this plugin.</span>';
$content = '<span class="wpar-footer">' . $content . '</span>';
}
Expand Down
45 changes: 30 additions & 15 deletions includes/Core/FetchPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function check_and_create_tasks() {
$in_process = get_transient( 'wpar_in_progress' );

if ( $this->valid_next_run() && ! $in_process ) {
// Lock the process to prevent duplicate schedules for 30 seconds.
set_transient( 'wpar_in_progress', true, 30 );
// Update timestamp refenrance.
// Lock the process to prevent duplicate schedules.
set_transient( 'wpar_in_progress', true, $this->get_interval() );
// Update timestamp reference.
update_option( 'wpar_last_global_cron_run', $this->current_timestamp() );
// Create Tasks.
$this->create_tasks();
Expand All @@ -107,20 +107,24 @@ public function check_and_create_tasks() {
*/
private function create_tasks() {
$post_types = $this->get_data( 'wpar_post_types', [ 'post' ] );

$counter = 0;
// delete storage if exists.
delete_option( 'wpar_global_republish_post_ids' );
if ( ! empty($post_types) ) {
$counter = 0;
foreach ( $post_types as $post_type ) {

if ( ! $this->has_future_posts( $post_type ) ) {
$counter++;
$this->schedule_single_action( time() + 30 * ($counter / 2), 'wpar/global_republish_flat_posts', [ $post_type ] );
$this->schedule_single_action( time() + 10 * ($counter / 2), 'wpar/global_republish_flat_posts', [ $post_type ] );
}
}
if ( $counter > 0 ) {
// Check for posts.
$this->schedule_single_action( time() + 30 * (($counter + 1) / 2), 'wpar/global_republish_flat_posts_completed' );
}
}
// Check for posts.

if ( $counter > 0 ) {
$this->schedule_single_action( time() + 10 * (($counter + 1) / 2), 'wpar/global_republish_flat_posts_completed' );
} else {
delete_transient( 'wpar_in_progress' );
}

}
Expand Down Expand Up @@ -203,7 +207,7 @@ public function query_posts( string $post_type ) {
}

/**
* Complete
* Complete republish tasks.
*/
public function complete() {
$timestamp = $this->current_timestamp();
Expand Down Expand Up @@ -243,6 +247,8 @@ public function complete() {

// delete temp storage
delete_option( 'wpar_global_republish_post_ids' );
// remove transient
delete_transient( 'wpar_in_progress' );
}

/**
Expand All @@ -266,12 +272,14 @@ public function set_schedule( array $post_ids ) {
// delete previosly scheduled hook if exists any.
$this->unschedule_all_actions( 'wpar/global_republish_single_post', [ $post_id ] );
// schedule single post republish event
$this->schedule_single_action( $utc_timestamp, 'wpar/global_republish_single_post', [ $post_id ] );
$action_id = $this->schedule_single_action( $utc_timestamp, 'wpar/global_republish_single_post', [ $post_id ] );
// Convert to local timestamp
$local_datetime = get_date_from_gmt( date( 'Y-m-d H:i:s', $utc_timestamp ) );
// update required post metas
$this->update_meta( $post_id, 'wpar_global_republish_status', 'pending' );
$this->update_meta( $post_id, '_wpar_global_republish_datetime', $local_datetime );
// store action id
$this->update_meta( $post_id, 'wpar_republish_as_action_id', $action_id );
// update reference
$this->set_limit( $post_id );
}
Expand All @@ -292,14 +300,21 @@ private function next_schedule( int $timestamp, string $format = 'GMT' ) {
return ( 'local' === $format ? $formatted_date : get_gmt_from_date( $formatted_date, 'U' ) );
}

/**
* Check if current run is actually eligible.
*/
private function get_interval() {
$interval = $this->get_data( 'wpar_minimun_republish_interval', 3600 );
return ( $interval >= 86400 ? 3600 : $interval );
}

/**
* Check if current run is actually eligible.
*/
private function valid_next_run() {
$last = get_option( 'wpar_last_global_cron_run' );
$current_time = $this->current_timestamp();
$interval = $this->get_data( 'wpar_minimun_republish_interval', 3600 );
$interval = ( $interval >= 86400 ? 3600 : $interval );
$interval = $this->get_interval();
$proceed = false;
// switch
if ( $this->slot_available() ) {
Expand Down Expand Up @@ -375,7 +390,7 @@ private function has_future_posts( string $post_type ) {
if ( ! $can_check ) {
return false;
}
// cureent timestmap
// current timestamp
$timestamp = $this->current_timestamp();
$args = $this->do_filter( 'has_future_post_args', [
'numberposts' => -1,
Expand Down
18 changes: 13 additions & 5 deletions includes/Core/PostRepublish.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PostRepublish
public function register() {
$this->action( 'wpar/global_republish_single_post', 'do_republish' );
$this->action( 'wpar/process_republish_post', 'call_republish' );
$this->action( 'wpar/as_action_removed', 'remove_meta' );
}

/**
Expand Down Expand Up @@ -55,16 +56,24 @@ public function call_republish( array $args ) {
* @param int $post_id Post ID
*/
public function do_republish( $post_id ) {
// delete metas
// delete data.
$this->delete_meta( $post_id, 'wpar_global_republish_status' );
$this->delete_meta( $post_id, '_wpar_global_republish_datetime' );
$this->delete_meta( $post_id, 'wpar_filter_republish_status' );
$this->delete_meta( $post_id, '_wpar_filter_republish_datetime' );
$this->delete_meta( $post_id, 'wpar_republish_rule_action' );
$this->remove_meta( $post_id );
// Republish.
$this->handle( (int) $post_id );
}

/**
* Delete post meta data flags.
*
* @since 1.5.1
* @param int $post_id Post ID
*/
public function remove_meta( $post_id ) {
$this->delete_meta( $post_id, 'wpar_republish_as_action_id' );
}

/**
* Handle Trigger post update process.
*
Expand Down Expand Up @@ -127,7 +136,6 @@ public function update_old_post(
$post->ID,
$post
);
//error_log( print_r( $args, true ) );
wp_update_post( $args );
$this->do_action( 'clear_site_cache' );
// reinit kses filters
Expand Down
48 changes: 35 additions & 13 deletions includes/Helpers/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@
trait Scheduler
{

/**
* Create the async action event.
*
* @param string $hook Action Hook.
* @param array $args Parameters.
* @param integer $priority Load Order Priority.
* @param boolean $unique Whether the action should be unique.
* @param string $group Group Name.
* @return string
*/
protected function schedule_async_action( $hook, $args = [], $priority = 5, $unique = false, $group = 'wp-auto-republish' ) {
$action_id = \as_enqueue_async_action( $hook, $args, $group, $unique, $priority ); // @phpstan-ignore-line

return $action_id;
}

/**
* Create the recurring action event.
*
* @param integer $timestamp Timestamp.
* @param integer $interval_in_seconds Interval in Seconds.
* @param string $hook Action Hook.
* @param array $args Parameters.
* @param integer $priority Load Order Priority.
* @param boolean $unique Whether the action should be unique.
* @param string $group Group Name.
* @return string
*/
protected function schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = [], $unique = false, $group = 'wp-auto-republish' ) {
$action_id = \as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group, $unique ); // @phpstan-ignore-line
protected function schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = [], $priority = 5, $unique = false, $group = 'wp-auto-republish' ) {
$action_id = \as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group, $unique, $priority ); // @phpstan-ignore-line

return $action_id;
}
Expand All @@ -39,12 +57,14 @@ protected function schedule_recurring_action( $timestamp, $interval_in_seconds,
*
* @param integer $timestamp Timestamp.
* @param string $hook Hook.
* @param array $arg Parameter.
* @param array $args Parameters.
* @param integer $priority Load Order Priority.
* @param boolean $unique Whether the action should be unique.
* @param string $group Group Name.
* @return string
*/
protected function schedule_single_action( $timestamp, $hook, $args = [], $unique = false, $group = 'wp-auto-republish' ) {
$action_id = \as_schedule_single_action( $timestamp, $hook, $args, $group, $unique ); // @phpstan-ignore-line
protected function schedule_single_action( $timestamp, $hook, $args = [], $priority = 5, $unique = false, $group = 'wp-auto-republish' ) {
$action_id = \as_schedule_single_action( $timestamp, $hook, $args, $group, $unique, $priority ); // @phpstan-ignore-line

return $action_id;
}
Expand All @@ -53,7 +73,7 @@ protected function schedule_single_action( $timestamp, $hook, $args = [], $uniqu
* Unschedule all action events.
*
* @param string $hook Hook.
* @param array $arg Parameter.
* @param array $arg Parameters.
* @param string $group Group Name.
*/
protected function unschedule_all_actions( $hook, $args = [], $group = 'wp-auto-republish' ) {
Expand All @@ -64,7 +84,7 @@ protected function unschedule_all_actions( $hook, $args = [], $group = 'wp-auto-
* Unschedule last action event.
*
* @param string $hook Hook.
* @param array $arg Parameter.
* @param array $arg Parameters.
* @param string $group Group Name.
*/
protected function unschedule_last_action( $hook, $args = [], $group = 'wp-auto-republish' ) {
Expand Down Expand Up @@ -140,17 +160,19 @@ protected function get_next_action_by_data( $hook, $timestamp, $args ) {
*
* @since 1.3.2
*
* @param array $ids Post IDs.
* @param array $post_ids Post IDs.
* @param string $name Action Name.
* @param integer $chunk_size Size of the Chunk.
* @param integer $interval Interval between two batch tasks.
* @param array $args Args to merge.
* @param integer $priority Load Order Priority.
*/
protected function schedule_batch_actions( $ids, $name, $chunk_size = 50, $interval = 10, $args = [] ) {
if ( $ids && is_array( $ids ) ) {
$interval = $interval * 2;
$counter = 0;
$chunks = \array_chunk( $ids, $chunk_size );
protected function schedule_batch_actions( $post_ids, $name, $chunk_size = 50, $interval = 10, $args = [] ) {
$interval = $interval * 2;
$counter = 0;

if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
$chunks = \array_chunk( $post_ids, $chunk_size );
foreach ( $chunks as $chunk ) {
$counter++;
$this->schedule_single_action( time() + ( $interval * ( $counter / 2 ) ), $name, array_merge( [ $chunk ], $args ) );
Expand Down
2 changes: 1 addition & 1 deletion includes/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function setFields() {
private function build_settings_fields() {
$managers = [
'general' => [
'enable_plugin' => __( 'Enable Auto Republishing?', 'wp-auto-republish' ),
'enable_plugin' => __( 'Enable Global Auto Republishing?', 'wp-auto-republish' ),
'republish_interval_days' => __( 'Schedule Auto Republish Process Every (in days)', 'wp-auto-republish' ),
'minimun_republish_interval' => __( 'Republish Process Interval within a Day', 'wp-auto-republish' ),
'random_republish_interval' => __( 'Date Time Random Interval', 'wp-auto-republish' ),
Expand Down
25 changes: 25 additions & 0 deletions includes/Tools/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function register() {
$this->filter( 'wpar/tools/regenerate_schedule', 'regenerate_schedule' );
$this->filter( 'wpar/tools/recreate_tables', 'maybe_recreate_actionscheduler_tables' );
$this->action( 'wpar/deschedule_posts_task', 'deschedule_posts_task' );
$this->action( 'action_scheduler_deleted_action', 'action_removed' );
$this->action( 'action_scheduler_canceled_action', 'action_removed' );
// AJAX.
$this->ajax( 'process_copy_data', 'copy_data' );
$this->ajax( 'process_import_data', 'import_data' );
Expand Down Expand Up @@ -185,6 +187,29 @@ public function admin_notice() {

}

/**
* Trigger when Action Scheduler action is cancelled or deleted.
*
* @param int $action_id Action ID
*/
public function action_removed( $action_id ) {
$post_ids = $this->get_posts( [
'posts_per_page' => -1,
'post_status' => 'any',
'post_type' => 'any',
'fields' => 'ids',
'meta_key' => 'wpar_republish_as_action_id',
'meta_value' => $action_id,
] );
if ( ! empty($post_ids) ) {
foreach ( $post_ids as $post_id ) {
$this->do_action( 'as_action_removed', $post_id );
$this->delete_meta( $post_id, 'wpar_global_republish_status' );
$this->delete_meta( $post_id, '_wpar_global_republish_datetime' );
}
}
}

/**
* Process reset plugin settings
*/
Expand Down
Loading

0 comments on commit e07b742

Please sign in to comment.