PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.1
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.1
0.5.7 0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 All 33 releases
← All changes | classes/core.php +30 -27 0.4.60.4.1 View file →
@@ -132,9 +132,9 @@
132 132
133 133 $options = $this->sanitize_options( $options );
134 134
135 135 if ( !update_option( $this->option_name, $options, false ) ) {
136 - //$this->log( '💾 There was an issue updating the options.' );
136 + $this->log( '💾 There was an issue updating the options.' );
137 137 }
138 138
139 139 return $options;
140 140 }
@@ -167,9 +167,9 @@
167 167 $options_modified = true;
168 168 }
169 169
170 170 // Update AI Engine status
171 - $options = $this->updateAIEngineStatus( $options );
171 + $options_modified = $this->updateAIEngineStatus( $options ) || $options_modified;
172 172
173 173 // Disable AI related features if AI Engine is not available
174 174 if ( ! $options['ai_engine_status'] ) {
175 175 if ( $options['ai_suggestions'] !== false ) {
@@ -185,13 +185,31 @@
185 185
186 186 private function updateAIEngineStatus( &$options ) {
187 187 global $mwai;
188 188
189 - $options['mwai_has_ai'] = !empty( $mwai ) && method_exists( $mwai, 'hasAI' ) && $mwai->hasAI();
190 - // Legacy
191 - $options['ai_engine_status'] = $options['mwai_has_ai'];
189 + if ( is_null( $mwai ) || ! isset( $mwai ) ) {
190 + $options['ai_engine_status'] = false;
191 + $options['ai_engine_message'] = 'AI Engine is not available.';
192 + return true;
193 + }
192 194
193 - return $options;
195 + try {
196 + $status = $mwai->checkStatus();
197 +
198 + if ( $options['ai_engine_status'] != true || $options['ai_engine_message'] != $status ) {
199 + $options['ai_engine_status'] = true;
200 + $options['ai_engine_message'] = $status;
201 + return true;
202 + }
203 + } catch ( Exception $e ) {
204 + if ( $options['ai_engine_status'] != false || $options['ai_engine_message'] != $e->getMessage() ) {
205 + $options['ai_engine_status'] = false;
206 + $options['ai_engine_message'] = $e->getMessage();
207 + return true;
208 + }
209 + }
210 +
211 + return false;
194 212 }
195 213
196 214 #endregion
197 215
@@ -269,9 +287,9 @@
269 287
270 288 return [ $name, $value ];
271 289 }
272 290
273 - function run_non_fn_snippet( $id, $code = null, $test = false, $prefix = '' ) {
291 + function run_non_fn_snippet( $id, $code = null, $test = false ) {
274 292 // Retrieve the snippet code from the provided code or via the snippet ID.
275 293 if ( $code ) {
276 294 $snippet = [ 'code' => $code ];
277 295 } else {
@@ -283,12 +301,8 @@
283 301
284 302 if ( $test ) {
285 303 $snippet['code'] = preg_replace( '/echo\s+(.+?);/s', 'echo $1 . "\n";', $snippet['code'] );
286 304 }
287 -
288 - if( $prefix ) {
289 - $snippet['code'] = $prefix . "\n" . $snippet['code'];
290 - }
291 305
292 306 $error = null;
293 307 $output = null;
294 308
@@ -630,26 +644,16 @@
630 644
631 645 #endregion
632 646
633 647 #region Shortcodes
634 - function separate_mwcode_atts( $atts ) {
635 648
636 - if( array_key_exists( 'id', $atts ) ) unset( $atts['id'] );
637 - if( array_key_exists( 'target', $atts ) ) unset( $atts['target'] );
638 - if( array_key_exists( 'code', $atts ) ) unset( $atts['code'] );
639 -
640 - return $atts;
641 - }
642 -
643 649 function content_shortcode( $atts ) {
644 650
645 - $user_atts = $this->separate_mwcode_atts( $atts );
646 -
647 651 $atts = shortcode_atts( array(
648 - 'id' => null,
649 - 'target' => null, // js or php
650 - 'code' => null, // For Guttenberg block usage
651 - ), $atts, 'code-engine' );
652 + 'id' => null,
653 + 'target' => null,
654 + 'code' => null,
655 + ), $atts );
652 656
653 657 $id = $atts['id'];
654 658 $target = $atts['target'];
655 659 $code = $atts['code'];
@@ -732,10 +736,9 @@
732 736 $output = '<script>' . $snippet['code'] . '</script>';
733 737 }
734 738
735 739 if ( $is_content_php ) {
736 - $prefix = "\$mwcode_atts = unserialize( '" . serialize( $user_atts ) . "' );";
737 - $output = $this->run_non_fn_snippet( $id, null, false, $prefix );
740 + $output = $this->run_non_fn_snippet( $id );
738 741 }
739 742
740 743 return $output;
741 744 }