PluginProbe
Social Media Auto Poster – Schedule & Publish to Buffer / 3.8.2
Social Media Auto Poster – Schedule & Publish to Buffer v3.8.2
6.2.3 6.2.2 6.2.1 6.2.0 6.1.2 6.1.1 6.1.0 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 All 124 releases
wp-to-buffer / vendor / includes / admin / install.php

install.php in Social Media Auto Poster – Schedule & Publish to Buffer 3.8.2, at vendor/includes/admin/install.php

238 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Runs any steps required on plugin activation and upgrade.
4 *
5 * @package WP_To_Social_Pro
6 * @author Tim Carr
7 * @version 3.2.5
8 */
9 class WP_To_Social_Pro_Install {
10
11 /**
12 * Holds the base class object.
13 *
14 * @since 3.2.5
15 *
16 * @var object
17 */
18 public $base;
19
20 /**
21 * Constructor
22 *
23 * @since 3.4.7
24 *
25 * @param object $base Base Plugin Class
26 */
27 public function __construct( $base ) {
28
29 // Store base class
30 $this->base = $base;
31
32 }
33
34 /**
35 * Runs installation routines for first time users
36 *
37 * @since 3.4.0
38 */
39 public function install() {
40
41 // Enable logging by default
42 $this->base->get_class( 'settings' )->update_option( 'log', array(
43 'enabled' => 1,
44 'display_on_posts' => 1,
45 'preserve_days' => 30,
46 'log_level' => array(
47 'success',
48 'test',
49 'pending',
50 'warning',
51 'error',
52 ),
53 ) );
54
55 // Create logging database table
56 $this->base->get_class( 'log' )->activate();
57
58 // Reschedule the cron events
59 $this->base->get_class( 'cron' )->schedule_log_cleanup_event();
60
61 // Bail if settings already exist
62 $settings = $this->base->get_class( 'settings' )->get_settings( 'post' );
63 if ( $settings != false ) {
64 return;
65 }
66
67 // Get default installation settings
68 $settings = $this->base->get_class( 'settings' )->default_installation_settings( 'post' );
69 $this->base->get_class( 'settings' )->update_settings( 'post', $settings );
70
71 }
72
73 /**
74 * Runs migrations for Pro to Pro version upgrades
75 *
76 * @since 3.2.5
77 */
78 public function upgrade() {
79
80 // Get current installed version number
81 $installed_version = get_option( $this->base->plugin->name . '-version' ); // false | 1.1.7
82
83 // If the version number matches the plugin version, bail
84 if ( $installed_version == $this->base->plugin->version ) {
85 return;
86 }
87
88 // Reschedule the cron events
89 $this->base->get_class( 'cron' )->reschedule_log_cleanup_event();
90
91 /**
92 * 3.6.2: Migrate Log Level Settings
93 */
94 if ( ! $installed_version || $installed_version < '3.6.2' ) {
95 // Get Log Settings
96 $log_settings = get_option( $this->base->plugin->settingsName . '-log' );
97
98 // If Log Level isn't an array, we need to update it
99 if ( is_array( $log_settings ) && ! is_array( $log_settings['log_level'] ) ) {
100 // Depending on the log level, define the values
101 switch ( $log_settings['log_level'] ) {
102 case 'test_warning_error':
103 $log_levels = array(
104 'test',
105 'warning',
106 'error',
107 );
108 break;
109
110 case 'warning_error':
111 $log_levels = array(
112 'warning',
113 'error',
114 );
115 break;
116
117 case 'error':
118 $log_levels = array(
119 'error',
120 );
121 break;
122
123 default:
124 // All
125 $log_levels = array(
126 'success',
127 'test',
128 'pending',
129 'warning',
130 'error',
131 );
132 break;
133 }
134
135 // Assign log levels to settings and save
136 $log_settings['log_level'] = $log_levels;
137 update_option( $this->base->plugin->settingsName . '-log', $log_settings );
138 }
139 }
140
141 /**
142 * 3.5.6: Migrate Log Settings
143 */
144 if ( ! $installed_version || $installed_version < '3.5.6' ) {
145 // Check if the log settings already migrated on Plugin activation
146 $log = get_option( $this->base->plugin->settingsName . '-log' );
147 if ( ! is_array( $log ) ) {
148 $this->base->get_class( 'settings' )->update_option( 'log', array(
149 'enabled' => 1,
150 'display_on_posts' => 1,
151 'preserve_days' => 30,
152 ) );
153 }
154
155 // Schedule the log cleanup event, now that the settings permit it
156 $this->base->get_class( 'cron' )->schedule_log_cleanup_event();
157 }
158
159 /**
160 * 3.5.5: Migrate Log to new DB Table
161 */
162 if ( ! $installed_version || $installed_version < '3.5.5' ) {
163 // Create logging database table
164 $this->base->get_class( 'log' )->activate();
165
166 // Define Post Meta Log Key
167 $meta_key = '_' . str_replace( '-', '_', $this->base->plugin->settingsName ) . '_log';
168
169 // Fetch all Posts that have a Log
170 $posts = new WP_Query( array(
171 'post_type' => 'any',
172 'post_status' => 'any',
173 'posts_per_page' => -1,
174
175 // Where the log meta value exists
176 'meta_key' => $meta_key,
177 'meta_compare' => 'EXISTS',
178
179 // Performance
180 'fields' => 'ids',
181 'update_post_meta_cache'=> false,
182 'update_post_term_cache'=> false,
183 ) );
184
185 if ( $posts->post_count > 0 ) {
186 foreach ( $posts->posts as $post_id ) {
187 // Fetch Log from Post Meta
188 $log = get_post_meta( $post_id, $meta_key, true );
189
190 // Iterate through log, adding to new database table
191 foreach ( $log as $log_entry ) {
192 // Determine result
193 if ( $log_entry['success'] && isset( $log_entry['status_created_at'] ) ) {
194 $result = 'success';
195 } elseif ( $log_entry['success'] ) {
196 $result = 'pending';
197 } else {
198 $result = 'error';
199 }
200
201 // Add to Log
202 $this->base->get_class( 'log' )->add( $post_id, array(
203 'action' => '', // not supplied from Post Meta logs
204 'request_sent' => date( 'Y-m-d H:i:s', $log_entry['date'] ),
205 'profile_id' => ( isset( $log_entry['profile'] ) ? $log_entry['profile'] : '' ),
206 'profile_name' => ( isset( $log_entry['profile_name'] ) ? $log_entry['profile_name'] : '' ),
207 'result' => $result, // success, pending, error
208 'result_message' => $log_entry['message'],
209 'status_text' => ( isset( $log_entry['status_text'] ) ? $log_entry['status_text'] : '' ),
210 'status_created_at' => ( isset( $log_entry['status_created_at'] ) && is_numeric( $log_entry['status_created_at'] ) ? date( 'Y-m-d H:i:s', $log_entry['status_created_at'] ) : '' ),
211 'status_due_at' => ( isset( $log_entry['status_due_at'] )&& is_numeric( $log_entry['status_due_at'] ) ? date( 'Y-m-d H:i:s', $log_entry['status_due_at'] ) : '' ),
212 ) );
213 }
214
215 // Delete Post Meta
216 delete_post_meta( $post_id, $meta_key );
217 }
218 }
219 }
220
221 // Update the version number
222 update_option( $this->base->plugin->name . '-version', $this->base->plugin->version );
223
224 }
225
226 /**
227 * Runs uninstallation routines
228 *
229 * @since 3.7.2
230 */
231 public function uninstall() {
232
233 // Unschedule any CRON events
234 $this->base->get_class( 'cron' )->unschedule_log_cleanup_event();
235
236 }
237
238 }