Elementor\Api::get_template_content PHP Method

get_template_content() public static method

public static get_template_content ( $template_id )
    public static function get_template_content($template_id)
    {
        $url = sprintf(self::$api_get_template_content_url, $template_id);
        $response = wp_remote_get($url, ['timeout' => 40, 'body' => ['api_version' => ELEMENTOR_VERSION, 'site_lang' => get_bloginfo('language')]]);
        if (is_wp_error($response) || 200 !== (int) wp_remote_retrieve_response_code($response)) {
            return false;
        }
        $template_content = json_decode(wp_remote_retrieve_body($response), true);
        if (empty($template_content) || !is_array($template_content)) {
            return false;
        }
        if (empty($template_content['data'])) {
            return false;
        }
        return $template_content['data'];
    }

Usage Example

Beispiel #1
0
 public function get_content($item_id, $context = 'display')
 {
     $data = Api::get_template_content($item_id);
     if (!$data) {
         return false;
     }
     $data = $this->replace_elements_ids($data);
     $data = $this->process_export_import_data($data, 'on_import');
     return $data;
 }