简单的 WP 插件抛出意外结束

simple WP plugin throw unexpected end

我创建了插件文件夹 'my-plugin',文件名为 my-plugin.php,内容如下。当我尝试打开插件时出现错误:

"Parse error: syntax error, unexpected end of file in (...)\wp-content\plugins\my-plugin\my-plugin.php on line 83".

这是此文件中的最后一个空行。问题出在哪里?

<?php

/**
 * @package my_plugin
 * @version 1.0
 */
/*
Plugin Name: My plugin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Your Name
Version: 1.0
Author URI: https://yourwebsite.com/
*/

/**
 * Register a shortcode
 *
 * @param array $atts Array of shortcode attributes
 */
function kinsta_get_posts_cb( $atts ){

    // safely extract custom arguments and set default values
    extract( shortcode_atts(
            array(
                'numberposts'       => 3,
                'post_type'         => 'post',
                'book_category'     => 'fantasy',
                'year_published'    => 1900,
                'price_min'         => 0,
                'price_max'         => 50
            ),
            $atts,
            'kinsta_get_posts'
        ) );

    // define the array of query arguments
    $args = array(
        'numberposts'   => $numberposts,
        'post_type'     => $post_type,
        'tax_query'     => array(
            array(
                'taxonomy'  => 'book_category',
                'field'     => 'slug',
                'terms'     => $book_category,
            )
        ),
        'meta_query'    => array(
            'relation'      => 'AND',
            'year_clause'   => array(
                'key'       => 'year_published',
                'value'     => $year_published,
                'type'      => 'numeric',
                'compare'   => '>',
            ),
            'price_clause'  => array(
                'key'       => 'price',
                'value'     => array( $price_min, $price_max ),
                'type'      => 'numeric',
                'compare'   => 'BETWEEN',
            )
        ),
        'orderby' => array( 'price_clause' => 'ASC' )
    );

    $custom_posts = get_posts( $args );

    if( ! empty( $custom_posts ) ){
        $output = '<ul>';
        foreach ( $custom_posts as $p ){

            $output .= '<li><a href="'
            . get_permalink( $p->ID ) . '">'
            . $p->post_title . '</a> ('
            . get_post_meta( $p->ID, 'year_published', true )
            . ') - Price: ' . get_post_meta( $p->ID, 'price', true ) . '</li>';
        }

        $output .= '</ul>';
    }

return $output ?? '<strong>Sorry. No posts matching your criteria!</strong>';

显然,您忘记了在文件末尾关闭 }