config = $config; } /** * Retrieves raw data and decodes it, returns an array of templates. * * @since 2.7 * * @return array */ public function get_templates() { if ( is_array( $this->templates ) ) { return $this->templates; } $uri = rgar( $this->config, 'uri' ); try { $this->raw_data = @file_get_contents( $uri ); } catch ( Exception $e ) { return array(); } $this->templates = json_decode( $this->raw_data, true ); if ( ! is_array( $this->templates ) ) { return array(); } return $this->templates; } /** * Returns a template by its ID. * * @since 2.7 * * @param string $id The id of the template. * * @return GF_Template_Library_Template|false */ public function get( $id ) { $template_data = rgar( $this->get_templates(), $id ); if ( ! $template_data ) { return false; } return new GF_Template_Library_Template( $template_data ); } /** * Returns the all the templates as an array. * * @since 2.7 * * @param bool $include_meta whether to include the template form meta or not. * * @return array */ public function all( $include_meta = false ) { if ( $include_meta ) { return $this->get_templates(); } $templates_data = array_map( function( $template_data ) { unset( $template_data['form_meta'] ); unset( $template_data['version'] ); return $template_data; }, $this->get_templates() ); return $templates_data; } }