Der WordPress-Core verwendet keine PHP-Sessions, aber manchmal sind sie für deinen Anwendungsfall, ein Plugin oder ein Theme erforderlich.
Dieses Plugin implementiert die nativen Session-Handler von PHP, die von der WordPress-Datenbank unterstützt werden. Dadurch können Plugins, Themes und benutzerdefinierter Code sicher PHP $_SESSION
s in einer verteilten Umgebung verwenden, in der die standardmäßige Speicherung von temporären PHP-Dateien nicht funktioniert.
Bitte beachte, dass die primäre Entwicklung auf GitHub stattfindet. Wenn du dazu beitragen möchtest:
https://github.com/pantheon-systems/wp-native-php-sessions
Configuration
By default the session lifetime is set to 0, which is until the browser is closed.
To override this use the pantheon_session_expiration
filter before the WordPress Native PHP Sessions plugin is loaded. For example a small Must-use plugin (a.k.a. mu-plugin) could contain:
<?php
function my_session_expiration_override() {
return 60*60*4; // 4 hours
}
add_filter( 'pantheon_session_expiration', 'my_session_expiration_override' );<h3>CLI Commands</h3>
wp pantheon session add-index
Added in 1.4.0. This command should be run if your installation of the plugin occurred before the addition of the primary ID key to the session table in version 1.2.2. You will be automatically notified when you visit any admin page if this is the case. If there’s no message, your version is good to go. Note that this command is non-destructive, a new table will be created and the existing one preserved in a backup state until you have verified that the upgrade is functioning as expected.
wp pantheon session primary-key-finalize
Added in 1.4.0. If you have run the add-index
command and have verified that the new table is functioning correctly, running the primary-key-finalize
command will perform a database cleanup and remove the backup table.
wp pantheon session primary-key-revert
Added in 1.4.0. If you have run the add-index
command and something unexpected has occurred, just run the primary-key-revert
command and the backup table will immediately be returned to being the active table.
WordPress Multisite
As of 1.4.2 the add-index
, primary-key-add
and primary-key-revert
commands are fully multisite compatible.
Mitwirken
See CONTRIBUTING.md for information on contributing.
Problembehandlung
Wenn du einen Fehler wie „Fatal error: session_start(): Failed to initialize storage module:“ oder „Warning: ini_set(): A session is active.“ erhältst, dann hast du wahrscheinlich ein Plugin, das eine Session startet, bevor WP Native PHP Sessions geladen wird.
Erstelle eine neue Datei in wp-content/mu-plugins/000-loader.php
und füge die folgenden Zeilen ein, um dieses Problem zu beheben:
<?php
require_once WP_PLUGIN_DIR . '/wp-native-php-sessions/pantheon-sessions.php';
Dieses mu-Plugin lädt WP Native PHP Sessions vor allen anderen Plugins, während du weiterhin den WordPress-Plugin-Updater verwenden kannst, um das Plugin auf dem neuesten Stand zu halten.