Skip to content

Commit

Permalink
clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgrainger committed Jun 13, 2022
1 parent 681aaca commit 702f443
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 40 deletions.
74 changes: 49 additions & 25 deletions src/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ class Columns
public $sortable = [];

/**
* Set the all columns
* @param array $columns an array of all the columns to replace
* Set the all columns.
*
* @param array $columns an array of all the columns to replace.
*/
public function set($columns)
{
$this->items = $columns;
}

/**
* Add a new column
* @param string $column the slug of the column
* @param string $label the label for the column
* Add a new column.
*
* @param string $column the slug of the column.
* @param string $label the label for the column.
*
* @return PostType\Columns
*/
public function add($columns, $label = null)
{
Expand All @@ -90,8 +94,11 @@ public function add($columns, $label = null)
}

/**
* Add a column to hide
* @param string $column the slug of the column to hdie
* Add a column to hide.
*
* @param string $column the slug of the column to hide.
*
* @return PostType\Columns
*/
public function hide($columns)
{
Expand All @@ -107,9 +114,12 @@ public function hide($columns)
}

/**
* Set a custom callback to populate a column
* @param string $column the column slug
* @param mixed $callback callback function
* Set a custom callback to populate a column.
*
* @param string $column the column slug.
* @param mixed $callback callback function.
*
* @return PostType\Columns
*/
public function populate($column, $callback)
{
Expand All @@ -119,8 +129,11 @@ public function populate($column, $callback)
}

/**
* Define the postion for a columns
* Define the postion for a columns.
*
* @param string $columns an array of columns
*
* @return PostType\Columns
*/
public function order($columns)
{
Expand All @@ -132,10 +145,13 @@ public function order($columns)
}

/**
* Set columns that are sortable
* Set columns that are sortable.
*
* @param string $column the slug of the column
* @param string $meta_value the meta_value to orderby
* @param boolean $is_num whether to order by string/number
*
* @return PostType\Columns
*/
public function sortable($sortable)
{
Expand All @@ -148,7 +164,10 @@ public function sortable($sortable)

/**
* Check if an orderby field is a custom sort option.
* @param string $orderby the orderby value from query params
*
* @param string $orderby the orderby value from query params.
*
* @return boolean
*/
public function isSortable($orderby)
{
Expand All @@ -170,7 +189,10 @@ public function isSortable($orderby)

/**
* Get meta key for an orderby.
* @param string $orderby the orderby value from query params
*
* @param string $orderby the orderby value from query params
*
* @return mixed
*/
public function sortableMeta($orderby)
{
Expand All @@ -191,46 +213,48 @@ public function sortableMeta($orderby)
}

/**
* Modify the columns for the object
* Modify the columns for the object.
*
* @param array $columns WordPress default columns
* @return array The modified columns
*
* @return array
*/
public function modifyColumns($columns)
{
// if user defined set columns, return those
// If user defined set columns, return those.
if (!empty($this->items)) {
return $this->items;
}

// add additional columns
// Add additional columns.
if (!empty($this->add)) {
foreach ($this->add as $key => $label) {
$columns[$key] = $label;
}
}

// unset hidden columns
// Unset hidden columns.
if (!empty($this->hide)) {
foreach ($this->hide as $key) {
unset($columns[$key]);
}
}

// if user has made added custom columns
// If user has made added custom columns.
if (!empty($this->positions)) {
foreach ($this->positions as $key => $position) {
// find index of the element in the array
// Find index of the element in the array.
$index = array_search($key, array_keys($columns));
// retrieve the element in the array of columns
// Retrieve the element in the array of columns.
$item = array_slice($columns, $index, 1);
// remove item from the array
// Remove item from the array.
unset($columns[$key]);

// split columns array into two at the desired position
// Split columns array into two at the desired position.
$start = array_slice($columns, 0, $position, true);
$end = array_slice($columns, $position, count($columns) - 1, true);

// insert column into position
// Insert column into position.
$columns = $start + $item + $end;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function labels(array $labels);
*
* @param array $posttypes An array of post types to register to the taxonomy.
*
* @return PostType\Taxonomy
* @return PostTypes\Taxonomy
*/
public function posttype(array $posttypes);

Expand Down
18 changes: 10 additions & 8 deletions src/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function __construct($names, $options = [], $labels = [])
*
* @param mixed $names A string for the name, or an array of names.
*
* @return $this
* @return PostTypes\PostType
*/
public function names($names)
{
Expand All @@ -125,7 +125,7 @@ public function names($names)
*
* @param array $options An array of options for the PostType.
*
* @return $this
* @return PostTypes\PostType
*/
public function options(array $options)
{
Expand All @@ -139,7 +139,7 @@ public function options(array $options)
*
* @param array $labels An array of labels for the PostType.
*
* @return $this
* @return PostTypes\PostType
*/
public function labels(array $labels)
{
Expand All @@ -153,7 +153,7 @@ public function labels(array $labels)
*
* @param mixed $taxonomies The Taxonomy name(s) to add.
*
* @return $this
* @return PostTypes\PostType
*/
public function taxonomy($taxonomies)
{
Expand All @@ -167,7 +167,7 @@ public function taxonomy($taxonomies)
*
* @param array $filters An array of Taxonomy filters.
*
* @return $this
* @return PostTypes\PostType
*/
public function filters(array $filters)
{
Expand All @@ -177,9 +177,11 @@ public function filters(array $filters)
}

/**
* Set the menu icon for the PostType
* @param string $icon A dashicon class for the menu icon
* @return $this
* Set the menu icon for the PostType.
*
* @param string $icon A dashicon class for the menu icon.
*
* @return PostTypes\PostType
*/
public function icon($icon)
{
Expand Down
1 change: 0 additions & 1 deletion src/Registrars/PostTypeRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,4 @@ public function sortSortableColumns($query)
$query->set('orderby', $meta_value);
}
}

}
5 changes: 4 additions & 1 deletion src/Registrars/TaxonomyRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ public function modifyColumns($columns)
public function populateColumns($content, $column, $term_id)
{
if (isset($this->taxonomy->columns->populate[$column])) {
$content = call_user_func_array($this->taxonomy->columns()->populate[$column], [$content, $column, $term_id]);
$content = call_user_func_array(
$this->taxonomy->columns()->populate[$column],
[$content, $column, $term_id]
);
}

return $content;
Expand Down
8 changes: 4 additions & 4 deletions src/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct($names, $options = [], $labels = [])
*
* @param mixed $names The name(s) for the Taxonomy.
*
* @return $this
* @return PostType\Taxonomy
*/
public function names($names)
{
Expand All @@ -108,7 +108,7 @@ public function names($names)
*
* @param array $options An array of Taxonomy options.
*
* @return $this
* @return PostType\Taxonomy
*/
public function options(array $options = [])
{
Expand All @@ -122,7 +122,7 @@ public function options(array $options = [])
*
* @param array $labels The Taxonomy labels.
*
* @return $this
* @return PostType\Taxonomy
*/
public function labels(array $labels = [])
{
Expand All @@ -136,7 +136,7 @@ public function labels(array $labels = [])
*
* @param mixed $posttypes An array of post types names.
*
* @return $this
* @return PostType\Taxonomy
*/
public function posttype($posttypes)
{
Expand Down

0 comments on commit 702f443

Please sign in to comment.