# code-engine/0.2.8/classes/api.php

Code Engine – PHP Snippets, AI Functions &amp; Automation for WordPress, version 0.2.8. 70 lines.

- Page: https://pluginprobe.com/plugins/code-engine/0.2.8/code/classes/api.php
- Raw: https://pluginprobe.com/plugins/code-engine/0.2.8/raw/classes/api.php
- Modified: 2024-12-27T01:13:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-engine/0.2.8/code/classes/api.php#L10-L20`.

```php
<?php

class Meow_MWCODE_API
{
  private $core = null;
  private $snippet = null;


  public function __construct( $core, $snippet ) {
		$this->core = $core;
    $this->snippet = $snippet;
	}

  /**
   * Get a function by its ID.
   * 
   * The options are used to filter the functions:
   * - 'php_ready_args' (bool): If false, the arguments will not be formatted for PHP. (no $ before the names).
   *
   * @param $id
   * @param array $options
   *
   * @return mixed
   */
  public function get_function( $id, $options = [] ) {
    $snippet = $this->snippet->get_function( $id, $options );
    return $snippet;
  }

  /**
   * Get all functions.
   * 
   * @return mixed 
   * 
   */
  public function get_functions( $safe = true ) {
    $snippets = $this->snippet->get_functions();

    if ( $safe ) {

      $snippets = array_filter( $snippets, function( $snippet ) {
        $name = $snippet['name'];
        if ( !preg_match( '/^[a-zA-Z0-9_-]{1,64}$/', $name ) ) {
          return false;
        }

        return true;
      } );
      
    }

    return $snippets;
  }

  /**
   * Execute a function by its ID.
   * The arguments should be an associative array with the argument names as keys.
   * Example: [ "$city" => " 'Tokyo' ", "$date" => "1999" ]
   *
   * @param $id
   * @param $args
   *
   * @return mixed
   */
  public function execute_function( $id, $args ) {
    $output = $this->core->run_snippet( $id, $args );
    return $output;
  }
}

```
