Skip to content

Commit 147701c

Browse files
author
Felix Arntz
committed
Load correct autoloader depending on PHP version and centralize file loading logic.
1 parent 466ca46 commit 147701c

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

load-files.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
// Exit if this file is directly accessed
3+
if ( ! defined( 'ABSPATH' ) ) { exit; }
4+
5+
/**
6+
* Loads the plugin files.
7+
*/
8+
function wpephpcompat_load_files() {
9+
require_once dirname( __FILE__ ) . '/src/wpephpcompat.php';
10+
11+
if ( version_compare( phpversion(), '5.3', '<' ) ) {
12+
$autoload_file = dirname( __FILE__ ) . '/php52/vendor/autoload.php';
13+
} else {
14+
$autoload_file = dirname( __FILE__ ) . '/vendor/autoload.php';
15+
}
16+
17+
require_once $autoload_file;
18+
19+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
20+
require_once dirname( __FILE__ ) . '/src/wpcli.php';
21+
}
22+
}
23+
24+
wpephpcompat_load_files();

src/wpcli.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
2-
require_once dirname( dirname( __FILE__ ) ) . '/src/wpephpcompat.php';
3-
require_once dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php';
2+
require_once dirname( dirname( __FILE__ ) ) . '/load-files.php';
43

54
/**
65
* PHPCompat WP-CLI command.

src/wpephpcompat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Exit if this file is directly accessed
33
if ( ! defined( 'ABSPATH' ) ) { exit; }
44

5-
require_once dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php';
5+
require_once dirname( dirname( __FILE__ ) ) . '/load-files.php';
66

77
/**
88
* Summary.

uninstall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
die;
66
}
77

8-
require_once dirname( __FILE__ ) . '/src/wpephpcompat.php';
8+
require_once dirname( __FILE__ ) . '/load-files.php';
99

1010
$wpephpc = new WPEPHPCompat( dirname( __FILE__ ) );
1111
$wpephpc->clean_after_scan();

wpengine-phpcompat.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
// Exit if this file is directly accessed
1313
if ( ! defined( 'ABSPATH' ) ) { exit; }
1414

15-
require_once dirname( __FILE__ ) . '/src/wpephpcompat.php';
16-
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
17-
18-
// Add the phpcompat WP-CLI command.
19-
if ( defined( 'WP_CLI' ) && WP_CLI ) {
20-
require_once dirname( __FILE__ ) . '/src/wpcli.php';
21-
}
15+
require_once dirname( __FILE__ ) . '/load-files.php';
2216

2317
/**
2418
* This handles hooking into WordPress.

0 commit comments

Comments
 (0)