forked from BrilliantPlugins/wp-geometa-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-geometa-lib-loader.php
136 lines (117 loc) · 3.79 KB
/
wp-geometa-lib-loader.php
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
<?php
/**
* This is the loader file for WP-GeoMeta-lib.
*
* @package wp-geometa-lib
*
* Version: 0.4.0
*
* To include spatial metadata support in your plugin, simply include this file.
*
* WP-GeoMeta-lib handles having multiple versions of itself installed corretly, always loading the latest version.
*
* It also handles setting up the spatial meta tables, so this file should be included directly, and not inside a hook or action.
*/
defined( 'ABSPATH' ) or die( 'No direct access' );
$wp_geometa_version = '0.4.0';
if ( ! class_exists( 'WP_GeoMeta_Installs' ) ) {
/**
* This class is deliberately simple, because if it ever changes
* the changes need to be backwards compatible.
*
* We're using a singleton instead of a global array to capture
* each WP-GeoMeta's version and location.
*/
class WP_GeoMeta_Installs {
/**
* List of installs
*
* @var $installs
*/
public static $installs = array();
/**
* List of versions
*
* @var $versions
*/
public static $versions = array();
/**
* Add an install listing
*
* @param string $file __FILE__ of wp-geometa.php.
* @param string $version the version of wp-geometa.php.
*/
public static function add( $file, $version ) {
WP_GeoMeta_Installs::$installs[ $file ] = $version;
WP_GeoMeta_Installs::$versions[ $version ] = $file;
}
/**
* Get the list of installs with versions.
*/
public static function get_list() {
return WP_GeoMeta_Installs::$installs;
}
/**
* A loader function for apl_autoload_register.
*
* This gets called by PHP if LeafletPHP is not a class.
*
* This is preferable to always loading the class, since
* this will avoid loading it if it's not needed.
*
* @param string $class_name The class name that PHP is looking for.
*/
public static function load( $class_name ) {
if ( in_array( $class_name, array( 'WP_GeoMeta', 'WP_GeoQuery', 'WP_GeoUtil' ), true ) ) {
WP_GeoMeta_Installs::load_now();
}
}
/**
* This method will go away eventually.
*/
public static function load_now() {
// Sort keys by version_compare.
uksort( WP_GeoMeta_Installs::$versions, 'version_compare' );
// Go to the end of the array and require the file.
// Then get the directory.
end( WP_GeoMeta_Installs::$versions );
$this_dir = dirname( current( WP_GeoMeta_Installs::$versions ) );
$wp_geometa_max_version = get_option( 'wp_geometa_version', '0.0.0' );
// Require the wp-geometa-lib file which will handle DB upgrades, initializing stuff and setting up needed hooks.
require_once( $this_dir . '/wp-geometa-lib.php' );
}
}
// Let PHP auto loading only include the file if needed.
spl_autoload_register( array( 'WP_GeoMeta_Installs', 'load' ) );
add_action( 'plugins_loaded', array( 'WP_GeoMeta_Installs', 'load_now' ) );
}
// Add ourself to the list of installs.
WP_GeoMeta_Installs::add( __FILE__, $wp_geometa_version );
/**
* Legacy handling
*
* If we detect an older version of WP_GeoMeta, do the old stuff to make sure we get loaded.
*/
$wp_geometa_max_version = get_option( 'wp_geometa_version', '0.0.0' );
/**
* -1 means that our version is lower.
* 0 means they are equal.
* 1 means our version is higher.
*/
if ( '0.0.0' !== $wp_geometa_max_version && 1 === version_compare( $wp_geometa_version, $wp_geometa_max_version ) ) {
require_once( dirname( __FILE__ ) . '/wp-geometa-lib.php' );
if ( ! function_exists( 'wp_geometa_load_older_version' ) ) {
/**
* Do nothing, just stop older versions from defining this function which would cause them to load.
*/
function wp_geometa_load_older_version() {
}
}
if ( ! function_exists( 'wpgeometa_setup_latlng_fields' ) ) {
/**
* Do nothing, just stop older versions from defining this function.
*/
function wpgeometa_setup_latlng_fields() {
}
}
}