The plugin generated xx characters of unexpected output. How to solve?

I get the following message when I activate the plugin `The plugin generated 655 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.’

How can I debug this? I have turned WP_DEBUG on. Any solutions?

<?php
/*
Plugin Name: costing calculator
Description: A costing calculator for the engineering industry
Author: Matthew Pollard
Version: 1.0
*/


register_activation_hook( __FILE__, 'mp_install_countries_table' );
register_activation_hook( __FILE__, 'mp_install_country_data' );
register_activation_hook( __FILE__, 'mp_install_machines_table' );
register_activation_hook( __FILE__, 'mp_install_machines_data' );
register_activation_hook( __FILE__, 'mp_install_settings_table' );
register_activation_hook( __FILE__, 'mp_install_settings_data' );

function mp_install_countries_table()  {
    global $wpdb;
    $table_name = $wpdb->prefix . 'countries';


    $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name tinytext NOT NULL,
        labour_cost INT,
        overheads FLOAT,
        profit FLOAT,
        UNIQUE KEY id (id)
    );";

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

function mp_install_country_data() {

    global $wpdb;

    $table_name = $wpdb->prefix . 'countries';

  $rows =   array(
           array(
            'id' => '1',
            'name' => 'UK',
            'labour_cost' => '20',
            'overheads' => '0.45',
            'profit' => '0.22'     
        ),
        array(
            'id' => '2',
            'name' =>'james',
            'labour_cost' => '6',
            'overheads' => '0.27',
            'profit' => '0.17'  
        )
    );  

    foreach( $rows as $row )
    {
    $wpdb->insert( $table_name, $row);
    }
}

  //creating machines table
function mp_install_machines_table() {
global $wpdb;
    $table_name2 = $wpdb->prefix . 'machines';

 $sql2= "CREATE TABLE $table_name2 (
          id int(11) NOT NULL AUTO_INCREMENT,
          name varchar(255) DEFAULT NULL,
          rate int(11) NOT NULL,
          UNIQUE KEY id (id)
          ) ; ";
          require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
          dbDelta ( $sql2 );
          }
 // populate machines table
function mp_install_machines_data() {
global $wpdb;
$table_name_mach_in = $wpdb->prefix . 'machines';

  $machine_id = '1';
  $machine_name  = 'robot spot welder';
  $machine_rate = '91';   

      $rows_affectedmac = $wpdb->insert( $table_name_mach_in, array( 'id' => $machine_id, 'name' => $machine_name, 'rate' => $machine_rate ));
     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     dbDelta( $rows_affectedmac );
  }

  //creating settings table
function mp_install_settings_table() {
global $wpdb;
    $table_name3 = $wpdb->prefix . 'settings';

 $sql5= "CREATE TABLE $table_name3 (
          id int(11) NOT NULL AUTO_INCREMENT,
          robot_constructional INT,
          robot_stitching FLOAT,
          robot_addr_in FLOAT,
          robot_addr_out FLOAT,
          UNIQUE KEY id (id)
          ) ; ";
          require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
          dbDelta ( $sql5 );
          }  
 //populate settings table
  function mp_install_settings_data() {
global $wpdb;
$table_name_sett_in = $wpdb->prefix . 'settings';

  $setting_id = '1';
  $setting_con  = '3';
  $setting_stitc = '1.8';     
  $setting_rob_in = '2.4';
  $setting_rob_out =  '2.4';
      $rows_affectedset = $wpdb->insert( $table_name_sett_in, array( 'id' => $setting_id, 'robot_constructional' => $setting_con, 'robot_stitching' => $setting_stitc, 'robot_addr_in' => $setting_rob_in, 'robot_addr_out' => $setting_rob_out ));
     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     dbDelta( $rows_affectedset );
  }
  // end of  create table and populating

 // deadctivate the plugin and delete tables
 function mp_uninstall_countries_table() {
  global $wpdb;
  $thetable = $wpdb->prefix. 'countries';
  //Delete any options that's stored also?
   // delete_option('wp_yourplugin_version');
  $wpdb->query("DROP TABLE IF EXISTS $thetable");
} 

 register_deactivation_hook( __FILE__, 'mp_uninstall_countries_table') ;  


//include jquery
add_action( 'wp_enqueue_script', 'load_jquery2' );
function load_jquery2() {
    wp_enqueue_script( 'jquery' );
}      

function add_my_css_and_my_js_files(){
    wp_enqueue_script('jquery-validate-min', plugins_url('activate/jquery_validate_min.js', __FILE__ ) );
}
add_action('wp_enqueue_scripts', "add_my_css_and_my_js_files");

// shortcode to display calcs
add_action( 'init', 'register_shortcodes');
function register_shortcodes() {
add_shortcode( 'displaycalcs', 'mp_calcs_display' );
}

function mp_calcs_display() {
return '
<form name="calsinput" action="" method="post" id="calsinput" >
<h1> Process </h1>
<p> operation type always robot </p>
<br> <br>
Number of welds: <input type="number" name="numberofwelds" class="required digits" title="This field is required and must be a no."  >
<br> <br>
Number of construction welds: <input type="number" name="numberofconwelds" class="required digits"  title="This field is required and must be a no.">
<br> <br>
<h2> Outputs </h2>
<br> <br>
Robot in/out: <input type="text" name="robotinout" disabled>
<br> <br>
Weld time: <input type="text" name="weldtime" disabled>
<br> <br>
Controlling cycle: <input type="text" name="concycle" disabled> 
<br> <br>
Total time(secs): <input type="text" name="totaltimesecs" disabled>
<br> <br> <br> <br>
<input type="submit" value="Calculate cycle time ">
</form>  

<script type="text/javascript">
    jQuery(document).ready(function($) {
        $("#calsinput").validate();
    });  
</script>';
}

Related posts

1 comment

  1. The issue appears to be in the formatting of your mp_calcs_display() function. I modified the function to use the heredoc syntax for your html output, and was then able to activate the plugin successfully.

     function mp_calcs_display() {
        $output = <<<HTML
    <form name="calsinput" action="" method="post" id="calsinput" ><h1> Process </h1>
    <p> operation type always robot </p>
    <br> <br>
    Number of welds: <input type="number" name="numberofwelds" class="required digits" title="This field is required and must be a no."  >
    <br> <br>
    Number of construction welds: <input type="number" name="numberofconwelds" class="required digits"  title="This field is required and must be a no.">
    <br> <br>
    <h2> Outputs </h2>
    <br> <br>
    Robot in/out: <input type="text" name="robotinout" disabled>
    <br> <br>
    Weld time: <input type="text" name="weldtime" disabled>
    <br> <br>
    Controlling cycle: <input type="text" name="concycle" disabled>
    <br> <br>
    Total time(secs): <input type="text" name="totaltimesecs" disabled>
    <br> <br> <br> <br>
    <input type="submit" value="Calculate cycle time ">
    </form>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $("#calsinput").validate();
        });</script>
    HTML;
    
        return $output;
    }
    

    Full plugin file with above fix that was used for testing: https://gist.github.com/rachelbaker/ac13110e19321aed45ae

Comments are closed.