fatal error: Parse error: syntax error, unexpected

2019-09-21 17:40发布

This is the wordpress plugin that was runing fine on old PHP version but now on PHP5.4.X producing the following error.

Plugin could not be activated because it triggered a fatal error.

Parse error: syntax error, unexpected $end in C:\wamp\www\testweb\wp-content\plugins\bxslider\slider.php on line 175

HERE is the SLIDER.PHP File.

<?php
error_reporting(1);
if(!defined('ABSPATH')) {
    die("Don't call this file directly.");
}
if (!defined('WP_CONTENT_URL')) {
    define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
}
define('CONTENT_SLIDE_URL',get_option('siteurl').'/wp-content/plugins/bxslider/');



/* Add Administrator Menu's*/
function bx_content_slide_menu()
{
    $level = 'level_10';
   add_menu_page('BX Content Slide', 'BX Content Slide', $level, __FILE__,'bx_content_slide_options',CONTENT_SLIDE_URL.'images/icon6.png');
   add_submenu_page(__FILE__, 'Help &amp; Support', 'Help &amp; Support', $level,'bx_content_slide_help','bx_content_slide_help');
}
add_action('admin_menu', 'bx_content_slide_menu');

function bx_content_slide_options()
{
    bx_settings_update();
    global $wpdb;
    $query="Select * from wp_slider";
    $slider_res=$wpdb->get_results($query);

    if($_GET['mode']=='edit'){
        $query="select * from wp_slider where id='".$_GET['id']."'";
        $cur_slider_res=$wpdb->get_results($query);


    }

    include_once dirname(__FILE__).'/options_page.php';
}


function bx_settings_update(){
    global $wpdb;
    if(isset($_POST['total_options']))
    {
        echo '<div class="updated fade" id="message"><p>Content Slide Settings <strong>Updated</strong></p></div>';


        for($i=1;$i<=($_POST['total_options']-1);$i++){
            if(!empty($_POST['wpcs_options']['slide_imagetext'.$i])){   
        $query="INSERT INTO `wp_slider` (`image`, `link`, `content`,`name`) VALUES ('".$_POST['wpcs_options']['slide_image'.$i]."', '".$_POST['wpcs_options']['slide_imagelink'.$i]."', '".$_POST['wpcs_options']['slide_imagetext'.$i]."', '".$_POST['name']."');";
        $wpdb->query($query);
            }
        }
        //update_option('bx_options', $_POST['bx_options']);
    }
    if($_GET['mode']=='delete'){
        $wpdb->query("Delete from wp_slider where id='".$_GET['id']."'");
        header("location:admin.php?page=bxslider/slider.php" );
    }
    if($_GET['mode']=='edit' && isset($_POST['id'])){

    $wpdb->query("update wp_slider set image='".$_POST['wpcs_options']['slide_image1']."', link='".$_POST['wpcs_options']['slide_imagelink1']."', content='".$_POST['wpcs_options']['slide_imagetext1'] ."',name='".$_POST['name']  ."' where id='".$_POST['id']."'");
        header("location:admin.php?page=bxslider/slider.php" ); 

    }


}


function createTable()
{
      global $wpdb;

    $qndTable = $wpdb->prefix . "slider";

    if($wpdb->get_var("show tables like '$qndTable'") != $qndTable)
    {
        $create =   "CREATE TABLE " . $qndTable . " (
                              `id` int(11) NOT NULL AUTO_INCREMENT,
                              `image` varchar(255) NOT NULL,
                              `link` varchar(255) NOT NULL,
                              `content` text NOT NULL,
                              `name` varchar(255) NOT NULL,
                              PRIMARY KEY (`id`)
                            ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($create);

    }
}
function deleteTable(){
     global $wpdb;
     $wpdb->query("DROP table ".$wpdb->prefix . "slider");

}

register_activation_hook(__FILE__,  'createTable');

register_deactivation_hook(__FILE__,  'deleteTable');


function bxcontent_slider( $atts ) {
    $sname=$atts[slider];
    $type=$atts[type];
    if(!$type) $type='image';
    global $wpdb;
    $query="Select * from wp_slider where name='".$sname."' ";
    $slider_res=$wpdb->get_results($query);


    addbx_head($sname);         

    if($type=='image'){
    $content .='<ul class="'.$sname.'">';   
        foreach($slider_res as $slider){
            $content .= '<li><img src="'.$slider->image.'" /></li>';
        }
    $content .='</ul>';
    }elseif($type=='content'){
    $content .='<div class="'.$sname.'">';  
        foreach($slider_res as $slider){
        $content .= '<div>'.$slider->content.'</div>';
        }
        $content .='</div>';
    }

    return $content;
    // echo  "slider = {$atts[slider]}";
}
add_shortcode('bxcontentslider', 'bxcontent_slider');
function addbx_head($sname){
?>
<script language='javascript'>
                var $jquery = jQuery.noConflict(); 
                $jquery(document).ready(function(){

                  $jquery('.<?php echo $sname ?>').bxSlider({
                      auto:true,
                      controls:false,
                       pagerCustom: '#bx-pager-<?php echo $sname?>',
                       pagerActiveClass:"active"
                      });


                });

                </script>
<?
}
function add_bxjs() {
    /*wp_enqueue_script(
        'custom-script',
        plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ) ,
        array( 'jquery' )
    );*/
    wp_enqueue_style('bxstyle', plugins_url('/bxslider/jquery.bxslider.css', __FILE__ ));
    wp_enqueue_script('jquery',plugins_url('/bxslider/jquery.min.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('easing',plugins_url('/bxslider/jquery.easing.1.3.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('bxscript',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ), array('jquery'));
}

add_action( 'wp_enqueue_scripts', 'add_bxjs' );

The line 175 stated is have add_action( 'wp_enqueue_scripts', 'add_bxjs' );

标签: php wordpress
1条回答
Fickle 薄情
2楼-- · 2019-09-21 18:29

You have issue with php default and short tags.

<? ... ?>   PHP short tag
<?php ... ?> PHP default tag

See here for more details

Please replace your last few lines with following code

<?php
}
function add_bxjs() {
    /*wp_enqueue_script(
        'custom-script',
        plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ) ,
        array( 'jquery' )
    );*/
    wp_enqueue_style('bxstyle', plugins_url('/bxslider/jquery.bxslider.css', __FILE__ ));
    wp_enqueue_script('jquery',plugins_url('/bxslider/jquery.min.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('easing',plugins_url('/bxslider/jquery.easing.1.3.js', __FILE__ ), array('jquery'));
    wp_enqueue_script('bxscript',plugins_url('/bxslider/jquery.bxslider.js', __FILE__ ), array('jquery'));
}

add_action( 'wp_enqueue_scripts', 'add_bxjs' );
?>
查看更多
登录 后发表回答