Skip to content

Commit

Permalink
Merge branch 'acf_fix' into 'beta'
Browse files Browse the repository at this point in the history
acf fix

See merge request WordPress/plugin-hacks!14
  • Loading branch information
Helmut Januschka committed Mar 27, 2019
2 parents 6cef1b6 + 6505be0 commit 1343f1f
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public function add_actions()
return 86400 * 30;
});

//FIX OLD/legacy ACF entries that used to have double encoded values
add_filter('acf/load_value', [$this, 'acf_load_value'], 10, 3);

//Disable comment count in admin-navigation
if (is_admin()) {
add_filter('wp_count_comments', function ($counts, $post_id) {
Expand Down Expand Up @@ -118,6 +121,11 @@ public function add_actions()
});
}

public function acf_load_value($value, $post_id, $field)
{
return maybe_unserialize($value);
}

public function ep_post_sync_args($args, $post_id)
{
$args['comment_status'] = absint($args['comment_status']);
Expand Down Expand Up @@ -185,29 +193,29 @@ public function ep_index_post_request_args($args, $post)

public function wildCardIt($s)
{
if($this->isExtenendEPQuery($s)) {
return $s;
if ($this->isExtenendEPQuery($s)) {
return $s;
}
$w = explode(' ', $s);
$fin = [];
foreach ($w as $word) {
$fin[] = '/.*' . $word . '.*/';
$fin[] = '/.*' . $word . '.*/';
}

return join($fin, ' ');
}

public function ep_config_mapping($mapping)
{

/*
*
$mapping['settings']['analysis']['analyzer']['default']['filter'] = [ 'standard','lowercase', 'edge_ngram'];
$mapping['settings']['analysis']['filter']['edge_ngram']['min_gram'] = 3;
$mapping['settings']['analysis']['filter']['edge_ngram']['max_gram'] = 128; //(quite bit but we're happy with this)
*/
/*
*
$mapping['settings']['analysis']['analyzer']['default']['filter'] = [ 'standard','lowercase', 'edge_ngram'];
$mapping['settings']['analysis']['filter']['edge_ngram']['min_gram'] = 3;
$mapping['settings']['analysis']['filter']['edge_ngram']['max_gram'] = 128; //(quite bit but we're happy with this)
*/
return $mapping;
}

public function ep_formatted_args($args)
{
if (! array_key_exists('bool', $args['query'])) {
Expand All @@ -219,15 +227,14 @@ public function ep_formatted_args($args)
$qs = $args['query']['bool']['should'][0]['multi_match']['query'];
$qs = $this->wildCardIt($qs);
$qs = $this->sanitizeEPQuery($qs);
$nq = [
$nq = [
'query_string' => [
'default_field' => 'post_title.post_title',
"query" => $qs,
'query' => $qs,
'default_operator' => 'AND',
"analyze_wildcard" => true,
"fuzziness" => 5

]
'analyze_wildcard' => true,
'fuzziness' => 5,
],
];
//Reset
unset($args['query']);
Expand All @@ -238,19 +245,23 @@ public function ep_formatted_args($args)
//exit;
return $args;
}
public function sanitizeEPQuery($q) {
if($this->isExtenendEPQuery($q)) {
return preg_replace("#^\!#", "", $q);
}
return str_replace(

public function sanitizeEPQuery($q)
{
if ($this->isExtenendEPQuery($q)) {
return preg_replace("#^\!#", '', $q);
}

return str_replace(
['\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '?', ':'],
['\\\\', "\+", "\-", "\&", "\|", "\!", "\(", "\)", "\{", "\}", "\[", "\]", "\^", "\~", "\?", "\:"],
$q
);

}
public function isExtenendEPQuery($q) {
return preg_match("#^\!#", $q);

public function isExtenendEPQuery($q)
{
return preg_match("#^\!#", $q);
}

/*
Expand Down

0 comments on commit 1343f1f

Please sign in to comment.