-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoauthor.php
70 lines (62 loc) · 2.28 KB
/
coauthor.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
<?php
/**
* Plugin Name: Coauthor - AI Writing Assistant
* Description: Coauthor is here to help so you can focus on making your posts shine. You can automatically generate new paragraphs and Images using OpenAI.
* Version: 0.3.5
* Author: Artur Piszek (artpi)
* Author URI: https://piszek.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: coauthor
*
* @package coauthor
*/
function create_block_coauthor_init() {
$dir = __DIR__;
// If this executes in WordPress.com context, we don't need those.
// We don't even sync the settings file.
if ( ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) && file_exists( __DIR__ . '/class.settings.php' ) ) {
require_once __DIR__ . '/class.openai-rest-controller.php';
new OpenAI_REST_Controller();
require_once __DIR__ . '/class.settings.php';
new \Coauthor\Settings();
}
$script_asset_path = "$dir/build/index.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
throw new Error(
'You need to run `npm start` or `npm run build` for the "create-block/coauthor" block first.'
);
}
$index_js = 'build/index.js';
$script_asset = require $script_asset_path;
wp_register_script(
'create-block-coauthor-block-editor',
plugins_url( $index_js, __FILE__ ),
array_merge( $script_asset['dependencies'], array( 'wp-data', 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-block-editor' ) ), // This is hardcoded here because Jetpack does not play nice with ES6 dependencies for these.
$script_asset['version']
);
wp_set_script_translations( 'create-block-coauthor-block-editor', 'coauthor' );
$editor_css = 'build/index.css';
wp_register_style(
'create-block-coauthor-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(),
filemtime( "$dir/$editor_css" )
);
$style_css = 'build/style-index.css';
wp_register_style(
'create-block-coauthor-block',
plugins_url( $style_css, __FILE__ ),
array(),
filemtime( "$dir/$style_css" )
);
register_block_type(
'create-block/coauthor',
array(
'editor_script' => 'create-block-coauthor-block-editor',
'editor_style' => 'create-block-coauthor-block-editor',
'style' => 'create-block-coauthor-block',
)
);
}
add_action( 'init', 'create_block_coauthor_init' );