Completed
Push — develop ( 0a7f51...08bc86 )
by David
01:05
created
src/includes/class-wordlift-post-excerpt-helper.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return string The excerpt.
40 40
 	 */
41
-	public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
41
+	public static function get_text_excerpt($post, $length = 55, $more = '...') {
42 42
 
43 43
 		/*
44 44
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
 		 *
47 47
 		 * @since 3.20.0
48 48
 		 */
49
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
49
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
50 50
 
51 51
 		// Filter shortcode content in post_content, before using it for trimming
52
-		$post_content = do_shortcode( $post_content );
52
+		$post_content = do_shortcode($post_content);
53 53
 
54 54
 		// Get the excerpt and trim it. Use the `post_excerpt` if available.
55
-		$excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
55
+		$excerpt = wp_trim_words( ! empty($post->post_excerpt) ? $post->post_excerpt : $post_content, $length, $more);
56 56
 
57 57
 		// Remove shortcodes and decode html entities.
58
-		return wp_strip_all_tags( html_entity_decode( self::strip_all_shortcodes( $excerpt ) ) );
58
+		return wp_strip_all_tags(html_entity_decode(self::strip_all_shortcodes($excerpt)));
59 59
 	}
60 60
 
61 61
 	/**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string The content without shortcodes.
71 71
 	 */
72
-	private static function strip_all_shortcodes( $content ) {
72
+	private static function strip_all_shortcodes($content) {
73 73
 
74
-		return preg_replace( '/\[[^]]+\]/', '', $content );
74
+		return preg_replace('/\[[^]]+\]/', '', $content);
75 75
 	}
76 76
 
77 77
 }
Please login to merge, or discard this patch.
src/wordlift/vocabulary-terms/jsonld/class-jsonld-generator.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	private $entity_service;
30 30
 
31
-	public function __construct( $entity_type_service, $property_getter ) {
31
+	public function __construct($entity_type_service, $property_getter) {
32 32
 		$this->entity_type_service      = $entity_type_service;
33 33
 		$this->property_getter          = $property_getter;
34 34
 		$this->term_entity_type_service = Type_Service::get_instance();
@@ -36,26 +36,26 @@  discard block
 block discarded – undo
36 36
 	}
37 37
 
38 38
 	public function init() {
39
-		add_filter( 'wl_term_jsonld_array', array( $this, 'wl_term_jsonld_array' ), 10, 2 );
39
+		add_filter('wl_term_jsonld_array', array($this, 'wl_term_jsonld_array'), 10, 2);
40 40
 	}
41 41
 
42
-	public function wl_term_jsonld_array( $data, $term_id ) {
42
+	public function wl_term_jsonld_array($data, $term_id) {
43 43
 		$jsonld     = $data['jsonld'];
44 44
 		$references = $data['references'];
45 45
 
46
-		$term_jsonld_data = $this->get_jsonld_data_for_term( $term_id );
46
+		$term_jsonld_data = $this->get_jsonld_data_for_term($term_id);
47 47
 
48 48
 		// Return early if we dont have the entity data
49 49
 		// for the term.
50
-		if ( ! $term_jsonld_data ) {
50
+		if ( ! $term_jsonld_data) {
51 51
 			return $data;
52 52
 		}
53 53
 
54 54
 		$term_jsonld = $term_jsonld_data['jsonld'];
55 55
 
56
-		$references = array_merge( $references, $term_jsonld_data['references'] );
56
+		$references = array_merge($references, $term_jsonld_data['references']);
57 57
 
58
-		array_unshift( $jsonld, $term_jsonld );
58
+		array_unshift($jsonld, $term_jsonld);
59 59
 
60 60
 		return array(
61 61
 			'jsonld'     => $jsonld,
@@ -63,50 +63,50 @@  discard block
 block discarded – undo
63 63
 		);
64 64
 	}
65 65
 
66
-	private function get_jsonld_data_for_term( $term_id ) {
66
+	private function get_jsonld_data_for_term($term_id) {
67 67
 
68
-		$id = $this->entity_service->get_uri( $term_id, Object_Type_Enum::TERM );
68
+		$id = $this->entity_service->get_uri($term_id, Object_Type_Enum::TERM);
69 69
 
70 70
 		// If we don't have a dataset  URI, then don't publish the term data
71 71
 		// on this page.
72
-		if ( ! $id ) {
72
+		if ( ! $id) {
73 73
 			return false;
74 74
 		}
75 75
 
76 76
 		$references = array();
77
-		$term       = get_term( $term_id );
78
-		$permalink  = get_term_link( $term );
77
+		$term       = get_term($term_id);
78
+		$permalink  = get_term_link($term);
79 79
 
80
-		$custom_fields = $this->entity_type_service->get_custom_fields_for_term( $term_id );
81
-		$term          = get_term( $term_id );
80
+		$custom_fields = $this->entity_type_service->get_custom_fields_for_term($term_id);
81
+		$term          = get_term($term_id);
82 82
 		$jsonld        = array(
83 83
 			'@context'    => 'http://schema.org',
84 84
 			'name'        => $term->name,
85
-			'@type'       => $this->term_entity_type_service->get_entity_types_labels( $term_id ),
85
+			'@type'       => $this->term_entity_type_service->get_entity_types_labels($term_id),
86 86
 			'@id'         => $id,
87
-			'description' => wp_strip_all_tags( self::strip_all_shortcodes( $term->description ) ),
87
+			'description' => wp_strip_all_tags(self::strip_all_shortcodes($term->description)),
88 88
 		);
89 89
 
90
-		if ( ! $custom_fields || ! is_array( $custom_fields ) ) {
90
+		if ( ! $custom_fields || ! is_array($custom_fields)) {
91 91
 			return $jsonld;
92 92
 		}
93 93
 
94
-		foreach ( $custom_fields as $key => $value ) {
95
-			$name  = $this->relative_to_schema_context( $value['predicate'] );
96
-			$value = $this->property_getter->get( $term_id, $key, Object_Type_Enum::TERM );
97
-			$value = $this->process_value( $value, $references );
98
-			if ( ! isset( $value ) ||
99
-				 is_array( $value ) && empty( $value ) ||
100
-				 is_string( $value ) && empty( $value ) ) {
94
+		foreach ($custom_fields as $key => $value) {
95
+			$name  = $this->relative_to_schema_context($value['predicate']);
96
+			$value = $this->property_getter->get($term_id, $key, Object_Type_Enum::TERM);
97
+			$value = $this->process_value($value, $references);
98
+			if ( ! isset($value) ||
99
+				 is_array($value) && empty($value) ||
100
+				 is_string($value) && empty($value)) {
101 101
 				continue;
102 102
 			}
103
-			$jsonld[ $name ] = $value;
103
+			$jsonld[$name] = $value;
104 104
 
105 105
 		}
106 106
 
107
-		$jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process( $jsonld );
107
+		$jsonld = \Wordlift_Entity_Post_To_Jsonld_Converter::post_process($jsonld);
108 108
 
109
-		if ( $permalink ) {
109
+		if ($permalink) {
110 110
 			$jsonld['mainEntityOfPage'] = $permalink;
111 111
 		}
112 112
 
@@ -121,21 +121,21 @@  discard block
 block discarded – undo
121 121
 
122 122
 	}
123 123
 
124
-	private function relative_to_schema_context( $predicate ) {
125
-		return str_replace( 'http://schema.org/', '', $predicate );
124
+	private function relative_to_schema_context($predicate) {
125
+		return str_replace('http://schema.org/', '', $predicate);
126 126
 	}
127 127
 
128
-	private function process_value( $value, &$references ) {
128
+	private function process_value($value, &$references) {
129 129
 
130
-		if ( is_array( $value )
131
-			 && count( $value ) > 0
132
-			 && $value[0] instanceof \Wordlift_Property_Entity_Reference ) {
130
+		if (is_array($value)
131
+			 && count($value) > 0
132
+			 && $value[0] instanceof \Wordlift_Property_Entity_Reference) {
133 133
 
134 134
 			// All of the references from the custom fields are post references.
135 135
 			$references = array_merge(
136 136
 				$references,
137 137
 				array_map(
138
-					function ( $property_entity_reference ) {
138
+					function($property_entity_reference) {
139 139
 						/**
140 140
 						 * @var $property_entity_reference \Wordlift_Property_Entity_Reference
141 141
 						 */
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 			);
147 147
 
148 148
 			return array_map(
149
-				function ( $reference ) {
149
+				function($reference) {
150 150
 					/**
151 151
 					 * @var $reference \Wordlift_Property_Entity_Reference
152 152
 					 */
153
-					return array( '@id' => $reference->get_url() );
153
+					return array('@id' => $reference->get_url());
154 154
 				},
155 155
 				$value
156 156
 			);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	 *
172 172
 	 * @return string The content without shortcodes.
173 173
 	 */
174
-	private static function strip_all_shortcodes( $content ) {
175
-		return preg_replace( '/\[[^]]+\]/', '', $content );
174
+	private static function strip_all_shortcodes($content) {
175
+		return preg_replace('/\[[^]]+\]/', '', $content);
176 176
 	}
177 177
 }
Please login to merge, or discard this patch.