PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.2.8
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.2.8
0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 All 32 releases
code-engine / classes / api.php

api.php in Code Engine – PHP Snippets, AI Functions & Automation for WordPress 0.2.8, at classes/api.php

70 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_MWCODE_API
4 {
5 private $core = null;
6 private $snippet = null;
7
8
9 public function __construct( $core, $snippet ) {
10 $this->core = $core;
11 $this->snippet = $snippet;
12 }
13
14 /**
15 * Get a function by its ID.
16 *
17 * The options are used to filter the functions:
18 * - 'php_ready_args' (bool): If false, the arguments will not be formatted for PHP. (no $ before the names).
19 *
20 * @param $id
21 * @param array $options
22 *
23 * @return mixed
24 */
25 public function get_function( $id, $options = [] ) {
26 $snippet = $this->snippet->get_function( $id, $options );
27 return $snippet;
28 }
29
30 /**
31 * Get all functions.
32 *
33 * @return mixed
34 *
35 */
36 public function get_functions( $safe = true ) {
37 $snippets = $this->snippet->get_functions();
38
39 if ( $safe ) {
40
41 $snippets = array_filter( $snippets, function( $snippet ) {
42 $name = $snippet['name'];
43 if ( !preg_match( '/^[a-zA-Z0-9_-]{1,64}$/', $name ) ) {
44 return false;
45 }
46
47 return true;
48 } );
49
50 }
51
52 return $snippets;
53 }
54
55 /**
56 * Execute a function by its ID.
57 * The arguments should be an associative array with the argument names as keys.
58 * Example: [ "$city" => " 'Tokyo' ", "$date" => "1999" ]
59 *
60 * @param $id
61 * @param $args
62 *
63 * @return mixed
64 */
65 public function execute_function( $id, $args ) {
66 $output = $this->core->run_snippet( $id, $args );
67 return $output;
68 }
69 }
70