Commit dfeb8797 authored by Thomas Lartaud's avatar Thomas Lartaud
Browse files

categories shouldnt hide post hide post where we are author if option if set to

parent ded79454
......@@ -102,6 +102,7 @@ feel free to fork the project and send us pull requests!
= 8.0.5 (2021/??/??) =
* Fix: File's categories hide empty categories option
* Fix: jQuery un-compatibility that was preventing multiple checkboxes to work on capabilities screen
* Fix: jQuery deprecated functions
......
......@@ -101,12 +101,18 @@ if (!class_exists('CUAR_TermsWidget')) :
{
/** @var CUAR_PostOwnerAddOn $po_addon */
$po_addon = cuar_addon('post-owner');
$query = new WP_Query([
$query_args = [
'query_filter' => 'cuar_widget_add_authored_by',
'post_type' => $this->get_friendly_post_type(),
'posts_per_page' => -1,
'fields' => 'ids',
'meta_query' => $po_addon->get_meta_query_post_owned_by(get_current_user_id()),
]);
];
add_filter( 'posts_where', [&$this, 'filter_query_to_add_authored_by'], 9, 2);
$query = new WP_Query($query_args);
remove_filter('posts_where', [&$this, 'filter_query_to_add_authored_by']);
$post_ids = $query->get_posts();
$get_terms_options = [
......@@ -157,6 +163,24 @@ if (!class_exists('CUAR_TermsWidget')) :
echo $args['after_widget'];
}
public function filter_query_to_add_authored_by( $where, $q ) {
if ( isset($q->query['query_filter']) && 'cuar_widget_add_authored_by' === $q->query['query_filter'] ) {
global $wpdb;
$disable_authored_by = apply_filters('cuar/core/page/query-disable-authored-by', true);
$disable_authored_by = apply_filters('cuar/core/page/query-disable-authored-by?post_type=' . $q->query['post_type'], $disable_authored_by, $q);
if($disable_authored_by) return $where;
$needle_open = "( " . $wpdb->prefix . "postmeta.meta_key = '" . CUAR_PostOwnerAddOn::$META_OWNER_QUERYABLE . "'";
$pos_open = strpos($where, $needle_open);
if ($pos_open !== false) {
$new_cond_open = "( post_author = " . apply_filters('cuar/core/page/query-disable-authored-by/override-user-id', get_current_user_id()) . " ) OR " . $needle_open;
$where = substr_replace($where, $new_cond_open, $pos_open, strlen($needle_open));
}
}
return $where;
}
protected function get_term_downstream_hierarchy($term, $hide_empty, $whitelist = null)
{
if ($whitelist !== null && !in_array($term->term_id, $whitelist, true))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment