get_description() ) ); $words = ( '' === $text ) ? 0 : count( preg_split( '/\s+/', $text, -1, PREG_SPLIT_NO_EMPTY ) ); // Substantial already — nothing to nudge. if ( $words >= self::THIN_WORDS ) { return array(); } return array( array( 'field' => 'description', 'label' => __( 'Long description', 'agentictrack-agent-readiness-for-woocommerce' ), 'before' => '' === $text ? __( 'Empty', 'agentictrack-agent-readiness-for-woocommerce' ) : wp_trim_words( $text, 30, '…' ), 'after' => '', 'needs_input' => true, 'auto' => false, 'input_type' => 'textarea', 'current' => (string) $product->get_description(), 'placeholder' => __( 'Describe the product with real specifics: materials, size, features, use…', 'agentictrack-agent-readiness-for-woocommerce' ), 'note' => __( 'Add real details (materials, size, features). This also feeds the schema summary.', 'agentictrack-agent-readiness-for-woocommerce' ), ), ); } /** * {@inheritDoc} */ public function apply( WC_Product $product, array $input ) { if ( ! isset( $input['description'] ) ) { return $this->result(); } $new = trim( wp_kses_post( wp_unslash( $input['description'] ) ) ); if ( '' === $new ) { return new WP_Error( 'arwc_empty_description', __( 'Enter a description first.', 'agentictrack-agent-readiness-for-woocommerce' ) ); } $before = trim( wp_strip_all_tags( (string) $product->get_description() ) ); $result = $this->result(); $product->set_description( $new ); $product->save(); $result->add_change( 'description', __( 'Long description', 'agentictrack-agent-readiness-for-woocommerce' ), '' === $before ? __( 'Empty', 'agentictrack-agent-readiness-for-woocommerce' ) : wp_trim_words( $before, 20, '…' ), wp_trim_words( wp_strip_all_tags( $new ), 20, '…' ) ); return $result; } }