link_builder = $link_builder; } /** * The main entry point for modifying content. * * Hooks into `the_content` and applies the internal linking logic. * * @since 1.0 * @param string $content The original post content. * @return string The modified post content. */ public function process_content( $content ) { if ( ! is_singular() && ! is_page() && ! is_home() && ! is_front_page() ) { return $content; } if ( is_admin() || empty( $content ) ) { return $content; } global $post; if ( ! $post ) { return $content; } // URL exclusion check $exclude_raw = get_option( 'ailm_exclude_urls', '' ); if ( ! empty( $exclude_raw ) ) { $patterns = array_map( 'trim', explode( ',', $exclude_raw ) ); $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; $normalized_uri = '/' . trim( $request_uri, '/' ) . '/'; foreach ( $patterns as $pat ) { if ( empty( $pat ) ) { continue; } if ( $pat === '*' && ( is_front_page() || is_home() ) ) { return $content; } if ( $pat !== '*' && strpos( $normalized_uri, '/' . trim( $pat, '/' ) . '/' ) !== false ) { return $content; } } } // Content length check $min_chars = get_option( 'ailm_min_chars', 2000 ); if ( mb_strlen( wp_strip_all_tags( $content ), 'UTF-8' ) < $min_chars ) { return $content; } // Call the Link Builder class to process the content return $this->link_builder->build_links( $content, $post ); } }