Skip to content

Commit

Permalink
more sprintf removals
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Sep 4, 2024
1 parent a82fad3 commit c6b92ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/class-shortcode-most-viewed-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ public function content($args): string
foreach ($posts as $p) {
$post_title = get_the_title($p);
$title = $post_title !== '' ? $post_title : esc_html__('(no title)', 'koko-analytics');
$aria_current = '';
$permalink = get_the_permalink($p);

$aria_current = '';
if (get_queried_object_id() === $p->ID) {
$aria_current = ' aria-current="page"';
}

$html .= '<li>';
$html .= sprintf('<a href="%s" %s>%s</a>', get_the_permalink($p), $aria_current, $title);
$html .= "<a href=\"{$permalink})}\" {$aria_current}>{$title}</a>";

if ($args['show_date']) {
$html .= sprintf(PHP_EOL . ' <span class="post-date">%s</span>', get_the_date('', $p));
$date = get_the_date('', $p);
$html .= " <span class=\"post-date\">{$date}</span>";
}
$html .= '</li>';
}
Expand Down
3 changes: 2 additions & 1 deletion src/class-widget-most-viewed-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public function form($settings)
<select class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>" name="<?php echo $this->get_field_name('post_type'); ?>">
<?php
foreach ($post_types as $post_type) {
echo sprintf('<option value="%s" %s>%s</option>', $post_type->name, selected($settings['post_type'], $post_type->name, false), $post_type->label);
$selected = selected($settings['post_type'], $post_type->name, false);
echo "<option value=\"{$post_type->name}\" {$selected}>{$post_type->label}</option>";
}
?>
</select>
Expand Down
9 changes: 7 additions & 2 deletions src/views/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
<select id="ka-exclude-user-roles" multiple="" name="koko_analytics_settings[exclude_user_roles][]" style="min-height: <?php echo count($user_roles) * 30; ?>px; min-width: 240px;">
<?php
foreach ($user_roles as $key => $value) {
echo sprintf('<option value="%s" %s>%s</option>', esc_attr($key), selected(in_array($key, $settings['exclude_user_roles']), true, false), esc_html($value));
$key = esc_attr($key);
$value = esc_html($value);
$selected = (in_array($key, $settings['exclude_user_roles']) ? 'selected' : '');

echo "<option value=\"{$key}\" {$selected}>{$value}</option>";
}
?>
</select>
Expand Down Expand Up @@ -88,7 +92,8 @@
<select id="ka-default-date-period" name="koko_analytics_settings[default_view]">
<?php
foreach ($date_presets as $key => $label) {
echo sprintf('<option value="%s" %s>%s</option>', esc_attr($key), selected($key === $settings['default_view'], true, false), esc_html($label));
$selected = ($key === $settings['default_view'] ? 'selected' : '');
echo "<option value=\"{$key}\" {$selected}>{$label}</option>";
}
?>
</select>
Expand Down

0 comments on commit c6b92ce

Please sign in to comment.