PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.2
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.2
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 5.6.2 All 33 releases
automatorwp / integrations / code-snippets / includes / functions.php

functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.2, at integrations/code-snippets/includes/functions.php

94 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package AutomatorWP\Integrations\Code_Snippets\Functions
6 * @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Get snippets from Code Snippets
14 *
15 * @since 1.0.0
16 *
17 * @param stdClass $field
18 *
19 * @return array
20 */
21 function automatorwp_code_snippets_options_cb_snippet( $field ) {
22
23 // Setup vars
24 $value = $field->escaped_value;
25 $none_value = 'any';
26 $none_label = __( 'any snippet', 'automatorwp' );
27 $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label );
28
29 if( ! empty( $value ) ) {
30 if( ! is_array( $value ) ) {
31 $value = array( $value );
32 }
33
34 foreach( $value as $snippet_id ) {
35
36 // Skip option none
37 if( $snippet_id === $none_value ) {
38 continue;
39 }
40
41 $options[$snippet_id] = automatorwp_code_snippets_get_snippet_name( $snippet_id );
42 }
43 }
44
45 return $options;
46
47 }
48
49 /**
50 * Get snippets from Code Snippets
51 *
52 * @since 1.0.0
53 *
54 *
55 * @return array
56 */
57 function automatorwp_code_snippets_get_snippets( ) {
58
59 $snippets = array();
60
61 $all_snippets = Code_Snippets\get_snippets();
62
63 foreach ( $all_snippets as $snippet ){
64
65 $snippets[] = array(
66 'id' => $snippet->id,
67 'name' => $snippet->name,
68 );
69
70 }
71
72 return $snippets;
73
74 }
75
76 /**
77 * Get snippet name
78 *
79 * @since 1.0.0
80 *
81 * @param int $snippet_id ID snippet
82 *
83 */
84 function automatorwp_code_snippets_get_snippet_name( $snippet_id ) {
85
86 if( ! $snippet_id ) {
87 return '';
88 }
89
90 $snippet = Code_Snippets\get_snippet( $snippet_id );
91
92 return $snippet->name;
93
94 }