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 / Apps.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
Apps.php
137 lines
1 <?php
2 /**
3 * Admin panel kirki entry point
4 *
5 * @package kirki
6 */
7
8 namespace Kirki;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 // Created alias for legacy Droip\Apps references
15 if ( ! class_exists( 'Droip\Apps', false ) ) {
16 class_alias( 'Kirki\Apps', 'Droip\Apps' );
17 }
18
19 /**
20 * Kirki Apps
21 */
22 class Apps {
23 /**
24 * Initialize the class
25 *
26 * @return void
27 */
28 public function __construct() {
29 $this->import_kirki_component_library();
30 $this->import_kirki_external_apps();
31 }
32
33 private function import_kirki_component_library() {
34 require_once KIRKI_ROOT_PATH . 'ComponentLibrary/index.php';
35 if ( IS_DEVELOPING_KIRKI_APPS ) {
36 require_once KIRKI_DEVELOPING_APPS_INCLUDES;
37 }
38 }
39
40 private function import_kirki_external_apps() {
41 $apps = HelperFunctions::get_global_data_using_key( 'kirki_installed_apps' );
42 if ( ! $apps ) {
43 $apps = array();
44 }
45
46 if ( ! IS_DEVELOPING_KIRKI_APPS ) {
47 foreach ( $apps as $key => $app ) {
48 $app_slug = $app['app_slug'];
49 $base_upload_dir = WP_CONTENT_DIR; // Absolute path to 'uploads'
50 $app_folder_index_file = $base_upload_dir . '/kirki-apps/' . $app_slug . '/index.php';
51 $app_legecy_folder_index_file = $base_upload_dir . '/droip-apps/' . $app_slug . '/index.php';
52 // Check if the index.php file exists
53 if ( file_exists( $app_folder_index_file ) ) {
54 // Import logic goes here
55 $this->import_app( $app_slug, $app_folder_index_file );
56 } elseif ( file_exists( $app_legecy_folder_index_file ) ) {
57 // Import logic goes here
58 $this->import_app( $app_slug, $app_legecy_folder_index_file );
59 }
60 }
61 }
62 }
63
64 // Example import logic function
65 private function import_app( $app_slug, $index_file_path ) {
66 // Custom logic for importing the app
67 include_once $index_file_path; // Example: including the index.php file
68 // Additional logic for handling the app
69 }
70
71 /**
72 * Get app settings based on the caller's file path
73 *
74 * @return array|null App settings or null if not found
75 */
76 public static function get_settings( $slug ) {
77 return self::get_app_settings_by_slug( $slug );
78 // Get the debug backtrace
79 $backtrace = debug_backtrace();
80
81 // Find the file from the calling context
82 $caller_file = isset( $backtrace[0]['file'] ) ? $backtrace[0]['file'] : null;
83
84 if ( ! $caller_file ) {
85 return null; // Cannot determine caller
86 }
87
88 // Find the app_slug from the caller's file path
89 $base_upload_dir = WP_CONTENT_DIR . '/kirki-apps/'; // Base directory for apps
90
91 // Check if the file is in the apps folder
92 if ( strpos( $caller_file, $base_upload_dir ) === 0 ) {
93 // Extract the app folder name
94 $relative_path = str_replace( $base_upload_dir, '', $caller_file );
95 $path_parts = explode( '/', $relative_path );
96 $app_slug = $path_parts[0]; // The first part of the relative path is the app_slug
97 // Retrieve app-specific settings
98 return self::get_app_settings_by_slug( $app_slug );
99 }
100
101 return null; // Not an app file
102 }
103
104 /**
105 * Retrieve app settings by app_slug
106 *
107 * @param string $app_slug The app ID
108 * @return array|null App settings or null if not found / not installed
109 */
110 private static function get_app_settings_by_slug( $app_slug ) {
111 // Check if the app is installed
112 $installed_apps = HelperFunctions::get_global_data_using_key( 'kirki_installed_apps' );
113
114 if ( ! $installed_apps || ! is_array( $installed_apps ) ) {
115 return null;
116 }
117
118 $is_installed = false;
119 foreach ( $installed_apps as $app ) {
120 if ( isset( $app['app_slug'] ) && $app['app_slug'] === $app_slug ) {
121 $is_installed = true;
122 break;
123 }
124 }
125
126 if ( ! $is_installed ) {
127 return null;
128 }
129
130 // Fetch app settings
131 $app_settings = HelperFunctions::get_global_data_using_key( 'kirki_app_settings_' . $app_slug );
132
133 return $app_settings ? $app_settings : null;
134 }
135
136 }
137