55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
function twentytwentyfive_child_enqueue_styles() {
|
|
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
|
|
wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'), wp_get_theme()->get('Version'));
|
|
}
|
|
add_action('wp_enqueue_scripts', 'twentytwentyfive_child_enqueue_styles');
|
|
|
|
// Add Meta Box for Review Score
|
|
function gamepulse_add_review_score_meta_box() {
|
|
add_meta_box(
|
|
'gamepulse_review_score',
|
|
'Review Score',
|
|
'gamepulse_review_score_callback',
|
|
'post',
|
|
'side'
|
|
);
|
|
}
|
|
add_action('add_meta_boxes', 'gamepulse_add_review_score_meta_box');
|
|
|
|
function gamepulse_review_score_callback($post) {
|
|
$value = get_post_meta($post->ID, '_gamepulse_review_score', true);
|
|
echo '<label for="gamepulse_score_field">Score (0.0 - 10.0): </label>';
|
|
echo '<input type="number" step="0.1" min="0" max="10" id="gamepulse_score_field" name="gamepulse_score_field" value="' . esc_attr($value) . '" style="width:100%;" />';
|
|
}
|
|
|
|
function gamepulse_save_review_score($post_id) {
|
|
if (array_key_exists('gamepulse_score_field', $_POST)) {
|
|
update_post_meta(
|
|
$post_id,
|
|
'_gamepulse_review_score',
|
|
sanitize_text_field($_POST['gamepulse_score_field'])
|
|
);
|
|
}
|
|
}
|
|
add_action('save_post', 'gamepulse_save_review_score');
|
|
|
|
// Shortcode to display score
|
|
function gamepulse_score_shortcode() {
|
|
$score = get_post_meta(get_the_ID(), '_gamepulse_review_score', true);
|
|
if (empty($score)) return '';
|
|
|
|
return '<div class="gamepulse-score-badge">' . esc_html($score) . '</div>';
|
|
}
|
|
add_shortcode('gamepulse_score', 'gamepulse_score_shortcode');
|
|
|
|
// Display score on single posts automatically
|
|
function gamepulse_display_score_in_content($content) {
|
|
if (is_singular('post') && in_the_loop() && is_main_query()) {
|
|
$score_html = gamepulse_score_shortcode();
|
|
return $score_html . $content;
|
|
}
|
|
return $content;
|
|
}
|
|
add_filter('the_content', 'gamepulse_display_score_in_content');
|