Skip to content

Commit 675b322

Browse files
authored
Merge pull request #890 from alleyinteractive/hotfix/query-cb
Fix issue where query callback is a non-string callable
2 parents 584979f + cae0a2e commit 675b322

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ jobs:
4141
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
4242

4343
- name: Set up Composer caching
44-
uses: actions/cache@v2
45-
env:
46-
cache-name: cache-composer-dependencies
44+
uses: actions/cache@v4
4745
with:
4846
path: |
4947
${{ steps.composer-cache.outputs.dir }}

php/class-fieldmanager-autocomplete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Fieldmanager_Autocomplete extends Fieldmanager_Field {
4242
*
4343
* The function signature should be query_callback( $match, $args );
4444
*
45-
* @var callable
45+
* @var callable|null
4646
*/
4747
public $query_callback = null;
4848

php/datasource/class-fieldmanager-datasource-post.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Fieldmanager_Datasource_Post extends Fieldmanager_Datasource {
1414
* Supply a function which returns a list of posts; takes one argument,
1515
* a possible fragment.
1616
*
17-
* @var null
17+
* @var callback|null
1818
*/
1919
public $query_callback = null;
2020

@@ -202,8 +202,20 @@ public function get_ajax_action() {
202202
if ( ! empty( $this->ajax_action ) ) {
203203
return $this->ajax_action;
204204
}
205-
$unique_key = wp_json_encode( $this->query_args );
206-
$unique_key .= (string) $this->query_callback;
205+
$unique_key = wp_json_encode( $this->query_args );
206+
if ( is_string( $this->query_callback ) ) {
207+
$unique_key .= $this->query_callback;
208+
} elseif (
209+
is_array( $this->query_callback )
210+
&& isset( $this->query_callback[0] )
211+
&& isset( $this->query_callback[1] )
212+
&& is_string( $this->query_callback[1] )
213+
) {
214+
$unique_key .= is_object( $this->query_callback[0] ) ? get_debug_type( $this->query_callback[0] ) : (string) $this->query_callback[0];
215+
$unique_key .= $this->query_callback[1];
216+
} else {
217+
$unique_key .= get_debug_type( $this->query_callback );
218+
}
207219
$unique_key .= get_called_class();
208220
return 'fm_datasource_post_' . crc32( $unique_key );
209221
}

php/datasource/class-fieldmanager-datasource-user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Fieldmanager_Datasource_User extends Fieldmanager_Datasource {
1414
* Supply a function which returns a list of users; takes one argument,
1515
* a possible fragment.
1616
*
17-
* @var callable
17+
* @var callable|null
1818
*/
1919
public $query_callback = null;
2020

0 commit comments

Comments
 (0)