PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.2
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.2
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 +24 -6 0.4.60.4.2 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