| @@ -1,0 +1,1426 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Automation UI | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Automation_UI | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Render automation type dialog | |
| 14 | + * | |
| 15 | + * @since 1.3.0 | |
| 16 | + */ | |
| 17 | +function automatorwp_render_automation_type_dialog() { | |
| 18 | + | |
| 19 | + if( ! isset( $_GET['page'] ) ) { | |
| 20 | + return; | |
| 21 | + } | |
| 22 | + | |
| 23 | + $allowed_pages = array( | |
| 24 | + 'automatorwp_automations', | |
| 25 | + 'edit_automatorwp_automations', | |
| 26 | + ); | |
| 27 | + | |
| 28 | + // Only render on allowed pages | |
| 29 | + if( ! in_array( $_GET['page'], $allowed_pages ) ) { | |
| 30 | + return; | |
| 31 | + } | |
| 32 | + | |
| 33 | + $types = automatorwp_get_automation_types(); ?> | |
| 34 | + | |
| 35 | + <div class="automatorwp-automation-type-dialog-wrapper" style="display: none;"> | |
| 36 | + | |
| 37 | + <div class="automatorwp-automation-type-dialog"> | |
| 38 | + <h2 class="automatorwp-automation-type-dialog-title"><?php esc_html_e( 'Automation type', 'automatorwp' ); ?></h2> | |
| 39 | + <div class="automatorwp-automation-types"> | |
| 40 | + <?php foreach( $types as $type => $args ) : | |
| 41 | + if( in_array( $type, automatorwp_get_automation_loop_types() ) ) continue; ?> | |
| 42 | + <div class="automatorwp-automation-type automatorwp-automation-type-<?php echo $type; ?>" data-type="<?php echo $type; ?>"> | |
| 43 | + <img src="<?php echo $args['image']; ?>" alt="<?php echo $args['label']; ?>"> | |
| 44 | + <div class="automatorwp-automation-type-description"> | |
| 45 | + <strong><?php echo $args['label']; ?></strong> | |
| 46 | + <span><?php echo $args['desc']; ?></span> | |
| 47 | + </div> | |
| 48 | + </div> | |
| 49 | + <?php endforeach; ?> | |
| 50 | + </div> | |
| 51 | + <h3 class="automatorwp-automation-type-dialog-automation-loop-title"> | |
| 52 | + <?php esc_html_e( 'Loop Automations', 'automatorwp' ); ?> | |
| 53 | + <span class="cmb-tooltip"> | |
| 54 | + <i class="dashicons dashicons-cmb-tooltip"></i> | |
| 55 | + <span class="cmb-tooltip-desc cmb-tooltip-top"><?php _e( 'Designed to run actions on a <b>group of elements</b>. Can be run <b>manually</b>, on a <b>specific date</b> or on a <b>recurring</b> basis.', 'automatorwp' ); ?></span> | |
| 56 | + </span> | |
| 57 | + </h3> | |
| 58 | + <div class="automatorwp-automation-types automatorwp-automation-loop-types"> | |
| 59 | + <?php foreach( $types as $type => $args ) : | |
| 60 | + if( ! in_array( $type, automatorwp_get_automation_loop_types() ) ) continue; ?> | |
| 61 | + <div class="automatorwp-automation-type automatorwp-automation-type-<?php echo $type; ?>" data-type="<?php echo $type; ?>"> | |
| 62 | + <img src="<?php echo $args['image']; ?>" alt="<?php echo $args['label']; ?>"> | |
| 63 | + <div class="automatorwp-automation-type-description"> | |
| 64 | + <strong><?php echo $args['label']; ?></strong> | |
| 65 | + <span><?php echo $args['desc']; ?></span> | |
| 66 | + </div> | |
| 67 | + </div> | |
| 68 | + <?php endforeach; ?> | |
| 69 | + </div> | |
| 70 | + <div class="automatorwp-notice-warning"> | |
| 71 | + <?php echo __( '<strong>Note:</strong> Automation type cannot be changed later. ', 'automatorwp' ); ?> | |
| 72 | + </div> | |
| 73 | + <div class="automatorwp-dialog-bottom automatorwp-automation-type-dialog-bottom"> | |
| 74 | + <div class="automatorwp-dialog-buttons automatorwp-automation-type-dialog-buttons"> | |
| 75 | + <button type="button" class="button button-primary automatorwp-automation-type-dialog-confirm"><?php _e( 'Confirm', 'automatorwp' ); ?></button> | |
| 76 | + <button type="button" data-dialog="automatorwp-automation-type-dialog" class="button automatorwp-button-danger automatorwp-dialog-cancel automatorwp-automation-type-dialog-cancel"><?php _e( 'Cancel', 'automatorwp' ); ?></button> | |
| 77 | + </div> | |
| 78 | + </div> | |
| 79 | + </div> | |
| 80 | + | |
| 81 | + </div> | |
| 82 | + | |
| 83 | + <?php | |
| 84 | + | |
| 85 | +} | |
| 86 | +add_action( 'admin_footer', 'automatorwp_render_automation_type_dialog' ); | |
| 87 | + | |
| 88 | +/** | |
| 89 | + * Render automation url export dialog | |
| 90 | + * | |
| 91 | + * @since 1.4.8 | |
| 92 | + */ | |
| 93 | +function automatorwp_render_automation_url_export_dialog() { | |
| 94 | + | |
| 95 | + if( ! isset( $_GET['page'] ) ) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + | |
| 99 | + $allowed_pages = array( | |
| 100 | + 'automatorwp_automations', | |
| 101 | + 'edit_automatorwp_automations', | |
| 102 | + ); | |
| 103 | + | |
| 104 | + // Only render on allowed pages | |
| 105 | + if( ! in_array( $_GET['page'], $allowed_pages ) ) { | |
| 106 | + return; | |
| 107 | + } ?> | |
| 108 | + | |
| 109 | + <div class="automatorwp-automation-url-export-dialog-wrapper" style="display: none;"> | |
| 110 | + | |
| 111 | + <div class="automatorwp-automation-url-export-dialog"> | |
| 112 | + <h2><?php _e( 'Export automation', 'automatorwp' ); ?></h2> | |
| 113 | + <div class="automatorwp-automation-url-export-dialog-input"> | |
| 114 | + <label><?php _e( 'Enter you website URL:', 'automatorwp' ); ?></label> | |
| 115 | + <input type="text" placeholder="https://website.com"> | |
| 116 | + <div class="automatorwp-notice-error" style="display: none;"><?php _e( 'Please, enter a valid URL.', 'automatorwp' ); ?></div> | |
| 117 | + </div> | |
| 118 | + <div class="automatorwp-automation-url-export-dialog-url"> | |
| 119 | + <label><?php _e( 'Exportable URL:', 'automatorwp' ); ?></label> | |
| 120 | + <input type="text"> | |
| 121 | + <div class="automatorwp-automation-url-export-dialog-url-copy"> | |
| 122 | + <div class="automatorwp-automation-url-export-dialog-url-copy-icon"><span class="dashicons dashicons-admin-page"></span></div> | |
| 123 | + <div class="automatorwp-automation-url-export-dialog-url-copy-text"> | |
| 124 | + <span class="automatorwp-automation-url-export-dialog-url-copy-text-copy"><?php _e( 'Copy URL', 'automatorwp' ); ?></span> | |
| 125 | + <span class="automatorwp-automation-url-export-dialog-url-copy-text-copied" style="display: none;"><?php _e( 'Copied!', 'automatorwp' ); ?></span> | |
| 126 | + </div> | |
| 127 | + </div> | |
| 128 | + <span class="automatorwp-automation-url-export-dialog-desc"><?php _e( 'Copy this URL and place it on your browser to automatically import this automation on your website.', 'automatorwp' ); ?></span> | |
| 129 | + </div> | |
| 130 | + <div class="automatorwp-dialog-bottom automatorwp-automation-url-export-dialog-bottom"> | |
| 131 | + <div class="automatorwp-dialog-buttons automatorwp-automation-url-export-dialog-buttons"> | |
| 132 | + <button type="button" class="button button-primary automatorwp-automation-url-export-dialog-confirm"> | |
| 133 | + <span class="automatorwp-automation-url-export-dialog-confirm-default-text"><?php _e( 'Generate URL to export', 'automatorwp' ); ?></span> | |
| 134 | + <span class="automatorwp-automation-url-export-dialog-confirm-generating-text" style="display: none;"><?php _e( 'Generating URL', 'automatorwp' ); ?>...</span> | |
| 135 | + <span class="automatorwp-automation-url-export-dialog-confirm-success-text" style="display: none;"><?php _e( 'Done', 'automatorwp' ); ?></span> | |
| 136 | + </button> | |
| 137 | + <button type="button" data-dialog="automatorwp-automation-url-export-dialog" class="button automatorwp-button-danger automatorwp-dialog-cancel automatorwp-automation-url-export-dialog-cancel"><?php _e( 'Cancel', 'automatorwp' ); ?></button> | |
| 138 | + </div> | |
| 139 | + </div> | |
| 140 | + </div> | |
| 141 | + | |
| 142 | + </div> | |
| 143 | + | |
| 144 | + <?php | |
| 145 | + | |
| 146 | +} | |
| 147 | +add_action( 'admin_footer', 'automatorwp_render_automation_url_export_dialog' ); | |
| 148 | + | |
| 149 | +/** | |
| 150 | + * Render automation type dialog | |
| 151 | + * | |
| 152 | + * @since 1.3.0 | |
| 153 | + * | |
| 154 | + * @param string $classes | |
| 155 | + * | |
| 156 | + * @return string | |
| 157 | + */ | |
| 158 | +function automatorwp_automation_ui_admin_body_class( $classes ) { | |
| 159 | + | |
| 160 | + global $ct_table; | |
| 161 | + | |
| 162 | + if( ! isset( $_GET['page'] ) ) { | |
| 163 | + return $classes; | |
| 164 | + } | |
| 165 | + | |
| 166 | + // Only add class on allowed pages | |
| 167 | + if( $_GET['page'] !== 'edit_automatorwp_automations' ) { | |
| 168 | + return $classes; | |
| 169 | + } | |
| 170 | + | |
| 171 | + if( $ct_table->name !== 'automatorwp_automations' ) { | |
| 172 | + return $classes; | |
| 173 | + } | |
| 174 | + | |
| 175 | + $primary_key = $ct_table->db->primary_key; | |
| 176 | + | |
| 177 | + if( ! isset( $_GET[$primary_key] ) ) { | |
| 178 | + return $classes; | |
| 179 | + } | |
| 180 | + | |
| 181 | + $automation_id = (int) $_GET[$primary_key]; | |
| 182 | + $automation = $ct_table->db->get( $automation_id ); | |
| 183 | + | |
| 184 | + $classes .= ' edit-' . $automation->type . '-automation '; | |
| 185 | + | |
| 186 | + $classes = apply_filters( 'automatorwp_automation_ui_admin_body_class', $classes, $automation ); | |
| 187 | + | |
| 188 | + return $classes; | |
| 189 | + | |
| 190 | +} | |
| 191 | +add_filter( 'admin_body_class', 'automatorwp_automation_ui_admin_body_class' ); | |
| 192 | + | |
| 193 | +/** | |
| 194 | + * Automation UI meta boxes | |
| 195 | + * | |
| 196 | + * @since 1.0.0 | |
| 197 | + */ | |
| 198 | +function automatorwp_automation_ui_add_meta_boxes() { | |
| 199 | + | |
| 200 | + add_meta_box( 'automatorwp_triggers', __( 'Triggers', 'automatorwp' ), 'automatorwp_automation_ui_triggers_meta_box', 'automatorwp_automations', 'normal', 'default' ); | |
| 201 | + add_meta_box( 'automatorwp_actions', __( 'Actions', 'automatorwp' ), 'automatorwp_automation_ui_actions_meta_box', 'automatorwp_automations', 'normal', 'default' ); | |
| 202 | + | |
| 203 | +} | |
| 204 | +add_action( 'add_meta_boxes', 'automatorwp_automation_ui_add_meta_boxes' ); | |
| 205 | + | |
| 206 | +/** | |
| 207 | + * Renders the triggers meta box | |
| 208 | + * | |
| 209 | + * @since 1.0.0 | |
| 210 | + * | |
| 211 | + * @param stdClass $automation The automation object | |
| 212 | + * @param string $type Type to render form | |
| 213 | + */ | |
| 214 | +function automatorwp_automation_ui_triggers_meta_box( $automation, $type ) { | |
| 215 | + | |
| 216 | + global $automatorwp_triggers_current_position; | |
| 217 | + | |
| 218 | + $automatorwp_triggers_current_position = 0; | |
| 219 | + | |
| 220 | + $triggers = automatorwp_get_automation_triggers( $automation->id ); | |
| 221 | + | |
| 222 | + ?> | |
| 223 | + <?php // Section title and subtitle ?> | |
| 224 | + <div class="automatorwp-title"><?php _e( 'Triggers', 'automatorwp' ); ?></div> | |
| 225 | + <div class="automatorwp-subtitle"><?php _e( 'When this happens...', 'automatorwp' ); ?></div> | |
| 226 | + | |
| 227 | + <?php // Sequential ?> | |
| 228 | + <div class="automatorwp-sequential-field cmb2-switch"> | |
| 229 | + <label for="sequential"><?php _e( 'Sequential', 'automatorwp' ); ?> <?php echo cmb_tooltip_get_html( __( 'Check this option to force users to complete triggers in order.', 'automatorwp' ) ) ?></label> | |
| 230 | + <div class="cmb-td"> | |
| 231 | + <input type="checkbox" id="sequential" name="sequential" class="automatorwp-auto-save" value="1" <?php checked( $automation->sequential, 1 ); ?> /> | |
| 232 | + <label for="sequential"><span class="cmb2-metabox-description"></span></label> | |
| 233 | + </div> | |
| 234 | + </div> | |
| 235 | + | |
| 236 | + <?php // Triggers ?> | |
| 237 | + <div class="automatorwp-automation-items automatorwp-triggers"> | |
| 238 | + | |
| 239 | + <?php $triggers = automatorwp_check_automation_required_triggers( $automation, $triggers ); ?> | |
| 240 | + | |
| 241 | + <?php foreach( $triggers as $trigger ) : ?> | |
| 242 | + | |
| 243 | + <?php automatorwp_automation_item_edit_html( $trigger, 'trigger', $automation ); ?> | |
| 244 | + | |
| 245 | + <?php endforeach; ?> | |
| 246 | + | |
| 247 | + </div> | |
| 248 | + | |
| 249 | + <?php automatorwp_automation_ui_add_item_form( $automation, 'trigger' ); ?> | |
| 250 | + | |
| 251 | + <?php // Anonymous automation notice ?> | |
| 252 | + <div class="automatorwp-automation-ui-anonymous-notice"><span class="dashicons dashicons-info"></span> <?php _e( 'Anonymous automations only support one trigger per automation.', 'automatorwp' ); ?></div> | |
| 253 | + <?php // Add Trigger ?> | |
| 254 | + <button type="button" class="button automatorwp-button-success automatorwp-add-trigger"><span class="dashicons dashicons-plus"></span><?php _e( 'Add Trigger', 'automatorwp' ); ?></button> | |
| 255 | + <?php // Add Filter ?> | |
| 256 | + <button type="button" class="button button-primary automatorwp-add-filter"><span class="dashicons dashicons-filter"></span><?php _e( 'Add Filter', 'automatorwp' ); ?></button> | |
| 257 | + <?php // Box spinner ?> | |
| 258 | + <div class="automatorwp-spinner automatorwp-box-spinner" style="display: none;"> | |
| 259 | + <span class="spinner is-active"></span> | |
| 260 | + <span class="spinner-label"><?php _e( 'Saving...', 'automatorwp' ); ?></span> | |
| 261 | + </div> | |
| 262 | + <?php | |
| 263 | +} | |
| 264 | + | |
| 265 | +/** | |
| 266 | + * Renders the actions meta box | |
| 267 | + * | |
| 268 | + * @since 1.0.0 | |
| 269 | + * | |
| 270 | + * @param stdClass $automation The automation object | |
| 271 | + * @param string $type Type to render form | |
| 272 | + */ | |
| 273 | +function automatorwp_automation_ui_actions_meta_box( $automation, $type ) { | |
| 274 | + | |
| 275 | + $actions = automatorwp_get_automation_actions( $automation->id ); | |
| 276 | + | |
| 277 | + ?> | |
| 278 | + <?php // Section title and subtitle ?> | |
| 279 | + <div class="automatorwp-title"><?php _e( 'Actions', 'automatorwp' ); ?></div> | |
| 280 | + <div class="automatorwp-subtitle"><?php _e( 'Do this...', 'automatorwp' ); ?></div> | |
| 281 | + | |
| 282 | + <?php // Actions ?> | |
| 283 | + <div class="automatorwp-automation-items automatorwp-actions"> | |
| 284 | + | |
| 285 | + <?php $actions = automatorwp_check_automation_required_actions( $automation, $actions ); ?> | |
| 286 | + | |
| 287 | + <?php foreach( $actions as $action ) : ?> | |
| 288 | + | |
| 289 | + <?php automatorwp_automation_item_edit_html( $action, 'action', $automation ); ?> | |
| 290 | + | |
| 291 | + <?php endforeach; ?> | |
| 292 | + | |
| 293 | + </div> | |
| 294 | + | |
| 295 | + <?php automatorwp_automation_ui_add_item_form( $automation, 'action' ); ?> | |
| 296 | + | |
| 297 | + <?php // Add Action ?> | |
| 298 | + <button type="button" class="button automatorwp-button-success automatorwp-add-action"><span class="dashicons dashicons-plus"></span><?php _e( 'Add Action', 'automatorwp' ); ?></button> | |
| 299 | + <?php // Add Filter ?> | |
| 300 | + <button type="button" class="button button-primary automatorwp-add-filter"><span class="dashicons dashicons-filter"></span><?php _e( 'Add Filter', 'automatorwp' ); ?></button> | |
| 301 | + <?php // Box spinner ?> | |
| 302 | + <div class="automatorwp-spinner automatorwp-box-spinner" style="display: none;"> | |
| 303 | + <span class="spinner is-active"></span> | |
| 304 | + <span class="spinner-label"><?php _e( 'Saving...', 'automatorwp' ); ?></span> | |
| 305 | + </div> | |
| 306 | + <?php | |
| 307 | +} | |
| 308 | + | |
| 309 | +/** | |
| 310 | + * Automation UI add item form | |
| 311 | + * | |
| 312 | + * @since 1.0.0 | |
| 313 | + * | |
| 314 | + * @param stdClass $automation The automation object | |
| 315 | + * @param string $item_type The item type (trigger|action) | |
| 316 | + */ | |
| 317 | +function automatorwp_automation_ui_add_item_form( $automation, $item_type ) { | |
| 318 | + | |
| 319 | + $choices_filters = array( | |
| 320 | + 'show_in_selector' => true, | |
| 321 | + ); | |
| 322 | + | |
| 323 | + if( $item_type === 'trigger' ) { | |
| 324 | + $choices_filters['anonymous'] = (bool) ( $automation->type === 'anonymous' ); | |
| 325 | + } | |
| 326 | + | |
| 327 | + // Sort integrations | |
| 328 | + $integrations = AutomatorWP()->integrations; | |
| 329 | + ksort( $integrations ); | |
| 330 | + | |
| 331 | + ?> | |
| 332 | + | |
| 333 | + <div class="automatorwp-add-item-form" style="display: none;"> | |
| 334 | + | |
| 335 | + <div class="automatorwp-automation-item-details"> | |
| 336 | + <div class="automatorwp-integration-icon"></div> | |
| 337 | + </div> | |
| 338 | + | |
| 339 | + <div class="automatorwp-automation-item-content"> | |
| 340 | + | |
| 341 | + <?php | |
| 342 | + /** | |
| 343 | + * Available action at top of the add item content | |
| 344 | + * | |
| 345 | + * @since 1.57 | |
| 346 | + * | |
| 347 | + * @param stdClass $automation The automation object | |
| 348 | + * @param string $item_type The item type | |
| 349 | + */ | |
| 350 | + do_action( 'automatorwp_automation_ui_add_item_content_top', $automation, $item_type ); ?> | |
| 351 | + | |
| 352 | + <div class="automatorwp-automation-item-actions"> | |
| 353 | + <div class="automatorwp-automation-item-action automatorwp-automation-item-action-close" title="<?php echo esc_attr( __( 'Close', 'automatorwp') ); ?>"><span class="dashicons dashicons-no-alt"></span></div> | |
| 354 | + </div> | |
| 355 | + | |
| 356 | + <div class="automatorwp-select-integration automatorwp-form"> | |
| 357 | + | |
| 358 | + <div class="automatorwp-select-integration-label"><?php _e( 'Select an integration', 'automatorwp' ); ?></div> | |
| 359 | + | |
| 360 | + <select class="automatorwp-all-integrations-choices"> | |
| 361 | + <option value=""><?php echo esc_html( $item_type === 'trigger' ? __( 'Search for triggers', 'automatorwp' ) : __( 'Search for actions', 'automatorwp' ) ); ?></option> | |
| 362 | + <?php foreach( $integrations as $integration => $args ) : ?> | |
| 363 | + | |
| 364 | + <?php // Skip filters | |
| 365 | + if( $integration === 'filter' ) continue; ?> | |
| 366 | + | |
| 367 | + <?php switch ( $item_type ) { | |
| 368 | + case 'trigger': | |
| 369 | + $choices = automatorwp_get_integration_triggers( $integration, $choices_filters ); | |
| 370 | + break; | |
| 371 | + case 'action': | |
| 372 | + $choices = automatorwp_get_integration_actions( $integration, $choices_filters ); | |
| 373 | + break; | |
| 374 | + default: | |
| 375 | + $choices = array(); | |
| 376 | + break; | |
| 377 | + } | |
| 378 | + | |
| 379 | + // Skip integrations without triggers or actions | |
| 380 | + if( ! empty( $choices ) ) : ?> | |
| 381 | + <optgroup label="<?php echo esc_attr( $args['label'] ); ?>" data-icon="<?php echo esc_attr( $args['icon'] ); ?>"> | |
| 382 | + | |
| 383 | + <?php foreach( $choices as $trigger => $args ) : | |
| 384 | + | |
| 385 | + if( empty( $args['select_option'] ) && empty( $args['label'] ) ) { | |
| 386 | + continue; | |
| 387 | + } ?> | |
| 388 | + <option value="<?php echo esc_attr( $trigger ); ?>" data-text="<?php echo esc_attr( $args['select_option'] ); ?>"><?php echo $args['label']; ?></option> | |
| 389 | + <?php endforeach; ?> | |
| 390 | + | |
| 391 | + </optgroup> | |
| 392 | + | |
| 393 | + <?php endif; ?> | |
| 394 | + | |
| 395 | + <?php endforeach; ?> | |
| 396 | + </select> | |
| 397 | + | |
| 398 | + <div class="automatorwp-integrations"> | |
| 399 | + | |
| 400 | + <?php foreach( $integrations as $integration => $args ) : ?> | |
| 401 | + | |
| 402 | + <?php // Skip filters | |
| 403 | + if( $integration === 'filter' ) continue; ?> | |
| 404 | + | |
| 405 | + <?php switch ( $item_type ) { | |
| 406 | + case 'trigger': | |
| 407 | + $choices = automatorwp_get_integration_triggers( $integration, $choices_filters ); | |
| 408 | + break; | |
| 409 | + case 'action': | |
| 410 | + $choices = automatorwp_get_integration_actions( $integration, $choices_filters ); | |
| 411 | + break; | |
| 412 | + default: | |
| 413 | + $choices = array(); | |
| 414 | + break; | |
| 415 | + } | |
| 416 | + | |
| 417 | + // Skip integrations without triggers or actions | |
| 418 | + if( ! empty( $choices ) ) : ?> | |
| 419 | + | |
| 420 | + <div class="automatorwp-integration" | |
| 421 | + data-integration="<?php echo esc_attr( $integration ); ?>" | |
| 422 | + data-label="<?php echo esc_attr( $args['label'] ); ?>" | |
| 423 | + data-icon="<?php echo esc_attr( $args['icon'] ); ?>"> | |
| 424 | + <div class="automatorwp-integration-icon"> | |
| 425 | + <img src="<?php echo esc_attr( $args['icon'] ); ?>" alt="<?php echo esc_attr( $args['label'] ); ?>"> | |
| 426 | + </div> | |
| 427 | + <div class="automatorwp-integration-label"><?php echo $args['label']; ?></div> | |
| 428 | + </div> | |
| 429 | + | |
| 430 | + <?php endif; ?> | |
| 431 | + | |
| 432 | + <?php | |
| 433 | + /** | |
| 434 | + * Available action to extend integration markup | |
| 435 | + * | |
| 436 | + * @since 1.0.0 | |
| 437 | + * | |
| 438 | + * @param string $integration The integration name | |
| 439 | + * @param array $integration_args Integration arguments | |
| 440 | + * @param stdClass $automation The automation object | |
| 441 | + * @param string $item_type The item type | |
| 442 | + */ | |
| 443 | + do_action( 'automatorwp_automation_ui_after_integration_choice', $integration, $args, $automation, $item_type ); ?> | |
| 444 | + | |
| 445 | + <?php endforeach; ?> | |
| 446 | + | |
| 447 | + </div> | |
| 448 | + | |
| 449 | + </div> | |
| 450 | + | |
| 451 | + <div class="automatorwp-integration-choices-container" style="display: none;"> | |
| 452 | + | |
| 453 | + <?php if ( $item_type === 'trigger' ) : ?> | |
| 454 | + | |
| 455 | + <div class="automatorwp-select-trigger-label"><?php _e( 'Select a trigger', 'automatorwp' ); ?></div> | |
| 456 | + | |
| 457 | + <?php foreach( $integrations as $integration => $args ) : ?> | |
| 458 | + | |
| 459 | + <?php // Skip filters | |
| 460 | + if( $integration === 'filter' ) continue; ?> | |
| 461 | + | |
| 462 | + <select class="automatorwp-integration-choices" | |
| 463 | + data-integration="<?php echo esc_attr( $integration ); ?>" | |
| 464 | + data-placeholder="<?php echo esc_attr( __( 'Search for triggers', 'automatorwp' ) ); ?>" | |
| 465 | + style="display: none;"> | |
| 466 | + | |
| 467 | + <option value=""></option> | |
| 468 | + <?php foreach( automatorwp_get_integration_triggers( $integration, $choices_filters ) as $trigger => $args ) : | |
| 469 | + | |
| 470 | + if( empty( $args['select_option'] ) && empty( $args['label'] ) ) { | |
| 471 | + continue; | |
| 472 | + } ?> | |
| 473 | + <option value="<?php echo esc_attr( $trigger ); ?>" data-text="<?php echo esc_attr( $args['select_option'] ); ?>"><?php echo $args['label']; ?></option> | |
| 474 | + <?php endforeach; ?> | |
| 475 | + | |
| 476 | + <?php | |
| 477 | + /** | |
| 478 | + * Available action to extend integration triggers choices | |
| 479 | + * | |
| 480 | + * @since 1.2.4 | |
| 481 | + * | |
| 482 | + * @param string $integration The integration name | |
| 483 | + * @param array $integration_args Integration arguments | |
| 484 | + * @param stdClass $automation The automation object | |
| 485 | + * @param string $item_type The item type | |
| 486 | + */ | |
| 487 | + do_action( 'automatorwp_automation_ui_after_integration_triggers_choices', $integration, $args, $automation, $item_type ); ?> | |
| 488 | + | |
| 489 | + </select> | |
| 490 | + | |
| 491 | + <?php endforeach; ?> | |
| 492 | + | |
| 493 | + <?php elseif ( $item_type === 'action' ) : ?> | |
| 494 | + | |
| 495 | + <div class="automatorwp-select-action-label"><?php _e( 'Select an action', 'automatorwp' ); ?></div> | |
| 496 | + | |
| 497 | + <?php foreach( $integrations as $integration => $args ) : ?> | |
| 498 | + | |
| 499 | + <select class="automatorwp-integration-choices" | |
| 500 | + data-integration="<?php echo esc_attr( $integration ); ?>" | |
| 501 | + data-placeholder="<?php echo esc_attr( __( 'Search for actions', 'automatorwp' ) ); ?>" | |
| 502 | + style="display: none;"> | |
| 503 | + | |
| 504 | + <option value=""></option> | |
| 505 | + <?php foreach( automatorwp_get_integration_actions( $integration, $choices_filters ) as $action => $args ) : | |
| 506 | + | |
| 507 | + if( empty( $args['select_option'] ) && empty( $args['label'] ) ) { | |
| 508 | + continue; | |
| 509 | + } ?> | |
| 510 | + <option value="<?php echo esc_attr( $action ); ?>" data-text="<?php echo esc_attr( $args['select_option'] ); ?>"><?php echo $args['label']; ?></option> | |
| 511 | + <?php endforeach; ?> | |
| 512 | + | |
| 513 | + <?php | |
| 514 | + /** | |
| 515 | + * Available action to extend integration actions choices | |
| 516 | + * | |
| 517 | + * @since 1.2.4 | |
| 518 | + * | |
| 519 | + * @param string $integration The integration name | |
| 520 | + * @param array $integration_args Integration arguments | |
| 521 | + * @param stdClass $automation The automation object | |
| 522 | + * @param string $item_type The item type | |
| 523 | + */ | |
| 524 | + do_action( 'automatorwp_automation_ui_after_integration_actions_choices', $integration, $args, $automation, $item_type ); ?> | |
| 525 | + | |
| 526 | + </select> | |
| 527 | + | |
| 528 | + <?php endforeach; ?> | |
| 529 | + | |
| 530 | + <?php endif; ?> | |
| 531 | + | |
| 532 | + <button type="button" class="button button-compact automatorwp-button-danger automatorwp-cancel-choice-select"><?php _e( 'Cancel', 'automatorwp' ); ?></button> | |
| 533 | + | |
| 534 | + </div> | |
| 535 | + | |
| 536 | + <?php | |
| 537 | + /** | |
| 538 | + * Available action at bottom of the add item content | |
| 539 | + * | |
| 540 | + * @since 1.57 | |
| 541 | + * | |
| 542 | + * @param stdClass $automation The automation object | |
| 543 | + * @param string $item_type The item type (trigger|action) | |
| 544 | + */ | |
| 545 | + do_action( 'automatorwp_automation_ui_add_item_content_bottom', $automation, $item_type ); ?> | |
| 546 | + | |
| 547 | + </div> | |
| 548 | + | |
| 549 | + </div> | |
| 550 | + | |
| 551 | + <?php | |
| 552 | + | |
| 553 | +} | |
| 554 | + | |
| 555 | +/** | |
| 556 | + * Get the object type args | |
| 557 | + * | |
| 558 | + * @since 1.0.0 | |
| 559 | + * | |
| 560 | + * @param stdClass $object The trigger/action object | |
| 561 | + * @param string $item_type The item type (trigger|action) | |
| 562 | + * | |
| 563 | + * @return array | |
| 564 | + */ | |
| 565 | +function automatorwp_automation_item_type_args( $object, $item_type ) { | |
| 566 | + | |
| 567 | + $type_args = array(); | |
| 568 | + | |
| 569 | + if( $item_type === 'trigger' ) { | |
| 570 | + $type_args = automatorwp_get_trigger( $object->type ); | |
| 571 | + } else if( $item_type === 'action' ) { | |
| 572 | + $type_args = automatorwp_get_action( $object->type ); | |
| 573 | + } | |
| 574 | + | |
| 575 | + /** | |
| 576 | + * Get the object type args | |
| 577 | + * | |
| 578 | + * @since 1.0.0 | |
| 579 | + * | |
| 580 | + * @param array $type_args The trigger/action args | |
| 581 | + * @param stdClass $object The trigger/action object | |
| 582 | + * @param string $item_type The item type (trigger|action) | |
| 583 | + * | |
| 584 | + * @return array | |
| 585 | + */ | |
| 586 | + return apply_filters( 'automatorwp_automation_item_type_args', $type_args, $object, $item_type ); | |
| 587 | + | |
| 588 | +} | |
| 589 | + | |
| 590 | +/** | |
| 591 | + * Renders the trigger/action edit HTML | |
| 592 | + * | |
| 593 | + * @since 1.0.0 | |
| 594 | + * | |
| 595 | + * @param stdClass $object The trigger/action object | |
| 596 | + * @param string $item_type The item type (trigger|action) | |
| 597 | + * @param stdClass $automation The automation object | |
| 598 | + */ | |
| 599 | +function automatorwp_automation_item_edit_html( $object, $item_type, $automation ) { | |
| 600 | + | |
| 601 | + global $automatorwp_triggers_current_position; | |
| 602 | + | |
| 603 | + // Check item type | |
| 604 | + if( ! in_array( $item_type, array( 'trigger', 'action' ) ) ) { | |
| 605 | + return; | |
| 606 | + } | |
| 607 | + | |
| 608 | + // Check type args | |
| 609 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 610 | + | |
| 611 | + if( ! $type_args ) { | |
| 612 | + automatorwp_automation_missing_integration_item_edit_html( $object, $item_type, $automation ); | |
| 613 | + return; | |
| 614 | + } | |
| 615 | + | |
| 616 | + // Check integration | |
| 617 | + $integration = automatorwp_get_integration( $type_args['integration'] ); | |
| 618 | + | |
| 619 | + if( ! $integration ) { | |
| 620 | + automatorwp_automation_missing_integration_item_edit_html( $object, $item_type, $automation ); | |
| 621 | + return; | |
| 622 | + } | |
| 623 | + | |
| 624 | + if( $item_type === 'action' && $object->type === 'automatorwp_anonymous_user' ) { | |
| 625 | + $integration['icon'] = AUTOMATORWP_URL . 'assets/img/automatorwp-anonymous.svg'; | |
| 626 | + } | |
| 627 | + | |
| 628 | + // Setup the item classes | |
| 629 | + $classes = array( | |
| 630 | + 'automatorwp-automation-item', | |
| 631 | + 'automatorwp-' . $item_type, | |
| 632 | + 'automatorwp-' . $item_type . '-' . str_replace( '_', '-', $object->type ), | |
| 633 | + ); | |
| 634 | + | |
| 635 | + if( $object->type === 'filter' ) { | |
| 636 | + $classes[] = 'automatorwp-automation-item-filter'; | |
| 637 | + } | |
| 638 | + | |
| 639 | + // Setup the item actions | |
| 640 | + $actions = array( | |
| 641 | + 'move-up' => array( | |
| 642 | + 'label' => __( 'Move up', 'automatorwp'), | |
| 643 | + 'icon' => 'arrow-up-alt2' | |
| 644 | + ), | |
| 645 | + 'move-down' => array( | |
| 646 | + 'label' => __( 'Move down', 'automatorwp'), | |
| 647 | + 'icon' => 'arrow-down-alt2' | |
| 648 | + ), | |
| 649 | + 'delete' => array( | |
| 650 | + 'label' => __( 'Delete', 'automatorwp'), | |
| 651 | + 'icon' => 'trash' | |
| 652 | + ), | |
| 653 | + ); | |
| 654 | + | |
| 655 | + // Anonymous | |
| 656 | + if( $automation->type === 'anonymous' ) { | |
| 657 | + if( $item_type === 'trigger' ) { | |
| 658 | + $classes[] = 'automatorwp-no-grab'; | |
| 659 | + unset( $actions['move-up'] ); | |
| 660 | + unset( $actions['move-down'] ); | |
| 661 | + } else if( $object->type === 'automatorwp_anonymous_user' ) { | |
| 662 | + $classes[] = 'automatorwp-no-grab'; | |
| 663 | + unset( $actions['move-up'] ); | |
| 664 | + unset( $actions['move-down'] ); | |
| 665 | + unset( $actions['delete'] ); | |
| 666 | + } | |
| 667 | + } | |
| 668 | + | |
| 669 | + /** | |
| 670 | + * Filter to modify the integration args of the trigger/action edit HTML | |
| 671 | + * | |
| 672 | + * @since 1.0.0 | |
| 673 | + * | |
| 674 | + * @param array $integration The integration args | |
| 675 | + * @param stdClass $object The trigger/action object | |
| 676 | + * @param string $item_type The item type (trigger|action) | |
| 677 | + * @param stdClass $automation The automation object | |
| 678 | + * | |
| 679 | + * @return array | |
| 680 | + */ | |
| 681 | + $integration = apply_filters( 'automatorwp_automation_item_edit_html_integration', $integration, $object, $item_type, $automation ); | |
| 682 | + | |
| 683 | + /** | |
| 684 | + * Filter to modify the CSS classes of the trigger/action edit HTML | |
| 685 | + * | |
| 686 | + * @since 1.3.0 | |
| 687 | + * | |
| 688 | + * @param array $classes The trigger/action CSS classes | |
| 689 | + * @param stdClass $object The trigger/action object | |
| 690 | + * @param string $item_type The item type (trigger|action) | |
| 691 | + * @param stdClass $automation The automation object | |
| 692 | + * | |
| 693 | + * @return array | |
| 694 | + */ | |
| 695 | + $classes = apply_filters( 'automatorwp_automations_ui_item_edit_html_classes', $classes, $object, $item_type, $automation ); | |
| 696 | + | |
| 697 | + /** | |
| 698 | + * Filter to modify the actions of the trigger/action edit HTML | |
| 699 | + * | |
| 700 | + * @since 1.3.0 | |
| 701 | + * | |
| 702 | + * @param array $actions The trigger/action actions | |
| 703 | + * @param stdClass $object The trigger/action object | |
| 704 | + * @param string $item_type The item type (trigger|action) | |
| 705 | + * @param stdClass $automation The automation object | |
| 706 | + * | |
| 707 | + * @return array | |
| 708 | + */ | |
| 709 | + $actions = apply_filters( 'automatorwp_automations_ui_item_edit_html_actions', $actions, $object, $item_type, $automation ); | |
| 710 | + | |
| 711 | + ?> | |
| 712 | + <div id="automatorwp-item-<?php echo esc_attr( $object->id ); ?>" class="<?php echo implode( ' ', $classes ); ?>"> | |
| 713 | + | |
| 714 | + <div class="automatorwp-automation-item-details"> | |
| 715 | + <div class="automatorwp-integration-icon"> | |
| 716 | + <img src="<?php echo esc_attr( $integration['icon'] ); ?>" title="<?php echo esc_attr( $integration['label'] ); ?>" alt="<?php echo esc_attr( $integration['label'] ); ?>"> | |
| 717 | + </div> | |
| 718 | + </div> | |
| 719 | + | |
| 720 | + <div class="automatorwp-automation-item-content"> | |
| 721 | + | |
| 722 | + <?php if( ! empty( $actions ) ) : ?> | |
| 723 | + <div class="automatorwp-automation-item-actions"> | |
| 724 | + <?php foreach( $actions as $action => $action_args ) : ?> | |
| 725 | + <div class="automatorwp-automation-item-action automatorwp-automation-item-action-<?php echo $action; ?> cmb-tooltip"> | |
| 726 | + <span class="dashicons dashicons-<?php echo $action_args['icon']; ?>"></span> | |
| 727 | + <span class="cmb-tooltip-desc cmb-tooltip-top"><?php echo esc_html( $action_args['label'] ); ?></span> | |
| 728 | + </div> | |
| 729 | + <?php endforeach; ?> | |
| 730 | + | |
| 731 | + </div> | |
| 732 | + <?php endif; ?> | |
| 733 | + | |
| 734 | + <div class="automatorwp-integration-label"><?php echo $integration['label']; ?></div> | |
| 735 | + | |
| 736 | + <?php | |
| 737 | + | |
| 738 | + $position = ( is_int( $automatorwp_triggers_current_position ) ? $automatorwp_triggers_current_position + 1 : $object->position + 1 ); | |
| 739 | + | |
| 740 | + if( $object->type !== 'filter' && is_int( $automatorwp_triggers_current_position ) ) { | |
| 741 | + $automatorwp_triggers_current_position++; | |
| 742 | + } | |
| 743 | + | |
| 744 | + ?> | |
| 745 | + | |
| 746 | + <div class="automatorwp-automation-item-position" style="<?php echo ( $automation->sequential ? '' : 'display: none;' ); ?>"><?php echo $position; ?>.</div> | |
| 747 | + <div class="automatorwp-automation-item-label"><?php echo automatorwp_parse_automation_item_edit_label( $object, $item_type ); ?></div> | |
| 748 | + | |
| 749 | + <?php | |
| 750 | + /** | |
| 751 | + * After item label | |
| 752 | + * | |
| 753 | + * @since 1.0.0 | |
| 754 | + * | |
| 755 | + * @param stdClass $object The trigger/action object | |
| 756 | + * @param string $item_type The object type (trigger|action) | |
| 757 | + */ | |
| 758 | + do_action( 'automatorwp_automation_ui_after_item_label', $object, $item_type ); ?> | |
| 759 | + | |
| 760 | + <?php // Render the options form ?> | |
| 761 | + <?php foreach( $type_args['options'] as $option => $args ) : ?> | |
| 762 | + | |
| 763 | + <div class="automatorwp-option-form-container" data-option="<?php echo esc_attr( $option ); ?>" data-from="<?php echo esc_attr( ( isset( $args['from'] ) ? $args['from'] : '' ) ); ?>" style="display: none;"> | |
| 764 | + | |
| 765 | + <?php | |
| 766 | + /** | |
| 767 | + * After option from | |
| 768 | + * | |
| 769 | + * @since 1.0.0 | |
| 770 | + * | |
| 771 | + * @param stdClass $object The trigger/action object | |
| 772 | + * @param string $item_type The object type (trigger|action) | |
| 773 | + * @param string $option The option key | |
| 774 | + * @param array $args The option arguments | |
| 775 | + */ | |
| 776 | + do_action( 'automatorwp_automation_ui_after_option_form', $object, $item_type, $option, $args ); ?> | |
| 777 | + | |
| 778 | + <?php | |
| 779 | + // Get the option form | |
| 780 | + $cmb2 = automatorwp_get_automation_item_option_form( $object, $item_type, $option, $automation ); | |
| 781 | + | |
| 782 | + if( $cmb2 ) { | |
| 783 | + | |
| 784 | + ct_setup_table( "automatorwp_{$item_type}s" ); | |
| 785 | + | |
| 786 | + // Render the form | |
| 787 | + CMB2_Hookup::enqueue_cmb_css(); | |
| 788 | + CMB2_Hookup::enqueue_cmb_js(); | |
| 789 | + $cmb2->show_form(); | |
| 790 | + | |
| 791 | + ct_reset_setup_table(); | |
| 792 | + } | |
| 793 | + ?> | |
| 794 | + | |
| 795 | + <?php | |
| 796 | + /** | |
| 797 | + * Before option from | |
| 798 | + * | |
| 799 | + * @since 1.0.0 | |
| 800 | + * | |
| 801 | + * @param stdClass $object The trigger/action object | |
| 802 | + * @param string $item_type The object type (trigger|action) | |
| 803 | + * @param string $option The option key | |
| 804 | + * @param array $args The option arguments | |
| 805 | + */ | |
| 806 | + do_action( 'automatorwp_automation_ui_before_option_form', $object, $item_type, $option, $args ); ?> | |
| 807 | + | |
| 808 | + <button type="button" class="button button-compact button-primary automatorwp-save-option-form"><?php _e( 'Save', 'automatorwp' ); ?></button> | |
| 809 | + <button type="button" class="button button-compact automatorwp-button-danger automatorwp-cancel-option-form"><?php _e( 'Cancel', 'automatorwp' ); ?></button> | |
| 810 | + | |
| 811 | + <div class="automatorwp-spinner" style="display: none;"> | |
| 812 | + <span class="spinner is-active"></span> | |
| 813 | + <span class="spinner-label"><?php _e( 'Saving...', 'automatorwp' ); ?></span> | |
| 814 | + </div> | |
| 815 | + | |
| 816 | + </div> | |
| 817 | + | |
| 818 | + <?php endforeach; ?> | |
| 819 | + | |
| 820 | + </div> | |
| 821 | + | |
| 822 | + <?php // Hidden fields ?> | |
| 823 | + <input type="hidden" class="id" value="<?php echo esc_attr( $object->id ); ?>"/> | |
| 824 | + <input type="hidden" class="type" value="<?php echo esc_attr( $object->type ); ?>"/> | |
| 825 | + <input type="hidden" class="status" value="<?php echo esc_attr( $object->status ); ?>"/> | |
| 826 | + <input type="hidden" class="position" value="<?php echo esc_attr( $object->position ); ?>"/> | |
| 827 | + | |
| 828 | + </div> | |
| 829 | + <?php | |
| 830 | + | |
| 831 | +} | |
| 832 | + | |
| 833 | +/** | |
| 834 | + * Creates if the required triggers exists | |
| 835 | + * | |
| 836 | + * @since 2.2.2 | |
| 837 | + * | |
| 838 | + * @param stdClass $automation The automation object | |
| 839 | + * @param array $triggers The automation triggers | |
| 840 | + * | |
| 841 | + * @return array | |
| 842 | + */ | |
| 843 | +function automatorwp_check_automation_required_triggers( $automation, $triggers ) { | |
| 844 | + | |
| 845 | + return apply_filters( 'automatorwp_check_automation_required_triggers', $triggers, $automation ); | |
| 846 | + | |
| 847 | +} | |
| 848 | + | |
| 849 | +/** | |
| 850 | + * Creates if the required actions exists | |
| 851 | + * | |
| 852 | + * @since 1.3.0 | |
| 853 | + * | |
| 854 | + * @param stdClass $automation The automation object | |
| 855 | + * @param array $actions The automation actions | |
| 856 | + * | |
| 857 | + * @return array | |
| 858 | + */ | |
| 859 | +function automatorwp_check_automation_required_actions( $automation, $actions ) { | |
| 860 | + | |
| 861 | + if( $automation->type === 'anonymous' ) { | |
| 862 | + | |
| 863 | + $create = false; | |
| 864 | + | |
| 865 | + // Check if the first action is the action required for anonymous automations | |
| 866 | + if( ! isset( $actions[0] ) ) { | |
| 867 | + $create = true; | |
| 868 | + } | |
| 869 | + | |
| 870 | + if( isset( $actions[0] ) && $actions[0]->type !== 'automatorwp_anonymous_user' ) { | |
| 871 | + $create = true; | |
| 872 | + } | |
| 873 | + | |
| 874 | + if( $create ) { | |
| 875 | + ct_setup_table( 'automatorwp_actions' ); | |
| 876 | + | |
| 877 | + $action_data = array( | |
| 878 | + 'automation_id' => $automation->id, | |
| 879 | + 'title' => sprintf( __( 'Actions will be run on %1$s', 'automatorwp' ), '{user}' ), | |
| 880 | + 'type' => 'automatorwp_anonymous_user', | |
| 881 | + 'status' => 'active', | |
| 882 | + 'position' => '0', | |
| 883 | + 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), | |
| 884 | + ); | |
| 885 | + | |
| 886 | + // Insert the new action | |
| 887 | + $action_id = ct_insert_object( $action_data ); | |
| 888 | + | |
| 889 | + if( $action_id ) { | |
| 890 | + $action_data['id'] = $action_id; | |
| 891 | + | |
| 892 | + $action_data = (object) $action_data; | |
| 893 | + | |
| 894 | + // Prepend the new action at start of the actions list | |
| 895 | + array_unshift( $actions, $action_data ); | |
| 896 | + } | |
| 897 | + | |
| 898 | + ct_reset_setup_table(); | |
| 899 | + } | |
| 900 | + | |
| 901 | + } | |
| 902 | + | |
| 903 | + return apply_filters( 'automatorwp_check_automation_required_actions', $actions, $automation ); | |
| 904 | + | |
| 905 | +} | |
| 906 | + | |
| 907 | +/** | |
| 908 | + * Renders the trigger/action missing integration edit HTML | |
| 909 | + * | |
| 910 | + * @since 1.1.2 | |
| 911 | + * | |
| 912 | + * @param stdClass $object The trigger/action object | |
| 913 | + * @param string $item_type The item type (trigger|action) | |
| 914 | + * @param stdClass $automation The automation object | |
| 915 | + */ | |
| 916 | +function automatorwp_automation_missing_integration_item_edit_html( $object, $item_type, $automation ) { | |
| 917 | + | |
| 918 | + if( $item_type === 'trigger' ) { | |
| 919 | + $warning_message = __( 'Trigger disabled because plugin associated couldn\'t be found. Please, re-install the plugin associated or remove this trigger.', 'automatorwp' ); | |
| 920 | + } else { | |
| 921 | + $warning_message = __( 'Action disabled because plugin associated couldn\'t be found. Please, re-install the plugin associated or remove this action.', 'automatorwp' ); | |
| 922 | + | |
| 923 | + } | |
| 924 | + | |
| 925 | + ?> | |
| 926 | + <div id="automatorwp-item-<?php echo esc_attr( $object->id ); ?>" class="automatorwp-automation-item automatorwp-automation-missing-integration-item automatorwp-<?php echo esc_attr( $item_type ); ?>"> | |
| 927 | + | |
| 928 | + <div class="automatorwp-automation-item-details"> | |
| 929 | + <div class="automatorwp-integration-icon"> | |
| 930 | + <img src="<?php echo esc_attr( AUTOMATORWP_URL . 'assets/img/integration-missing.svg' ); ?>" title="<?php echo esc_attr( __( 'Missing plugin', 'automatorwp' ) ); ?>"> | |
| 931 | + </div> | |
| 932 | + </div> | |
| 933 | + | |
| 934 | + <div class="automatorwp-automation-item-content"> | |
| 935 | + | |
| 936 | + <div class="automatorwp-automation-item-actions"> | |
| 937 | + <div class="automatorwp-automation-item-action automatorwp-automation-item-action-delete" title="<?php echo esc_attr( __( 'Delete', 'automatorwp') ); ?>"><span class="dashicons dashicons-trash"></span></div> | |
| 938 | + </div> | |
| 939 | + | |
| 940 | + <div class="automatorwp-integration-label"><?php echo __( 'Missing plugin', 'automatorwp' ); ?></div> | |
| 941 | + | |
| 942 | + <div class="automatorwp-automation-item-position" style="<?php echo ( $automation->sequential ? '' : 'display: none;' ); ?>"><?php echo $object->position + 1; ?>.</div> | |
| 943 | + <div class="automatorwp-automation-item-label"><?php echo $object->title; ?></div> | |
| 944 | + | |
| 945 | + <div class="automatorwp-notice-warning"><?php echo $warning_message; ?></div> | |
| 946 | + | |
| 947 | + <?php | |
| 948 | + /** | |
| 949 | + * After missing integration item label | |
| 950 | + * | |
| 951 | + * @since 1.1.2 | |
| 952 | + * | |
| 953 | + * @param stdClass $object The trigger/action object | |
| 954 | + * @param string $item_type The object type (trigger|action) | |
| 955 | + */ | |
| 956 | + do_action( 'automatorwp_automation_ui_after_missing_integration_item_label', $object, $item_type ); ?> | |
| 957 | + | |
| 958 | + </div> | |
| 959 | + | |
| 960 | + <?php // Hidden fields ?> | |
| 961 | + <input type="hidden" class="id" value="<?php echo esc_attr( $object->id ); ?>"/> | |
| 962 | + <input type="hidden" class="type" value="<?php echo esc_attr( $object->type ); ?>"/> | |
| 963 | + <input type="hidden" class="status" value="<?php echo esc_attr( $object->status ); ?>"/> | |
| 964 | + <input type="hidden" class="position" value="<?php echo esc_attr( $object->position ); ?>"/> | |
| 965 | + | |
| 966 | + </div> | |
| 967 | + <?php | |
| 968 | + | |
| 969 | +} | |
| 970 | + | |
| 971 | +/** | |
| 972 | + * Parses the trigger/action edit label | |
| 973 | + * | |
| 974 | + * @since 1.0.0 | |
| 975 | + * | |
| 976 | + * @param stdClass $object The trigger object | |
| 977 | + * @param string $item_type The item type (trigger|action) | |
| 978 | + * @param string $context The context this function is executed | |
| 979 | + * | |
| 980 | + * @return string | |
| 981 | + */ | |
| 982 | +function automatorwp_parse_automation_item_edit_label( $object, $item_type, $context = 'edit' ) { | |
| 983 | + | |
| 984 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 985 | + | |
| 986 | + if( ! $type_args ) { | |
| 987 | + return ''; | |
| 988 | + } | |
| 989 | + | |
| 990 | + /** | |
| 991 | + * Filter to dynamically change the edit label | |
| 992 | + * | |
| 993 | + * @since 1.0.0 | |
| 994 | + * | |
| 995 | + * @param string $label The edit label | |
| 996 | + * @param stdClass $object The trigger/action object | |
| 997 | + * @param string $item_type The item type (trigger|action) | |
| 998 | + * @param string $context The context this function is executed | |
| 999 | + * @param array $type_args The type parameters | |
| 1000 | + * | |
| 1001 | + * @return string | |
| 1002 | + */ | |
| 1003 | + $label = apply_filters( 'automatorwp_parse_automation_item_edit_label', $type_args['edit_label'], $object, $item_type, $context, $type_args ); | |
| 1004 | + | |
| 1005 | + return automatorwp_parse_automation_item_label( $object, $item_type, $label, $context ); | |
| 1006 | + | |
| 1007 | +} | |
| 1008 | + | |
| 1009 | +/** | |
| 1010 | + * Parses the trigger/action log label | |
| 1011 | + * | |
| 1012 | + * @since 1.0.0 | |
| 1013 | + * | |
| 1014 | + * @param stdClass $object The trigger/action object | |
| 1015 | + * @param string $item_type The item type (trigger|action) | |
| 1016 | + * @param string $context The context this function is executed | |
| 1017 | + * | |
| 1018 | + * @return string | |
| 1019 | + */ | |
| 1020 | +function automatorwp_parse_automation_item_log_label( $object, $item_type, $context = 'edit' ) { | |
| 1021 | + | |
| 1022 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 1023 | + | |
| 1024 | + if( ! $type_args ) { | |
| 1025 | + return ''; | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + /** | |
| 1029 | + * Filter to dynamically change the log label | |
| 1030 | + * | |
| 1031 | + * @since 1.0.0 | |
| 1032 | + * | |
| 1033 | + * @param string $label The edit label | |
| 1034 | + * @param stdClass $object The trigger/action object | |
| 1035 | + * @param string $item_type The item type (trigger|action) | |
| 1036 | + * @param string $context The context this function is executed | |
| 1037 | + * @param array $type_args The type parameters | |
| 1038 | + * | |
| 1039 | + * @return string | |
| 1040 | + */ | |
| 1041 | + $label = apply_filters( 'automatorwp_parse_automation_item_log_label', $type_args['log_label'], $object, $item_type, $context, $type_args ); | |
| 1042 | + | |
| 1043 | + return automatorwp_parse_automation_item_label( $object, $item_type, $label, $context ); | |
| 1044 | + | |
| 1045 | +} | |
| 1046 | + | |
| 1047 | +/** | |
| 1048 | + * Parses the trigger/action label given | |
| 1049 | + * | |
| 1050 | + * @since 1.0.0 | |
| 1051 | + * | |
| 1052 | + * @param stdClass $object The trigger object | |
| 1053 | + * @param string $item_type The item type (trigger|action) | |
| 1054 | + * @param string $label The label to parse | |
| 1055 | + * @param string $context The context this function is executed | |
| 1056 | + * | |
| 1057 | + * @return string | |
| 1058 | + */ | |
| 1059 | +function automatorwp_parse_automation_item_label( $object, $item_type, $label, $context = 'edit' ) { | |
| 1060 | + | |
| 1061 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 1062 | + | |
| 1063 | + if( ! $type_args ) { | |
| 1064 | + return ''; | |
| 1065 | + } | |
| 1066 | + | |
| 1067 | + $replacements = array(); | |
| 1068 | + | |
| 1069 | + foreach( $type_args['options'] as $option => $args ) { | |
| 1070 | + $replacements['{' . $option . '}'] = automatorwp_get_automation_item_option_replacement( $object, $item_type, $option, $context ); | |
| 1071 | + } | |
| 1072 | + | |
| 1073 | + /** | |
| 1074 | + * Trigger/action label replacements | |
| 1075 | + * | |
| 1076 | + * @since 1.0.0 | |
| 1077 | + * | |
| 1078 | + * @param array $replacements The replacements to apply | |
| 1079 | + * @param stdClass $object The trigger object | |
| 1080 | + * @param string $item_type The item type (trigger|action) | |
| 1081 | + * @param string $label The label to parse | |
| 1082 | + * @param string $context The context this function is executed | |
| 1083 | + * | |
| 1084 | + * @return array | |
| 1085 | + */ | |
| 1086 | + $replacements = apply_filters( 'automatorwp_parse_automation_item_label_replacements', $replacements, $object, $item_type, $label, $context ); | |
| 1087 | + | |
| 1088 | + $tags = array_keys( $replacements ); | |
| 1089 | + | |
| 1090 | + $label_parsed = str_replace( $tags, $replacements, $label ); | |
| 1091 | + | |
| 1092 | + /** | |
| 1093 | + * Trigger/action label parsed | |
| 1094 | + * | |
| 1095 | + * @since 1.0.0 | |
| 1096 | + * | |
| 1097 | + * @param string $label_parsed The label parsed | |
| 1098 | + * @param stdClass $object The trigger object | |
| 1099 | + * @param string $item_type The item type (trigger|action) | |
| 1100 | + * @param string $label The originallabel to parse | |
| 1101 | + * @param string $context The context this function is executed | |
| 1102 | + * @param array $tags The tags applied | |
| 1103 | + * @param array $replacements The replacements applied | |
| 1104 | + * | |
| 1105 | + * @return string | |
| 1106 | + */ | |
| 1107 | + return apply_filters( 'automatorwp_parse_automation_item_label', $label_parsed, $object, $item_type, $label, $context, $tags, $replacements ); | |
| 1108 | + | |
| 1109 | +} | |
| 1110 | + | |
| 1111 | +/** | |
| 1112 | + * Get the option replacement | |
| 1113 | + * | |
| 1114 | + * @since 1.0.0 | |
| 1115 | + * | |
| 1116 | + * @param stdClass $object The trigger/action object | |
| 1117 | + * @param string $item_type The item type (trigger|action) | |
| 1118 | + * @param string $option The option name | |
| 1119 | + * @param string $context The context this function is executed | |
| 1120 | + * | |
| 1121 | + * @return string | |
| 1122 | + */ | |
| 1123 | +function automatorwp_get_automation_item_option_replacement( $object, $item_type, $option, $context = 'edit' ) { | |
| 1124 | + | |
| 1125 | + global $automatorwp_event; | |
| 1126 | + | |
| 1127 | + // Check item type | |
| 1128 | + if( ! in_array( $item_type, array( 'trigger', 'action' ) ) ) { | |
| 1129 | + return false; | |
| 1130 | + } | |
| 1131 | + | |
| 1132 | + // Check type args | |
| 1133 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 1134 | + | |
| 1135 | + if( ! $type_args ) { | |
| 1136 | + return ''; | |
| 1137 | + } | |
| 1138 | + | |
| 1139 | + // Bail if this type hasn't any option | |
| 1140 | + if( ! isset( $type_args['options'][$option] ) ) { | |
| 1141 | + return ''; | |
| 1142 | + } | |
| 1143 | + | |
| 1144 | + $option_args = $type_args['options'][$option]; | |
| 1145 | + | |
| 1146 | + $field_id = ( isset( $option_args['from'] ) ? $option_args['from'] : '' ); | |
| 1147 | + $value = ''; | |
| 1148 | + | |
| 1149 | + // If not isset the from field, try to get a default value | |
| 1150 | + if( ! isset( $option_args['fields'][$field_id] ) ) { | |
| 1151 | + | |
| 1152 | + if( isset( $option_args['default'] ) && ! empty( $option_args['default'] ) ) { | |
| 1153 | + $value = $option_args['default']; | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + } else { | |
| 1157 | + | |
| 1158 | + ct_setup_table( "automatorwp_{$item_type}s" ); | |
| 1159 | + | |
| 1160 | + $field = $option_args['fields'][$field_id]; | |
| 1161 | + $value = ct_get_object_meta( $object->id, $field_id, true ); | |
| 1162 | + | |
| 1163 | + if( ( $value === '' || is_null( $value ) ) && isset( $field['default'] ) ) { | |
| 1164 | + $value = $field['default']; | |
| 1165 | + } | |
| 1166 | + | |
| 1167 | + // Ensure the field value and escaped_value keys | |
| 1168 | + $field['object_id'] = $object->id; | |
| 1169 | + $field['value'] = $value; | |
| 1170 | + $field['escaped_value'] = $value; | |
| 1171 | + | |
| 1172 | + // Select field | |
| 1173 | + if( in_array( $field['type'], array( 'select', 'automatorwp_select', 'automatorwp_select_filter' ) ) ) { | |
| 1174 | + | |
| 1175 | + // Get the field options | |
| 1176 | + $field_options = automatorwp_get_field_options( $field ); | |
| 1177 | + | |
| 1178 | + // Try to get the displayed value | |
| 1179 | + $found = automatorwp_get_array_key_value( $value, $field_options ); | |
| 1180 | + | |
| 1181 | + if( $found ) { | |
| 1182 | + $value = $found; | |
| 1183 | + } | |
| 1184 | + } | |
| 1185 | + | |
| 1186 | + // Array values | |
| 1187 | + if( is_array( $value ) ) { | |
| 1188 | + | |
| 1189 | + // Get the field options | |
| 1190 | + $field_options = automatorwp_get_field_options( $field ); | |
| 1191 | + | |
| 1192 | + // Replace values by the options label | |
| 1193 | + if( count( $field_options ) ) { | |
| 1194 | + foreach( $value as $i => $v ) { | |
| 1195 | + // Try to get the displayed value | |
| 1196 | + $found = automatorwp_get_array_key_value( $v, $field_options ); | |
| 1197 | + | |
| 1198 | + if( isset( $found ) ) { | |
| 1199 | + $value[$i] = $found; | |
| 1200 | + } | |
| 1201 | + } | |
| 1202 | + } | |
| 1203 | + | |
| 1204 | + /* translators: The ampersand character who represents the word "and" */ | |
| 1205 | + $and = __( '&', 'automatorwp' ); | |
| 1206 | + $value = automatorwp_implode_array( ', ', " {$and} ", $value ); | |
| 1207 | + } | |
| 1208 | + | |
| 1209 | + // Fallback to default option if exists | |
| 1210 | + if( ( $value === '' || is_null( $value ) ) && isset( $option_args['default'] ) && ! empty( $option_args['default'] ) ) { | |
| 1211 | + $value = $option_args['default']; | |
| 1212 | + } | |
| 1213 | + | |
| 1214 | + ct_reset_setup_table(); | |
| 1215 | + | |
| 1216 | + } | |
| 1217 | + | |
| 1218 | + /** | |
| 1219 | + * Filters the option value for replacement on labels | |
| 1220 | + * | |
| 1221 | + * @since 1.0.0 | |
| 1222 | + * | |
| 1223 | + * @param string $value The option value | |
| 1224 | + * @param stdClass $object The trigger/action object | |
| 1225 | + * @param string $item_type The item type (trigger|action) | |
| 1226 | + * @param string $option The option name | |
| 1227 | + * @param string $context The context this function is executed | |
| 1228 | + * | |
| 1229 | + * @return string | |
| 1230 | + */ | |
| 1231 | + $value = apply_filters( 'automatorwp_get_automation_item_option_replacement', $value, $object, $item_type, $option, $context ); | |
| 1232 | + | |
| 1233 | + if( $context === 'edit' ) { | |
| 1234 | + | |
| 1235 | + $option_class = 'button button-compact button-primary'; | |
| 1236 | + | |
| 1237 | + if( $object->type === 'filter' ) { | |
| 1238 | + $option_class = 'button button-compact'; | |
| 1239 | + } | |
| 1240 | + | |
| 1241 | + /** | |
| 1242 | + * Filters the option button class | |
| 1243 | + * | |
| 1244 | + * @since 1.2.4 | |
| 1245 | + * | |
| 1246 | + * @param string $option_class The option class | |
| 1247 | + * @param stdClass $object The trigger/action object | |
| 1248 | + * @param string $item_type The item type (trigger|action) | |
| 1249 | + * @param string $option The option name | |
| 1250 | + * @param string $context The context this function is executed | |
| 1251 | + * | |
| 1252 | + * @return string | |
| 1253 | + */ | |
| 1254 | + $option_class = apply_filters( 'automatorwp_get_automation_item_option_button_class', $option_class, $object, $item_type, $option, $context ); | |
| 1255 | + | |
| 1256 | + $value = '<span class="' . esc_attr__( $option_class ) . ' automatorwp-option" data-option="' . $option . '">' . $value . '</span>'; | |
| 1257 | + } else if( $context === 'view' ) { | |
| 1258 | + | |
| 1259 | + $automation = automatorwp_get_trigger_automation( $object->id ); | |
| 1260 | + | |
| 1261 | + if( is_object( $automation ) ) { | |
| 1262 | + | |
| 1263 | + $user_id = ( isset( $automatorwp_event['user_id'] ) ? $automatorwp_event['user_id'] : 0 ); | |
| 1264 | + | |
| 1265 | + $value = automatorwp_parse_automation_tags( $automation->id, $user_id, $value ); | |
| 1266 | + } | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + } | |
| 1270 | + | |
| 1271 | + return $value; | |
| 1272 | + | |
| 1273 | +} | |
| 1274 | + | |
| 1275 | +/** | |
| 1276 | + * Gets a CMB2 object from a trigger/action option | |
| 1277 | + * | |
| 1278 | + * @since 1.0.0 | |
| 1279 | + * | |
| 1280 | + * @param stdClass $object The trigger/action object | |
| 1281 | + * @param string $item_type The item type (trigger|action) | |
| 1282 | + * @param string $option Option form to render | |
| 1283 | + * @param stdClass $automation The automation object | |
| 1284 | + * | |
| 1285 | + * @return CMB2|false | |
| 1286 | + */ | |
| 1287 | +function automatorwp_get_automation_item_option_form( $object, $item_type, $option, $automation ) { | |
| 1288 | + | |
| 1289 | + // Check item type | |
| 1290 | + if( ! in_array( $item_type, array( 'trigger', 'action' ) ) ) { | |
| 1291 | + return false; | |
| 1292 | + } | |
| 1293 | + | |
| 1294 | + // Check type args | |
| 1295 | + $type_args = automatorwp_automation_item_type_args( $object, $item_type ); | |
| 1296 | + | |
| 1297 | + if( ! $type_args ) { | |
| 1298 | + return false; | |
| 1299 | + } | |
| 1300 | + | |
| 1301 | + // Bail if this type hasn't any option | |
| 1302 | + if( ! isset( $type_args['options'][$option] ) ) { | |
| 1303 | + return false; | |
| 1304 | + } | |
| 1305 | + | |
| 1306 | + $args = $type_args['options'][$option]; | |
| 1307 | + | |
| 1308 | + /** | |
| 1309 | + * Filter to override the trigger/action option fields | |
| 1310 | + * | |
| 1311 | + * @since 1.0.0 | |
| 1312 | + * | |
| 1313 | + * @param array $fields The option fields | |
| 1314 | + * @param stdClass $object The trigger/action object | |
| 1315 | + * @param string $item_type The item type (trigger|action) | |
| 1316 | + * @param string $option Option form to render | |
| 1317 | + * @param stdClass $automation The automation object | |
| 1318 | + * | |
| 1319 | + * @return array | |
| 1320 | + */ | |
| 1321 | + $fields = apply_filters( 'automatorwp_get_automation_item_option_form_fields', $args['fields'], $object, $item_type, $option, $automation ); | |
| 1322 | + | |
| 1323 | + ct_setup_table( "automatorwp_{$item_type}s" ); | |
| 1324 | + | |
| 1325 | + // Setup the CMB2 form | |
| 1326 | + $cmb2 = new CMB2( array( | |
| 1327 | + 'id' => $option .'_form', | |
| 1328 | + 'object_types' => array( 'automatorwp_triggers', 'automatorwp_actions' ), | |
| 1329 | + 'classes' => 'automatorwp-form automatorwp-option-form', | |
| 1330 | + 'hookup' => false, | |
| 1331 | + ), $object->id ); | |
| 1332 | + | |
| 1333 | + // Setup the options fields | |
| 1334 | + foreach ( $fields as $field_id => $field ) { | |
| 1335 | + | |
| 1336 | + $field['id'] = $field_id; | |
| 1337 | + | |
| 1338 | + if( $field['type'] === 'group' ) { | |
| 1339 | + // Group fields | |
| 1340 | + | |
| 1341 | + // Setup field arguments on each group field | |
| 1342 | + foreach ( $field['fields'] as $field_group_id => $field_group ) { | |
| 1343 | + | |
| 1344 | + $field_group['id'] = $field_group_id; | |
| 1345 | + | |
| 1346 | + $field['fields'][$field_group_id] = automatorwp_automation_item_option_field_args( $object, $item_type, $option, $automation, $field_id . '[' .$field_group_id . ']', $field_group ); | |
| 1347 | + | |
| 1348 | + } | |
| 1349 | + | |
| 1350 | + } else { | |
| 1351 | + // Single fields | |
| 1352 | + | |
| 1353 | + $field = automatorwp_automation_item_option_field_args( $object, $item_type, $option, $automation, $field_id, $field ); | |
| 1354 | + | |
| 1355 | + } | |
| 1356 | + | |
| 1357 | + // Add the field to the form | |
| 1358 | + $cmb2->add_field( $field ); | |
| 1359 | + | |
| 1360 | + } | |
| 1361 | + | |
| 1362 | + ct_reset_setup_table(); | |
| 1363 | + | |
| 1364 | + return $cmb2; | |
| 1365 | + | |
| 1366 | +} | |
| 1367 | + | |
| 1368 | +/** | |
| 1369 | + * Gets a CMB2 object from a trigger option | |
| 1370 | + * | |
| 1371 | + * @since 1.0.0 | |
| 1372 | + * | |
| 1373 | + * @param stdClass $object The trigger/action object | |
| 1374 | + * @param string $item_type The item type (trigger|action) | |
| 1375 | + * @param string $option Option form to render | |
| 1376 | + * @param stdClass $automation The automation object | |
| 1377 | + * @param string $field_id The field ID | |
| 1378 | + * @param array $field The field parameters | |
| 1379 | + * | |
| 1380 | + * @return array | |
| 1381 | + */ | |
| 1382 | +function automatorwp_automation_item_option_field_args( $object, $item_type, $option, $automation, $field_id, $field ) { | |
| 1383 | + | |
| 1384 | + $repeatable = ( isset( $field['repeatable'] ) && $field['repeatable'] === true ); | |
| 1385 | + | |
| 1386 | + // Prevent to render field names to avoid conflicts on the main form | |
| 1387 | + $field['attributes']['name'] = ''; | |
| 1388 | + | |
| 1389 | + // Update id attribute to avoid id collisions | |
| 1390 | + $field['attributes']['id'] = $field_id . '-' . $object->id; | |
| 1391 | + $field['attributes']['data-option'] = $field_id . ( $repeatable ? '[]' : '' ); | |
| 1392 | + | |
| 1393 | + // Setup the fields tags selector | |
| 1394 | + | |
| 1395 | + // Set a specific sanitization callback for fields that support HTML and URLs | |
| 1396 | + if( in_array( $field['type'], array( 'textarea', 'wysiwyg', 'oembed', 'file' ) ) ) { | |
| 1397 | + $field['sanitization_cb'] = 'automatorwp_textarea_sanitization_cb'; | |
| 1398 | + } | |
| 1399 | + | |
| 1400 | + // Check if field type is compatible with tags selector | |
| 1401 | + if( in_array( $field['type'], array( 'text', 'textarea', 'wysiwyg', 'file' ) ) ) { | |
| 1402 | + $field['after_field'] = automatorwp_get_tags_selector_html( $automation, $object, $item_type ); | |
| 1403 | + } | |
| 1404 | + | |
| 1405 | + // If field is required, update its label with the required mark | |
| 1406 | + if( isset( $field['required'] ) && $field['required'] && isset( $field['name'] ) ) { | |
| 1407 | + $field['name'] .= '<span class="automatorwp-field-required">*</span>'; | |
| 1408 | + } | |
| 1409 | + | |
| 1410 | + /** | |
| 1411 | + * Filter available to process custom field parameters | |
| 1412 | + * | |
| 1413 | + * @since 1.0.0 | |
| 1414 | + * | |
| 1415 | + * @param array $field The field parameters | |
| 1416 | + * @param stdClass $object The trigger/action object | |
| 1417 | + * @param string $item_type The item type (trigger|action) | |
| 1418 | + * @param string $option Option form to render | |
| 1419 | + * @param stdClass $automation The automation object | |
| 1420 | + * @param string $field_id The field ID | |
| 1421 | + * | |
| 1422 | + * @return array | |
| 1423 | + */ | |
| 1424 | + return apply_filters( 'automatorwp_automation_item_option_field_args', $field, $object, $item_type, $option, $automation, $field_id ); | |
| 1425 | + | |
| 1426 | +} | |