PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / schema-aggregator / application / enhancement / abstract-schema-enhancer.php

abstract-schema-enhancer.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/schema-aggregator/application/enhancement/abstract-schema-enhancer.php

31 lines 936 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3 namespace Yoast\WP\SEO\Schema_Aggregator\Application\Enhancement;
4
5 /**
6 * The abstract schema enhancer.
7 */
8 abstract class Abstract_Schema_Enhancer {
9
10 /**
11 * Trims content to a maximum length, attempting to break at word boundaries.
12 *
13 * @param int $max_length Maximum length of content.
14 * @param string $content The content to trim.
15 *
16 * @return string The trimmed content.
17 */
18 protected function trim_content_to_max_length( int $max_length, string $content ): string {
19 if ( $max_length > 0 && \strlen( $content ) > $max_length ) {
20 $content = \substr( $content, 0, $max_length );
21 $last_space = \strrpos( $content, ' ' );
22 if ( $last_space !== false && $last_space > ( $max_length * 0.9 ) ) {
23 $content = \substr( $content, 0, $last_space );
24 }
25 $content .= '...';
26 }
27
28 return $content;
29 }
30 }
31