Skip to content

Commit 91839af

Browse files
authored
Merge pull request #3 from FeXd/Blocks
Blocks Support
2 parents 6d10f6b + 4c04e8e commit 91839af

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

quick-weblog.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,25 @@ function quick_weblog_submit_form() {
132132
$category = intval( $_POST['category'] );
133133
$tags = sanitize_text_field( $_POST['tags'] );
134134

135+
// Create block content
136+
$image_block = '<!-- wp:image {"url":"' . esc_attr($image_url) . '","alt":"' . esc_attr($image_description) . '"} -->' .
137+
'<figure class="wp-block-image">' .
138+
'<img src="' . esc_url($image_url) . '" alt="' . esc_attr($image_description) . '">' .
139+
'<figcaption>' . esc_html($image_description) . '</figcaption>' .
140+
'</figure><!-- /wp:image -->';
141+
142+
$quote_block = '<!-- wp:quote {"citation":"' . esc_attr($url) . '"} -->' .
143+
'<blockquote class="wp-block-quote">' .
144+
'<p>' . esc_html($quote) . '</p>' .
145+
'<cite><a href="' . esc_url($url) . '" target="_blank" rel="noreferrer noopener">' . esc_html($url) . '</a></cite>' .
146+
'</blockquote><!-- /wp:quote -->';
147+
148+
$block_content = $image_block . $quote_block;
149+
135150
// Create a new post
136151
$post_data = array(
137152
'post_title' => $title,
138-
'post_content' => sprintf( '
139-
<blockquote class="wp-block-quote">
140-
<figure class="wp-block-image">
141-
<img decoding="async" src="%s" alt>
142-
<figcaption class="wp-element-caption">%s</figcaption>
143-
</figure><p>%s</p>
144-
<cite><a href="%s" target="_blank" rel="noreferrer noopener">%s</a></cite>
145-
</blockquote>'
146-
, $image_url, $image_description, $quote, $url, $url ),
153+
'post_content' => $block_content,
147154
'post_category' => array( $category ),
148155
'tags_input' => $tags,
149156
'post_status' => 'publish'

0 commit comments

Comments
 (0)