__( 'Article templates', 'karma-docs' ) ) ); /** * Filters the article templates (slug => title, description, content). * * @param array $templates Templates. */ $templates = (array) apply_filters( 'kdocs_article_templates', self::templates() ); foreach ( $templates as $slug => $template ) { register_block_pattern( 'karma-docs/' . $slug, array( 'title' => $template['title'], 'description' => $template['description'], 'content' => $template['content'], 'categories' => array( 'karma-docs-templates' ), 'blockTypes' => array( 'core/post-content' ), 'postTypes' => array( PostTypes::ARTICLE ), ) ); } } /** * Heading block. * * @param string $text Text. * @return string */ private static function h2( $text ) { return "\n

" . esc_html( $text ) . "

\n\n\n"; } /** * Paragraph block. * * @param string $text Text. * @return string */ private static function p( $text ) { return "\n

" . esc_html( $text ) . "

\n\n\n"; } /** * List block. * * @param string[] $items Items. * @param bool $ordered Ordered. * @return string */ private static function items( array $items, $ordered = false ) { $tag = $ordered ? 'ol' : 'ul'; $attrs = $ordered ? ' {"ordered":true}' : ''; $out = "\n<{$tag} class=\"wp-block-list\">"; foreach ( $items as $item ) { $out .= "\n
  • " . esc_html( $item ) . "
  • \n"; } return $out . "\n\n\n"; } /** * Callout block. * * @param string $type info|tip|warning|danger. * @param string $text Text. * @return string */ private static function callout( $type, $text ) { $emoji = array( 'tip' => 'đź’ˇ', 'warning' => '⚠️', ); // Same markup as the block's save() so the editor accepts it. return '' . "\n" . '
    ' . esc_html( $text ) . "
    \n\n\n"; } /** * Built-in templates. * * @return array */ public static function templates() { return array( 'how-to' => array( 'title' => __( 'How-to guide', 'karma-docs' ), 'description' => __( 'Steps to complete one task.', 'karma-docs' ), 'content' => self::p( __( 'In this guide you will… (one sentence on the result).', 'karma-docs' ) ) . self::h2( __( 'Before you start', 'karma-docs' ) ) . self::items( array( __( 'What the reader needs (access, plan, data)…', 'karma-docs' ) ) ) . self::h2( __( 'Steps', 'karma-docs' ) ) . self::items( array( __( 'Open…', 'karma-docs' ), __( 'Click…', 'karma-docs' ), __( 'Save…', 'karma-docs' ) ), true ) . self::h2( __( 'Check that it worked', 'karma-docs' ) ) . self::p( __( 'What the reader should see now.', 'karma-docs' ) ) . self::h2( __( 'Next steps', 'karma-docs' ) ) . self::items( array( __( 'Link to the next article…', 'karma-docs' ) ) ), ), 'troubleshooting' => array( 'title' => __( 'Troubleshooting', 'karma-docs' ), 'description' => __( 'A problem, its causes and the fixes.', 'karma-docs' ), 'content' => self::h2( __( 'Symptoms', 'karma-docs' ) ) . self::p( __( 'What the reader sees (error message, behavior).', 'karma-docs' ) ) . self::h2( __( 'Cause', 'karma-docs' ) ) . self::p( __( 'Why it happens.', 'karma-docs' ) ) . self::h2( __( 'Solution', 'karma-docs' ) ) . self::items( array( __( 'First thing to try…', 'karma-docs' ), __( 'If that did not help…', 'karma-docs' ) ), true ) . self::callout( 'tip', __( 'Still stuck? Tell the reader what to send to support.', 'karma-docs' ) ), ), 'reference' => array( 'title' => __( 'Reference', 'karma-docs' ), 'description' => __( 'Options, fields or settings explained one by one.', 'karma-docs' ), 'content' => self::p( __( 'What this reference covers.', 'karma-docs' ) ) . "\n
    " . esc_html__( 'Name', 'karma-docs' ) . '' . esc_html__( 'Type', 'karma-docs' ) . '' . esc_html__( 'Default', 'karma-docs' ) . '' . esc_html__( 'Description', 'karma-docs' ) . "
    \n\n\n" . self::h2( __( 'Examples', 'karma-docs' ) ) . "\n
    \n\n\n", ), 'release-notes' => array( 'title' => __( 'Release notes', 'karma-docs' ), 'description' => __( 'What changed in a release.', 'karma-docs' ), 'content' => self::p( __( 'Release date and a one-line summary.', 'karma-docs' ) ) . self::h2( __( 'New', 'karma-docs' ) ) . self::items( array( '…' ) ) . self::h2( __( 'Improved', 'karma-docs' ) ) . self::items( array( '…' ) ) . self::h2( __( 'Fixed', 'karma-docs' ) ) . self::items( array( '…' ) ) . self::callout( 'warning', __( 'Breaking changes and what to do about them.', 'karma-docs' ) ), ), ); } }