| 1 |
<?php |
| 2 |
/** |
| 3 |
* Help |
| 4 |
* |
| 5 |
* @package AutomatorWP\AI_Assistant\Help |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Render AI assistant help |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
function automatorwp_ai_assistant_render_help() { |
| 18 |
|
| 19 |
$user = wp_get_current_user(); |
| 20 |
$user_first = $user->user_login; |
| 21 |
$user_email = $user->user_email; |
| 22 |
$user_id = $user->ID; |
| 23 |
|
| 24 |
$abilities = array( |
| 25 |
'create-automations' => array( |
| 26 |
'label' => __( 'Create New Automations', 'automatorwp' ), |
| 27 |
'icon' => 'heart', |
| 28 |
'desc' => __( 'I\'m able to create new automations with multiples triggers and actions in the same prompt.', 'automatorwp' ), |
| 29 |
'prompts' => automatorwp_ai_assistant_get_random_prompts( 'create-automations' ), |
| 30 |
), |
| 31 |
'run-actions' => array( |
| 32 |
'label' => __( 'Run Actions', 'automatorwp' ), |
| 33 |
'icon' => 'controls-play', |
| 34 |
'desc' => __( 'I\'m able to execute any action available in AutomatorWP.', 'automatorwp' ) |
| 35 |
. ' ' . __( 'For points types, I can also define points awards and deductions in the same prompt.', 'automatorwp' ) , |
| 36 |
'prompts' => automatorwp_ai_assistant_get_random_prompts( 'run-actions' ), |
| 37 |
), |
| 38 |
'create-triggers-actions' => array( |
| 39 |
'label' => __( 'Set Up Triggers & Actions', 'automatorwp' ), |
| 40 |
'icon' => 'admin-tools', |
| 41 |
'desc' => __( 'I can configure new triggers an actions for existent automations.', 'automatorwp' ), |
| 42 |
'prompts' => automatorwp_ai_assistant_get_random_prompts( 'create-triggers-actions' ), |
| 43 |
), |
| 44 |
); |
| 45 |
|
| 46 |
$first_ability = array_keys( $abilities )[0]; |
| 47 |
|
| 48 |
?> |
| 49 |
|
| 50 |
<div class="automatorwp-ai-assistant-help-presentation"> |
| 51 |
<?php _e( 'I\'m an <strong>AI assistant</strong> specially designed to help you manage <strong>AutomatorWP</strong> using natural language.', 'automatorwp' ); ?> |
| 52 |
<br> |
| 53 |
<br> |
| 54 |
<?php esc_html_e( 'Here\'s what I can do:', 'automatorwp' ); ?> |
| 55 |
</div> |
| 56 |
|
| 57 |
<?php foreach( $abilities as $ability => $data ) : ?> |
| 58 |
<div class="automatorwp-ai-assistant-help-ability automatorwp-ai-assistant-help-ability-<?php echo esc_attr( $ability ); ?> <?php echo ( $ability === $first_ability ? 'automatorwp-ai-assistant-help-ability-open' : 'automatorwp-ai-assistant-help-ability-close' ); ?>"> |
| 59 |
<div class="automatorwp-ai-assistant-help-ability-label"><?php |
| 60 |
echo automatorwp_dashicon( $data['icon'] ) |
| 61 |
. ' ' . esc_html( $data['label'] ) |
| 62 |
. ' ' . automatorwp_dashicon( 'arrow-up-alt2' ); |
| 63 |
?></div> |
| 64 |
<div class="automatorwp-ai-assistant-help-ability-desc" style="<?php echo ( $ability === $first_ability ? '' : 'display: none;' ); ?>"> |
| 65 |
<div class="automatorwp-ai-assistant-help-ability-desc-text"><?php echo esc_html( $data['desc'] ); ?></div> |
| 66 |
<strong><small><?php esc_html_e( 'Examples', 'automatorwp' ); ?></small></strong> |
| 67 |
<div class="automatorwp-ai-assistant-help-ability-prompts"> |
| 68 |
<?php foreach( $data['prompts'] as $prompt ) : ?> |
| 69 |
<span class="automatorwp-ai-assistant-prompt"><?php echo esc_html( $prompt ); ?></span> |
| 70 |
<div class="automatorwp-ai-assistant-send-prompt cmb-tooltip" data-prompt="<?php echo esc_attr( $prompt ); ?>"> |
| 71 |
<?php echo automatorwp_dashicon( 'edit' ); ?> |
| 72 |
<div class="cmb-tooltip-desc cmb-tooltip-top"><?php echo esc_html( __( 'Edit Prompt', 'automatorwp' ) ); ?></div> |
| 73 |
</div> |
| 74 |
<div class="automatorwp-ai-assistant-send-prompt cmb-tooltip" data-prompt="<?php echo esc_attr( $prompt ); ?>" data-send="true"> |
| 75 |
<?php echo automatorwp_dashicon( 'share-alt2' ); ?> |
| 76 |
<div class="cmb-tooltip-desc cmb-tooltip-top"><?php echo esc_html( __( 'Send to Assistant', 'automatorwp' ) ); ?></div> |
| 77 |
</div> |
| 78 |
<br> |
| 79 |
<?php endforeach; ?> |
| 80 |
</div> |
| 81 |
</div> |
| 82 |
</div> |
| 83 |
<?php endforeach; ?> |
| 84 |
|
| 85 |
<?php |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Get a random prompts |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* |
| 93 |
* @return array |
| 94 |
*/ |
| 95 |
function automatorwp_ai_assistant_get_random_prompts( $section, $desired = 3 ) { |
| 96 |
|
| 97 |
$pompts = array(); |
| 98 |
|
| 99 |
while ( count( $pompts ) < $desired ) { |
| 100 |
$new = automatorwp_ai_assistant_get_random_prompt( $section ); |
| 101 |
|
| 102 |
if( ! in_array( $new, $pompts ) ) |
| 103 |
$pompts[] = $new; |
| 104 |
} |
| 105 |
|
| 106 |
return $pompts; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Get a random prompt |
| 111 |
* |
| 112 |
* @since 1.0.0 |
| 113 |
* |
| 114 |
* @return string |
| 115 |
*/ |
| 116 |
function automatorwp_ai_assistant_get_random_prompt( $section ) { |
| 117 |
|
| 118 |
$options = array(); |
| 119 |
|
| 120 |
switch ( $section ) { |
| 121 |
case 'create-automations': |
| 122 |
$options = automatorwp_ai_assistant_get_create_automations_prompts(); |
| 123 |
break; |
| 124 |
case 'create-triggers-actions': |
| 125 |
$options = automatorwp_ai_assistant_get_create_triggers_actions_prompts(); |
| 126 |
break; |
| 127 |
case 'run-actions': |
| 128 |
$options = automatorwp_ai_assistant_get_run_actions_prompts(); |
| 129 |
break; |
| 130 |
} |
| 131 |
|
| 132 |
$k = array_rand( $options ); |
| 133 |
|
| 134 |
return $options[$k]; |
| 135 |
|
| 136 |
} |
| 137 |
|
| 138 |
function automatorwp_ai_assistant_get_create_automations_prompts() { |
| 139 |
$plugin = automatorwp_ai_assistant_get_random_plugin(); |
| 140 |
|
| 141 |
switch ( $plugin ) { |
| 142 |
case 'GamiPress': |
| 143 |
case 'LearnDash': |
| 144 |
case 'LearnPress': |
| 145 |
case 'LifterLMS': |
| 146 |
case 'Tutor LMS': |
| 147 |
case 'H5P': |
| 148 |
$options = array( |
| 149 |
__( 'New automation: When user passes a quiz, add the tag "Student" in ActiveCampaign', 'automatorwp' ), |
| 150 |
__( 'Build an automation when a user views a course, send an email to the author ', 'automatorwp' ), |
| 151 |
__( 'When user completes a course, award them a GamiPress achievement and send them a congratulations email', 'automatorwp' ), |
| 152 |
); |
| 153 |
break; |
| 154 |
case 'Easy Digital Downloads': |
| 155 |
case 'SureCart': |
| 156 |
case 'WooCommerce': |
| 157 |
$options = array( |
| 158 |
__( 'New automation: When a user completes a purchase, subscribe them to my Mailchimp audience', 'automatorwp' ), |
| 159 |
__( 'Build an automation when a user purchases "Sample Product", add the tag "Customer" in ActiveCampaign', 'automatorwp' ), |
| 160 |
__( 'Build an automation when a user purchases "Course Product", enroll them in "Sample Course" course', 'automatorwp' ), |
| 161 |
__( 'When a customer buys a product, award them 100 GamiPress points and add them to a coupon', 'automatorwp' ), |
| 162 |
); |
| 163 |
break; |
| 164 |
case 'BuddyBoss': |
| 165 |
case 'BuddyPress': |
| 166 |
$options = array( |
| 167 |
__( 'New automation: When user completes a course, award them a GamiPress achievement and send them a congratulations email', 'automatorwp' ), |
| 168 |
__( 'Build an automation when a user views a post, send an email to the author ', 'automatorwp' ), |
| 169 |
__( 'When user completes a course, award them a GamiPress achievement and send them a congratulations email', 'automatorwp' ), |
| 170 |
); |
| 171 |
break; |
| 172 |
case 'WordPress': |
| 173 |
default: |
| 174 |
$options = array( |
| 175 |
__( 'New automation: When user registers on the site, send them a welcome email', 'automatorwp' ), |
| 176 |
__( 'When a post is published in the "News" category, create a post on Bluesky with the post title and URL', 'automatorwp' ), |
| 177 |
__( 'Build an automation when a user comments on a post, award them 10 points in GamiPress', 'automatorwp' ), |
| 178 |
); |
| 179 |
break; |
| 180 |
} |
| 181 |
|
| 182 |
return $options; |
| 183 |
} |
| 184 |
|
| 185 |
function automatorwp_ai_assistant_get_create_triggers_actions_prompts() { |
| 186 |
|
| 187 |
$plugin = automatorwp_ai_assistant_get_random_plugin(); |
| 188 |
|
| 189 |
$automation_names = array( |
| 190 |
__( 'Sample Automation', 'automatorwp' ), |
| 191 |
__( 'My Automation', 'automatorwp' ), |
| 192 |
__( 'Test Automation', 'automatorwp' ), |
| 193 |
__( 'Demo Automation', 'automatorwp' ), |
| 194 |
); |
| 195 |
|
| 196 |
$automation_name = $automation_names[array_rand( $automation_names )]; |
| 197 |
|
| 198 |
switch ( $plugin ) { |
| 199 |
case 'GamiPress': |
| 200 |
case 'LearnDash': |
| 201 |
case 'LearnPress': |
| 202 |
case 'LifterLMS': |
| 203 |
case 'Tutor LMS': |
| 204 |
case 'H5P': |
| 205 |
$options = array( |
| 206 |
sprintf( __( 'Add an action to award 10 points in GamiPress to "%s"', 'automatorwp' ), $automation_name ), |
| 207 |
sprintf( __( 'Add an action to enroll user in "Sample" course to "%s"', 'automatorwp' ), $automation_name ), |
| 208 |
sprintf( __( 'Add a trigger for unlock "Sample" badge in GamiPress to "%s"', 'automatorwp' ), $automation_name ), |
| 209 |
sprintf( __( 'Add a trigger for complete "Sample" course to "%s"', 'automatorwp' ), $automation_name ), |
| 210 |
); |
| 211 |
break; |
| 212 |
case 'Easy Digital Downloads': |
| 213 |
case 'SureCart': |
| 214 |
case 'WooCommerce': |
| 215 |
$options = array( |
| 216 |
sprintf( __( 'Add an action to add the user to "BIGSALE" coupon to "%s"', 'automatorwp' ), $automation_name ), |
| 217 |
sprintf( __( 'Add a trigger for purchase a product in "Offers" category to "%s"', 'automatorwp' ), $automation_name ), |
| 218 |
sprintf( __( 'Add a trigger for viewing "T-Shirt" product to "%s"', 'automatorwp' ), $automation_name ), |
| 219 |
); |
| 220 |
break; |
| 221 |
case 'BuddyBoss': |
| 222 |
case 'BuddyPress': |
| 223 |
$options = array( |
| 224 |
sprintf( __( 'Add a trigger for joining "Sample" group to "%s"', 'automatorwp' ), $automation_name ), |
| 225 |
sprintf( __( 'Add a trigger for completing the user profile to "%s"', 'automatorwp' ), $automation_name ), |
| 226 |
sprintf( __( 'Add an action to add the user to "Sample" group to "%s"', 'automatorwp' ), $automation_name ), |
| 227 |
); |
| 228 |
break; |
| 229 |
case 'WordPress': |
| 230 |
default: |
| 231 |
$options = array( |
| 232 |
sprintf( __( 'Add an action to send a welcome email to "%s"', 'automatorwp' ), $automation_name ), |
| 233 |
sprintf( __( 'Add a trigger for publishing a post in "News" category to "%s"', 'automatorwp' ), $automation_name ), |
| 234 |
// External |
| 235 |
sprintf( __( 'Add an action to tag the user in ActiveCampaign to "%s"', 'automatorwp' ), $automation_name ), |
| 236 |
sprintf( __( 'Add an action to subscribe the user in Mailchimp to "%s"', 'automatorwp' ), $automation_name ), |
| 237 |
sprintf( __( 'Add an action to add a post in Bluesky to "%s"', 'automatorwp' ), $automation_name ), |
| 238 |
); |
| 239 |
break; |
| 240 |
} |
| 241 |
|
| 242 |
return $options; |
| 243 |
|
| 244 |
} |
| 245 |
|
| 246 |
function automatorwp_ai_assistant_get_run_actions_prompts() { |
| 247 |
|
| 248 |
$plugin = automatorwp_ai_assistant_get_random_plugin(); |
| 249 |
|
| 250 |
$user = wp_get_current_user(); |
| 251 |
$user_first = $user->user_login; |
| 252 |
$user_email = $user->user_email; |
| 253 |
$user_id = $user->ID; |
| 254 |
|
| 255 |
switch ( $plugin ) { |
| 256 |
case 'GamiPress': |
| 257 |
case 'LearnDash': |
| 258 |
case 'LearnPress': |
| 259 |
case 'LifterLMS': |
| 260 |
case 'Tutor LMS': |
| 261 |
case 'H5P': |
| 262 |
$options = array( |
| 263 |
sprintf( __( 'Award 10 points to %s', 'automatorwp' ), $user_first ), |
| 264 |
sprintf( __( 'Award the badge "Sample Badge" to %s', 'automatorwp' ), $user_first ), |
| 265 |
sprintf( __( 'Award the rank "Sample Rank" to %s', 'automatorwp' ), $user_first ), |
| 266 |
sprintf( __( 'Enroll %s in course "Sample Course"', 'automatorwp' ), $user_first ), |
| 267 |
); |
| 268 |
break; |
| 269 |
case 'Easy Digital Downloads': |
| 270 |
case 'SureCart': |
| 271 |
case 'WooCommerce': |
| 272 |
$options = array( |
| 273 |
sprintf( __( 'Add %1$s to coupon "%2$s"', 'automatorwp' ), $user_first, 'BFCM' . date('Y') ), |
| 274 |
); |
| 275 |
break; |
| 276 |
case 'BuddyBoss': |
| 277 |
case 'BuddyPress': |
| 278 |
$options = array( |
| 279 |
sprintf( __( 'Add %s to group "Sample Group"', 'automatorwp' ), $user_first ), |
| 280 |
sprintf( __( 'Set the profile type "Member" to %s', 'automatorwp' ), $user_first ), |
| 281 |
); |
| 282 |
break; |
| 283 |
case 'WordPress': |
| 284 |
default: |
| 285 |
$options = array( |
| 286 |
sprintf( __( 'Set the role "Contributor" to %s', 'automatorwp' ), $user_first ), |
| 287 |
sprintf( __( 'Send a congratulations email to %s', 'automatorwp' ), $user_first ), |
| 288 |
sprintf( __( 'Update %s user meta "approved" to "yes"', 'automatorwp' ), $user_first ), |
| 289 |
sprintf( __( 'Create a privacy policy page and a link for that page in ShortLinks Pro', 'automatorwp' ), $user_first ), |
| 290 |
sprintf( __( 'Create an about us page and a link for that page in ShortLinks Pro', 'automatorwp' ), $user_first ), |
| 291 |
sprintf( __( 'Delete the page "Sample Page"', 'automatorwp' ), $user_first ), |
| 292 |
sprintf( __( 'Delete the user "Test"', 'automatorwp' ), $user_first ), |
| 293 |
sprintf( __( 'Delete the user "Test"', 'automatorwp' ), $user_first ), |
| 294 |
// External |
| 295 |
sprintf( __( 'Add the tag "New" to %s in ActiveCampaign', 'automatorwp' ), $user_first ), |
| 296 |
sprintf( __( 'Add %s to Mailchimp', 'automatorwp' ), $user_first ), |
| 297 |
sprintf( __( 'Publish a post in Bluesky about this site', 'automatorwp' ), $user_first ), |
| 298 |
); |
| 299 |
break; |
| 300 |
} |
| 301 |
|
| 302 |
return $options; |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Get a random plugin name |
| 308 |
* |
| 309 |
* @since 1.0.0 |
| 310 |
* |
| 311 |
* @return string |
| 312 |
*/ |
| 313 |
function automatorwp_ai_assistant_get_random_plugin() { |
| 314 |
return automatorwp_assoc_array_rand( automatorwp_ai_assistant_get_available_plugins(), 'WordPress' ); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Get a list of random plugins names |
| 319 |
* |
| 320 |
* @since 1.0.0 |
| 321 |
* |
| 322 |
* @return string |
| 323 |
*/ |
| 324 |
function automatorwp_ai_assistant_get_random_plugins( $desired = 3 ) { |
| 325 |
$available = automatorwp_ai_assistant_get_available_plugins(); |
| 326 |
|
| 327 |
if( $desired === 1 ) |
| 328 |
return automatorwp_ai_assistant_get_random_plugin(); |
| 329 |
|
| 330 |
|
| 331 |
if( count( $available ) < $desired ) |
| 332 |
return automatorwp_join_words( $available ); |
| 333 |
|
| 334 |
$results = array(); |
| 335 |
|
| 336 |
for( $i = 0; $i < $desired; $i++ ) { |
| 337 |
$result = automatorwp_assoc_array_rand( $available, 'WordPress' ); |
| 338 |
|
| 339 |
$k = array_search( $result, $available ); |
| 340 |
unset( $available[$k] ); |
| 341 |
|
| 342 |
$results[] = $result; |
| 343 |
} |
| 344 |
|
| 345 |
return automatorwp_join_words( array_unique( $results ) ); |
| 346 |
} |
| 347 |
|
| 348 |
/** |
| 349 |
* Get available plugins names |
| 350 |
* |
| 351 |
* @since 1.0.0 |
| 352 |
* |
| 353 |
* @return array |
| 354 |
*/ |
| 355 |
function automatorwp_ai_assistant_get_available_plugins() { |
| 356 |
|
| 357 |
$options = array(); |
| 358 |
|
| 359 |
if( class_exists( 'GamiPress' ) ) $options[] = 'GamiPress'; |
| 360 |
// if( class_exists( 'AutomatorWP' ) ) $options[] = 'AutomatorWP'; |
| 361 |
if( class_exists( 'ShortLinksPro' ) ) $options[] = 'ShortLinks Pro'; |
| 362 |
if( class_exists( 'BBForms' ) ) $options[] = 'BBForms'; |
| 363 |
|
| 364 |
if( defined( 'BP_PLATFORM_VERSION' ) ) $options[] = 'BuddyBoss'; |
| 365 |
if( class_exists( 'BuddyPress' ) && ! defined( 'BP_PLATFORM_VERSION' ) ) $options[] = 'BuddyPress'; |
| 366 |
|
| 367 |
if( class_exists( 'SFWD_LMS' ) ) $options[] = 'LearnDash'; |
| 368 |
if( class_exists( 'LearnPress' ) ) $options[] = 'LearnPress'; |
| 369 |
if( class_exists( 'LifterLMS' ) ) $options[] = 'LifterLMS'; |
| 370 |
if( function_exists( 'tutor' ) ) $options[] = 'Tutor LMS'; |
| 371 |
if( class_exists( 'H5P_Plugin' ) ) $options[] = 'H5P'; |
| 372 |
|
| 373 |
if( class_exists( 'Easy_Digital_Downloads' ) ) $options[] = 'Easy Digital Downloads'; |
| 374 |
if( class_exists( 'SureCart' ) ) $options[] = 'SureCart'; |
| 375 |
if( class_exists( 'WooCommerce' ) ) $options[] = 'WooCommerce'; |
| 376 |
|
| 377 |
$options[] = 'WordPress'; |
| 378 |
|
| 379 |
return $options; |
| 380 |
} |