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