| 1 |
<?php |
| 2 |
/** |
| 3 |
* Feature report class |
| 4 |
* |
| 5 |
* @since 4.4.0 |
| 6 |
* @package elasticpress |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ElasticPress\StatusReport; |
| 10 |
|
| 11 |
use ElasticPress\Features as EP_Features; |
| 12 |
use ElasticPress\Feature\Search\Search; |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* Feature report class |
| 18 |
* |
| 19 |
* @package ElasticPress |
| 20 |
*/ |
| 21 |
class Features extends Report { |
| 22 |
|
| 23 |
/** |
| 24 |
* Return the report title |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public function get_title(): string { |
| 29 |
return __( 'Feature Settings', 'elasticpress' ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Return the report fields |
| 34 |
* |
| 35 |
* @return array |
| 36 |
*/ |
| 37 |
public function get_groups(): array { |
| 38 |
$features_settings = \ElasticPress\Utils\get_option( 'ep_feature_settings', [] ); |
| 39 |
|
| 40 |
$features = array_filter( |
| 41 |
EP_Features::factory()->registered_features, |
| 42 |
function ( $feature ) { |
| 43 |
return $feature->is_active(); |
| 44 |
} |
| 45 |
); |
| 46 |
$features = wp_list_sort( $features, 'title' ); |
| 47 |
|
| 48 |
$groups = []; |
| 49 |
foreach ( $features as $feature ) { |
| 50 |
$feature_settings = $features_settings[ $feature->slug ] ?? []; |
| 51 |
|
| 52 |
$fields = []; |
| 53 |
foreach ( $feature_settings as $feature_setting => $value ) { |
| 54 |
$fields[ $feature_setting ] = [ |
| 55 |
'label' => $feature_setting, |
| 56 |
'value' => $value, |
| 57 |
]; |
| 58 |
} |
| 59 |
ksort( $fields ); |
| 60 |
|
| 61 |
if ( method_exists( $this, "get_{$feature->slug}_extra_fields" ) ) { |
| 62 |
$fields = call_user_func( [ $this, "get_{$feature->slug}_extra_fields" ], $fields, $feature ); |
| 63 |
} |
| 64 |
|
| 65 |
$groups[] = [ |
| 66 |
'title' => $feature->get_short_title(), |
| 67 |
'fields' => $fields, |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
return $groups; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Extra fields for the Search feature |
| 76 |
* |
| 77 |
* @since 4.7.1 |
| 78 |
* @param array $fields Current fields |
| 79 |
* @param Search $feature Feature object |
| 80 |
* @return array New fields |
| 81 |
*/ |
| 82 |
protected function get_search_extra_fields( array $fields, Search $feature ): array { |
| 83 |
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { |
| 84 |
return $fields; |
| 85 |
} |
| 86 |
|
| 87 |
return array_merge( |
| 88 |
$fields, |
| 89 |
[ |
| 90 |
'synonyms' => [ |
| 91 |
'label' => __( 'Synonyms', 'elasticpress' ), |
| 92 |
'value' => '<pre>' . $feature->synonyms->get_synonyms_raw() . '</pre>', |
| 93 |
], |
| 94 |
'weighting' => [ |
| 95 |
'label' => __( 'Search Fields & Weighting', 'elasticpress' ), |
| 96 |
'value' => $feature->weighting->get_weighting_configuration(), |
| 97 |
], |
| 98 |
] |
| 99 |
); |
| 100 |
} |
| 101 |
} |
| 102 |
|