admin管理员组文章数量:1130349
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_optionandupdate_optionforadd_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: .php
*/
/*
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
* Current plugin version -
* 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.
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_optionandupdate_optionforadd_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/licenses/gpl-license.php
*/
/*
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
* Current plugin version - https://semver
* 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.
Share Improve this question edited Nov 16, 2018 at 17:18 Tahi Reu asked Nov 16, 2018 at 16:43 Tahi ReuTahi Reu 3081 silver badge14 bronze badges 5 |1 Answer
Reset to default 1I solved this issue. Problem was in way I was using register_activation_hook.
I loaded TbybInstall along with other classes:
/*
* Load classes
*/
require plugin_dir_path( __FILE__ ) . 'classes/class.PreparedCarts.php';
require plugin_dir_path( __FILE__ ) . 'classes/class.ReturnOptions.php';
require plugin_dir_path( __FILE__ ) . 'classes/class.TbybInstall.php';
...and I used register_activation_hook in a way which is more similar to official WordPress guide:
/* Create database table on plugin install */
function create_tables(){
TbybInstall::create_tbyb_prepared_carts_table();
}
register_activation_hook( __FILE__, 'create_tables' );
And that's it.
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_optionandupdate_optionforadd_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: .php
*/
/*
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
* Current plugin version -
* 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.
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_optionandupdate_optionforadd_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/licenses/gpl-license.php
*/
/*
* Prevent intruders from sneaking around
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
* Current plugin version - https://semver
* 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.
Share Improve this question edited Nov 16, 2018 at 17:18 Tahi Reu asked Nov 16, 2018 at 16:43 Tahi ReuTahi Reu 3081 silver badge14 bronze badges 5- 1 The "unexpected output" is probably a fatal error message. Check your error logs. – Jacob Peattie Commented Nov 16, 2018 at 17:02
-
I see 2 spaces before the opening
<?phpin yourclass.TbybInstall.phpfile -- are they present on the server, or are they a copy-and-paste artifact present only here? – Pat J Commented Nov 16, 2018 at 17:03 - 1 I don't have anything related to this in my debug.log file. Those two spaces somehow occurred when I pasted code here (I fixed that now). There is no any empty space before <?php in my .php file. – Tahi Reu Commented Nov 16, 2018 at 17:29
-
Check your Apache (or whatever webserver you're using) error logs as well as
debug.log. – Pat J Commented Nov 16, 2018 at 17:36 - Seems like there is no any recent errors in /var/log/apache2/error_log – Tahi Reu Commented Nov 16, 2018 at 17:50
1 Answer
Reset to default 1I solved this issue. Problem was in way I was using register_activation_hook.
I loaded TbybInstall along with other classes:
/*
* Load classes
*/
require plugin_dir_path( __FILE__ ) . 'classes/class.PreparedCarts.php';
require plugin_dir_path( __FILE__ ) . 'classes/class.ReturnOptions.php';
require plugin_dir_path( __FILE__ ) . 'classes/class.TbybInstall.php';
...and I used register_activation_hook in a way which is more similar to official WordPress guide:
/* Create database table on plugin install */
function create_tables(){
TbybInstall::create_tbyb_prepared_carts_table();
}
register_activation_hook( __FILE__, 'create_tables' );
And that's it.
本文标签: phpThe plugin generated 225 characters of unexpected output during activation
版权声明:本文标题:php - The plugin generated 225 characters of unexpected output during activation 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749174357a2327544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


<?phpin yourclass.TbybInstall.phpfile -- are they present on the server, or are they a copy-and-paste artifact present only here? – Pat J Commented Nov 16, 2018 at 17:03debug.log. – Pat J Commented Nov 16, 2018 at 17:36