Skip to content

Commit 74bdfce

Browse files
committed
PHP Intelliphense VSCode Extension
- for better or worse, linting with this extension - Format Document has made a lot of subtle changes - I don't love them all, but at least things can be a bit more consistent?
1 parent 4bc6319 commit 74bdfce

File tree

1 file changed

+77
-62
lines changed

1 file changed

+77
-62
lines changed

quick-weblog.php

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,67 @@
1212
Text Domain: quick-weblog
1313
*/
1414

15-
function quick_weblog_form() {
16-
15+
function quick_weblog_form()
16+
{
17+
1718
$api_key = get_option('quick_weblog_api_key', '');
1819

19-
?>
20+
?>
2021
<style>
2122
#quick-weblog {
2223
padding: 1em 0;
2324
}
25+
2426
#quick-weblog div {
2527
padding: 0.75em 0;
2628
}
29+
2730
#quick-weblog div:nth-last-child(1) {
2831
padding-bottom: 0;
29-
}
32+
}
33+
3034
#quick-weblog div:nth-child(1) {
3135
padding-top: 0;
32-
}
36+
}
37+
3338
#quick-weblog div label {
3439
font-weight: 600;
3540
}
41+
3642
#quick-weblog-description {
3743
max-width: 520px;
3844
}
45+
3946
#quick-weblog div input,
4047
#quick-weblog div textarea,
4148
#quick-weblog div select {
4249
display: block;
4350
max-width: 600px;
4451
width: 99%;
4552
}
53+
4654
#quick-weblog div input[type=submit] {
4755
width: auto;
4856
}
4957
</style>
5058

51-
<script src="<?php echo plugin_dir_url( __FILE__ ); ?>quick-weblog.js"></script>
59+
<script src="<?php echo plugin_dir_url(__FILE__); ?>quick-weblog.js"></script>
5260

5361
<script>
5462
window.addEventListener("DOMContentLoaded", (event) => {
5563
document.getElementById("quick-weblog-auto").addEventListener("click", (click_event) => {
5664
click_event.preventDefault();
57-
getArticle(document.getElementById("quick-weblog-url").value, "<?php echo esc_js( wp_kses( $api_key, array() ) ); ?>" );
65+
getArticle(document.getElementById("quick-weblog-url").value, "<?php echo esc_js(wp_kses($api_key, array())); ?>");
5866
});
5967
});
6068
</script>
6169

6270
<p id="quick-weblog-description">Quickly create a simple Post that highlights an existing news article. Posts include a captioned image and quote with URL citation of original article. All fields are required.</p>
6371

6472
<div class="card">
65-
<form id="quick-weblog" method="post" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>">
73+
<form id="quick-weblog" method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
6674
<div>
67-
<label for="url"><?php _e( 'Post URL', 'quick-weblog' ); ?></label>
75+
<label for="url"><?php _e('Post URL', 'quick-weblog'); ?></label>
6876
<input type="text" name="url" id="quick-weblog-url" required>
6977
</div>
7078

@@ -74,55 +82,56 @@ function quick_weblog_form() {
7482
</div>
7583

7684
<div>
77-
<label for="title"><?php _e( 'Post Title', 'quick-weblog' ); ?></label>
85+
<label for="title"><?php _e('Post Title', 'quick-weblog'); ?></label>
7886
<input type="text" name="title" id="quick-weblog-title" required>
7987
</div>
8088

8189
<div>
82-
<label for="image_url"><?php _e( 'Image URL', 'quick-weblog' ); ?></label>
90+
<label for="image_url"><?php _e('Image URL', 'quick-weblog'); ?></label>
8391
<input type="text" name="image_url" id="quick-weblog-image_url" required>
8492
</div>
8593

8694
<div>
87-
<label for="image_description"><?php _e( 'Image Description', 'quick-weblog' ); ?></label>
95+
<label for="image_description"><?php _e('Image Description', 'quick-weblog'); ?></label>
8896
<input type="text" name="image_description" id="quick-weblog-image_description" required>
8997
</div>
9098

9199
<div>
92-
<label for="quote"><?php _e( 'Quote', 'quick-weblog' ); ?></label>
100+
<label for="quote"><?php _e('Quote', 'quick-weblog'); ?></label>
93101
<textarea name="quote" id="quick-weblog-quote" rows="6" required></textarea>
94102
</div>
95103

96104
<div>
97-
<label for="category"><?php _e( 'Category', 'quick-weblog' ); ?></label>
98-
<?php wp_dropdown_categories( array( 'name' => 'category', 'orderby' => 'name', 'taxonomy' => 'category', 'selected' => 1) ); ?>
105+
<label for="category"><?php _e('Category', 'quick-weblog'); ?></label>
106+
<?php wp_dropdown_categories(array('name' => 'category', 'orderby' => 'name', 'taxonomy' => 'category', 'selected' => 1)); ?>
99107
</div>
100108

101109
<div>
102-
<label for="tags"><?php _e( 'Tags', 'quick-weblog' ); ?></label>
110+
<label for="tags"><?php _e('Tags', 'quick-weblog'); ?></label>
103111
<input type="text" name="tags" id="quick-weblog-tags" required>
104112
</div>
105113

106114
<div>
107-
<label for="post_date"><?php _e( 'Post Date', 'quick-weblog' ); ?></label>
108-
<?php $default_date = date( 'Y-m-d\TH:i' ); ?>
115+
<label for="post_date"><?php _e('Post Date', 'quick-weblog'); ?></label>
116+
<?php $default_date = date('Y-m-d\TH:i'); ?>
109117
<input type="datetime-local" name="post_date" id="quick-weblog-post_date" required value="<?php echo $default_date; ?>">
110118
</div>
111119

112120
<div>
113121
<input type="hidden" name="action" value="quick_weblog_submit_form">
114-
<?php wp_nonce_field( 'quick_weblog_submit_form', 'quick_weblog_form_nonce' ); ?>
115-
<input type="submit" value="<?php _e( 'Submit', 'quick-weblog' ); ?>">
122+
<?php wp_nonce_field('quick_weblog_submit_form', 'quick_weblog_form_nonce'); ?>
123+
<input type="submit" value="<?php _e('Submit', 'quick-weblog'); ?>">
116124
</div>
117125
</form>
118126
</div>
119-
<?php
127+
<?php
120128
}
121129

122-
function quick_weblog_add_menu_page() {
130+
function quick_weblog_add_menu_page()
131+
{
123132
add_menu_page(
124-
__( 'Quick Weblog', 'quick-weblog' ), // Page title
125-
__( 'Quick Weblog', 'quick-weblog' ), // Menu title
133+
__('Quick Weblog', 'quick-weblog'), // Page title
134+
__('Quick Weblog', 'quick-weblog'), // Menu title
126135
'manage_options', // Capability required to access the page
127136
'quick-weblog', // Menu slug
128137
'quick_weblog_menu_page', // Callback function to render the page
@@ -132,73 +141,76 @@ function quick_weblog_add_menu_page() {
132141

133142
add_submenu_page(
134143
'quick-weblog', // Parent slug
135-
__( 'API Settings', 'quick-weblog' ), // Page title
136-
__( 'API Settings', 'quick-weblog' ), // Menu title
144+
__('API Settings', 'quick-weblog'), // Page title
145+
__('API Settings', 'quick-weblog'), // Menu title
137146
'manage_options', // Capability required to access the page
138147
'quick-weblog-settings', // Menu slug
139148
'quick_weblog_settings_page' // Callback function to render the page
140149
);
141150
}
142151

143-
add_action( 'admin_menu', 'quick_weblog_add_menu_page' );
152+
add_action('admin_menu', 'quick_weblog_add_menu_page');
144153

145-
function quick_weblog_menu_page() {
146-
?>
154+
function quick_weblog_menu_page()
155+
{
156+
?>
147157
<div class="wrap">
148-
<h1><?php _e( 'Quick Weblog', 'quick-weblog' ); ?></h1>
158+
<h1><?php _e('Quick Weblog', 'quick-weblog'); ?></h1>
149159
<?php quick_weblog_form(); ?>
150160
</div>
151-
<?php
161+
<?php
152162
}
153163

154-
function quick_weblog_submit_form() {
164+
function quick_weblog_submit_form()
165+
{
155166
// Check the nonce to verify the form submission
156-
if ( ! isset( $_POST['quick_weblog_form_nonce'] ) || ! wp_verify_nonce( $_POST['quick_weblog_form_nonce'], 'quick_weblog_submit_form' ) ) {
157-
wp_die( __( 'Error: Invalid nonce.', 'quick-weblog' ) );
167+
if (!isset($_POST['quick_weblog_form_nonce']) || !wp_verify_nonce($_POST['quick_weblog_form_nonce'], 'quick_weblog_submit_form')) {
168+
wp_die(__('Error: Invalid nonce.', 'quick-weblog'));
158169
}
159170

160171
// Get the form data
161-
$title = sanitize_text_field( $_POST['title'] );
162-
$image_url = sanitize_text_field( $_POST['image_url'] );
163-
$image_description = sanitize_text_field( $_POST['image_description'] );
164-
$quote = sanitize_text_field( $_POST['quote'] );
165-
$url = esc_url_raw( $_POST['url'] );
166-
$category = intval( $_POST['category'] );
167-
$tags = sanitize_text_field( $_POST['tags'] );
172+
$title = sanitize_text_field($_POST['title']);
173+
$image_url = sanitize_text_field($_POST['image_url']);
174+
$image_description = sanitize_text_field($_POST['image_description']);
175+
$quote = sanitize_text_field($_POST['quote']);
176+
$url = esc_url_raw($_POST['url']);
177+
$category = intval($_POST['category']);
178+
$tags = sanitize_text_field($_POST['tags']);
168179

169180
// Create block content
170181
$image_block = '<!-- wp:image {"url":"' . esc_attr($image_url) . '","alt":"' . esc_attr($image_description) . '"} -->' .
171-
'<figure class="wp-block-image">' .
172-
'<img src="' . esc_url($image_url) . '" alt="' . esc_attr($image_description) . '">' .
173-
'<figcaption>' . esc_html($image_description) . '</figcaption>' .
174-
'</figure><!-- /wp:image -->';
182+
'<figure class="wp-block-image">' .
183+
'<img src="' . esc_url($image_url) . '" alt="' . esc_attr($image_description) . '">' .
184+
'<figcaption>' . esc_html($image_description) . '</figcaption>' .
185+
'</figure><!-- /wp:image -->';
175186

176187
$quote_block = '<!-- wp:quote {"citation":"' . esc_attr($url) . '"} -->' .
177-
'<blockquote class="wp-block-quote">' .
178-
'<p>' . esc_html($quote) . '</p>' .
179-
'<cite><a href="' . esc_url($url) . '" target="_blank" rel="noreferrer noopener">' . esc_html($url) . '</a></cite>' .
180-
'</blockquote><!-- /wp:quote -->';
188+
'<blockquote class="wp-block-quote">' .
189+
'<p>' . esc_html($quote) . '</p>' .
190+
'<cite><a href="' . esc_url($url) . '" target="_blank" rel="noreferrer noopener">' . esc_html($url) . '</a></cite>' .
191+
'</blockquote><!-- /wp:quote -->';
181192

182193
$block_content = $image_block . $quote_block;
183194

184195
// Create a new post
185196
$post_data = array(
186197
'post_title' => $title,
187198
'post_content' => $block_content,
188-
'post_category' => array( $category ),
199+
'post_category' => array($category),
189200
'tags_input' => $tags,
190201
'post_status' => 'publish'
191202
);
192-
$post_id = wp_insert_post( $post_data );
203+
$post_id = wp_insert_post($post_data);
193204

194205
// Redirect to the new post
195-
wp_redirect( get_permalink( $post_id ) );
206+
wp_redirect(get_permalink($post_id));
196207
exit();
197208
}
198209

199-
add_action( 'admin_post_quick_weblog_submit_form', 'quick_weblog_submit_form' );
210+
add_action('admin_post_quick_weblog_submit_form', 'quick_weblog_submit_form');
200211

201-
function quick_weblog_settings_init() {
212+
function quick_weblog_settings_init()
213+
{
202214
add_settings_section('quick_weblog_api_section', 'API Settings', null, 'quick-weblog');
203215
add_settings_field('quick_weblog_api_key', 'API Key', 'quick_weblog_api_key_callback', 'quick-weblog', 'quick_weblog_api_section');
204216

@@ -208,30 +220,33 @@ function quick_weblog_settings_init() {
208220

209221
add_action('admin_init', 'quick_weblog_settings_init');
210222

211-
function quick_weblog_api_key_callback() {
223+
function quick_weblog_api_key_callback()
224+
{
212225
$value = get_option('quick_weblog_api_key', '');
213226
echo '<input type="text" name="quick_weblog_api_key" value="' . esc_attr($value) . '" />';
214227
}
215228

216-
function quick_weblog_add_settings_link($links) {
217-
$settings_link = '<a href="' . admin_url('options-general.php?page=quick-weblog') . '">' . __( 'Settings', 'quick-weblog' ) . '</a>';
229+
function quick_weblog_add_settings_link($links)
230+
{
231+
$settings_link = '<a href="' . admin_url('options-general.php?page=quick-weblog') . '">' . __('Settings', 'quick-weblog') . '</a>';
218232
array_push($links, $settings_link);
219233
return $links;
220234
}
221235

222236
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'quick_weblog_add_settings_link');
223237

224-
function quick_weblog_settings_page() {
225-
?>
238+
function quick_weblog_settings_page()
239+
{
240+
?>
226241
<div class="wrap">
227-
<h1><?php _e( 'API Settings', 'quick-weblog' ); ?></h1>
242+
<h1><?php _e('API Settings', 'quick-weblog'); ?></h1>
228243
<form method="post" action="options.php">
229244
<?php settings_fields('quick_weblog_settings'); ?>
230245
<?php do_settings_sections('quick-weblog'); ?>
231246
<?php submit_button(); ?>
232247
</form>
233248
</div>
234-
<?php
249+
<?php
235250
}
236251

237-
?>
252+
?>

0 commit comments

Comments
 (0)