PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Admin / API / GetFields.php
shop-press / Admin / API Last commit date
Export.php 2 years ago GetFields.php 4 months ago Import.php 2 years ago Options.php 2 weeks ago Pages.php 2 years ago Posts.php 4 months ago Services.php 1 year ago
GetFields.php
121 lines
1 <?php
2 /**
3 * Get Fields.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Admin\API;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use ShopPress\Admin\PagesFields;
13
14 class GetFields {
15 /**
16 * Instance of this class.
17 *
18 * @since 1.0.0
19 */
20 public static $instance;
21
22 /**
23 * Provides access to a single instance of a module using the singleton pattern.
24 *
25 * @since 1.0.0
26 *
27 * @return object
28 */
29 public static function instance() {
30 if ( self::$instance === null ) {
31 self::$instance = new self();
32 }
33 return self::$instance;
34 }
35
36 /**
37 * Get settings fields.
38 *
39 * @since 1.2.0
40 *
41 * @param object $request
42 */
43 public function get_fields( $request ) {
44 $type = $request->get_param( 'type' );
45 $template = $request->get_param( 'template' );
46 $module = $request->get_param( 'module' );
47 $page = $request->get_param( 'page' );
48 $parent = $request->get_param( 'parent' );
49 $setting = $request->get_param( 'setting' );
50
51 $class_name = null;
52 $class_name_pro = null;
53 $method_name = null;
54
55 if ( $type === 'features' && isset( $type ) ) {
56
57 $templates = PagesFields\Templates::fields();
58 $modules = PagesFields\Modules::fields();
59
60 return array(
61 'templates' => $templates,
62 'modules' => $modules,
63 );
64 }
65
66 if ( $type === 'template' && isset( $template ) ) {
67 $class_name = 'ShopPress\\Admin\\SettingsFields\\Templates';
68 $class_name_pro = 'ShopPressPro\\Admin\\SettingsFields\\Templates';
69 $method_name = $template;
70 } elseif ( isset( $parent ) && isset( $setting ) ) {
71 $class_name = 'ShopPress\\Admin\\SettingsFields\\' . $parent;
72 $class_name_pro = 'ShopPressPro\\Admin\\SettingsFields\\' . $parent;
73 $method_name = $setting;
74 } elseif ( $type === 'module' && isset( $module ) ) {
75 $class_name = 'ShopPress\\Admin\\SettingsFields\\Modules';
76 $class_name_pro = 'ShopPressPro\\Admin\\SettingsFields\\Modules';
77 $method_name = $module;
78 }
79
80 $fields = array();
81 if ( $class_name && $method_name ) {
82 if ( method_exists( $class_name, $method_name ) ) {
83 $fields = call_user_func( array( $class_name, $method_name ) );
84 }
85 if ( $class_name_pro && ! class_exists( $class_name_pro ) ) {
86 $pro_path = defined( 'SHOPPRESS_PRO_PATH' ) ? SHOPPRESS_PRO_PATH : $this->get_pro_plugin_path();
87 if ( $pro_path ) {
88 $pro_modules_file = $pro_path . 'Admin/SettingsFields/Modules.php';
89 if ( file_exists( $pro_modules_file ) ) {
90 require_once $pro_modules_file;
91 }
92 }
93 }
94 if ( class_exists( $class_name_pro ) && method_exists( $class_name_pro, $method_name ) ) {
95 $fields = call_user_func( array( $class_name_pro, $method_name ) );
96 }
97 }
98
99 $filter_name = $method_name ? "shoppress/settings_fields/{$type}/{$method_name}" : 'shoppress/settings_fields/unknown';
100 return apply_filters( $filter_name, $fields );
101 }
102
103 /**
104 * Get ShopPress Pro plugin path when constant is not defined.
105 *
106 * @return string|null
107 */
108 private function get_pro_plugin_path() {
109 if ( ! function_exists( 'get_plugins' ) ) {
110 require_once ABSPATH . 'wp-admin/includes/plugin.php';
111 }
112 $plugins = get_plugins();
113 foreach ( array_keys( $plugins ) as $plugin_file ) {
114 if ( strpos( $plugin_file, 'shop-press-pro' ) === 0 && is_plugin_active( $plugin_file ) ) {
115 return trailingslashit( WP_PLUGIN_DIR . '/' . dirname( $plugin_file ) );
116 }
117 }
118 return null;
119 }
120 }
121