forked from pressbooks/pressbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpressbooks.php
More file actions
148 lines (120 loc) · 5.78 KB
/
Copy pathpressbooks.php
File metadata and controls
148 lines (120 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/*
Plugin Name: Pressbooks
Plugin URI: https://pressbooks.com
Description: Simple Book Production
Version: 3.9.7-dev
Author: Book Oven Inc.
Author URI: https://pressbooks.com
Text Domain: pressbooks
License: GPLv2
GitHub Plugin URI: https://github.com/pressbooks/pressbooks
Release Asset: true
*/
if ( ! defined( 'ABSPATH' ) ) {
return;
}
// -------------------------------------------------------------------------------------------------------------------
// Turn on $_SESSION
// -------------------------------------------------------------------------------------------------------------------
function _pb_session_start() {
if ( ! session_id() ) {
if ( ! headers_sent() ) {
ini_set( 'session.use_only_cookies', true );
apply_filters( 'pressbooks_session_configuration', false );
session_start();
} else {
error_log( 'There was a problem with _pb_session_start(), headers already sent!' );
}
}
}
function _pb_session_kill() {
$_SESSION = array();
session_destroy();
}
add_action( 'init', '_pb_session_start', 1 );
add_action( 'wp_logout', '_pb_session_kill' );
add_action( 'wp_login', '_pb_session_kill' );
// -------------------------------------------------------------------------------------------------------------------
// Setup some defaults
// -------------------------------------------------------------------------------------------------------------------
if ( ! defined( 'PB_PLUGIN_VERSION' ) ) {
define( 'PB_PLUGIN_VERSION', '3.9.6' );
}
if ( ! defined( 'PB_PLUGIN_DIR' ) ) {
define( 'PB_PLUGIN_DIR', ( is_link( WP_PLUGIN_DIR . '/pressbooks' ) ? trailingslashit( WP_PLUGIN_DIR . '/pressbooks' ) : trailingslashit( __DIR__ ) ) ); // Must have trailing slash!
}
if ( ! defined( 'PB_PLUGIN_URL' ) ) {
define( 'PB_PLUGIN_URL', trailingslashit( plugins_url( 'pressbooks' ) ) ); // Must have trailing slash!
}
if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
if ( defined( 'PB_BOOK_THEME' ) ) {
define( 'WP_DEFAULT_THEME', PB_BOOK_THEME );
} else {
define( 'WP_DEFAULT_THEME', 'pressbooks-book' );
}
}
if ( ! defined( 'PB_ROOT_THEME' ) ) {
define( 'PB_ROOT_THEME', 'pressbooks-publisher' );
}
// -------------------------------------------------------------------------------------------------------------------
// Class autoloader
// -------------------------------------------------------------------------------------------------------------------
function _pressbooks_autoload( $class_name ) {
$prefix = 'Pressbooks\\';
$len = strlen( $prefix );
if ( strncasecmp( $prefix, $class_name, $len ) !== 0 ) {
// Ignore classes not in our namespace
return;
}
$parts = explode( '\\', strtolower( $class_name ) );
array_shift( $parts );
$class_file = 'class-pb-' . str_replace( '_', '-', array_pop( $parts ) ) . '.php';
$path = count( $parts ) ? implode( '/', $parts ) . '/' : '';
@include( PB_PLUGIN_DIR . 'includes/' . $path . $class_file );
}
spl_autoload_register( '_pressbooks_autoload' );
// -------------------------------------------------------------------------------------------------------------------
// Composer autoloader (if needed)
// -------------------------------------------------------------------------------------------------------------------
if ( file_exists( $composer = PB_PLUGIN_DIR . 'vendor/autoload.php' ) ) {
require_once( $composer );
} else {
if ( ! class_exists( '\Pimple\Container' ) ) {
die( sprintf( __( 'Pressbooks dependencies are missing. Please make sure that your project’s <a href="%1$s">Composer autoload file</a> is being required, or use the <a href="%2$s">latest release</a> instead.', 'pressbooks' ), 'https://getcomposer.org/doc/01-basic-usage.md#autoloading', 'https://github.com/pressbooks/pressbooks/releases/latest/' ) );
}
}
// -------------------------------------------------------------------------------------------------------------------
// Check minimum requirements
// -------------------------------------------------------------------------------------------------------------------
if ( ! function_exists( 'pb_meets_minimum_requirements' ) && ! @include_once( PB_PLUGIN_DIR . 'compatibility.php' ) ) {
add_action( 'admin_notices', function () {
echo '<div id="message" class="error fade"><p>' . __( 'Cannot find Pressbooks install.', 'pressbooks' ) . '</p></div>';
} );
return;
} elseif ( ! pb_meets_minimum_requirements() ) {
return;
}
// -------------------------------------------------------------------------------------------------------------------
// Configure root site
// -------------------------------------------------------------------------------------------------------------------
register_activation_hook( __FILE__, function () {
$activate = new \Pressbooks\Activation();
$activate->registerActivationHook();
} );
// -------------------------------------------------------------------------------------------------------------------
// Initialize
// -------------------------------------------------------------------------------------------------------------------
$GLOBALS['pressbooks'] = new \Pressbooks\Pressbooks();
// -------------------------------------------------------------------------------------------------------------------
// Hooks
// -------------------------------------------------------------------------------------------------------------------
require( PB_PLUGIN_DIR . 'hooks.php' );
if ( is_admin() ) {
require( PB_PLUGIN_DIR . 'hooks-admin.php' );
}
// --------------------------------------------------------------------------------------------------------------------
// Shortcuts to help template designers who don't use real namespaces...
// --------------------------------------------------------------------------------------------------------------------
require( PB_PLUGIN_DIR . 'functions.php' );
/* The distinction between "the internet" & "books" will disappear in 5 years. Start adjusting now. */