l-score-widget'. * @param array $data Data to be passed to the button template. * * @return void */ public function render_add_page_btn( string $type, array $data ): void { echo $this->get_add_page_btn( $type, $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Determines if the given title exceeds the maximum allowed length. * * @since 3.20 * * @param string $title The title to check. * @return bool True if the title is truncated, false otherwise. */ public function is_title_truncated( string $title ): bool { $max_length = 37; if ( mb_strlen( $title ) <= $max_length ) { return false; } return true; } /** * Generates the URL for the View Details link pointing to RI settings page with expanded metrics. * * @since 3.20.5 * * @param int $row_id The database row ID for the test. * @return string The URL to the RI settings page with the test expanded. */ public function get_view_details_url( int $row_id ): string { $settings_url = add_query_arg( [ 'page' => WP_ROCKET_PLUGIN_SLUG, 'ri_id' => $row_id, ], admin_url( 'options-general.php' ) ); return $settings_url . '#rocket_insights'; } /** * Generates the Rocket Insights column content for post listing pages. * * @since 3.20.1 * * @param string $url The URL of the post. * @param int $post_id Post ID of post. * * @return string The rendered HTML for the Rocket Insights column. */ public function get_rocket_insights_column( string $url, int $post_id ): string { // Query for existing row in the database. // Try both with and without trailing slash for compatibility. $url_no_slash = untrailingslashit( $url ); $url_with_slash = trailingslashit( $url ); $row = null; $results = $this->query->query( [ 'url' => $url_no_slash ] ); // If not found without slash, try with slash. if ( empty( $results ) || ! is_array( $results ) ) { $results = $this->query->query( [ 'url' => $url_with_slash ] ); } if ( ! empty( $results ) && is_array( $results ) ) { $row = $results[0]; } // Use normalized URL (without trailing slash) for frontend. $normalized_url = $url_no_slash; // Get credit availability. $has_credit = true; $can_add_pages = $this->context->is_adding_page_allowed(); // Prepare template variables. $template_data = [ 'wpr_rocket_insights_url' => $normalized_url, 'wpr_rocket_row' => $row, 'wpr_has_credit' => $has_credit, 'wpr_can_add_pages' => $can_add_pages, '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, ]; 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'] = 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. $template_data['wpr_score_data'] = $this->prepare_score_data( $row ); } return $this->generate( 'partials/rocket-insights/rocket-insights-column', $template_data ); } /** * Renders the Rocket Insights column content for post listing pages. * * @since 3.20.1 * * @param string $url The URL of the post. * @param int $post_id Post ID of post. * * @return void */ public function render_rocket_insights_column( string $url, int $post_id ): void { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Template handles escaping. echo $this->get_rocket_insights_column( $url, $post_id ); } /** * Get the error message for when page limit is reached. * * @since 3.17 * * @return string The formatted error message. */ public function get_page_limit_error_message(): string { return sprintf( /* translators: %1$s: opening tag, %2$s: closing tag */ __( "You've %1\$sreached the page limit%2\$s. Please remove at least one page to continue.", 'rocket' ), '', '' ); } } l-score-widget'. * @param array $data Data to be passed to the button template. * * @return void */ public function render_add_page_btn( string $type, array $data ): void { echo $this->get_add_page_btn( $type, $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Determines if the given title exceeds the maximum allowed length. * * @since 3.20 * * @param string $title The title to check. * @return bool True if the title is truncated, false otherwise. */ public function is_title_truncated( string $title ): bool { $max_length = 37; if ( mb_strlen( $title ) <= $max_length ) { return false; } return true; } /** * Generates the URL for the View Details link pointing to RI settings page with expanded metrics. * * @since 3.20.5 * * @param int $row_id The database row ID for the test. * @return string The URL to the RI settings page with the test expanded. */ public function get_view_details_url( int $row_id ): string { $settings_url = add_query_arg( [ 'page' => WP_ROCKET_PLUGIN_SLUG, 'ri_id' => $row_id, ], admin_url( 'options-general.php' ) ); return $settings_url . '#rocket_insights'; } /** * Generates the Rocket Insights column content for post listing pages. * * @since 3.20.1 * * @param string $url The URL of the post. * @param int $post_id Post ID of post. * * @return string The rendered HTML for the Rocket Insights column. */ public function get_rocket_insights_column( string $url, int $post_id ): string { // Query for existing row in the database. // Try both with and without trailing slash for compatibility. $url_no_slash = untrailingslashit( $url ); $url_with_slash = trailingslashit( $url ); $row = null; $results = $this->query->query( [ 'url' => $url_no_slash ] ); // If not found without slash, try with slash. if ( empty( $results ) || ! is_array( $results ) ) { $results = $this->query->query( [ 'url' => $url_with_slash ] ); } if ( ! empty( $results ) && is_array( $results ) ) { $row = $results[0]; } // Use normalized URL (without trailing slash) for frontend. $normalized_url = $url_no_slash; // Get credit availability. $has_credit = true; $can_add_pages = $this->context->is_adding_page_allowed(); // Prepare template variables. $template_data = [ 'wpr_rocket_insights_url' => $normalized_url, 'wpr_rocket_row' => $row, 'wpr_has_credit' => $has_credit, 'wpr_can_add_pages' => $can_add_pages, '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, ]; 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'] = 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. $template_data['wpr_score_data'] = $this->prepare_score_data( $row ); } return $this->generate( 'partials/rocket-insights/rocket-insights-column', $template_data ); } /** * Renders the Rocket Insights column content for post listing pages. * * @since 3.20.1 * * @param string $url The URL of the post. * @param int $post_id Post ID of post. * * @return void */ public function render_rocket_insights_column( string $url, int $post_id ): void { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Template handles escaping. echo $this->get_rocket_insights_column( $url, $post_id ); } /** * Get the error message for when page limit is reached. * * @since 3.17 * * @return string The formatted error message. */ public function get_page_limit_error_message(): string { return sprintf( /* translators: %1$s: opening tag, %2$s: closing tag */ __( "You've %1\$sreached the page limit%2\$s. Please remove at least one page to continue.", 'rocket' ), '', '' ); } }