Skip to content

Commit

Permalink
updating enqueue for uses
Browse files Browse the repository at this point in the history
  • Loading branch information
jackabox committed Oct 11, 2017
1 parent a087062 commit 7a73d00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.idea
.DS_Store
135 changes: 5 additions & 130 deletions Framework/Enqueue.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

namespace Billy\Framework;

Expand Down Expand Up @@ -30,15 +30,15 @@ class Enqueue {
public function buildInclude($attrs, $footer)
{
if (isset($attrs['filter']) && !empty($attrs['filter'])) {

$filterBy = key($attrs['filter']);
$filterWith = reset($attrs['filter']);

if (!is_array($filterWith)) {
$filterWith = [$filterWith];
}

if (!$this->filterBy($filterBy, $attrs, $filterWith))
if (!$this->filterBy($filterBy, $attrs, $filterWith))
return;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ protected function filterBy($by, $attrs, $with)
*/
public function admin($attrs, $footer = 'header')
{
add_action('admin_enqueue_scripts', function ($hook) use ($attrs, $footer)
add_action('admin_enqueue_scripts', function ($hook) use ($attrs, $footer)
{
$attrs['hook'] = $hook;
$this->buildInclude($attrs, $this->setFooterFlag($footer));
Expand Down Expand Up @@ -126,129 +126,4 @@ protected function setFooterFlag($footer)
{
return $footer === 'footer';
}

/**
* Filter by Hook (Wordpress standard panels),
* if '*' is provided then pass as this means it
* should work on all admin panels.
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterHook($attrs, $filterWith)
{
$hook = $attrs['hook'];

if ($filterWith[0] === '*')
return true;

return array_search($hook, $filterWith) !== null;
}

/**
* Filter by Page, if '*' is provided then
* check we are on a page before passing.
* Else check all values using 'is_page()'
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterPage($attrs, $filterWith)
{
if ($filterWith[0] === '*' && is_page())
return true;

foreach ($filterWith as $filter) {
if (is_page($filter)) return true;
}

return false;
}

/**
* Filter by Post, if '*' is provided then
* check we are on a single before passing.
* Else check all values using 'is_single()'
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterPost($attrs, $filterWith)
{
if ($filterWith[0] === '*' && is_single())
return true;

foreach ($filterWith as $filter) {
if (is_single($filter))
return true;
}

return false;
}

/**
* Filter by Category, if '*' is provided then
* check we are on a category page before passing.
* Else check all values using 'is_category()'
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterCategory($attrs, $filterWith)
{
if ($filterWith[0] === '*' && is_category())
return true;

foreach ($filterWith as $filter) {
if (is_category($filter))
return true;
}

return false;
}

/**
* Filter by Archive, check if the page is a archive
* using 'is_archive()'.
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterArchive($attrs, $filterWith)
{
return is_archive();
}

/**
* Filter by Search, check if this is a search page
* using 'is_search()'.
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterSearch($attrs, $filterWith)
{
return is_search();
}

/**
* Filter by Post Type, check all values using
* 'get_post_type()'. Select all '*' is not
* supported. In that case you 'filterPost'
*
* @param $attrs
* @param $filterWith
* @return bool
*/
public function filterPostType($attrs, $filterWith)
{
return array_search(get_post_type(), $filterWith) !== null;
}

}
}

0 comments on commit 7a73d00

Please sign in to comment.