PluginProbe
Social Media Auto Poster – Schedule & Publish to Buffer / 6.2.0
Social Media Auto Poster – Schedule & Publish to Buffer v6.2.0
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 / includes / class-wp-to-buffer.php

class-wp-to-buffer.php in Social Media Auto Poster – Schedule & Publish to Buffer 6.2.0, at includes/class-wp-to-buffer.php

363 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP to Buffer class.
4 *
5 * @package WP_To_Buffer
6 * @author WP Zinc
7 */
8
9 /**
10 * Main WP to Buffer class, used to load the Plugin.
11 *
12 * @package WP_To_Buffer
13 * @author WP Zinc
14 * @version 1.0.0
15 */
16 class WP_To_Buffer {
17
18 /**
19 * Holds the class object.
20 *
21 * @since 3.1.4
22 *
23 * @var object
24 */
25 public static $instance;
26
27 /**
28 * Plugin
29 *
30 * @since 3.0.0
31 *
32 * @var object
33 */
34 public $plugin = '';
35
36 /**
37 * Dashboard
38 *
39 * @since 3.1.4
40 *
41 * @var object
42 */
43 public $dashboard = '';
44
45 /**
46 * Classes
47 *
48 * @since 3.4.9
49 *
50 * @var array
51 */
52 public $classes = '';
53
54 /**
55 * Constructor. Acts as a bootstrap to load the rest of the plugin
56 *
57 * @since 1.0.0
58 */
59 public function __construct() {
60
61 // Plugin Details.
62 $this->plugin = new stdClass();
63 $this->plugin->name = 'wp-to-buffer';
64 $this->plugin->filter_name = 'wp_to_buffer';
65 $this->plugin->displayName = 'WP to Buffer';
66
67 $this->plugin->settingsName = 'wp-to-buffer-pro'; // Settings key - used in both Free + Pro, and for oAuth.
68 $this->plugin->account = 'Buffer';
69 $this->plugin->version = WP_TO_BUFFER_PLUGIN_VERSION;
70 $this->plugin->buildDate = WP_TO_BUFFER_PLUGIN_BUILD_DATE;
71 $this->plugin->folder = WP_TO_BUFFER_PLUGIN_PATH;
72 $this->plugin->url = WP_TO_BUFFER_PLUGIN_URL;
73 $this->plugin->documentation_url = 'https://www.wpzinc.com/documentation/wordpress-buffer-pro';
74 $this->plugin->support_url = 'https://www.wpzinc.com/support';
75 $this->plugin->upgrade_url = 'https://www.wpzinc.com/plugins/wordpress-to-buffer-pro';
76
77 // Logo.
78 $this->plugin->logo = WP_TO_BUFFER_PLUGIN_URL . 'lib/social/assets/images/icons/buffer-dark.svg';
79 $this->plugin->header_background_color = '#ffffff';
80 $this->plugin->header_primary_text_color = '#3d3d3d';
81 $this->plugin->header_secondary_text_color = '#6e6e6e';
82
83 // Review.
84 $this->plugin->review_name = 'wp-to-buffer';
85 $this->plugin->review_notice = sprintf(
86 'Thanks for using %s to schedule your social media statuses on %s!',
87 $this->plugin->displayName,
88 $this->plugin->account
89 );
90
91 // ConvertKit Form UID.
92 $this->plugin->convertkit_form_uid = '71346c6086';
93
94 // Default Settings.
95 $this->plugin->default_schedule = 'immediate';
96
97 // Defer loading of Plugin Classes.
98 add_action( 'init', array( $this, 'initialize' ), 1 );
99 add_action( 'init', array( $this, 'upgrade' ), 2 );
100
101 // Admin Menus.
102 add_action( $this->plugin->filter_name . '_admin_admin_menu', array( $this, 'admin_menus' ) );
103
104 // Add queue_end Schedule Option.
105 add_filter( $this->plugin->filter_name . '_get_schedule_options', array( $this, 'get_schedule_options' ) );
106
107 }
108
109 /**
110 * Defines the schedule options available for statuses in WP to Buffer (Free).
111 *
112 * @since 6.2.0
113 *
114 * @param array $schedule Schedule Options.
115 * @return array Schedule Options
116 */
117 public function get_schedule_options( $schedule ) {
118
119 // Buffer supports a queue, in addition to the always-available immediate option.
120 $schedule['queue_end'] = __( 'Add to End of Queue', 'wp-to-buffer' );
121
122 return $schedule;
123
124 }
125
126 /**
127 * Register menus and submenus.
128 *
129 * @since 3.9.7
130 *
131 * @param string $minimum_capability Minimum required capability.
132 */
133 public function admin_menus( $minimum_capability ) {
134
135 // Menus.
136 add_menu_page( $this->plugin->displayName, $this->plugin->displayName, $minimum_capability, $this->plugin->name . '-settings', array( $this->get_class( 'admin' ), 'settings_screen' ), $this->plugin->url . 'lib/social/assets/images/icons/' . strtolower( $this->plugin->account ) . '-light.svg' );
137
138 // Register Submenu Pages.
139 $settings_page = add_submenu_page( $this->plugin->name . '-settings', __( 'Settings', 'wp-to-buffer' ), __( 'Settings', 'wp-to-buffer' ), $minimum_capability, $this->plugin->name . '-settings', array( $this->get_class( 'admin' ), 'settings_screen' ) );
140
141 // Logs.
142 if ( $this->get_class( 'log' )->is_enabled() ) {
143 $log_page = add_submenu_page( $this->plugin->name . '-settings', __( 'Logs', 'wp-to-buffer' ), __( 'Logs', 'wp-to-buffer' ), $minimum_capability, $this->plugin->name . '-log', array( $this->get_class( 'admin' ), 'log_screen' ) );
144 add_action( "load-$log_page", array( $this->get_class( 'log' ), 'add_screen_options' ) );
145 }
146
147 $upgrade_page = add_submenu_page( $this->plugin->name . '-settings', __( 'Upgrade', 'wp-to-buffer' ), __( 'Upgrade', 'wp-to-buffer' ), $minimum_capability, $this->plugin->name . '-upgrade', array( $this->get_class( 'admin' ), 'upgrade_screen' ) );
148
149 }
150
151 /**
152 * Initializes required classes
153 *
154 * @since 3.4.9
155 */
156 public function initialize() {
157
158 // Define translation strings.
159 $this->plugin->review_notice = sprintf(
160 /* translators: 1: Plugin Name, 2: Social Network */
161 __( 'Thanks for using %1$s to schedule your social media statuses on %2$s!', 'wp-to-buffer' ),
162 $this->plugin->displayName,
163 $this->plugin->account
164 );
165
166 // Upgrade Reasons.
167 $this->plugin->upgrade_reasons = array(
168 array(
169 __( 'Post to Instagram and Pinterest', 'wp-to-buffer' ),
170 __( 'Pro supports Direct Posting to Instagram Business Profiles and Pinterest Boards', 'wp-to-buffer' ),
171 ),
172 array(
173 __( 'Multiple Buffer Account Support', 'wp-to-buffer' ),
174 __( 'Pro supports connecting multiple Buffer accounts to a single WordPress site', 'wp-to-buffer' ),
175 ),
176 array(
177 __( 'Multiple, Customisable Status Messages', 'wp-to-buffer' ),
178 __( 'Each Post Type and Social Network can have multiple, unique status message and settings', 'wp-to-buffer' ),
179 ),
180 array(
181 __( 'Conditionally send Status Messages', 'wp-to-buffer' ),
182 __( 'Only send status(es) to Buffer based on Post Author(s), Taxonomy Term(s) and/or Custom Field Values', 'wp-to-buffer' ),
183 ),
184 array(
185 __( 'More Scheduling Options', 'wp-to-buffer' ),
186 __( 'Each status update can be added to the start/end of your Buffer queue, posted immediately or scheduled at a specific time', 'wp-to-buffer' ),
187 ),
188 array(
189 __( 'Dynamic Status Tags', 'wp-to-buffer' ),
190 __( 'Dynamically build status updates with data from the Post Author and Custom Fields', 'wp-to-buffer' ),
191 ),
192 array(
193 __( 'Separate Statuses per Social Network', 'wp-to-buffer' ),
194 __( 'Define different statuses for each Post Type and Social Network', 'wp-to-buffer' ),
195 ),
196 array(
197 __( 'Per-Post Settings', 'wp-to-buffer' ),
198 __( 'Override Settings on Individual Posts: Each Post can have its own Buffer settings', 'wp-to-buffer' ),
199 ),
200 array(
201 __( 'Repost Old Posts', 'wp-to-buffer' ),
202 __( 'Automatically Revive Old Posts that haven\'t been updated in a while, choosing the number of days, weeks or years to re-share content on social media.', 'wp-to-buffer' ),
203 ),
204 array(
205 __( 'Bulk Publish Old Posts', 'wp-to-buffer' ),
206 __( 'Manually re-share evergreen WordPress content and revive old posts with the Bulk Publish option', 'wp-to-buffer' ),
207 ),
208 array(
209 __( 'The Events Calendar, Event Manager and Modern Events Calendar Integration', 'wp-to-buffer' ),
210 __( 'Schedule Posts to Buffer based on your Event\'s Start or End date, and display Event-specific details in your status updates', 'wp-to-buffer' ),
211 ),
212 array(
213 __( 'SEO Integration', 'wp-to-buffer' ),
214 __( 'Display SEO-specific information in your status updates from All-In-One SEO Pack, Rank Math, SEOPress and Yoast SEO', 'wp-to-buffer' ),
215 ),
216 array(
217 __( 'WooCommerce Integration', 'wp-to-buffer' ),
218 __( 'Display Product-specific information in your status updates', 'wp-to-buffer' ),
219 ),
220 array(
221 __( 'Autoblogging and Frontend Post Submission Integration', 'wp-to-buffer' ),
222 __( 'Pro supports autoblogging and frontend post submission Plugins, including User Submitted Posts, WP Property Feed, WPeMatico and WP Job Manager', 'wp-to-buffer' ),
223 ),
224 array(
225 __( 'Shortcode Support', 'wp-to-buffer' ),
226 __( 'Use shortcodes in status updates', 'wp-to-buffer' ),
227 ),
228 array(
229 __( 'Full Image Control', 'wp-to-buffer' ),
230 __( 'Choose to display one or more images in your status updates, from the Post\'s Featured Image, the Media Gallery, the Post Content or an Advanced Custom Fields Image or Gallery.', 'wp-to-buffer' ),
231 ),
232 array(
233 __( 'WP-Cron and WP-CLI Compatible', 'wp-to-buffer' ),
234 __( 'Optionally enable WP-Cron to send status updates via Cron, speeding up UI performance and/or choose to use WP-CLI for reposting old posts', 'wp-to-buffer' ),
235 ),
236 );
237
238 // Shared admin module (autoloaded from lib/shared).
239 $this->dashboard = new \WPZinc\Shared\Admin_UI( $this->plugin );
240
241 // Initialize Plugin classes.
242 $this->classes = new stdClass();
243
244 // Initialize required classes.
245 $this->classes->admin = new \WPZinc\Social\Admin( self::$instance );
246 $this->classes->ajax = new \WPZinc\Social\AJAX( self::$instance );
247 $this->classes->api = new \WPZinc\Social\Buffer_API( self::$instance );
248 $this->classes->common = new \WPZinc\Social\Common( self::$instance );
249 $this->classes->cron = new \WPZinc\Social\Cron( self::$instance );
250 $this->classes->date = new \WPZinc\Social\Date( self::$instance );
251 $this->classes->image = new \WPZinc\Social\Image( self::$instance );
252 $this->classes->install = new \WPZinc\Social\Install( self::$instance );
253 $this->classes->log = new \WPZinc\Social\Log( self::$instance );
254 $this->classes->media_library = new \WPZinc\Social\Media_Library( self::$instance );
255 $this->classes->notices = new \WPZinc\Social\Notices( self::$instance );
256 $this->classes->post = new \WPZinc\Social\Post( self::$instance );
257 $this->classes->publish = new \WPZinc\Social\Publish( self::$instance );
258 $this->classes->screen = new \WPZinc\Social\Screen( self::$instance );
259 $this->classes->settings = new \WPZinc\Social\Settings( self::$instance );
260 $this->classes->validation = new \WPZinc\Social\Validation( self::$instance );
261
262 }
263
264 /**
265 * Runs the upgrade routine once the plugin has loaded
266 *
267 * @since 3.2.5
268 */
269 public function upgrade() {
270
271 // Run upgrade routine.
272 $this->get_class( 'install' )->upgrade();
273
274 }
275
276 /**
277 * Returns the given class
278 *
279 * @since 3.4.9
280 *
281 * @param string $name Class Name.
282 */
283 public function get_class( $name ) {
284
285 // If the class hasn't been loaded, throw a WordPress die screen
286 // to avoid a PHP fatal error.
287 if ( ! isset( $this->classes->{ $name } ) ) {
288 // Define the error.
289 $error = new WP_Error(
290 'wp_to_buffer_get_class',
291 sprintf(
292 /* translators: %1$s: Plugin Name, %2$s: PHP class name */
293 __( '%1$s: Error: Could not load Plugin class %2$s', 'wp-to-buffer' ),
294 $this->plugin->displayName,
295 $name
296 )
297 );
298
299 // Depending on the request, return or display an error.
300 // Admin UI.
301 if ( is_admin() ) {
302 wp_die(
303 esc_html( $error->get_error_message() ),
304 sprintf(
305 /* translators: Plugin Name */
306 esc_html__( '%s: Error', 'wp-to-buffer' ),
307 esc_html( $this->plugin->displayName )
308 ),
309 array(
310 'back_link' => true,
311 )
312 );
313 }
314
315 // Cron / CLI.
316 return $error;
317 }
318
319 // Return the class object.
320 return $this->classes->{ $name };
321
322 }
323
324 /**
325 * Helper method to determine whether this Plugin supports a specific feature.
326 *
327 * Typically used by the lib/ classes.
328 *
329 * @since 3.5.5
330 *
331 * @param string $feature Feature.
332 * @return bool Feature Supported
333 */
334 public function supports( $feature ) {
335
336 // Define supported featured.
337 $supported_features = array(
338 'webp',
339 );
340
341 return in_array( $feature, $supported_features, true );
342
343 }
344
345 /**
346 * Returns the singleton instance of the class.
347 *
348 * @since 3.1.4
349 *
350 * @return object Class.
351 */
352 public static function get_instance() {
353
354 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
355 self::$instance = new self();
356 }
357
358 return self::$instance;
359
360 }
361
362 }
363