Ich schreibe mein erstes Plugin und meine Echo-Ausgabe wird auf jeder Seite meiner WordPress-Installation angezeigt

Ich benutze Echo und print_r, um beim Debuggen zu helfen, und die Ausgabe wird überall angezeigt. Ich verwende wp_cron und $ wpdb sowie regelmäßige SQL-Abfragen. Irgendeine Idee warum das passiert? Ich habe nach einer Antwort gegoogelt und konnte nichts finden. Das lässt mich denken, dass ich etwas falsch gemacht habe, wenn niemand sonst dieses Problem hatte.

<?php /** * Plugin Name: Automatic Home Descriptions * Plugin URI: ***************** * Description: this is my plugin * Author: David Petrey * Version: 1.0 */ if ( !defined('ABSPATH') ) { /** Set up WordPress environment */ require_once('../../../wp-load.php'); } // $included_files = get_included_files(); // foreach ($included_files as $filename) { // echo "$filename\n"; // } global $wpdb; //Create connection $conn = mysqli_connect(**************************); //Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } //echo 'connect mysqli 

'; // add custom interval function add_new_intervals($schedules) { // add weekly and monthly intervals $schedules['desc_update'] = array( 'interval' => 30, 'display' => __('Desc_Update') ); return $schedules; } add_filter( 'cron_schedules', 'add_new_intervals'); //echo 'set custom time

'; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Finds out what id's need to be processed $d = $wpdb->get_results( "SELECT productid FROM homes WHERE populated=' ' AND builder_code !=' '", ARRAY_A); $newids = array(); foreach($d as $ds){ foreach ($ds as $k) { $newids[] = $k; // echo '  '; echo $k; echo '  '; }; }; echo ' new id\'s '; print_r($newids); echo '
'; //echo 'new id\'s

'; // Random word spinner ///////////////////// $exclude = array(); $sp1 = array('gorgeous', 'stunning', 'beautiful', 'charming', 'exquisite', 'elegant', 'lovely', 'enchanting'); $sp2 = array('home', 'house'); $sp3 = array('spacious', 'roomy', 'comfortable'); function randWord($ar, $reset) { global $exclude; global $sp1; global $sp2; global $sp3; if($reset == true){ $exclude = array(); //echo 'reset

'; } //echo '

===

'; $wrdcount = count($ar); //echo ' $wrdcount ' . $wrdcount; do { $num = rand(0,$wrdcount - 1); } while(in_array($num, $exclude)); //echo ' $num ' . $num . ' '; array_push($exclude, $num); //echo 'my exclude array '; print_r($exclude); echo '
'; // echo ' rand $exclude '; print_r($ar); // echo ' $ar[$num] '.$ar[$num].'
'; return $ar[$num]; } /////////////////// //echo 'word spinner

'; // PULLS OUT ATTRIBUTES ////////////////// function runfeat ($feat_table, $builder){ global $wpdb; $get_features = $wpdb->get_results( "SELECT Feature FROM $feat_table WHERE $builder='Y'", ARRAY_A ); $feat_all = array(); foreach($get_features as $get_feature){ array_push($feat_all,$get_feature['Feature']); } shuffle($feat_all); if($feat_table == 'feat_kit'){ if(count($feat_all) < 8){ $need = 8 - count($feat_all); for($a=0; $a < $need; $a++){ array_push($feat_all, $feat_all[$a]); } } } echo ' inside runfeat '; print_r($feat_all); return $feat_all; } //////////////////// //echo 'grab attributes

'; // add wp cron task // add_action( 'hook_name', 'function_name' ); add_action( 'cron_testing', 'builder_task' ); if( !wp_next_scheduled( 'cron_testing' ) ) { wp_schedule_event( time(), 'desc_update', 'cron_testing' ); } // echo 'add cron event

'; // remove cron task ////////////////////////////////////// // if( false !== ( $time = wp_next_scheduled( 'my_cron' ) ) ) { // wp_unschedule_event( $time, 'my_cron' ); // } // or remove cron task // $timestamp = wp_next_scheduled( 'cron_testing' ); // wp_unschedule_event($timestamp, 'cron_testing' ); function builder_task() { global $conn; global $newids; global $wpdb; // CREATES NEW ROWS IN home_descriptions /////////// LOOP ///////// //echo 'newids? '; print_r($newids); //echo 'newids? count '; print_r(count($newids)); echo '
'; for($i=0; $i < count($newids); $i++){ //echo '

----------loop to create rows
'; $getbuilder = $wpdb->get_row("SELECT builder_code FROM homes WHERE productid=$newids[$i]", ARRAY_A); $builder = $getbuilder['builder_code']; echo ' $builder '.$builder.'

'; echo 'call runfeat

'; $kitlist = runfeat('feat_kit', $builder); $bathlist = runfeat('feat_bath', $builder); $mbathlist = runfeat('feat_mbath', $builder); echo 'after run feature
'; global $sp1; global $sp2; global $sp3; $spin1 = randWord($sp1, true); $spin2 = randWord($sp2, false); $spin3 = randWord($sp3, false); //echo '
called word spinner

'; //echo 'spinner words '.$spin1 .' '. $spin2 .' '. $spin3.'
'; // DOES ROW EXIST? IF NOT ADD IT $check = $wpdb->get_row("SELECT productid FROM home_descriptions WHERE productid=$newids[$i]", ARRAY_A); //if( $check['productid'] == NULL){ //echo '

check for id if its not there, add it

'; $wpdb->insert('home_descriptions', array('productid' => $newids[$i] )); echo 'bcode '. $builder_code; // WRITE TO NEW home_descriptions row $sql = "UPDATE home_descriptions SET spin1 = '$spin1', spin2 = '$spin2', spin3 = '$spin3', kit1 = '$kitlist[0]', kit2 = '$kitlist[1]', kit3 = '$kitlist[2]', kit4 = '$kitlist[3]', kit5 = '$kitlist[4]', kit6 = '$kitlist[5]', kit7 = '$kitlist[6]', kit8 = '$kitlist[7]', bath1 = '$bathlist[0]', bath2 = '$bathlist[1]', bath3 = '$bathlist[2]', mbath1 = '$mbathlist[0]', mbath2 = '$mbathlist[1]', mbath3 = '$mbathlist[2]' WHERE productid = $newids[$i]"; if (mysqli_query($conn, $sql)) { $wpdb->update("homes", array("populated" => 'true'), array( 'productid' => $newids[$i] )); echo "Record updated successfully"; } else { echo "Error updating record: " . mysqli_error($conn); } //}else{ // echo '

already exists'; //} } } if(count($newids) > 0){ //echo '

--call builder task--


'; builder_task(); }else{ // echo '

no new id\'s


'; } //echo 'disconnect

'; mysqli_close($conn); ?>

Solutions Collecting From Web of "Ich schreibe mein erstes Plugin und meine Echo-Ausgabe wird auf jeder Seite meiner WordPress-Installation angezeigt"