Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug.log warnings - session already started and headers being already sent #32

Open
wants to merge 1 commit into
base: v2.x
Choose a base branch
from

Conversation

kimhornung
Copy link

I have a custom theme that has user logins and related code where I use the PHP session.
In such a case, the SCORM Cloud plugin causes warnings to be written to the log file when WP debug is enabled.

Steps to reproduce

  1. Add the following lines to wp-config.php to enable WP debug
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);
  1. Add the following lines to your theme's functions.php
function theme_start_session() {
	if ( ! session_id() && ! headers_sent() ) {
		session_start();
	}
}
add_action('init', 'theme_start_session');
  1. Visit any page on the website or in the admin.

  2. Also trigger WP cron by visiting "/wp-cron.php?doing_wp_cron=1667920617.6225979328155517578125"

  3. Check /wp-content/debug.log

Result:
The following warnings appears in the log file:

[08-Nov-2022 15:23:57 UTC] PHP Notice:  session_start(): A session had already been started - ignoring in <webroote>/scormcloud/scormcloudcontenthandler.php on line 239
[08-Nov-2022 15:23:57 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at <webroot>/scormcloud/scormcloudcontenthandler.php:239) in <webroot>/wp-includes/pluggable.php on line 1421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant