-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubstack-importer.php
More file actions
62 lines (48 loc) · 1.95 KB
/
substack-importer.php
File metadata and controls
62 lines (48 loc) · 1.95 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
<?php
/**
* Plugin Name: Substack Importer
* Plugin URI: https://github.com/wordpress/substack-importer
* Description: A plugin that lets you import content from Substack to your WordPress site
* Author: wordpressdotorg
* Text Domain: substack-importer
* Version: 1.1.2
* Requires PHP: 7.4
* Tested up to: 6.9
*
* @package SubstackImporter
*/
use SubstackImporter\Importer_Admin;
defined( 'ABSPATH' ) || exit;
/** Before the plugin is activated, check if the wxr-generator and wordpress-import plugins are loaded. */
register_activation_hook( __FILE__, 'child_plugin_activate' );
function child_plugin_activate() {
$error_msg = __( 'Sorry but this plugin requires the %s plugin to be installed and active.', 'substack-importer' );
$plugins_link = '<a href="' . admin_url( 'plugins.php' ) . '">' . __( '« Return to plugins', 'substack-importer' ) . '</a>';
if ( ! is_plugin_active( 'wordpress-importer/wordpress-importer.php' ) && current_user_can( 'activate_plugins' ) ) {
wp_die( sprintf( $error_msg, 'WordPress Importer' ) . '<br>' . $plugins_link );
}
}
function substack_importer_init() {
require __DIR__ . '/vendor/autoload.php';
load_plugin_textdomain( 'substack-importer' );
$importer = new Importer_Admin();
// Register the Ajax action that handles fetching additional post data through the Substack API
add_action( 'wp_ajax_substack_progress', array( $importer, 'progress' ) );
if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
return;
}
register_importer(
'substack',
'Substack',
__( 'Import content from a Substack newsletter', 'substack-importer' ),
array(
$importer,
'run',
)
);
if ( isset( $_GET['import'] ) && 'substack' === $_GET['import'] ) {
wp_enqueue_script( 'substack-index-js', plugins_url( '/js/index.js', __FILE__ ) );
wp_enqueue_style( 'substack-index-css', plugins_url( '/css/index.css', __FILE__ ) );
}
}
add_action( 'admin_init', 'substack_importer_init' );