Completed
Push — develop ( 4f9670...66f708 )
by David
02:29 queued 15s
created
src/includes/properties/class-wordlift-required-property-service.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
  */
7 7
 class Wordlift_Required_Property_Service extends Wordlift_Entity_Property_Service {
8 8
 
9
-	/**
10
-	 * {@inheritdoc}
11
-	 */
12
-	public function get( $id, $meta_key, $type ) {
9
+    /**
10
+     * {@inheritdoc}
11
+     */
12
+    public function get( $id, $meta_key, $type ) {
13 13
 
14
-		return array_map(
15
-			function ( $item ) {
14
+        return array_map(
15
+            function ( $item ) {
16 16
 
17
-				// If this is an entity reference, set that this entity is always required in SD output.
18
-				if ( $item instanceof Wordlift_Property_Entity_Reference ) {
19
-					  $item->set_required( true );
20
-				}
17
+                // If this is an entity reference, set that this entity is always required in SD output.
18
+                if ( $item instanceof Wordlift_Property_Entity_Reference ) {
19
+                        $item->set_required( true );
20
+                }
21 21
 
22
-				return $item;
23
-			},
24
-			parent::get( $id, $meta_key, $type )
25
-		);
26
-	}
22
+                return $item;
23
+            },
24
+            parent::get( $id, $meta_key, $type )
25
+        );
26
+    }
27 27
 
28 28
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 	/**
10 10
 	 * {@inheritdoc}
11 11
 	 */
12
-	public function get( $id, $meta_key, $type ) {
12
+	public function get($id, $meta_key, $type) {
13 13
 
14 14
 		return array_map(
15
-			function ( $item ) {
15
+			function($item) {
16 16
 
17 17
 				// If this is an entity reference, set that this entity is always required in SD output.
18
-				if ( $item instanceof Wordlift_Property_Entity_Reference ) {
19
-					  $item->set_required( true );
18
+				if ($item instanceof Wordlift_Property_Entity_Reference) {
19
+					  $item->set_required(true);
20 20
 				}
21 21
 
22 22
 				return $item;
23 23
 			},
24
-			parent::get( $id, $meta_key, $type )
24
+			parent::get($id, $meta_key, $type)
25 25
 		);
26 26
 	}
27 27
 
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-location-property-service.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,28 +15,28 @@
 block discarded – undo
15 15
  */
16 16
 class Wordlift_Location_Property_Service extends Wordlift_Entity_Property_Service {
17 17
 
18
-	/**
19
-	 * {@inheritdoc}
20
-	 */
21
-	public function get( $id, $meta_key, $type ) {
18
+    /**
19
+     * {@inheritdoc}
20
+     */
21
+    public function get( $id, $meta_key, $type ) {
22 22
 
23
-		return array_map(
24
-			function ( $item ) {
23
+        return array_map(
24
+            function ( $item ) {
25 25
 
26
-				// If this is an entity reference, set that this entity is always required in SD output.
27
-				if ( $item instanceof Wordlift_Property_Entity_Reference ) {
28
-					  $item->set_required( true );
26
+                // If this is an entity reference, set that this entity is always required in SD output.
27
+                if ( $item instanceof Wordlift_Property_Entity_Reference ) {
28
+                        $item->set_required( true );
29 29
 
30
-					  return $item;
31
-				}
30
+                        return $item;
31
+                }
32 32
 
33
-				return array(
34
-					'@type' => 'Place',
35
-					'name'  => $item,
36
-				);
37
-			},
38
-			parent::get( $id, $meta_key, $type )
39
-		);
40
-	}
33
+                return array(
34
+                    '@type' => 'Place',
35
+                    'name'  => $item,
36
+                );
37
+            },
38
+            parent::get( $id, $meta_key, $type )
39
+        );
40
+    }
41 41
 
42 42
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * {@inheritdoc}
20 20
 	 */
21
-	public function get( $id, $meta_key, $type ) {
21
+	public function get($id, $meta_key, $type) {
22 22
 
23 23
 		return array_map(
24
-			function ( $item ) {
24
+			function($item) {
25 25
 
26 26
 				// If this is an entity reference, set that this entity is always required in SD output.
27
-				if ( $item instanceof Wordlift_Property_Entity_Reference ) {
28
-					  $item->set_required( true );
27
+				if ($item instanceof Wordlift_Property_Entity_Reference) {
28
+					  $item->set_required(true);
29 29
 
30 30
 					  return $item;
31 31
 				}
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 					'name'  => $item,
36 36
 				);
37 37
 			},
38
-			parent::get( $id, $meta_key, $type )
38
+			parent::get($id, $meta_key, $type)
39 39
 		);
40 40
 	}
41 41
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-redirect-service.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -14,143 +14,143 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Redirect_Service {
16 16
 
17
-	const LOD_ENDPOINT = 'http://www.lodview.it';
18
-	const LOD_HOST     = 'www.lodview.it';
19
-
20
-	/**
21
-	 * The Log service.
22
-	 *
23
-	 * @since 3.2.0
24
-	 * @access private
25
-	 * @var \Wordlift_Log_Service $log_service The Log service.
26
-	 */
27
-	private $log_service;
28
-
29
-	/**
30
-	 * The Entity URI service.
31
-	 *
32
-	 * @since 3.2.0
33
-	 * @access private
34
-	 * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
35
-	 */
36
-	private $entity_uri_service;
37
-
38
-	/**
39
-	 * A singleton instance of the Redirect service (useful for unit tests).
40
-	 *
41
-	 * @since 3.2.0
42
-	 * @access private
43
-	 * @var \Wordlift_Redirect_Service $instance The singleton instance.
44
-	 */
45
-	private static $instance;
46
-
47
-	/**
48
-	 * Create a Wordlift_Redirect_Service instance.
49
-	 *
50
-	 * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
51
-	 *
52
-	 * @since 3.2.0
53
-	 */
54
-	public function __construct( $entity_uri_service ) {
55
-
56
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
57
-
58
-		$this->entity_uri_service = $entity_uri_service;
59
-
60
-		self::$instance = $this;
61
-
62
-	}
63
-
64
-	/**
65
-	 * Get the singleton instance of the Wordlift_Redirect_Service
66
-	 *
67
-	 * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service.
68
-	 * @since 3.2.0
69
-	 */
70
-	public static function get_instance() {
71
-
72
-		return self::$instance;
73
-	}
74
-
75
-	/**
76
-	 * Perform redirect depending on entity uri and target
77
-	 *
78
-	 * @since 3.2.0
79
-	 */
80
-	public function ajax_redirect() {
81
-
82
-		// Check the `uri` parameter.
83
-		$entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
84
-		if ( ! $entity_uri ) {
85
-			wp_die(
86
-				esc_html__( 'Invalid URI.', 'wordlift' ),
87
-				esc_html__( 'Invalid URI.', 'wordlift' ),
88
-				array(
89
-					'response'  => 400,
90
-					'back_link' => true,
91
-				)
92
-			);
93
-		}
94
-
95
-		// Check the `to` parameter.
96
-		$target = filter_input( INPUT_GET, 'to' );
97
-		if ( ! $target ) {
98
-			wp_die(
99
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
101
-				array(
102
-					'response'  => 400,
103
-					'back_link' => true,
104
-				)
105
-			);
106
-		}
107
-
108
-		/** @var Wordpress_Content $content */
109
-		$content = Wordpress_Content_Service::get_instance()
110
-											->get_by_entity_id_or_same_as( $entity_uri );
111
-
112
-		if ( ! isset( $content ) ) {
113
-			wp_die(
114
-				esc_html__( 'Entity not found.', 'wordlift' ),
115
-				esc_html__( 'Entity not found.', 'wordlift' ),
116
-				array(
117
-					'response'  => 404,
118
-					'back_link' => true,
119
-				)
120
-			);
121
-		}
122
-
123
-		switch ( $target ) {
124
-			case 'edit':
125
-				$redirect_url = $content->get_edit_link();
126
-				break;
127
-			case 'lod':
128
-				$redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
129
-				break;
130
-			case 'permalink':
131
-				$redirect_url = $content->get_permalink();
132
-				break;
133
-			default:
134
-				wp_die( 'Unsupported redirect target.' );
135
-		}
136
-
137
-		// Perform the redirect
138
-		wp_safe_redirect( $redirect_url );
139
-		exit;
140
-	}
141
-
142
-	/**
143
-	 * Register custom allowed hosts.
144
-	 *
145
-	 * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
146
-	 *
147
-	 * @since 3.2.0
148
-	 *
149
-	 * @return array permalink.
150
-	 */
151
-	public function allowed_redirect_hosts( $content ) {
152
-
153
-		return array_merge( $content, array( self::LOD_HOST ) );
154
-	}
17
+    const LOD_ENDPOINT = 'http://www.lodview.it';
18
+    const LOD_HOST     = 'www.lodview.it';
19
+
20
+    /**
21
+     * The Log service.
22
+     *
23
+     * @since 3.2.0
24
+     * @access private
25
+     * @var \Wordlift_Log_Service $log_service The Log service.
26
+     */
27
+    private $log_service;
28
+
29
+    /**
30
+     * The Entity URI service.
31
+     *
32
+     * @since 3.2.0
33
+     * @access private
34
+     * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
35
+     */
36
+    private $entity_uri_service;
37
+
38
+    /**
39
+     * A singleton instance of the Redirect service (useful for unit tests).
40
+     *
41
+     * @since 3.2.0
42
+     * @access private
43
+     * @var \Wordlift_Redirect_Service $instance The singleton instance.
44
+     */
45
+    private static $instance;
46
+
47
+    /**
48
+     * Create a Wordlift_Redirect_Service instance.
49
+     *
50
+     * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
51
+     *
52
+     * @since 3.2.0
53
+     */
54
+    public function __construct( $entity_uri_service ) {
55
+
56
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
57
+
58
+        $this->entity_uri_service = $entity_uri_service;
59
+
60
+        self::$instance = $this;
61
+
62
+    }
63
+
64
+    /**
65
+     * Get the singleton instance of the Wordlift_Redirect_Service
66
+     *
67
+     * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service.
68
+     * @since 3.2.0
69
+     */
70
+    public static function get_instance() {
71
+
72
+        return self::$instance;
73
+    }
74
+
75
+    /**
76
+     * Perform redirect depending on entity uri and target
77
+     *
78
+     * @since 3.2.0
79
+     */
80
+    public function ajax_redirect() {
81
+
82
+        // Check the `uri` parameter.
83
+        $entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
84
+        if ( ! $entity_uri ) {
85
+            wp_die(
86
+                esc_html__( 'Invalid URI.', 'wordlift' ),
87
+                esc_html__( 'Invalid URI.', 'wordlift' ),
88
+                array(
89
+                    'response'  => 400,
90
+                    'back_link' => true,
91
+                )
92
+            );
93
+        }
94
+
95
+        // Check the `to` parameter.
96
+        $target = filter_input( INPUT_GET, 'to' );
97
+        if ( ! $target ) {
98
+            wp_die(
99
+                esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
+                esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
101
+                array(
102
+                    'response'  => 400,
103
+                    'back_link' => true,
104
+                )
105
+            );
106
+        }
107
+
108
+        /** @var Wordpress_Content $content */
109
+        $content = Wordpress_Content_Service::get_instance()
110
+                                            ->get_by_entity_id_or_same_as( $entity_uri );
111
+
112
+        if ( ! isset( $content ) ) {
113
+            wp_die(
114
+                esc_html__( 'Entity not found.', 'wordlift' ),
115
+                esc_html__( 'Entity not found.', 'wordlift' ),
116
+                array(
117
+                    'response'  => 404,
118
+                    'back_link' => true,
119
+                )
120
+            );
121
+        }
122
+
123
+        switch ( $target ) {
124
+            case 'edit':
125
+                $redirect_url = $content->get_edit_link();
126
+                break;
127
+            case 'lod':
128
+                $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
129
+                break;
130
+            case 'permalink':
131
+                $redirect_url = $content->get_permalink();
132
+                break;
133
+            default:
134
+                wp_die( 'Unsupported redirect target.' );
135
+        }
136
+
137
+        // Perform the redirect
138
+        wp_safe_redirect( $redirect_url );
139
+        exit;
140
+    }
141
+
142
+    /**
143
+     * Register custom allowed hosts.
144
+     *
145
+     * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
146
+     *
147
+     * @since 3.2.0
148
+     *
149
+     * @return array permalink.
150
+     */
151
+    public function allowed_redirect_hosts( $content ) {
152
+
153
+        return array_merge( $content, array( self::LOD_HOST ) );
154
+    }
155 155
 
156 156
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @since 3.2.0
53 53
 	 */
54
-	public function __construct( $entity_uri_service ) {
54
+	public function __construct($entity_uri_service) {
55 55
 
56
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
56
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Redirect_Service');
57 57
 
58 58
 		$this->entity_uri_service = $entity_uri_service;
59 59
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	public function ajax_redirect() {
81 81
 
82 82
 		// Check the `uri` parameter.
83
-		$entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
84
-		if ( ! $entity_uri ) {
83
+		$entity_uri = filter_input(INPUT_GET, 'uri', FILTER_VALIDATE_URL);
84
+		if ( ! $entity_uri) {
85 85
 			wp_die(
86
-				esc_html__( 'Invalid URI.', 'wordlift' ),
87
-				esc_html__( 'Invalid URI.', 'wordlift' ),
86
+				esc_html__('Invalid URI.', 'wordlift'),
87
+				esc_html__('Invalid URI.', 'wordlift'),
88 88
 				array(
89 89
 					'response'  => 400,
90 90
 					'back_link' => true,
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 
95 95
 		// Check the `to` parameter.
96
-		$target = filter_input( INPUT_GET, 'to' );
97
-		if ( ! $target ) {
96
+		$target = filter_input(INPUT_GET, 'to');
97
+		if ( ! $target) {
98 98
 			wp_die(
99
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
99
+				esc_html__('Invalid `to` parameter.', 'wordlift'),
100
+				esc_html__('Invalid `to` parameter.', 'wordlift'),
101 101
 				array(
102 102
 					'response'  => 400,
103 103
 					'back_link' => true,
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 
108 108
 		/** @var Wordpress_Content $content */
109 109
 		$content = Wordpress_Content_Service::get_instance()
110
-											->get_by_entity_id_or_same_as( $entity_uri );
110
+											->get_by_entity_id_or_same_as($entity_uri);
111 111
 
112
-		if ( ! isset( $content ) ) {
112
+		if ( ! isset($content)) {
113 113
 			wp_die(
114
-				esc_html__( 'Entity not found.', 'wordlift' ),
115
-				esc_html__( 'Entity not found.', 'wordlift' ),
114
+				esc_html__('Entity not found.', 'wordlift'),
115
+				esc_html__('Entity not found.', 'wordlift'),
116 116
 				array(
117 117
 					'response'  => 404,
118 118
 					'back_link' => true,
@@ -120,22 +120,22 @@  discard block
 block discarded – undo
120 120
 			);
121 121
 		}
122 122
 
123
-		switch ( $target ) {
123
+		switch ($target) {
124 124
 			case 'edit':
125 125
 				$redirect_url = $content->get_edit_link();
126 126
 				break;
127 127
 			case 'lod':
128
-				$redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
128
+				$redirect_url = self::LOD_ENDPOINT.'/lodview/?IRI='.rawurlencode($entity_uri);
129 129
 				break;
130 130
 			case 'permalink':
131 131
 				$redirect_url = $content->get_permalink();
132 132
 				break;
133 133
 			default:
134
-				wp_die( 'Unsupported redirect target.' );
134
+				wp_die('Unsupported redirect target.');
135 135
 		}
136 136
 
137 137
 		// Perform the redirect
138
-		wp_safe_redirect( $redirect_url );
138
+		wp_safe_redirect($redirect_url);
139 139
 		exit;
140 140
 	}
141 141
 
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return array permalink.
150 150
 	 */
151
-	public function allowed_redirect_hosts( $content ) {
151
+	public function allowed_redirect_hosts($content) {
152 152
 
153
-		return array_merge( $content, array( self::LOD_HOST ) );
153
+		return array_merge($content, array(self::LOD_HOST));
154 154
 	}
155 155
 
156 156
 }
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-sync-service.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -16,128 +16,128 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Schemaorg_Sync_Service {
18 18
 
19
-	/**
20
-	 * A {@link Wordlift_Log_Service} instance.
21
-	 *
22
-	 * @since 3.20.0
23
-	 * @access private
24
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
25
-	 */
26
-	private $log;
27
-
28
-	/**
29
-	 * The singleton instance.
30
-	 *
31
-	 * @since 3.20.0
32
-	 * @access private
33
-	 * @var \Wordlift_Schemaorg_Sync_Service $instance The singleton instance.
34
-	 */
35
-	private static $instance;
36
-
37
-	/**
38
-	 * Create a {@link Wordlift_Schemaorg_Sync_Service} instance.
39
-	 *
40
-	 * @since 3.20.0
41
-	 */
42
-	public function __construct() {
43
-
44
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
45
-
46
-		// Hook the `wl_sync_schemaorg` ajax action.
47
-		add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) );
48
-
49
-		self::$instance = $this;
50
-
51
-	}
52
-
53
-	/**
54
-	 * Get the singleton instance.
55
-	 *
56
-	 * @since 3.20.0
57
-	 *
58
-	 * @return \Wordlift_Schemaorg_Sync_Service The singleton instance.
59
-	 */
60
-	public static function get_instance() {
61
-
62
-		return self::$instance;
63
-	}
64
-
65
-	/**
66
-	 * Load the Schema.org classes from a file.
67
-	 *
68
-	 * @since 3.20.0
69
-	 *
70
-	 * @return bool True if successful otherwise false.
71
-	 */
72
-	public function load_from_file() {
73
-
74
-		// Load the file contents.
75
-		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
76
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
77
-
78
-		// Load the file contents.
79
-		return $this->load( $contents );
80
-	}
81
-
82
-	/**
83
-	 * Load the Schema.org classes from the provided contents.
84
-	 *
85
-	 * @param $contents
86
-	 *
87
-	 * @return bool
88
-	 */
89
-	private function load( $contents ) {
90
-
91
-		// Decode the JSON contents.
92
-		$json = json_decode( $contents, true );
93
-
94
-		if ( null === $json ) {
95
-			$this->log->error( 'Invalid json.' );
96
-
97
-			// Error: invalid body.
98
-			return false;
99
-		}
100
-
101
-		if ( ! isset( $json['schemaClasses'] ) ) {
102
-			$this->log->error( '`schemaClasses` missing from json.' );
103
-
104
-			// Error: invalid json.
105
-			return false;
106
-		}
107
-
108
-		// Load the Schema.org classes.
109
-		foreach ( $json['schemaClasses'] as $schema_class ) {
110
-			$slug = $schema_class['dashname'];
111
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
112
-
113
-			$args = array(
114
-				'parent'      => 0,
115
-				'description' => $schema_class['description'],
116
-				'slug'        => $schema_class['dashname'],
117
-			);
118
-			if ( null !== $term ) {
119
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
120
-			} else {
121
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
122
-			}
123
-
124
-			// Update the parents/children relationship.
125
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
126
-			foreach ( $schema_class['children'] as $child ) {
127
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
128
-			}
129
-
130
-			// Update the term name.
131
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
132
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
133
-
134
-			// Update the term URI.
135
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
136
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
137
-
138
-		}
139
-
140
-		return true;
141
-	}
19
+    /**
20
+     * A {@link Wordlift_Log_Service} instance.
21
+     *
22
+     * @since 3.20.0
23
+     * @access private
24
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
25
+     */
26
+    private $log;
27
+
28
+    /**
29
+     * The singleton instance.
30
+     *
31
+     * @since 3.20.0
32
+     * @access private
33
+     * @var \Wordlift_Schemaorg_Sync_Service $instance The singleton instance.
34
+     */
35
+    private static $instance;
36
+
37
+    /**
38
+     * Create a {@link Wordlift_Schemaorg_Sync_Service} instance.
39
+     *
40
+     * @since 3.20.0
41
+     */
42
+    public function __construct() {
43
+
44
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
45
+
46
+        // Hook the `wl_sync_schemaorg` ajax action.
47
+        add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) );
48
+
49
+        self::$instance = $this;
50
+
51
+    }
52
+
53
+    /**
54
+     * Get the singleton instance.
55
+     *
56
+     * @since 3.20.0
57
+     *
58
+     * @return \Wordlift_Schemaorg_Sync_Service The singleton instance.
59
+     */
60
+    public static function get_instance() {
61
+
62
+        return self::$instance;
63
+    }
64
+
65
+    /**
66
+     * Load the Schema.org classes from a file.
67
+     *
68
+     * @since 3.20.0
69
+     *
70
+     * @return bool True if successful otherwise false.
71
+     */
72
+    public function load_from_file() {
73
+
74
+        // Load the file contents.
75
+        // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
76
+        $contents = file_get_contents( __DIR__ . '/schema-classes.json' );
77
+
78
+        // Load the file contents.
79
+        return $this->load( $contents );
80
+    }
81
+
82
+    /**
83
+     * Load the Schema.org classes from the provided contents.
84
+     *
85
+     * @param $contents
86
+     *
87
+     * @return bool
88
+     */
89
+    private function load( $contents ) {
90
+
91
+        // Decode the JSON contents.
92
+        $json = json_decode( $contents, true );
93
+
94
+        if ( null === $json ) {
95
+            $this->log->error( 'Invalid json.' );
96
+
97
+            // Error: invalid body.
98
+            return false;
99
+        }
100
+
101
+        if ( ! isset( $json['schemaClasses'] ) ) {
102
+            $this->log->error( '`schemaClasses` missing from json.' );
103
+
104
+            // Error: invalid json.
105
+            return false;
106
+        }
107
+
108
+        // Load the Schema.org classes.
109
+        foreach ( $json['schemaClasses'] as $schema_class ) {
110
+            $slug = $schema_class['dashname'];
111
+            $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
112
+
113
+            $args = array(
114
+                'parent'      => 0,
115
+                'description' => $schema_class['description'],
116
+                'slug'        => $schema_class['dashname'],
117
+            );
118
+            if ( null !== $term ) {
119
+                wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
120
+            } else {
121
+                $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
122
+            }
123
+
124
+            // Update the parents/children relationship.
125
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
126
+            foreach ( $schema_class['children'] as $child ) {
127
+                add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
128
+            }
129
+
130
+            // Update the term name.
131
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
132
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
133
+
134
+            // Update the term URI.
135
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
136
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
137
+
138
+        }
139
+
140
+        return true;
141
+    }
142 142
 
143 143
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public function __construct() {
43 43
 
44
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
44
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
45 45
 
46 46
 		// Hook the `wl_sync_schemaorg` ajax action.
47
-		add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) );
47
+		add_action('wp_ajax_wl_sync_schemaorg', array($this, 'load'));
48 48
 
49 49
 		self::$instance = $this;
50 50
 
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 
74 74
 		// Load the file contents.
75 75
 		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
76
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
76
+		$contents = file_get_contents(__DIR__.'/schema-classes.json');
77 77
 
78 78
 		// Load the file contents.
79
-		return $this->load( $contents );
79
+		return $this->load($contents);
80 80
 	}
81 81
 
82 82
 	/**
@@ -86,54 +86,54 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @return bool
88 88
 	 */
89
-	private function load( $contents ) {
89
+	private function load($contents) {
90 90
 
91 91
 		// Decode the JSON contents.
92
-		$json = json_decode( $contents, true );
92
+		$json = json_decode($contents, true);
93 93
 
94
-		if ( null === $json ) {
95
-			$this->log->error( 'Invalid json.' );
94
+		if (null === $json) {
95
+			$this->log->error('Invalid json.');
96 96
 
97 97
 			// Error: invalid body.
98 98
 			return false;
99 99
 		}
100 100
 
101
-		if ( ! isset( $json['schemaClasses'] ) ) {
102
-			$this->log->error( '`schemaClasses` missing from json.' );
101
+		if ( ! isset($json['schemaClasses'])) {
102
+			$this->log->error('`schemaClasses` missing from json.');
103 103
 
104 104
 			// Error: invalid json.
105 105
 			return false;
106 106
 		}
107 107
 
108 108
 		// Load the Schema.org classes.
109
-		foreach ( $json['schemaClasses'] as $schema_class ) {
109
+		foreach ($json['schemaClasses'] as $schema_class) {
110 110
 			$slug = $schema_class['dashname'];
111
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
111
+			$term = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
112 112
 
113 113
 			$args = array(
114 114
 				'parent'      => 0,
115 115
 				'description' => $schema_class['description'],
116 116
 				'slug'        => $schema_class['dashname'],
117 117
 			);
118
-			if ( null !== $term ) {
119
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
118
+			if (null !== $term) {
119
+				wp_update_term($term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
120 120
 			} else {
121
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
121
+				$term = wp_insert_term($schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
122 122
 			}
123 123
 
124 124
 			// Update the parents/children relationship.
125
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
126
-			foreach ( $schema_class['children'] as $child ) {
127
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
125
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY);
126
+			foreach ($schema_class['children'] as $child) {
127
+				add_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname']);
128 128
 			}
129 129
 
130 130
 			// Update the term name.
131
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
132
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
131
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY);
132
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name']);
133 133
 
134 134
 			// Update the term URI.
135
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
136
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
135
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY);
136
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}");
137 137
 
138 138
 		}
139 139
 
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-class-service.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -18,118 +18,118 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Schemaorg_Class_Service {
20 20
 
21
-	/**
22
-	 * The term meta key holding the CamelCase name for the term. The term has also a WP_Term->name
23
-	 * property which however is to be considered a customizable label (especially for languages other
24
-	 * than English).
25
-	 *
26
-	 * @since 3.20.0
27
-	 */
28
-	const NAME_META_KEY = '_wl_name';
29
-
30
-	/**
31
-	 * The term meta key holding the term URI.
32
-	 *
33
-	 * @since 3.20.0
34
-	 */
35
-	const URI_META_KEY = '_wl_uri';
36
-
37
-	/**
38
-	 * The term meta key holding the list of children terms ids.
39
-	 *
40
-	 * @since 3.20.0
41
-	 */
42
-	const PARENT_OF_META_KEY = '_wl_parent_of';
43
-
44
-	/**
45
-	 * The singleton instance.
46
-	 *
47
-	 * @since 3.20.0
48
-	 * @access private
49
-	 * @var \Wordlift_Schemaorg_Class_Service $instance The singleton instance.
50
-	 */
51
-	private static $instance;
52
-
53
-	/**
54
-	 * Create a {@link Wordlift_Schema_Class} instance.
55
-	 *
56
-	 * @since 3.20.0
57
-	 */
58
-	public function __construct() {
59
-
60
-		add_action( 'wp_ajax_wl_schemaorg_class', array( $this, 'schemaorg_class' ) );
61
-
62
-		self::$instance = $this;
63
-
64
-	}
65
-
66
-	/**
67
-	 * Get the singleton instance.
68
-	 *
69
-	 * @since 3.20.0
70
-	 * @return \Wordlift_Schemaorg_Class_Service The singleton instance.
71
-	 */
72
-	public static function get_instance() {
73
-
74
-		return self::$instance;
75
-	}
76
-
77
-	/**
78
-	 * The end-point to output the list of terms from the `wl_entity_taxonomy`.
79
-	 *
80
-	 * Example output:
81
-	 * ```
82
-	 * {
83
-	 *  "name": "AMRadioChannel",
84
-	 *  "dashname": "am-radio-channel",
85
-	 *  "description": "A radio channel that uses AM.",
86
-	 *  "children": []
87
-	 * }
88
-	 * ```
89
-	 *
90
-	 * @since 3.20.0
91
-	 */
92
-	public function schemaorg_class() {
93
-
94
-		// Since we want to be compatible with WP 4.4, we use the pre-4.5.0 style when
95
-		// calling `get_terms`.
96
-		$terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) );
97
-
98
-		// PHP 5.3 compat.
99
-		$name_meta_key      = self::NAME_META_KEY;
100
-		$parent_of_meta_key = self::PARENT_OF_META_KEY;
101
-
102
-		$json = array_map(
103
-			function ( $term ) use ( $name_meta_key, $parent_of_meta_key ) {
104
-				// Do not change the following, the `name` is used to reference the correct
105
-				// Schema.org class (CamelCase name). Do not use WP_Term->name.
106
-				$camel_case_name = get_term_meta( $term->term_id, $name_meta_key, true );
107
-
108
-				return array(
109
-					'id'          => $term->term_id,
110
-					// Do not change the following, the `name` is used to reference the correct
111
-					// Schema.org class (CamelCase name). Do not use WP_Term->name.
112
-					'name'        => $camel_case_name,
113
-					'dashname'    => $term->slug,
114
-					'description' => $term->description,
115
-					'children'    => array_map(
116
-						function ( $child ) {
117
-							// Map the slug to the term id.
118
-							$child_term = get_term_by( 'slug', $child, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
119
-
120
-							return array( 'id' => $child_term->term_id );
121
-						},
122
-						get_term_meta( $term->term_id, $parent_of_meta_key )
123
-					),
124
-				);
125
-
126
-			},
127
-			$terms
128
-		);
129
-
130
-		// Finally send the data.
131
-		wp_send_json_success( array( 'schemaClasses' => $json ) );
132
-
133
-	}
21
+    /**
22
+     * The term meta key holding the CamelCase name for the term. The term has also a WP_Term->name
23
+     * property which however is to be considered a customizable label (especially for languages other
24
+     * than English).
25
+     *
26
+     * @since 3.20.0
27
+     */
28
+    const NAME_META_KEY = '_wl_name';
29
+
30
+    /**
31
+     * The term meta key holding the term URI.
32
+     *
33
+     * @since 3.20.0
34
+     */
35
+    const URI_META_KEY = '_wl_uri';
36
+
37
+    /**
38
+     * The term meta key holding the list of children terms ids.
39
+     *
40
+     * @since 3.20.0
41
+     */
42
+    const PARENT_OF_META_KEY = '_wl_parent_of';
43
+
44
+    /**
45
+     * The singleton instance.
46
+     *
47
+     * @since 3.20.0
48
+     * @access private
49
+     * @var \Wordlift_Schemaorg_Class_Service $instance The singleton instance.
50
+     */
51
+    private static $instance;
52
+
53
+    /**
54
+     * Create a {@link Wordlift_Schema_Class} instance.
55
+     *
56
+     * @since 3.20.0
57
+     */
58
+    public function __construct() {
59
+
60
+        add_action( 'wp_ajax_wl_schemaorg_class', array( $this, 'schemaorg_class' ) );
61
+
62
+        self::$instance = $this;
63
+
64
+    }
65
+
66
+    /**
67
+     * Get the singleton instance.
68
+     *
69
+     * @since 3.20.0
70
+     * @return \Wordlift_Schemaorg_Class_Service The singleton instance.
71
+     */
72
+    public static function get_instance() {
73
+
74
+        return self::$instance;
75
+    }
76
+
77
+    /**
78
+     * The end-point to output the list of terms from the `wl_entity_taxonomy`.
79
+     *
80
+     * Example output:
81
+     * ```
82
+     * {
83
+     *  "name": "AMRadioChannel",
84
+     *  "dashname": "am-radio-channel",
85
+     *  "description": "A radio channel that uses AM.",
86
+     *  "children": []
87
+     * }
88
+     * ```
89
+     *
90
+     * @since 3.20.0
91
+     */
92
+    public function schemaorg_class() {
93
+
94
+        // Since we want to be compatible with WP 4.4, we use the pre-4.5.0 style when
95
+        // calling `get_terms`.
96
+        $terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) );
97
+
98
+        // PHP 5.3 compat.
99
+        $name_meta_key      = self::NAME_META_KEY;
100
+        $parent_of_meta_key = self::PARENT_OF_META_KEY;
101
+
102
+        $json = array_map(
103
+            function ( $term ) use ( $name_meta_key, $parent_of_meta_key ) {
104
+                // Do not change the following, the `name` is used to reference the correct
105
+                // Schema.org class (CamelCase name). Do not use WP_Term->name.
106
+                $camel_case_name = get_term_meta( $term->term_id, $name_meta_key, true );
107
+
108
+                return array(
109
+                    'id'          => $term->term_id,
110
+                    // Do not change the following, the `name` is used to reference the correct
111
+                    // Schema.org class (CamelCase name). Do not use WP_Term->name.
112
+                    'name'        => $camel_case_name,
113
+                    'dashname'    => $term->slug,
114
+                    'description' => $term->description,
115
+                    'children'    => array_map(
116
+                        function ( $child ) {
117
+                            // Map the slug to the term id.
118
+                            $child_term = get_term_by( 'slug', $child, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
119
+
120
+                            return array( 'id' => $child_term->term_id );
121
+                        },
122
+                        get_term_meta( $term->term_id, $parent_of_meta_key )
123
+                    ),
124
+                );
125
+
126
+            },
127
+            $terms
128
+        );
129
+
130
+        // Finally send the data.
131
+        wp_send_json_success( array( 'schemaClasses' => $json ) );
132
+
133
+    }
134 134
 
135 135
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function __construct() {
59 59
 
60
-		add_action( 'wp_ajax_wl_schemaorg_class', array( $this, 'schemaorg_class' ) );
60
+		add_action('wp_ajax_wl_schemaorg_class', array($this, 'schemaorg_class'));
61 61
 
62 62
 		self::$instance = $this;
63 63
 
@@ -93,17 +93,17 @@  discard block
 block discarded – undo
93 93
 
94 94
 		// Since we want to be compatible with WP 4.4, we use the pre-4.5.0 style when
95 95
 		// calling `get_terms`.
96
-		$terms = get_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'get' => 'all' ) );
96
+		$terms = get_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('get' => 'all'));
97 97
 
98 98
 		// PHP 5.3 compat.
99 99
 		$name_meta_key      = self::NAME_META_KEY;
100 100
 		$parent_of_meta_key = self::PARENT_OF_META_KEY;
101 101
 
102 102
 		$json = array_map(
103
-			function ( $term ) use ( $name_meta_key, $parent_of_meta_key ) {
103
+			function($term) use ($name_meta_key, $parent_of_meta_key) {
104 104
 				// Do not change the following, the `name` is used to reference the correct
105 105
 				// Schema.org class (CamelCase name). Do not use WP_Term->name.
106
-				$camel_case_name = get_term_meta( $term->term_id, $name_meta_key, true );
106
+				$camel_case_name = get_term_meta($term->term_id, $name_meta_key, true);
107 107
 
108 108
 				return array(
109 109
 					'id'          => $term->term_id,
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
 					'dashname'    => $term->slug,
114 114
 					'description' => $term->description,
115 115
 					'children'    => array_map(
116
-						function ( $child ) {
116
+						function($child) {
117 117
 							// Map the slug to the term id.
118
-							$child_term = get_term_by( 'slug', $child, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
118
+							$child_term = get_term_by('slug', $child, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
119 119
 
120
-							return array( 'id' => $child_term->term_id );
120
+							return array('id' => $child_term->term_id);
121 121
 						},
122
-						get_term_meta( $term->term_id, $parent_of_meta_key )
122
+						get_term_meta($term->term_id, $parent_of_meta_key)
123 123
 					),
124 124
 				);
125 125
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		);
129 129
 
130 130
 		// Finally send the data.
131
-		wp_send_json_success( array( 'schemaClasses' => $json ) );
131
+		wp_send_json_success(array('schemaClasses' => $json));
132 132
 
133 133
 	}
134 134
 
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -16,119 +16,119 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Schemaorg_Sync_Batch_Operation implements Wordlift_Batch_Operation_Interface {
18 18
 
19
-	private static $instance = null;
20
-
21
-	public static function get_instance() {
22
-
23
-		if ( ! isset( self::$instance ) ) {
24
-			self::$instance = new self();
25
-		}
26
-
27
-		return self::$instance;
28
-	}
29
-
30
-	/**
31
-	 * Process the batch operation starting from the specified offset.
32
-	 *
33
-	 * @param int $offset Start from the specified offset (or 0 if not specified).
34
-	 * @param int $limit Process the specified amount of items per call (or 10 if not specified).
35
-	 *
36
-	 * @return array {
37
-	 * The operation result.
38
-	 *
39
-	 * @type int $next The next offset.
40
-	 * @type int $limit The amount of items to process per call.
41
-	 * @type int $remaining The remaining number of elements to process.
42
-	 * }
43
-	 * @since 3.20.0
44
-	 */
45
-	public function process( $offset = 0, $limit = 10 ) {
46
-
47
-		// Get the schema classes.
48
-		$all_schema_classes = $this->get_schema_classes();
49
-
50
-		// Get only the part that we need to process.
51
-		$schema_classes = array_slice( $all_schema_classes, $offset, $limit );
52
-
53
-		// Load the Schema.org classes.
54
-		foreach ( $schema_classes as $schema_class ) {
55
-			$slug = $schema_class['dashname'];
56
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
57
-
58
-			$args = array(
59
-				'parent'      => 0,
60
-				'description' => $schema_class['description'],
61
-				'slug'        => $schema_class['dashname'],
62
-			);
63
-			if ( null !== $term ) {
64
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
65
-			} else {
66
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
67
-			}
68
-
69
-			// Update the parents/children relationship.
70
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
-			foreach ( $schema_class['children'] as $child ) {
72
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
73
-			}
74
-
75
-			// Update the term name.
76
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
78
-
79
-			// Update the term URI.
80
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
82
-
83
-		}
84
-
85
-		// Calculate the return values.
86
-		$next      = $offset + $limit;
87
-		$remaining = $this->count();
88
-
89
-		return array(
90
-			'next'      => $next,
91
-			'limit'     => $limit,
92
-			'complete'  => ( 0 === $remaining ),
93
-			'remaining' => $remaining,
94
-		);
95
-	}
96
-
97
-	/**
98
-	 * Count the number of elements that would be affected by the operation.
99
-	 *
100
-	 * @return int The number of elements that would be affected.
101
-	 * @since 3.20.0
102
-	 */
103
-	public function count() {
104
-
105
-		// Schema Classes count.
106
-		$schema_classes_count = count( $this->get_schema_classes() );
107
-
108
-		// Terms count.
109
-		$terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
110
-
111
-		// Return the difference.
112
-		return $schema_classes_count - $terms_count;
113
-	}
114
-
115
-	/**
116
-	 * Get the schema.org classes from the JSON file.
117
-	 *
118
-	 * @return array An array of schema classes.
119
-	 * @since 3.20.0
120
-	 */
121
-	private function get_schema_classes() {
122
-
123
-		// Load the file contents.
124
-		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
126
-
127
-		// Decode the JSON contents.
128
-		$json = json_decode( $contents, true );
129
-
130
-		// Return the schema classes or an empty array.
131
-		return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
132
-	}
19
+    private static $instance = null;
20
+
21
+    public static function get_instance() {
22
+
23
+        if ( ! isset( self::$instance ) ) {
24
+            self::$instance = new self();
25
+        }
26
+
27
+        return self::$instance;
28
+    }
29
+
30
+    /**
31
+     * Process the batch operation starting from the specified offset.
32
+     *
33
+     * @param int $offset Start from the specified offset (or 0 if not specified).
34
+     * @param int $limit Process the specified amount of items per call (or 10 if not specified).
35
+     *
36
+     * @return array {
37
+     * The operation result.
38
+     *
39
+     * @type int $next The next offset.
40
+     * @type int $limit The amount of items to process per call.
41
+     * @type int $remaining The remaining number of elements to process.
42
+     * }
43
+     * @since 3.20.0
44
+     */
45
+    public function process( $offset = 0, $limit = 10 ) {
46
+
47
+        // Get the schema classes.
48
+        $all_schema_classes = $this->get_schema_classes();
49
+
50
+        // Get only the part that we need to process.
51
+        $schema_classes = array_slice( $all_schema_classes, $offset, $limit );
52
+
53
+        // Load the Schema.org classes.
54
+        foreach ( $schema_classes as $schema_class ) {
55
+            $slug = $schema_class['dashname'];
56
+            $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
57
+
58
+            $args = array(
59
+                'parent'      => 0,
60
+                'description' => $schema_class['description'],
61
+                'slug'        => $schema_class['dashname'],
62
+            );
63
+            if ( null !== $term ) {
64
+                wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
65
+            } else {
66
+                $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
67
+            }
68
+
69
+            // Update the parents/children relationship.
70
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
+            foreach ( $schema_class['children'] as $child ) {
72
+                add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
73
+            }
74
+
75
+            // Update the term name.
76
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
78
+
79
+            // Update the term URI.
80
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
82
+
83
+        }
84
+
85
+        // Calculate the return values.
86
+        $next      = $offset + $limit;
87
+        $remaining = $this->count();
88
+
89
+        return array(
90
+            'next'      => $next,
91
+            'limit'     => $limit,
92
+            'complete'  => ( 0 === $remaining ),
93
+            'remaining' => $remaining,
94
+        );
95
+    }
96
+
97
+    /**
98
+     * Count the number of elements that would be affected by the operation.
99
+     *
100
+     * @return int The number of elements that would be affected.
101
+     * @since 3.20.0
102
+     */
103
+    public function count() {
104
+
105
+        // Schema Classes count.
106
+        $schema_classes_count = count( $this->get_schema_classes() );
107
+
108
+        // Terms count.
109
+        $terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
110
+
111
+        // Return the difference.
112
+        return $schema_classes_count - $terms_count;
113
+    }
114
+
115
+    /**
116
+     * Get the schema.org classes from the JSON file.
117
+     *
118
+     * @return array An array of schema classes.
119
+     * @since 3.20.0
120
+     */
121
+    private function get_schema_classes() {
122
+
123
+        // Load the file contents.
124
+        // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
+        $contents = file_get_contents( __DIR__ . '/schema-classes.json' );
126
+
127
+        // Decode the JSON contents.
128
+        $json = json_decode( $contents, true );
129
+
130
+        // Return the schema classes or an empty array.
131
+        return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
132
+    }
133 133
 
134 134
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public static function get_instance() {
22 22
 
23
-		if ( ! isset( self::$instance ) ) {
23
+		if ( ! isset(self::$instance)) {
24 24
 			self::$instance = new self();
25 25
 		}
26 26
 
@@ -42,43 +42,43 @@  discard block
 block discarded – undo
42 42
 	 * }
43 43
 	 * @since 3.20.0
44 44
 	 */
45
-	public function process( $offset = 0, $limit = 10 ) {
45
+	public function process($offset = 0, $limit = 10) {
46 46
 
47 47
 		// Get the schema classes.
48 48
 		$all_schema_classes = $this->get_schema_classes();
49 49
 
50 50
 		// Get only the part that we need to process.
51
-		$schema_classes = array_slice( $all_schema_classes, $offset, $limit );
51
+		$schema_classes = array_slice($all_schema_classes, $offset, $limit);
52 52
 
53 53
 		// Load the Schema.org classes.
54
-		foreach ( $schema_classes as $schema_class ) {
54
+		foreach ($schema_classes as $schema_class) {
55 55
 			$slug = $schema_class['dashname'];
56
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
56
+			$term = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
57 57
 
58 58
 			$args = array(
59 59
 				'parent'      => 0,
60 60
 				'description' => $schema_class['description'],
61 61
 				'slug'        => $schema_class['dashname'],
62 62
 			);
63
-			if ( null !== $term ) {
64
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
63
+			if (null !== $term) {
64
+				wp_update_term($term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
65 65
 			} else {
66
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
66
+				$term = wp_insert_term($schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
67 67
 			}
68 68
 
69 69
 			// Update the parents/children relationship.
70
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
-			foreach ( $schema_class['children'] as $child ) {
72
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
70
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY);
71
+			foreach ($schema_class['children'] as $child) {
72
+				add_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname']);
73 73
 			}
74 74
 
75 75
 			// Update the term name.
76
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
76
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY);
77
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name']);
78 78
 
79 79
 			// Update the term URI.
80
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
80
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY);
81
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}");
82 82
 
83 83
 		}
84 84
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		return array(
90 90
 			'next'      => $next,
91 91
 			'limit'     => $limit,
92
-			'complete'  => ( 0 === $remaining ),
92
+			'complete'  => (0 === $remaining),
93 93
 			'remaining' => $remaining,
94 94
 		);
95 95
 	}
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	public function count() {
104 104
 
105 105
 		// Schema Classes count.
106
-		$schema_classes_count = count( $this->get_schema_classes() );
106
+		$schema_classes_count = count($this->get_schema_classes());
107 107
 
108 108
 		// Terms count.
109
-		$terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
109
+		$terms_count = wp_count_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
110 110
 
111 111
 		// Return the difference.
112 112
 		return $schema_classes_count - $terms_count;
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 
123 123
 		// Load the file contents.
124 124
 		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
125
+		$contents = file_get_contents(__DIR__.'/schema-classes.json');
126 126
 
127 127
 		// Decode the JSON contents.
128
-		$json = json_decode( $contents, true );
128
+		$json = json_decode($contents, true);
129 129
 
130 130
 		// Return the schema classes or an empty array.
131
-		return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
131
+		return isset($json['schemaClasses']) ? $json['schemaClasses'] : array();
132 132
 	}
133 133
 
134 134
 }
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-property-service.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -16,110 +16,110 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Schemaorg_Property_Service {
18 18
 
19
-	/**
20
-	 * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the
21
-	 * edit screen custom fields metabox.
22
-	 *
23
-	 * @since 3.20.0
24
-	 */
25
-	const PREFIX = '_wl_prop_';
26
-
27
-	/**
28
-	 * Create a {@link Wordlift_Schemaorg_Property_Service} instance.
29
-	 *
30
-	 * @since 3.20.0
31
-	 */
32
-	protected function __construct() {
33
-
34
-	}
35
-
36
-	private static $instance = null;
37
-
38
-	/**
39
-	 * Get the singleton instance.
40
-	 *
41
-	 * @return \Wordlift_Schemaorg_Property_Service The singleton instance.
42
-	 * @since 3.20.0
43
-	 */
44
-	public static function get_instance() {
45
-
46
-		if ( ! isset( self::$instance ) ) {
47
-			self::$instance = new self();
48
-		}
49
-
50
-		return self::$instance;
51
-	}
52
-
53
-	/**
54
-	 * Get all the properties bound to the specified post.
55
-	 *
56
-	 * @param int $post_id The post id.
57
-	 *
58
-	 * @return array An array of properties instances keyed by the property name. Each property contains a
59
-	 *  `type` and a `value` and optionally a `language`.
60
-	 * }
61
-	 * @since 3.20.0
62
-	 */
63
-	public function get_all( $post_id ) {
64
-
65
-		// Get all the post metas.
66
-		$post_metas = get_post_meta( $post_id );
67
-
68
-		// Cycle through them to get the Schema.org properties.
69
-		$props = array();
70
-		foreach ( $post_metas as $key => $values ) {
71
-			$matches = array();
72
-
73
-			// We're looking for `_wl_prop_propName_uuid_key`.
74
-			if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
75
-				$name = $matches[1];
76
-				$uuid = $matches[2];
77
-				$key  = $matches[3];
78
-
79
-				// Record the value.
80
-				$props[ $name ][ $uuid ][ $key ] = $values[0];
81
-			}
82
-		}
83
-
84
-		// Remove the UUIDs.
85
-		foreach ( $props as $name => $instance ) {
86
-			foreach ( $instance as $uuid => $keys ) {
87
-				// This way we remove the `uuid`s.
88
-				$props[ $name ] = array_values( $instance );
89
-			}
90
-		}
91
-
92
-		// Finally return the props.
93
-		return $props;
94
-	}
95
-
96
-	/**
97
-	 * Get the meta keys for Schema.org properties associated with the specified post.
98
-	 *
99
-	 * @param int $post_id The post id.
100
-	 *
101
-	 * @return array An array of meta keys.
102
-	 * @since 3.20.0
103
-	 */
104
-	public function get_keys( $post_id ) {
105
-
106
-		// Get all the post metas to remove the `_wl_prop` ones.
107
-		$post_meta = get_post_meta( $post_id );
108
-
109
-		// Get the keys.
110
-		$post_meta_keys = array_unique( array_keys( $post_meta ) );
111
-
112
-		// Get only the `_wl_prop` keys. `array_values` resets the indexes.
113
-		$prop_keys = array_values(
114
-			array_filter(
115
-				$post_meta_keys,
116
-				function ( $item ) {
117
-					return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
118
-				}
119
-			)
120
-		);
121
-
122
-		return $prop_keys;
123
-	}
19
+    /**
20
+     * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the
21
+     * edit screen custom fields metabox.
22
+     *
23
+     * @since 3.20.0
24
+     */
25
+    const PREFIX = '_wl_prop_';
26
+
27
+    /**
28
+     * Create a {@link Wordlift_Schemaorg_Property_Service} instance.
29
+     *
30
+     * @since 3.20.0
31
+     */
32
+    protected function __construct() {
33
+
34
+    }
35
+
36
+    private static $instance = null;
37
+
38
+    /**
39
+     * Get the singleton instance.
40
+     *
41
+     * @return \Wordlift_Schemaorg_Property_Service The singleton instance.
42
+     * @since 3.20.0
43
+     */
44
+    public static function get_instance() {
45
+
46
+        if ( ! isset( self::$instance ) ) {
47
+            self::$instance = new self();
48
+        }
49
+
50
+        return self::$instance;
51
+    }
52
+
53
+    /**
54
+     * Get all the properties bound to the specified post.
55
+     *
56
+     * @param int $post_id The post id.
57
+     *
58
+     * @return array An array of properties instances keyed by the property name. Each property contains a
59
+     *  `type` and a `value` and optionally a `language`.
60
+     * }
61
+     * @since 3.20.0
62
+     */
63
+    public function get_all( $post_id ) {
64
+
65
+        // Get all the post metas.
66
+        $post_metas = get_post_meta( $post_id );
67
+
68
+        // Cycle through them to get the Schema.org properties.
69
+        $props = array();
70
+        foreach ( $post_metas as $key => $values ) {
71
+            $matches = array();
72
+
73
+            // We're looking for `_wl_prop_propName_uuid_key`.
74
+            if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
75
+                $name = $matches[1];
76
+                $uuid = $matches[2];
77
+                $key  = $matches[3];
78
+
79
+                // Record the value.
80
+                $props[ $name ][ $uuid ][ $key ] = $values[0];
81
+            }
82
+        }
83
+
84
+        // Remove the UUIDs.
85
+        foreach ( $props as $name => $instance ) {
86
+            foreach ( $instance as $uuid => $keys ) {
87
+                // This way we remove the `uuid`s.
88
+                $props[ $name ] = array_values( $instance );
89
+            }
90
+        }
91
+
92
+        // Finally return the props.
93
+        return $props;
94
+    }
95
+
96
+    /**
97
+     * Get the meta keys for Schema.org properties associated with the specified post.
98
+     *
99
+     * @param int $post_id The post id.
100
+     *
101
+     * @return array An array of meta keys.
102
+     * @since 3.20.0
103
+     */
104
+    public function get_keys( $post_id ) {
105
+
106
+        // Get all the post metas to remove the `_wl_prop` ones.
107
+        $post_meta = get_post_meta( $post_id );
108
+
109
+        // Get the keys.
110
+        $post_meta_keys = array_unique( array_keys( $post_meta ) );
111
+
112
+        // Get only the `_wl_prop` keys. `array_values` resets the indexes.
113
+        $prop_keys = array_values(
114
+            array_filter(
115
+                $post_meta_keys,
116
+                function ( $item ) {
117
+                    return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
118
+                }
119
+            )
120
+        );
121
+
122
+        return $prop_keys;
123
+    }
124 124
 
125 125
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public static function get_instance() {
45 45
 
46
-		if ( ! isset( self::$instance ) ) {
46
+		if ( ! isset(self::$instance)) {
47 47
 			self::$instance = new self();
48 48
 		}
49 49
 
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 	 * }
61 61
 	 * @since 3.20.0
62 62
 	 */
63
-	public function get_all( $post_id ) {
63
+	public function get_all($post_id) {
64 64
 
65 65
 		// Get all the post metas.
66
-		$post_metas = get_post_meta( $post_id );
66
+		$post_metas = get_post_meta($post_id);
67 67
 
68 68
 		// Cycle through them to get the Schema.org properties.
69 69
 		$props = array();
70
-		foreach ( $post_metas as $key => $values ) {
70
+		foreach ($post_metas as $key => $values) {
71 71
 			$matches = array();
72 72
 
73 73
 			// We're looking for `_wl_prop_propName_uuid_key`.
74
-			if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
74
+			if (1 === preg_match('/'.self::PREFIX.'(\w+)_([\w-]+)_(\w+)/i', $key, $matches)) {
75 75
 				$name = $matches[1];
76 76
 				$uuid = $matches[2];
77 77
 				$key  = $matches[3];
78 78
 
79 79
 				// Record the value.
80
-				$props[ $name ][ $uuid ][ $key ] = $values[0];
80
+				$props[$name][$uuid][$key] = $values[0];
81 81
 			}
82 82
 		}
83 83
 
84 84
 		// Remove the UUIDs.
85
-		foreach ( $props as $name => $instance ) {
86
-			foreach ( $instance as $uuid => $keys ) {
85
+		foreach ($props as $name => $instance) {
86
+			foreach ($instance as $uuid => $keys) {
87 87
 				// This way we remove the `uuid`s.
88
-				$props[ $name ] = array_values( $instance );
88
+				$props[$name] = array_values($instance);
89 89
 			}
90 90
 		}
91 91
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	 * @return array An array of meta keys.
102 102
 	 * @since 3.20.0
103 103
 	 */
104
-	public function get_keys( $post_id ) {
104
+	public function get_keys($post_id) {
105 105
 
106 106
 		// Get all the post metas to remove the `_wl_prop` ones.
107
-		$post_meta = get_post_meta( $post_id );
107
+		$post_meta = get_post_meta($post_id);
108 108
 
109 109
 		// Get the keys.
110
-		$post_meta_keys = array_unique( array_keys( $post_meta ) );
110
+		$post_meta_keys = array_unique(array_keys($post_meta));
111 111
 
112 112
 		// Get only the `_wl_prop` keys. `array_values` resets the indexes.
113 113
 		$prop_keys = array_values(
114 114
 			array_filter(
115 115
 				$post_meta_keys,
116
-				function ( $item ) {
117
-					return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
116
+				function($item) {
117
+					return 0 === strpos($item, Wordlift_Schemaorg_Property_Service::PREFIX);
118 118
 				}
119 119
 			)
120 120
 		);
Please login to merge, or discard this patch.
src/includes/class-wordlift-newrelic-adapter.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_NewRelic_Adapter {
18 18
 
19
-	/**
20
-	 * Tell NewRelic to ignore this "transaction" for the Apdex.
21
-	 *
22
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/521
23
-	 *
24
-	 * @since 3.11.3
25
-	 */
26
-	public static function ignore_apdex() {
19
+    /**
20
+     * Tell NewRelic to ignore this "transaction" for the Apdex.
21
+     *
22
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/521
23
+     *
24
+     * @since 3.11.3
25
+     */
26
+    public static function ignore_apdex() {
27 27
 
28
-		// Ensure PHP agent and the function are available.
29
-		if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) {
30
-			newrelic_ignore_apdex();
31
-		}
28
+        // Ensure PHP agent and the function are available.
29
+        if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) {
30
+            newrelic_ignore_apdex();
31
+        }
32 32
 
33
-	}
33
+    }
34 34
 
35 35
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	public static function ignore_apdex() {
27 27
 
28 28
 		// Ensure PHP agent and the function are available.
29
-		if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) {
29
+		if (extension_loaded('newrelic') && function_exists('newrelic_ignore_apdex')) {
30 30
 			newrelic_ignore_apdex();
31 31
 		}
32 32
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-page-service.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -17,54 +17,54 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Entity_Page_Service {
19 19
 
20
-	/**
21
-	 * Set the entity post types as one to be included in archive pages.
22
-	 *
23
-	 * In order to have entities show up in standard WP categories (Posts categories)
24
-	 * we configure the `entity` post type, but we also need to alter the main
25
-	 * WP query (which by default queries posts only) to include the `entities`.
26
-	 *
27
-	 * @since 3.12.0
28
-	 *
29
-	 * @param WP_Query $query WP's {@link WP_Query} instance.
30
-	 */
31
-	public function pre_get_posts( $query ) {
32
-
33
-		// Only for the main query, avoid problems with widgets and what not.
34
-		if ( ! $query->is_main_query() ) {
35
-			return;
36
-		}
37
-
38
-		// We don't want to alter the query if we're in the admin UI, if this is
39
-		// not a entity type achieve query, or if the `suppress_filters` is set.
40
-		//
41
-		// Note that it is unlikely for `suppress_filter` to be set on the front
42
-		// end, but let's be safe if it is set the calling code assumes no
43
-		// modifications of queries.
44
-
45
-		// Ignore admin side request, requests for which filters should be
46
-		// suppressed, and when we are not on a entity type archive page.
47
-		if ( is_admin() ||
48
-			 ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ||
49
-			 ! empty( $query->query_vars['suppress_filters'] )
50
-		) {
51
-			return;
52
-		}
53
-
54
-		// Events should be sorted by start date in descending order.
55
-		if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) {
56
-
57
-			// Update the query to use the start time meta and desc order.
58
-			$meta_query = array(
59
-				array(
60
-					'key' => Wordlift_Schema_Service::FIELD_DATE_START,
61
-				),
62
-			);
63
-			$query->set( 'meta_query', $meta_query );
64
-			$query->set( 'orderby', 'meta_value' );
65
-			$query->set( 'order', 'DESC' );
66
-		} else {
67
-			/*
20
+    /**
21
+     * Set the entity post types as one to be included in archive pages.
22
+     *
23
+     * In order to have entities show up in standard WP categories (Posts categories)
24
+     * we configure the `entity` post type, but we also need to alter the main
25
+     * WP query (which by default queries posts only) to include the `entities`.
26
+     *
27
+     * @since 3.12.0
28
+     *
29
+     * @param WP_Query $query WP's {@link WP_Query} instance.
30
+     */
31
+    public function pre_get_posts( $query ) {
32
+
33
+        // Only for the main query, avoid problems with widgets and what not.
34
+        if ( ! $query->is_main_query() ) {
35
+            return;
36
+        }
37
+
38
+        // We don't want to alter the query if we're in the admin UI, if this is
39
+        // not a entity type achieve query, or if the `suppress_filters` is set.
40
+        //
41
+        // Note that it is unlikely for `suppress_filter` to be set on the front
42
+        // end, but let's be safe if it is set the calling code assumes no
43
+        // modifications of queries.
44
+
45
+        // Ignore admin side request, requests for which filters should be
46
+        // suppressed, and when we are not on a entity type archive page.
47
+        if ( is_admin() ||
48
+             ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ||
49
+             ! empty( $query->query_vars['suppress_filters'] )
50
+        ) {
51
+            return;
52
+        }
53
+
54
+        // Events should be sorted by start date in descending order.
55
+        if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) {
56
+
57
+            // Update the query to use the start time meta and desc order.
58
+            $meta_query = array(
59
+                array(
60
+                    'key' => Wordlift_Schema_Service::FIELD_DATE_START,
61
+                ),
62
+            );
63
+            $query->set( 'meta_query', $meta_query );
64
+            $query->set( 'orderby', 'meta_value' );
65
+            $query->set( 'order', 'DESC' );
66
+        } else {
67
+            /*
68 68
 			 * All other entity types should be sorted by their connectivity.
69 69
 			 * For this we need to query the relationship table which has
70 70
 			 * to be done by manipulating the SQL generated for the query.
@@ -72,73 +72,73 @@  discard block
 block discarded – undo
72 72
 			 * additional filters to handle it.
73 73
 			 */
74 74
 
75
-			add_filter( 'posts_join', array( $this, 'posts_join' ) );
76
-			add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
77
-			add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
78
-		}
79
-	}
80
-
81
-	/**
82
-	 * Filter handler that sets the join part of a query to include the
83
-	 * relationship table to be able to use it in the sorting.
84
-	 *
85
-	 * @since 3.15.0
86
-	 *
87
-	 * @param string $join_statement The join part of the SQL statement which is used for the query.
88
-	 *
89
-	 * @return string An join SQL which add the relationships table to the join.
90
-	 */
91
-	public function posts_join( $join_statement ) {
92
-
93
-		global $wpdb;
94
-
95
-		$join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri "
96
-						   . " ON (ri.object_id = {$wpdb->posts}.ID)";
97
-
98
-		// Remove to make sure it will not run agan in other context.
99
-		remove_filter( 'posts_join', array( $this, 'posts_join' ) );
100
-
101
-		return $join_statement;
102
-	}
103
-
104
-	/**
105
-	 * Filter handler that sets the groupby part of a query to include the
106
-	 * relationship table to be able to use it in the sorting.
107
-	 *
108
-	 * @since 3.15.0
109
-	 *
110
-	 * @param string $groupby_statement The groupby part of the SQL statement which is used for the query.
111
-	 *
112
-	 * @return string A groupby SQL which add the relationships table to the join.
113
-	 */
114
-	public function posts_groupby( $groupby_statement ) {
115
-
116
-		$groupby_statement = 'ri.object_id, ' . $groupby_statement;
117
-
118
-		// Remove to make sure it will not run agan in other context.
119
-		remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
120
-
121
-		return $groupby_statement;
122
-	}
123
-
124
-	/**
125
-	 * Filter handler that sets the orderby part of a query to sort by number of
126
-	 * relationships.
127
-	 *
128
-	 * @since 3.15.0
129
-	 *
130
-	 * @param string $orderby_statement The orderby part of the SQL statement which is used for the query.
131
-	 *
132
-	 * @return string An orderby SQL which sorts by the number of relationships
133
-	 */
134
-	public function posts_orderby( $orderby_statement ) {
135
-
136
-		$orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement;
137
-
138
-		// Remove to make sure it will not run agan in other context.
139
-		remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
140
-
141
-		return $orderby_statement;
142
-	}
75
+            add_filter( 'posts_join', array( $this, 'posts_join' ) );
76
+            add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
77
+            add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
78
+        }
79
+    }
80
+
81
+    /**
82
+     * Filter handler that sets the join part of a query to include the
83
+     * relationship table to be able to use it in the sorting.
84
+     *
85
+     * @since 3.15.0
86
+     *
87
+     * @param string $join_statement The join part of the SQL statement which is used for the query.
88
+     *
89
+     * @return string An join SQL which add the relationships table to the join.
90
+     */
91
+    public function posts_join( $join_statement ) {
92
+
93
+        global $wpdb;
94
+
95
+        $join_statement .= " LEFT JOIN {$wpdb->prefix}wl_relation_instances ri "
96
+                            . " ON (ri.object_id = {$wpdb->posts}.ID)";
97
+
98
+        // Remove to make sure it will not run agan in other context.
99
+        remove_filter( 'posts_join', array( $this, 'posts_join' ) );
100
+
101
+        return $join_statement;
102
+    }
103
+
104
+    /**
105
+     * Filter handler that sets the groupby part of a query to include the
106
+     * relationship table to be able to use it in the sorting.
107
+     *
108
+     * @since 3.15.0
109
+     *
110
+     * @param string $groupby_statement The groupby part of the SQL statement which is used for the query.
111
+     *
112
+     * @return string A groupby SQL which add the relationships table to the join.
113
+     */
114
+    public function posts_groupby( $groupby_statement ) {
115
+
116
+        $groupby_statement = 'ri.object_id, ' . $groupby_statement;
117
+
118
+        // Remove to make sure it will not run agan in other context.
119
+        remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
120
+
121
+        return $groupby_statement;
122
+    }
123
+
124
+    /**
125
+     * Filter handler that sets the orderby part of a query to sort by number of
126
+     * relationships.
127
+     *
128
+     * @since 3.15.0
129
+     *
130
+     * @param string $orderby_statement The orderby part of the SQL statement which is used for the query.
131
+     *
132
+     * @return string An orderby SQL which sorts by the number of relationships
133
+     */
134
+    public function posts_orderby( $orderby_statement ) {
135
+
136
+        $orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement;
137
+
138
+        // Remove to make sure it will not run agan in other context.
139
+        remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
140
+
141
+        return $orderby_statement;
142
+    }
143 143
 
144 144
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param WP_Query $query WP's {@link WP_Query} instance.
30 30
 	 */
31
-	public function pre_get_posts( $query ) {
31
+	public function pre_get_posts($query) {
32 32
 
33 33
 		// Only for the main query, avoid problems with widgets and what not.
34
-		if ( ! $query->is_main_query() ) {
34
+		if ( ! $query->is_main_query()) {
35 35
 			return;
36 36
 		}
37 37
 
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
 
45 45
 		// Ignore admin side request, requests for which filters should be
46 46
 		// suppressed, and when we are not on a entity type archive page.
47
-		if ( is_admin() ||
48
-			 ! is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ) ||
49
-			 ! empty( $query->query_vars['suppress_filters'] )
47
+		if (is_admin() ||
48
+			 ! is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME) ||
49
+			 ! empty($query->query_vars['suppress_filters'])
50 50
 		) {
51 51
 			return;
52 52
 		}
53 53
 
54 54
 		// Events should be sorted by start date in descending order.
55
-		if ( is_tax( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event' ) ) {
55
+		if (is_tax(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, 'event')) {
56 56
 
57 57
 			// Update the query to use the start time meta and desc order.
58 58
 			$meta_query = array(
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
 					'key' => Wordlift_Schema_Service::FIELD_DATE_START,
61 61
 				),
62 62
 			);
63
-			$query->set( 'meta_query', $meta_query );
64
-			$query->set( 'orderby', 'meta_value' );
65
-			$query->set( 'order', 'DESC' );
63
+			$query->set('meta_query', $meta_query);
64
+			$query->set('orderby', 'meta_value');
65
+			$query->set('order', 'DESC');
66 66
 		} else {
67 67
 			/*
68 68
 			 * All other entity types should be sorted by their connectivity.
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 			 * additional filters to handle it.
73 73
 			 */
74 74
 
75
-			add_filter( 'posts_join', array( $this, 'posts_join' ) );
76
-			add_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
77
-			add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
75
+			add_filter('posts_join', array($this, 'posts_join'));
76
+			add_filter('posts_groupby', array($this, 'posts_groupby'));
77
+			add_filter('posts_orderby', array($this, 'posts_orderby'));
78 78
 		}
79 79
 	}
80 80
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return string An join SQL which add the relationships table to the join.
90 90
 	 */
91
-	public function posts_join( $join_statement ) {
91
+	public function posts_join($join_statement) {
92 92
 
93 93
 		global $wpdb;
94 94
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 						   . " ON (ri.object_id = {$wpdb->posts}.ID)";
97 97
 
98 98
 		// Remove to make sure it will not run agan in other context.
99
-		remove_filter( 'posts_join', array( $this, 'posts_join' ) );
99
+		remove_filter('posts_join', array($this, 'posts_join'));
100 100
 
101 101
 		return $join_statement;
102 102
 	}
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @return string A groupby SQL which add the relationships table to the join.
113 113
 	 */
114
-	public function posts_groupby( $groupby_statement ) {
114
+	public function posts_groupby($groupby_statement) {
115 115
 
116
-		$groupby_statement = 'ri.object_id, ' . $groupby_statement;
116
+		$groupby_statement = 'ri.object_id, '.$groupby_statement;
117 117
 
118 118
 		// Remove to make sure it will not run agan in other context.
119
-		remove_filter( 'posts_groupby', array( $this, 'posts_groupby' ) );
119
+		remove_filter('posts_groupby', array($this, 'posts_groupby'));
120 120
 
121 121
 		return $groupby_statement;
122 122
 	}
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @return string An orderby SQL which sorts by the number of relationships
133 133
 	 */
134
-	public function posts_orderby( $orderby_statement ) {
134
+	public function posts_orderby($orderby_statement) {
135 135
 
136
-		$orderby_statement = 'COUNT( ri.object_id ) DESC, ' . $orderby_statement;
136
+		$orderby_statement = 'COUNT( ri.object_id ) DESC, '.$orderby_statement;
137 137
 
138 138
 		// Remove to make sure it will not run agan in other context.
139
-		remove_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );
139
+		remove_filter('posts_orderby', array($this, 'posts_orderby'));
140 140
 
141 141
 		return $orderby_statement;
142 142
 	}
Please login to merge, or discard this patch.