-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtm-deployment.php
220 lines (194 loc) · 6.39 KB
/
mtm-deployment.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/*
Plugin Name: MTM WordPress Deployment Updates
Description: Runs update routines allowing code based database updates.
Author: Metal Toad Media
Version: 1.02
Based on: http://andymantell.com/blog/2013/07/quick-and-dirty-wordpress-deployment-plugin
*/
add_action( 'admin_init', 'deployment_admin_init' );
/**
* Attached to init. Runs any necessary update routines
*/
function deployment_admin_init() {
// What is the current version of this plugin?
$deployment_version = 3;
// What is the current version in the db
$db_version = get_option( 'deployment_version', 0 );
// Is the db out of date?
if ( $db_version < $deployment_version ) {
// If so, loop over all subsequent version numbers and attempt to run corresponding deployment_update_N functions
for ( $version = $db_version + 1; $version <= $deployment_version; $version ++ ) {
if ( function_exists( 'deployment_update_' . $version ) ) {
$success = call_user_func( 'deployment_update_' . $version );
// If the function returns a boolean false, log an error and bail out. Subsequent updates may rely on this update
// so we shouldn't proceed any further.
if ( $success === FALSE ) {
// @TODO: log error here
break;
}
}
// If we've reached this far without error, update the db version
update_option( 'deployment_version', $version );
}
// @TODO: output update summary on success
}
}
/**
* Update functions.
*/
function deployment_update_1() {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
global $wpdb;
global $related_post_id;
//$wpdb->insert( $table, $data, $format );
$wpdb->insert(
'wp_posts',
array(
'ID' => $wpdb->insert_id,
'post_author' => 1,
'post_date' => '2015-11-02 12:08:30',
'post_date_gmt' => '2015-11-02 20:08:30',
'post_content' => '',
'post_title' => 'Account',
'post_excerpt' => '',
'post_status' => 'publish',
'comment_status' => 'open',
'ping_status' => 'open',
'post_password' => '',
'post_name' => 'my-account',
'to_ping' => '',
'pinged' => '',
'post_modified' => '2015-11-02 12:09:10',
'post_modified_gmt' => '2015-11-02 20:09:10',
'post_content_filtered' => '',
'post_parent' => 0,
'guid' => 'https://redacted.dev/logout',
'menu_order' => 5,
'post_type' => 'nav_menu_item',
'post_mime_type' => '',
'comment_count' => 0,
),
array(
'%d',
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%d',
'%s',
'%d',
'%s',
'%s',
'%d',
)
);
$related_post_id = $wpdb->insert_id;
$wpdb->query( "INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
VALUES
($related_post_id, '_menu_item_type', 'post_type'),
($related_post_id, '_menu_item_url', ''),
($related_post_id, '_menu_item_xfn', ''),
($related_post_id, '_menu_item_classes', 'a:1:{i:0;s:10:\"my-account\";}'),
($related_post_id, '_menu_item_object_id', ' 54'),
($related_post_id, '_menu_item_object', 'page'),
($related_post_id, '_menu_item_target', ''),
($related_post_id, '_menu_item_menu_item_parent', '0')" );
$wpdb->query( "INSERT INTO wp_term_relationships (object_id, term_taxonomy_id, term_order)
VALUES
($related_post_id, 43, 0)" );
}
// PS-11dep branched off the deploy branch of 2015-12. modify registration form.
function deployment_update_2() {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
// Magic Number: update page 55
$registration_page = array(
'ID' => 55,
'post_content' => '[theme-my-login register_template="theme-my-login/register-form.php"]',
);
wp_update_post( $registration_page );
// Magic Number: update the username specifications of page 55 to match what's seen on production
update_post_meta( 55, 'username_specifics', ' ' );
// Magic Number: update page 53
$login_page = array(
'ID' => 53,
'post_content' => '[theme-my-login login_template="theme-my-login/login-form.php"]',
);
wp_update_post( $login_page );
}
// PS-7 activates a new plugin for photo gallery lightbox
function deployment_update_3() {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
activate_plugins( WP_PLUGIN_DIR . '/lightbox-plus/lightboxplus.php' );
update_option( 'lightboxplus_options', array(
"lightboxplus_multi" => "0",
"use_inline" => "0",
"inline_num" => "5",
"lightboxplus_style" => "dark",
"use_custom_style" => "1",
"disable_css" => "0",
"hide_about" => "1",
"output_htmlv" => "0",
"data_name" => "lightboxplus",
"load_location" => "wp_footer",
"load_priority" => "10",
"use_perpage" => "1",
"use_forpage" => "0",
"use_forpost" => "1",
"transition" => "elastic",
"speed" => "300",
"width" => "false",
"height" => "false",
"inner_width" => "false",
"inner_height" => "false",
"initial_width" => "30%",
"initial_height" => "30%",
"max_width" => "90%",
"max_height" => "90%",
"resize" => "1",
"opacity" => "0.8",
"preloading" => "1",
"label_image" => "Image",
"label_of" => "of",
"previous" => "previous",
"next" => "next",
"close" => "close",
"overlay_close" => "1",
"slideshow" => "1",
"slideshow_auto" => "0",
"slideshow_speed" => "2500",
"slideshow_start" => "start",
"slideshow_stop" => "stop",
"use_caption_title" => "1",
"gallery_lightboxplus" => "0",
"multiple_galleries" => "0",
"use_class_method" => "0",
"class_name" => "lbp_primary",
"no_auto_lightbox" => "0",
"text_links" => "0",
"no_display_title" => "0",
"scrolling" => "1",
"photo" => "0",
"rel" => "0",
"loop" => "1",
"esc_key" => "1",
"arrow_key" => "1",
"top" => "false",
"bottom" => "false",
"left" => "false",
"right" => "false",
"fixed" => "0",
) );
}