Completed
Pull Request — develop (#1633)
by Naveen
01:05
created
src/wordlift/dataset/index.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -14,38 +14,38 @@
 block discarded – undo
14 14
 use Wordlift\Jsonld\Jsonld_Service;
15 15
 
16 16
 if ( ! defined( 'ABSPATH' ) ) {
17
-	exit;
17
+    exit;
18 18
 }
19 19
 
20 20
 // Register the Dataset JSON Endpoint.
21 21
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
22 22
 if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
23 23
 
24
-	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
-	$sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
-	new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
-	new Sync_User_Hooks( $sync_service );
24
+    $sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
+    $sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
+    new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
+    new Sync_User_Hooks( $sync_service );
28 28
 
29
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
-	if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
-		new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
32
-	}
33
-	/**
34
-	 * @since 3.28.0
35
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36
-	 */
37
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
29
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
+    if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
+        new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
32
+    }
33
+    /**
34
+     * @since 3.28.0
35
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36
+     */
37
+    new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
38 38
 
39
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
-	if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
41
-		new Sync_Hooks_Wordpress_Ontology();
42
-	}
39
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
+    if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
41
+        new Sync_Hooks_Wordpress_Ontology();
42
+    }
43 43
 
44
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-	if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
46
-		// Set up the sync background process.
47
-		$sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
-		new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
49
-		new Sync_Page();
50
-	}
44
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
+    if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
46
+        // Set up the sync background process.
47
+        $sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
+        new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
49
+        new Sync_Page();
50
+    }
51 51
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
 use Wordlift\Dataset\Sync_User_Hooks;
14 14
 use Wordlift\Jsonld\Jsonld_Service;
15 15
 
16
-if ( ! defined( 'ABSPATH' ) ) {
16
+if ( ! defined('ABSPATH')) {
17 17
 	exit;
18 18
 }
19 19
 
20 20
 // Register the Dataset JSON Endpoint.
21 21
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
22
-if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
22
+if (apply_filters('wl_feature__enable__dataset-ng', false)) {
23 23
 
24 24
 	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
25
-	$sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
26
-	new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
27
-	new Sync_User_Hooks( $sync_service );
25
+	$sync_service                = new Sync_Service(Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance());
26
+	new Sync_Post_Hooks($sync_service, $sync_object_adapter_factory);
27
+	new Sync_User_Hooks($sync_service);
28 28
 
29 29
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
-	if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
31
-		new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
30
+	if (apply_filters('wl_feature__enable__no-vocabulary-terms', false)) {
31
+		new Sync_Term_Hooks($sync_service, $sync_object_adapter_factory);
32 32
 	}
33 33
 	/**
34 34
 	 * @since 3.28.0
35 35
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
36 36
 	 */
37
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
37
+	new Sync_Hooks_Entity_Relation(Wordlift_Entity_Service::get_instance());
38 38
 
39 39
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
40
-	if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
40
+	if (apply_filters('wl_feature__enable__wordpress-ontology', false)) {
41 41
 		new Sync_Hooks_Wordpress_Ontology();
42 42
 	}
43 43
 
44 44
 	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
45
-	if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
45
+	if (apply_filters('wl_feature__enable__sync-background', false)) {
46 46
 		// Set up the sync background process.
47
-		$sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
48
-		new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
47
+		$sync_background_process = new Sync_Background_Process($sync_service, $sync_object_adapter_factory);
48
+		new Sync_Background_Process_Wpjson_Endpoint($sync_background_process);
49 49
 		new Sync_Page();
50 50
 	}
51 51
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-hooks-wordpress-ontology.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,65 +7,65 @@
 block discarded – undo
7 7
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
8 8
 class Sync_Hooks_Wordpress_Ontology {
9 9
 
10
-	const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11
-
12
-	public function __construct() {
13
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
14
-	}
15
-
16
-	public function jsonld( $jsonld, $type, $object_id ) {
17
-
18
-		$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
19
-
20
-		switch ( $type ) {
21
-
22
-			case Object_Type_Enum::TERM:
23
-				$term = get_term( $object_id );
24
-
25
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
28
-				break;
29
-
30
-			case Object_Type_Enum::USER:
31
-				$user = get_userdata( $object_id );
32
-
33
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
35
-				break;
36
-
37
-			case Object_Type_Enum::POST:
38
-				$post = get_post( $object_id );
39
-
40
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
-				$content = has_blocks( $post ) ?
45
-					do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
-
50
-				$taxonomies = get_post_taxonomies( $post );
51
-				$_tmp_terms = array();
52
-				foreach ( $taxonomies as $taxonomy ) {
53
-					$terms = wp_get_post_terms( $post->ID, $taxonomy );
54
-					/** @var \WP_Term $term */
55
-					foreach ( $terms as $term ) {
56
-						$_tmp_terms[] = "$taxonomy:$term->name";
57
-					}
58
-				}
59
-				if ( ! empty( $_tmp_terms ) ) {
60
-					$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
61
-				}
62
-
63
-				break;
64
-
65
-			default:
66
-		}
67
-
68
-		return $jsonld;
69
-	}
10
+    const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11
+
12
+    public function __construct() {
13
+        add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
14
+    }
15
+
16
+    public function jsonld( $jsonld, $type, $object_id ) {
17
+
18
+        $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
19
+
20
+        switch ( $type ) {
21
+
22
+            case Object_Type_Enum::TERM:
23
+                $term = get_term( $object_id );
24
+
25
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
28
+                break;
29
+
30
+            case Object_Type_Enum::USER:
31
+                $user = get_userdata( $object_id );
32
+
33
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
35
+                break;
36
+
37
+            case Object_Type_Enum::POST:
38
+                $post = get_post( $object_id );
39
+
40
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
+                $content = has_blocks( $post ) ?
45
+                    do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
+                $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
+
50
+                $taxonomies = get_post_taxonomies( $post );
51
+                $_tmp_terms = array();
52
+                foreach ( $taxonomies as $taxonomy ) {
53
+                    $terms = wp_get_post_terms( $post->ID, $taxonomy );
54
+                    /** @var \WP_Term $term */
55
+                    foreach ( $terms as $term ) {
56
+                        $_tmp_terms[] = "$taxonomy:$term->name";
57
+                    }
58
+                }
59
+                if ( ! empty( $_tmp_terms ) ) {
60
+                    $jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
61
+                }
62
+
63
+                break;
64
+
65
+            default:
66
+        }
67
+
68
+        return $jsonld;
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -10,54 +10,54 @@
 block discarded – undo
10 10
 	const HTTP_PURL_ORG_WORDPRESS_1_0 = 'http://purl.org/wordpress/1.0/';
11 11
 
12 12
 	public function __construct() {
13
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
13
+		add_filter('wl_dataset__sync_service__sync_item__jsonld', array($this, 'jsonld'), 10, 3);
14 14
 	}
15 15
 
16
-	public function jsonld( $jsonld, $type, $object_id ) {
16
+	public function jsonld($jsonld, $type, $object_id) {
17 17
 
18
-		$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'id' ] = $object_id;
18
+		$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'id'] = $object_id;
19 19
 
20
-		switch ( $type ) {
20
+		switch ($type) {
21 21
 
22 22
 			case Object_Type_Enum::TERM:
23
-				$term = get_term( $object_id );
23
+				$term = get_term($object_id);
24 24
 
25
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'term';
26
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'name' ]        = $term->name;
27
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'description' ] = $term->description;
25
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']        = 'term';
26
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'name']        = $term->name;
27
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'description'] = $term->description;
28 28
 				break;
29 29
 
30 30
 			case Object_Type_Enum::USER:
31
-				$user = get_userdata( $object_id );
31
+				$user = get_userdata($object_id);
32 32
 
33
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]        = 'user';
34
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'displayName' ] = $user->display_name;
33
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']        = 'user';
34
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'displayName'] = $user->display_name;
35 35
 				break;
36 36
 
37 37
 			case Object_Type_Enum::POST:
38
-				$post = get_post( $object_id );
39
-
40
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'type' ]       = 'post';
41
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'customType' ] = $post->post_type;
42
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'title' ]      = $post->post_title;
43
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'status' ]     = $post->post_status;
44
-				$content = has_blocks( $post ) ?
45
-					do_blocks( $post->post_content ) : do_shortcode( $post->post_content );
46
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'content' ]   = $content;
47
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'permalink' ] = get_permalink( $post );
48
-				$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'sticky' ]    = is_sticky( $post->ID );
49
-
50
-				$taxonomies = get_post_taxonomies( $post );
38
+				$post = get_post($object_id);
39
+
40
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'type']       = 'post';
41
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'customType'] = $post->post_type;
42
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'title']      = $post->post_title;
43
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'status']     = $post->post_status;
44
+				$content = has_blocks($post) ?
45
+					do_blocks($post->post_content) : do_shortcode($post->post_content);
46
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'content']   = $content;
47
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'permalink'] = get_permalink($post);
48
+				$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'sticky']    = is_sticky($post->ID);
49
+
50
+				$taxonomies = get_post_taxonomies($post);
51 51
 				$_tmp_terms = array();
52
-				foreach ( $taxonomies as $taxonomy ) {
53
-					$terms = wp_get_post_terms( $post->ID, $taxonomy );
52
+				foreach ($taxonomies as $taxonomy) {
53
+					$terms = wp_get_post_terms($post->ID, $taxonomy);
54 54
 					/** @var \WP_Term $term */
55
-					foreach ( $terms as $term ) {
55
+					foreach ($terms as $term) {
56 56
 						$_tmp_terms[] = "$taxonomy:$term->name";
57 57
 					}
58 58
 				}
59
-				if ( ! empty( $_tmp_terms ) ) {
60
-					$jsonld[0][ self::HTTP_PURL_ORG_WORDPRESS_1_0 . 'terms' ] = $_tmp_terms;
59
+				if ( ! empty($_tmp_terms)) {
60
+					$jsonld[0][self::HTTP_PURL_ORG_WORDPRESS_1_0.'terms'] = $_tmp_terms;
61 61
 				}
62 62
 
63 63
 				break;
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-object-adapter-factory.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -6,37 +6,37 @@
 block discarded – undo
6 6
 
7 7
 class Sync_Object_Adapter_Factory {
8 8
 
9
-	/**
10
-	 * @param int $type One of Object_Type_Enum::POST, Object_Type_Enum::USER, ...
11
-	 * @param int $object_id The object id.
12
-	 *
13
-	 * @return Sync_Object_Adapter
14
-	 * @throws \Exception when an error occurs.
15
-	 */
16
-	public function create( $type, $object_id ) {
17
-
18
-		switch ( $type ) {
19
-			case Object_Type_Enum::POST:
20
-				return new Sync_Post_Adapter( $object_id );
21
-			case Object_Type_Enum::USER:
22
-				return new Sync_User_Adapter( $object_id );
23
-			case Object_Type_Enum::TERM:
24
-				return new Sync_Term_Adapter( $object_id );
25
-			default:
26
-				throw new \Exception( "Unsupported type $type." );
27
-		}
28
-
29
-	}
30
-
31
-	public function create_many( $type, $object_ids ) {
32
-		$that = $this;
33
-
34
-		return array_map(
35
-			function ( $item ) use ( $type, $that ) {
36
-				return $that->create( $type, $item );
37
-			},
38
-			(array) $object_ids
39
-		);
40
-	}
9
+    /**
10
+     * @param int $type One of Object_Type_Enum::POST, Object_Type_Enum::USER, ...
11
+     * @param int $object_id The object id.
12
+     *
13
+     * @return Sync_Object_Adapter
14
+     * @throws \Exception when an error occurs.
15
+     */
16
+    public function create( $type, $object_id ) {
17
+
18
+        switch ( $type ) {
19
+            case Object_Type_Enum::POST:
20
+                return new Sync_Post_Adapter( $object_id );
21
+            case Object_Type_Enum::USER:
22
+                return new Sync_User_Adapter( $object_id );
23
+            case Object_Type_Enum::TERM:
24
+                return new Sync_Term_Adapter( $object_id );
25
+            default:
26
+                throw new \Exception( "Unsupported type $type." );
27
+        }
28
+
29
+    }
30
+
31
+    public function create_many( $type, $object_ids ) {
32
+        $that = $this;
33
+
34
+        return array_map(
35
+            function ( $item ) use ( $type, $that ) {
36
+                return $that->create( $type, $item );
37
+            },
38
+            (array) $object_ids
39
+        );
40
+    }
41 41
 
42 42
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,27 +13,27 @@
 block discarded – undo
13 13
 	 * @return Sync_Object_Adapter
14 14
 	 * @throws \Exception when an error occurs.
15 15
 	 */
16
-	public function create( $type, $object_id ) {
16
+	public function create($type, $object_id) {
17 17
 
18
-		switch ( $type ) {
18
+		switch ($type) {
19 19
 			case Object_Type_Enum::POST:
20
-				return new Sync_Post_Adapter( $object_id );
20
+				return new Sync_Post_Adapter($object_id);
21 21
 			case Object_Type_Enum::USER:
22
-				return new Sync_User_Adapter( $object_id );
22
+				return new Sync_User_Adapter($object_id);
23 23
 			case Object_Type_Enum::TERM:
24
-				return new Sync_Term_Adapter( $object_id );
24
+				return new Sync_Term_Adapter($object_id);
25 25
 			default:
26
-				throw new \Exception( "Unsupported type $type." );
26
+				throw new \Exception("Unsupported type $type.");
27 27
 		}
28 28
 
29 29
 	}
30 30
 
31
-	public function create_many( $type, $object_ids ) {
31
+	public function create_many($type, $object_ids) {
32 32
 		$that = $this;
33 33
 
34 34
 		return array_map(
35
-			function ( $item ) use ( $type, $that ) {
36
-				return $that->create( $type, $item );
35
+			function($item) use ($type, $that) {
36
+				return $that->create($type, $item);
37 37
 			},
38 38
 			(array) $object_ids
39 39
 		);
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-page.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -4,49 +4,49 @@  discard block
 block discarded – undo
4 4
 
5 5
 class Sync_Page {
6 6
 
7
-	/**
8
-	 * Sync_Page constructor.
9
-	 */
10
-	public function __construct() {
11
-
12
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
-
14
-	}
15
-
16
-	public function admin_menu() {
17
-
18
-		add_submenu_page(
19
-			'wl_admin_menu',
20
-			__( 'Synchronize Dataset', 'wordlift' ),
21
-			__( 'Synchronize Dataset', 'wordlift' ),
22
-			'manage_options',
23
-			'wl_dataset_sync',
24
-			array(
25
-				$this,
26
-				'render',
27
-			)
28
-		);
29
-
30
-	}
31
-
32
-	public function render() {
33
-
34
-		wp_enqueue_style(
35
-			'wl-tasks-page',
36
-			plugin_dir_url( __DIR__ ) . 'tasks/admin/assets/tasks-page.css',
37
-			array(),
38
-			\Wordlift::get_instance()->get_version()
39
-		);
40
-
41
-		wp_enqueue_script(
42
-			'wl-dataset-sync-page',
43
-			plugin_dir_url( __FILE__ ) . 'assets/sync-page.js',
44
-			array( 'wp-api' ),
45
-			\Wordlift::get_instance()->get_version(),
46
-			false
47
-		);
48
-
49
-		?>
7
+    /**
8
+     * Sync_Page constructor.
9
+     */
10
+    public function __construct() {
11
+
12
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
+
14
+    }
15
+
16
+    public function admin_menu() {
17
+
18
+        add_submenu_page(
19
+            'wl_admin_menu',
20
+            __( 'Synchronize Dataset', 'wordlift' ),
21
+            __( 'Synchronize Dataset', 'wordlift' ),
22
+            'manage_options',
23
+            'wl_dataset_sync',
24
+            array(
25
+                $this,
26
+                'render',
27
+            )
28
+        );
29
+
30
+    }
31
+
32
+    public function render() {
33
+
34
+        wp_enqueue_style(
35
+            'wl-tasks-page',
36
+            plugin_dir_url( __DIR__ ) . 'tasks/admin/assets/tasks-page.css',
37
+            array(),
38
+            \Wordlift::get_instance()->get_version()
39
+        );
40
+
41
+        wp_enqueue_script(
42
+            'wl-dataset-sync-page',
43
+            plugin_dir_url( __FILE__ ) . 'assets/sync-page.js',
44
+            array( 'wp-api' ),
45
+            \Wordlift::get_instance()->get_version(),
46
+            false
47
+        );
48
+
49
+        ?>
50 50
 		<div class="wrap">
51 51
 			<h2><?php esc_html_e( 'Synchronize Dataset', 'wordlift' ); ?></h2>
52 52
 
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
 
58 58
 			<button id="wl-start-btn" type="button" class="button button-large button-primary">
59 59
 			<?php
60
-				esc_html_e( 'Start', 'wordlift' );
61
-			?>
60
+                esc_html_e( 'Start', 'wordlift' );
61
+            ?>
62 62
 				</button>
63 63
 			<button id="wl-stop-btn" type="button" class="button button-large button-primary hidden">
64 64
 			<?php
65
-				esc_html_e( 'Stop', 'wordlift' );
66
-			?>
65
+                esc_html_e( 'Stop', 'wordlift' );
66
+            ?>
67 67
 				</button>
68 68
 
69 69
 		</div>
70 70
 		<?php
71
-	}
71
+    }
72 72
 
73 73
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	 */
10 10
 	public function __construct() {
11 11
 
12
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
12
+		add_action('admin_menu', array($this, 'admin_menu'));
13 13
 
14 14
 	}
15 15
 
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 
18 18
 		add_submenu_page(
19 19
 			'wl_admin_menu',
20
-			__( 'Synchronize Dataset', 'wordlift' ),
21
-			__( 'Synchronize Dataset', 'wordlift' ),
20
+			__('Synchronize Dataset', 'wordlift'),
21
+			__('Synchronize Dataset', 'wordlift'),
22 22
 			'manage_options',
23 23
 			'wl_dataset_sync',
24 24
 			array(
@@ -33,22 +33,22 @@  discard block
 block discarded – undo
33 33
 
34 34
 		wp_enqueue_style(
35 35
 			'wl-tasks-page',
36
-			plugin_dir_url( __DIR__ ) . 'tasks/admin/assets/tasks-page.css',
36
+			plugin_dir_url(__DIR__).'tasks/admin/assets/tasks-page.css',
37 37
 			array(),
38 38
 			\Wordlift::get_instance()->get_version()
39 39
 		);
40 40
 
41 41
 		wp_enqueue_script(
42 42
 			'wl-dataset-sync-page',
43
-			plugin_dir_url( __FILE__ ) . 'assets/sync-page.js',
44
-			array( 'wp-api' ),
43
+			plugin_dir_url(__FILE__).'assets/sync-page.js',
44
+			array('wp-api'),
45 45
 			\Wordlift::get_instance()->get_version(),
46 46
 			false
47 47
 		);
48 48
 
49 49
 		?>
50 50
 		<div class="wrap">
51
-			<h2><?php esc_html_e( 'Synchronize Dataset', 'wordlift' ); ?></h2>
51
+			<h2><?php esc_html_e('Synchronize Dataset', 'wordlift'); ?></h2>
52 52
 
53 53
 			<div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;">
54 54
 				<div class="wl-task__progress__bar"
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 
58 58
 			<button id="wl-start-btn" type="button" class="button button-large button-primary">
59 59
 			<?php
60
-				esc_html_e( 'Start', 'wordlift' );
60
+				esc_html_e('Start', 'wordlift');
61 61
 			?>
62 62
 				</button>
63 63
 			<button id="wl-stop-btn" type="button" class="button button-large button-primary hidden">
64 64
 			<?php
65
-				esc_html_e( 'Stop', 'wordlift' );
65
+				esc_html_e('Stop', 'wordlift');
66 66
 			?>
67 67
 				</button>
68 68
 
Please login to merge, or discard this patch.
src/wordlift/faq/class-faq-content-filter.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -10,33 +10,33 @@
 block discarded – undo
10 10
 namespace Wordlift\Faq;
11 11
 
12 12
 class Faq_Content_Filter {
13
-	/**
14
-	 * Constants used for replacing the tags in the html string.
15
-	 */
16
-	const FAQ_QUESTION_TAG_NAME = 'wl-faq-question';
17
-	const FAQ_ANSWER_TAG_NAME   = 'wl-faq-answer';
18
-	/**
19
-	 * Replaces all the html tags inserted by Faq highlighting code in the front end
20
-	 *
21
-	 * @param $content string Post content
22
-	 * @return string String after replacing all the opening and closing tags.
23
-	 */
24
-	public function remove_all_faq_question_and_answer_tags( $content ) {
25
-		/**
26
-		 * Replace all the question tags.
27
-		 */
28
-		$faq_question_closing_tag = '</' . self::FAQ_QUESTION_TAG_NAME . '>';
29
-		$content                  = preg_replace( '/<wl-faq-question class=".+?">/m', '', $content );
30
-		$content                  = str_replace( $faq_question_closing_tag, '', $content );
31
-		/**
32
-		 * Replace all the answer tags.
33
-		 */
34
-		$faq_answer_closing_tag = '</' . self::FAQ_ANSWER_TAG_NAME . '>';
35
-		$content                = preg_replace( '/<wl-faq-answer class=".+?">/m', '', $content );
36
-		$content                = str_replace( $faq_answer_closing_tag, '', $content );
13
+    /**
14
+     * Constants used for replacing the tags in the html string.
15
+     */
16
+    const FAQ_QUESTION_TAG_NAME = 'wl-faq-question';
17
+    const FAQ_ANSWER_TAG_NAME   = 'wl-faq-answer';
18
+    /**
19
+     * Replaces all the html tags inserted by Faq highlighting code in the front end
20
+     *
21
+     * @param $content string Post content
22
+     * @return string String after replacing all the opening and closing tags.
23
+     */
24
+    public function remove_all_faq_question_and_answer_tags( $content ) {
25
+        /**
26
+         * Replace all the question tags.
27
+         */
28
+        $faq_question_closing_tag = '</' . self::FAQ_QUESTION_TAG_NAME . '>';
29
+        $content                  = preg_replace( '/<wl-faq-question class=".+?">/m', '', $content );
30
+        $content                  = str_replace( $faq_question_closing_tag, '', $content );
31
+        /**
32
+         * Replace all the answer tags.
33
+         */
34
+        $faq_answer_closing_tag = '</' . self::FAQ_ANSWER_TAG_NAME . '>';
35
+        $content                = preg_replace( '/<wl-faq-answer class=".+?">/m', '', $content );
36
+        $content                = str_replace( $faq_answer_closing_tag, '', $content );
37 37
 
38
-		/** Return all the replaced content */
39
-		return $content;
40
-	}
38
+        /** Return all the replaced content */
39
+        return $content;
40
+    }
41 41
 
42 42
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,19 +21,19 @@
 block discarded – undo
21 21
 	 * @param $content string Post content
22 22
 	 * @return string String after replacing all the opening and closing tags.
23 23
 	 */
24
-	public function remove_all_faq_question_and_answer_tags( $content ) {
24
+	public function remove_all_faq_question_and_answer_tags($content) {
25 25
 		/**
26 26
 		 * Replace all the question tags.
27 27
 		 */
28
-		$faq_question_closing_tag = '</' . self::FAQ_QUESTION_TAG_NAME . '>';
29
-		$content                  = preg_replace( '/<wl-faq-question class=".+?">/m', '', $content );
30
-		$content                  = str_replace( $faq_question_closing_tag, '', $content );
28
+		$faq_question_closing_tag = '</'.self::FAQ_QUESTION_TAG_NAME.'>';
29
+		$content                  = preg_replace('/<wl-faq-question class=".+?">/m', '', $content);
30
+		$content                  = str_replace($faq_question_closing_tag, '', $content);
31 31
 		/**
32 32
 		 * Replace all the answer tags.
33 33
 		 */
34
-		$faq_answer_closing_tag = '</' . self::FAQ_ANSWER_TAG_NAME . '>';
35
-		$content                = preg_replace( '/<wl-faq-answer class=".+?">/m', '', $content );
36
-		$content                = str_replace( $faq_answer_closing_tag, '', $content );
34
+		$faq_answer_closing_tag = '</'.self::FAQ_ANSWER_TAG_NAME.'>';
35
+		$content                = preg_replace('/<wl-faq-answer class=".+?">/m', '', $content);
36
+		$content                = str_replace($faq_answer_closing_tag, '', $content);
37 37
 
38 38
 		/** Return all the replaced content */
39 39
 		return $content;
Please login to merge, or discard this patch.
src/wordlift/faq/class-faq-to-jsonld-converter.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -17,80 +17,80 @@
 block discarded – undo
17 17
  */
18 18
 class Faq_To_Jsonld_Converter {
19 19
 
20
-	const FAQ_JSONLD_TYPE = 'FAQPage';
20
+    const FAQ_JSONLD_TYPE = 'FAQPage';
21 21
 
22
-	public function __construct() {
23
-		add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
24
-		add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
25
-	}
22
+    public function __construct() {
23
+        add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
24
+        add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
25
+    }
26 26
 
27
-	/**
28
-	 * Set the FAQ type to the json ld array
29
-	 *
30
-	 * @param $jsonld array The jsonld array.
31
-	 *
32
-	 * @return array Returns the json ld array with the type set.
33
-	 */
34
-	public function set_faq_type( $jsonld ) {
35
-		if ( array_key_exists( '@type', $jsonld ) ) {
36
-			if ( is_string( $jsonld['@type'] ) ) {
37
-				// If a plain string is present, create an array with previous items.
38
-				$jsonld['@type'] = array( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
39
-				return $jsonld;
40
-			}
41
-			// check if it is a array, then append the type.
42
-			if ( is_array( $jsonld['@type'] ) && ! in_array( self::FAQ_JSONLD_TYPE, $jsonld['@type'], true ) ) {
43
-				array_push( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
44
-				return $jsonld;
45
-			}
46
-		} else {
47
-			$jsonld['@type'] = array( self::FAQ_JSONLD_TYPE );
48
-		}
49
-		return $jsonld;
50
-	}
51
-	/**
52
-	 * @param $post_id int The id of the post.
53
-	 *
54
-	 * @return array Get the converted jsonld data
55
-	 */
56
-	public function get_jsonld_for_faq( $jsonld, $post_id ) {
27
+    /**
28
+     * Set the FAQ type to the json ld array
29
+     *
30
+     * @param $jsonld array The jsonld array.
31
+     *
32
+     * @return array Returns the json ld array with the type set.
33
+     */
34
+    public function set_faq_type( $jsonld ) {
35
+        if ( array_key_exists( '@type', $jsonld ) ) {
36
+            if ( is_string( $jsonld['@type'] ) ) {
37
+                // If a plain string is present, create an array with previous items.
38
+                $jsonld['@type'] = array( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
39
+                return $jsonld;
40
+            }
41
+            // check if it is a array, then append the type.
42
+            if ( is_array( $jsonld['@type'] ) && ! in_array( self::FAQ_JSONLD_TYPE, $jsonld['@type'], true ) ) {
43
+                array_push( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
44
+                return $jsonld;
45
+            }
46
+        } else {
47
+            $jsonld['@type'] = array( self::FAQ_JSONLD_TYPE );
48
+        }
49
+        return $jsonld;
50
+    }
51
+    /**
52
+     * @param $post_id int The id of the post.
53
+     *
54
+     * @return array Get the converted jsonld data
55
+     */
56
+    public function get_jsonld_for_faq( $jsonld, $post_id ) {
57 57
 
58
-		$faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY );
59
-		/**
60
-		 * Apply the FAQ mapping only if the FAQ items are present.
61
-		 */
62
-		if ( count( $faq_items ) > 0 ) {
63
-			$faq_data = $this->get_faq_data( $faq_items );
64
-			// Merge the FAQ data with jsonld.
65
-			$jsonld = array_merge( $jsonld, $faq_data );
66
-			// check if the @type is set on json ld
67
-			$jsonld = $this->set_faq_type( $jsonld );
68
-		}
69
-		return $jsonld;
70
-	}
58
+        $faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY );
59
+        /**
60
+         * Apply the FAQ mapping only if the FAQ items are present.
61
+         */
62
+        if ( count( $faq_items ) > 0 ) {
63
+            $faq_data = $this->get_faq_data( $faq_items );
64
+            // Merge the FAQ data with jsonld.
65
+            $jsonld = array_merge( $jsonld, $faq_data );
66
+            // check if the @type is set on json ld
67
+            $jsonld = $this->set_faq_type( $jsonld );
68
+        }
69
+        return $jsonld;
70
+    }
71 71
 
72
-	/**
73
-	 * @param $faq_items array List of FAQ items extracted from the meta.
74
-	 *
75
-	 * @return array Associtative array of type, mainEntity.
76
-	 */
77
-	private function get_faq_data( $faq_items ) {
78
-		$jsonld_data               = array();
79
-		$jsonld_data['mainEntity'] = array();
80
-		foreach ( $faq_items as $faq_item ) {
81
-			if ( 0 === strlen( $faq_item['question'] ) || 0 === strlen( $faq_item['answer'] ) ) {
82
-				// Bail out if question or answer is not present
83
-				continue;
84
-			}
85
-			$faq_data                            = array();
86
-			$faq_data['@type']                   = 'Question';
87
-			$faq_data['name']                    = $faq_item['question'];
88
-			$faq_data['acceptedAnswer']          = array();
89
-			$faq_data['acceptedAnswer']['@type'] = 'Answer';
90
-			$faq_data['acceptedAnswer']['text']  = $faq_item['answer'];
91
-			array_push( $jsonld_data['mainEntity'], $faq_data );
92
-		}
72
+    /**
73
+     * @param $faq_items array List of FAQ items extracted from the meta.
74
+     *
75
+     * @return array Associtative array of type, mainEntity.
76
+     */
77
+    private function get_faq_data( $faq_items ) {
78
+        $jsonld_data               = array();
79
+        $jsonld_data['mainEntity'] = array();
80
+        foreach ( $faq_items as $faq_item ) {
81
+            if ( 0 === strlen( $faq_item['question'] ) || 0 === strlen( $faq_item['answer'] ) ) {
82
+                // Bail out if question or answer is not present
83
+                continue;
84
+            }
85
+            $faq_data                            = array();
86
+            $faq_data['@type']                   = 'Question';
87
+            $faq_data['name']                    = $faq_item['question'];
88
+            $faq_data['acceptedAnswer']          = array();
89
+            $faq_data['acceptedAnswer']['@type'] = 'Answer';
90
+            $faq_data['acceptedAnswer']['text']  = $faq_item['answer'];
91
+            array_push( $jsonld_data['mainEntity'], $faq_data );
92
+        }
93 93
 
94
-		return $jsonld_data;
95
-	}
94
+        return $jsonld_data;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 	const FAQ_JSONLD_TYPE = 'FAQPage';
21 21
 
22 22
 	public function __construct() {
23
-		add_filter( 'wl_post_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
24
-		add_filter( 'wl_entity_jsonld', array( $this, 'get_jsonld_for_faq' ), 11, 2 );
23
+		add_filter('wl_post_jsonld', array($this, 'get_jsonld_for_faq'), 11, 2);
24
+		add_filter('wl_entity_jsonld', array($this, 'get_jsonld_for_faq'), 11, 2);
25 25
 	}
26 26
 
27 27
 	/**
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return array Returns the json ld array with the type set.
33 33
 	 */
34
-	public function set_faq_type( $jsonld ) {
35
-		if ( array_key_exists( '@type', $jsonld ) ) {
36
-			if ( is_string( $jsonld['@type'] ) ) {
34
+	public function set_faq_type($jsonld) {
35
+		if (array_key_exists('@type', $jsonld)) {
36
+			if (is_string($jsonld['@type'])) {
37 37
 				// If a plain string is present, create an array with previous items.
38
-				$jsonld['@type'] = array( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
38
+				$jsonld['@type'] = array($jsonld['@type'], self::FAQ_JSONLD_TYPE);
39 39
 				return $jsonld;
40 40
 			}
41 41
 			// check if it is a array, then append the type.
42
-			if ( is_array( $jsonld['@type'] ) && ! in_array( self::FAQ_JSONLD_TYPE, $jsonld['@type'], true ) ) {
43
-				array_push( $jsonld['@type'], self::FAQ_JSONLD_TYPE );
42
+			if (is_array($jsonld['@type']) && ! in_array(self::FAQ_JSONLD_TYPE, $jsonld['@type'], true)) {
43
+				array_push($jsonld['@type'], self::FAQ_JSONLD_TYPE);
44 44
 				return $jsonld;
45 45
 			}
46 46
 		} else {
47
-			$jsonld['@type'] = array( self::FAQ_JSONLD_TYPE );
47
+			$jsonld['@type'] = array(self::FAQ_JSONLD_TYPE);
48 48
 		}
49 49
 		return $jsonld;
50 50
 	}
@@ -53,18 +53,18 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return array Get the converted jsonld data
55 55
 	 */
56
-	public function get_jsonld_for_faq( $jsonld, $post_id ) {
56
+	public function get_jsonld_for_faq($jsonld, $post_id) {
57 57
 
58
-		$faq_items = get_post_meta( $post_id, Faq_Rest_Controller::FAQ_META_KEY );
58
+		$faq_items = get_post_meta($post_id, Faq_Rest_Controller::FAQ_META_KEY);
59 59
 		/**
60 60
 		 * Apply the FAQ mapping only if the FAQ items are present.
61 61
 		 */
62
-		if ( count( $faq_items ) > 0 ) {
63
-			$faq_data = $this->get_faq_data( $faq_items );
62
+		if (count($faq_items) > 0) {
63
+			$faq_data = $this->get_faq_data($faq_items);
64 64
 			// Merge the FAQ data with jsonld.
65
-			$jsonld = array_merge( $jsonld, $faq_data );
65
+			$jsonld = array_merge($jsonld, $faq_data);
66 66
 			// check if the @type is set on json ld
67
-			$jsonld = $this->set_faq_type( $jsonld );
67
+			$jsonld = $this->set_faq_type($jsonld);
68 68
 		}
69 69
 		return $jsonld;
70 70
 	}
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return array Associtative array of type, mainEntity.
76 76
 	 */
77
-	private function get_faq_data( $faq_items ) {
77
+	private function get_faq_data($faq_items) {
78 78
 		$jsonld_data               = array();
79 79
 		$jsonld_data['mainEntity'] = array();
80
-		foreach ( $faq_items as $faq_item ) {
81
-			if ( 0 === strlen( $faq_item['question'] ) || 0 === strlen( $faq_item['answer'] ) ) {
80
+		foreach ($faq_items as $faq_item) {
81
+			if (0 === strlen($faq_item['question']) || 0 === strlen($faq_item['answer'])) {
82 82
 				// Bail out if question or answer is not present
83 83
 				continue;
84 84
 			}
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			$faq_data['acceptedAnswer']          = array();
89 89
 			$faq_data['acceptedAnswer']['@type'] = 'Answer';
90 90
 			$faq_data['acceptedAnswer']['text']  = $faq_item['answer'];
91
-			array_push( $jsonld_data['mainEntity'], $faq_data );
91
+			array_push($jsonld_data['mainEntity'], $faq_data);
92 92
 		}
93 93
 
94 94
 		return $jsonld_data;
Please login to merge, or discard this patch.
src/wordlift/faq/class-faq-rest-controller.php 2 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -17,233 +17,233 @@
 block discarded – undo
17 17
  * @package Wordlift\FAQ
18 18
  */
19 19
 class Faq_Rest_Controller {
20
-	const FAQ_META_KEY = '_wl_faq';
21
-	/**
22
-	 * Enumerations to determine the field to be deleted on
23
-	 * the DELETE request in API.
24
-	 */
25
-	const QUESTION = 'question';
26
-	const ANSWER   = 'answer';
27
-
28
-	public static function register_routes() {
29
-		add_action( 'rest_api_init', 'Wordlift\FAQ\FAQ_Rest_Controller::register_route_callback' );
30
-	}
31
-
32
-	public static function register_route_callback() {
33
-		/**
34
-		 * Specifies the list of arguments to be present for update request.
35
-		 */
36
-		$post_id_validation_settings   = array(
37
-			'required'          => true,
38
-			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
39
-			'validate_callback' => function ( $param, $request, $key ) {
40
-				return is_numeric( $param );
41
-			},
42
-		);
43
-		$faq_items_validation_settings = array(
44
-			'required'          => true,
45
-			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
-			'validate_callback' => function ( $param, $request, $key ) {
47
-				return is_array( $param ) && count( $param ) > 0;
48
-			},
49
-		);
50
-		/**
51
-		 * Array of args to be present in order to
52
-		 * make create, update or delete request.
53
-		 */
54
-		$create_or_update_or_delete_args = array(
55
-			'post_id'   => $post_id_validation_settings,
56
-			'faq_items' => $faq_items_validation_settings,
57
-		);
58
-
59
-		/**
60
-		 * Rest route for creating new faq item.
61
-		 */
62
-		register_rest_route(
63
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
64
-			'/faq',
65
-			array(
66
-				'methods'             => \WP_REST_Server::CREATABLE,
67
-				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::add_faq_items',
68
-				'permission_callback' => function () {
69
-					return current_user_can( 'publish_posts' );
70
-				},
71
-				'args'                => $create_or_update_or_delete_args,
72
-			)
73
-		);
74
-		/**
75
-		 * Rest route for updating faq items.
76
-		 */
77
-		register_rest_route(
78
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
79
-			'/faq',
80
-			array(
81
-				'methods'             => \WP_REST_Server::EDITABLE,
82
-				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::update_faq_items',
83
-				'permission_callback' => function () {
84
-					return current_user_can( 'publish_posts' );
85
-				},
86
-				'args'                => $create_or_update_or_delete_args,
87
-			)
88
-		);
89
-		/**
90
-		 * Rest route for getting the faq items.
91
-		 */
92
-		register_rest_route(
93
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
94
-			'/faq/(?P<post_id>\d+)',
95
-			array(
96
-				'methods'             => \WP_REST_Server::READABLE,
97
-				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::get_faq_items',
98
-				'permission_callback' => function () {
99
-					return current_user_can( 'publish_posts' );
100
-				},
101
-				'args'                => array( 'post_id' => $post_id_validation_settings ),
102
-			)
103
-		);
104
-		/**
105
-		 * Rest route for deleting faq item.
106
-		 */
107
-		register_rest_route(
108
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
-			'/faq',
110
-			array(
111
-				'methods'             => \WP_REST_Server::DELETABLE,
112
-				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::delete_faq_items',
113
-				'permission_callback' => function () {
114
-					return current_user_can( 'publish_posts' );
115
-				},
116
-				'args'                => $create_or_update_or_delete_args,
117
-			)
118
-		);
119
-	}
120
-
121
-	/**
122
-	 * Get all FAQ items for a post id.
123
-	 *
124
-	 * @param $request $request WP_REST_Request $request {@link WP_REST_Request instance}.
125
-	 *
126
-	 * @return array Result array, if post id is not given then error array is returned.
127
-	 */
128
-	public static function get_faq_items( $request ) {
129
-		$data    = $request->get_params();
130
-		$post_id = (int) $data['post_id'];
131
-
132
-		return get_post_meta( $post_id, self::FAQ_META_KEY );
133
-	}
134
-
135
-	/**
136
-	 * Update all FAQ items for a post id.
137
-	 *
138
-	 * @param $request $request WP_REST_Request $request {@link WP_REST_Request instance}.
139
-	 *
140
-	 * @return array Result array, if post id is not given then error array is returned.
141
-	 */
142
-	public static function update_faq_items( $request ) {
143
-		$data      = $request->get_params();
144
-		$post_id   = (int) $data['post_id'];
145
-		$faq_items = (array) $data['faq_items'];
146
-		foreach ( $faq_items as $faq_item ) {
147
-			$previous_value = array(
148
-				'question' => (string) $faq_item['previous_question_value'],
149
-				'answer'   => (string) $faq_item['previous_answer_value'],
150
-				'id'       => (int) $faq_item['id'],
151
-			);
152
-			$new_value      = array(
153
-				'question' => (string) $faq_item['question'],
154
-				'answer'   => (string) $faq_item['answer'],
155
-				'id'       => (int) $faq_item['id'],
156
-			);
157
-			update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
158
-		}
159
-
160
-		return array(
161
-			'status'  => 'success',
162
-			'message' => __( 'Faq Items updated successfully', 'wordlift' ),
163
-		);
164
-
165
-	}
166
-
167
-	/**
168
-	 * Delete Faq items.
169
-	 *
170
-	 * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
171
-	 *
172
-	 * @return array Associative array whether the faq item is deleted or not.
173
-	 */
174
-	public static function delete_faq_items( $request ) {
175
-		$post_data = $request->get_params();
176
-		$post_id   = $post_data['post_id'];
177
-		$faq_items = $post_data['faq_items'];
178
-		foreach ( $faq_items as $faq_item ) {
179
-			/**
180
-			 * Note: the order of keys is important in order to delete it properly
181
-			 * If the order change, delete operation will fail since it is converted
182
-			 * in to a string when it was stored.
183
-			 * we cant rely on client to post it in correct order, so we create an array
184
-			 * in correct order.
185
-			 */
186
-			$deleted_faq_item = array(
187
-				'question' => $faq_item['question'],
188
-				'answer'   => $faq_item['answer'],
189
-				'id'       => (int) $faq_item['id'],
190
-			);
191
-			/**
192
-			 * If the field to be deleted is answer, then don't delete the faq item,
193
-			 * if it is question then delete the faq item.
194
-			 */
195
-			if ( self::ANSWER === $faq_item['field_to_be_deleted'] ) {
196
-				$previous_value = $deleted_faq_item;
197
-				// then don't delete the faq item, set the answer as empty.
198
-				$deleted_faq_item['answer'] = '';
199
-				$new_value                  = $deleted_faq_item;
200
-				update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
201
-			} elseif ( self::QUESTION === $faq_item['field_to_be_deleted'] ) {
202
-				/**
203
-				 * If the question is deleted, then delete the faq item.
204
-				 */
205
-				delete_post_meta( $post_id, self::FAQ_META_KEY, $deleted_faq_item );
206
-			}
207
-		}
208
-
209
-		/**
210
-		 * We are returning only the first item id, since the user can select only one text at a time.
211
-		 */
212
-		return array(
213
-			'status'  => 'success',
214
-			'message' => __( 'Faq item successfully deleted.', 'wordlift' ),
215
-		);
216
-	}
217
-
218
-	/**
219
-	 * Insert or update FAQ items.
220
-	 *
221
-	 * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
222
-	 *
223
-	 * @return array Associative array whether the faq item is inserted or not
224
-	 */
225
-	public static function add_faq_items( $request ) {
226
-		$post_data = $request->get_params();
227
-		$post_id   = $post_data['post_id'];
228
-		$faq_items = $post_data['faq_items'];
229
-		foreach ( $faq_items as &$faq_item ) {
230
-			// Add an identifier id to the faq item, it helps to prevent duplication problem.
231
-			/**
232
-			 * We are using time() and a random integer to prevent
233
-			 * duplication problem.
234
-			 */
235
-			$faq_item['id'] = time() + wp_rand( 1, 100 ) + wp_rand( 1, 100 );
236
-			add_post_meta( (int) $post_id, self::FAQ_META_KEY, $faq_item );
237
-		}
238
-
239
-		/**
240
-		 * We are returning only the first item id, since the user can select only one text at a time.
241
-		 */
242
-		return array(
243
-			'status'  => 'success',
244
-			'message' => __( 'Question successfully added.', 'wordlift' ),
245
-			'id'      => (int) $faq_items[0]['id'],
246
-		);
247
-
248
-	}
20
+    const FAQ_META_KEY = '_wl_faq';
21
+    /**
22
+     * Enumerations to determine the field to be deleted on
23
+     * the DELETE request in API.
24
+     */
25
+    const QUESTION = 'question';
26
+    const ANSWER   = 'answer';
27
+
28
+    public static function register_routes() {
29
+        add_action( 'rest_api_init', 'Wordlift\FAQ\FAQ_Rest_Controller::register_route_callback' );
30
+    }
31
+
32
+    public static function register_route_callback() {
33
+        /**
34
+         * Specifies the list of arguments to be present for update request.
35
+         */
36
+        $post_id_validation_settings   = array(
37
+            'required'          => true,
38
+            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
39
+            'validate_callback' => function ( $param, $request, $key ) {
40
+                return is_numeric( $param );
41
+            },
42
+        );
43
+        $faq_items_validation_settings = array(
44
+            'required'          => true,
45
+            // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
+            'validate_callback' => function ( $param, $request, $key ) {
47
+                return is_array( $param ) && count( $param ) > 0;
48
+            },
49
+        );
50
+        /**
51
+         * Array of args to be present in order to
52
+         * make create, update or delete request.
53
+         */
54
+        $create_or_update_or_delete_args = array(
55
+            'post_id'   => $post_id_validation_settings,
56
+            'faq_items' => $faq_items_validation_settings,
57
+        );
58
+
59
+        /**
60
+         * Rest route for creating new faq item.
61
+         */
62
+        register_rest_route(
63
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
64
+            '/faq',
65
+            array(
66
+                'methods'             => \WP_REST_Server::CREATABLE,
67
+                'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::add_faq_items',
68
+                'permission_callback' => function () {
69
+                    return current_user_can( 'publish_posts' );
70
+                },
71
+                'args'                => $create_or_update_or_delete_args,
72
+            )
73
+        );
74
+        /**
75
+         * Rest route for updating faq items.
76
+         */
77
+        register_rest_route(
78
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
79
+            '/faq',
80
+            array(
81
+                'methods'             => \WP_REST_Server::EDITABLE,
82
+                'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::update_faq_items',
83
+                'permission_callback' => function () {
84
+                    return current_user_can( 'publish_posts' );
85
+                },
86
+                'args'                => $create_or_update_or_delete_args,
87
+            )
88
+        );
89
+        /**
90
+         * Rest route for getting the faq items.
91
+         */
92
+        register_rest_route(
93
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
94
+            '/faq/(?P<post_id>\d+)',
95
+            array(
96
+                'methods'             => \WP_REST_Server::READABLE,
97
+                'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::get_faq_items',
98
+                'permission_callback' => function () {
99
+                    return current_user_can( 'publish_posts' );
100
+                },
101
+                'args'                => array( 'post_id' => $post_id_validation_settings ),
102
+            )
103
+        );
104
+        /**
105
+         * Rest route for deleting faq item.
106
+         */
107
+        register_rest_route(
108
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
+            '/faq',
110
+            array(
111
+                'methods'             => \WP_REST_Server::DELETABLE,
112
+                'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::delete_faq_items',
113
+                'permission_callback' => function () {
114
+                    return current_user_can( 'publish_posts' );
115
+                },
116
+                'args'                => $create_or_update_or_delete_args,
117
+            )
118
+        );
119
+    }
120
+
121
+    /**
122
+     * Get all FAQ items for a post id.
123
+     *
124
+     * @param $request $request WP_REST_Request $request {@link WP_REST_Request instance}.
125
+     *
126
+     * @return array Result array, if post id is not given then error array is returned.
127
+     */
128
+    public static function get_faq_items( $request ) {
129
+        $data    = $request->get_params();
130
+        $post_id = (int) $data['post_id'];
131
+
132
+        return get_post_meta( $post_id, self::FAQ_META_KEY );
133
+    }
134
+
135
+    /**
136
+     * Update all FAQ items for a post id.
137
+     *
138
+     * @param $request $request WP_REST_Request $request {@link WP_REST_Request instance}.
139
+     *
140
+     * @return array Result array, if post id is not given then error array is returned.
141
+     */
142
+    public static function update_faq_items( $request ) {
143
+        $data      = $request->get_params();
144
+        $post_id   = (int) $data['post_id'];
145
+        $faq_items = (array) $data['faq_items'];
146
+        foreach ( $faq_items as $faq_item ) {
147
+            $previous_value = array(
148
+                'question' => (string) $faq_item['previous_question_value'],
149
+                'answer'   => (string) $faq_item['previous_answer_value'],
150
+                'id'       => (int) $faq_item['id'],
151
+            );
152
+            $new_value      = array(
153
+                'question' => (string) $faq_item['question'],
154
+                'answer'   => (string) $faq_item['answer'],
155
+                'id'       => (int) $faq_item['id'],
156
+            );
157
+            update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
158
+        }
159
+
160
+        return array(
161
+            'status'  => 'success',
162
+            'message' => __( 'Faq Items updated successfully', 'wordlift' ),
163
+        );
164
+
165
+    }
166
+
167
+    /**
168
+     * Delete Faq items.
169
+     *
170
+     * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
171
+     *
172
+     * @return array Associative array whether the faq item is deleted or not.
173
+     */
174
+    public static function delete_faq_items( $request ) {
175
+        $post_data = $request->get_params();
176
+        $post_id   = $post_data['post_id'];
177
+        $faq_items = $post_data['faq_items'];
178
+        foreach ( $faq_items as $faq_item ) {
179
+            /**
180
+             * Note: the order of keys is important in order to delete it properly
181
+             * If the order change, delete operation will fail since it is converted
182
+             * in to a string when it was stored.
183
+             * we cant rely on client to post it in correct order, so we create an array
184
+             * in correct order.
185
+             */
186
+            $deleted_faq_item = array(
187
+                'question' => $faq_item['question'],
188
+                'answer'   => $faq_item['answer'],
189
+                'id'       => (int) $faq_item['id'],
190
+            );
191
+            /**
192
+             * If the field to be deleted is answer, then don't delete the faq item,
193
+             * if it is question then delete the faq item.
194
+             */
195
+            if ( self::ANSWER === $faq_item['field_to_be_deleted'] ) {
196
+                $previous_value = $deleted_faq_item;
197
+                // then don't delete the faq item, set the answer as empty.
198
+                $deleted_faq_item['answer'] = '';
199
+                $new_value                  = $deleted_faq_item;
200
+                update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
201
+            } elseif ( self::QUESTION === $faq_item['field_to_be_deleted'] ) {
202
+                /**
203
+                 * If the question is deleted, then delete the faq item.
204
+                 */
205
+                delete_post_meta( $post_id, self::FAQ_META_KEY, $deleted_faq_item );
206
+            }
207
+        }
208
+
209
+        /**
210
+         * We are returning only the first item id, since the user can select only one text at a time.
211
+         */
212
+        return array(
213
+            'status'  => 'success',
214
+            'message' => __( 'Faq item successfully deleted.', 'wordlift' ),
215
+        );
216
+    }
217
+
218
+    /**
219
+     * Insert or update FAQ items.
220
+     *
221
+     * @param $request WP_REST_Request $request {@link WP_REST_Request instance}.
222
+     *
223
+     * @return array Associative array whether the faq item is inserted or not
224
+     */
225
+    public static function add_faq_items( $request ) {
226
+        $post_data = $request->get_params();
227
+        $post_id   = $post_data['post_id'];
228
+        $faq_items = $post_data['faq_items'];
229
+        foreach ( $faq_items as &$faq_item ) {
230
+            // Add an identifier id to the faq item, it helps to prevent duplication problem.
231
+            /**
232
+             * We are using time() and a random integer to prevent
233
+             * duplication problem.
234
+             */
235
+            $faq_item['id'] = time() + wp_rand( 1, 100 ) + wp_rand( 1, 100 );
236
+            add_post_meta( (int) $post_id, self::FAQ_META_KEY, $faq_item );
237
+        }
238
+
239
+        /**
240
+         * We are returning only the first item id, since the user can select only one text at a time.
241
+         */
242
+        return array(
243
+            'status'  => 'success',
244
+            'message' => __( 'Question successfully added.', 'wordlift' ),
245
+            'id'      => (int) $faq_items[0]['id'],
246
+        );
247
+
248
+    }
249 249
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -26,25 +26,25 @@  discard block
 block discarded – undo
26 26
 	const ANSWER   = 'answer';
27 27
 
28 28
 	public static function register_routes() {
29
-		add_action( 'rest_api_init', 'Wordlift\FAQ\FAQ_Rest_Controller::register_route_callback' );
29
+		add_action('rest_api_init', 'Wordlift\FAQ\FAQ_Rest_Controller::register_route_callback');
30 30
 	}
31 31
 
32 32
 	public static function register_route_callback() {
33 33
 		/**
34 34
 		 * Specifies the list of arguments to be present for update request.
35 35
 		 */
36
-		$post_id_validation_settings   = array(
36
+		$post_id_validation_settings = array(
37 37
 			'required'          => true,
38 38
 			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
39
-			'validate_callback' => function ( $param, $request, $key ) {
40
-				return is_numeric( $param );
39
+			'validate_callback' => function($param, $request, $key) {
40
+				return is_numeric($param);
41 41
 			},
42 42
 		);
43 43
 		$faq_items_validation_settings = array(
44 44
 			'required'          => true,
45 45
 			// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46
-			'validate_callback' => function ( $param, $request, $key ) {
47
-				return is_array( $param ) && count( $param ) > 0;
46
+			'validate_callback' => function($param, $request, $key) {
47
+				return is_array($param) && count($param) > 0;
48 48
 			},
49 49
 		);
50 50
 		/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 			array(
66 66
 				'methods'             => \WP_REST_Server::CREATABLE,
67 67
 				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::add_faq_items',
68
-				'permission_callback' => function () {
69
-					return current_user_can( 'publish_posts' );
68
+				'permission_callback' => function() {
69
+					return current_user_can('publish_posts');
70 70
 				},
71 71
 				'args'                => $create_or_update_or_delete_args,
72 72
 			)
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 			array(
81 81
 				'methods'             => \WP_REST_Server::EDITABLE,
82 82
 				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::update_faq_items',
83
-				'permission_callback' => function () {
84
-					return current_user_can( 'publish_posts' );
83
+				'permission_callback' => function() {
84
+					return current_user_can('publish_posts');
85 85
 				},
86 86
 				'args'                => $create_or_update_or_delete_args,
87 87
 			)
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
 			array(
96 96
 				'methods'             => \WP_REST_Server::READABLE,
97 97
 				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::get_faq_items',
98
-				'permission_callback' => function () {
99
-					return current_user_can( 'publish_posts' );
98
+				'permission_callback' => function() {
99
+					return current_user_can('publish_posts');
100 100
 				},
101
-				'args'                => array( 'post_id' => $post_id_validation_settings ),
101
+				'args'                => array('post_id' => $post_id_validation_settings),
102 102
 			)
103 103
 		);
104 104
 		/**
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 			array(
111 111
 				'methods'             => \WP_REST_Server::DELETABLE,
112 112
 				'callback'            => 'Wordlift\Faq\Faq_Rest_Controller::delete_faq_items',
113
-				'permission_callback' => function () {
114
-					return current_user_can( 'publish_posts' );
113
+				'permission_callback' => function() {
114
+					return current_user_can('publish_posts');
115 115
 				},
116 116
 				'args'                => $create_or_update_or_delete_args,
117 117
 			)
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @return array Result array, if post id is not given then error array is returned.
127 127
 	 */
128
-	public static function get_faq_items( $request ) {
128
+	public static function get_faq_items($request) {
129 129
 		$data    = $request->get_params();
130 130
 		$post_id = (int) $data['post_id'];
131 131
 
132
-		return get_post_meta( $post_id, self::FAQ_META_KEY );
132
+		return get_post_meta($post_id, self::FAQ_META_KEY);
133 133
 	}
134 134
 
135 135
 	/**
@@ -139,27 +139,27 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return array Result array, if post id is not given then error array is returned.
141 141
 	 */
142
-	public static function update_faq_items( $request ) {
142
+	public static function update_faq_items($request) {
143 143
 		$data      = $request->get_params();
144 144
 		$post_id   = (int) $data['post_id'];
145 145
 		$faq_items = (array) $data['faq_items'];
146
-		foreach ( $faq_items as $faq_item ) {
146
+		foreach ($faq_items as $faq_item) {
147 147
 			$previous_value = array(
148 148
 				'question' => (string) $faq_item['previous_question_value'],
149 149
 				'answer'   => (string) $faq_item['previous_answer_value'],
150 150
 				'id'       => (int) $faq_item['id'],
151 151
 			);
152
-			$new_value      = array(
152
+			$new_value = array(
153 153
 				'question' => (string) $faq_item['question'],
154 154
 				'answer'   => (string) $faq_item['answer'],
155 155
 				'id'       => (int) $faq_item['id'],
156 156
 			);
157
-			update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
157
+			update_post_meta($post_id, self::FAQ_META_KEY, $new_value, $previous_value);
158 158
 		}
159 159
 
160 160
 		return array(
161 161
 			'status'  => 'success',
162
-			'message' => __( 'Faq Items updated successfully', 'wordlift' ),
162
+			'message' => __('Faq Items updated successfully', 'wordlift'),
163 163
 		);
164 164
 
165 165
 	}
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 *
172 172
 	 * @return array Associative array whether the faq item is deleted or not.
173 173
 	 */
174
-	public static function delete_faq_items( $request ) {
174
+	public static function delete_faq_items($request) {
175 175
 		$post_data = $request->get_params();
176 176
 		$post_id   = $post_data['post_id'];
177 177
 		$faq_items = $post_data['faq_items'];
178
-		foreach ( $faq_items as $faq_item ) {
178
+		foreach ($faq_items as $faq_item) {
179 179
 			/**
180 180
 			 * Note: the order of keys is important in order to delete it properly
181 181
 			 * If the order change, delete operation will fail since it is converted
@@ -192,17 +192,17 @@  discard block
 block discarded – undo
192 192
 			 * If the field to be deleted is answer, then don't delete the faq item,
193 193
 			 * if it is question then delete the faq item.
194 194
 			 */
195
-			if ( self::ANSWER === $faq_item['field_to_be_deleted'] ) {
195
+			if (self::ANSWER === $faq_item['field_to_be_deleted']) {
196 196
 				$previous_value = $deleted_faq_item;
197 197
 				// then don't delete the faq item, set the answer as empty.
198 198
 				$deleted_faq_item['answer'] = '';
199 199
 				$new_value                  = $deleted_faq_item;
200
-				update_post_meta( $post_id, self::FAQ_META_KEY, $new_value, $previous_value );
201
-			} elseif ( self::QUESTION === $faq_item['field_to_be_deleted'] ) {
200
+				update_post_meta($post_id, self::FAQ_META_KEY, $new_value, $previous_value);
201
+			} elseif (self::QUESTION === $faq_item['field_to_be_deleted']) {
202 202
 				/**
203 203
 				 * If the question is deleted, then delete the faq item.
204 204
 				 */
205
-				delete_post_meta( $post_id, self::FAQ_META_KEY, $deleted_faq_item );
205
+				delete_post_meta($post_id, self::FAQ_META_KEY, $deleted_faq_item);
206 206
 			}
207 207
 		}
208 208
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		 */
212 212
 		return array(
213 213
 			'status'  => 'success',
214
-			'message' => __( 'Faq item successfully deleted.', 'wordlift' ),
214
+			'message' => __('Faq item successfully deleted.', 'wordlift'),
215 215
 		);
216 216
 	}
217 217
 
@@ -222,18 +222,18 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @return array Associative array whether the faq item is inserted or not
224 224
 	 */
225
-	public static function add_faq_items( $request ) {
225
+	public static function add_faq_items($request) {
226 226
 		$post_data = $request->get_params();
227 227
 		$post_id   = $post_data['post_id'];
228 228
 		$faq_items = $post_data['faq_items'];
229
-		foreach ( $faq_items as &$faq_item ) {
229
+		foreach ($faq_items as &$faq_item) {
230 230
 			// Add an identifier id to the faq item, it helps to prevent duplication problem.
231 231
 			/**
232 232
 			 * We are using time() and a random integer to prevent
233 233
 			 * duplication problem.
234 234
 			 */
235
-			$faq_item['id'] = time() + wp_rand( 1, 100 ) + wp_rand( 1, 100 );
236
-			add_post_meta( (int) $post_id, self::FAQ_META_KEY, $faq_item );
235
+			$faq_item['id'] = time() + wp_rand(1, 100) + wp_rand(1, 100);
236
+			add_post_meta((int) $post_id, self::FAQ_META_KEY, $faq_item);
237 237
 		}
238 238
 
239 239
 		/**
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		 */
242 242
 		return array(
243 243
 			'status'  => 'success',
244
-			'message' => __( 'Question successfully added.', 'wordlift' ),
244
+			'message' => __('Question successfully added.', 'wordlift'),
245 245
 			'id'      => (int) $faq_items[0]['id'],
246 246
 		);
247 247
 
Please login to merge, or discard this patch.
src/wordlift/faq/class-faq-tinymce-adapter.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -13,41 +13,41 @@
 block discarded – undo
13 13
 
14 14
 class Faq_Tinymce_Adapter {
15 15
 
16
-	const FAQ_TINYMCE_PLUGIN_NAME = 'wl_faq_tinymce';
17
-
18
-	const FAQ_TINYMCE_ADD_BUTTON_ID = 'wl-faq-toolbar-button';
19
-
20
-	/**
21
-	 * Add a list of custom tags which is to be used by our highlighting program.
22
-	 *
23
-	 * @param $init_array
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function register_custom_tags( $init_array ) {
28
-		$opts                                   = '~wl-faq-question,~wl-faq-answer';
29
-		$init_array['custom_elements']         .= ( empty( $init_array['custom_elements'] ) ? '' : ',' ) . $opts;
30
-		$init_array['extended_valid_elements'] .= ( empty( $init_array['extended_valid_elements'] ) ? '' : ',' ) . $opts;
31
-
32
-		return $init_array;
33
-	}
34
-
35
-	public function register_faq_tinymce_plugin( $plugins ) {
36
-		/**
37
-		 * Registering the tinymce plugin for FAQ here.
38
-		 *
39
-		 * @since 3.26.0
40
-		 */
41
-		$version                                  = Wordlift::get_instance()->get_version();
42
-		$plugins[ self::FAQ_TINYMCE_PLUGIN_NAME ] = plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/tinymce-faq-plugin.full.js?ver=' . $version;
43
-
44
-		return $plugins;
45
-	}
46
-
47
-	public function register_faq_toolbar_button( $buttons ) {
48
-		array_push( $buttons, self::FAQ_TINYMCE_ADD_BUTTON_ID );
49
-
50
-		return $buttons;
51
-	}
16
+    const FAQ_TINYMCE_PLUGIN_NAME = 'wl_faq_tinymce';
17
+
18
+    const FAQ_TINYMCE_ADD_BUTTON_ID = 'wl-faq-toolbar-button';
19
+
20
+    /**
21
+     * Add a list of custom tags which is to be used by our highlighting program.
22
+     *
23
+     * @param $init_array
24
+     *
25
+     * @return array
26
+     */
27
+    public function register_custom_tags( $init_array ) {
28
+        $opts                                   = '~wl-faq-question,~wl-faq-answer';
29
+        $init_array['custom_elements']         .= ( empty( $init_array['custom_elements'] ) ? '' : ',' ) . $opts;
30
+        $init_array['extended_valid_elements'] .= ( empty( $init_array['extended_valid_elements'] ) ? '' : ',' ) . $opts;
31
+
32
+        return $init_array;
33
+    }
34
+
35
+    public function register_faq_tinymce_plugin( $plugins ) {
36
+        /**
37
+         * Registering the tinymce plugin for FAQ here.
38
+         *
39
+         * @since 3.26.0
40
+         */
41
+        $version                                  = Wordlift::get_instance()->get_version();
42
+        $plugins[ self::FAQ_TINYMCE_PLUGIN_NAME ] = plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/tinymce-faq-plugin.full.js?ver=' . $version;
43
+
44
+        return $plugins;
45
+    }
46
+
47
+    public function register_faq_toolbar_button( $buttons ) {
48
+        array_push( $buttons, self::FAQ_TINYMCE_ADD_BUTTON_ID );
49
+
50
+        return $buttons;
51
+    }
52 52
 
53 53
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,28 +24,28 @@
 block discarded – undo
24 24
 	 *
25 25
 	 * @return array
26 26
 	 */
27
-	public function register_custom_tags( $init_array ) {
27
+	public function register_custom_tags($init_array) {
28 28
 		$opts                                   = '~wl-faq-question,~wl-faq-answer';
29
-		$init_array['custom_elements']         .= ( empty( $init_array['custom_elements'] ) ? '' : ',' ) . $opts;
30
-		$init_array['extended_valid_elements'] .= ( empty( $init_array['extended_valid_elements'] ) ? '' : ',' ) . $opts;
29
+		$init_array['custom_elements']         .= (empty($init_array['custom_elements']) ? '' : ',').$opts;
30
+		$init_array['extended_valid_elements'] .= (empty($init_array['extended_valid_elements']) ? '' : ',').$opts;
31 31
 
32 32
 		return $init_array;
33 33
 	}
34 34
 
35
-	public function register_faq_tinymce_plugin( $plugins ) {
35
+	public function register_faq_tinymce_plugin($plugins) {
36 36
 		/**
37 37
 		 * Registering the tinymce plugin for FAQ here.
38 38
 		 *
39 39
 		 * @since 3.26.0
40 40
 		 */
41 41
 		$version                                  = Wordlift::get_instance()->get_version();
42
-		$plugins[ self::FAQ_TINYMCE_PLUGIN_NAME ] = plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/tinymce-faq-plugin.full.js?ver=' . $version;
42
+		$plugins[self::FAQ_TINYMCE_PLUGIN_NAME] = plugin_dir_url(dirname(__DIR__)).'js/dist/tinymce-faq-plugin.full.js?ver='.$version;
43 43
 
44 44
 		return $plugins;
45 45
 	}
46 46
 
47
-	public function register_faq_toolbar_button( $buttons ) {
48
-		array_push( $buttons, self::FAQ_TINYMCE_ADD_BUTTON_ID );
47
+	public function register_faq_toolbar_button($buttons) {
48
+		array_push($buttons, self::FAQ_TINYMCE_ADD_BUTTON_ID);
49 49
 
50 50
 		return $buttons;
51 51
 	}
Please login to merge, or discard this patch.
src/wordlift/cleanup/class-post-handler.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@
 block discarded – undo
14 14
 
15 15
 class Post_Handler {
16 16
 
17
-	/**
18
-	 * Process post.
19
-	 *
20
-	 * @param int $post_id
21
-	 */
22
-	public static function fix( $post_id ) {
23
-		// 3 cases:
24
-		// 1. item id w/o the base URI: itemid="/entity/marketing"
25
-		// 2. item id w/ domain outside the scope of dataset URI: itemid="https://data.wordlift.io/wl95583/entity/emailing"
26
-		// 3. item id w/ domain within the scope of the dataset URI, but non existent.
27
-		// 4. should we manipulate also the `wp:wordlift/classification` block?
28
-
29
-		$post             = get_post( $post_id );
30
-		$new_post_content = preg_replace_callback(
31
-			'@<(\w+)[^<]*class="([^"]*)"\sitemid="([^"]+)"[^>]*>(.*?)</\1>@i',
32
-			array( get_class(), 'fix_annotations' ),
33
-			$post->post_content,
34
-			- 1,
35
-			$count
36
-		);
37
-
38
-		if ( 0 === $count || $new_post_content === $post->post_content ) {
39
-			// Bail out if the regex doesn't match or if the post content didn't change.
40
-			return;
41
-		}
42
-
43
-		wp_update_post(
44
-			array(
45
-				'ID'           => $post_id,
46
-				'post_content' => $new_post_content,
47
-			)
48
-		);
49
-
50
-	}
51
-
52
-	public static function fix_annotations( $args ) {
53
-		// Make the item id relative.
54
-		if ( 0 === preg_match( '@(?:https?://[^/]+/[^/]+)?/?(.*)@', $args[3], $matches ) ) {
55
-			return $args[4];
56
-		}
57
-
58
-		$item_id = $matches[1];
59
-
60
-		// Bail out if the item id is empty.
61
-		if ( empty( $item_id ) ) {
62
-			return $args[4];
63
-		}
64
-
65
-		// Find a matching content.
66
-		$content_service = Wordpress_Content_Service::get_instance();
67
-		$content         = $content_service->get_by_entity_id_or_same_as( $item_id );
68
-
69
-		if ( ! isset( $content ) ) {
70
-			// No content found return only label.
71
-			return $args[4];
72
-		} else {
73
-			// Get the actual entity id.
74
-			$new_item_id = $content_service->get_entity_id(
75
-				new Wordpress_Content_Id( $content->get_id(), $content->get_object_type_enum() )
76
-			);
77
-
78
-			// Replace the incoming entity id with the actual entity id.
79
-			return str_replace( $args[3], $new_item_id, $args[0] );
80
-		}
81
-	}
17
+    /**
18
+     * Process post.
19
+     *
20
+     * @param int $post_id
21
+     */
22
+    public static function fix( $post_id ) {
23
+        // 3 cases:
24
+        // 1. item id w/o the base URI: itemid="/entity/marketing"
25
+        // 2. item id w/ domain outside the scope of dataset URI: itemid="https://data.wordlift.io/wl95583/entity/emailing"
26
+        // 3. item id w/ domain within the scope of the dataset URI, but non existent.
27
+        // 4. should we manipulate also the `wp:wordlift/classification` block?
28
+
29
+        $post             = get_post( $post_id );
30
+        $new_post_content = preg_replace_callback(
31
+            '@<(\w+)[^<]*class="([^"]*)"\sitemid="([^"]+)"[^>]*>(.*?)</\1>@i',
32
+            array( get_class(), 'fix_annotations' ),
33
+            $post->post_content,
34
+            - 1,
35
+            $count
36
+        );
37
+
38
+        if ( 0 === $count || $new_post_content === $post->post_content ) {
39
+            // Bail out if the regex doesn't match or if the post content didn't change.
40
+            return;
41
+        }
42
+
43
+        wp_update_post(
44
+            array(
45
+                'ID'           => $post_id,
46
+                'post_content' => $new_post_content,
47
+            )
48
+        );
49
+
50
+    }
51
+
52
+    public static function fix_annotations( $args ) {
53
+        // Make the item id relative.
54
+        if ( 0 === preg_match( '@(?:https?://[^/]+/[^/]+)?/?(.*)@', $args[3], $matches ) ) {
55
+            return $args[4];
56
+        }
57
+
58
+        $item_id = $matches[1];
59
+
60
+        // Bail out if the item id is empty.
61
+        if ( empty( $item_id ) ) {
62
+            return $args[4];
63
+        }
64
+
65
+        // Find a matching content.
66
+        $content_service = Wordpress_Content_Service::get_instance();
67
+        $content         = $content_service->get_by_entity_id_or_same_as( $item_id );
68
+
69
+        if ( ! isset( $content ) ) {
70
+            // No content found return only label.
71
+            return $args[4];
72
+        } else {
73
+            // Get the actual entity id.
74
+            $new_item_id = $content_service->get_entity_id(
75
+                new Wordpress_Content_Id( $content->get_id(), $content->get_object_type_enum() )
76
+            );
77
+
78
+            // Replace the incoming entity id with the actual entity id.
79
+            return str_replace( $args[3], $new_item_id, $args[0] );
80
+        }
81
+    }
82 82
 
83 83
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,23 +19,23 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param int $post_id
21 21
 	 */
22
-	public static function fix( $post_id ) {
22
+	public static function fix($post_id) {
23 23
 		// 3 cases:
24 24
 		// 1. item id w/o the base URI: itemid="/entity/marketing"
25 25
 		// 2. item id w/ domain outside the scope of dataset URI: itemid="https://data.wordlift.io/wl95583/entity/emailing"
26 26
 		// 3. item id w/ domain within the scope of the dataset URI, but non existent.
27 27
 		// 4. should we manipulate also the `wp:wordlift/classification` block?
28 28
 
29
-		$post             = get_post( $post_id );
29
+		$post             = get_post($post_id);
30 30
 		$new_post_content = preg_replace_callback(
31 31
 			'@<(\w+)[^<]*class="([^"]*)"\sitemid="([^"]+)"[^>]*>(.*?)</\1>@i',
32
-			array( get_class(), 'fix_annotations' ),
32
+			array(get_class(), 'fix_annotations'),
33 33
 			$post->post_content,
34 34
 			- 1,
35 35
 			$count
36 36
 		);
37 37
 
38
-		if ( 0 === $count || $new_post_content === $post->post_content ) {
38
+		if (0 === $count || $new_post_content === $post->post_content) {
39 39
 			// Bail out if the regex doesn't match or if the post content didn't change.
40 40
 			return;
41 41
 		}
@@ -49,34 +49,34 @@  discard block
 block discarded – undo
49 49
 
50 50
 	}
51 51
 
52
-	public static function fix_annotations( $args ) {
52
+	public static function fix_annotations($args) {
53 53
 		// Make the item id relative.
54
-		if ( 0 === preg_match( '@(?:https?://[^/]+/[^/]+)?/?(.*)@', $args[3], $matches ) ) {
54
+		if (0 === preg_match('@(?:https?://[^/]+/[^/]+)?/?(.*)@', $args[3], $matches)) {
55 55
 			return $args[4];
56 56
 		}
57 57
 
58 58
 		$item_id = $matches[1];
59 59
 
60 60
 		// Bail out if the item id is empty.
61
-		if ( empty( $item_id ) ) {
61
+		if (empty($item_id)) {
62 62
 			return $args[4];
63 63
 		}
64 64
 
65 65
 		// Find a matching content.
66 66
 		$content_service = Wordpress_Content_Service::get_instance();
67
-		$content         = $content_service->get_by_entity_id_or_same_as( $item_id );
67
+		$content         = $content_service->get_by_entity_id_or_same_as($item_id);
68 68
 
69
-		if ( ! isset( $content ) ) {
69
+		if ( ! isset($content)) {
70 70
 			// No content found return only label.
71 71
 			return $args[4];
72 72
 		} else {
73 73
 			// Get the actual entity id.
74 74
 			$new_item_id = $content_service->get_entity_id(
75
-				new Wordpress_Content_Id( $content->get_id(), $content->get_object_type_enum() )
75
+				new Wordpress_Content_Id($content->get_id(), $content->get_object_type_enum())
76 76
 			);
77 77
 
78 78
 			// Replace the incoming entity id with the actual entity id.
79
-			return str_replace( $args[3], $new_item_id, $args[0] );
79
+			return str_replace($args[3], $new_item_id, $args[0]);
80 80
 		}
81 81
 	}
82 82
 
Please login to merge, or discard this patch.