|
14 | 14 | use WP_Error;
|
15 | 15 |
|
16 | 16 | use function Classifai\get_asset_info;
|
| 17 | +use function Classifai\Providers\Watson\get_supported_post_statuses; |
| 18 | +use function Classifai\Providers\Watson\get_supported_post_types; |
17 | 19 |
|
18 | 20 | class Embeddings extends Provider {
|
19 | 21 |
|
@@ -127,6 +129,58 @@ public function render_provider_fields() {
|
127 | 129 | );
|
128 | 130 |
|
129 | 131 | do_action( 'classifai_' . static::ID . '_render_provider_fields', $this );
|
| 132 | + add_action( 'classifai_after_feature_settings_form', [ $this, 'render_previewer' ] ); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Renders the previewer window for the feature. |
| 137 | + * |
| 138 | + * @param string $active_feature The active feature. |
| 139 | + */ |
| 140 | + public function render_previewer( string $active_feature ) { |
| 141 | + $feature = new Classification(); |
| 142 | + $provider = $feature->get_feature_provider_instance(); |
| 143 | + |
| 144 | + if ( |
| 145 | + self::ID !== $provider::ID || |
| 146 | + $feature::ID !== $active_feature || |
| 147 | + ! $feature->is_feature_enabled() |
| 148 | + ) { |
| 149 | + return; |
| 150 | + } |
| 151 | + ?> |
| 152 | + |
| 153 | + <div id="classifai-post-preview-app"> |
| 154 | + <?php |
| 155 | + $supported_post_statuses = get_supported_post_statuses(); |
| 156 | + $supported_post_types = get_supported_post_types(); |
| 157 | + |
| 158 | + $posts_to_preview = get_posts( |
| 159 | + array( |
| 160 | + 'post_type' => $supported_post_types, |
| 161 | + 'post_status' => $supported_post_statuses, |
| 162 | + 'posts_per_page' => 10, |
| 163 | + ) |
| 164 | + ); |
| 165 | + ?> |
| 166 | + |
| 167 | + <h2><?php esc_html_e( 'Preview Language Processing', 'classifai' ); ?></h2> |
| 168 | + <div id="classifai-post-preview-controls"> |
| 169 | + <select id="classifai-preview-post-selector"> |
| 170 | + <?php foreach ( $posts_to_preview as $post ) : ?> |
| 171 | + <option value="<?php echo esc_attr( $post->ID ); ?>"><?php echo esc_html( $post->post_title ); ?></option> |
| 172 | + <?php endforeach; ?> |
| 173 | + </select> |
| 174 | + <?php wp_nonce_field( 'classifai-previewer-action', 'classifai-previewer-nonce' ); ?> |
| 175 | + <button type="button" class="button" id="get-classifier-preview-data-btn"> |
| 176 | + <span><?php esc_html_e( 'Preview', 'classifai' ); ?></span> |
| 177 | + </button> |
| 178 | + </div> |
| 179 | + <div id="classifai-post-preview-wrapper"> |
| 180 | + </div> |
| 181 | + </div> |
| 182 | + |
| 183 | + <?php |
130 | 184 | }
|
131 | 185 |
|
132 | 186 | /**
|
|
0 commit comments