Skip to content
Open
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
2 changes: 1 addition & 1 deletion assets/css/wpr-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ a:focus, button:focus {
}
}
.wpr-Page#dashboard .wpr-documentation {
margin-top: 98px;
margin-top: 48px;
padding: 43px 16px;
}
@media (max-width: 1239px) {
Expand Down
2 changes: 1 addition & 1 deletion assets/css/wpr-admin.min.css

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions inc/Engine/Admin/RocketInsights/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,15 @@ public function is_schedule_allowed(): bool {
}

/**
* Check if current installation is a reseller account or non-live site.
* Check if current installation is a non-live site.
*
* This will block Rocket Insights functionality for reseller accounts and localhost installations.
* This will block Rocket Insights functionality for localhost installations.
*
* @since 3.20
*
* @return bool True if is reseller account or non-live installation, false otherwise.
* @return bool True if is non-live installation, false otherwise.
*/
public function is_reseller_or_non_live(): bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename the function as we are only checking if this is a live site ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a public function that we might re-use later, I didn't modify the name. We could create a new method, use it instead, and keep the old one as a deprecated wrapper, if we feel it's necessary. What do you think?

// Hide for reseller accounts.
if ( $this->user->is_reseller_account() ) {
return true;
}

// Hide for non-live installations.
if ( ! rocket_is_live_site() ) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion inc/Engine/Admin/RocketInsights/Context/SaasContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function is_allowed( array $data = [] ): bool {
// This filter is documented in inc/Engine/Admin/RocketInsights/Context/Context.php.
$enabled = wpm_apply_filters_typed( 'boolean', 'rocket_rocket_insights_enabled', true );

// Block for reseller accounts and non-live installations.
// Block for non-live installations.
if ( $enabled && $this->context->is_reseller_or_non_live() ) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function delete_url() {
* @return bool
*/
public function can_access_report(): bool {
return ! empty( $this->report_url ) && ! $this->is_blurred;
return ! empty( $this->report_url );
}

/**
Expand All @@ -224,7 +224,7 @@ public function can_access_report(): bool {
* @return bool
*/
public function can_re_test(): bool {
return ! $this->is_running() && ! $this->is_blurred;
return ! $this->is_running();
}

/**
Expand Down
15 changes: 1 addition & 14 deletions inc/Engine/Admin/RocketInsights/GlobalScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@ private function calculate_current_status(): string {
return 'in-progress';
}

// Check if any URLs are blurred.
$blurred_count = $this->query->query(
[
'count' => true,
'status__in' => [ 'completed' ],
'is_blurred' => 1,
]
);

if ( (int) $blurred_count > 0 ) {
return 'blurred';
}

// Check if *all* URLs have failed.
$failed_count = $this->query->query(
[
Expand All @@ -174,7 +161,7 @@ private function calculate_current_status(): string {
return 'failed';
}

// All tests are complete and none are blurred.
// All tests are complete.
return 'complete';
}
}
42 changes: 9 additions & 33 deletions inc/Engine/Admin/RocketInsights/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@
use WP_Rocket\Engine\Admin\Beacon\Beacon;
use WP_Rocket\Engine\Admin\RocketInsights\Context\Context;
use WP_Rocket\Engine\Admin\RocketInsights\Database\Queries\RocketInsights as Query;
use WP_Rocket\Engine\Admin\RocketInsights\Managers\Plan;

class Render extends Abstract_Render {
/**
* Plan instance.
*
* @var Plan
*/
private $plan;

/**
* Context instance.
*
Expand Down Expand Up @@ -58,16 +50,13 @@ class Render extends Abstract_Render {
* Initializes the Render instance with the provided template path and CreditManager.
*
* @param string $template_path Path to the template file.
* @param Plan $plan Plan instance.
* @param Context $context Instance of PerformanceMonitoringContext for managing performance monitoring context.
* @param Beacon $beacon Beacon instance.
* @param Query $query Query instance.
* @param MetricFormatter $metric_formatter MetricFormatter instance.
*/
public function __construct( $template_path, Plan $plan, Context $context, Beacon $beacon, Query $query, MetricFormatter $metric_formatter ) {
public function __construct( $template_path, Context $context, Beacon $beacon, Query $query, MetricFormatter $metric_formatter ) {
parent::__construct( $template_path );

$this->plan = $plan;
$this->context = $context;
$this->beacon = $beacon;
$this->query = $query;
Expand All @@ -84,7 +73,7 @@ private function prepare_score_data( $row ): array {
$score_data = [
'score' => $row->score,
'status' => $row->status,
'is_blurred' => $row->is_blurred,
'is_blurred' => false,
'is_dashboard' => false,
];

Expand Down Expand Up @@ -142,7 +131,7 @@ public function render_global_score_row( array $data ) {
public function render_rocket_insights_urls_table( array $data ) {
$rocket_insights_beacon = $this->beacon->get_suggest( 'rocket_insights' );

$data['has_credit'] = $this->plan->has_credit();
$data['has_credit'] = true;
$data['can_add_url'] = $this->context->is_adding_page_allowed();
$data['reach_max_url'] = ! $data['can_add_url'];
$data['help'] = $rocket_insights_beacon;
Expand Down Expand Up @@ -211,7 +200,7 @@ private function prepare_global_score_widget_data( array $data ) {
return array_merge(
$data,
[
'has_credit' => $this->plan->has_credit(),
'has_credit' => true,
'can_add_url' => $is_adding_page_allowed,
'reach_max_url' => ! $is_adding_page_allowed,
'status_text' => $this->get_monitoring_status_text(),
Expand All @@ -238,7 +227,7 @@ private function is_first_completed_test( int $id ): bool {
* @return string The rendered HTML for the performance monitoring row.
*/
public function get_performance_monitoring_list_row( object $data, bool $is_ajax = true ): string {
$data->has_credit = $this->plan->has_credit();
$data->has_credit = true;
$data->formatted_metrics = $this->metric_formatter->get_formatted_metrics( $data->metric_data );
$data->rocket_can_show_advanced_indicators = ! $data->is_running() && 'failed' !== $data->status;
if ( $data->rocket_can_show_advanced_indicators ) {
Expand Down Expand Up @@ -478,7 +467,7 @@ public function get_rocket_insights_column( string $url, int $post_id ): string
$normalized_url = $url_no_slash;

// Get credit availability.
$has_credit = $this->plan->has_credit();
$has_credit = true;

$can_add_pages = $this->context->is_adding_page_allowed();

Expand All @@ -488,7 +477,7 @@ public function get_rocket_insights_column( string $url, int $post_id ): string
'wpr_rocket_row' => $row,
'wpr_has_credit' => $has_credit,
'wpr_can_add_pages' => $can_add_pages,
'wpr_is_free_user' => $this->context->is_free_user(),
'wpr_is_free_user' => false,
'wpr_limit_reached_message' => $this->get_page_limit_error_message(),
'is_draft' => get_post_status( $post_id ) === 'draft',
'wpr_post_id' => $post_id,
Expand All @@ -497,8 +486,8 @@ public function get_rocket_insights_column( string $url, int $post_id ): string
if ( null !== $row ) {
$template_data['wpr_is_running'] = $row->is_running();
$template_data['wpr_has_results'] = 'completed' === $row->status || 'blurred' === $row->status;
$template_data['wpr_is_blurred'] = isset( $row->is_blurred ) && $row->is_blurred;
$template_data['wpr_can_access_report'] = $row->can_access_report();
$template_data['wpr_is_blurred'] = false;
$template_data['wpr_can_access_report'] = true;
$template_data['wpr_view_details_url'] = $this->get_view_details_url( (int) $row->id );

// Prepare score data for template rendering.
Expand Down Expand Up @@ -534,19 +523,6 @@ public function render_rocket_insights_column( string $url, int $post_id ): void
* @return string The formatted error message.
*/
public function get_page_limit_error_message(): string {
if ( $this->context->is_free_user() ) {
$upgrade_url = admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG . '&rocket_source=wp_posts_list#rocket_insights' );

return sprintf(
/* translators: %1$s: opening <strong> tag, %2$s: closing </strong> tag, %3$s: opening link tag, %4$s: closing link tag */
__( "You've %1\$sreached your free limit%2\$s. %3\$sUpgrade to continue%4\$s.", 'rocket' ),
'<strong>',
'</strong>',
'<a href="' . esc_url( $upgrade_url ) . '">',
'</a>'
);
}

return sprintf(
/* translators: %1$s: opening <strong> tag, %2$s: closing </strong> tag */
__( "You've %1\$sreached the page limit%2\$s. Please remove at least one page to continue.", 'rocket' ),
Expand Down
34 changes: 3 additions & 31 deletions inc/Engine/Admin/RocketInsights/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function create_item( $request ) {
$payload['html'] = $this->render->get_performance_monitoring_list_row( $row_data );
$payload['global_score_data'] = $this->get_global_score_payload();
$payload['remaining_urls'] = $this->get_remaining_url_count();
$payload['has_credit'] = $this->plan->has_credit();
$payload['has_credit'] = true;
$payload['can_add_pages'] = $this->context->is_adding_page_allowed();

// Add disabled button html data to payload.
Expand Down Expand Up @@ -542,21 +542,6 @@ public function update_item( $request ) {
return rest_ensure_response( $error );
}

// Check if adding a page is allowed based on URL limits.
if ( ! $this->plan->has_credit() ) {
$error = new WP_Error(
'rest_forbidden',
esc_html__( 'Upgrade your plan to get access to re-test performance or run new tests', 'rocket' ),
[
'status' => 403,
'remaining_urls' => 0,
'can_add_pages' => false,
]
);

return rest_ensure_response( $error );
}

$source = $request->get_param( 'source' );

$additional_details = [
Expand Down Expand Up @@ -595,7 +580,7 @@ public function update_item( $request ) {
'html' => $this->render->get_performance_monitoring_list_row( $row ),
'global_score_data' => $this->get_global_score_payload(),
'remaining_urls' => $this->get_remaining_url_count(),
'has_credit' => $this->plan->has_credit(),
'has_credit' => true,
'can_add_pages' => $this->context->is_adding_page_allowed(),
];

Expand Down Expand Up @@ -746,7 +731,7 @@ public function get_progress( $request ) {
$payload['success'] = true;
$payload['results'] = $results;
$payload['global_score_data'] = $this->get_global_score_payload();
$payload['has_credit'] = $this->plan->has_credit();
$payload['has_credit'] = true;
$payload['can_add_pages'] = $this->context->is_adding_page_allowed();

return rest_ensure_response( $payload );
Expand Down Expand Up @@ -887,19 +872,6 @@ private function get_remaining_url_count(): int {
* @return string The formatted error message.
*/
private function get_page_limit_error_message(): string {
if ( $this->context->is_free_user() ) {
$upgrade_url = admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG . '&rocket_source=notice_free_page_limit_reached#rocket_insights' );

return sprintf(
/* translators: %1$s: opening <strong> tag, %2$s: closing </strong> tag, %3$s: opening link tag, %4$s: closing link tag */
__( "You've %1\$sreached your free limit%2\$s. %3\$sUpgrade to continue%4\$s.", 'rocket' ),
'<strong>',
'</strong>',
'<a href="' . esc_url( $upgrade_url ) . '">',
'</a>'
);
}

return sprintf(
/* translators: %1$s: opening <strong> tag, %2$s: closing </strong> tag */
__( "You've %1\$sreached the page limit%2\$s. Please remove at least one page to continue.", 'rocket' ),
Expand Down
2 changes: 0 additions & 2 deletions inc/Engine/Admin/RocketInsights/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function register(): void {
->addArguments(
[
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/settings/' ),
'ri_plan',
'ri_context',
'beacon',
'ri_query',
Expand Down Expand Up @@ -187,7 +186,6 @@ public function register(): void {
'ri_queue',
'ri_context',
'ri_global_score',
'options',
'ri_manager',
'ri_plan',
'renewal',
Expand Down
6 changes: 1 addition & 5 deletions inc/Engine/Admin/RocketInsights/Settings/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public function __construct( Controller $controller ) {
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_dashboard_after_account_data' => [ 'display_addon_status', 9 ], // Higher priority than RocketCDN.
'rocket_insights_settings_enabled' => 'disable_for_free_plan',
'pre_get_rocket_option_performance_monitoring' => 'disable_performance_monitoring_schedule',
];
return [];
}

/**
Expand Down
Loading
Loading