PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.2.22
MxChat – AI Chatbot & Content Generation for WordPress v3.2.22
3.2.25 3.2.24 3.2.23 3.2.22 3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 All 156 releases
mxchat-basic / includes / class-mxchat-editor-assistant.php

class-mxchat-editor-assistant.php in MxChat – AI Chatbot & Content Generation for WordPress 3.2.22, at includes/class-mxchat-editor-assistant.php

140 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Editor Assistant loader (folded into core by plan-8cb0cb).
4 *
5 * Magic-wand-style AI actions inside the Gutenberg block editor — select a
6 * block, pick an action (rewrite / summarize / translate / continue / fix
7 * grammar), accept or discard. Reuses whichever chat provider the site has
8 * configured in mxchat-basic.
9 *
10 * FREE core feature, OFF by default. The whole surface (REST route, streaming
11 * AJAX action, and the block-editor sidebar assets) is gated on the standalone
12 * option `mxchat_editor_assistant_enabled` === 'on'. When off, NOTHING here is
13 * registered — zero editor footprint, no REST route, no AJAX action.
14 *
15 * Was the standalone plugin mxchat-editor-assistant (never released); folded in
16 * per Maxwell direction. The PRO license gate + update-checker + dependency
17 * notices from the standalone are intentionally dropped in the fold.
18 *
19 * @package MxChat
20 */
21
22 if (!defined('ABSPATH')) {
23 exit;
24 }
25
26 class MxChat_Editor_Assistant {
27
28 const OPTION = 'mxchat_editor_assistant_enabled';
29
30 /**
31 * True when the owner has turned the feature on. Default OFF — a fresh or
32 * upgraded install has the block-editor assistant disabled until enabled.
33 */
34 public static function is_enabled() {
35 return get_option(self::OPTION, 'off') === 'on';
36 }
37
38 /**
39 * Wire the feature — only when enabled. Called from mxchat_include_classes()
40 * during plugins_loaded, before rest_api_init / wp_ajax / enqueue fire.
41 */
42 public static function init() {
43 if (!self::is_enabled()) {
44 return;
45 }
46
47 require_once __DIR__ . '/class-mxchat-editor-assistant-rest.php';
48 require_once __DIR__ . '/class-mxchat-editor-assistant-stream.php';
49
50 MxChat_Editor_Assistant_REST::register();
51 MxChat_Editor_Assistant_Stream::register();
52
53 add_action('enqueue_block_editor_assets', array(__CLASS__, 'enqueue_sidebar'));
54 }
55
56 /**
57 * Enqueue the Gutenberg sidebar bundle inside the block editor. Only for
58 * users who can edit posts, and only in the block editor.
59 *
60 * The sidebar uses wp.element.createElement directly (no JSX, no build step).
61 * Assets ship from mxchat-basic/assets/editor-assistant/.
62 */
63 public static function enqueue_sidebar() {
64 if (!current_user_can('edit_posts')) {
65 return;
66 }
67
68 $main_file = dirname(__DIR__) . '/mxchat-basic.php';
69 $ver = defined('MXCHAT_VERSION') ? MXCHAT_VERSION : '1.0';
70
71 wp_enqueue_script(
72 'mxchat-editor-assistant-sidebar',
73 plugins_url('assets/editor-assistant/sidebar.js', $main_file),
74 array('wp-plugins', 'wp-edit-post', 'wp-element', 'wp-data', 'wp-components', 'wp-i18n', 'wp-api-fetch', 'wp-blocks'),
75 $ver,
76 true
77 );
78
79 wp_enqueue_style(
80 'mxchat-editor-assistant-sidebar',
81 plugins_url('assets/editor-assistant/sidebar.css', $main_file),
82 array('wp-edit-blocks'),
83 $ver
84 );
85
86 wp_localize_script(
87 'mxchat-editor-assistant-sidebar',
88 'MxChatEditorAssistant',
89 array(
90 'restUrl' => esc_url_raw(rest_url('mxchat-editor/v1/transform')),
91 'nonce' => wp_create_nonce('wp_rest'),
92 'ajaxUrl' => esc_url_raw(admin_url('admin-ajax.php')),
93 'streamAction' => MxChat_Editor_Assistant_Stream::AJAX_ACTION,
94 'streamNonce' => wp_create_nonce(MxChat_Editor_Assistant_Stream::NONCE),
95 // Free core feature — no license gate. Kept as a constant true so any
96 // older cached asset that still reads it stays functional.
97 'licenseActive' => true,
98 'actions' => MxChat_Editor_Assistant_REST::get_actions_for_client(),
99 'supportedBlocks' => array('core/paragraph', 'core/heading', 'core/list-item', 'core/quote'),
100 'locales' => array(
101 array('value' => 'en', 'label' => __('English', 'mxchat')),
102 array('value' => 'es', 'label' => __('Spanish', 'mxchat')),
103 array('value' => 'fr', 'label' => __('French', 'mxchat')),
104 array('value' => 'de', 'label' => __('German', 'mxchat')),
105 array('value' => 'ja', 'label' => __('Japanese', 'mxchat')),
106 array('value' => 'pt', 'label' => __('Portuguese', 'mxchat')),
107 ),
108 'i18n' => array(
109 'panelTitle' => __('MxChat Editor Assistant', 'mxchat'),
110 'sidebarHeading' => __('Block actions', 'mxchat'),
111 'selectBlockNotice' => __('Select a paragraph, heading, list item, or quote block to use the assistant.', 'mxchat'),
112 'unsupportedNotice' => __('This action works on paragraph, heading, list item, and quote blocks. Select one of those to continue.', 'mxchat'),
113 'workingLabel' => __('Working…', 'mxchat'),
114 'resultHeading' => __('Result', 'mxchat'),
115 'accept' => __('Accept', 'mxchat'),
116 'discard' => __('Discard', 'mxchat'),
117 'tryAgain' => __('Try again', 'mxchat'),
118 'translateTo' => __('Translate to', 'mxchat'),
119 'licenseRequired' => __('MxChat PRO license required. Actions are disabled.', 'mxchat'),
120 'errorPrefix' => __('Editor Assistant error:', 'mxchat'),
121 'emptyContent' => __('The selected block has no text content.', 'mxchat'),
122 'streamingLabel' => __('Streaming…', 'mxchat'),
123 'acceptAll' => __('Accept all', 'mxchat'),
124 'pending' => __('Waiting…', 'mxchat'),
125 'done' => __('Done', 'mxchat'),
126 'failed' => __('Failed', 'mxchat'),
127 'skipped' => __('Skipped — unsupported block', 'mxchat'),
128 /* translators: %1$d: applied count, %2$d: total selected */
129 'appliedSummary' => __('Applied to %1$d of %2$d selected blocks.', 'mxchat'),
130 /* translators: %d: number of blocks */
131 'blocksLabelSuffix' => __('(%d blocks)', 'mxchat'),
132 'blockLabel' => __('Block', 'mxchat'),
133 ),
134 )
135 );
136
137 wp_set_script_translations('mxchat-editor-assistant-sidebar', 'mxchat');
138 }
139 }
140