Completed
Push — master ( 585add...ca5180 )
by David
02:23
created
src/modules/core/wordlift_core_entity_api.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,47 +20,47 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function wl_entity_get_by_title( $title, $autocomplete = false, $include_alias = true ) {
22 22
 
23
-	global $wpdb;
24
-
25
-	// Search by substring
26
-	if ( $autocomplete ) {
27
-		$title = '%' . $title . '%';
28
-	}
29
-
30
-	// The title is a LIKE query.
31
-	$query = "SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug"
32
-			 . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t"
33
-			 . "  WHERE p.post_title LIKE %s"
34
-			 . "   AND t.term_id = tt.term_id"
35
-			 . "   AND tt.taxonomy = %s"
36
-			 . "   AND tt.term_taxonomy_id = tr.term_taxonomy_id"
37
-			 . "   AND tr.object_id = p.ID"
38
-			 // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278.
39
-			 . "   AND p.post_status != 'trash'";
40
-
41
-	if ( $include_alias ) {
42
-
43
-		$query .= " UNION"
44
-				  . "  SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug"
45
-				  . "  FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m"
46
-				  . "   WHERE m.meta_key = %s AND m.meta_value LIKE %s"
47
-				  . "    AND m.post_id = p.ID"
48
-				  . "    AND t.term_id = tt.term_id"
49
-				  . "    AND tt.taxonomy = %s"
50
-				  . "    AND tt.term_taxonomy_id = tr.term_taxonomy_id"
51
-				  . "    AND tr.object_id = p.ID"
52
-				  // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278.
53
-				  . "    AND p.post_status != 'trash'";
54
-	}
55
-
56
-	return $wpdb->get_results( $wpdb->prepare(
57
-		$query,
58
-		$title,
59
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
60
-		Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
61
-		$title,
62
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME
63
-	) );
23
+    global $wpdb;
24
+
25
+    // Search by substring
26
+    if ( $autocomplete ) {
27
+        $title = '%' . $title . '%';
28
+    }
29
+
30
+    // The title is a LIKE query.
31
+    $query = "SELECT DISTINCT p.ID AS id, p.post_title AS title, t.name AS schema_type_name, t.slug AS type_slug"
32
+                . " FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t"
33
+                . "  WHERE p.post_title LIKE %s"
34
+                . "   AND t.term_id = tt.term_id"
35
+                . "   AND tt.taxonomy = %s"
36
+                . "   AND tt.term_taxonomy_id = tr.term_taxonomy_id"
37
+                . "   AND tr.object_id = p.ID"
38
+                // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278.
39
+                . "   AND p.post_status != 'trash'";
40
+
41
+    if ( $include_alias ) {
42
+
43
+        $query .= " UNION"
44
+                    . "  SELECT DISTINCT p.ID AS id, CONCAT( m.meta_value, ' (', p.post_title, ')' ) AS title, t.name AS schema_type_name, t.slug AS type_slug"
45
+                    . "  FROM $wpdb->posts p, $wpdb->term_taxonomy tt, $wpdb->term_relationships tr, $wpdb->terms t, $wpdb->postmeta m"
46
+                    . "   WHERE m.meta_key = %s AND m.meta_value LIKE %s"
47
+                    . "    AND m.post_id = p.ID"
48
+                    . "    AND t.term_id = tt.term_id"
49
+                    . "    AND tt.taxonomy = %s"
50
+                    . "    AND tt.term_taxonomy_id = tr.term_taxonomy_id"
51
+                    . "    AND tr.object_id = p.ID"
52
+                    // Ensure we don't load entities from the trash, see https://github.com/insideout10/wordlift-plugin/issues/278.
53
+                    . "    AND p.post_status != 'trash'";
54
+    }
55
+
56
+    return $wpdb->get_results( $wpdb->prepare(
57
+        $query,
58
+        $title,
59
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
60
+        Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
61
+        $title,
62
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME
63
+    ) );
64 64
 }
65 65
 
66 66
 /**
@@ -70,41 +70,41 @@  discard block
 block discarded – undo
70 70
  */
71 71
 function wl_entity_ajax_get_by_title() {
72 72
 
73
-	// `wl_entity_metaboxes_utilities.js` still uses `GET`.
74
-	//
75
-	// See https://github.com/insideout10/wordlift-plugin/issues/438.
76
-	// Get the title to search.
77
-	if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) {
78
-		@ob_clean();
79
-		wp_send_json_error( 'The title parameter is required.' );
80
-	}
81
-
82
-	// `wl_entity_metaboxes_utilities.js` still uses `GET`.
83
-	//
84
-	// See https://github.com/insideout10/wordlift-plugin/issues/438.
85
-	$title = $_POST['title'] ?: $_GET['title'];
86
-
87
-	// Are we searching for a specific title or for a containing title?
88
-	$autocomplete = isset( $_GET['autocomplete'] );
89
-
90
-	// Are we searching also for the aliases?
91
-	$include_alias = isset( $_GET['alias'] );
92
-
93
-	// Get the edit link.
94
-	$post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME );
95
-	$edit_link        = $post_type_object->_edit_link . '&action=edit';
96
-
97
-	// Prepare the response with the edit link.
98
-	$response = array(
99
-		'edit_link' => $edit_link,
100
-		'results'   => wl_entity_get_by_title( $title, $autocomplete, $include_alias ),
101
-	);
102
-
103
-	// Clean any buffer.
104
-	ob_clean();
105
-
106
-	// Send the success response.
107
-	wp_send_json_success( $response );
73
+    // `wl_entity_metaboxes_utilities.js` still uses `GET`.
74
+    //
75
+    // See https://github.com/insideout10/wordlift-plugin/issues/438.
76
+    // Get the title to search.
77
+    if ( empty( $_POST['title'] ) && empty( $_GET['title'] ) ) {
78
+        @ob_clean();
79
+        wp_send_json_error( 'The title parameter is required.' );
80
+    }
81
+
82
+    // `wl_entity_metaboxes_utilities.js` still uses `GET`.
83
+    //
84
+    // See https://github.com/insideout10/wordlift-plugin/issues/438.
85
+    $title = $_POST['title'] ?: $_GET['title'];
86
+
87
+    // Are we searching for a specific title or for a containing title?
88
+    $autocomplete = isset( $_GET['autocomplete'] );
89
+
90
+    // Are we searching also for the aliases?
91
+    $include_alias = isset( $_GET['alias'] );
92
+
93
+    // Get the edit link.
94
+    $post_type_object = get_post_type_object( Wordlift_Entity_Service::TYPE_NAME );
95
+    $edit_link        = $post_type_object->_edit_link . '&action=edit';
96
+
97
+    // Prepare the response with the edit link.
98
+    $response = array(
99
+        'edit_link' => $edit_link,
100
+        'results'   => wl_entity_get_by_title( $title, $autocomplete, $include_alias ),
101
+    );
102
+
103
+    // Clean any buffer.
104
+    ob_clean();
105
+
106
+    // Send the success response.
107
+    wp_send_json_success( $response );
108 108
 
109 109
 }
110 110
 
Please login to merge, or discard this patch.