-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwp-content-pilot.php
More file actions
378 lines (340 loc) · 10.5 KB
/
Copy pathwp-content-pilot.php
File metadata and controls
378 lines (340 loc) · 10.5 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<?php
/**
* Plugin Name: Content Pilot
* Plugin URI: https://wpcontentpilot.com
* Description: Content Pilot automatically posts contents from various sources based on the predefined keywords.
* Version: 2.2.3
* Requires at least: 5.2
* Requires PHP: 8.0
* Author: PluginEver
* Author URI: https://pluginever.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-content-pilot
* Domain Path: /i18n/languages
* Tested up to: 7.0
*
* @package WPContentPilot
*
* Copyright (c) 2026 PluginEver (email : support@pluginever.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) || exit(); // Exit if accessed directly.
/**
* Main ContentPilot Class.
*
* @since 1.0.0
* @class ContentPilot
*/
final class ContentPilot {
/**
* ContentPilot_Pro version.
*
* @var string
*
* @since 1.0.0
*/
protected $version = '2.2.3';
/**
* The single instance of the class.
*
* @var ContentPilot
*
* @since 1.0.0
*/
protected static $instance = null;
/**
* Main ContentPilot Instance.
*
* Ensures only one instance of ContentPilot is loaded or can be loaded.
*
* @static
* @since 1.0.0
* @return ContentPilot - Main instance.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cloning is forbidden.', 'wp-content-pilot' ), '1.0.0' );
}
/**
* Universalizing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Universalizing instances of this class is forbidden.', 'wp-content-pilot' ), '1.0.0' );
}
/**
* ContentPilot constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->define_constants();
$this->define_tables();
$this->includes();
$this->init_hooks();
}
/**
* Define ContentPilot Constants.
*
* @since 1.0.0
* @return void
*/
private function define_constants() {
define( 'WPCP_VERSION', $this->version );
define( 'WPCP_FILE', __FILE__ );
define( 'WPCP_PATH', dirname( WPCP_FILE ) );
define( 'WPCP_INCLUDES', WPCP_PATH . '/includes' );
define( 'WPCP_MODULES', WPCP_PATH . '/modules' );
define( 'WPCP_LIBRARY', WPCP_INCLUDES . '/library' );
define( 'WPCP_URL', plugins_url( '', WPCP_FILE ) );
define( 'WPCP_VIEWS', WPCP_PATH . '/views' );
define( 'WPCP_ASSETS_URL', WPCP_URL . '/assets' );
define( 'WPCP_TEMPLATES_DIR', WPCP_PATH . '/templates' );
}
/**
* Register custom tables within $wpdb object.
*
* @since 1.0.0
*/
private function define_tables() {
global $wpdb;
$tables = array(
'wpcp_links',
'wpcp_logs',
'wpcp_items',
);
foreach ( $tables as $table ) {
$wpdb->$table = $wpdb->prefix . $table;
$wpdb->tables[] = $table;
}
}
/**
* Include all required files
*
* @since 1.0.0
* @return void
*/
public function includes() {
// Required classes.
require_once WPCP_INCLUDES . '/class-wpcp-install.php';
require_once WPCP_PATH . '/vendor/autoload.php';
// Required functions.
require_once WPCP_INCLUDES . '/core-functions.php';
require_once WPCP_INCLUDES . '/action-functions.php';
require_once WPCP_INCLUDES . '/formatting-functions.php';
require_once WPCP_INCLUDES . '/post-types.php';
require_once WPCP_INCLUDES . '/script-functions.php';
require_once WPCP_INCLUDES . '/class-wpcp-html.php';
// Required core files.
// phpcs:disable
// require_once( WPCP_LIBRARY . '/readability/Readability_OLD.php' );
// phpcs:enable
require_once WPCP_LIBRARY . '/readability/Readability.php';
require_once WPCP_INCLUDES . '/class-wpcp-readability.php';
require_once WPCP_INCLUDES . '/class-wpcp-logger.php';
require_once WPCP_INCLUDES . '/class-wpcp-dom.php';
require_once WPCP_INCLUDES . '/class-wpcp-modules.php';
require_once WPCP_INCLUDES . '/class-wpcp-module.php';
require_once WPCP_INCLUDES . '/class-wpcp-notices.php';
// Required modules.
require_once WPCP_INCLUDES . '/modules/class-wpcp-article.php';
require_once WPCP_INCLUDES . '/modules/class-wpcp-feed.php';
require_once WPCP_INCLUDES . '/modules/class-wpcp-youtube.php';
require_once WPCP_INCLUDES . '/modules/class-wpcp-envato.php';
require_once WPCP_INCLUDES . '/modules/class-wpcp-flickr.php';
if ( is_admin() ) {
require_once WPCP_INCLUDES . '/admin/class-wpcp-admin.php';
}
// Update helper for pro version. This will be removed in the future.
if ( defined( 'WPCP_PRO_VERSION' ) ) {
add_filter( 'http_request_args', array( $this, 'pro_updater' ), 10, 2 );
}
}
/**
* Pro Updater.
*
* This is a temporary solution to update the pro version.
* This will be removed in the future.
*
* @param array $args HTTP request arguments.
* @param string $url Request URL.
*
* @since 2.0.7
* @return array $args HTTP request arguments.
*/
public function pro_updater( $args, $url ) {
if ( str_contains( $url, 'pluginever.com' ) && empty( $args['body']['item_id'] ) && 'wp-content-pilot-pro' === $args['body']['slug'] ) {
$args['body']['item_id'] = absint( '59161' );
}
return $args;
}
/**
* Hook into actions and filters.
*
* @since 1.0.0
*/
private function init_hooks() {
register_activation_hook( __FILE__, array( 'WPCP_Install', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'WPCP_Install', 'deactivate' ) );
register_activation_hook( __FILE__, array( $this, 'activate_cron' ) );
register_shutdown_function( array( $this, 'log_errors' ) );
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), - 1 );
add_action( 'init', array( $this, 'localization_setup' ) );
add_filter( 'cron_schedules', array( $this, 'custom_cron_schedules' ), 20 ); // phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
}
/**
* When WP has loaded all plugins, trigger the `content__pilot__loaded` hook.
*
* This ensures `content__pilot__loaded` is called only after all other plugins
* are loaded, to avoid issues caused by plugin directory naming changing
*
* @since 1.2.5
*/
public function on_plugins_loaded() {
do_action( 'content__pilot__loaded' );
}
/**
* Initialize plugin for localization
*
* @since 1.0.0
* @return void
*/
public function localization_setup() {
load_plugin_textdomain( 'wp-content-pilot', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages/' );
}
/**
* Create cron job
*
* since 1.0.7
*
* @return void
*/
public function activate_cron() {
wp_schedule_event( time(), 'once_a_minute', 'wpcp_per_minute_scheduled_events' );
wp_schedule_event( time(), 'daily', 'wpcp_daily_scheduled_events' );
}
/**
* Plugin action links.
*
* @param array $links Links.
*
* @since 1.0.0
* @return array
*/
public function plugin_action_links( $links ) {
$action_links = array(
'settings' => '<a href="' . admin_url( 'edit.php?post_type=wp_content_pilot&page=wpcp-settings' ) . '">' . __( 'Settings', 'wp-content-pilot' ) . '</a>',
);
$links = array_merge( $action_links, $links );
if ( ! defined( 'WPCP_PRO_VERSION' ) ) {
$upgrade_link = 'https://wpcontentpilot.com/?utm_source=plugin_action_link&utm_medium=link&utm_campaign=wp-content-pilot-pro&utm_content=Upgrade%20to%20Pro';
$upgrade_links = array(
'upgrade' => '<a href="' . esc_url( $upgrade_link ) . '" style="color: red;font-weight: bold;" target="_blank">' . __( 'Go Pro', 'wp-content-pilot' ) . '</a>',
);
$links = array_merge( $links, $upgrade_links );
}
return $links;
}
/**
* Add plugin docs links in plugin row links
*
* @param mixed $links Links.
* @param mixed $file File.
*
* @since 1.2.8
* @return array
*/
public function plugin_row_meta( $links, $file ) {
if ( plugin_basename( __FILE__ ) === $file ) {
$row_meta = array(
'docs' => '<a href="' . esc_url( apply_filters( 'wpcp_docs_url', 'https://wpcontentpilot.com/docs/' ) ) . '" aria-label="' . esc_attr__( 'View documentation', 'wp-content-pilot' ) . '">' . esc_html__( 'Docs', 'wp-content-pilot' ) . '</a>',
);
return array_merge( $links, $row_meta );
}
return $links;
}
/**
* Add custom cron schedule
*
* @param array $schedules Array of Existing schedules.
*
* @since 1.0.7
* @return mixed
*/
public function custom_cron_schedules( $schedules ) {
$schedules ['once_a_minute'] = array(
'interval' => 60,
'display' => __( 'Once a Minute', 'wp-content-pilot' ),
);
return $schedules;
}
/**
* Log fatal error
*
* @since 1.2.4
*/
public function log_errors() {
$error = error_get_last();
if ( $error && in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
wpcp_logger()->error( sprintf( /* translators: 1. message, 2. File, 3. Line number */ __( '%1$s in %2$s on line %3$s', 'wp-content-pilot' ), $error['message'], $error['file'], $error['line'] ) . PHP_EOL );
do_action( 'wpcp_shutdown_error', $error );
}
}
/**
* Get version
*
* @since 1.2.3
* @return string Version.
*/
public function get_version() {
return $this->version;
}
/**
* Module class
*
* @since 1.2.0
* @return WPCP_Modules Module instance
*/
public function modules() {
return WPCP_Modules::instance();
}
}
/**
* Returns the main instance of ContentPilot to prevent the need to use globals.
*
* @return ContentPilot The main instance.
*
* @since 1.0.0
*/
function content_pilot() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
return ContentPilot::instance();
}
// Fire off the plugin.
content_pilot();