PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.12
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.12
6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / API.php
kirki / includes Last commit date
API 2 weeks ago Admin 1 month ago Ajax 1 week ago ExportImport 2 weeks ago FormValidator 2 months ago Frontend 1 week ago Manager 2 weeks ago API.php 1 month ago Admin.php 2 months ago Ajax.php 1 week ago Apps.php 1 month ago ContentManager.php 2 months ago DbQueryUtils.php 1 month ago ElementVisibilityConditions.php 2 months ago Frontend.php 2 months ago HelperFunctions.php 1 week ago KirkiBase.php 2 months ago PostsQueryUtils.php 2 months ago Staging.php 2 months ago View.php 2 weeks ago
API.php
103 lines
1 <?php
2
3 /**
4 * Register routes for Media and Frontend
5 *
6 * @package kirki
7 */
8
9 namespace Kirki;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 use Kirki\API\ContentManager\ContentManagerRest;
16 use Kirki\API\KirkiComments\KirkiCommentsRest;
17 use Kirki\API\Media;
18 use Kirki\API\Frontend\FrontendApi;
19
20 /**
21 * API Class
22 */
23 class API {
24
25
26
27 /**
28 * Initialize the class
29 *
30 * @return void
31 */
32 public function __construct() {
33 add_action( 'rest_api_init', array( $this, 'register_api' ) );
34 add_action( 'init', array( $this, 'download_zip_endpoint' ) );
35 }
36
37 /**
38 * Register_api
39 *
40 * @return void
41 */
42 public function register_api() {
43 // Media apis.
44 $media = new Media();
45 $media->register_routes();
46
47 $content_manager = new ContentManagerRest();
48 $content_manager->register_routes();
49
50 $kirki_comments = new KirkiCommentsRest();
51 $kirki_comments->register_routes();
52
53 FrontendApi::register();
54 }
55
56 public function download_zip_endpoint() {
57 if (
58 ! isset( $_GET['page-export'], $_GET['file-name'] ) ||
59 'true' !== $_GET['page-export']
60 ) {
61 return;
62 }
63
64 if ( ! HelperFunctions::has_access( KIRKI_ACCESS_LEVELS['FULL_ACCESS'] ) ) {
65 wp_send_json_error( 'Not authorized', 401 );
66 }
67
68 // TODO: need to check nonce
69 $this->downloadZIP();
70 }
71
72 private function downloadZIP() {
73 $upload_dir = wp_upload_dir();
74 $file_name = HelperFunctions::sanitize_text( $_GET['file-name'] );
75 $file_name = basename( $file_name );
76 // Check if the file has a .zip extension
77 if ( pathinfo( $file_name, PATHINFO_EXTENSION ) !== 'zip' ) {
78 echo 'Invalid file type.';
79 die();
80 }
81 $zipFilePath = $upload_dir['basedir'] . "/$file_name";
82 // Send the zip file to the client.
83 header( 'Content-Type: application/zip' );
84 header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
85 header( 'Content-Length: ' . filesize( $zipFilePath ) );
86 $this->output_file_and_cleanup( $zipFilePath, $file_name );
87 exit;
88 }
89
90 private function output_file_and_cleanup( $path, $name ) {
91 global $wp_filesystem;
92 if ( empty( $wp_filesystem ) ) {
93 require_once ABSPATH . 'wp-admin/includes/file.php';
94 WP_Filesystem();
95 }
96
97 if ( $wp_filesystem->exists( $path ) ) {
98 echo $wp_filesystem->get_contents( $path ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
99 wp_delete_file( $path );
100 }
101 }
102 }
103