[wp-trac] [WordPress Trac] #57475: wp_schedule_event function causes "Headers already sent" error

WordPress Trac noreply at wordpress.org
Mon Jan 16 21:19:53 UTC 2023


#57475: wp_schedule_event function causes "Headers already sent" error
--------------------------+------------------------------
 Reporter:  onetarek      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Cron API      |    Version:  6.1.1
 Severity:  normal        |   Keywords:  has-testing-info
  Focuses:                |
--------------------------+------------------------------
 I need to start the **PHP session** for my plugin. On plugin activation, I
 am getting PHP Warning.

 {{{
 PHP Warning:  session_start(): Cannot start session when headers already
 sent in..
 }}}

 On register_activation_hook I am using **wp_schedule_event()** to register
 my custom event hook. If I remove wp_schedule_event() I don't see the PHP
 Warning. So we can say that the wp_schedule_event function prints
 something that causes the Warning.

 To test this issue use my simple plugin code below.

 {{{#!php
 <?php
 /**
  * Plugin Name: Test plugin
  * Description: Just a Test plugin
  * Plugin URI: http://onetarek.com
  * Author: oneTarek
  * Author URI: http://onetarek.com
  * Version: 1.0.0
  */


 function test_activation() {
         wp_schedule_event( time(), 'daily', 'test_daily_event_hook' );
 }

 function test_deactivation() {
         wp_clear_scheduled_hook( 'test_daily_event_hook' );
 }

 register_activation_hook( __FILE__, 'test_activation' );

 register_deactivation_hook( __FILE__, 'test_deactivation' );

 if( session_id() == "" ){ session_start(); }
 }}}

 Install this plugin code. Activate and check debug log. Try activating and
 deactivating this plugin multiple times if you don't see any Warning.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57475>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list