PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
← All changes | integrations/code-snippets/includes/actions/deactivate-snippet.php +157 -0 5.7.8 → 6.0.3 View file →
@@ -1,0 +1,157 @@
1 +<?php
2 +/**
3 + * Deactive Snippet
4 + *
5 + * @package AutomatorWP\Integrations\Code_Snippets\Actions\Deactive_Snippet
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 +class AutomatorWP_Code_Snippets_Deactive_Snippet extends AutomatorWP_Integration_Action {
13 +
14 + public $integration = 'code_snippets';
15 + public $action = 'code_snippets_deactive_snippet';
16 +
17 + /**
18 + * Register the trigger
19 + *
20 + * @since 1.0.0
21 + */
22 + public function register() {
23 +
24 + automatorwp_register_action( $this->action, array(
25 + 'integration' => $this->integration,
26 + 'label' => __( 'Deactivate a snippet', 'automatorwp' ),
27 + 'select_option' => __( '<strong>Deactivate</strong> a snippet', 'automatorwp' ),
28 + /* translators: %1$s: Title snippet. */
29 + 'edit_label' => sprintf( __( 'Deactivate %1$s', 'automatorwp' ), '{snippet}' ),
30 + /* translators: %1$s: Title snippet. */
31 + 'log_label' => sprintf( __( 'Deactivate %1$s', 'automatorwp' ), '{snippet}' ),
32 + 'options' => array(
33 + 'snippet' => automatorwp_utilities_ajax_selector_option( array(
34 + 'field' => 'snippet',
35 + 'option_default' => __( 'Snippet', 'automatorwp' ),
36 + 'name' => __( 'Snippet:', 'automatorwp' ),
37 + 'action_cb' => 'automatorwp_code_snippets_get_snippets',
38 + 'options_cb' => 'automatorwp_code_snippets_options_cb_snippet',
39 + 'placeholder' => 'Select a snippet',
40 + 'default' => ''
41 + ) ),
42 + ),
43 + ) );
44 +
45 + }
46 +
47 + /**
48 + * Action execution function
49 + *
50 + * @since 1.0.0
51 + *
52 + * @param stdClass $action The action object
53 + * @param int $user_id The user ID
54 + * @param array $action_options The action's stored options (with tags already passed)
55 + * @param stdClass $automation The action's automation object
56 + */
57 + public function execute( $action, $user_id, $action_options, $automation ) {
58 +
59 + // Shorthand
60 + $this->result = '';
61 + $snippet_id = $action_options['snippet'];
62 +
63 + if ( empty ( $snippet_id ) ) {
64 + $this->result = __( 'Please, select a snippet to deactivate', 'automatorwp' );
65 + return;
66 + }
67 +
68 + $snippet = Code_Snippets\get_snippet( $snippet_id );
69 +
70 + if ( empty( $snippet->active ) ) {
71 + $this->result = sprintf( __( 'The snippet %s is already inactive', 'automatorwp' ), $snippet->name );
72 + return;
73 + }
74 +
75 + $activated_snippet = Code_Snippets\deactivate_snippet( $snippet_id );
76 +
77 + $this->result = sprintf( __( 'The snippet %s has been deactivated', 'automatorwp' ), $activated_snippet->name );
78 +
79 + }
80 +
81 + /**
82 + * Register required hooks
83 + *
84 + * @since 1.0.0
85 + */
86 + public function hooks() {
87 +
88 + // Log meta data
89 + add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
90 +
91 + // Log fields
92 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
93 +
94 + parent::hooks();
95 +
96 + }
97 +
98 + /**
99 + * Action custom log meta
100 + *
101 + * @since 1.0.0
102 + *
103 + * @param array $log_meta Log meta data
104 + * @param stdClass $action The action object
105 + * @param int $user_id The user ID
106 + * @param array $action_options The action's stored options (with tags already passed)
107 + * @param stdClass $automation The action's automation object
108 + *
109 + * @return array
110 + */
111 + public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
112 +
113 + // Bail if action type don't match this action
114 + if( $action->type !== $this->action ) {
115 + return $log_meta;
116 + }
117 +
118 + // Store the action's result
119 + $log_meta['result'] = $this->result;
120 +
121 + return $log_meta;
122 + }
123 +
124 + /**
125 + * Action custom log fields
126 + *
127 + * @since 1.0.0
128 + *
129 + * @param array $log_fields The log fields
130 + * @param stdClass $log The log object
131 + * @param stdClass $object The trigger/action/automation object attached to the log
132 + *
133 + * @return array
134 + */
135 + public function log_fields( $log_fields, $log, $object ) {
136 +
137 + // Bail if log is not assigned to an action
138 + if( $log->type !== 'action' ) {
139 + return $log_fields;
140 + }
141 +
142 + // Bail if action type don't match this action
143 + if( $object->type !== $this->action ) {
144 + return $log_fields;
145 + }
146 +
147 + $log_fields['result'] = array(
148 + 'name' => __( 'Result:', 'automatorwp' ),
149 + 'type' => 'text',
150 + );
151 +
152 + return $log_fields;
153 + }
154 +
155 +}
156 +
157 +new AutomatorWP_Code_Snippets_Deactive_Snippet();