• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implement native PHP sessions stored in the database for WordPress.

WordPress Native PHP Sessions

Contributors: getpantheon, outlandish josh, mpvanwinkle77, danielbachhuber, andrew.taylor, jazzs3quence, stovak, jspellman
Tags: comments, sessions
Requires at least: 4.7
Tested up to: 6.2.2
Stable tag: 1.3.6
Requires PHP: 5.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Use native PHP sessions and stay horizontally scalable. Better living through superior technology.

Description

Actively Maintained CircleCI

WordPress core does not use PHP sessions, but sometimes they are required by your use-case, a plugin or theme.

This plugin implements PHP's native session handlers, backed by the WordPress database. This allows plugins, themes, and custom code to safely use PHP $_SESSIONs in a distributed environment where PHP's default tempfile storage just won't work.

Note that primary development is on GitHub if you would like to contribute:

https://github.com/pantheon-systems/wp-native-php-sessions

Installation

  1. Upload to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress

That's it!

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' );

Contributing

See CONTRIBUTING.md for information on contributing.

Frequently Asked Questions

Why not use another session plugin?

This implements the built-in PHP session handling functions, rather than introducing anything custom. That way you can use built-in language functions like the $_SESSION superglobal and session_start() in your code. Everything else will "just work".

Why store them in the database?

PHP's fallback default functionality is to allow sessions to be stored in a temporary file. This is what most code that invokes sessions uses by default, and in simple use-cases it works, which is why so many plugins do it.

However, if you intend to scale your application, local tempfiles are a dangerous choice. They are not shared between different instances of the application, producing erratic behavior that can be impossible to debug. By storing them in the database the state of the sessions is shared across all application instances.

Troubleshooting

If you see an error like "Fatal error: session_start(): Failed to initialize storage module:" or "Warning: ini_set(): A session is active.", then you likely have a plugin that is starting a session before WP Native PHP Sessions is loading.

To fix, create a new file at wp-content/mu-plugins/000-loader.php and include the following:

<?php
require_once WP_PLUGIN_DIR . '/wp-native-php-sessions/pantheon-sessions.php';

This mu-plugin will load WP Native PHP Sessions before all other plugins, while letting you still use the WordPress plugin updater to keep the plugin up-to-date.

Changelog

1.3.6 (June 1, 2023)

  • Fixes PHP 8.2 deprecated dynamic property error [#251] (props @miguelaxcar)
  • Update CONTRIBUTING.md [#252].
  • Update informational Error message for the case of headers already sent [#249].
  • Add pantheon-wp-coding-standards [#247].

1.3.5 (April 7, 2023)

  • Bump yoast/phpunit-polyfills from 1.0.4 to 1.0.5 [#245].
  • Bump tested up to version

1.3.4 (February 7, 2023)

  • Add fallback for $session->get_data() [[#237(#237)]] (reported on WordPress.org)
  • Update CODEOWNERS file [#239]
  • Fix GPL license in composer.json file [#236]
  • Bump grunt from 1.5.3 to 1.6.1 [#235]

1.3.3 (January 25, 2023)

  • Bump version in pantheon-sessions.php [#234].

1.3.2 (January 25, 2023)

  • PHP 8.2 compatibility [#232].
  • Bump dealerdirect/phpcodesniffer-composer-installer from 0.7.2 to 1.0.0 [#229].
  • Update images for lint and test-behat jobs [#228].

1.3.1 (December 5, 2022)

  • Document session lifetime handling [#224].
  • Make dependabot target develop branch [#226].
  • Ignore .wordpress-org directory [#223].

1.3.0 (November 28th, 2022)

  • Added CONTRIBUTING.MD and GitHub action to automate deployments to wp.org. [#219]

1.2.5 (October 28th, 2022)

  • Added #[ReturnTypeWillChange] where required to silence deprecation warnings in PHP 8.1. [#216]

1.2.4 (September 14th, 2021)

  • Increases data blob size from 64k to 16M for new session tables; existing tables will need to manually modify the column if they want to apply this change [#193].

1.2.3 (April 9th, 2021)

  • Assigns the table name to a variable before using in query [#188].

1.2.2 (March 29th, 2021)

  • Includes an auto-incrementing id column for replication support [#187].

1.2.1 (September 17th, 2020)

  • Plugin textdomain needs to be the same as the WordPress.org slug [#169].

1.2.0 (May 18th, 2020)

  • Avoids using cookies for sessions when WP-CLI is executing [#154].

1.1.0 (April 23rd, 2020)

  • Avoids initializing PHP sessions when doing cron [#149].

1.0.0 (March 2nd, 2020)

  • Plugin is stable.

0.9.0 (October 14th, 2019)

  • Refactors session callback logic into Session_Handler abstraction, fixing PHP notice in PHP 7.3 [#135].

0.8.1 (August 19th, 2019)

  • Fixes handling of 'X-Forwarded-For' header in get_client_ip_server() [#126].

0.8.0 (August 13th, 2019)

  • Respects various HTTP_* sources for client IP address [#122].

0.7.0 (April 3rd, 2019)

  • Adds a safety check that restores $wpdb when it's missing.

0.6.9 (May 15th, 2018)

  • Ensures _pantheon_session_destroy() uses a return value.

0.6.8 (May 4th, 2018)

  • Switches to E_USER_WARNING instead of E_WARNING when triggering errors.

0.6.7 (April 26th, 2018)

  • Disables plugin load when WP_INSTALLING, because session table creation breaks installation process.

0.6.6 (March 8th, 2018)

  • Restores session instantiation when WP-CLI is executing, because not doing so causes other problems.

0.6.5 (February 6th, 2018)

  • Disables session instantiation when defined( 'WP_CLI' ) && WP_CLI because sessions don't work on CLI.

0.6.4 (October 10th, 2017)

  • Triggers PHP error when plugin fails to write session to database.

0.6.3 (September 29th, 2017)

  • Returns false when we entirely fail to generate a session.

0.6.2 (June 6th, 2017)

  • Syncs session user id when a user logs in and logs out.

0.6.1 (May 25th, 2017)

  • Bug fix: Prevents warning session_write_close() expects exactly 0 parameters, 1 given.

0.6.0 (November 23rd, 2016)

  • Bug fix: Prevents PHP fatal error in session_write_close() by running on WordPress' shutdown action, before $wpdb destructs itself.
  • Bug fix: Stores the actual user id in the sessions table, instead of (bool) $user_id.

0.5

  • Compatibility with PHP 7.
  • Adds pantheon_session_expiration filter to modify session expiration value.

0.4

  • Adjustment to session_id() behavior for wider compatibility
  • Using superglobal for REQUEST_TIME as opposed to time()

0.3

  • Fixes issue related to WordPress plugin load order

0.1

  • Initial release

More Repositories

1

terminus

The Pantheon CLI — a standalone utility for performing operations on the Pantheon Platform
PHP
298
star
2

wp-redis

WordPress Object Cache using Redis.
PHP
204
star
3

wordpress-at-scale

Gathering best practices from the community to help developers and site owners find success in scaling WordPress.
197
star
4

documentation

Pantheon Docs
JavaScript
188
star
5

autotag

Git repository version tagging tool
Go
172
star
6

WordPress

WordPress upstream for the Pantheon website platform. Includes a platform integration plugins and a pre-configured wp-config.php.
PHP
157
star
7

quicksilver-examples

Example scripts for using Pantheon's Quicksilver Platform Hooks
PHP
128
star
8

solr-power

A WordPress plugin to connect to Pantheon's Apache Solr search infrastructure, or your own!
PHP
123
star
9

drops-7

Pantheon Upstream for Drupal 7 Sites
PHP
97
star
10

example-wordpress-composer

PHP
95
star
11

example-drops-8-composer

Install drops-8 with Composer on Pantheon.
Shell
94
star
12

wp_launch_check

WP-CLI Plugin to run checks against installation for Performance and Security
PHP
94
star
13

terminus-build-tools-plugin

Manage multidev environments for a Pantheon site using a GitHub PR workflow.
PHP
83
star
14

drops-8

Pantheon Upstream for Drupal 8 Sites. Deprecated; please see https://github.com/pantheon-upstreams/drupal-composer-managed
PHP
81
star
15

wp-saml-auth

Rock-solid SAML authentication for WordPress built on a modern foundation.
PHP
81
star
16

drush-config-workflow

Jumpstart your Drupal configuration merge magic with this repo's code and instructions.
Shell
68
star
17

example-terminus-auto-update-script

Shell
56
star
18

fusedav

Successor to git://git.0pointer.de/fusedav.git
C
45
star
19

docker-build-tools-ci

Dockerfile source for docker image pantheon-public/build-tools-ci on quay.io
Shell
33
star
20

github-gist-gutenberg-block

Include GitHub Gists in your Gutenberg posts without the hassle of shortcodes
Shell
33
star
21

pantheon-advanced-page-cache

Plugin to make the most of Pantheon's Global CDN with advanced page caching options.
PHP
32
star
22

pantheon-settings-examples

Pantheon optimized examples for hard-coded Drupal configuration in settings.php
PHP
28
star
23

terminus-secrets-plugin

A simple secrets management plugin for Terminus
PHP
22
star
24

kube-gce-cleanup

Clean up GCE network load-balancer resources left behind by kubernetes (GKE)
Shell
19
star
25

ariadne-extensions

Set of scripts and helper utilities to extend Ariadne GraphQL library
Python
17
star
26

terminus-site-clone-plugin

A Terminus plugin that adds the `site:clone` command to facilitate cloning sites on Pantheon
PHP
17
star
27

terminus-github-actions

A GitHub Action for setting up Pantheon's CLI tool, Terminus.
16
star
28

terminus-rsync-plugin

Terminus Plugin that provides a quick shortcut for rsync-ing files to and from a Pantheon site.
PHP
15
star
29

pantheon-wordpress-upstream-tests

Tests behavior of WordPress Core upstreams for Pantheon. Also within test suites of contrib plugins
Gherkin
15
star
30

iozone

iozone filesystem benchmark, based on v. 3_414
C
14
star
31

quicksilver-pushback

Push any commits made on the Pantheon dashboard back to the original GitHub repository.
PHP
14
star
32

pantheon-hud

Pantheon HUD plugin for WordPress providing a heads-up display into your Pantheon environment.
PHP
14
star
33

wordpress-network

This is a derived upstream from https://github.com/pantheon-systems/wordpress which contains the necessary configuration adjustments to make a WordPress Multisite successful on Pantheon.
PHP
14
star
34

decoupled-kit-js

Pantheon's monorepo for JavaScript SDKs, starter examples, and published npm packages.
JavaScript
14
star
35

terminus-mass-update

A Terminus plugin to apply upstream updates to multiple sites at once
PHP
13
star
36

cassandra-operator

operator for managing cassandra clusters
Go
12
star
37

terminus-composer-plugin

A Terminus plugin for running Composer commands on a Pantheon site
Shell
12
star
38

pantheon_domain_masking

Domain Masking helper module for D8
PHP
11
star
39

pantheon-wordpress-develop

A set of scripts to do nightly testing on Pantheon of the latest WordPress commits
PHP
11
star
40

site-audit-tool

Experimental project to extract Site Audit checks into a separate project
PHP
10
star
41

wordpress-bedrock-recommended

Shell
10
star
42

drupal-composer-managed

Pantheon platform's standard Drupal upstream, and recommended starter template for custom upstreams.
PHP
10
star
43

circleci-orb

Use CircleCI to push code to Pantheon Dev and Multidev Environments
10
star
44

drupal-integrations

Add this project to any Drupal distribution based on drupal/core-composer-scaffold to enable it for use on Pantheon.
PHP
10
star
45

pauditd

go based alternative to auditd
Go
9
star
46

terminus-site-debug

A Terminus plugin that can parse site logs and display NewRelic summary.
PHP
9
star
47

wordpress-composer

WordPress for Pantheon with a composer.json file.
PHP
9
star
48

pantheon-mu-plugin

Pantheon's WordPress mu-plugin for all WordPress-based upstreams.
PHP
8
star
49

docker_iptables

Utility to help manually manage iptables port mappings of Docker containers
Python
8
star
50

terminus-drupal-console-plugin

Run Drupal Console commands on Pantheon
Shell
7
star
51

terminus-installer

Installer for Pantheon Terminus
PHP
7
star
52

wp-decoupled-preview

Preview WordPress content on Front-end sites including Next.js
PHP
7
star
53

terminus-secrets-manager-plugin

Terminus Secrets Manager Plugin (Early Access)
PHP
7
star
54

drops-6

Pantheon Pressflow 6 for DROPs
PHP
7
star
55

search_api_pantheon

ApachSolr on Pantheon for Drupal 8/9 via Search API
PHP
7
star
56

example-drops-7-composer

Install drops-7 with Composer on Pantheon.
PHP
7
star
57

next-drupal-starter

This repository is a mirror. See https://github.com/pantheon-systems/decoupled-kit-js to join the discussion or submit an issue.
JavaScript
7
star
58

localdev-issues

Issue tracking for Pantheon localdev
6
star
59

drupal-recommended

DEPRECATED: Please use https://github.com/pantheon-upstreams/drupal-composer-managed
Shell
6
star
60

terminus_debugging_tools

A collection of terminus plugins to facilitate managing sites on Pantheon.
PHP
6
star
61

wordpress-composer-managed

WordPress boilerplate with Composer, easier configuration, and an improved folder structure
Shell
6
star
62

pmr

Process maps restarter
Python
6
star
63

drops-8-scaffolding

Scaffold files from drops-8: everything except /core, /composer.lock and /vendor
PHP
6
star
64

terminus-quicksilver-plugin

A Terminus plugin to help you get started quickly with Quicksilver
PHP
6
star
65

kube-gce-dns

Kube system service to register services in GCE DNS
Go
5
star
66

gatsby-starter-default

Development repository for Pantheon's Gatsby starter
CSS
5
star
67

countdown-timer-gutenberg-block

JavaScript
5
star
68

pantheon-image-enrichment

Proof of Concept - using Google Vision API to add value to WordPress
PHP
5
star
69

go-certauth

Go handlers and middleware to do client cert authentication.
Go
5
star
70

go-healthz

Package that implements a healthcheck server
Go
4
star
71

downstream-updater

Scripts useful for building a Continuous Integration system to update and test new releases from an upstream project.
Shell
4
star
72

pantheon-content-cloud-sdk

TypeScript
4
star
73

terminus-composer-logs-plugin

Terminus plugin to show composer logs.
PHP
4
star
74

redis

PHP
4
star
75

tbt-ci-templates

CI Integrations for Terminus Build Tools template repos
Shell
4
star
76

pantheon_log_retriever

PHP, Shell, Python and Perl script for app and db server log retrieval
PHP
4
star
77

smart_content_cdn

An experimental Drupal module to leverage Edge Integrations
PHP
4
star
78

update-tool

The Update Tool is responsible for detecting available software updates and creating pull requested as needed.
PHP
4
star
79

baryon

Layered Chef Universe Server
Go
4
star
80

nginx

Fork from git://pkgs.fedoraproject.org/nginx.git with support for systemd socket activation, full WebDAV, and syslog logging
Shell
4
star
81

selenium-zoetrope

PHP
4
star
82

systemd

Pantheon's very shallow fork of the official Fedora package
Shell
4
star
83

pantheon-edge-integrations

PHP
3
star
84

phpcompatibility-action

Shell
3
star
85

php-remote-error-monitor

PHP Module replacing APM in PHP 8
C
3
star
86

terminus-aliases-plugin

A plugin for Terminus which creates a complete aliases file.
PHP
3
star
87

dnscheck

DEPRECATED - no longer maintained. A PHP app to check that your DNS is correctly configured for Pantheon routing.
Less
3
star
88

fastly-io

WordPress plugin to let Fastly IO handle all the media library cropping and resizing
PHP
3
star
89

alpine-node

Tiny Node.js container built on alpine linux
Dockerfile
3
star
90

composer-lock-docker

Provides a "composer lock" service as a Python Flask app in a docker container.
Python
3
star
91

pantheon_advanced_page_cache

Drupal cache metadata + Pantheon's Global CDN
PHP
3
star
92

terminus-plugin-example

A simple plugin for Terminus to demonstrate how to add new commands
PHP
3
star
93

terminus-conversion-tools-plugin

Conversion Tools is a Terminus plugin that contains commands to convert a standard Drupal site into a composer managed one.
PHP
3
star
94

terminus-autopilot-plugin

PHP
2
star
95

etl-framework

Python
2
star
96

apm

Legacy APM version for PHP log submission.
C
2
star
97

vue-agcdn-mgmt

Vue app for AGCDN management
Vue
2
star
98

drupal-9-with-circleci-orb

PHP
2
star
99

markdown-toc-docker

markdown-toc CLI in a small docker container
Dockerfile
2
star
100

advanced-ci-templates

DEPRECATED - Advanced Templates and CI Integrations for Terminus Build Tools projects
Shell
2
star