Skip to content

Commit

Permalink
Merge pull request #1987 from Rahmon/feat/ordering-features
Browse files Browse the repository at this point in the history
Add a way to change the ordering of the features on the Features page
  • Loading branch information
felipeelia authored May 28, 2021
2 parents e950aa9 + 04193a6 commit 5f76f26
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
17 changes: 17 additions & 0 deletions includes/classes/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ abstract class Feature {
*/
public $requires_install_reindex;

/**
* The order in the features screen
*
* @var int
* @since 3.6.0
*/
public $order;

/**
* Set if a feature should be on the left or right side
*
* @var string
* @since 3.6.0
*/
public $group_order;


/**
* Run on every page load for feature to set itself up
*
Expand Down
27 changes: 23 additions & 4 deletions includes/partials/dashboard-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@
<div class="wrap">
<h2 class="ep-list-features"><?php esc_html_e( 'List of features', 'elasticpress' ); // We use this since WP inserts warnings after the first h2. This will be hidden. ?></h2>
<div class="ep-features metabox-holder">
<?php $features = Features::factory()->registered_features; ?>
<?php
$features = Features::factory()->registered_features;
uasort(
$features,
function( $feature_a, $feature_b ) {
$order_feature_a = (int) $feature_a->order;
$order_feature_b = (int) $feature_b->order;

if ( $order_feature_a === $order_feature_b ) {
return 0;
}

return $order_feature_a < $order_feature_b ? -1 : 1;
}
);
?>

<?php
$left = '';
Expand Down Expand Up @@ -68,10 +83,14 @@
</div>
</div>
<?php
if ( 0 === $i % 2 ) {
$right .= ob_get_clean();
if ( 'right' === $feature->group_order || 'left' === $feature->group_order ) {
${$feature->group_order} .= ob_get_clean();
} else {
$left .= ob_get_clean();
if ( 0 === $i % 2 ) {
$right .= ob_get_clean();
} else {
$left .= ob_get_clean();
}
}
?>
<?php endforeach; ?>
Expand Down

0 comments on commit 5f76f26

Please sign in to comment.