Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow consistent filtering of datasource items #696

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion php/datasource/class-fieldmanager-datasource-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ public function get_items( $fragment = null ) {
}
$ret[ $p->ID ] = $p->post_title . $date_pad;
}
return $ret;

/**
* Filter items to be returned
*
* @param array $ret Available options, filtered by fragment.
* @param array $posts Found posts.
* @param object $this Datasource object.
* @param string $fragment Search term.
*/
return apply_filters( 'fm_datasource_post_get_items', $ret, $posts, $this, $fragment );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions php/datasource/class-fieldmanager-datasource-term.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ public function get_items( $fragment = null ) {
$key = $this->store_term_taxonomy_id ? $term->term_taxonomy_id : $term->term_id;
$stack[ $key ] = $term->name;
}

/**
* Filter items to be returned
*
* @param array $stack Term list, filtered by fragment.
* @param array $terms Found terms.
* @param object $this Datasource object.
* @param string $fragment Search term.
*/
return apply_filters( 'fm_datasource_term_get_items', $stack, $terms, $this, $fragment );
}

Expand Down
10 changes: 9 additions & 1 deletion php/datasource/class-fieldmanager-datasource-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,15 @@ public function get_items( $fragment = null ) {
$ret[ $u->{$this->store_property} ] = $u->{$this->display_property};
}

return $ret;
/**
* Filter items to be returned
*
* @param array $ret User list, filtered by fragment.
* @param array $users Found users.
* @param object $this Datasource object.
* @param string $fragment Search term.
*/
return apply_filters( 'fm_datasource_user_get_items', $ret, $users, $this, $fragment );
}

/**
Expand Down
13 changes: 11 additions & 2 deletions php/datasource/class-fieldmanager-datasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,16 @@ public function get_items( $fragment = null ) {
$ret[ $k ] = $v;
}
}
return $ret;

/**
* Filter items to be returned
*
* @param array $ret Available options, filtered by fragment.
* @param array $this->options All available options.
* @param object $this Datasource object.
* @param string $fragment Search term.
*/
return apply_filters( 'fm_datasource_get_items', $ret, $this->options, $this, $fragment );
}

/**
Expand Down Expand Up @@ -180,7 +189,7 @@ public function get_items_for_ajax( $fragment = null ) {
);
}

return $return;
return apply_filters( 'fm_datasource_get_items_for_ajax', $return, $items, $this, $fragment );
}

/**
Expand Down