Completed
Pull Request — master (#1560)
by Naveen
01:34
created
src/wordlift/vocabulary-terms/class-entity-type.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,48 +15,48 @@  discard block
 block discarded – undo
15 15
 
16 16
 class Entity_Type {
17 17
 
18
-	public function __construct() {
19
-
20
-		$that = $this;
21
-
22
-		add_action(
23
-			'init',
24
-			function () use ( $that ) {
25
-				$that->init_ui_and_save_handlers();
26
-			}
27
-		);
28
-	}
29
-
30
-
31
-	/**
32
-	 * @param $term  \WP_Term
33
-	 */
34
-	public function render_ui( $term ) {
35
-
36
-		$entity_types_text     = __( 'Entity Types', 'wordlift' );
37
-		$selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
38
-
39
-		/**
40
-		 * Thing should be the default selected entity type
41
-		 * when this feature is activated.
42
-		 */
43
-		if ( count( $selected_entity_types ) === 0 ) {
44
-			$selected_entity_types[] = 'thing';
45
-		}
46
-
47
-		$entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME;
48
-		$types                = Terms_Compat::get_terms(
49
-			$entity_type_taxonomy,
50
-			array(
51
-				'taxonomy'   => $entity_type_taxonomy,
52
-				'parent'     => 0,
53
-				'hide_empty' => false,
54
-			)
55
-		);
56
-
57
-		$terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types );
58
-
59
-		$template = <<<EOF
18
+    public function __construct() {
19
+
20
+        $that = $this;
21
+
22
+        add_action(
23
+            'init',
24
+            function () use ( $that ) {
25
+                $that->init_ui_and_save_handlers();
26
+            }
27
+        );
28
+    }
29
+
30
+
31
+    /**
32
+     * @param $term  \WP_Term
33
+     */
34
+    public function render_ui( $term ) {
35
+
36
+        $entity_types_text     = __( 'Entity Types', 'wordlift' );
37
+        $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
38
+
39
+        /**
40
+         * Thing should be the default selected entity type
41
+         * when this feature is activated.
42
+         */
43
+        if ( count( $selected_entity_types ) === 0 ) {
44
+            $selected_entity_types[] = 'thing';
45
+        }
46
+
47
+        $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME;
48
+        $types                = Terms_Compat::get_terms(
49
+            $entity_type_taxonomy,
50
+            array(
51
+                'taxonomy'   => $entity_type_taxonomy,
52
+                'parent'     => 0,
53
+                'hide_empty' => false,
54
+            )
55
+        );
56
+
57
+        $terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types );
58
+
59
+        $template = <<<EOF
60 60
         <tr class="form-field term-name-wrap">
61 61
             <th scope="row"><label for="wl-entity-type__checklist">%s</label></th>
62 62
             <td>
@@ -64,42 +64,42 @@  discard block
 block discarded – undo
64 64
             </td>
65 65
         </tr>
66 66
 EOF;
67
-		echo sprintf( $template, esc_html( $entity_types_text ), $terms_html );
68
-
69
-		$this->enqueue_script_and_style();
70
-	}
71
-
72
-	public function save_field( $term_id ) {
73
-		if ( ! isset( $_REQUEST['tax_input'] ) ) {
74
-			return;
75
-		}
76
-		$entity_types = isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] )
77
-			? (array) $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] : array();
78
-		if ( isset( $entity_types ) && is_array( $entity_types ) ) {
79
-			// Save the taxonomies.
80
-			delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
81
-			foreach ( $entity_types as $entity_type ) {
82
-				add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type );
83
-			}
84
-		}
85
-	}
86
-
87
-	public function init_ui_and_save_handlers() {
88
-		$taxonomies = Terms_Compat::get_public_taxonomies();
89
-		foreach ( $taxonomies as $taxonomy ) {
90
-			add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 );
91
-			add_action( "edited_${taxonomy}", array( $this, 'save_field' ) );
92
-		}
93
-	}
94
-
95
-	private function enqueue_script_and_style() {
96
-
97
-		Scripts_Helper::enqueue_based_on_wordpress_version( 'wl-vocabulary-term',
98
-			plugin_dir_url( dirname(  __DIR__ ) ) . '/js/dist/vocabulary-term',
99
-			array('wp-polyfill')
100
-		);
101
-		wp_enqueue_style( 'wl-vocabulary-term',
102
-			plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css' );
103
-	}
67
+        echo sprintf( $template, esc_html( $entity_types_text ), $terms_html );
68
+
69
+        $this->enqueue_script_and_style();
70
+    }
71
+
72
+    public function save_field( $term_id ) {
73
+        if ( ! isset( $_REQUEST['tax_input'] ) ) {
74
+            return;
75
+        }
76
+        $entity_types = isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] )
77
+            ? (array) $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] : array();
78
+        if ( isset( $entity_types ) && is_array( $entity_types ) ) {
79
+            // Save the taxonomies.
80
+            delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
81
+            foreach ( $entity_types as $entity_type ) {
82
+                add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type );
83
+            }
84
+        }
85
+    }
86
+
87
+    public function init_ui_and_save_handlers() {
88
+        $taxonomies = Terms_Compat::get_public_taxonomies();
89
+        foreach ( $taxonomies as $taxonomy ) {
90
+            add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 );
91
+            add_action( "edited_${taxonomy}", array( $this, 'save_field' ) );
92
+        }
93
+    }
94
+
95
+    private function enqueue_script_and_style() {
96
+
97
+        Scripts_Helper::enqueue_based_on_wordpress_version( 'wl-vocabulary-term',
98
+            plugin_dir_url( dirname(  __DIR__ ) ) . '/js/dist/vocabulary-term',
99
+            array('wp-polyfill')
100
+        );
101
+        wp_enqueue_style( 'wl-vocabulary-term',
102
+            plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css' );
103
+    }
104 104
 
105 105
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 		add_action(
23 23
 			'init',
24
-			function () use ( $that ) {
24
+			function() use ($that) {
25 25
 				$that->init_ui_and_save_handlers();
26 26
 			}
27 27
 		);
@@ -31,16 +31,16 @@  discard block
 block discarded – undo
31 31
 	/**
32 32
 	 * @param $term  \WP_Term
33 33
 	 */
34
-	public function render_ui( $term ) {
34
+	public function render_ui($term) {
35 35
 
36
-		$entity_types_text     = __( 'Entity Types', 'wordlift' );
37
-		$selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
36
+		$entity_types_text     = __('Entity Types', 'wordlift');
37
+		$selected_entity_types = get_term_meta($term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
38 38
 
39 39
 		/**
40 40
 		 * Thing should be the default selected entity type
41 41
 		 * when this feature is activated.
42 42
 		 */
43
-		if ( count( $selected_entity_types ) === 0 ) {
43
+		if (count($selected_entity_types) === 0) {
44 44
 			$selected_entity_types[] = 'thing';
45 45
 		}
46 46
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			)
55 55
 		);
56 56
 
57
-		$terms_html = Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types );
57
+		$terms_html = Term_Checklist::render('tax_input[wl_entity_type]', $types, $selected_entity_types);
58 58
 
59 59
 		$template = <<<EOF
60 60
         <tr class="form-field term-name-wrap">
@@ -64,42 +64,42 @@  discard block
 block discarded – undo
64 64
             </td>
65 65
         </tr>
66 66
 EOF;
67
-		echo sprintf( $template, esc_html( $entity_types_text ), $terms_html );
67
+		echo sprintf($template, esc_html($entity_types_text), $terms_html);
68 68
 
69 69
 		$this->enqueue_script_and_style();
70 70
 	}
71 71
 
72
-	public function save_field( $term_id ) {
73
-		if ( ! isset( $_REQUEST['tax_input'] ) ) {
72
+	public function save_field($term_id) {
73
+		if ( ! isset($_REQUEST['tax_input'])) {
74 74
 			return;
75 75
 		}
76
-		$entity_types = isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] )
77
-			? (array) $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] : array();
78
-		if ( isset( $entity_types ) && is_array( $entity_types ) ) {
76
+		$entity_types = isset($_REQUEST['tax_input'][Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME])
77
+			? (array) $_REQUEST['tax_input'][Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME] : array();
78
+		if (isset($entity_types) && is_array($entity_types)) {
79 79
 			// Save the taxonomies.
80
-			delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
81
-			foreach ( $entity_types as $entity_type ) {
82
-				add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type );
80
+			delete_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
81
+			foreach ($entity_types as $entity_type) {
82
+				add_term_meta($term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type);
83 83
 			}
84 84
 		}
85 85
 	}
86 86
 
87 87
 	public function init_ui_and_save_handlers() {
88 88
 		$taxonomies = Terms_Compat::get_public_taxonomies();
89
-		foreach ( $taxonomies as $taxonomy ) {
90
-			add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 );
91
-			add_action( "edited_${taxonomy}", array( $this, 'save_field' ) );
89
+		foreach ($taxonomies as $taxonomy) {
90
+			add_action("${taxonomy}_edit_form_fields", array($this, 'render_ui'), 1);
91
+			add_action("edited_${taxonomy}", array($this, 'save_field'));
92 92
 		}
93 93
 	}
94 94
 
95 95
 	private function enqueue_script_and_style() {
96 96
 
97
-		Scripts_Helper::enqueue_based_on_wordpress_version( 'wl-vocabulary-term',
98
-			plugin_dir_url( dirname(  __DIR__ ) ) . '/js/dist/vocabulary-term',
97
+		Scripts_Helper::enqueue_based_on_wordpress_version('wl-vocabulary-term',
98
+			plugin_dir_url(dirname(__DIR__)).'/js/dist/vocabulary-term',
99 99
 			array('wp-polyfill')
100 100
 		);
101
-		wp_enqueue_style( 'wl-vocabulary-term',
102
-			plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css' );
101
+		wp_enqueue_style('wl-vocabulary-term',
102
+			plugin_dir_url(dirname(__DIR__)).'/js/dist/vocabulary-term.css');
103 103
 	}
104 104
 
105 105
 }
Please login to merge, or discard this patch.