PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.4
Elementor Website Builder – more than just a page builder v4.2.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / site-navigation / data / endpoints / recent-posts.php

recent-posts.php in Elementor Website Builder – more than just a page builder 4.2.4, at modules/site-navigation/data/endpoints/recent-posts.php

102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\SiteNavigation\Data\Endpoints;
4
5 use Elementor\Core\Base\Document;
6 use Elementor\Core\Kits\Documents\Kit;
7 use Elementor\Data\V2\Base\Endpoint;
8 use Elementor\Plugin;
9 use Elementor\TemplateLibrary\Source_Local;
10 use Elementor\Utils;
11 use WP_REST_Server;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Recent_Posts extends Endpoint {
18
19 public function register_items_route( $methods = WP_REST_Server::READABLE, $args = [] ) {
20 $args = [
21 'posts_per_page' => [
22 'description' => 'Number of posts to return',
23 'type' => 'integer',
24 'required' => true,
25 'sanitize_callback' => 'absint',
26 'validate_callback' => 'rest_validate_request_arg',
27 ],
28 'post_type' => [
29 'description' => 'Post types to retrieve',
30 'type' => 'array',
31 'required' => false,
32 'default' => [ 'page', 'post', Source_Local::CPT ],
33 'sanitize_callback' => 'rest_sanitize_array',
34 'validate_callback' => 'rest_validate_request_arg',
35 ],
36 'post__not_in' => [
37 'description' => 'Post id`s to exclude',
38 'type' => 'array',
39 'required' => [],
40 'sanitize_callback' => 'wp_parse_id_list',
41 'validate_callback' => 'rest_validate_request_arg',
42 ],
43 ];
44
45 parent::register_items_route( $methods, $args );
46 }
47
48 public function get_name() {
49 return 'recent-posts';
50 }
51
52 public function get_format() {
53 return 'site-navigation/recent-posts';
54 }
55
56 public function get_items( $request ) {
57 $args = [
58 'posts_per_page' => $request->get_param( 'posts_per_page' ),
59 'post_type' => $request->get_param( 'post_type' ),
60 'fields' => 'ids',
61 'meta_query' => [
62 [
63 'key' => Document::TYPE_META_KEY,
64 'value' => Kit::get_type(), // Exclude kits.
65 'compare' => '!=',
66 ],
67 ],
68 ];
69
70 $exclude = $request->get_param( 'post__not_in' );
71
72 if ( ! empty( $exclude ) ) {
73 $args['post__not_in'] = $exclude;
74 }
75
76 $recently_edited_query = Utils::get_recently_edited_posts_query( $args );
77
78 $recent = [];
79
80 foreach ( $recently_edited_query->posts as $id ) {
81 $document = Plugin::$instance->documents->get( $id );
82
83 $recent[] = [
84 'id' => $id,
85 'title' => get_the_title( $id ),
86 'edit_url' => $document->get_edit_url(),
87 'date_modified' => get_post_timestamp( $id, 'modified' ),
88 'type' => [
89 'post_type' => get_post_type( $id ),
90 'doc_type' => $document->get_name(),
91 'label' => $document->get_title(),
92 ],
93 'user_can' => [
94 'edit' => current_user_can( 'edit_post', $id ),
95 ],
96 ];
97 }
98
99 return $recent;
100 }
101 }
102