问题描述
我创建了名为“ my-plugin.PHP”的插件文件夹“ my-plugin”,内容如下。当我尝试打开插件时出现错误:
“解析错误:语法错误,文件中的意外结尾 (...)\ wp-content \ plugins \ my-plugin \ my-plugin.PHP行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 ),'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>';
解决方法
显然,您忘记了在文件末尾关闭}
。