現在ローカル環境にXAMPPを設置しそこにWordPressをインストールしています。
ローカル環境ではエラーが出なかったPHPを本番環境にアップすると「Parse error: syntax error, unexpected ')'」が発生しました。
発生したPHPは以下のコードとなります。
php
1class NewEntryWidget extends WP_Widget{ 2 3 /* コンストラクタ */ 4 public function __construct(){ 5 $widget_options = array( 6 'classname' => 'new-entry-widget', 7 'description' => 'サムネイル付きの新着エントリーを表示します。', 8 'customize_selective_refresh' => true, 9 ); 10 parent::__construct( 11 'new-entry-widget', //ID 12 '新着エントリー', //ウィジット名 13 $widget_options, //情報用設定 14 ); 15 } 16 17 /* ウィジェットサイト表示 */ 18 public function widget( $args, $instance ){ 19 //設定値取得 20 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 21 $count = !empty( $instance['count'] ) ? absint( $instance['count'] ) : 5; 22 23 //サイト出力 24 echo $args['before_widget']; 25 echo $args['before_title']; 26 if( $title ){ //タイトル設定あり 27 echo $title; 28 }else{ //タイトル設定なし 29 echo '新着エントリー'; 30 } 31 echo $args['after_title']; 32 ?> 33 <ul> 34 <?php query_posts( 'posts_per_page='. $count ); //クエリの作成 ?> 35 <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?> 36 <li class="newEntry"> 37 <div class="newEntryCard"> 38 <a href="<?php the_permalink(); ?>" class="newEntryImgLink none"><?php echo ys_get_thumbnail(get_the_ID(), '70'); ?></a> 39 <p class="newEntryTitle"><a href="<?php the_permalink(); ?>" class="newEntryTitleLink none linkLine"><?php the_title();?></a></p> 40 41 </div><!-- .new-entry-card --> 42 </li><!-- .new-entry --> 43 <?php endwhile; ?> 44 <?php else : ?> 45 <p>新着記事はありません。</p> 46 <?php endif; ?> 47 <?php wp_reset_query(); ?> 48 </ul> 49 <?php 50 echo $args['after_widget']; 51 } 52 53 /* 管理画面のウィジェット設定フォーム */ 54 public function form( $instance ){ 55 //初期値 56 $defaults = array( 57 'title' => '', 58 'count' => 5, 59 ); 60 //設定値と初期値のすり合わせ 61 $instance = wp_parse_args( $instance, $defaults ); 62 //設定値の無害化(サニタイズ) 63 $title = sanitize_text_field( $instance['title'] ); 64 $count = absint( $instance['count'] ); 65 ?> 66 <!-- 設定フォーム:タイトル --> 67 <p> 68 <label for="<?php echo $this->get_field_id( 'title' ); ?>">タイトル:</label> 69 <input class="widefat" id="<?php echo $this -> get_field_id( 'title' ); ?>" name="<?php echo $this -> get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 70 </p> 71 <!-- 設定フォーム:表示数 --> 72 <p> 73 <label for="<?php echo $this -> get_field_id( 'count' ); ?>">表示数:</label> 74 <input class="tiny-text" id="<?php echo $this -> get_field_id( 'count' ); ?>" name="<?php echo $this -> get_field_name( 'count' ); ?>" type="number" min="3" max="30" value="<?php echo $count; ?>" /> 75 </p> 76 <?php 77 } 78 79 /* 設定保存 */ 80 public function update( $new_instance, $old_instance ){ 81 $instance = $old_instance; 82 //ウィジェットオプションのデータ検証/無害化 83 $instance['title'] = sanitize_text_field( $new_instance['title'] ); 84 //数値は数値として明示 85 $instance['count'] = absint( $new_instance['count'] ); 86 return $instance; 87 } 88} 89/* ウィジェットテンプレート登録 */ 90add_action( 'widgets_init', function(){ 91 register_widget( 'NewEntryWidget' ); 92});
「Parse error: syntax error, unexpected ')'」は15行目らしいのですが、その周辺を念入りに確認しても特に閉じ忘れ等は見当たりません。
もうどうして良いのやらお手上げ状態なのですが、何か解決方法などはございますでしょうか?
本番環境のPHPバージョンは7.2.6、ローカル環境の方は7.3となります。
使用しているWordPresは最新バージョンの5.0です。
回答1件
あなたの回答
tips
プレビュー