<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; }

function sifency_addons_get_elementor_templates() {

	if ( ! class_exists( 'Elementor\Plugin' ) ) {
		return array();
	}

	$templates = array();

	$section_templates = get_posts(
		array(
			'post_type'      => 'section_templates',
			'posts_per_page' => -1,
			'post_status'    => 'publish',
			'orderby'        => 'title',
			'order'          => 'ASC',
		)
	);
	$page_templates    = get_posts(
		array(
			'post_type'      => 'page',
			'posts_per_page' => -1,
			'post_status'    => 'publish',
			'orderby'        => 'title',
			'order'          => 'ASC',
		)
	);
	foreach ( $page_templates as $post ) {
		$templates[ $post->ID ] = '[Page] ' . $post->post_title;
	}
	foreach ( $section_templates as $post ) {
		$templates[ $post->ID ] = '[Section] ' . $post->post_title;
	}

	$elementor_posts = get_posts(
		array(
			'post_type'      => 'elementor_library',
			'posts_per_page' => -1,
			'post_status'    => 'publish',
			'orderby'        => 'title',
			'order'          => 'ASC',
		)
	);

	foreach ( $elementor_posts as $post ) {
		$templates[ $post->ID ] = '[Elementor] ' . $post->post_title;
	}

	return $templates;
}
