@@ -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 ) || ! defined( 'PODS_VERSION' ) ) { //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,28 +35,28 @@ 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 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
42 | - $field_definition = $factory->get_field_definition(); |
|
43 | - $field_definition->register(); |
|
41 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
42 | + $field_definition = $factory->get_field_definition(); |
|
43 | + $field_definition->register(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var $installer \Wordlift\Modules\Pods\Installer |
|
47 | - */ |
|
48 | - $installer = $container_builder->get( Installer::class ); |
|
49 | - $installer->register_hooks(); |
|
45 | + /** |
|
46 | + * @var $installer \Wordlift\Modules\Pods\Installer |
|
47 | + */ |
|
48 | + $installer = $container_builder->get( Installer::class ); |
|
49 | + $installer->register_hooks(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var $notices \Wordlift\Modules\Pods\Notices |
|
53 | - */ |
|
54 | - $notices = $container_builder->get( Notices::class ); |
|
55 | - $notices->register_hooks(); |
|
51 | + /** |
|
52 | + * @var $notices \Wordlift\Modules\Pods\Notices |
|
53 | + */ |
|
54 | + $notices = $container_builder->get( Notices::class ); |
|
55 | + $notices->register_hooks(); |
|
56 | 56 | |
57 | - $filters = $container_builder->get( Filters::class ); |
|
57 | + $filters = $container_builder->get( Filters::class ); |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | ); |
61 | 61 | |
62 | 62 |
@@ -16,45 +16,45 @@ |
||
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 ) || ! defined( 'PODS_VERSION' ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
23 | +if ( ! apply_filters('wl_feature__enable__pods-integration', false) || ! defined('PODS_VERSION')) { //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 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
41 | + $factory = $container_builder->get(FieldDefinitionFactory::class); |
|
42 | 42 | $field_definition = $factory->get_field_definition(); |
43 | 43 | $field_definition->register(); |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @var $installer \Wordlift\Modules\Pods\Installer |
47 | 47 | */ |
48 | - $installer = $container_builder->get( Installer::class ); |
|
48 | + $installer = $container_builder->get(Installer::class); |
|
49 | 49 | $installer->register_hooks(); |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @var $notices \Wordlift\Modules\Pods\Notices |
53 | 53 | */ |
54 | - $notices = $container_builder->get( Notices::class ); |
|
54 | + $notices = $container_builder->get(Notices::class); |
|
55 | 55 | $notices->register_hooks(); |
56 | 56 | |
57 | - $filters = $container_builder->get( Filters::class ); |
|
57 | + $filters = $container_builder->get(Filters::class); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | ); |
@@ -4,99 +4,99 @@ |
||
4 | 4 | |
5 | 5 | class Schema { |
6 | 6 | |
7 | - public function get_context_type() { |
|
8 | - |
|
9 | - if ( isset( $_REQUEST['post'] ) || isset( $_REQUEST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
10 | - return Context::POST; |
|
11 | - } |
|
12 | - if ( isset( $_REQUEST['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
13 | - return Context::TERM; |
|
14 | - } |
|
15 | - |
|
16 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
17 | - return Context::ADMIN_AJAX; |
|
18 | - } |
|
19 | - |
|
20 | - return Context::UNKNOWN; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @return Context |
|
25 | - */ |
|
26 | - public function get() { |
|
27 | - // we need to identify the context to filter the results. |
|
28 | - |
|
29 | - $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
30 | - : sanitize_text_field( wp_unslash( isset( $_REQUEST['post_ID'] ) ? $_REQUEST['post_ID'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
31 | - |
|
32 | - if ( $identifier ) { |
|
33 | - // If post identifier, get schema. |
|
34 | - return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
35 | - } |
|
36 | - |
|
37 | - $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
38 | - |
|
39 | - if ( $identifier ) { |
|
40 | - // If post identifier, get schema. |
|
41 | - return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
42 | - } |
|
43 | - |
|
44 | - if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
45 | - return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
46 | - } |
|
47 | - |
|
48 | - return new Context( Context::UNKNOWN, null, null ); |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return Schema_Field_Group[] |
|
54 | - */ |
|
55 | - private function get_fields_for_post( $identifier ) { |
|
56 | - $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
57 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
58 | - |
|
59 | - return array_map( |
|
60 | - function ( $schema_type ) use ( $schema_classes ) { |
|
61 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
62 | - |
|
63 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
64 | - }, |
|
65 | - $types |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @return Schema_Field_Group[] |
|
71 | - */ |
|
72 | - private function get_fields_for_term( $identifier ) { |
|
73 | - $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
74 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
75 | - |
|
76 | - return array_map( |
|
77 | - function ( $schema_type ) use ( $schema_classes ) { |
|
78 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
79 | - |
|
80 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
81 | - }, |
|
82 | - $term_entity_types |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - private function get_all_fields() { |
|
87 | - $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
88 | - $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
89 | - |
|
90 | - return array_filter( |
|
91 | - array_map( |
|
92 | - function ( $schema_type ) use ( $schema_classes ) { |
|
93 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
94 | - |
|
95 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
96 | - }, |
|
97 | - $all_schema_slugs |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
7 | + public function get_context_type() { |
|
8 | + |
|
9 | + if ( isset( $_REQUEST['post'] ) || isset( $_REQUEST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
10 | + return Context::POST; |
|
11 | + } |
|
12 | + if ( isset( $_REQUEST['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
13 | + return Context::TERM; |
|
14 | + } |
|
15 | + |
|
16 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
17 | + return Context::ADMIN_AJAX; |
|
18 | + } |
|
19 | + |
|
20 | + return Context::UNKNOWN; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @return Context |
|
25 | + */ |
|
26 | + public function get() { |
|
27 | + // we need to identify the context to filter the results. |
|
28 | + |
|
29 | + $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
30 | + : sanitize_text_field( wp_unslash( isset( $_REQUEST['post_ID'] ) ? $_REQUEST['post_ID'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
31 | + |
|
32 | + if ( $identifier ) { |
|
33 | + // If post identifier, get schema. |
|
34 | + return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
35 | + } |
|
36 | + |
|
37 | + $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
38 | + |
|
39 | + if ( $identifier ) { |
|
40 | + // If post identifier, get schema. |
|
41 | + return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
42 | + } |
|
43 | + |
|
44 | + if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
45 | + return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
46 | + } |
|
47 | + |
|
48 | + return new Context( Context::UNKNOWN, null, null ); |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return Schema_Field_Group[] |
|
54 | + */ |
|
55 | + private function get_fields_for_post( $identifier ) { |
|
56 | + $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
57 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
58 | + |
|
59 | + return array_map( |
|
60 | + function ( $schema_type ) use ( $schema_classes ) { |
|
61 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
62 | + |
|
63 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
64 | + }, |
|
65 | + $types |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @return Schema_Field_Group[] |
|
71 | + */ |
|
72 | + private function get_fields_for_term( $identifier ) { |
|
73 | + $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
74 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
75 | + |
|
76 | + return array_map( |
|
77 | + function ( $schema_type ) use ( $schema_classes ) { |
|
78 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
79 | + |
|
80 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
81 | + }, |
|
82 | + $term_entity_types |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + private function get_all_fields() { |
|
87 | + $schema_classes = \Wordlift_Schema_Service::get_instance(); |
|
88 | + $all_schema_slugs = $schema_classes->get_all_schema_slugs(); |
|
89 | + |
|
90 | + return array_filter( |
|
91 | + array_map( |
|
92 | + function ( $schema_type ) use ( $schema_classes ) { |
|
93 | + $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
94 | + |
|
95 | + return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
96 | + }, |
|
97 | + $all_schema_slugs |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | } |
@@ -6,14 +6,14 @@ discard block |
||
6 | 6 | |
7 | 7 | public function get_context_type() { |
8 | 8 | |
9 | - if ( isset( $_REQUEST['post'] ) || isset( $_REQUEST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
9 | + if (isset($_REQUEST['post']) || isset($_REQUEST['post_ID'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
10 | 10 | return Context::POST; |
11 | 11 | } |
12 | - if ( isset( $_REQUEST['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
12 | + if (isset($_REQUEST['tag_ID'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
13 | 13 | return Context::TERM; |
14 | 14 | } |
15 | 15 | |
16 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
16 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
17 | 17 | return Context::ADMIN_AJAX; |
18 | 18 | } |
19 | 19 | |
@@ -26,41 +26,41 @@ discard block |
||
26 | 26 | public function get() { |
27 | 27 | // we need to identify the context to filter the results. |
28 | 28 | |
29 | - $identifier = isset( $_REQUEST['post'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
30 | - : sanitize_text_field( wp_unslash( isset( $_REQUEST['post_ID'] ) ? $_REQUEST['post_ID'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
29 | + $identifier = isset($_REQUEST['post']) ? sanitize_text_field(wp_unslash($_REQUEST['post'])) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
30 | + : sanitize_text_field(wp_unslash(isset($_REQUEST['post_ID']) ? $_REQUEST['post_ID'] : '')); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
31 | 31 | |
32 | - if ( $identifier ) { |
|
32 | + if ($identifier) { |
|
33 | 33 | // If post identifier, get schema. |
34 | - return new Context( Context::POST, $identifier, $this->get_fields_for_post( $identifier ) ); |
|
34 | + return new Context(Context::POST, $identifier, $this->get_fields_for_post($identifier)); |
|
35 | 35 | } |
36 | 36 | |
37 | - $identifier = isset( $_REQUEST['tag_ID'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tag_ID'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
37 | + $identifier = isset($_REQUEST['tag_ID']) ? sanitize_text_field(wp_unslash($_REQUEST['tag_ID'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
38 | 38 | |
39 | - if ( $identifier ) { |
|
39 | + if ($identifier) { |
|
40 | 40 | // If post identifier, get schema. |
41 | - return new Context( Context::TERM, $identifier, $this->get_fields_for_term( $identifier ) ); |
|
41 | + return new Context(Context::TERM, $identifier, $this->get_fields_for_term($identifier)); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( is_admin() && defined( 'DOING_AJAX' ) ) { |
|
45 | - return new Context( Context::ADMIN_AJAX, null, $this->get_all_fields() ); |
|
44 | + if (is_admin() && defined('DOING_AJAX')) { |
|
45 | + return new Context(Context::ADMIN_AJAX, null, $this->get_all_fields()); |
|
46 | 46 | } |
47 | 47 | |
48 | - return new Context( Context::UNKNOWN, null, null ); |
|
48 | + return new Context(Context::UNKNOWN, null, null); |
|
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return Schema_Field_Group[] |
54 | 54 | */ |
55 | - private function get_fields_for_post( $identifier ) { |
|
56 | - $types = \Wordlift_Entity_Type_Service::get_instance()->get_names( $identifier ); |
|
55 | + private function get_fields_for_post($identifier) { |
|
56 | + $types = \Wordlift_Entity_Type_Service::get_instance()->get_names($identifier); |
|
57 | 57 | $schema_classes = \Wordlift_Schema_Service::get_instance(); |
58 | 58 | |
59 | 59 | return array_map( |
60 | - function ( $schema_type ) use ( $schema_classes ) { |
|
61 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
60 | + function($schema_type) use ($schema_classes) { |
|
61 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
62 | 62 | |
63 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
63 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
64 | 64 | }, |
65 | 65 | $types |
66 | 66 | ); |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * @return Schema_Field_Group[] |
71 | 71 | */ |
72 | - private function get_fields_for_term( $identifier ) { |
|
73 | - $term_entity_types = get_term_meta( (int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
72 | + private function get_fields_for_term($identifier) { |
|
73 | + $term_entity_types = get_term_meta((int) $identifier, \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
74 | 74 | $schema_classes = \Wordlift_Schema_Service::get_instance(); |
75 | 75 | |
76 | 76 | return array_map( |
77 | - function ( $schema_type ) use ( $schema_classes ) { |
|
78 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
77 | + function($schema_type) use ($schema_classes) { |
|
78 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
79 | 79 | |
80 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
80 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
81 | 81 | }, |
82 | 82 | $term_entity_types |
83 | 83 | ); |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | |
90 | 90 | return array_filter( |
91 | 91 | array_map( |
92 | - function ( $schema_type ) use ( $schema_classes ) { |
|
93 | - $data = $schema_classes->get_schema( strtolower( $schema_type ) ); |
|
92 | + function($schema_type) use ($schema_classes) { |
|
93 | + $data = $schema_classes->get_schema(strtolower($schema_type)); |
|
94 | 94 | |
95 | - return new Schema_Field_Group( $schema_type, $data['custom_fields'] ); |
|
95 | + return new Schema_Field_Group($schema_type, $data['custom_fields']); |
|
96 | 96 | }, |
97 | 97 | $all_schema_slugs |
98 | 98 | ) |
@@ -6,305 +6,305 @@ |
||
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 int |
|
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 | - foreach ( $schema_field_groups as $schema_field_group ) { |
|
36 | - $custom_fields = $schema_field_group->get_custom_fields(); |
|
37 | - if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
38 | - $this->group( |
|
39 | - $schema_field_group->get_schema_type(), |
|
40 | - $pod, |
|
41 | - $this->group_fields( |
|
42 | - ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
43 | - ) |
|
44 | - ); |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - return $pod_id; |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - protected function text() { |
|
53 | - return array( |
|
54 | - 'description' => '', |
|
55 | - 'weight' => 0, |
|
56 | - 'type' => 'text', |
|
57 | - 'sister_id' => '-- Select One --', |
|
58 | - 'rest_route' => '/pods/v1/fields', |
|
59 | - 'required' => '0', |
|
60 | - 'text_allowed_html_tags' => 'strong em a ul ol li b i', |
|
61 | - 'text_max_length' => '255', |
|
62 | - 'roles_allowed' => 'administrator', |
|
63 | - 'rest_pick_response' => 'array', |
|
64 | - 'rest_pick_depth' => '1', |
|
65 | - ); |
|
66 | - } |
|
67 | - |
|
68 | - protected function relationship( $name, $field_data ) { |
|
69 | - |
|
70 | - $supported_schema_types = $field_data['constraints']['uri_type']; |
|
71 | - |
|
72 | - if ( ! is_array( $supported_schema_types ) ) { |
|
73 | - $supported_schema_types = array( $supported_schema_types ); |
|
74 | - } |
|
75 | - |
|
76 | - return array( |
|
77 | - 'description' => '', |
|
78 | - 'weight' => 0, |
|
79 | - 'type' => 'pick', |
|
80 | - 'pick_object' => 'wlentity', |
|
81 | - 'sister_id' => '-- Select One --', |
|
82 | - 'rest_route' => '/pods/v1/fields', |
|
83 | - 'pick_table' => '-- Select One --', |
|
84 | - 'required' => '0', |
|
85 | - 'repeatable' => '0', |
|
86 | - 'pick_format_type' => 'single', |
|
87 | - 'pick_format_single' => 'autocomplete', |
|
88 | - 'pick_format_multi' => 'list', |
|
89 | - 'pick_display_format_multi' => 'autocomplete', |
|
90 | - 'pick_display_format_separator' => ', ', |
|
91 | - 'pick_allow_add_new' => '1', |
|
92 | - 'pick_taggable' => '0', |
|
93 | - 'pick_show_icon' => '1', |
|
94 | - 'pick_show_edit_link' => '1', |
|
95 | - 'pick_show_view_link' => '1', |
|
96 | - 'pick_limit' => '0', |
|
97 | - 'pick_user_role' => 'Administrator', |
|
98 | - 'pick_post_status' => 'publish', |
|
99 | - 'pick_post_author' => '0', |
|
100 | - 'roles_allowed' => 'administrator', |
|
101 | - 'rest_pick_response' => 'array', |
|
102 | - 'rest_pick_depth' => '1', |
|
103 | - 'supported_schema_types' => $supported_schema_types, |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
108 | - $field['repeatable'] = 1; |
|
109 | - $field['repeatable_add_new_label'] = $repeatable_label; |
|
110 | - |
|
111 | - return $field; |
|
112 | - } |
|
113 | - |
|
114 | - protected function website() { |
|
115 | - return array( |
|
116 | - 'description' => '', |
|
117 | - 'weight' => 0, |
|
118 | - 'type' => 'website', |
|
119 | - 'sister_id' => '-- Select One --', |
|
120 | - 'rest_route' => '/pods/v1/fields', |
|
121 | - 'required' => '0', |
|
122 | - 'repeatable' => '0', |
|
123 | - 'roles_allowed' => 'administrator', |
|
124 | - 'rest_pick_response' => 'array', |
|
125 | - 'rest_pick_depth' => '1', |
|
126 | - 'website_format' => 'normal', |
|
127 | - 'website_allow_port' => '0', |
|
128 | - 'website_clickable' => '0', |
|
129 | - 'website_new_window' => '0', |
|
130 | - 'website_nofollow' => '0', |
|
131 | - 'website_max_length' => '255', |
|
132 | - 'website_html5' => '0', |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - protected function group_fields( ...$fields ) { |
|
137 | - $result = array(); |
|
138 | - array_map( |
|
139 | - function ( $item ) use ( &$result ) { |
|
140 | - $field_name = $item['name']; |
|
141 | - $result[ $field_name ] = $item; |
|
142 | - }, |
|
143 | - $fields |
|
144 | - ); |
|
145 | - |
|
146 | - return $result; |
|
147 | - } |
|
148 | - |
|
149 | - protected function group( $name, $pod, $group_fields ) { |
|
150 | - $group = array( |
|
151 | - 'name' => $name, |
|
152 | - 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
153 | - 'description' => '', |
|
154 | - 'weight' => 0, |
|
155 | - |
|
156 | - ); |
|
157 | - pods_register_group( $group, $pod['name'], $group_fields ); |
|
158 | - } |
|
159 | - |
|
160 | - protected function pod( $pod_id, $name, $type ) { |
|
161 | - $pod = array( |
|
162 | - 'name' => $name, |
|
163 | - 'label' => $this->format_label( $name ), |
|
164 | - 'description' => '', |
|
165 | - 'type' => $type, |
|
166 | - 'storage' => 'meta', |
|
167 | - 'id' => $pod_id, |
|
168 | - 'object' => $name, |
|
169 | - ); |
|
170 | - |
|
171 | - pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
172 | - |
|
173 | - return $pod; |
|
174 | - } |
|
175 | - |
|
176 | - protected function register_on_all_supported_taxonomies() { |
|
177 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
178 | - foreach ( $taxonomies as $taxonomy ) { |
|
179 | - $this->register_pod( $taxonomy, 'taxonomy' ); |
|
180 | - |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - protected function get_field_by_type( $name, $type, $field_data ) { |
|
185 | - if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
186 | - return $this->relationship( $name, $field_data ); |
|
187 | - } elseif ( 'uri' === $type ) { |
|
188 | - return $this->website(); |
|
189 | - } elseif ( 'string' === $type ) { |
|
190 | - return $this->text(); |
|
191 | - } elseif ( 'double' === $type ) { |
|
192 | - return $this->number( $name, 2 ); |
|
193 | - } elseif ( 'date' === $type ) { |
|
194 | - return $this->datetime(); |
|
195 | - } elseif ( 'multiline' === $type ) { |
|
196 | - return $this->multiline(); |
|
197 | - } else { |
|
198 | - return $this->text(); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - protected function datetime() { |
|
203 | - return array( |
|
204 | - 'description' => '', |
|
205 | - 'weight' => 2, |
|
206 | - 'type' => 'datetime', |
|
207 | - 'sister_id' => '-- Select One --', |
|
208 | - 'rest_route' => '/pods/v1/fields', |
|
209 | - 'required' => '0', |
|
210 | - 'repeatable' => '0', |
|
211 | - 'datetime_type' => 'format', |
|
212 | - 'datetime_format' => 'ymd_slash', |
|
213 | - 'datetime_time_type' => '24', |
|
214 | - 'datetime_time_format' => 'h_mma', |
|
215 | - 'datetime_time_format_24' => 'hh_mm', |
|
216 | - 'datetime_allow_empty' => '1', |
|
217 | - 'datetime_html5' => '0', |
|
218 | - 'roles_allowed' => 'administrator', |
|
219 | - 'rest_pick_response' => 'array', |
|
220 | - 'rest_pick_depth' => '1', |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - protected function number( $name, $decimals = 0 ) { |
|
225 | - return array( |
|
226 | - 'description' => '', |
|
227 | - 'weight' => 1, |
|
228 | - 'type' => 'number', |
|
229 | - 'sister_id' => '-- Select One --', |
|
230 | - 'rest_route' => '/pods/v1/fields', |
|
231 | - 'required' => '0', |
|
232 | - 'repeatable' => '0', |
|
233 | - 'number_format_type' => 'number', |
|
234 | - 'number_format' => 'i18n', |
|
235 | - 'number_decimals' => $decimals, |
|
236 | - 'number_format_soft' => '0', |
|
237 | - 'number_step' => '2', |
|
238 | - 'number_max_length' => '0', |
|
239 | - 'number_html5' => '0', |
|
240 | - 'roles_allowed' => 'administrator', |
|
241 | - 'rest_pick_response' => 'array', |
|
242 | - 'rest_pick_depth' => '1', |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - protected function multiline() { |
|
247 | - return array( |
|
248 | - 'description' => '', |
|
249 | - 'weight' => 3, |
|
250 | - 'type' => 'paragraph', |
|
251 | - 'sister_id' => '-- Select One --', |
|
252 | - 'rest_route' => '/pods/v1/fields', |
|
253 | - 'required' => '0', |
|
254 | - 'repeatable' => '0', |
|
255 | - 'paragraph_allowed_html_tags' => 'strong em a ul ol li b i', |
|
256 | - 'paragraph_max_length' => '-1', |
|
257 | - 'roles_allowed' => 'administrator', |
|
258 | - 'rest_pick_response' => 'array', |
|
259 | - 'rest_pick_depth' => '1', |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - protected function may_be_repeatable( $custom_field, $field ) { |
|
264 | - $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
265 | - if ( $repeatable ) { |
|
266 | - return $this->repeatable( $field ); |
|
267 | - } |
|
268 | - |
|
269 | - return $field; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @return array |
|
274 | - * A function which defines these pods on the edit post screen. |
|
275 | - */ |
|
276 | - protected function custom_field_to_pod_field( $custom_field ) { |
|
277 | - |
|
278 | - $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
279 | - $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
280 | - |
|
281 | - return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
282 | - } |
|
283 | - |
|
284 | - protected function wordlift_css_class( $field ) { |
|
285 | - $field['class'] = 'wordlift'; |
|
286 | - |
|
287 | - return $field; |
|
288 | - } |
|
289 | - |
|
290 | - protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
291 | - |
|
292 | - $pod_fields = array(); |
|
293 | - |
|
294 | - foreach ( $custom_fields as $name => $custom_field ) { |
|
295 | - $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
296 | - 'pod_id' => $pod_id, |
|
297 | - 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
298 | - 'name' => $name, |
|
299 | - 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - return array_values( $pod_fields ); |
|
304 | - } |
|
305 | - |
|
306 | - protected function format_label( $name ) { |
|
307 | - return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
308 | - } |
|
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 int |
|
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 | + foreach ( $schema_field_groups as $schema_field_group ) { |
|
36 | + $custom_fields = $schema_field_group->get_custom_fields(); |
|
37 | + if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
38 | + $this->group( |
|
39 | + $schema_field_group->get_schema_type(), |
|
40 | + $pod, |
|
41 | + $this->group_fields( |
|
42 | + ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
43 | + ) |
|
44 | + ); |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + return $pod_id; |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + protected function text() { |
|
53 | + return array( |
|
54 | + 'description' => '', |
|
55 | + 'weight' => 0, |
|
56 | + 'type' => 'text', |
|
57 | + 'sister_id' => '-- Select One --', |
|
58 | + 'rest_route' => '/pods/v1/fields', |
|
59 | + 'required' => '0', |
|
60 | + 'text_allowed_html_tags' => 'strong em a ul ol li b i', |
|
61 | + 'text_max_length' => '255', |
|
62 | + 'roles_allowed' => 'administrator', |
|
63 | + 'rest_pick_response' => 'array', |
|
64 | + 'rest_pick_depth' => '1', |
|
65 | + ); |
|
66 | + } |
|
67 | + |
|
68 | + protected function relationship( $name, $field_data ) { |
|
69 | + |
|
70 | + $supported_schema_types = $field_data['constraints']['uri_type']; |
|
71 | + |
|
72 | + if ( ! is_array( $supported_schema_types ) ) { |
|
73 | + $supported_schema_types = array( $supported_schema_types ); |
|
74 | + } |
|
75 | + |
|
76 | + return array( |
|
77 | + 'description' => '', |
|
78 | + 'weight' => 0, |
|
79 | + 'type' => 'pick', |
|
80 | + 'pick_object' => 'wlentity', |
|
81 | + 'sister_id' => '-- Select One --', |
|
82 | + 'rest_route' => '/pods/v1/fields', |
|
83 | + 'pick_table' => '-- Select One --', |
|
84 | + 'required' => '0', |
|
85 | + 'repeatable' => '0', |
|
86 | + 'pick_format_type' => 'single', |
|
87 | + 'pick_format_single' => 'autocomplete', |
|
88 | + 'pick_format_multi' => 'list', |
|
89 | + 'pick_display_format_multi' => 'autocomplete', |
|
90 | + 'pick_display_format_separator' => ', ', |
|
91 | + 'pick_allow_add_new' => '1', |
|
92 | + 'pick_taggable' => '0', |
|
93 | + 'pick_show_icon' => '1', |
|
94 | + 'pick_show_edit_link' => '1', |
|
95 | + 'pick_show_view_link' => '1', |
|
96 | + 'pick_limit' => '0', |
|
97 | + 'pick_user_role' => 'Administrator', |
|
98 | + 'pick_post_status' => 'publish', |
|
99 | + 'pick_post_author' => '0', |
|
100 | + 'roles_allowed' => 'administrator', |
|
101 | + 'rest_pick_response' => 'array', |
|
102 | + 'rest_pick_depth' => '1', |
|
103 | + 'supported_schema_types' => $supported_schema_types, |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
108 | + $field['repeatable'] = 1; |
|
109 | + $field['repeatable_add_new_label'] = $repeatable_label; |
|
110 | + |
|
111 | + return $field; |
|
112 | + } |
|
113 | + |
|
114 | + protected function website() { |
|
115 | + return array( |
|
116 | + 'description' => '', |
|
117 | + 'weight' => 0, |
|
118 | + 'type' => 'website', |
|
119 | + 'sister_id' => '-- Select One --', |
|
120 | + 'rest_route' => '/pods/v1/fields', |
|
121 | + 'required' => '0', |
|
122 | + 'repeatable' => '0', |
|
123 | + 'roles_allowed' => 'administrator', |
|
124 | + 'rest_pick_response' => 'array', |
|
125 | + 'rest_pick_depth' => '1', |
|
126 | + 'website_format' => 'normal', |
|
127 | + 'website_allow_port' => '0', |
|
128 | + 'website_clickable' => '0', |
|
129 | + 'website_new_window' => '0', |
|
130 | + 'website_nofollow' => '0', |
|
131 | + 'website_max_length' => '255', |
|
132 | + 'website_html5' => '0', |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + protected function group_fields( ...$fields ) { |
|
137 | + $result = array(); |
|
138 | + array_map( |
|
139 | + function ( $item ) use ( &$result ) { |
|
140 | + $field_name = $item['name']; |
|
141 | + $result[ $field_name ] = $item; |
|
142 | + }, |
|
143 | + $fields |
|
144 | + ); |
|
145 | + |
|
146 | + return $result; |
|
147 | + } |
|
148 | + |
|
149 | + protected function group( $name, $pod, $group_fields ) { |
|
150 | + $group = array( |
|
151 | + 'name' => $name, |
|
152 | + 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
153 | + 'description' => '', |
|
154 | + 'weight' => 0, |
|
155 | + |
|
156 | + ); |
|
157 | + pods_register_group( $group, $pod['name'], $group_fields ); |
|
158 | + } |
|
159 | + |
|
160 | + protected function pod( $pod_id, $name, $type ) { |
|
161 | + $pod = array( |
|
162 | + 'name' => $name, |
|
163 | + 'label' => $this->format_label( $name ), |
|
164 | + 'description' => '', |
|
165 | + 'type' => $type, |
|
166 | + 'storage' => 'meta', |
|
167 | + 'id' => $pod_id, |
|
168 | + 'object' => $name, |
|
169 | + ); |
|
170 | + |
|
171 | + pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
172 | + |
|
173 | + return $pod; |
|
174 | + } |
|
175 | + |
|
176 | + protected function register_on_all_supported_taxonomies() { |
|
177 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
178 | + foreach ( $taxonomies as $taxonomy ) { |
|
179 | + $this->register_pod( $taxonomy, 'taxonomy' ); |
|
180 | + |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + protected function get_field_by_type( $name, $type, $field_data ) { |
|
185 | + if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
186 | + return $this->relationship( $name, $field_data ); |
|
187 | + } elseif ( 'uri' === $type ) { |
|
188 | + return $this->website(); |
|
189 | + } elseif ( 'string' === $type ) { |
|
190 | + return $this->text(); |
|
191 | + } elseif ( 'double' === $type ) { |
|
192 | + return $this->number( $name, 2 ); |
|
193 | + } elseif ( 'date' === $type ) { |
|
194 | + return $this->datetime(); |
|
195 | + } elseif ( 'multiline' === $type ) { |
|
196 | + return $this->multiline(); |
|
197 | + } else { |
|
198 | + return $this->text(); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + protected function datetime() { |
|
203 | + return array( |
|
204 | + 'description' => '', |
|
205 | + 'weight' => 2, |
|
206 | + 'type' => 'datetime', |
|
207 | + 'sister_id' => '-- Select One --', |
|
208 | + 'rest_route' => '/pods/v1/fields', |
|
209 | + 'required' => '0', |
|
210 | + 'repeatable' => '0', |
|
211 | + 'datetime_type' => 'format', |
|
212 | + 'datetime_format' => 'ymd_slash', |
|
213 | + 'datetime_time_type' => '24', |
|
214 | + 'datetime_time_format' => 'h_mma', |
|
215 | + 'datetime_time_format_24' => 'hh_mm', |
|
216 | + 'datetime_allow_empty' => '1', |
|
217 | + 'datetime_html5' => '0', |
|
218 | + 'roles_allowed' => 'administrator', |
|
219 | + 'rest_pick_response' => 'array', |
|
220 | + 'rest_pick_depth' => '1', |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + protected function number( $name, $decimals = 0 ) { |
|
225 | + return array( |
|
226 | + 'description' => '', |
|
227 | + 'weight' => 1, |
|
228 | + 'type' => 'number', |
|
229 | + 'sister_id' => '-- Select One --', |
|
230 | + 'rest_route' => '/pods/v1/fields', |
|
231 | + 'required' => '0', |
|
232 | + 'repeatable' => '0', |
|
233 | + 'number_format_type' => 'number', |
|
234 | + 'number_format' => 'i18n', |
|
235 | + 'number_decimals' => $decimals, |
|
236 | + 'number_format_soft' => '0', |
|
237 | + 'number_step' => '2', |
|
238 | + 'number_max_length' => '0', |
|
239 | + 'number_html5' => '0', |
|
240 | + 'roles_allowed' => 'administrator', |
|
241 | + 'rest_pick_response' => 'array', |
|
242 | + 'rest_pick_depth' => '1', |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + protected function multiline() { |
|
247 | + return array( |
|
248 | + 'description' => '', |
|
249 | + 'weight' => 3, |
|
250 | + 'type' => 'paragraph', |
|
251 | + 'sister_id' => '-- Select One --', |
|
252 | + 'rest_route' => '/pods/v1/fields', |
|
253 | + 'required' => '0', |
|
254 | + 'repeatable' => '0', |
|
255 | + 'paragraph_allowed_html_tags' => 'strong em a ul ol li b i', |
|
256 | + 'paragraph_max_length' => '-1', |
|
257 | + 'roles_allowed' => 'administrator', |
|
258 | + 'rest_pick_response' => 'array', |
|
259 | + 'rest_pick_depth' => '1', |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + protected function may_be_repeatable( $custom_field, $field ) { |
|
264 | + $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
265 | + if ( $repeatable ) { |
|
266 | + return $this->repeatable( $field ); |
|
267 | + } |
|
268 | + |
|
269 | + return $field; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @return array |
|
274 | + * A function which defines these pods on the edit post screen. |
|
275 | + */ |
|
276 | + protected function custom_field_to_pod_field( $custom_field ) { |
|
277 | + |
|
278 | + $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
279 | + $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
280 | + |
|
281 | + return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
282 | + } |
|
283 | + |
|
284 | + protected function wordlift_css_class( $field ) { |
|
285 | + $field['class'] = 'wordlift'; |
|
286 | + |
|
287 | + return $field; |
|
288 | + } |
|
289 | + |
|
290 | + protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
291 | + |
|
292 | + $pod_fields = array(); |
|
293 | + |
|
294 | + foreach ( $custom_fields as $name => $custom_field ) { |
|
295 | + $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
296 | + 'pod_id' => $pod_id, |
|
297 | + 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
298 | + 'name' => $name, |
|
299 | + 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + return array_values( $pod_fields ); |
|
304 | + } |
|
305 | + |
|
306 | + protected function format_label( $name ) { |
|
307 | + return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
308 | + } |
|
309 | 309 | |
310 | 310 | } |
@@ -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,19 +27,19 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return int |
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 | - foreach ( $schema_field_groups as $schema_field_group ) { |
|
35 | + foreach ($schema_field_groups as $schema_field_group) { |
|
36 | 36 | $custom_fields = $schema_field_group->get_custom_fields(); |
37 | - if ( is_array( $custom_fields ) && count( $custom_fields ) > 0 ) { |
|
37 | + if (is_array($custom_fields) && count($custom_fields) > 0) { |
|
38 | 38 | $this->group( |
39 | 39 | $schema_field_group->get_schema_type(), |
40 | 40 | $pod, |
41 | 41 | $this->group_fields( |
42 | - ...$this->custom_fields_to_pod_fields( $custom_fields, $pod_id ) |
|
42 | + ...$this->custom_fields_to_pod_fields($custom_fields, $pod_id) |
|
43 | 43 | ) |
44 | 44 | ); |
45 | 45 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - protected function relationship( $name, $field_data ) { |
|
68 | + protected function relationship($name, $field_data) { |
|
69 | 69 | |
70 | 70 | $supported_schema_types = $field_data['constraints']['uri_type']; |
71 | 71 | |
72 | - if ( ! is_array( $supported_schema_types ) ) { |
|
73 | - $supported_schema_types = array( $supported_schema_types ); |
|
72 | + if ( ! is_array($supported_schema_types)) { |
|
73 | + $supported_schema_types = array($supported_schema_types); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return array( |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | - protected function repeatable( $field, $repeatable_label = 'Add New' ) { |
|
107 | + protected function repeatable($field, $repeatable_label = 'Add New') { |
|
108 | 108 | $field['repeatable'] = 1; |
109 | 109 | $field['repeatable_add_new_label'] = $repeatable_label; |
110 | 110 | |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | ); |
134 | 134 | } |
135 | 135 | |
136 | - protected function group_fields( ...$fields ) { |
|
136 | + protected function group_fields(...$fields) { |
|
137 | 137 | $result = array(); |
138 | 138 | array_map( |
139 | - function ( $item ) use ( &$result ) { |
|
139 | + function($item) use (&$result) { |
|
140 | 140 | $field_name = $item['name']; |
141 | - $result[ $field_name ] = $item; |
|
141 | + $result[$field_name] = $item; |
|
142 | 142 | }, |
143 | 143 | $fields |
144 | 144 | ); |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | return $result; |
147 | 147 | } |
148 | 148 | |
149 | - protected function group( $name, $pod, $group_fields ) { |
|
149 | + protected function group($name, $pod, $group_fields) { |
|
150 | 150 | $group = array( |
151 | 151 | 'name' => $name, |
152 | - 'label' => sprintf( 'WordLift - %s', $this->format_label( $name ) ), |
|
152 | + 'label' => sprintf('WordLift - %s', $this->format_label($name)), |
|
153 | 153 | 'description' => '', |
154 | 154 | 'weight' => 0, |
155 | 155 | |
156 | 156 | ); |
157 | - pods_register_group( $group, $pod['name'], $group_fields ); |
|
157 | + pods_register_group($group, $pod['name'], $group_fields); |
|
158 | 158 | } |
159 | 159 | |
160 | - protected function pod( $pod_id, $name, $type ) { |
|
160 | + protected function pod($pod_id, $name, $type) { |
|
161 | 161 | $pod = array( |
162 | 162 | 'name' => $name, |
163 | - 'label' => $this->format_label( $name ), |
|
163 | + 'label' => $this->format_label($name), |
|
164 | 164 | 'description' => '', |
165 | 165 | 'type' => $type, |
166 | 166 | 'storage' => 'meta', |
@@ -168,31 +168,31 @@ discard block |
||
168 | 168 | 'object' => $name, |
169 | 169 | ); |
170 | 170 | |
171 | - pods_register_type( $pod['type'], $pod['name'], $pod ); |
|
171 | + pods_register_type($pod['type'], $pod['name'], $pod); |
|
172 | 172 | |
173 | 173 | return $pod; |
174 | 174 | } |
175 | 175 | |
176 | 176 | protected function register_on_all_supported_taxonomies() { |
177 | 177 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
178 | - foreach ( $taxonomies as $taxonomy ) { |
|
179 | - $this->register_pod( $taxonomy, 'taxonomy' ); |
|
178 | + foreach ($taxonomies as $taxonomy) { |
|
179 | + $this->register_pod($taxonomy, 'taxonomy'); |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - protected function get_field_by_type( $name, $type, $field_data ) { |
|
185 | - if ( 'uri' === $type && isset( $field_data['constraints']['uri_type'] ) ) { |
|
186 | - return $this->relationship( $name, $field_data ); |
|
187 | - } elseif ( 'uri' === $type ) { |
|
184 | + protected function get_field_by_type($name, $type, $field_data) { |
|
185 | + if ('uri' === $type && isset($field_data['constraints']['uri_type'])) { |
|
186 | + return $this->relationship($name, $field_data); |
|
187 | + } elseif ('uri' === $type) { |
|
188 | 188 | return $this->website(); |
189 | - } elseif ( 'string' === $type ) { |
|
189 | + } elseif ('string' === $type) { |
|
190 | 190 | return $this->text(); |
191 | - } elseif ( 'double' === $type ) { |
|
192 | - return $this->number( $name, 2 ); |
|
193 | - } elseif ( 'date' === $type ) { |
|
191 | + } elseif ('double' === $type) { |
|
192 | + return $this->number($name, 2); |
|
193 | + } elseif ('date' === $type) { |
|
194 | 194 | return $this->datetime(); |
195 | - } elseif ( 'multiline' === $type ) { |
|
195 | + } elseif ('multiline' === $type) { |
|
196 | 196 | return $this->multiline(); |
197 | 197 | } else { |
198 | 198 | return $this->text(); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | ); |
222 | 222 | } |
223 | 223 | |
224 | - protected function number( $name, $decimals = 0 ) { |
|
224 | + protected function number($name, $decimals = 0) { |
|
225 | 225 | return array( |
226 | 226 | 'description' => '', |
227 | 227 | 'weight' => 1, |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | ); |
261 | 261 | } |
262 | 262 | |
263 | - protected function may_be_repeatable( $custom_field, $field ) { |
|
264 | - $repeatable = isset( $custom_field['constraints']['cardinality'] ) && INF === $custom_field['constraints']['cardinality']; |
|
265 | - if ( $repeatable ) { |
|
266 | - return $this->repeatable( $field ); |
|
263 | + protected function may_be_repeatable($custom_field, $field) { |
|
264 | + $repeatable = isset($custom_field['constraints']['cardinality']) && INF === $custom_field['constraints']['cardinality']; |
|
265 | + if ($repeatable) { |
|
266 | + return $this->repeatable($field); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $field; |
@@ -273,38 +273,38 @@ discard block |
||
273 | 273 | * @return array |
274 | 274 | * A function which defines these pods on the edit post screen. |
275 | 275 | */ |
276 | - protected function custom_field_to_pod_field( $custom_field ) { |
|
276 | + protected function custom_field_to_pod_field($custom_field) { |
|
277 | 277 | |
278 | - $name = str_replace( 'http://schema.org/', '', $custom_field['predicate'] ); |
|
279 | - $type = isset( $custom_field['type'] ) ? $custom_field['type'] : 'string'; |
|
278 | + $name = str_replace('http://schema.org/', '', $custom_field['predicate']); |
|
279 | + $type = isset($custom_field['type']) ? $custom_field['type'] : 'string'; |
|
280 | 280 | |
281 | - return $this->may_be_repeatable( $custom_field, $this->get_field_by_type( $name, $type, $custom_field ) ); |
|
281 | + return $this->may_be_repeatable($custom_field, $this->get_field_by_type($name, $type, $custom_field)); |
|
282 | 282 | } |
283 | 283 | |
284 | - protected function wordlift_css_class( $field ) { |
|
284 | + protected function wordlift_css_class($field) { |
|
285 | 285 | $field['class'] = 'wordlift'; |
286 | 286 | |
287 | 287 | return $field; |
288 | 288 | } |
289 | 289 | |
290 | - protected function custom_fields_to_pod_fields( $custom_fields, $pod_id ) { |
|
290 | + protected function custom_fields_to_pod_fields($custom_fields, $pod_id) { |
|
291 | 291 | |
292 | 292 | $pod_fields = array(); |
293 | 293 | |
294 | - foreach ( $custom_fields as $name => $custom_field ) { |
|
295 | - $pod_fields[] = $this->wordlift_css_class( $this->custom_field_to_pod_field( $custom_field ) ) + array( |
|
294 | + foreach ($custom_fields as $name => $custom_field) { |
|
295 | + $pod_fields[] = $this->wordlift_css_class($this->custom_field_to_pod_field($custom_field)) + array( |
|
296 | 296 | 'pod_id' => $pod_id, |
297 | - 'id' => intval( substr( md5( $pod_id . '_' . $name ), 0, 8 ), 16 ), |
|
297 | + 'id' => intval(substr(md5($pod_id.'_'.$name), 0, 8), 16), |
|
298 | 298 | 'name' => $name, |
299 | - 'label' => $this->format_label( str_replace( 'http://schema.org/', '', $custom_field['predicate'] ) ), |
|
299 | + 'label' => $this->format_label(str_replace('http://schema.org/', '', $custom_field['predicate'])), |
|
300 | 300 | ); |
301 | 301 | } |
302 | 302 | |
303 | - return array_values( $pod_fields ); |
|
303 | + return array_values($pod_fields); |
|
304 | 304 | } |
305 | 305 | |
306 | - protected function format_label( $name ) { |
|
307 | - return join( ' ', array_map( 'ucwords', preg_split( '/(?=[A-Z])/', $name ) ) ); |
|
306 | + protected function format_label($name) { |
|
307 | + return join(' ', array_map('ucwords', preg_split('/(?=[A-Z])/', $name))); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | } |
@@ -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,66 +6,66 @@ discard block |
||
6 | 6 | |
7 | 7 | class Notices { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Plugin |
|
11 | - */ |
|
12 | - private $pods_plugin; |
|
13 | - |
|
14 | - public function __construct( Plugin $plugin ) { |
|
15 | - $this->pods_plugin = $plugin; |
|
16 | - } |
|
17 | - |
|
18 | - public function register_hooks() { |
|
19 | - add_action( 'wl_metabox_before_html', array( $this, 'admin_notices' ) ); |
|
20 | - } |
|
21 | - |
|
22 | - public function admin_notices() { |
|
23 | - |
|
24 | - /** |
|
25 | - * When pods not installed or activated then the notice should appear. |
|
26 | - */ |
|
27 | - if ( ! $this->pods_plugin->is_plugin_installed() ) { |
|
28 | - $this->display_notice( |
|
29 | - __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift' ), |
|
30 | - __( 'Reinstall & Activate', 'wordlift' ) |
|
31 | - ); |
|
32 | - |
|
33 | - // Dont display notice. |
|
34 | - return; |
|
35 | - } |
|
36 | - |
|
37 | - if ( ! $this->pods_plugin->is_plugin_activated() ) { |
|
38 | - $this->display_notice( |
|
39 | - __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift' ), |
|
40 | - __( 'Reactivate', 'wordlift' ) |
|
41 | - ); |
|
42 | - |
|
43 | - return; |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - private function display_notice( $message, $button_text ) { |
|
48 | - |
|
49 | - $kses_options = array( |
|
50 | - 'p' => array(), |
|
51 | - 'b' => array(), |
|
52 | - 'button' => array( |
|
53 | - 'class' => array(), |
|
54 | - 'onclick' => array(), |
|
55 | - ), |
|
56 | - ); |
|
57 | - $installation_success_message = __( |
|
58 | - '<p>WordLift: <b>Pods – Custom Content Types and Fields</b> plugin installed and activated.</p>', // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings |
|
59 | - 'wordlift' |
|
60 | - ); |
|
61 | - |
|
62 | - $installing_message = __( 'Installing', 'wordlift' ) . ' <span class="spinner is-active"></span>'; |
|
63 | - $installation_failed_message = '<p>' . |
|
64 | - __( 'Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift' ) |
|
65 | - . '</p><button class="button action" onclick="wordliftInstallPods(this)">' |
|
66 | - . __( 'Retry', 'wordlift' ) |
|
67 | - . '</button>'; |
|
68 | - ?> |
|
9 | + /** |
|
10 | + * @var Plugin |
|
11 | + */ |
|
12 | + private $pods_plugin; |
|
13 | + |
|
14 | + public function __construct( Plugin $plugin ) { |
|
15 | + $this->pods_plugin = $plugin; |
|
16 | + } |
|
17 | + |
|
18 | + public function register_hooks() { |
|
19 | + add_action( 'wl_metabox_before_html', array( $this, 'admin_notices' ) ); |
|
20 | + } |
|
21 | + |
|
22 | + public function admin_notices() { |
|
23 | + |
|
24 | + /** |
|
25 | + * When pods not installed or activated then the notice should appear. |
|
26 | + */ |
|
27 | + if ( ! $this->pods_plugin->is_plugin_installed() ) { |
|
28 | + $this->display_notice( |
|
29 | + __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is not installed.', 'wordlift' ), |
|
30 | + __( 'Reinstall & Activate', 'wordlift' ) |
|
31 | + ); |
|
32 | + |
|
33 | + // Dont display notice. |
|
34 | + return; |
|
35 | + } |
|
36 | + |
|
37 | + if ( ! $this->pods_plugin->is_plugin_activated() ) { |
|
38 | + $this->display_notice( |
|
39 | + __( 'WordLift detected that <b>Pods – Custom Content Types and Fields</b> is deactivated.', 'wordlift' ), |
|
40 | + __( 'Reactivate', 'wordlift' ) |
|
41 | + ); |
|
42 | + |
|
43 | + return; |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + private function display_notice( $message, $button_text ) { |
|
48 | + |
|
49 | + $kses_options = array( |
|
50 | + 'p' => array(), |
|
51 | + 'b' => array(), |
|
52 | + 'button' => array( |
|
53 | + 'class' => array(), |
|
54 | + 'onclick' => array(), |
|
55 | + ), |
|
56 | + ); |
|
57 | + $installation_success_message = __( |
|
58 | + '<p>WordLift: <b>Pods – Custom Content Types and Fields</b> plugin installed and activated.</p>', // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings |
|
59 | + 'wordlift' |
|
60 | + ); |
|
61 | + |
|
62 | + $installing_message = __( 'Installing', 'wordlift' ) . ' <span class="spinner is-active"></span>'; |
|
63 | + $installation_failed_message = '<p>' . |
|
64 | + __( 'Wordlift: Pods – Custom Content Types and Fields installation failed, please retry or contact [email protected]', 'wordlift' ) |
|
65 | + . '</p><button class="button action" onclick="wordliftInstallPods(this)">' |
|
66 | + . __( 'Retry', 'wordlift' ) |
|
67 | + . '</button>'; |
|
68 | + ?> |
|
69 | 69 | |
70 | 70 | <script> |
71 | 71 | window.addEventListener("load", function () { |
@@ -100,5 +100,5 @@ discard block |
||
100 | 100 | <br/> |
101 | 101 | </div> |
102 | 102 | <?php |
103 | - } |
|
103 | + } |
|
104 | 104 | } |