Skip to content

Commit

Permalink
Updated minimum share interval (#983)
Browse files Browse the repository at this point in the history
* Update minimum share interval

* Fix PHPUnit testcase error

* Improve license checker condition

* Add a new option to identify new users

* Improve new user flag

* Avoid every time option(rop_first_install_date) calling
  • Loading branch information
girishpanchal30 authored Jul 10, 2024
1 parent da0b9b5 commit e07c53a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
17 changes: 14 additions & 3 deletions includes/admin/class-rop-global-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class Rop_Global_Settings {
* @var array $settings_defaults The class defaults for settings.
*/
private $settings_defaults = array(
'default_interval' => 10,
'min_interval' => 5,
'default_interval' => 12,
'min_interval' => 12,
'step_interval' => 0.5,
'minimum_post_age' => 30,
'maximum_post_age' => 365,
Expand Down Expand Up @@ -387,7 +387,18 @@ public static function instance() {
self::$instance->services_defaults
);

self::$instance->settings_defaults['min_interval'] = apply_filters( 'rop_min_interval_bw_shares_min', ROP_DEBUG ? 0.05 : 0.5 );
$is_new_user = (int) get_option( 'rop_is_new_user', 0 );
$install_time = ! $is_new_user ? (int) get_option( 'rop_first_install_date', 0 ) : 0;
if ( ! $is_new_user && ( $install_time && $install_time >= strtotime( '-1 hour' ) ) ) {
$is_new_user = update_option( 'rop_is_new_user', 1 );
}

$min_interval = 0.5;
// Apply new limit for new free users.
if ( $is_new_user && 1 < self::$instance->license_type() ) {
$min_interval = 12;
}
self::$instance->settings_defaults['min_interval'] = apply_filters( 'rop_min_interval_bw_shares_min', ROP_DEBUG ? 0.05 : $min_interval );
self::$instance->settings_defaults['step_interval'] = apply_filters( 'rop_min_interval_bw_shares_step', 0.1 );

self::$instance->settings = apply_filters(
Expand Down
6 changes: 4 additions & 2 deletions includes/admin/models/class-rop-settings-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ private function validate_settings( $data ) {
}

$global_settings = new Rop_Global_Settings();
$min_hours = 5;
$is_new_user = (int) get_option( 'rop_is_new_user', 0 );
$min_hours = $is_new_user ? 12 : 5;

if ( $global_settings->license_type() > 0 ) {
$min_hours = 0.5;
Expand All @@ -432,7 +433,8 @@ private function validate_settings( $data ) {
$data['interval_r'] = 0.1;
}

$min_hours = 5;
$is_new_user = (int) get_option( 'rop_is_new_user', 0 );
$min_hours = $is_new_user ? 12 : 5;

if ( $global_settings->license_type() > 0 ) {
$min_hours = 0.5;
Expand Down
1 change: 1 addition & 0 deletions includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public static function get_labels( $key = '' ) {
'exclude_single_post' => __( 'Exclude this post', 'tweet-old-post' ),
'no_posts_found' => __( 'No posts found.', 'tweet-old-post' ),
'load_more_posts' => __( 'Load more posts.', 'tweet-old-post' ),
'min_interval_upsell' => __( 'Choosing a lower interval is available in the Pro version.', 'tweet-old-post' ),
'tracking_field' => __( 'Contributing', 'tweet-old-post' ),
'tracking' => __( 'Send anonymous data to help us understand how you use the plugin.', 'tweet-old-post' ),
'tracking_info' => __( 'What do we track?', 'tweet-old-post' ),
Expand Down
2 changes: 1 addition & 1 deletion tests/test-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test_settings_model() {
$this->assertFalse( $settings->get_custom_messages(), 'Custom messages should be off by default.' );
$this->assertEmpty( $settings->get_selected_posts(), 'Exclude posts should be empty by default.' );
$this->assertTrue( $settings->get_ga_tracking(), 'GA tags should be on by default.' );
$this->assertEquals( 10.00, $settings->get_interval(), 'Default interval should be 4 hours.' );
$this->assertEquals( 12.00, $settings->get_interval(), 'Default interval should be 4 hours.' );
$this->assertEquals( 365, $settings->get_maximum_post_age(), 'Default maximum age should be 0' );
$this->assertEquals( 30, $settings->get_minimum_post_age(), 'Default minimum age should be 0' );
$this->assertTrue( $settings->get_more_than_once(), 'More than once setting should be on' );
Expand Down
11 changes: 11 additions & 0 deletions vue/src/vue-elements/settings-tab-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
/>
</div>
</div>

<div
v-if="!isPro && generalSettings.default_interval < 12"
class="columns "
>
<div class="column text-center">
<p class="upsell">
<i class="fa fa-info-circle" /> {{ labels.min_interval_upsell }}
</p>
</div>
</div>

<span
v-if="! isBiz"
Expand Down

0 comments on commit e07c53a

Please sign in to comment.