-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,413 additions
and
937 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
trait zusnippets_Classes { | ||
|
||
// Classes manipulations --------------------------------------------------] | ||
|
||
public function split_classes($classes, $as_is = false) { | ||
$classes = is_array($classes) ? $classes : preg_split('/[\s,]+/', $classes); | ||
$classes = array_map('trim', $classes); | ||
return $as_is ? $classes : array_unique(array_filter($classes)); | ||
} | ||
|
||
public function merge_classes($classes, $join = true) { | ||
$classes = $this->split_classes($classes, $join ? false : true); | ||
return $join ? implode(' ', $classes) : $classes; | ||
} | ||
|
||
public function remove_classes($classes, $remove = [], $join = true) { | ||
$classes = $this->split_classes($classes); | ||
foreach($remove as $test) if(in_array($test, $classes)) unset($classes[array_search($test, $classes)]); | ||
return $join ? implode(' ', $classes) : $classes; | ||
} | ||
|
||
public function add_body_class($my_classes, $prefix = '') { | ||
add_filter('body_class', function($classes) use ($my_classes, $prefix) { | ||
$my_classes = $this->prefix_an_clean_class($classes, $my_classes, $prefix); | ||
$classes[] = $this->merge_classes($my_classes); | ||
return array_filter($classes); | ||
}); | ||
} | ||
|
||
public function add_admin_body_class($my_classes, $prefix = '') { | ||
add_filter('admin_body_class', function($classes) use ($my_classes, $prefix) { | ||
$classes = $this->split_classes($classes); | ||
$my_classes = $this->prefix_an_clean_class($classes, $my_classes, $prefix); | ||
return $this->merge_classes(array_merge($classes, array_filter($my_classes))); | ||
}); | ||
} | ||
|
||
private function prefix_an_clean_class($classes, $my_classes, $prefix) { | ||
$my_classes = $this->split_classes($my_classes); | ||
// add prefix to all classes | ||
if(!empty($prefix)) $my_classes = preg_filter('/^/', $prefix, $my_classes); | ||
// remove all already existing classes | ||
return $this->remove_classes($my_classes, $classes, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.