PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.1
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.1
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / modules / dynamic-content / cpt-api.php
elementskit-lite / modules / dynamic-content Last commit date
cpt-api.php 3 weeks ago cpt.php 3 weeks ago init.php 4 years ago
cpt-api.php
117 lines
1 <?php
2 namespace ElementsKit_Lite;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class ElementsKit_Cpt_Api extends Core\Handler_Api {
7
8 public function config() {
9 $this->prefix = 'dynamic-content';
10 $this->param = '/(?P<type>\w+)/(?P<key>\w+(|[-]\w+))/';
11 }
12
13 public function get_content_editor() {
14
15 if ( ! is_user_logged_in() ) {
16 wp_die(
17 esc_html__( 'You must be logged in.', 'elementskit-lite' ),
18 401
19 );
20 }
21
22 if ( ! current_user_can( 'edit_posts' ) ) {
23 wp_die(
24 esc_html__( 'You are not allowed to access this page.', 'elementskit-lite' ),
25 403
26 );
27 }
28
29 $content_key = sanitize_key( $this->request['key'] );
30 $content_type = sanitize_key( $this->request['type'] );
31 $builder_post_title = 'dynamic-content-' . $content_type . '-' . $content_key;
32
33 $builder_post_slug = Utils::get_page_by_title( $builder_post_title, 'elementskit_content' );
34
35 if ( is_null( $builder_post_slug ) ) {
36
37 // Contributors -> pending
38 // Authors/Editors/Admins -> publish
39 $post_status = current_user_can( 'publish_posts' )
40 ? 'publish'
41 : 'pending';
42
43 $builder_post_id = wp_insert_post(
44 array(
45 'post_content' => '',
46 'post_title' => $builder_post_title,
47 'post_name' => sanitize_title( $builder_post_title ),
48 'post_status' => $post_status,
49 'post_type' => 'elementskit_content',
50 'post_author' => get_current_user_id(),
51 )
52 );
53
54 if ( ! is_wp_error( $builder_post_id ) ) {
55 update_post_meta(
56 $builder_post_id,
57 '_wp_page_template',
58 'elementor_canvas'
59 );
60 }
61
62 } else {
63
64 $builder_post_id = $builder_post_slug->ID;
65
66 // Prevent users editing other users' content unless they have permission.
67 if (
68 ! current_user_can( 'edit_others_posts' ) &&
69 (int) get_post_field( 'post_author', $builder_post_id ) !== get_current_user_id()
70 ) {
71 wp_die(
72 esc_html__( 'You are not allowed to edit this content.', 'elementskit-lite' ),
73 403
74 );
75 }
76 }
77
78 // WPML support.
79 if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
80 $builder_post_id = $this->set_wpml_data( $builder_post_id );
81 }
82
83 $url = admin_url(
84 'post.php?post=' . absint( $builder_post_id ) . '&action=elementor'
85 );
86
87 wp_safe_redirect( $url );
88 exit;
89 }
90
91 public function set_wpml_data($builder_post_id) {
92 global $sitepress;
93 $default_language = $sitepress->get_default_language();
94 $wpml_element_type = apply_filters( 'wpml_element_type', 'elementskit_content' );
95 $trid = $sitepress->get_element_trid( $builder_post_id, $wpml_element_type );
96 if( ! $trid ) {
97 $sitepress->set_element_language_details( $builder_post_id, $wpml_element_type, false, $default_language, null, false );
98 }
99
100 // get wpml post by language code
101 $referer = wp_get_referer();
102 $referer = wp_parse_url($referer);
103 $referer = !empty($referer['query']) ? $referer['query'] : '';
104 $referer = parse_str($referer, $referer_args);
105
106 if( !empty($referer_args['post']) ) {
107 $language_details = apply_filters( 'wpml_post_language_details', NULL, $referer_args['post'] );
108 if( !is_wp_error($language_details) ) {
109 $builder_post_id = apply_filters( 'wpml_object_id', $builder_post_id, 'elementskit_content', true, $language_details['language_code'] );
110 }
111 }
112
113 return $builder_post_id;
114 }
115 }
116 new ElementsKit_Cpt_Api();
117