forked from 19h47/weblex-importer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weblex-importer.php
136 lines (112 loc) · 3.86 KB
/
weblex-importer.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
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://github.com/19h47/weblex-importer/
* @since 0.0.0
* @package Weblex_Importer
*
* @wordpress-plugin
* Plugin Name: Weblex Importer
* Plugin URI: https://github.com/19h47/weblex-importer/
* Description: Import posts from an Weblex RSS feed.
* Version: 1.0.20
* Author: Jérémy Levron
* Author URI: https://19h47.fr/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: webleximporter
* Domain Path: /languages
* Tags: importer, rss
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'WEBLEX_IMPORTER_DIR_PATH', plugin_dir_path( __FILE__ ) );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-weblex-importer-activator.php
*/
function activate_weblex_importer() {
require_once WEBLEX_IMPORTER_DIR_PATH . 'includes/class-weblex-importer-activator.php';
Weblex_Importer_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-weblex-importer-deactivator.php
*/
function deactivate_weblex_importer() {
require_once WEBLEX_IMPORTER_DIR_PATH . 'includes/class-weblex-importer-deactivator.php';
Weblex_Importer_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_weblex_importer' );
register_deactivation_hook( __FILE__, 'deactivate_weblex_importer' );
add_action( 'upgrader_process_complete', 'update_weblex_importer', 10, 2 );
/**
* Update Weblex Importer
*
* @param WP_Upgrader $upgrader WP_Upgrader instance. In other contexts this might be a Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
* @param array $hook_extra Array of bulk item update data.
*
* @see https://developer.wordpress.org/reference/hooks/upgrader_process_complete/
*/
function update_weblex_importer( WP_Upgrader $upgrader, array $hook_extra ) {
$current_plugin_path_name = plugin_basename( __FILE__ );
if ( 'update' === $hook_extra['action'] && 'plugin' === $hook_extra['type'] ) {
foreach ( $hook_extra['plugins'] as $plugin ) {
if ( $plugin === $current_plugin_path_name ) {
flush_rewrite_rules();
}
}
}
}
/**
* Get post type
*
* @return string Default 'post'.
*/
function weblex_importer_get_post_type() : string {
$post_type = get_option( 'weblex_importer_options' );
if ( ! $post_type ) {
return 'weblex-importer-post';
}
if ( is_array( $post_type ) && ! array_key_exists( 'post', $post_type ) ) {
return 'weblex-importer-post';
}
if ( null === $post_type || '0' === $post_type ) {
return 'weblex-importer-post';
}
return 'post';
}
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require WEBLEX_IMPORTER_DIR_PATH . 'includes/class-weblex-importer.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.0.0
*/
function run_weblex_importer() {
require WEBLEX_IMPORTER_DIR_PATH . 'vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
$plugin = new Weblex_Importer();
$plugin->run();
$update_checker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/19h47/weblex-importer/',
__FILE__,
'weblex-importer'
);
$update_checker->setBranch( 'wordpress-plugin' );
}
run_weblex_importer();