', ']]>', $text ); /** * Only restore the filter callback if it was removed above. The logic * to unhook and restore only applies on the default priority of 10, * which is generally used for the filter callback in WordPress core. */ // _removed /** * Filters the maximum number of words in a post excerpt. * * @param int $number The maximum number of words. Default 55. * * @since 2.7.0 */ $excerpt_length = apply_filters( 'excerpt_length', 55 ); /** * Filters the string in the "more" link displayed after a trimmed excerpt. * * @param string $more_string The string shown within the more link. * * @since 2.9.0 */ $excerpt_more = apply_filters( 'excerpt_more', ' […]' ); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); } else { // custom addition. Some themes, like Avada allow to use their page builders in // the Woo Product Short Description field, which is a post excerpt, // and without removals it causes issues. $text = strip_shortcodes( $text ); } /** * Filters the trimmed excerpt string. * * @param string $text The trimmed text. * @param string $raw_excerpt The text prior to trimming. * * @since 2.8.0 */ return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt ); } public function print_markup( string $field_id, Markup_Field_Data $markup_field_data ): void { $var = $markup_field_data->get_token_factory()->variable( $field_id )->add_item_path( 'value' ); $markup_field_data->get_token_factory()->to_echo( $var )->print(); } /** * @return array */ public function get_template_variables( Variable_Field_Data $variable_field_data ): array { $args = array( 'value' => $variable_field_data->get_field_data()->default_value, ); $post = $this->get_post( $variable_field_data->get_value() ); // it's important to check if the post type supports the excerpt (overall) // do not use has_excerpt(), because it checks only the 'excerpt' post field, // while user may want to see the wp generated excerpt (first sentences). if ( null === $post || ! post_type_supports( $post->post_type, 'excerpt' ) ) { return $args; } // custom modification to avoid issues (see body for the details). $excerpt = $this->get_excerpt( $post->post_excerpt, $post ); // to avoid double escaping. $excerpt = html_entity_decode( $excerpt, ENT_QUOTES ); $args['value'] = '' !== $excerpt ? $excerpt : $args['value']; return $args; } /** * @return array */ public function get_validation_template_variables( Variable_Field_Data $variable_field_data ): array { return array( 'value' => 'excerpt', ); } public function is_with_field_wrapper( Layout_Settings $layout_settings, Field_Settings $field_settings, Field_Meta $field_meta ): bool { return true; } }