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.1.6 1.6.86 0.1.7 1.6.87 0.1.8 1.6.88 0.1.9 1.6.89 0.2.0 1.6.90
ai-engine / classes / modules / advisor.php
ai-engine / classes / modules Last commit date
advisor.php 7 months ago chatbot.php 4 months ago discussions.php 5 months ago files.php 6 months ago forms-manager.php 10 months ago gdpr.php 4 months ago search.php 11 months ago security.php 11 months ago tasks-examples.php 6 months ago tasks.php 5 months ago wand.php 5 months ago
advisor.php
240 lines
1 <?php
2
3 class Meow_MWAI_Modules_Advisor {
4 private $core = null;
5 private $update_interval = 24 * 60 * 60;
6 private $prompt = "Based on all the plugins I have installed and my WordPress information, can you give me general advice and recommendations about my WordPress setup? Aim for a concise list of 6-8 recommendations total. Consider factors such as whether certain types of plugins are still needed, if some might be deprecated, their overall impact on performance, if there are redundancies or conflicts between plugins, and if some functionality is no longer required with recent versions of WordPress. Provide the recommendations in a JSON format with 'level', 'severity', 'title', and 'description' fields:
7
8 'level' can be 'success', 'warning', or 'danger'. Use 'success' to highlight areas that are working well and should be maintained to keep things running optimally. This motivates the user to continue good practices. Use 'warning' for issues that are not critical but could be improved. Use 'danger' for critical issues that should be addressed immediately.
9 'severity' should be an integer from 0 to 100, with 0 being the least severe and 100 being the most severe.
10 'title' should be a concise description of the recommendation.
11 'description' should provide more details about the recommendation.
12 Here is a simple JSON example of the format to use, without any actual data:
13 [
14 {
15 \"level\": \"success\",
16 \"severity\": 0,
17 \"title\": \"Example Success\",
18 \"description\": \"This is an example of a successful recommendation.\"
19 },
20 {
21
22 \"level\": \"warning\",
23 \"severity\": 50,
24 \"title\": \"Example Warning\",
25 \"description\": \"This is an example of a non-critical recommendation.\"
26 },
27 {
28 \"level\": \"danger\",
29 \"severity\": 100,
30 \"title\": \"Example Danger\",
31 \"description\": \"This is an example of a critical recommendation.\"
32 }
33 ]
34
35 Instead of focusing on individual plugins, provide more general and holistic recommendations based on the overall WordPress system and the installed plugins as a whole. Feel free to use titles like \"Useless Plugins\" or \"Performance Considerations\" to group related recommendations. Avoid repeating the same or very similar recommendations. Only output the JSON - do not include any other text or formatting like markdown. If you don't have any recommendations, output an empty array [].
36
37 Here are the plugins I have installed, along with my WordPress information:";
38
39 public function __construct( $core ) {
40 $this->core = $core;
41 add_action( 'init', [ $this, 'init' ] );
42
43 // Only add dashboard widget if module is enabled and user has permissions
44 if ( $this->core->get_option( 'module_advisor', false ) ) {
45 add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
46 }
47 }
48
49 public function init() {
50 // Handle manual refresh request
51 if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['refresh_advisor_nonce'] ) ) {
52 if ( wp_verify_nonce( $_POST['refresh_advisor_nonce'], 'refresh_advisor_action' ) ) {
53 $this->run_advisor();
54 wp_safe_redirect( remove_query_arg( 'refresh_advisor' ) );
55 exit;
56 }
57 }
58
59 // Always register the task handler (in case task exists from before)
60 add_filter( 'mwai_task_advisor_daily', [ $this, 'run_advisor_task' ], 10, 2 );
61
62 // Only ensure the task exists if module is enabled
63 if ( $this->core->get_option( 'module_advisor', false ) ) {
64 // Ensure the advisor task exists
65 $this->ensure_advisor_task();
66 }
67 }
68
69 /**
70 * Ensure the advisor task exists in the Tasks system
71 */
72 private function ensure_advisor_task() {
73 if ( !$this->core->tasks ) {
74 return;
75 }
76
77 $this->core->tasks->ensure( [
78 'name' => 'advisor_daily',
79 'description' => 'Analyze WordPress setup and provide recommendations.',
80 'category' => 'system',
81 'schedule' => '0 2 * * *', // Daily at 2 AM
82 'deletable' => 0, // System task, not deletable
83 ] );
84 }
85
86 /**
87 * Handle advisor task execution
88 */
89 public function run_advisor_task( $result, $job ) {
90 // Check if module is enabled
91 if ( !$this->core->get_option( 'module_advisor', false ) ) {
92 return [
93 'ok' => false,
94 'message' => 'Advisor module is disabled.'
95 ];
96 }
97
98 try {
99 $this->run_advisor();
100 return [
101 'ok' => true,
102 'message' => 'Advisor analysis completed successfully.'
103 ];
104 } catch ( Exception $e ) {
105 return [
106 'ok' => false,
107 'message' => 'Advisor analysis failed: ' . $e->getMessage()
108 ];
109 }
110 }
111
112 private function check_and_run_advisor() {
113 $last_run_data = get_option( 'mwai_advisor_data', [] );
114 $last_run_time = $last_run_data['date'] ?? 0;
115 $current_time = time();
116 if ( $current_time - $last_run_time > $this->update_interval ) {
117 $this->run_advisor();
118 }
119 }
120
121 public function run_advisor() {
122 try {
123 global $mwai;
124 $mwai->checkStatus();
125 $plugins = $this->get_all_installed_plugins();
126
127 $finalPrompt = $this->prompt;
128 foreach ( $plugins as $plugin ) {
129 $finalPrompt .= 'Plugin: ' . $plugin['title'] . "\n";
130 $finalPrompt .= '- Version: ' . $plugin['version'] . "\n";
131 $finalPrompt .= '- Description: ' . $plugin['description'] . "\n";
132 $finalPrompt .= '- Enabled: ' . ( $plugin['enabled'] ? 'Yes' : 'No' ) . "\n";
133 }
134 $finalPrompt .= "\n";
135
136 $finalPrompt .= "WordPress Information:\n";
137 $finalPrompt .= '- Number of Plugins: ' . count( $plugins ) . "\n";
138 $finalPrompt .= '- Site URL: ' . get_site_url() . "\n";
139 $finalPrompt .= '- PHP Version: ' . phpversion() . "\n";
140 $finalPrompt .= '- WordPress Version: ' . get_bloginfo( 'version' ) . "\n";
141 $finalPrompt .= '- Theme: ' . wp_get_theme()->get( 'Name' ) . "\n";
142 $finalPrompt .= "\n";
143
144 $finalPrompt .= "General Information:\n";
145 $finalPrompt .= "- Today's Date: " . date( 'Y-m-d' ) . "\n";
146 $finalPrompt .= "\n";
147
148 $errors = MeowKit_MWAI_Helpers::php_error_logs();
149 $errors = array_slice( $errors, -10 );
150 if ( !empty( $errors ) ) {
151 $finalPrompt .= "PHP Errors: \n";
152 foreach ( $errors as $error ) {
153 $finalPrompt .= $error['date'] . ' - ' . $error['type'] . ' - ' . $error['content'] . "\n";
154 }
155 }
156
157 $answer = $mwai->simpleTextQuery( $finalPrompt, [ 'scope' => 'advisor' ] );
158 $recommendations = json_decode( $answer, true );
159 update_option( 'mwai_advisor_data', [
160 'date' => time(),
161 'data' => $recommendations
162 ], false );
163
164 }
165 catch ( Exception $e ) {
166 error_log( 'AI Engine: ' . $e->getMessage() );
167 }
168 }
169
170 public function get_all_installed_plugins() {
171 if ( !function_exists( 'get_plugins' ) ) {
172 require_once ABSPATH . 'wp-admin/includes/plugin.php';
173 }
174 $all_plugins = get_plugins();
175 $active_plugins = get_option( 'active_plugins', [] );
176 $plugins_info = [];
177 foreach ( $all_plugins as $plugin_path => $plugin_data ) {
178 $plugin_info = [
179 'title' => $plugin_data['Name'],
180 'version' => $plugin_data['Version'],
181 'description' => $plugin_data['Description'],
182 'enabled' => in_array( $plugin_path, $active_plugins ) ? true : false
183 ];
184 $plugins_info[] = $plugin_info;
185 }
186 return $plugins_info;
187 }
188
189 public function add_dashboard_widget() {
190 wp_add_dashboard_widget(
191 'mwai_advisor_widget',
192 'AI Engine Advisor',
193 [ $this, 'advisor_metabox' ]
194 );
195 }
196
197 public function advisor_metabox() {
198 $data = get_option( 'mwai_advisor_data', [] );
199 $recommendations = $data['data'] ?? [];
200 if ( empty( $recommendations ) ) {
201 echo '<p>No recommendations yet.</p>';
202 }
203 else {
204 echo '<p>Everyday, AI Engine will analyze your WordPress setup and provide you with recommendations to improve it.</p>';
205 echo '<ul>';
206 foreach ( $recommendations as $recommendation ) {
207 $title = isset( $recommendation['title'] ) ? $recommendation['title'] : 'Miscellaneous';
208 $description = isset( $recommendation['description'] ) ? $recommendation['description'] : 'No information available.';
209 echo '<li style="display: inline;">';
210 echo '<div style="display: flex; margin-bottom: 10px;">';
211 echo $this->generate_badge( $recommendation['level'] );
212 echo '<div>';
213 echo '<strong>' . $title . '</strong> - ' . $description;
214 echo '</div>';
215 echo '</div>';
216 echo '</li>';
217 }
218 echo '</ul>';
219 }
220 echo '<form method="POST">';
221 wp_nonce_field( 'refresh_advisor_action', 'refresh_advisor_nonce' );
222 echo '<div style="display: flex; justify-content: end;">';
223 echo '<input type="submit" class="button" value="Refresh Recommendations">';
224 echo '</div>';
225 echo '</form>';
226 }
227
228 public function generate_badge( $level ) {
229 $color = ( $level === 'success' ) ? '#00ba37' : ( ( $level === 'warning' ) ? '#dba617' : '#e65054' );
230 return '<div style="display: flex; align-items: center; margin-bottom: 5px;">
231 <div style="width: 20px; height: 20px; margin-right: 10px;">
232 <svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
233 <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0" style="stroke: #e2e2e2;"></circle>
234 <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0" style="stroke-width: 15px; stroke: ' . $color . ';"></circle>
235 </svg>
236 </div>
237 </div>';
238 }
239 }
240