@@ -4,40 +4,40 @@ |
||
4 | 4 | |
5 | 5 | class Remote_Plugin implements Plugin { |
6 | 6 | |
7 | - private $slug; |
|
7 | + private $slug; |
|
8 | 8 | |
9 | - private $url; |
|
9 | + private $url; |
|
10 | 10 | |
11 | - private $name; |
|
11 | + private $name; |
|
12 | 12 | |
13 | - public function __construct( $slug, $name, $url ) { |
|
14 | - $this->slug = $slug; |
|
15 | - $this->url = $url; |
|
16 | - $this->name = $name; |
|
17 | - } |
|
13 | + public function __construct( $slug, $name, $url ) { |
|
14 | + $this->slug = $slug; |
|
15 | + $this->url = $url; |
|
16 | + $this->name = $name; |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_slug() { |
|
20 | - return $this->slug; |
|
21 | - } |
|
19 | + public function get_slug() { |
|
20 | + return $this->slug; |
|
21 | + } |
|
22 | 22 | |
23 | - public function get_zip_url() { |
|
24 | - return $this->url; |
|
25 | - } |
|
23 | + public function get_zip_url() { |
|
24 | + return $this->url; |
|
25 | + } |
|
26 | 26 | |
27 | - public function is_plugin_installed() { |
|
28 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
29 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
30 | - } |
|
31 | - $all_plugins = get_plugins(); |
|
27 | + public function is_plugin_installed() { |
|
28 | + if ( ! function_exists( 'get_plugins' ) ) { |
|
29 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
30 | + } |
|
31 | + $all_plugins = get_plugins(); |
|
32 | 32 | |
33 | - return array_key_exists( $this->slug, $all_plugins ); |
|
34 | - } |
|
33 | + return array_key_exists( $this->slug, $all_plugins ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function is_plugin_activated() { |
|
37 | - return is_plugin_active( $this->slug ); |
|
38 | - } |
|
36 | + public function is_plugin_activated() { |
|
37 | + return is_plugin_active( $this->slug ); |
|
38 | + } |
|
39 | 39 | |
40 | - public function get_name() { |
|
41 | - return $this->name; |
|
42 | - } |
|
40 | + public function get_name() { |
|
41 | + return $this->name; |
|
42 | + } |
|
43 | 43 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | private $name; |
12 | 12 | |
13 | - public function __construct( $slug, $name, $url ) { |
|
13 | + public function __construct($slug, $name, $url) { |
|
14 | 14 | $this->slug = $slug; |
15 | 15 | $this->url = $url; |
16 | 16 | $this->name = $name; |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | public function is_plugin_installed() { |
28 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
29 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
28 | + if ( ! function_exists('get_plugins')) { |
|
29 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
30 | 30 | } |
31 | 31 | $all_plugins = get_plugins(); |
32 | 32 | |
33 | - return array_key_exists( $this->slug, $all_plugins ); |
|
33 | + return array_key_exists($this->slug, $all_plugins); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function is_plugin_activated() { |
37 | - return is_plugin_active( $this->slug ); |
|
37 | + return is_plugin_active($this->slug); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function get_name() { |
@@ -6,76 +6,76 @@ |
||
6 | 6 | |
7 | 7 | class Installer { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Plugin |
|
11 | - */ |
|
12 | - private $plugin; |
|
13 | - /** |
|
14 | - * @var Plugin_Upgrader |
|
15 | - */ |
|
16 | - private $upgrader; |
|
17 | - |
|
18 | - /** |
|
19 | - * @param $upgrader Plugin_Upgrader |
|
20 | - * @param $plugin Plugin |
|
21 | - */ |
|
22 | - public function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
23 | - $this->upgrader = $upgrader; |
|
24 | - $this->plugin = $plugin; |
|
25 | - } |
|
26 | - |
|
27 | - public function install() { |
|
28 | - |
|
29 | - if ( $this->plugin->is_plugin_installed() ) { |
|
30 | - return; |
|
31 | - } |
|
32 | - |
|
33 | - try { |
|
34 | - wp_cache_flush(); |
|
35 | - $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
36 | - } catch ( \Exception $e ) { |
|
37 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
38 | - error_log( 'Error caught when installing plugin ' . $this->plugin->get_slug() . ' error: ' . $e->getMessage() ); |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - public function activate() { |
|
43 | - if ( $this->plugin->is_plugin_activated() ) { |
|
44 | - return; |
|
45 | - } |
|
46 | - activate_plugin( $this->plugin->get_slug() ); |
|
47 | - } |
|
48 | - |
|
49 | - public function install_and_activate_on_entity_type_change( $new_value ) { |
|
50 | - if ( ! $new_value ) { |
|
51 | - return; |
|
52 | - } |
|
53 | - $this->install_and_activate(); |
|
54 | - } |
|
55 | - |
|
56 | - public function install_and_activate() { |
|
57 | - ob_start(); |
|
58 | - $this->install(); |
|
59 | - $this->activate(); |
|
60 | - ob_end_clean(); |
|
61 | - } |
|
62 | - |
|
63 | - public function admin_ajax_install_and_activate() { |
|
64 | - |
|
65 | - $this->install_and_activate(); |
|
66 | - |
|
67 | - if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
68 | - wp_send_json_success( null, 200 ); |
|
69 | - } |
|
70 | - |
|
71 | - wp_send_json_error( null, 400 ); |
|
72 | - } |
|
73 | - |
|
74 | - public function register_hooks() { |
|
75 | - add_action( 'wl_feature__change__entity-types-professional', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
76 | - add_action( 'wl_feature__change__entity-types-business', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
77 | - add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'admin_ajax_install_and_activate' ) ); |
|
78 | - add_action( "wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'install_and_activate' ) ); |
|
79 | - } |
|
9 | + /** |
|
10 | + * @var Plugin |
|
11 | + */ |
|
12 | + private $plugin; |
|
13 | + /** |
|
14 | + * @var Plugin_Upgrader |
|
15 | + */ |
|
16 | + private $upgrader; |
|
17 | + |
|
18 | + /** |
|
19 | + * @param $upgrader Plugin_Upgrader |
|
20 | + * @param $plugin Plugin |
|
21 | + */ |
|
22 | + public function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
23 | + $this->upgrader = $upgrader; |
|
24 | + $this->plugin = $plugin; |
|
25 | + } |
|
26 | + |
|
27 | + public function install() { |
|
28 | + |
|
29 | + if ( $this->plugin->is_plugin_installed() ) { |
|
30 | + return; |
|
31 | + } |
|
32 | + |
|
33 | + try { |
|
34 | + wp_cache_flush(); |
|
35 | + $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
36 | + } catch ( \Exception $e ) { |
|
37 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
38 | + error_log( 'Error caught when installing plugin ' . $this->plugin->get_slug() . ' error: ' . $e->getMessage() ); |
|
39 | + } |
|
40 | + } |
|
41 | + |
|
42 | + public function activate() { |
|
43 | + if ( $this->plugin->is_plugin_activated() ) { |
|
44 | + return; |
|
45 | + } |
|
46 | + activate_plugin( $this->plugin->get_slug() ); |
|
47 | + } |
|
48 | + |
|
49 | + public function install_and_activate_on_entity_type_change( $new_value ) { |
|
50 | + if ( ! $new_value ) { |
|
51 | + return; |
|
52 | + } |
|
53 | + $this->install_and_activate(); |
|
54 | + } |
|
55 | + |
|
56 | + public function install_and_activate() { |
|
57 | + ob_start(); |
|
58 | + $this->install(); |
|
59 | + $this->activate(); |
|
60 | + ob_end_clean(); |
|
61 | + } |
|
62 | + |
|
63 | + public function admin_ajax_install_and_activate() { |
|
64 | + |
|
65 | + $this->install_and_activate(); |
|
66 | + |
|
67 | + if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
68 | + wp_send_json_success( null, 200 ); |
|
69 | + } |
|
70 | + |
|
71 | + wp_send_json_error( null, 400 ); |
|
72 | + } |
|
73 | + |
|
74 | + public function register_hooks() { |
|
75 | + add_action( 'wl_feature__change__entity-types-professional', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
76 | + add_action( 'wl_feature__change__entity-types-business', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
77 | + add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'admin_ajax_install_and_activate' ) ); |
|
78 | + add_action( "wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'install_and_activate' ) ); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -19,35 +19,35 @@ discard block |
||
19 | 19 | * @param $upgrader Plugin_Upgrader |
20 | 20 | * @param $plugin Plugin |
21 | 21 | */ |
22 | - public function __construct( Plugin_Upgrader $upgrader, Plugin $plugin ) { |
|
22 | + public function __construct(Plugin_Upgrader $upgrader, Plugin $plugin) { |
|
23 | 23 | $this->upgrader = $upgrader; |
24 | 24 | $this->plugin = $plugin; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function install() { |
28 | 28 | |
29 | - if ( $this->plugin->is_plugin_installed() ) { |
|
29 | + if ($this->plugin->is_plugin_installed()) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
33 | 33 | try { |
34 | 34 | wp_cache_flush(); |
35 | - $this->upgrader->install( $this->plugin->get_zip_url() ); |
|
36 | - } catch ( \Exception $e ) { |
|
35 | + $this->upgrader->install($this->plugin->get_zip_url()); |
|
36 | + } catch (\Exception $e) { |
|
37 | 37 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
38 | - error_log( 'Error caught when installing plugin ' . $this->plugin->get_slug() . ' error: ' . $e->getMessage() ); |
|
38 | + error_log('Error caught when installing plugin '.$this->plugin->get_slug().' error: '.$e->getMessage()); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | 42 | public function activate() { |
43 | - if ( $this->plugin->is_plugin_activated() ) { |
|
43 | + if ($this->plugin->is_plugin_activated()) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | - activate_plugin( $this->plugin->get_slug() ); |
|
46 | + activate_plugin($this->plugin->get_slug()); |
|
47 | 47 | } |
48 | 48 | |
49 | - public function install_and_activate_on_entity_type_change( $new_value ) { |
|
50 | - if ( ! $new_value ) { |
|
49 | + public function install_and_activate_on_entity_type_change($new_value) { |
|
50 | + if ( ! $new_value) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | $this->install_and_activate(); |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | |
65 | 65 | $this->install_and_activate(); |
66 | 66 | |
67 | - if ( $this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated() ) { |
|
68 | - wp_send_json_success( null, 200 ); |
|
67 | + if ($this->plugin->is_plugin_installed() && $this->plugin->is_plugin_activated()) { |
|
68 | + wp_send_json_success(null, 200); |
|
69 | 69 | } |
70 | 70 | |
71 | - wp_send_json_error( null, 400 ); |
|
71 | + wp_send_json_error(null, 400); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function register_hooks() { |
75 | - add_action( 'wl_feature__change__entity-types-professional', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
76 | - add_action( 'wl_feature__change__entity-types-business', array( $this, 'install_and_activate_on_entity_type_change' ), 10 ); |
|
77 | - add_action( "wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'admin_ajax_install_and_activate' ) ); |
|
78 | - add_action( "wl_install_and_activate_{$this->plugin->get_name()}", array( $this, 'install_and_activate' ) ); |
|
75 | + add_action('wl_feature__change__entity-types-professional', array($this, 'install_and_activate_on_entity_type_change'), 10); |
|
76 | + add_action('wl_feature__change__entity-types-business', array($this, 'install_and_activate_on_entity_type_change'), 10); |
|
77 | + add_action("wp_ajax_wl_install_and_activate_{$this->plugin->get_name()}", array($this, 'admin_ajax_install_and_activate')); |
|
78 | + add_action("wl_install_and_activate_{$this->plugin->get_name()}", array($this, 'install_and_activate')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | } |
@@ -19,81 +19,81 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array() ) { |
21 | 21 | |
22 | - global $wpdb; |
|
23 | - |
|
24 | - $schema_type_query = ''; |
|
25 | - |
|
26 | - if ( $schema_types ) { |
|
27 | - $schema_type_query = ' AND t.name IN (' . join( |
|
28 | - ',', |
|
29 | - array_map( |
|
30 | - function ( $schema_type ) { |
|
31 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
32 | - }, |
|
33 | - $schema_types |
|
34 | - ) |
|
35 | - ) . ')'; |
|
36 | - } |
|
37 | - |
|
38 | - // Search by substring |
|
39 | - if ( $autocomplete ) { |
|
40 | - $title = '%' . $title . '%'; |
|
41 | - } |
|
42 | - |
|
43 | - // The title is a LIKE query. |
|
44 | - $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
45 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
46 | - . ' WHERE p.post_title LIKE %s' |
|
47 | - . ' AND t.term_id = tt.term_id' |
|
48 | - . ' AND tt.taxonomy = %s' |
|
49 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
50 | - . ' AND tr.object_id = p.ID' |
|
51 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
52 | - . " AND p.post_status != 'trash'" |
|
53 | - . $schema_type_query; |
|
54 | - |
|
55 | - $params = array( |
|
56 | - $title, |
|
57 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
58 | - ); |
|
59 | - |
|
60 | - if ( $include_alias ) { |
|
61 | - |
|
62 | - $query .= ' UNION' |
|
63 | - . " SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug" |
|
64 | - . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
65 | - . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
66 | - . ' AND m.post_id = p.ID' |
|
67 | - . ' AND t.term_id = tt.term_id' |
|
68 | - . ' AND tt.taxonomy = %s' |
|
69 | - . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
70 | - . ' AND tr.object_id = p.ID' |
|
71 | - // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
72 | - . " AND p.post_status != 'trash'" |
|
73 | - . $schema_type_query; |
|
74 | - |
|
75 | - $params = array_merge( |
|
76 | - $params, |
|
77 | - array( |
|
78 | - Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
79 | - $title, |
|
80 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
81 | - ) |
|
82 | - ); |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - if ( $limit ) { |
|
87 | - $query .= ' LIMIT %d'; |
|
88 | - $params[] = $limit; |
|
89 | - } |
|
90 | - |
|
91 | - return $wpdb->get_results( |
|
92 | - $wpdb->prepare( |
|
93 | - $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
94 | - $params |
|
95 | - ) |
|
96 | - ); |
|
22 | + global $wpdb; |
|
23 | + |
|
24 | + $schema_type_query = ''; |
|
25 | + |
|
26 | + if ( $schema_types ) { |
|
27 | + $schema_type_query = ' AND t.name IN (' . join( |
|
28 | + ',', |
|
29 | + array_map( |
|
30 | + function ( $schema_type ) { |
|
31 | + return "'" . esc_sql( $schema_type ) . "'"; |
|
32 | + }, |
|
33 | + $schema_types |
|
34 | + ) |
|
35 | + ) . ')'; |
|
36 | + } |
|
37 | + |
|
38 | + // Search by substring |
|
39 | + if ( $autocomplete ) { |
|
40 | + $title = '%' . $title . '%'; |
|
41 | + } |
|
42 | + |
|
43 | + // The title is a LIKE query. |
|
44 | + $query = 'SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug' |
|
45 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t" |
|
46 | + . ' WHERE p.post_title LIKE %s' |
|
47 | + . ' AND t.term_id = tt.term_id' |
|
48 | + . ' AND tt.taxonomy = %s' |
|
49 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
50 | + . ' AND tr.object_id = p.ID' |
|
51 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
52 | + . " AND p.post_status != 'trash'" |
|
53 | + . $schema_type_query; |
|
54 | + |
|
55 | + $params = array( |
|
56 | + $title, |
|
57 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
58 | + ); |
|
59 | + |
|
60 | + if ( $include_alias ) { |
|
61 | + |
|
62 | + $query .= ' UNION' |
|
63 | + . " SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug" |
|
64 | + . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m" |
|
65 | + . ' WHERE m.meta_key = %s AND m.meta_value LIKE %s' |
|
66 | + . ' AND m.post_id = p.ID' |
|
67 | + . ' AND t.term_id = tt.term_id' |
|
68 | + . ' AND tt.taxonomy = %s' |
|
69 | + . ' AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
70 | + . ' AND tr.object_id = p.ID' |
|
71 | + // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278. |
|
72 | + . " AND p.post_status != 'trash'" |
|
73 | + . $schema_type_query; |
|
74 | + |
|
75 | + $params = array_merge( |
|
76 | + $params, |
|
77 | + array( |
|
78 | + Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
79 | + $title, |
|
80 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
81 | + ) |
|
82 | + ); |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + if ( $limit ) { |
|
87 | + $query .= ' LIMIT %d'; |
|
88 | + $params[] = $limit; |
|
89 | + } |
|
90 | + |
|
91 | + return $wpdb->get_results( |
|
92 | + $wpdb->prepare( |
|
93 | + $query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
94 | + $params |
|
95 | + ) |
|
96 | + ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,43 +103,43 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function wl_entity_ajax_get_by_title() { |
105 | 105 | |
106 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
107 | - // |
|
108 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
109 | - // Get the title to search. |
|
110 | - if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
111 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
112 | - @ob_clean(); |
|
113 | - wp_send_json_error( 'The title parameter is required.' ); |
|
114 | - } |
|
115 | - |
|
116 | - // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
117 | - // |
|
118 | - // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
119 | - $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
120 | - |
|
121 | - // Are we searching for a specific title or for a containing title? |
|
122 | - $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
123 | - |
|
124 | - // Are we searching also for the aliases? |
|
125 | - $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
126 | - |
|
127 | - // Get the edit link. |
|
128 | - $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
129 | - $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
130 | - |
|
131 | - // Prepare the response with the edit link. |
|
132 | - $response = array( |
|
133 | - 'edit_link' => $edit_link, |
|
134 | - 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
135 | - ); |
|
136 | - |
|
137 | - // Clean any buffer. |
|
138 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
139 | - @ob_clean(); |
|
140 | - |
|
141 | - // Send the success response. |
|
142 | - wp_send_json_success( $response ); |
|
106 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
107 | + // |
|
108 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
109 | + // Get the title to search. |
|
110 | + if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
111 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
112 | + @ob_clean(); |
|
113 | + wp_send_json_error( 'The title parameter is required.' ); |
|
114 | + } |
|
115 | + |
|
116 | + // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
|
117 | + // |
|
118 | + // See https://github.com/insideout10/wordlift-plugin/issues/438. |
|
119 | + $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
120 | + |
|
121 | + // Are we searching for a specific title or for a containing title? |
|
122 | + $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
123 | + |
|
124 | + // Are we searching also for the aliases? |
|
125 | + $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
126 | + |
|
127 | + // Get the edit link. |
|
128 | + $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
129 | + $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
130 | + |
|
131 | + // Prepare the response with the edit link. |
|
132 | + $response = array( |
|
133 | + 'edit_link' => $edit_link, |
|
134 | + 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
135 | + ); |
|
136 | + |
|
137 | + // Clean any buffer. |
|
138 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
139 | + @ob_clean(); |
|
140 | + |
|
141 | + // Send the success response. |
|
142 | + wp_send_json_success( $response ); |
|
143 | 143 | |
144 | 144 | } |
145 | 145 |
@@ -17,27 +17,27 @@ discard block |
||
17 | 17 | * @return array An array of WP_Post instances. |
18 | 18 | * @since 3.0.0 |
19 | 19 | */ |
20 | -function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array() ) { |
|
20 | +function wl_entity_get_by_title($title, $autocomplete = false, $include_alias = true, $limit = false, $schema_types = array()) { |
|
21 | 21 | |
22 | 22 | global $wpdb; |
23 | 23 | |
24 | 24 | $schema_type_query = ''; |
25 | 25 | |
26 | - if ( $schema_types ) { |
|
27 | - $schema_type_query = ' AND t.name IN (' . join( |
|
26 | + if ($schema_types) { |
|
27 | + $schema_type_query = ' AND t.name IN ('.join( |
|
28 | 28 | ',', |
29 | 29 | array_map( |
30 | - function ( $schema_type ) { |
|
31 | - return "'" . esc_sql( $schema_type ) . "'"; |
|
30 | + function($schema_type) { |
|
31 | + return "'".esc_sql($schema_type)."'"; |
|
32 | 32 | }, |
33 | 33 | $schema_types |
34 | 34 | ) |
35 | - ) . ')'; |
|
35 | + ).')'; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // Search by substring |
39 | - if ( $autocomplete ) { |
|
40 | - $title = '%' . $title . '%'; |
|
39 | + if ($autocomplete) { |
|
40 | + $title = '%'.$title.'%'; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // The title is a LIKE query. |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
58 | 58 | ); |
59 | 59 | |
60 | - if ( $include_alias ) { |
|
60 | + if ($include_alias) { |
|
61 | 61 | |
62 | 62 | $query .= ' UNION' |
63 | 63 | . " SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug" |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | } |
85 | 85 | |
86 | - if ( $limit ) { |
|
86 | + if ($limit) { |
|
87 | 87 | $query .= ' LIMIT %d'; |
88 | 88 | $params[] = $limit; |
89 | 89 | } |
@@ -107,31 +107,31 @@ discard block |
||
107 | 107 | // |
108 | 108 | // See https://github.com/insideout10/wordlift-plugin/issues/438. |
109 | 109 | // Get the title to search. |
110 | - if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
110 | + if (empty($_POST['title']) && empty($_GET['title'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
111 | 111 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
112 | 112 | @ob_clean(); |
113 | - wp_send_json_error( 'The title parameter is required.' ); |
|
113 | + wp_send_json_error('The title parameter is required.'); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // `wl_entity_metaboxes_utilities.js` still uses `GET`. |
117 | 117 | // |
118 | 118 | // See https://github.com/insideout10/wordlift-plugin/issues/438. |
119 | - $title = sanitize_text_field( wp_unslash( $_POST['title'] ? $_POST['title'] : $_GET['title'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
119 | + $title = sanitize_text_field(wp_unslash($_POST['title'] ? $_POST['title'] : $_GET['title'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing |
|
120 | 120 | |
121 | 121 | // Are we searching for a specific title or for a containing title? |
122 | - $autocomplete = isset( $_GET['autocomplete'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
122 | + $autocomplete = isset($_GET['autocomplete']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
123 | 123 | |
124 | 124 | // Are we searching also for the aliases? |
125 | - $include_alias = isset( $_GET['alias'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
125 | + $include_alias = isset($_GET['alias']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
126 | 126 | |
127 | 127 | // Get the edit link. |
128 | - $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME ); |
|
129 | - $edit_link = $post_type_object->_edit_link . '&action=edit'; |
|
128 | + $post_type_object = get_post_type_object(Wordlift_Entity_Service::TYPE_NAME); |
|
129 | + $edit_link = $post_type_object->_edit_link.'&action=edit'; |
|
130 | 130 | |
131 | 131 | // Prepare the response with the edit link. |
132 | 132 | $response = array( |
133 | 133 | 'edit_link' => $edit_link, |
134 | - 'results' => wl_entity_get_by_title( $title, $autocomplete, $include_alias ), |
|
134 | + 'results' => wl_entity_get_by_title($title, $autocomplete, $include_alias), |
|
135 | 135 | ); |
136 | 136 | |
137 | 137 | // Clean any buffer. |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | @ob_clean(); |
140 | 140 | |
141 | 141 | // Send the success response. |
142 | - wp_send_json_success( $response ); |
|
142 | + wp_send_json_success($response); |
|
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | -add_action( 'wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title' ); |
|
146 | +add_action('wp_ajax_entity_by_title', 'wl_entity_ajax_get_by_title'); |
@@ -4,60 +4,60 @@ |
||
4 | 4 | |
5 | 5 | class Context { |
6 | 6 | |
7 | - const POST = 0; |
|
8 | - const TERM = 1; |
|
9 | - const ADMIN_AJAX = 2; |
|
10 | - const UNKNOWN = -1; |
|
11 | - /** |
|
12 | - * @var $object_type int |
|
13 | - */ |
|
14 | - private $object_type; |
|
15 | - /** |
|
16 | - * @var $identifier int |
|
17 | - */ |
|
18 | - private $identifier; |
|
19 | - /** |
|
20 | - * @var $custom_fields Schema_Field_Group[] |
|
21 | - */ |
|
22 | - private $custom_fields; |
|
23 | - |
|
24 | - private static $pod_types_map = array( |
|
25 | - self::POST => 'post_type', |
|
26 | - self::TERM => 'taxonomy', |
|
27 | - ); |
|
28 | - |
|
29 | - /** |
|
30 | - * @param int $object_type |
|
31 | - * @param $identifier |
|
32 | - * @param $custom_fields |
|
33 | - */ |
|
34 | - public function __construct( $object_type, $identifier, $custom_fields ) { |
|
35 | - $this->object_type = $object_type; |
|
36 | - $this->identifier = $identifier; |
|
37 | - $this->custom_fields = $custom_fields; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return int |
|
42 | - */ |
|
43 | - public function get_object_type() { |
|
44 | - return $this->object_type; |
|
45 | - } |
|
46 | - |
|
47 | - public function get_pod_name() { |
|
48 | - if ( self::POST === $this->object_type ) { |
|
49 | - return get_post_type( $this->identifier ); |
|
50 | - } elseif ( self::TERM === $this->object_type ) { |
|
51 | - return get_term( $this->identifier )->taxonomy; |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - public function get_pod_type() { |
|
56 | - return self::$pod_types_map[ $this->object_type ]; |
|
57 | - } |
|
58 | - |
|
59 | - public function get_custom_fields() { |
|
60 | - return $this->custom_fields; |
|
61 | - } |
|
7 | + const POST = 0; |
|
8 | + const TERM = 1; |
|
9 | + const ADMIN_AJAX = 2; |
|
10 | + const UNKNOWN = -1; |
|
11 | + /** |
|
12 | + * @var $object_type int |
|
13 | + */ |
|
14 | + private $object_type; |
|
15 | + /** |
|
16 | + * @var $identifier int |
|
17 | + */ |
|
18 | + private $identifier; |
|
19 | + /** |
|
20 | + * @var $custom_fields Schema_Field_Group[] |
|
21 | + */ |
|
22 | + private $custom_fields; |
|
23 | + |
|
24 | + private static $pod_types_map = array( |
|
25 | + self::POST => 'post_type', |
|
26 | + self::TERM => 'taxonomy', |
|
27 | + ); |
|
28 | + |
|
29 | + /** |
|
30 | + * @param int $object_type |
|
31 | + * @param $identifier |
|
32 | + * @param $custom_fields |
|
33 | + */ |
|
34 | + public function __construct( $object_type, $identifier, $custom_fields ) { |
|
35 | + $this->object_type = $object_type; |
|
36 | + $this->identifier = $identifier; |
|
37 | + $this->custom_fields = $custom_fields; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return int |
|
42 | + */ |
|
43 | + public function get_object_type() { |
|
44 | + return $this->object_type; |
|
45 | + } |
|
46 | + |
|
47 | + public function get_pod_name() { |
|
48 | + if ( self::POST === $this->object_type ) { |
|
49 | + return get_post_type( $this->identifier ); |
|
50 | + } elseif ( self::TERM === $this->object_type ) { |
|
51 | + return get_term( $this->identifier )->taxonomy; |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + public function get_pod_type() { |
|
56 | + return self::$pod_types_map[ $this->object_type ]; |
|
57 | + } |
|
58 | + |
|
59 | + public function get_custom_fields() { |
|
60 | + return $this->custom_fields; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param $identifier |
32 | 32 | * @param $custom_fields |
33 | 33 | */ |
34 | - public function __construct( $object_type, $identifier, $custom_fields ) { |
|
34 | + public function __construct($object_type, $identifier, $custom_fields) { |
|
35 | 35 | $this->object_type = $object_type; |
36 | 36 | $this->identifier = $identifier; |
37 | 37 | $this->custom_fields = $custom_fields; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | public function get_pod_name() { |
48 | - if ( self::POST === $this->object_type ) { |
|
49 | - return get_post_type( $this->identifier ); |
|
50 | - } elseif ( self::TERM === $this->object_type ) { |
|
51 | - return get_term( $this->identifier )->taxonomy; |
|
48 | + if (self::POST === $this->object_type) { |
|
49 | + return get_post_type($this->identifier); |
|
50 | + } elseif (self::TERM === $this->object_type) { |
|
51 | + return get_term($this->identifier)->taxonomy; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | 55 | public function get_pod_type() { |
56 | - return self::$pod_types_map[ $this->object_type ]; |
|
56 | + return self::$pod_types_map[$this->object_type]; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function get_custom_fields() { |
@@ -4,12 +4,12 @@ |
||
4 | 4 | |
5 | 5 | interface FieldDefinition { |
6 | 6 | |
7 | - /** |
|
8 | - * Register the fields for the provided context in constructor. |
|
9 | - * |
|
10 | - * @return void |
|
11 | - */ |
|
12 | - public function register(); |
|
7 | + /** |
|
8 | + * Register the fields for the provided context in constructor. |
|
9 | + * |
|
10 | + * @return void |
|
11 | + */ |
|
12 | + public function register(); |
|
13 | 13 | |
14 | 14 | } |
15 | 15 |
@@ -10,27 +10,27 @@ |
||
10 | 10 | */ |
11 | 11 | class AllPodsDefiniton extends AbstractFieldDefiniton { |
12 | 12 | |
13 | - public function register() { |
|
14 | - |
|
15 | - add_action( 'init', array( $this, 'register_on_all_valid_post_types' ) ); |
|
16 | - add_action( 'setup_theme', array( $this, 'register_on_all_supported_taxonomies' ) ); |
|
17 | - } |
|
18 | - |
|
19 | - public function register_on_all_supported_taxonomies() { |
|
20 | - $context = $this->schema->get(); |
|
21 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
22 | - foreach ( $taxonomies as $taxonomy ) { |
|
23 | - $this->register_pod( $taxonomy, 'taxonomy', $context ); |
|
24 | - |
|
25 | - } |
|
26 | - } |
|
27 | - |
|
28 | - public function register_on_all_valid_post_types() { |
|
29 | - $context = $this->schema->get(); |
|
30 | - $supported_types = \Wordlift_Entity_Service::valid_entity_post_types(); |
|
31 | - foreach ( $supported_types as $supported_type ) { |
|
32 | - $this->register_pod( $supported_type, 'post_type', $context ); |
|
33 | - } |
|
34 | - } |
|
13 | + public function register() { |
|
14 | + |
|
15 | + add_action( 'init', array( $this, 'register_on_all_valid_post_types' ) ); |
|
16 | + add_action( 'setup_theme', array( $this, 'register_on_all_supported_taxonomies' ) ); |
|
17 | + } |
|
18 | + |
|
19 | + public function register_on_all_supported_taxonomies() { |
|
20 | + $context = $this->schema->get(); |
|
21 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
22 | + foreach ( $taxonomies as $taxonomy ) { |
|
23 | + $this->register_pod( $taxonomy, 'taxonomy', $context ); |
|
24 | + |
|
25 | + } |
|
26 | + } |
|
27 | + |
|
28 | + public function register_on_all_valid_post_types() { |
|
29 | + $context = $this->schema->get(); |
|
30 | + $supported_types = \Wordlift_Entity_Service::valid_entity_post_types(); |
|
31 | + foreach ( $supported_types as $supported_type ) { |
|
32 | + $this->register_pod( $supported_type, 'post_type', $context ); |
|
33 | + } |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | |
13 | 13 | public function register() { |
14 | 14 | |
15 | - add_action( 'init', array( $this, 'register_on_all_valid_post_types' ) ); |
|
16 | - add_action( 'setup_theme', array( $this, 'register_on_all_supported_taxonomies' ) ); |
|
15 | + add_action('init', array($this, 'register_on_all_valid_post_types')); |
|
16 | + add_action('setup_theme', array($this, 'register_on_all_supported_taxonomies')); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function register_on_all_supported_taxonomies() { |
20 | 20 | $context = $this->schema->get(); |
21 | 21 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
22 | - foreach ( $taxonomies as $taxonomy ) { |
|
23 | - $this->register_pod( $taxonomy, 'taxonomy', $context ); |
|
22 | + foreach ($taxonomies as $taxonomy) { |
|
23 | + $this->register_pod($taxonomy, 'taxonomy', $context); |
|
24 | 24 | |
25 | 25 | } |
26 | 26 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | public function register_on_all_valid_post_types() { |
29 | 29 | $context = $this->schema->get(); |
30 | 30 | $supported_types = \Wordlift_Entity_Service::valid_entity_post_types(); |
31 | - foreach ( $supported_types as $supported_type ) { |
|
32 | - $this->register_pod( $supported_type, 'post_type', $context ); |
|
31 | + foreach ($supported_types as $supported_type) { |
|
32 | + $this->register_pod($supported_type, 'post_type', $context); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 |
@@ -7,196 +7,196 @@ |
||
7 | 7 | |
8 | 8 | class Filters { |
9 | 9 | |
10 | - const FIELD_NAME = 'wlentity'; |
|
11 | - |
|
12 | - public function __construct() { |
|
13 | - |
|
14 | - pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
15 | - add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
16 | - add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
17 | - add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
18 | - add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
19 | - add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
20 | - |
|
21 | - add_action( |
|
22 | - 'pods_meta_save_taxonomy', |
|
23 | - function ( $data, $pod, $id, $groups, $term_id ) { |
|
24 | - $this->save_field( 'term', $term_id, $groups ); |
|
25 | - }, |
|
26 | - 10, |
|
27 | - 5 |
|
28 | - ); |
|
29 | - |
|
30 | - add_action( |
|
31 | - 'pods_meta_save_post', |
|
32 | - function ( $data, $pod, $id, $groups ) { |
|
33 | - $this->save_field( 'post', $id, $groups ); |
|
34 | - }, |
|
35 | - 10, |
|
36 | - 4 |
|
37 | - ); |
|
38 | - |
|
39 | - } |
|
40 | - |
|
41 | - private function save_field( $type, $identifier, $groups ) { |
|
42 | - |
|
43 | - $entity_fields = $this->filter_entity_fields( $groups ); |
|
44 | - |
|
45 | - foreach ( $entity_fields as $entity_field ) { |
|
46 | - delete_metadata( $type, $identifier, $entity_field ); |
|
47 | - $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
48 | - |
|
49 | - $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
50 | - |
|
51 | - if ( ! $data ) { |
|
52 | - continue; |
|
53 | - } |
|
54 | - $values = $data[ $key ]; |
|
55 | - |
|
56 | - foreach ( $values as $value ) { |
|
57 | - add_metadata( $type, $identifier, $entity_field, $value ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - private function filter_entity_fields( $groups ) { |
|
64 | - |
|
65 | - $pods = json_decode( wp_json_encode( $groups ), true ); |
|
66 | - |
|
67 | - $fields = array_reduce( |
|
68 | - $pods, |
|
69 | - function ( $carry, $item ) { |
|
70 | - return array_merge( $carry, $item['fields'] ); |
|
71 | - }, |
|
72 | - array() |
|
73 | - ); |
|
74 | - |
|
75 | - return array_map( |
|
76 | - function ( $item ) { |
|
77 | - return $item['name']; |
|
78 | - }, |
|
79 | - array_filter( |
|
80 | - $fields, |
|
81 | - function ( $item ) { |
|
82 | - return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
83 | - } |
|
84 | - ) |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - public function wl_pods_transform_data_for_pick_field( $item ) { |
|
89 | - |
|
90 | - $content = $item->get_content(); |
|
91 | - |
|
92 | - return array( |
|
93 | - 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
94 | - 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
95 | - 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
96 | - 'edit_link' => $content->get_edit_link(), |
|
97 | - 'link' => $content->get_permalink(), |
|
98 | - 'selected' => false, |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
103 | - |
|
104 | - if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
105 | - return $data; |
|
106 | - } |
|
107 | - |
|
108 | - $query = sanitize_text_field( wp_unslash( isset( $_REQUEST['query'] ) ? $_REQUEST['query'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
109 | - $query_service = Entity_Query_Service::get_instance(); |
|
110 | - |
|
111 | - return array_map( |
|
112 | - array( |
|
113 | - $this, |
|
114 | - 'wl_pods_transform_data_for_pick_field', |
|
115 | - ), |
|
116 | - $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
117 | - ); |
|
118 | - |
|
119 | - } |
|
120 | - |
|
121 | - public function data_filter( $data, $args ) { |
|
122 | - |
|
123 | - $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
124 | - $field_data = $args_arr['options']; |
|
125 | - |
|
126 | - if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
127 | - return $data; |
|
128 | - } |
|
129 | - |
|
130 | - if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
131 | - || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
132 | - return $data; |
|
133 | - } |
|
134 | - |
|
135 | - $name = $field_data['name']; |
|
136 | - $identifier = $args->id; |
|
137 | - $type = $args_arr['pod']['data']['pod_data']['type']; |
|
10 | + const FIELD_NAME = 'wlentity'; |
|
11 | + |
|
12 | + public function __construct() { |
|
13 | + |
|
14 | + pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
15 | + add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
16 | + add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
17 | + add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
18 | + add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
19 | + add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
20 | + |
|
21 | + add_action( |
|
22 | + 'pods_meta_save_taxonomy', |
|
23 | + function ( $data, $pod, $id, $groups, $term_id ) { |
|
24 | + $this->save_field( 'term', $term_id, $groups ); |
|
25 | + }, |
|
26 | + 10, |
|
27 | + 5 |
|
28 | + ); |
|
29 | + |
|
30 | + add_action( |
|
31 | + 'pods_meta_save_post', |
|
32 | + function ( $data, $pod, $id, $groups ) { |
|
33 | + $this->save_field( 'post', $id, $groups ); |
|
34 | + }, |
|
35 | + 10, |
|
36 | + 4 |
|
37 | + ); |
|
38 | + |
|
39 | + } |
|
40 | + |
|
41 | + private function save_field( $type, $identifier, $groups ) { |
|
42 | + |
|
43 | + $entity_fields = $this->filter_entity_fields( $groups ); |
|
44 | + |
|
45 | + foreach ( $entity_fields as $entity_field ) { |
|
46 | + delete_metadata( $type, $identifier, $entity_field ); |
|
47 | + $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
48 | + |
|
49 | + $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
50 | + |
|
51 | + if ( ! $data ) { |
|
52 | + continue; |
|
53 | + } |
|
54 | + $values = $data[ $key ]; |
|
55 | + |
|
56 | + foreach ( $values as $value ) { |
|
57 | + add_metadata( $type, $identifier, $entity_field, $value ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + private function filter_entity_fields( $groups ) { |
|
64 | + |
|
65 | + $pods = json_decode( wp_json_encode( $groups ), true ); |
|
66 | + |
|
67 | + $fields = array_reduce( |
|
68 | + $pods, |
|
69 | + function ( $carry, $item ) { |
|
70 | + return array_merge( $carry, $item['fields'] ); |
|
71 | + }, |
|
72 | + array() |
|
73 | + ); |
|
74 | + |
|
75 | + return array_map( |
|
76 | + function ( $item ) { |
|
77 | + return $item['name']; |
|
78 | + }, |
|
79 | + array_filter( |
|
80 | + $fields, |
|
81 | + function ( $item ) { |
|
82 | + return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
83 | + } |
|
84 | + ) |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + public function wl_pods_transform_data_for_pick_field( $item ) { |
|
89 | + |
|
90 | + $content = $item->get_content(); |
|
91 | + |
|
92 | + return array( |
|
93 | + 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
94 | + 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
|
95 | + 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
96 | + 'edit_link' => $content->get_edit_link(), |
|
97 | + 'link' => $content->get_permalink(), |
|
98 | + 'selected' => false, |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
103 | + |
|
104 | + if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
105 | + return $data; |
|
106 | + } |
|
107 | + |
|
108 | + $query = sanitize_text_field( wp_unslash( isset( $_REQUEST['query'] ) ? $_REQUEST['query'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
109 | + $query_service = Entity_Query_Service::get_instance(); |
|
110 | + |
|
111 | + return array_map( |
|
112 | + array( |
|
113 | + $this, |
|
114 | + 'wl_pods_transform_data_for_pick_field', |
|
115 | + ), |
|
116 | + $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
117 | + ); |
|
118 | + |
|
119 | + } |
|
120 | + |
|
121 | + public function data_filter( $data, $args ) { |
|
122 | + |
|
123 | + $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
124 | + $field_data = $args_arr['options']; |
|
125 | + |
|
126 | + if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
127 | + return $data; |
|
128 | + } |
|
129 | + |
|
130 | + if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
131 | + || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
132 | + return $data; |
|
133 | + } |
|
134 | + |
|
135 | + $name = $field_data['name']; |
|
136 | + $identifier = $args->id; |
|
137 | + $type = $args_arr['pod']['data']['pod_data']['type']; |
|
138 | 138 | |
139 | - if ( 'post_type' === $type ) { |
|
140 | - $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
141 | - } elseif ( 'taxonomy' === $type ) { |
|
142 | - $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
143 | - } |
|
144 | - |
|
145 | - return $data; |
|
146 | - } |
|
147 | - |
|
148 | - public function ajax_filter( $result, $name, $value, $field_options ) { |
|
149 | - |
|
150 | - if ( ! isset( $field_options['pick_object'] ) ) { |
|
151 | - return $result; |
|
152 | - } |
|
153 | - |
|
154 | - return self::FIELD_NAME === $field_options['pick_object']; |
|
155 | - } |
|
156 | - |
|
157 | - public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
158 | - |
|
159 | - if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
160 | - return $info; |
|
161 | - } |
|
162 | - // We need to return an non empty array here to prevent pods from querying a table. |
|
163 | - // This is necessary to prevent errors on ui. |
|
164 | - return array( 'foo' => 'bar' ); |
|
165 | - } |
|
166 | - |
|
167 | - public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
168 | - |
|
169 | - $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
170 | - |
|
171 | - $query_service = Entity_Query_Service::get_instance(); |
|
172 | - |
|
173 | - if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
174 | - && is_string( $object_params['options']['pick_object'] ) |
|
175 | - && self::FIELD_NAME === $object_params['options']['pick_object'] |
|
176 | - && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
177 | - && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
178 | - |
|
179 | - $type = $object_params['pod']['data']['pod_data']['type']; |
|
180 | - $linked_entities = array(); |
|
181 | - if ( 'post_type' === $type ) { |
|
182 | - $linked_entities = get_post_meta( $id, $name ); |
|
183 | - } elseif ( 'taxonomy' === $type ) { |
|
184 | - $linked_entities = get_term_meta( $id, $name ); |
|
185 | - } |
|
186 | - $data = array(); |
|
187 | - $linked_entities = $query_service->get( $linked_entities ); |
|
188 | - foreach ( $linked_entities as $linked_entity ) { |
|
189 | - $content = $linked_entity->get_content(); |
|
190 | - $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
191 | - $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
192 | - $data[ $id ] = $text; |
|
193 | - } |
|
194 | - |
|
195 | - return $data; |
|
196 | - } |
|
197 | - |
|
198 | - return $_; |
|
139 | + if ( 'post_type' === $type ) { |
|
140 | + $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
141 | + } elseif ( 'taxonomy' === $type ) { |
|
142 | + $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
143 | + } |
|
144 | + |
|
145 | + return $data; |
|
146 | + } |
|
147 | + |
|
148 | + public function ajax_filter( $result, $name, $value, $field_options ) { |
|
149 | + |
|
150 | + if ( ! isset( $field_options['pick_object'] ) ) { |
|
151 | + return $result; |
|
152 | + } |
|
153 | + |
|
154 | + return self::FIELD_NAME === $field_options['pick_object']; |
|
155 | + } |
|
156 | + |
|
157 | + public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
158 | + |
|
159 | + if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
160 | + return $info; |
|
161 | + } |
|
162 | + // We need to return an non empty array here to prevent pods from querying a table. |
|
163 | + // This is necessary to prevent errors on ui. |
|
164 | + return array( 'foo' => 'bar' ); |
|
165 | + } |
|
166 | + |
|
167 | + public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
168 | + |
|
169 | + $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
170 | + |
|
171 | + $query_service = Entity_Query_Service::get_instance(); |
|
172 | + |
|
173 | + if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
174 | + && is_string( $object_params['options']['pick_object'] ) |
|
175 | + && self::FIELD_NAME === $object_params['options']['pick_object'] |
|
176 | + && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
177 | + && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
178 | + |
|
179 | + $type = $object_params['pod']['data']['pod_data']['type']; |
|
180 | + $linked_entities = array(); |
|
181 | + if ( 'post_type' === $type ) { |
|
182 | + $linked_entities = get_post_meta( $id, $name ); |
|
183 | + } elseif ( 'taxonomy' === $type ) { |
|
184 | + $linked_entities = get_term_meta( $id, $name ); |
|
185 | + } |
|
186 | + $data = array(); |
|
187 | + $linked_entities = $query_service->get( $linked_entities ); |
|
188 | + foreach ( $linked_entities as $linked_entity ) { |
|
189 | + $content = $linked_entity->get_content(); |
|
190 | + $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
191 | + $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
192 | + $data[ $id ] = $text; |
|
193 | + } |
|
194 | + |
|
195 | + return $data; |
|
196 | + } |
|
197 | + |
|
198 | + return $_; |
|
199 | 199 | |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | 202 | } |
@@ -11,17 +11,17 @@ discard block |
||
11 | 11 | |
12 | 12 | public function __construct() { |
13 | 13 | |
14 | - pods_register_related_object( self::FIELD_NAME, 'WordLift Entity', array( 'simple' => false ) ); |
|
15 | - add_filter( 'pods_form_ui_field_pick_ajax', array( $this, 'ajax_filter' ), 10, 4 ); |
|
16 | - add_filter( 'pods_api_get_table_info', array( $this, 'table_info_filter' ), 10, 6 ); |
|
17 | - add_filter( 'pods_field_pick_object_data', array( $this, 'field_options_filter' ), 10, 7 ); |
|
18 | - add_filter( 'pods_field_dfv_data', array( $this, 'data_filter' ), 10, 2 ); |
|
19 | - add_filter( 'pods_field_pick_data_ajax', array( $this, 'admin_ajax_filter' ), 10, 4 ); |
|
14 | + pods_register_related_object(self::FIELD_NAME, 'WordLift Entity', array('simple' => false)); |
|
15 | + add_filter('pods_form_ui_field_pick_ajax', array($this, 'ajax_filter'), 10, 4); |
|
16 | + add_filter('pods_api_get_table_info', array($this, 'table_info_filter'), 10, 6); |
|
17 | + add_filter('pods_field_pick_object_data', array($this, 'field_options_filter'), 10, 7); |
|
18 | + add_filter('pods_field_dfv_data', array($this, 'data_filter'), 10, 2); |
|
19 | + add_filter('pods_field_pick_data_ajax', array($this, 'admin_ajax_filter'), 10, 4); |
|
20 | 20 | |
21 | 21 | add_action( |
22 | 22 | 'pods_meta_save_taxonomy', |
23 | - function ( $data, $pod, $id, $groups, $term_id ) { |
|
24 | - $this->save_field( 'term', $term_id, $groups ); |
|
23 | + function($data, $pod, $id, $groups, $term_id) { |
|
24 | + $this->save_field('term', $term_id, $groups); |
|
25 | 25 | }, |
26 | 26 | 10, |
27 | 27 | 5 |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | |
30 | 30 | add_action( |
31 | 31 | 'pods_meta_save_post', |
32 | - function ( $data, $pod, $id, $groups ) { |
|
33 | - $this->save_field( 'post', $id, $groups ); |
|
32 | + function($data, $pod, $id, $groups) { |
|
33 | + $this->save_field('post', $id, $groups); |
|
34 | 34 | }, |
35 | 35 | 10, |
36 | 36 | 4 |
@@ -38,74 +38,74 @@ discard block |
||
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | - private function save_field( $type, $identifier, $groups ) { |
|
41 | + private function save_field($type, $identifier, $groups) { |
|
42 | 42 | |
43 | - $entity_fields = $this->filter_entity_fields( $groups ); |
|
43 | + $entity_fields = $this->filter_entity_fields($groups); |
|
44 | 44 | |
45 | - foreach ( $entity_fields as $entity_field ) { |
|
46 | - delete_metadata( $type, $identifier, $entity_field ); |
|
47 | - $key = sprintf( 'pods_meta_%s', $entity_field ); |
|
45 | + foreach ($entity_fields as $entity_field) { |
|
46 | + delete_metadata($type, $identifier, $entity_field); |
|
47 | + $key = sprintf('pods_meta_%s', $entity_field); |
|
48 | 48 | |
49 | - $data = filter_var_array( $_REQUEST, array( $key => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
49 | + $data = filter_var_array($_REQUEST, array($key => array('flags' => FILTER_REQUIRE_ARRAY))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
50 | 50 | |
51 | - if ( ! $data ) { |
|
51 | + if ( ! $data) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | - $values = $data[ $key ]; |
|
54 | + $values = $data[$key]; |
|
55 | 55 | |
56 | - foreach ( $values as $value ) { |
|
57 | - add_metadata( $type, $identifier, $entity_field, $value ); |
|
56 | + foreach ($values as $value) { |
|
57 | + add_metadata($type, $identifier, $entity_field, $value); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
62 | 62 | |
63 | - private function filter_entity_fields( $groups ) { |
|
63 | + private function filter_entity_fields($groups) { |
|
64 | 64 | |
65 | - $pods = json_decode( wp_json_encode( $groups ), true ); |
|
65 | + $pods = json_decode(wp_json_encode($groups), true); |
|
66 | 66 | |
67 | 67 | $fields = array_reduce( |
68 | 68 | $pods, |
69 | - function ( $carry, $item ) { |
|
70 | - return array_merge( $carry, $item['fields'] ); |
|
69 | + function($carry, $item) { |
|
70 | + return array_merge($carry, $item['fields']); |
|
71 | 71 | }, |
72 | 72 | array() |
73 | 73 | ); |
74 | 74 | |
75 | 75 | return array_map( |
76 | - function ( $item ) { |
|
76 | + function($item) { |
|
77 | 77 | return $item['name']; |
78 | 78 | }, |
79 | 79 | array_filter( |
80 | 80 | $fields, |
81 | - function ( $item ) { |
|
82 | - return is_array( $item ) && isset( $item['pick_object'] ) && self::FIELD_NAME === $item['pick_object']; |
|
81 | + function($item) { |
|
82 | + return is_array($item) && isset($item['pick_object']) && self::FIELD_NAME === $item['pick_object']; |
|
83 | 83 | } |
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | } |
87 | 87 | |
88 | - public function wl_pods_transform_data_for_pick_field( $item ) { |
|
88 | + public function wl_pods_transform_data_for_pick_field($item) { |
|
89 | 89 | |
90 | 90 | $content = $item->get_content(); |
91 | 91 | |
92 | 92 | return array( |
93 | - 'id' => sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ), |
|
93 | + 'id' => sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()), |
|
94 | 94 | 'icon' => 'https:\/\/wordlift.localhost\/wp-content\/plugins\/wordlift\/images\/svg\/wl-vocabulary-icon.svg', |
95 | - 'name' => $item->get_title() . ' (' . $item->get_schema_type() . ')', |
|
95 | + 'name' => $item->get_title().' ('.$item->get_schema_type().')', |
|
96 | 96 | 'edit_link' => $content->get_edit_link(), |
97 | 97 | 'link' => $content->get_permalink(), |
98 | 98 | 'selected' => false, |
99 | 99 | ); |
100 | 100 | } |
101 | 101 | |
102 | - public function admin_ajax_filter( $data, $name, $_, $field ) { |
|
102 | + public function admin_ajax_filter($data, $name, $_, $field) { |
|
103 | 103 | |
104 | - if ( ( ! $field instanceof \Pods\Whatsit\Field ) || $field->get_arg( 'pick_object', false ) !== self::FIELD_NAME ) { |
|
104 | + if (( ! $field instanceof \Pods\Whatsit\Field) || $field->get_arg('pick_object', false) !== self::FIELD_NAME) { |
|
105 | 105 | return $data; |
106 | 106 | } |
107 | 107 | |
108 | - $query = sanitize_text_field( wp_unslash( isset( $_REQUEST['query'] ) ? $_REQUEST['query'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
108 | + $query = sanitize_text_field(wp_unslash(isset($_REQUEST['query']) ? $_REQUEST['query'] : '')); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
109 | 109 | $query_service = Entity_Query_Service::get_instance(); |
110 | 110 | |
111 | 111 | return array_map( |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | $this, |
114 | 114 | 'wl_pods_transform_data_for_pick_field', |
115 | 115 | ), |
116 | - $query_service->query( $query, $field->get_arg( 'supported_schema_types', array( 'Thing' ) ) ) |
|
116 | + $query_service->query($query, $field->get_arg('supported_schema_types', array('Thing'))) |
|
117 | 117 | ); |
118 | 118 | |
119 | 119 | } |
120 | 120 | |
121 | - public function data_filter( $data, $args ) { |
|
121 | + public function data_filter($data, $args) { |
|
122 | 122 | |
123 | - $args_arr = json_decode( wp_json_encode( $args ), true ); |
|
123 | + $args_arr = json_decode(wp_json_encode($args), true); |
|
124 | 124 | $field_data = $args_arr['options']; |
125 | 125 | |
126 | - if ( ! isset( $field_data['pick_object'] ) || self::FIELD_NAME !== $field_data['pick_object'] ) { |
|
126 | + if ( ! isset($field_data['pick_object']) || self::FIELD_NAME !== $field_data['pick_object']) { |
|
127 | 127 | return $data; |
128 | 128 | } |
129 | 129 | |
130 | - if ( ! isset( $args_arr['pod']['data']['pod_data']['type'] ) |
|
131 | - || ! is_string( $args_arr['pod']['data']['pod_data']['type'] ) ) { |
|
130 | + if ( ! isset($args_arr['pod']['data']['pod_data']['type']) |
|
131 | + || ! is_string($args_arr['pod']['data']['pod_data']['type'])) { |
|
132 | 132 | return $data; |
133 | 133 | } |
134 | 134 | |
@@ -136,60 +136,60 @@ discard block |
||
136 | 136 | $identifier = $args->id; |
137 | 137 | $type = $args_arr['pod']['data']['pod_data']['type']; |
138 | 138 | |
139 | - if ( 'post_type' === $type ) { |
|
140 | - $data['fieldValue'] = get_post_meta( $identifier, $name ); |
|
141 | - } elseif ( 'taxonomy' === $type ) { |
|
142 | - $data['fieldValue'] = get_term_meta( $identifier, $name ); |
|
139 | + if ('post_type' === $type) { |
|
140 | + $data['fieldValue'] = get_post_meta($identifier, $name); |
|
141 | + } elseif ('taxonomy' === $type) { |
|
142 | + $data['fieldValue'] = get_term_meta($identifier, $name); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | return $data; |
146 | 146 | } |
147 | 147 | |
148 | - public function ajax_filter( $result, $name, $value, $field_options ) { |
|
148 | + public function ajax_filter($result, $name, $value, $field_options) { |
|
149 | 149 | |
150 | - if ( ! isset( $field_options['pick_object'] ) ) { |
|
150 | + if ( ! isset($field_options['pick_object'])) { |
|
151 | 151 | return $result; |
152 | 152 | } |
153 | 153 | |
154 | 154 | return self::FIELD_NAME === $field_options['pick_object']; |
155 | 155 | } |
156 | 156 | |
157 | - public function table_info_filter( $info, $object_type, $object, $name, $pod, $field ) { |
|
157 | + public function table_info_filter($info, $object_type, $object, $name, $pod, $field) { |
|
158 | 158 | |
159 | - if ( $field === null || self::FIELD_NAME !== $field->get_arg( 'pick_object', false ) ) { |
|
159 | + if ($field === null || self::FIELD_NAME !== $field->get_arg('pick_object', false)) { |
|
160 | 160 | return $info; |
161 | 161 | } |
162 | 162 | // We need to return an non empty array here to prevent pods from querying a table. |
163 | 163 | // This is necessary to prevent errors on ui. |
164 | - return array( 'foo' => 'bar' ); |
|
164 | + return array('foo' => 'bar'); |
|
165 | 165 | } |
166 | 166 | |
167 | - public function field_options_filter( $_, $name, $value, $options, $pod, $id, $object_params ) { |
|
167 | + public function field_options_filter($_, $name, $value, $options, $pod, $id, $object_params) { |
|
168 | 168 | |
169 | - $object_params = json_decode( wp_json_encode( $object_params ), true ); |
|
169 | + $object_params = json_decode(wp_json_encode($object_params), true); |
|
170 | 170 | |
171 | 171 | $query_service = Entity_Query_Service::get_instance(); |
172 | 172 | |
173 | - if ( is_array( $object_params ) && isset( $object_params['options']['pick_object'] ) |
|
174 | - && is_string( $object_params['options']['pick_object'] ) |
|
173 | + if (is_array($object_params) && isset($object_params['options']['pick_object']) |
|
174 | + && is_string($object_params['options']['pick_object']) |
|
175 | 175 | && self::FIELD_NAME === $object_params['options']['pick_object'] |
176 | - && isset( $object_params['pod']['data']['pod_data']['type'] ) |
|
177 | - && is_string( $object_params['pod']['data']['pod_data']['type'] ) ) { |
|
176 | + && isset($object_params['pod']['data']['pod_data']['type']) |
|
177 | + && is_string($object_params['pod']['data']['pod_data']['type'])) { |
|
178 | 178 | |
179 | 179 | $type = $object_params['pod']['data']['pod_data']['type']; |
180 | 180 | $linked_entities = array(); |
181 | - if ( 'post_type' === $type ) { |
|
182 | - $linked_entities = get_post_meta( $id, $name ); |
|
183 | - } elseif ( 'taxonomy' === $type ) { |
|
184 | - $linked_entities = get_term_meta( $id, $name ); |
|
181 | + if ('post_type' === $type) { |
|
182 | + $linked_entities = get_post_meta($id, $name); |
|
183 | + } elseif ('taxonomy' === $type) { |
|
184 | + $linked_entities = get_term_meta($id, $name); |
|
185 | 185 | } |
186 | 186 | $data = array(); |
187 | - $linked_entities = $query_service->get( $linked_entities ); |
|
188 | - foreach ( $linked_entities as $linked_entity ) { |
|
187 | + $linked_entities = $query_service->get($linked_entities); |
|
188 | + foreach ($linked_entities as $linked_entity) { |
|
189 | 189 | $content = $linked_entity->get_content(); |
190 | - $id = sprintf( '%s_%d', Object_Type_Enum::to_string( $content->get_object_type_enum() ), $content->get_id() ); |
|
191 | - $text = $linked_entity->get_title() . ' (' . $linked_entity->get_schema_type() . ')'; |
|
192 | - $data[ $id ] = $text; |
|
190 | + $id = sprintf('%s_%d', Object_Type_Enum::to_string($content->get_object_type_enum()), $content->get_id()); |
|
191 | + $text = $linked_entity->get_title().' ('.$linked_entity->get_schema_type().')'; |
|
192 | + $data[$id] = $text; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | return $data; |
@@ -6,307 +6,307 @@ |
||
6 | 6 | use Wordlift\Vocabulary\Terms_Compat; |
7 | 7 | |
8 | 8 | abstract class AbstractFieldDefiniton implements FieldDefinition { |
9 | - /** |
|
10 | - * @var \Wordlift\Modules\Pods\Schema |
|
11 | - */ |
|
12 | - protected $schema; |
|
13 | - |
|
14 | - /** |
|
15 | - * @param \Wordlift\Modules\Pods\Schema $schema |
|
16 | - * |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct( $schema ) { |
|
20 | - $this->schema = $schema; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @param $name string |
|
25 | - * @param $type string |
|
26 | - * @param $context Context |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - protected function register_pod( $name, $type, $context ) { |
|
31 | - $pod_id = intval( substr( md5( $type . '_' . $name ), 0, 8 ), 16 ); |
|
32 | - $pod = $this->pod( $pod_id, $name, $type ); |
|
33 | - $schema_field_groups = $context->get_custom_fields(); |
|
34 | - |
|
35 | - if ( ! is_array( $schema_field_groups ) ) { |
|
36 | - return; |
|
37 | - } |
|
38 | - |
|
39 | - foreach ( $schema_field_groups as $schema_field_group ) { |
|
40 | - $custom_fields = $schema_field_group->get_custom_fields(); |
|
41 | - if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
42 | - $this->group( |
|
43 | - $schema_field_group->get_schema_type(), |
|
44 | - $pod, |
|
45 | - $this->group_fields( |
|
46 | - ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - protected function text() { |
|
55 | - return array( |
|
56 | - 'description' => '', |
|
57 | - 'weight' => 0, |
|
58 | - 'type' => 'text', |
|
59 | - 'sister_id' => '-- Select One --', |
|
60 | - 'rest_route' => '/pods/v1/fields', |
|
61 | - 'required' => '0', |
|
62 | - 'text_allowed_html_tags' => 'strong em a ul ol li b i', |
|
63 | - 'text_max_length' => '255', |
|
64 | - 'roles_allowed' => 'administrator', |
|
65 | - 'rest_pick_response' => 'array', |
|
66 | - 'rest_pick_depth' => '1', |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - protected function relationship( $name, $field_data ) { |
|
71 | - |
|
72 | - $supported_schema_types = $field_data['constraints']['uri_type']; |
|
73 | - |
|
74 | - if ( ! is_array( $supported_schema_types ) ) { |
|
75 | - $supported_schema_types = array( $supported_schema_types ); |
|
76 | - } |
|
77 | - |
|
78 | - return array( |
|
79 | - 'description' => '', |
|
80 | - 'weight' => 0, |
|
81 | - 'type' => 'pick', |
|
82 | - 'pick_object' => 'wlentity', |
|
83 | - 'sister_id' => '-- Select One --', |
|
84 | - 'rest_route' => '/pods/v1/fields', |
|
85 | - 'pick_table' => '-- Select One --', |
|
86 | - 'required' => '0', |
|
87 | - 'repeatable' => '0', |
|
88 | - 'pick_format_type' => 'single', |
|
89 | - 'pick_format_single' => 'autocomplete', |
|
90 | - 'pick_format_multi' => 'list', |
|
91 | - 'pick_display_format_multi' => 'autocomplete', |
|
92 | - 'pick_display_format_separator' => ', ', |
|
93 | - 'pick_allow_add_new' => '1', |
|
94 | - 'pick_taggable' => '0', |
|
95 | - 'pick_show_icon' => '1', |
|
96 | - 'pick_show_edit_link' => '1', |
|
97 | - 'pick_show_view_link' => '1', |
|
98 | - 'pick_limit' => '0', |
|
99 | - 'pick_user_role' => 'Administrator', |
|
100 | - 'pick_post_status' => 'publish', |
|
101 | - 'pick_post_author' => '0', |
|
102 | - 'roles_allowed' => 'administrator', |
|
103 | - 'rest_pick_response' => 'array', |
|
104 | - 'rest_pick_depth' => '1', |
|
105 | - 'supported_schema_types' => $supported_schema_types, |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
110 | - $field['repeatable'] = 1; |
|
111 | - $field['repeatable_add_new_label'] = $repeatable_label; |
|
112 | - |
|
113 | - return $field; |
|
114 | - } |
|
115 | - |
|
116 | - protected function website() { |
|
117 | - return array( |
|
118 | - 'description' => '', |
|
119 | - 'weight' => 0, |
|
120 | - 'type' => 'website', |
|
121 | - 'sister_id' => '-- Select One --', |
|
122 | - 'rest_route' => '/pods/v1/fields', |
|
123 | - 'required' => '0', |
|
124 | - 'repeatable' => '0', |
|
125 | - 'roles_allowed' => 'administrator', |
|
126 | - 'rest_pick_response' => 'array', |
|
127 | - 'rest_pick_depth' => '1', |
|
128 | - 'website_format' => 'normal', |
|
129 | - 'website_allow_port' => '0', |
|
130 | - 'website_clickable' => '0', |
|
131 | - 'website_new_window' => '0', |
|
132 | - 'website_nofollow' => '0', |
|
133 | - 'website_max_length' => '255', |
|
134 | - 'website_html5' => '0', |
|
135 | - ); |
|
136 | - } |
|
137 | - |
|
138 | - protected function group_fields( ...$fields ) { |
|
139 | - $result = array(); |
|
140 | - array_map( |
|
141 | - function ( $item ) use ( &$result ) { |
|
142 | - $field_name = $item['name']; |
|
143 | - $result[ $field_name ] = $item; |
|
144 | - }, |
|
145 | - $fields |
|
146 | - ); |
|
147 | - |
|
148 | - return $result; |
|
149 | - } |
|
150 | - |
|
151 | - protected function group( $name, $pod, $group_fields ) { |
|
152 | - $group = array( |
|
153 | - 'name' => $name, |
|
154 | - 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
155 | - 'description' => '', |
|
156 | - 'weight' => 0, |
|
157 | - |
|
158 | - ); |
|
159 | - pods_register_group( $group, $pod['name'], $group_fields ); |
|
160 | - } |
|
161 | - |
|
162 | - protected function pod( $pod_id, $name, $type ) { |
|
163 | - $pod = array( |
|
164 | - 'name' => $name, |
|
165 | - 'label' => $this->format_label( $name ), |
|
166 | - 'description' => '', |
|
167 | - 'type' => $type, |
|
168 | - 'storage' => 'meta', |
|
169 | - 'id' => $pod_id, |
|
170 | - 'object' => $name, |
|
171 | - ); |
|
172 | - |
|
173 | - pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
174 | - |
|
175 | - return $pod; |
|
176 | - } |
|
177 | - |
|
178 | - protected function register_on_all_supported_taxonomies() { |
|
179 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
180 | - foreach ( $taxonomies as $taxonomy ) { |
|
181 | - $this->register_pod( $taxonomy, 'taxonomy' ); |
|
182 | - |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - protected function get_field_by_type( $name, $type, $field_data ) { |
|
187 | - if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
188 | - return $this->relationship( $name, $field_data ); |
|
189 | - } elseif ( 'uri' === $type ) { |
|
190 | - return $this->website(); |
|
191 | - } elseif ( 'string' === $type ) { |
|
192 | - return $this->text(); |
|
193 | - } elseif ( 'double' === $type ) { |
|
194 | - return $this->number( $name, 2 ); |
|
195 | - } elseif ( 'date' === $type ) { |
|
196 | - return $this->datetime(); |
|
197 | - } elseif ( 'multiline' === $type ) { |
|
198 | - return $this->multiline(); |
|
199 | - } else { |
|
200 | - return $this->text(); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - protected function datetime() { |
|
205 | - return array( |
|
206 | - 'description' => '', |
|
207 | - 'weight' => 2, |
|
208 | - 'type' => 'datetime', |
|
209 | - 'sister_id' => '-- Select One --', |
|
210 | - 'rest_route' => '/pods/v1/fields', |
|
211 | - 'required' => '0', |
|
212 | - 'repeatable' => '0', |
|
213 | - 'datetime_type' => 'format', |
|
214 | - 'datetime_format' => 'ymd_slash', |
|
215 | - 'datetime_time_type' => '24', |
|
216 | - 'datetime_time_format' => 'h_mma', |
|
217 | - 'datetime_time_format_24' => 'hh_mm', |
|
218 | - 'datetime_allow_empty' => '1', |
|
219 | - 'datetime_html5' => '0', |
|
220 | - 'roles_allowed' => 'administrator', |
|
221 | - 'rest_pick_response' => 'array', |
|
222 | - 'rest_pick_depth' => '1', |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - protected function number( $name, $decimals = 0 ) { |
|
227 | - return array( |
|
228 | - 'description' => '', |
|
229 | - 'weight' => 1, |
|
230 | - 'type' => 'number', |
|
231 | - 'sister_id' => '-- Select One --', |
|
232 | - 'rest_route' => '/pods/v1/fields', |
|
233 | - 'required' => '0', |
|
234 | - 'repeatable' => '0', |
|
235 | - 'number_format_type' => 'number', |
|
236 | - 'number_format' => 'i18n', |
|
237 | - 'number_decimals' => $decimals, |
|
238 | - 'number_format_soft' => '0', |
|
239 | - 'number_step' => '2', |
|
240 | - 'number_max_length' => '0', |
|
241 | - 'number_html5' => '0', |
|
242 | - 'roles_allowed' => 'administrator', |
|
243 | - 'rest_pick_response' => 'array', |
|
244 | - 'rest_pick_depth' => '1', |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - protected function multiline() { |
|
249 | - return array( |
|
250 | - 'description' => '', |
|
251 | - 'weight' => 3, |
|
252 | - 'type' => 'paragraph', |
|
253 | - 'sister_id' => '-- Select One --', |
|
254 | - 'rest_route' => '/pods/v1/fields', |
|
255 | - 'required' => '0', |
|
256 | - 'repeatable' => '0', |
|
257 | - 'paragraph_allowed_html_tags' => 'strong em a ul ol li b i', |
|
258 | - 'paragraph_max_length' => '-1', |
|
259 | - 'roles_allowed' => 'administrator', |
|
260 | - 'rest_pick_response' => 'array', |
|
261 | - 'rest_pick_depth' => '1', |
|
262 | - ); |
|
263 | - } |
|
264 | - |
|
265 | - protected function may_be_repeatable( $custom_field, $field ) { |
|
266 | - $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
267 | - if ( $repeatable ) { |
|
268 | - return $this->repeatable( $field ); |
|
269 | - } |
|
270 | - |
|
271 | - return $field; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @return array |
|
276 | - * A function which defines these pods on the edit post screen. |
|
277 | - */ |
|
278 | - protected function custom_field_to_pod_field( $custom_field ) { |
|
279 | - |
|
280 | - $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
281 | - $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
282 | - |
|
283 | - return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
284 | - } |
|
285 | - |
|
286 | - protected function wordlift_css_class( $field ) { |
|
287 | - $field['class'] = 'wordlift'; |
|
288 | - |
|
289 | - return $field; |
|
290 | - } |
|
291 | - |
|
292 | - protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
293 | - |
|
294 | - $pod_fields = array(); |
|
295 | - |
|
296 | - foreach ( $custom_fields as $name => $custom_field ) { |
|
297 | - $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
298 | - 'pod_id' => $pod_id, |
|
299 | - 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
300 | - 'name' => $name, |
|
301 | - 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
302 | - ); |
|
303 | - } |
|
304 | - |
|
305 | - return array_values( $pod_fields ); |
|
306 | - } |
|
307 | - |
|
308 | - protected function format_label( $name ) { |
|
309 | - return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
310 | - } |
|
9 | + /** |
|
10 | + * @var \Wordlift\Modules\Pods\Schema |
|
11 | + */ |
|
12 | + protected $schema; |
|
13 | + |
|
14 | + /** |
|
15 | + * @param \Wordlift\Modules\Pods\Schema $schema |
|
16 | + * |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct( $schema ) { |
|
20 | + $this->schema = $schema; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @param $name string |
|
25 | + * @param $type string |
|
26 | + * @param $context Context |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + protected function register_pod( $name, $type, $context ) { |
|
31 | + $pod_id = intval( substr( md5( $type . '_' . $name ), 0, 8 ), 16 ); |
|
32 | + $pod = $this->pod( $pod_id, $name, $type ); |
|
33 | + $schema_field_groups = $context->get_custom_fields(); |
|
34 | + |
|
35 | + if ( ! is_array( $schema_field_groups ) ) { |
|
36 | + return; |
|
37 | + } |
|
38 | + |
|
39 | + foreach ( $schema_field_groups as $schema_field_group ) { |
|
40 | + $custom_fields = $schema_field_group->get_custom_fields(); |
|
41 | + if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
42 | + $this->group( |
|
43 | + $schema_field_group->get_schema_type(), |
|
44 | + $pod, |
|
45 | + $this->group_fields( |
|
46 | + ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + protected function text() { |
|
55 | + return array( |
|
56 | + 'description' => '', |
|
57 | + 'weight' => 0, |
|
58 | + 'type' => 'text', |
|
59 | + 'sister_id' => '-- Select One --', |
|
60 | + 'rest_route' => '/pods/v1/fields', |
|
61 | + 'required' => '0', |
|
62 | + 'text_allowed_html_tags' => 'strong em a ul ol li b i', |
|
63 | + 'text_max_length' => '255', |
|
64 | + 'roles_allowed' => 'administrator', |
|
65 | + 'rest_pick_response' => 'array', |
|
66 | + 'rest_pick_depth' => '1', |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + protected function relationship( $name, $field_data ) { |
|
71 | + |
|
72 | + $supported_schema_types = $field_data['constraints']['uri_type']; |
|
73 | + |
|
74 | + if ( ! is_array( $supported_schema_types ) ) { |
|
75 | + $supported_schema_types = array( $supported_schema_types ); |
|
76 | + } |
|
77 | + |
|
78 | + return array( |
|
79 | + 'description' => '', |
|
80 | + 'weight' => 0, |
|
81 | + 'type' => 'pick', |
|
82 | + 'pick_object' => 'wlentity', |
|
83 | + 'sister_id' => '-- Select One --', |
|
84 | + 'rest_route' => '/pods/v1/fields', |
|
85 | + 'pick_table' => '-- Select One --', |
|
86 | + 'required' => '0', |
|
87 | + 'repeatable' => '0', |
|
88 | + 'pick_format_type' => 'single', |
|
89 | + 'pick_format_single' => 'autocomplete', |
|
90 | + 'pick_format_multi' => 'list', |
|
91 | + 'pick_display_format_multi' => 'autocomplete', |
|
92 | + 'pick_display_format_separator' => ', ', |
|
93 | + 'pick_allow_add_new' => '1', |
|
94 | + 'pick_taggable' => '0', |
|
95 | + 'pick_show_icon' => '1', |
|
96 | + 'pick_show_edit_link' => '1', |
|
97 | + 'pick_show_view_link' => '1', |
|
98 | + 'pick_limit' => '0', |
|
99 | + 'pick_user_role' => 'Administrator', |
|
100 | + 'pick_post_status' => 'publish', |
|
101 | + 'pick_post_author' => '0', |
|
102 | + 'roles_allowed' => 'administrator', |
|
103 | + 'rest_pick_response' => 'array', |
|
104 | + 'rest_pick_depth' => '1', |
|
105 | + 'supported_schema_types' => $supported_schema_types, |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
110 | + $field['repeatable'] = 1; |
|
111 | + $field['repeatable_add_new_label'] = $repeatable_label; |
|
112 | + |
|
113 | + return $field; |
|
114 | + } |
|
115 | + |
|
116 | + protected function website() { |
|
117 | + return array( |
|
118 | + 'description' => '', |
|
119 | + 'weight' => 0, |
|
120 | + 'type' => 'website', |
|
121 | + 'sister_id' => '-- Select One --', |
|
122 | + 'rest_route' => '/pods/v1/fields', |
|
123 | + 'required' => '0', |
|
124 | + 'repeatable' => '0', |
|
125 | + 'roles_allowed' => 'administrator', |
|
126 | + 'rest_pick_response' => 'array', |
|
127 | + 'rest_pick_depth' => '1', |
|
128 | + 'website_format' => 'normal', |
|
129 | + 'website_allow_port' => '0', |
|
130 | + 'website_clickable' => '0', |
|
131 | + 'website_new_window' => '0', |
|
132 | + 'website_nofollow' => '0', |
|
133 | + 'website_max_length' => '255', |
|
134 | + 'website_html5' => '0', |
|
135 | + ); |
|
136 | + } |
|
137 | + |
|
138 | + protected function group_fields( ...$fields ) { |
|
139 | + $result = array(); |
|
140 | + array_map( |
|
141 | + function ( $item ) use ( &$result ) { |
|
142 | + $field_name = $item['name']; |
|
143 | + $result[ $field_name ] = $item; |
|
144 | + }, |
|
145 | + $fields |
|
146 | + ); |
|
147 | + |
|
148 | + return $result; |
|
149 | + } |
|
150 | + |
|
151 | + protected function group( $name, $pod, $group_fields ) { |
|
152 | + $group = array( |
|
153 | + 'name' => $name, |
|
154 | + 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
155 | + 'description' => '', |
|
156 | + 'weight' => 0, |
|
157 | + |
|
158 | + ); |
|
159 | + pods_register_group( $group, $pod['name'], $group_fields ); |
|
160 | + } |
|
161 | + |
|
162 | + protected function pod( $pod_id, $name, $type ) { |
|
163 | + $pod = array( |
|
164 | + 'name' => $name, |
|
165 | + 'label' => $this->format_label( $name ), |
|
166 | + 'description' => '', |
|
167 | + 'type' => $type, |
|
168 | + 'storage' => 'meta', |
|
169 | + 'id' => $pod_id, |
|
170 | + 'object' => $name, |
|
171 | + ); |
|
172 | + |
|
173 | + pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
174 | + |
|
175 | + return $pod; |
|
176 | + } |
|
177 | + |
|
178 | + protected function register_on_all_supported_taxonomies() { |
|
179 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
180 | + foreach ( $taxonomies as $taxonomy ) { |
|
181 | + $this->register_pod( $taxonomy, 'taxonomy' ); |
|
182 | + |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + protected function get_field_by_type( $name, $type, $field_data ) { |
|
187 | + if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
188 | + return $this->relationship( $name, $field_data ); |
|
189 | + } elseif ( 'uri' === $type ) { |
|
190 | + return $this->website(); |
|
191 | + } elseif ( 'string' === $type ) { |
|
192 | + return $this->text(); |
|
193 | + } elseif ( 'double' === $type ) { |
|
194 | + return $this->number( $name, 2 ); |
|
195 | + } elseif ( 'date' === $type ) { |
|
196 | + return $this->datetime(); |
|
197 | + } elseif ( 'multiline' === $type ) { |
|
198 | + return $this->multiline(); |
|
199 | + } else { |
|
200 | + return $this->text(); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + protected function datetime() { |
|
205 | + return array( |
|
206 | + 'description' => '', |
|
207 | + 'weight' => 2, |
|
208 | + 'type' => 'datetime', |
|
209 | + 'sister_id' => '-- Select One --', |
|
210 | + 'rest_route' => '/pods/v1/fields', |
|
211 | + 'required' => '0', |
|
212 | + 'repeatable' => '0', |
|
213 | + 'datetime_type' => 'format', |
|
214 | + 'datetime_format' => 'ymd_slash', |
|
215 | + 'datetime_time_type' => '24', |
|
216 | + 'datetime_time_format' => 'h_mma', |
|
217 | + 'datetime_time_format_24' => 'hh_mm', |
|
218 | + 'datetime_allow_empty' => '1', |
|
219 | + 'datetime_html5' => '0', |
|
220 | + 'roles_allowed' => 'administrator', |
|
221 | + 'rest_pick_response' => 'array', |
|
222 | + 'rest_pick_depth' => '1', |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + protected function number( $name, $decimals = 0 ) { |
|
227 | + return array( |
|
228 | + 'description' => '', |
|
229 | + 'weight' => 1, |
|
230 | + 'type' => 'number', |
|
231 | + 'sister_id' => '-- Select One --', |
|
232 | + 'rest_route' => '/pods/v1/fields', |
|
233 | + 'required' => '0', |
|
234 | + 'repeatable' => '0', |
|
235 | + 'number_format_type' => 'number', |
|
236 | + 'number_format' => 'i18n', |
|
237 | + 'number_decimals' => $decimals, |
|
238 | + 'number_format_soft' => '0', |
|
239 | + 'number_step' => '2', |
|
240 | + 'number_max_length' => '0', |
|
241 | + 'number_html5' => '0', |
|
242 | + 'roles_allowed' => 'administrator', |
|
243 | + 'rest_pick_response' => 'array', |
|
244 | + 'rest_pick_depth' => '1', |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + protected function multiline() { |
|
249 | + return array( |
|
250 | + 'description' => '', |
|
251 | + 'weight' => 3, |
|
252 | + 'type' => 'paragraph', |
|
253 | + 'sister_id' => '-- Select One --', |
|
254 | + 'rest_route' => '/pods/v1/fields', |
|
255 | + 'required' => '0', |
|
256 | + 'repeatable' => '0', |
|
257 | + 'paragraph_allowed_html_tags' => 'strong em a ul ol li b i', |
|
258 | + 'paragraph_max_length' => '-1', |
|
259 | + 'roles_allowed' => 'administrator', |
|
260 | + 'rest_pick_response' => 'array', |
|
261 | + 'rest_pick_depth' => '1', |
|
262 | + ); |
|
263 | + } |
|
264 | + |
|
265 | + protected function may_be_repeatable( $custom_field, $field ) { |
|
266 | + $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
267 | + if ( $repeatable ) { |
|
268 | + return $this->repeatable( $field ); |
|
269 | + } |
|
270 | + |
|
271 | + return $field; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @return array |
|
276 | + * A function which defines these pods on the edit post screen. |
|
277 | + */ |
|
278 | + protected function custom_field_to_pod_field( $custom_field ) { |
|
279 | + |
|
280 | + $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
281 | + $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
282 | + |
|
283 | + return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
284 | + } |
|
285 | + |
|
286 | + protected function wordlift_css_class( $field ) { |
|
287 | + $field['class'] = 'wordlift'; |
|
288 | + |
|
289 | + return $field; |
|
290 | + } |
|
291 | + |
|
292 | + protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
293 | + |
|
294 | + $pod_fields = array(); |
|
295 | + |
|
296 | + foreach ( $custom_fields as $name => $custom_field ) { |
|
297 | + $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
298 | + 'pod_id' => $pod_id, |
|
299 | + 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
300 | + 'name' => $name, |
|
301 | + 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
302 | + ); |
|
303 | + } |
|
304 | + |
|
305 | + return array_values( $pod_fields ); |
|
306 | + } |
|
307 | + |
|
308 | + protected function format_label( $name ) { |
|
309 | + return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
310 | + } |
|
311 | 311 | |
312 | 312 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return void |
18 | 18 | */ |
19 | - public function __construct( $schema ) { |
|
19 | + public function __construct($schema) { |
|
20 | 20 | $this->schema = $schema; |
21 | 21 | } |
22 | 22 | |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return void |
29 | 29 | */ |
30 | - protected function register_pod( $name, $type, $context ) { |
|
31 | - $pod_id = intval( substr( md5( $type . '_' . $name ), 0, 8 ), 16 ); |
|
32 | - $pod = $this->pod( $pod_id, $name, $type ); |
|
30 | + protected function register_pod($name, $type, $context) { |
|
31 | + $pod_id = intval(substr(md5($type.'_'.$name), 0, 8), 16); |
|
32 | + $pod = $this->pod($pod_id, $name, $type); |
|
33 | 33 | $schema_field_groups = $context->get_custom_fields(); |
34 | 34 | |
35 | - if ( ! is_array( $schema_field_groups ) ) { |
|
35 | + if ( ! is_array($schema_field_groups)) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | 38 | |
39 | - foreach ( $schema_field_groups as $schema_field_group ) { |
|
39 | + foreach ($schema_field_groups as $schema_field_group) { |
|
40 | 40 | $custom_fields = $schema_field_group->get_custom_fields(); |
41 | - if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
41 | + if (is_array($custom_fields) && count($custom_fields) > 0) { |
|
42 | 42 | $this->group( |
43 | 43 | $schema_field_group->get_schema_type(), |
44 | 44 | $pod, |
45 | 45 | $this->group_fields( |
46 | - ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
46 | + ...$this->custom_fields_to_pod_fields($custom_fields, $pod_id) |
|
47 | 47 | ) |
48 | 48 | ); |
49 | 49 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - protected function relationship( $name, $field_data ) { |
|
70 | + protected function relationship($name, $field_data) { |
|
71 | 71 | |
72 | 72 | $supported_schema_types = $field_data['constraints']['uri_type']; |
73 | 73 | |
74 | - if ( ! is_array( $supported_schema_types ) ) { |
|
75 | - $supported_schema_types = array( $supported_schema_types ); |
|
74 | + if ( ! is_array($supported_schema_types)) { |
|
75 | + $supported_schema_types = array($supported_schema_types); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return array( |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
109 | - protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
109 | + protected function repeatable($field, $repeatable_label = 'Add New') { |
|
110 | 110 | $field['repeatable'] = 1; |
111 | 111 | $field['repeatable_add_new_label'] = $repeatable_label; |
112 | 112 | |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | ); |
136 | 136 | } |
137 | 137 | |
138 | - protected function group_fields( ...$fields ) { |
|
138 | + protected function group_fields(...$fields) { |
|
139 | 139 | $result = array(); |
140 | 140 | array_map( |
141 | - function ( $item ) use ( &$result ) { |
|
141 | + function($item) use (&$result) { |
|
142 | 142 | $field_name = $item['name']; |
143 | - $result[ $field_name ] = $item; |
|
143 | + $result[$field_name] = $item; |
|
144 | 144 | }, |
145 | 145 | $fields |
146 | 146 | ); |
@@ -148,21 +148,21 @@ discard block |
||
148 | 148 | return $result; |
149 | 149 | } |
150 | 150 | |
151 | - protected function group( $name, $pod, $group_fields ) { |
|
151 | + protected function group($name, $pod, $group_fields) { |
|
152 | 152 | $group = array( |
153 | 153 | 'name' => $name, |
154 | - 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
154 | + 'label' => sprintf('WordLift - %s', $this->format_label($name)), |
|
155 | 155 | 'description' => '', |
156 | 156 | 'weight' => 0, |
157 | 157 | |
158 | 158 | ); |
159 | - pods_register_group( $group, $pod['name'], $group_fields ); |
|
159 | + pods_register_group($group, $pod['name'], $group_fields); |
|
160 | 160 | } |
161 | 161 | |
162 | - protected function pod( $pod_id, $name, $type ) { |
|
162 | + protected function pod($pod_id, $name, $type) { |
|
163 | 163 | $pod = array( |
164 | 164 | 'name' => $name, |
165 | - 'label' => $this->format_label( $name ), |
|
165 | + 'label' => $this->format_label($name), |
|
166 | 166 | 'description' => '', |
167 | 167 | 'type' => $type, |
168 | 168 | 'storage' => 'meta', |
@@ -170,31 +170,31 @@ discard block |
||
170 | 170 | 'object' => $name, |
171 | 171 | ); |
172 | 172 | |
173 | - pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
173 | + pods_register_type($pod['type'], $pod['name'], $pod); |
|
174 | 174 | |
175 | 175 | return $pod; |
176 | 176 | } |
177 | 177 | |
178 | 178 | protected function register_on_all_supported_taxonomies() { |
179 | 179 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
180 | - foreach ( $taxonomies as $taxonomy ) { |
|
181 | - $this->register_pod( $taxonomy, 'taxonomy' ); |
|
180 | + foreach ($taxonomies as $taxonomy) { |
|
181 | + $this->register_pod($taxonomy, 'taxonomy'); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - protected function get_field_by_type( $name, $type, $field_data ) { |
|
187 | - if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
188 | - return $this->relationship( $name, $field_data ); |
|
189 | - } elseif ( 'uri' === $type ) { |
|
186 | + protected function get_field_by_type($name, $type, $field_data) { |
|
187 | + if ('uri' === $type && isset($field_data['constraints']['uri_type'])) { |
|
188 | + return $this->relationship($name, $field_data); |
|
189 | + } elseif ('uri' === $type) { |
|
190 | 190 | return $this->website(); |
191 | - } elseif ( 'string' === $type ) { |
|
191 | + } elseif ('string' === $type) { |
|
192 | 192 | return $this->text(); |
193 | - } elseif ( 'double' === $type ) { |
|
194 | - return $this->number( $name, 2 ); |
|
195 | - } elseif ( 'date' === $type ) { |
|
193 | + } elseif ('double' === $type) { |
|
194 | + return $this->number($name, 2); |
|
195 | + } elseif ('date' === $type) { |
|
196 | 196 | return $this->datetime(); |
197 | - } elseif ( 'multiline' === $type ) { |
|
197 | + } elseif ('multiline' === $type) { |
|
198 | 198 | return $this->multiline(); |
199 | 199 | } else { |
200 | 200 | return $this->text(); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - protected function number( $name, $decimals = 0 ) { |
|
226 | + protected function number($name, $decimals = 0) { |
|
227 | 227 | return array( |
228 | 228 | 'description' => '', |
229 | 229 | 'weight' => 1, |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - protected function may_be_repeatable( $custom_field, $field ) { |
|
266 | - $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
267 | - if ( $repeatable ) { |
|
268 | - return $this->repeatable( $field ); |
|
265 | + protected function may_be_repeatable($custom_field, $field) { |
|
266 | + $repeatable = isset($custom_field['constraints']['cardinality']) && INF === $custom_field['constraints']['cardinality']; |
|
267 | + if ($repeatable) { |
|
268 | + return $this->repeatable($field); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | return $field; |
@@ -275,38 +275,38 @@ discard block |
||
275 | 275 | * @return array |
276 | 276 | * A function which defines these pods on the edit post screen. |
277 | 277 | */ |
278 | - protected function custom_field_to_pod_field( $custom_field ) { |
|
278 | + protected function custom_field_to_pod_field($custom_field) { |
|
279 | 279 | |
280 | - $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
281 | - $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
280 | + $name = str_replace('http://schema.org/', '', $custom_field['predicate']); |
|
281 | + $type = isset($custom_field['type']) ? $custom_field['type'] : 'string'; |
|
282 | 282 | |
283 | - return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
283 | + return $this->may_be_repeatable($custom_field, $this->get_field_by_type($name, $type, $custom_field)); |
|
284 | 284 | } |
285 | 285 | |
286 | - protected function wordlift_css_class( $field ) { |
|
286 | + protected function wordlift_css_class($field) { |
|
287 | 287 | $field['class'] = 'wordlift'; |
288 | 288 | |
289 | 289 | return $field; |
290 | 290 | } |
291 | 291 | |
292 | - protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
292 | + protected function custom_fields_to_pod_fields($custom_fields, $pod_id) { |
|
293 | 293 | |
294 | 294 | $pod_fields = array(); |
295 | 295 | |
296 | - foreach ( $custom_fields as $name => $custom_field ) { |
|
297 | - $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
296 | + foreach ($custom_fields as $name => $custom_field) { |
|
297 | + $pod_fields[] = $this->wordlift_css_class($this->custom_field_to_pod_field($custom_field)) + array( |
|
298 | 298 | 'pod_id' => $pod_id, |
299 | - 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
299 | + 'id' => intval(substr(md5($pod_id.'_'.$name), 0, 8), 16), |
|
300 | 300 | 'name' => $name, |
301 | - 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
301 | + 'label' => $this->format_label(str_replace('http://schema.org/', '', $custom_field['predicate'])), |
|
302 | 302 | ); |
303 | 303 | } |
304 | 304 | |
305 | - return array_values( $pod_fields ); |
|
305 | + return array_values($pod_fields); |
|
306 | 306 | } |
307 | 307 | |
308 | - protected function format_label( $name ) { |
|
309 | - return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
308 | + protected function format_label($name) { |
|
309 | + return join(' ', array_map('ucwords', preg_split('/(?=[A-Z])/', $name))); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | } |
@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
18 | 18 | |
19 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
20 | - exit; |
|
20 | + exit; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
24 | - return; |
|
24 | + return; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | // Autoloader for plugin itself. |
28 | 28 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
29 | - require __DIR__ . '/vendor/autoload.php'; |
|
29 | + require __DIR__ . '/vendor/autoload.php'; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $container_builder = new ContainerBuilder(); |
@@ -35,32 +35,32 @@ discard block |
||
35 | 35 | $container_builder->compile(); |
36 | 36 | |
37 | 37 | add_action( |
38 | - 'plugins_loaded', |
|
39 | - function () use ( $container_builder ) { |
|
38 | + 'plugins_loaded', |
|
39 | + function () use ( $container_builder ) { |
|
40 | 40 | |
41 | - if ( ! defined( 'PODS_VERSION' ) ) { |
|
42 | - return; |
|
43 | - } |
|
41 | + if ( ! defined( 'PODS_VERSION' ) ) { |
|
42 | + return; |
|
43 | + } |
|
44 | 44 | |
45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
46 | - $field_definition = $factory->get_field_definition(); |
|
47 | - $field_definition->register(); |
|
45 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
46 | + $field_definition = $factory->get_field_definition(); |
|
47 | + $field_definition->register(); |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var $installer \Wordlift\Modules\Pods\Installer |
|
51 | - */ |
|
52 | - $installer = $container_builder->get( Installer::class ); |
|
53 | - $installer->register_hooks(); |
|
49 | + /** |
|
50 | + * @var $installer \Wordlift\Modules\Pods\Installer |
|
51 | + */ |
|
52 | + $installer = $container_builder->get( Installer::class ); |
|
53 | + $installer->register_hooks(); |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var $notices \Wordlift\Modules\Pods\Notices |
|
57 | - */ |
|
58 | - $notices = $container_builder->get( Notices::class ); |
|
59 | - $notices->register_hooks(); |
|
55 | + /** |
|
56 | + * @var $notices \Wordlift\Modules\Pods\Notices |
|
57 | + */ |
|
58 | + $notices = $container_builder->get( Notices::class ); |
|
59 | + $notices->register_hooks(); |
|
60 | 60 | |
61 | - $container_builder->get( Filters::class ); |
|
61 | + $container_builder->get( Filters::class ); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | ); |
65 | 65 | |
66 | 66 |
@@ -16,49 +16,49 @@ |
||
16 | 16 | use Wordlift\Modules\Pods\Notices; |
17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
18 | 18 | |
19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
19 | +if ( ! defined('ABSPATH')) { |
|
20 | 20 | exit; |
21 | 21 | } |
22 | 22 | |
23 | -if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
23 | +if ( ! apply_filters('wl_feature__enable__pods-integration', false)) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
24 | 24 | return; |
25 | 25 | } |
26 | 26 | |
27 | 27 | // Autoloader for plugin itself. |
28 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
29 | - require __DIR__ . '/vendor/autoload.php'; |
|
28 | +if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
29 | + require __DIR__.'/vendor/autoload.php'; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $container_builder = new ContainerBuilder(); |
33 | -$loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
34 | -$loader->load( 'services.yml' ); |
|
33 | +$loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
34 | +$loader->load('services.yml'); |
|
35 | 35 | $container_builder->compile(); |
36 | 36 | |
37 | 37 | add_action( |
38 | 38 | 'plugins_loaded', |
39 | - function () use ( $container_builder ) { |
|
39 | + function() use ($container_builder) { |
|
40 | 40 | |
41 | - if ( ! defined( 'PODS_VERSION' ) ) { |
|
41 | + if ( ! defined('PODS_VERSION')) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
45 | + $factory = $container_builder->get(FieldDefinitionFactory::class); |
|
46 | 46 | $field_definition = $factory->get_field_definition(); |
47 | 47 | $field_definition->register(); |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @var $installer \Wordlift\Modules\Pods\Installer |
51 | 51 | */ |
52 | - $installer = $container_builder->get( Installer::class ); |
|
52 | + $installer = $container_builder->get(Installer::class); |
|
53 | 53 | $installer->register_hooks(); |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @var $notices \Wordlift\Modules\Pods\Notices |
57 | 57 | */ |
58 | - $notices = $container_builder->get( Notices::class ); |
|
58 | + $notices = $container_builder->get(Notices::class); |
|
59 | 59 | $notices->register_hooks(); |
60 | 60 | |
61 | - $container_builder->get( Filters::class ); |
|
61 | + $container_builder->get(Filters::class); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | ); |