-
Notifications
You must be signed in to change notification settings - Fork 19
/
BaseCommand.php
53 lines (39 loc) · 1.44 KB
/
BaseCommand.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
<?php
namespace Polylang_CLI\Commands;
use \Polylang_CLI\Api\Api;
use \Polylang_CLI\Api\Cli;
use \Polylang_CLI\Traits\Properties;
use \Polylang_CLI\Traits\Utils;
use \Polylang_CLI\Traits\SettingsErrors;
# make sure PLL_Admin_Model is available
if( ! defined( 'PLL_ADMIN' ) ) define( 'PLL_ADMIN', true );
if( ! defined( 'PLL_SETTINGS' ) ) define( 'PLL_SETTINGS', true );
if ( ! class_exists( 'Polylang_CLI\Commands\BaseCommand' ) ) {
/**
* Class BaseCommand
*
* @package Polylang_CLI
*/
class BaseCommand extends \WP_CLI_Command
{
use Properties, Utils, SettingsErrors;
public function __construct()
{
parent::__construct();
# invoke WP_CLI wrapper
$this->cli = new Cli();
# check if Polylang plugin is installed
if ( ! defined( 'POLYLANG_VERSION' ) ) {
return $this->cli->error( sprintf( 'This WP-CLI command requires the Polylang plugin: %s (%s)', 'wp plugin install polylang && wp plugin activate polylang', ABSPATH ) );
}
# check Polylang required version
if ( version_compare( POLYLANG_VERSION, '2.0.9', '<' ) ) {
return $this->cli->error( sprintf( 'This WP-CLI command requires Polylang version %s or higher: %s', '2.0.9', 'wp plugin update polylang' ) );
}
# get Polylang instance (global)
$this->pll = \PLL();
# make Polylang API functions available
$this->api = new Api( PLL_INC . '/api.php' );
}
}
}