-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaging2live.php
More file actions
111 lines (86 loc) · 2.45 KB
/
staging2live.php
File metadata and controls
111 lines (86 loc) · 2.45 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
<?php
/**
* Plugin Name: Staging2Live
* Description: Seamlessly migrate your changes between environments
* Author: Staging2Live Team
* Author URI: https://github.com/omnisend/staging2live
* Version: 0.0.1
* Text Domain: staging2live
* Domain Path: /languages/
* License: GPLv2 or later (license.txt)
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( !defined('STL_CORE_PLUGIN_URL' ) )
define( 'STL_CORE_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
if ( !defined('STL_PLUGIN_URL' ) )
define( 'STL_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
if ( !defined('STL_PLUGIN_PATH' ) )
define( 'STL_PLUGIN_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
if ( !defined('STL_STAGING_NAME_DEFAULT' ) )
define( 'STL_STAGING_NAME_DEFAULT', 'staging' );
/**
* Helper functions
*/
/**
* Returns plugin version or timestamp, depending on environment type
*
* @return int|string
*
* @since 0.0.1
*/
function stl_get_plugin_version() {
switch ( wp_get_environment_type() ) {
case 'development':
case 'staging':
case 'local':
$version = time();
break;
default:
$plugin_data = get_file_data(__FILE__, [
'Version' => 'Version'
], 'plugin');
$version = $plugin_data[ 'Version' ];
break;
}
return $version;
}
function stl_init(): void {
// load textdomain
load_plugin_textdomain( 'staging2live', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action ( 'plugins_loaded', 'stl_init' );
/**
* Returns an array with variable regarding the staging site
*
* @return array
*/
function stl_get_staging_values(): array {
global $wpdb;
$options = get_option( 'staging2live_settings' );
$name = empty( $options[ 'staging_name' ] ) ? STL_STAGING_NAME_DEFAULT : $options[ 'staging_name' ];;
return array(
'name' => $name,
'table_prefix' => $wpdb->prefix . $name,
'domain' => site_url() . '/' . $name
);
}
/**
* Returns tur if a staging site exists
*
* @return bool
*/
function stl_staging_exists(): bool {
global $wpdb;
$staging = stl_get_staging_values();
return $wpdb->get_var("SHOW TABLES LIKE '{$staging[ 'table_prefix' ]}_options'") == $staging[ 'table_prefix' ] . '_options';
}
// Autoload all PHP files in the includes/ folder.
foreach ( glob( STL_PLUGIN_PATH . 'includes/class-*.php' ) as $filename ) {
include_once $filename;
}
if( class_exists( 'STL_General' ) && is_admin() ) {
new STL_General();
}