I am getting the famous "The plugin generated xxx characters of unexpected output during activation." error when I activate plugin I am working on.
Terminal says my files are in us-ascii, but when I am working on this files in my PHP Storm, there is UTF-8 mark displayed in the bottom right corner.
I think I don't have empty spaces because my PHP Storm removes them automatically on command+s.
I tried:
- With and without: ?>
- With and without $table_name dynamic prefix declaration
- With and without
$tbyb_db_version
(version) declaration - With both
add_option
andupdate_option
foradd_option( 'tbyb_db_version', self::$tbyb_db_version );
line - With both procedural and OOP static function defining
This is my class.TbybInstall.php
class:
<?php
/**
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* TbybInstall class
*/
if ( !class_exists( 'TbybInstall' ) ) {
class TbybInstall
{
public static $tbyb_db_version = '1.0';
public static function create_tbyb_prepared_carts_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'tbyb_prepared_carts';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id int(11) NOT NULL AUTO_INCREMENT,
user_id int(11) NOT NULL,
product_id int(11) NOT NULL,
variation_id int(11) DEFAULT NULL,
imported_to_cart tinyint(1) DEFAULT '0' NOT NULL,
ordered tinyint(1) DEFAULT '0' NOT NULL,
quantity int(11) DEFAULT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
add_option( 'tbyb_db_version', self::$tbyb_db_version );
}
}
}
This is my plugin-name.php
file:
<?php
/**
* Plugin Name: Plugin name
* Plugin URI: plugin-uri
* Description: Description
* Version: 1.0.0
* Author: Tahi reu
* Author URI: github-link
* License: GPL
* License URI: http://www.opensource.org/licenses/gpl-license.php
*/
/*
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
* Current plugin version - https://semver.org
* This should be updated as new versions are released
*/
define( 'PLUGIN_NAME', '1.0.0' );
/*
* Variables
* */
const TEXT_DOMAIN = "plugin-name";
/*
* Load functions
*/
require plugin_dir_path( __FILE__ ) . 'functions.php';
/*
* Load classes
*/
require plugin_dir_path( __FILE__ ) . 'classes/class.PreparedCarts.php';
require plugin_dir_path( __FILE__ ) . 'classes/class.ReturnOptions.php';
/*
* Check if WooCommerce is installed and active
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
/* Create database table on plugin install */
function create_tables(){
require_once plugin_dir_path( __FILE__ ) . 'classes/class.TbybInstall.php';
TbybInstall::create_tbyb_prepared_carts_table();
}
register_activation_hook( __FILE__, array( 'TbybInstall', 'create_tables' ) );
/* Do the work */
PreparedCarts::on_load();
ReturnOptions::on_load();
} else {
/* Abort and display info message */
PreparedCarts::abort();
}
Any help/suggestions are appreciated. Thanks in advance.
<?php
in yourclass.TbybInstall.php
file -- are they present on the server, or are they a copy-and-paste artifact present only here?debug.log
.