0

I am making a plugin, and for some reason, it is now saying the first line is "unexpected," no matter what it is.

It was working fine before, I made an edit at the bottom of the file, but have since removed it and reuploaded, and it is still throwing the error.

For a second it switched to and "invalid header" error.

Here's the code:

<?php
/*
*Plugin Name: Products Tools
*Description: products widget
*/
require_once(plugin_dir_path( __FILE__ ).'get-product.php');
require_once(plugin_dir_path( __FILE__ ).'output.php');
require_once(plugin_dir_path( __FILE__ ).'shortcode.php');
require_once(plugin_dir_path( __FILE__ ).'all-products.php');
require_once(plugin_dir_path( __FILE__ ).'add-templates.php');
//require(plugin_dir_path( __FILE__ ).'products-json.php');
//require(plugin_dir_path( __FILE__ ).'create-page.php');
//require(plugin_dir_path( __FILE__ ).'widget.php');
//require(plugin_dir_path( __FILE__ ).'widget2.php');



function product_box_cpt() {

register_post_type( 'product', array(
  'labels' => array(
    'name' => 'Products',
    'singular_name' => 'Product',
   ),
  'description' => 'Hosting Prodcuts.',
  'public' => true,
  'menu_position' => 8,
  'supports' => array( 'title', 'editor', 'custom-fields' ),
  'has_archive' => 'products'
));
}

and the error:

Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /home/davidmno/public_html/beadedtreasures/wp-content/plugins/product-box/product-box.php on line 1

The thing is, if I comment out the require lines, then it just says "unexpected function"... It seems like whatever php is calling it could be the problem?

1
  • Did you try disabling all other plugins and switch to Wordpress standard twenty fifteen theme? Commented May 12, 2015 at 4:36

1 Answer 1

1

This is a long shot but is there any possibility your text editor is encoding the file in UTF-8 with BOM? Try to save / encode the file in UTF-8 without BOM and see if the issue is gone.

As for your plugin header, while it doesn't totally follow the recommended format your header should still be parsed correctly since this is what the main code looks like for parsing the header:

preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match )

Notice that you can in fact have spaces / tabs / asterisk at the beginning of each line.

1
  • Thanks for the reply.. I did check that. no dice. :/
    – scl
    Commented May 14, 2015 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.