Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/monara/public_html/test.athavaneng.com/themes.php on line 99
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 226
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 227
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 228
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 229
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 230
Warning: Cannot modify header information - headers already sent by (output started at /home/monara/public_html/test.athavaneng.com/themes.php:1) in /home/monara/public_html/test.athavaneng.com/themes.php on line 231
src/Auth/Roles.php 0000644 00000010556 15073230240 0010034 0 ustar 00 role_objects;
$names = wp_roles()->role_names;
return array_map(function($role, $name) {
/** @var $role \WP_Role */
return [ 'name' => $role->name, 'capabilities' => $role->capabilities, 'label' => $name ];
}, $objects, $names);
}
/**
* @return array
*/
public function capabilities()
{
$roles = wp_roles()->role_objects;
$capabilities = [];
foreach ($roles as $role) {
foreach ($role->capabilities as $cap => $value) {
$capabilities[$cap][] = $role->name;
}
}
return $capabilities;
}
/**
* @return array[]
*/
public function getEditableRoles()
{
return get_editable_roles();
}
/**
* @param string $role
* @param array $capabilities
* @param null|string $label
*
* @return $this
*/
public function add($role, array $capabilities, $label = null)
{
wp_roles()->add_role($role, $label ?? Str::makeWords($role, true), $capabilities);
return $this;
}
/**
* @param string $role
*
* @return $this
* @throws \Exception
*/
public function remove($role)
{
if(in_array($role, $this->guardRoles)) {
throw new \Exception('Can not delete guarded role: ' . $role);
}
wp_roles()->remove_role($role);
return $this;
}
/**
* @param $role
*
* @return bool
*/
public function exists($role)
{
return wp_roles()->is_role($role);
}
/**
* @param $role
*
* @return \WP_Role|null
*/
public function get($role)
{
return wp_roles()->get_role($role);
}
/**
* @param string $role
* @param array $capabilities
* @param bool $remove
*
* @return \WP_Role|null
*/
public function updateRolesCapabilities($role, array $capabilities, $remove = false)
{
$role = wp_roles()->get_role($role);
if($role instanceof \WP_Role) {
foreach ($capabilities as $capability) {
if($remove) {
$role->remove_cap($capability);
} else {
$role->add_cap($capability);
}
}
}
return $role;
}
/**
* Get Post Type Capabilities
*
* @param string $singular
* @param string $plural
*
* @return array
*/
public function getCustomPostTypeCapabilities($singular = 'post', $plural = 'posts')
{
return [
'edit_post' => "edit_$singular",
'read_post' => "read_$singular",
'delete_post' => "delete_$singular",
'edit_posts' => "edit_$plural",
'edit_others_posts' => "edit_others_$plural",
'publish_posts' => "publish_$plural",
'read_private_posts' => "read_private_$plural",
'read' => "read",
'delete_posts' => "delete_$plural",
'delete_private_posts' => "delete_private_$plural",
'delete_published_posts' => "delete_published_$plural",
'delete_others_posts' => "delete_others_$plural",
'edit_private_posts' => "edit_private_$plural",
'edit_published_posts' => "edit_published_$plural",
'create_posts' => "create_$plural",
];
}
/**
* @param string $singular
* @param string $plural
*
* @return string[]
*/
public function getTaxonomyCapabilities($singular = 'term', $plural = 'terms')
{
return [
'manage_terms' => 'manage_' . $plural,
'edit_terms' => 'edit_' . $plural,
'delete_terms' => 'delete_' . $plural,
'assign_terms' => 'assign_' . $plural,
];
}
/**
* @param mixed ...$args
*
* @return static
*/
public static function new(...$args)
{
return new static(...$args);
}
} src/Auth/Policy.php 0000644 00000000314 15073230240 0010176 0 ustar 00 user = $user;
}
} src/Html/Html.php 0000644 00000024465 15073230240 0007663 0 ustar 00 getString();
}
/**
* Get string of tag
*
* @return string
*/
protected function getString(): string
{
return $this->tag->getString();
}
/**
* Create new Tag
*
* @param string $tag
* @param array|string|null $attributes
* @param string|array|null $text
*
* @return $this
*/
protected function el($tag, $attributes = null, $text = null )
{
$this->tag = new Tag( $tag, $attributes, $text );
return $this;
}
/**
* Create Form
*
*
* @param $action
* @param string $method
* @param array|string $attributes
* @param null|string $text
*
* @return $this
*/
protected function form($action, $method = 'GET', $attributes = null, $text = null)
{
if(is_string($attributes) || is_numeric($attributes)) {
$text = $text ?? $attributes;
$attributes = [];
}
$attributes = $attributes ?? [];
$attributes = array_merge( ['action' => $action, 'method' => $method], $attributes );
$this->tag = new Tag( 'form', $attributes, $text );
return $this;
}
/**
* Create new link
*
* @param string|array $text
* @param string $url
* @param array $attributes
*
* @return $this
*/
protected function a($text = '', $url = '#', array $attributes = [])
{
$attributes = array_merge( array_filter(['href' => $url], '\TypeRocket\Utility\Str::notBlank'), $attributes );
$this->tag = new Tag( 'a', $attributes, $text );
return $this;
}
/**
* Create new image
*
* @param string $src
* @param array $attributes
*
* @return $this
*/
protected function img($src = '', array $attributes = [])
{
$attributes = array_merge( ['src' => $src], $attributes );
$this->tag = new Tag( 'img', $attributes );
return $this;
}
/**
* Create new input
*
* @param string $type
* @param string $name
* @param string $value
* @param array $attributes
*
* @return $this
*/
protected function input($type, $name, $value, array $attributes = [])
{
$defaults = array_filter(['type' => $type, 'name' => $name, 'value' => $value], '\TypeRocket\Utility\Str::notBlank');
$this->tag = new Tag( 'input', array_merge( $defaults, $attributes ) );
return $this;
}
/**
* Append inside of tag
*
* @param string|Tag|Html|array $tag
*
* @return $this
*/
protected function nest($tag)
{
$this->tag->nest( $tag );
return $this;
}
/**
* Prepend Inside of tag
*
* @param string|Tag|Html $tag
*
* @return $this
*/
protected function nestAtTop($tag)
{
$this->tag->nestAtTop( $tag );
return $this;
}
/**
* Tag
*
* @return Tag
*/
protected function tag()
{
return $this->tag;
}
/**
* @param $name
* @param $arguments
* @return Html|string
*/
public function __call($name, $arguments)
{
if(method_exists($this, $name)) {
return $this->{$name}(...$arguments);
}
return $this->el($name, ...$arguments);
}
/**
* @param $name
* @param $arguments
* @return Html
*/
public static function __callStatic($name, $arguments)
{
return (new static)->{$name}(...$arguments);
}
}
src/Html/Tag.php 0000644 00000006675 15073230240 0007475 0 ustar 00 tag = $tag;
$this->attrReset( $attributes );
$this->nest($nest);
if( in_array($this->tag, ['img', 'br', 'hr', 'input']) ) {
$this->closed = true;
}
return $this;
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getString();
}
/**
* Get string
*
* @return string
*/
public function getString(): string {
return $this->open().$this->inner().$this->close();
}
/**
* Create Tag
*
* @param string $tag
* @param array|string|null $attributes
* @param string|array|null $nest
*
* @return $this
*/
public static function el($tag, $attributes = null, $nest = null )
{
return new static( $tag, $attributes, $nest );
}
/**
* Append Inner Tag
*
* @param string|Tag|Html|array $tag
*
* @return $this
*/
public function nest($tag)
{
if(is_array($tag)) {
foreach ($tag as $t) {
array_push($this->nest, $t);
}
} else {
array_push($this->nest, $tag);
}
return $this;
}
/**
* Prepend inner tag
*
* @param Tag|Html|string|array $tag
*
* @return $this
*/
public function nestAtTop( $tag )
{
if(is_array($tag)) {
foreach ($tag as $t) {
array_unshift($this->nest, $t);
}
} else {
array_unshift($this->nest, $tag);
}
return $this;
}
/**
* Get the opening tag in string form
*
* @return string
*/
public function open() {
$openTag = "<{$this->tag}";
foreach($this->attr as $attribute => $value) {
$value = esc_attr($value);
$value = $value !== '' ? "=\"{$value}\"" : '';
$openTag .= " {$attribute}{$value}";
}
$openTag .= $this->closed ? " />" : ">";
return $openTag;
}
/**
* Get the closing tag as string
*
* @return string
*/
public function close() {
return $this->closed ? '' : "{$this->tag}>";
}
/**
* Get the string with inner HTML
*
* @return string
*/
public function inner() {
$html = '';
if( ! $this->closed ) {
foreach($this->nest as $tag) {
$html .= (string) $tag;
}
}
return $html;
}
/**
* @param string $tag
* @param null|array $attributes
* @param string|Tag|Html|array $nest
*
* @return static
*/
public static function new(string $tag, $attributes = null, $nest = null)
{
return new static(...func_get_args());
}
}
src/Html/Element.php 0000644 00000002314 15073230240 0010335 0 ustar 00 'tr-headline'], $attributes));
$tag->nest([
$icon ? "{$icon}" : null,
"" . esc_html($title) . ''
]);
return $tag;
}
/**
* Accessible Close Button
*
* @param array $attributes
* @param string $text close button symbol
*
* @return Tag
*/
public static function controlButton(array $attributes = [], $text = '×') {
$static = ['type' => 'button'];
$tag = new Tag( 'button', array_merge(['aria-label' => __('Close', 'typerocket-domain')], $attributes, $static) );
$tag->nest("{$text}");
return $tag;
}
} src/Register/Registrable.php 0000644 00000015522 15073230240 0012074 0 ustar 00 id = Sanitize::underscore($id);
$this->isReservedId();
return $this;
}
/**
* @return int
*/
public function getMaxIdLength()
{
return $this->maxIdLength;
}
/**
* Get the ID
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set Arguments
*
* @param array $args
*
* @return $this
*/
public function setArguments(array $args)
{
$this->args = $args;
return $this;
}
/**
* Get Arguments
*
* @return array
*/
public function getArguments()
{
return $this->args;
}
/**
* Get Argument by key
*
* @param string $key
*
* @return string|array
*/
public function getArgument($key)
{
if ( ! array_key_exists($key, $this->args)) {
return null;
}
return $this->args[$key];
}
/**
* Set Argument by key
*
* @param string $key
* @param string|array $value
*
* @return $this
*/
public function setArgument($key, $value)
{
$this->args[$key] = $value;
return $this;
}
/**
* Remove Argument by key
*
* @param string $key
*
* @return $this
*/
public function removeArgument($key)
{
if (array_key_exists($key, $this->args)) {
unset($this->args[$key]);
}
return $this;
}
/**
* Check If Reserved
*/
protected function isReservedId()
{
if (in_array($this->id, $this->reservedNames)) {
$exception = sprintf(__('You can not register a post type or taxonomy using the WordPress reserved name "%s".', 'typerocket-domain'), $this->id);
Notice::admin(['type' => 'error', 'message' => $exception]);
$this->blocked = true;
return true;
}
return false;
}
/**
* @return bool
*/
public function isBlocked()
{
return $this->blocked;
}
/**
* Use other Registrable objects or string IDs
*
* @param array|MetaBox|PostType|Taxonomy|Page $args variadic
*
* @return $this
* @throws \Exception
*/
public function apply($args)
{
if ( ! is_array($args)) {
$args = func_get_args();
}
if ( ! empty($args) && is_array($args)) {
$this->use = array_merge($this->use, $args);
}
$this->uses();
return $this;
}
/**
* Add Registrable to the registry
*
* @return $this
*/
public function addToRegistry()
{
if(!$this->blocked) {
Registry::addRegistrable($this);
}
return $this;
}
/**
* @param mixed ...$args
*
* @return static
*/
public static function add(...$args)
{
return (new static(...$args))->addToRegistry();
}
/**
* Register with WordPress
*
* Override this in concrete classes
*
* @return $this
*/
abstract public function register();
/**
* Used with the apply method to connect Registrable objects together.
* @throws \Exception
*/
protected function uses()
{
foreach ($this->use as $obj) {
if ($obj instanceof Registrable) {
$class = get_class($obj);
$class = substr(strrchr($class, "\\"), 1);
$method = 'add' . $class;
if (method_exists($this, $method)) {
$this->$method($obj);
} else {
$current_class = get_class($this);
throw new \Exception('TypeRocket: You are passing the unsupported object ' . $class . ' into ' . $current_class . '.');
}
}
}
}
/**
* @param string $id the registered ID
*
* @return Registrable|PostType|Page|Taxonomy|MetaBox
* @throws \Exception
*/
public function getAppliedById($id)
{
foreach ($this->use as $obj) {
if ($obj instanceof Registrable) {
if($obj->getId() === $id) {
return $obj;
}
}
}
throw new \Exception('TypeRocket: Registrable object of ID ' . $id . ' not found.');
}
/**
* Get the Use
*
* @return array
*/
public function getApplied()
{
return $this->use;
}
/**
* @param mixed ...$args
*
* @return static
*/
public static function new(...$args)
{
return new static(...$args);
}
}
src/Register/Taxonomy.php 0000644 00000032403 15073230240 0011444 0 ustar 00 applyQuickLabels($labelSingular, $labelPlural, $keep_case);
}
$existing = get_taxonomy( $id );
if ($existing) {
$this->existing = $existing;
$singular = Sanitize::underscore( $singular );
$plural = Sanitize::underscore( $plural );
$this->id = $this->existing->name;
$args = (array) $this->existing;
$this->resource = Registry::getTaxonomyResource($this->id) ?? [
'singular' => $singular,
'plural' => $plural,
'model' => null,
'controller' => null
];
$this->postTypes = $this->existing->object_type;
$this->args = array_merge($args, $this->args, $settings);
return $this;
}
// setup object for later use
$plural = Sanitize::underscore( $plural );
$singular = Sanitize::underscore( $singular );
// obj is set on registration
$this->resource = [
'singular' => $singular,
'plural' => $plural,
'model' => null,
'controller' => null
];
$this->setId($this->id ?: ($id ?? $singular));
if (array_key_exists( 'capabilities', $settings ) && $settings['capabilities'] === true) :
$settings['capabilities'] = (new Roles)->getTaxonomyCapabilities($singular, $plural);
endif;
$defaults = [
'show_admin_column' => false,
'rewrite' => ['slug' => Sanitize::dash( $plural )],
];
$this->args = array_merge( $this->args, $defaults, $settings );
if(class_exists( $model = \TypeRocket\Utility\Helper::modelClass($singular, false) ) ) {
$this->setModelClass($model);
}
return $this;
}
/**
* Set Model Class
*
* @param string $modelClass
*
* @return $this
*/
public function setModelClass(string $modelClass)
{
$this->modelClass = $modelClass;
// Default resource model is not the same as the modelClass
$this->resource['model'] = $this->modelClass;
return $this;
}
/**
* Get Model Class
*
* @return string
*/
public function getModelClass()
{
return $this->modelClass;
}
/**
* Use Custom Capabilities
*
* @return Taxonomy $this
*/
public function customCapabilities()
{
$cap = (new Roles)->getTaxonomyCapabilities($this->resource['singular'], $this->resource['plural']);
return $this->setArgument('capabilities', $cap);
}
/**
* Apply Quick Labels
*
* @param string $singular
* @param string $plural
* @param bool $keep_case
* @return Taxonomy $this
*/
public function applyQuickLabels($singular, $plural = null, $keep_case = false)
{
if(!$plural) { $plural = Inflect::pluralize($singular); }
// make lowercase
$upperPlural = $keep_case ? $plural : Str::uppercaseWords( $plural );
$upperSingular = $keep_case ? $singular : Str::uppercaseWords( $singular );
$lowerPlural = $keep_case ? $plural : mb_strtolower( $plural );
$context = 'taxonomy:' . $this->getId();
$labels = [
'add_new_item' => sprintf( _x( 'Add New %s', $context, 'typerocket-core' ), $upperSingular),
'add_or_remove_items' => sprintf( _x( 'Add or remove %s', $context, 'typerocket-core' ), $lowerPlural),
'all_items' => sprintf( _x( 'All %s', $context, 'typerocket-core' ), $upperPlural),
'back_to_items' => sprintf( _x( '← Back to %s', $context, 'typerocket-core' ), $lowerPlural),
'choose_from_most_used' => sprintf( _x( 'Choose from the most used %s', $context, 'typerocket-core' ), $lowerPlural),
'edit_item' => sprintf( _x( 'Edit %s', $context, 'typerocket-core' ), $upperSingular),
'name' => sprintf( _x( '%s', $context . ':taxonomy general name', 'typerocket-core' ), $upperPlural),
'menu_name' => sprintf( _x( '%s', $context . ':admin menu', 'typerocket-core' ), $upperPlural),
'new_item_name' => sprintf( _x( 'New %s Name', $context, 'typerocket-core' ), $upperSingular),
'no_terms' => sprintf( _x( 'No %s', $context, 'typerocket-core' ), $lowerPlural),
'not_found' => sprintf( _x( 'No %s found.', $context, 'typerocket-core' ), $lowerPlural),
'parent_item' => sprintf( _x( 'Parent %s', $context, 'typerocket-core' ), $upperSingular),
'parent_item_colon' => sprintf( _x( 'Parent %s:', $context, 'typerocket-core' ), $upperSingular),
'popular_items' => sprintf( _x( 'Popular %s', $context, 'typerocket-core' ), $upperPlural),
'search_items' => sprintf( _x( 'Search %s', $context, 'typerocket-core' ), $upperPlural),
'separate_items_with_commas' => sprintf( _x( 'Separate %s with commas', $context, 'typerocket-core' ), $lowerPlural),
'singular_name' => sprintf( _x( '%s', $context . ':taxonomy singular name', 'typerocket-core' ), $upperSingular),
'update_item' => sprintf( _x( 'Update %s', $context, 'typerocket-core' ), $upperSingular),
'view_item' => sprintf( _x( 'View %s', $context, 'typerocket-core' ), $upperSingular),
];
return $this->setLabels($labels, $upperPlural, false);;
}
/**
* Set Labels
*
* @param array $labels
* @param string $plural
* @param bool $merge
*
* @return Taxonomy $this
*/
public function setLabels(array $labels, $plural = null, $merge = true)
{
$this->args['labels'] = $merge ? array_merge($this->args['labels'] ?? [], $labels) : $labels;
$this->args['label'] = $plural ?? $this->args['label'];
return $this;
}
/**
* Set Hierarchical
*
* @param bool $bool
*
* @return Taxonomy $this
*/
public function setHierarchical($bool = true)
{
return $this->setArgument('hierarchical', $bool);
}
/**
* Get Existing Post Type
*
* @return \WP_Taxonomy|null
*/
public function getExisting()
{
return $this->existing;
}
/**
* Set the rewrite slug for the post type
*
* @param string $slug
* @param null|bool $withFront
*
* @return Taxonomy $this
*/
public function setSlug( $slug, $withFront = null )
{
if(!is_array($this->args['rewrite'])) {
$this->args['rewrite'] = [];
}
$this->args['rewrite']['slug'] = Sanitize::dash( $slug );
if(isset($withFront)) {
$this->args['rewrite']['with_front'] = $withFront;
}
return $this;
}
/**
* Disable Slug With Front
*
* @return $this
*/
public function disableSlugWithFront()
{
$this->args['rewrite']['with_front'] = false;
return $this;
}
/**
* Enable Hierarchical Rewrite
*
* @return $this
*/
public function enableHierarchicalSlug()
{
$this->args['rewrite']['hierarchical'] = true;
return $this;
}
/**
* Set the resource
*
* @param array $resource
*
* @return Taxonomy $this
*/
public function setResource( array $resource )
{
$this->resource = $resource;
return $this;
}
/**
* Get the form hook value by key
*
* @return mixed
*/
public function getMainForm()
{
return $this->form['main'] ?? null;
}
/**
* Set the form main hook
*
* From hook to be added just above the title field
*
* @param bool|true|callable $value
*
* @return Taxonomy $this
*/
public function setMainForm( $value = true )
{
if (is_callable( $value )) {
$this->form['main'] = $value;
} else {
$this->form['main'] = true;
}
return $this;
}
/**
* Get the slug
*
* @return mixed
*/
public function getSlug()
{
return $this->args['rewrite']['slug'];
}
/**
* Show Quick Edit
*
* @param bool $bool
*
* Whether to show the taxonomy in the quick/bulk edit panel.
*
* @return Taxonomy
*/
public function showQuickEdit($bool = true)
{
return $this->setArgument('show_in_quick_edit', $bool);
}
/**
* Show Post Type Admin Column
*
* Whether to allow automatic creation of taxonomy columns on associated post-types table.
*
* @param bool $bool
*
* @return Taxonomy
*/
public function showPostTypeAdminColumn($bool = true)
{
return $this->setArgument('show_admin_column', $bool);
}
/**
* @param bool|string $rest_base the REST API base path
* @param null|string $controller the REST controller default is \WP_REST_Terms_Controller::class
*
* @return Taxonomy $this
*/
public function setRest( $rest_base = false, $controller = null )
{
$this->args['rest_base'] = $rest_base ? $rest_base : $this->id;
$this->args['show_in_rest'] = true;
$controller ? $this->args['rest_controller_class'] = $controller : null;
return $this;
}
/**
* Set the taxonomy to only show in WordPress Admin
*
* @return Taxonomy $this
*/
public function setAdminOnly() {
$this->args['public'] = false;
$this->args['show_ui'] = true;
$this->args['show_in_nav_menus'] = true;
return $this;
}
/**
* Hide Frontend
*
* @param bool $bool
*
* @return $this
*/
public function hideFrontend($bool = true)
{
$this->args['publicly_queryable'] = !$bool;
return $this;
}
/**
* Hide Admin
*
* @return Taxonomy $this
*/
public function hideAdmin()
{
$this->args['show_ui'] = false;
$this->args['show_in_menu'] = false;
$this->args['show_in_nav_menus'] = false;
return $this;
}
/**
* Register the taxonomy with WordPress
*
* @return Taxonomy $this
*/
public function register()
{
if(!$this->existing) {
if($this->isReservedId()) {
return $this;
}
}
do_action('typerocket_register_taxonomy_' . $this->id, $this );
register_taxonomy( $this->id, $this->postTypes, $this->args );
$this->resource['object'] = $this;
Registry::addTaxonomyResource($this->id, $this->resource);
$this->attachHooks();
return $this;
}
/**
* Apply post types
*
* @param string|PostType|array $s
*
* @return Taxonomy $this
*/
public function addPostType( $s )
{
if ($s instanceof PostType) {
$s = $s->getId();
} elseif (is_array( $s )) {
foreach ($s as $n) {
$this->addPostType( $n );
}
}
if ( is_string($s) && ! in_array( $s, $this->postTypes )) {
$this->postTypes[] = $s;
}
return $this;
}
/**
* Attach Hooks
*/
public function attachHooks()
{
if(!$this->hooksAttached) {
Registry::taxonomyHooks($this);
$this->hooksAttached = true;
}
}
}
src/Register/Registry.php 0000644 00000053435 15073230240 0011446 0 ustar 00 ['singular' => 'post', 'plural' => 'posts', 'controller' => null, 'object' => null, 'model' => null],
'page' => ['singular' => 'page', 'plural' => 'pages', 'controller' => null, 'object' => null, 'model' => null],
];
public static $taxonomies = [
'category' => ['singular' => 'category', 'plural' => 'categories', 'controller' => null, 'object' => null, 'model' => null],
'post_tag' => ['singular' => 'tag', 'plural' => 'tags', 'controller' => null, 'object' => null, 'model' => null]
];
public static $customs = [];
/**
* Add a post type resource
*
* @param string $id post type id
* @param array $resource resource name ex. posts, pages, books
*/
public static function addPostTypeResource($id, $resource = []) {
self::$postTypes[$id] = array_pad($resource, 5, null);
}
/**
* Get the post type resource
*
* @param string $id
*
* @return null
*/
public static function getPostTypeResource($id) {
return ! empty(self::$postTypes[$id]) ? self::$postTypes[$id] : null;
}
/**
* Get the taxonomy resource
*
* @param string $id
*
* @return null
*/
public static function getTaxonomyResource($id) {
return ! empty(self::$taxonomies[$id]) ? self::$taxonomies[$id] : null;
}
/**
* Add a taxonomy resource
*
* @param string $id post type id
* @param array $resource resource name ex. posts, pages, books
*/
public static function addTaxonomyResource($id, $resource = []) {
self::$taxonomies[$id] = array_pad($resource, 5, null);
}
/**
* Add a custom resource
*
* @param string $id custom resource id
* @param array $resource resource name ex. posts, pages, books
*/
public static function addCustomResource($id, $resource = []) {
self::$customs[$id] = array_pad($resource, 3, null);
}
/**
* Get the custom resource
*
* @param string $id
*
* @return null
*/
public static function getCustomResource($id) {
return self::$customs[$id] ?? null;
}
/**
* Add Registrable objects to collection
*
* @param null|Registrable|string $obj
*/
public static function addRegistrable( $obj = null )
{
if ( $obj instanceof Registrable) {
self::$collection[] = $obj;
}
}
/**
* Loop through each Registrable and add hooks automatically
*/
public static function initHooks()
{
$collection = [];
$later = [];
if(empty(self::$collection)) {
return;
}
foreach(self::$collection as $obj) {
if ( $obj instanceof Registrable) {
$collection[] = $obj;
$use = $obj->getApplied();
foreach($use as $objUsed) {
if( ! in_array($objUsed, $collection) && ! $objUsed instanceof Page) {
$later[] = $obj;
array_pop($collection);
break 1;
}
}
if ($obj instanceof Page && ! empty( $obj->getParent() ) ) {
$later[] = $obj;
array_pop($collection);
}
}
}
$collection = array_merge($collection, $later);
foreach ($collection as $obj) {
if ($obj instanceof Taxonomy) {
add_action( 'init', [$obj, 'register']);
} elseif ($obj instanceof PostType) {
/** @var PostType $obj */
add_action( 'init', [$obj, 'register']);
} elseif ($obj instanceof MetaBox) {
add_action( 'admin_init', [$obj, 'register']);
add_action( 'add_meta_boxes', [$obj, 'register']);
} elseif ($obj instanceof Page) {
if($obj->getHandler()) {
add_action( 'admin_init', [$obj, 'respond']);
}
add_action( 'admin_menu', [$obj, 'register']);
}
}
add_action( 'init', function() {
self::setAggregatePostTypeHooks();
}, 12);
}
/**
* Taxonomy Hooks
*
* @param Taxonomy $obj
*/
public static function taxonomyHooks(Taxonomy $obj)
{
self::taxonomyFormContent($obj);
if($custom_templates = $obj->getTemplates()) {
foreach(['taxonomy', 'category', 'tag'] as $template_hook) {
add_filter($template_hook . '_template', Closure::bind(function($template) use ($custom_templates) {
/** @var WP_Term $term */
$term = get_queried_object();
if($term->taxonomy == $this->getId()) {
$template = $custom_templates['archive'];
}
return $template;
}, $obj), 0, 1);
}
}
}
/**
* Post Type Hooks
*
* @param PostType $obj
*/
public static function postTypeHooks(PostType $obj)
{
if (is_string( $obj->getTitlePlaceholder() )) {
add_filter( 'enter_title_here', function($title) use ($obj) {
global $post;
if(!empty($post)) {
if ( $post->post_type == $obj->getId() ) {
return $obj->getTitlePlaceholder();
}
}
return $title;
} );
}
if( !empty($obj->getArchiveQuery()) ) {
add_action('pre_get_posts', Closure::bind(function( WP_Query $main_query ) {
/**
* @var PostType $this
*/
if(!$main_query->is_main_query() || $main_query->is_admin) {
return;
}
$isTax = false;
$id = $this->getId();
if($this->getArchiveQueryWithTaxonomies() && !empty($main_query->tax_query->queries)) {
$taxonomyList = get_object_taxonomies($id);
foreach($taxonomyList as $taxonomy){
if($taxonomy == 'category' && $main_query->is_category()) {
$isTax = true;
break;
}
elseif($taxonomy == 'post_tag' && $main_query->is_tag()) {
$isTax = true;
break;
}
elseif($main_query->is_tax($taxonomy)){
$isTax = true;
break;
}
}
}
if($main_query->is_post_type_archive($id) || $isTax) {
$query = $this->getArchiveQuery();
foreach ($query as $key => $value) {
$main_query->set($key, $value);
}
}
}, $obj));
}
if($custom_templates = $obj->getTemplates()) {
foreach(['single', 'archive', 'page'] as $template_hook) {
if(!empty($custom_templates[$template_hook])) {
add_filter($template_hook . '_template', Closure::bind(function($template, $type) use ($custom_templates) {
/** @var WP_Post $post */
global $post;
if($post->post_type == $this->getId()) {
$template = $custom_templates[$type];
}
return $template;
}, $obj), 0, 2);
}
}
}
if(!empty($obj->getSaves())) {
add_action('save_post', function ($id, $post) use ($obj) {
if(
$post->post_type != $obj->getId() ||
wp_is_post_revision($id) ||
$post->post_status == 'auto-draft' ||
$post->post_status == 'trash'
) { return; }
global $wpdb;
$saves = $obj->getSaves();
$class = $obj->getModelClass();
$model = (new $class)->wpPost($post, true)->load('meta');
$fields = [];
foreach ($saves as $field => $fn) {
$value = $fn($model);
$value = sanitize_post_field($field, $value, $id, 'db' );
$fields[$field] = $value;
}
$wpdb->update( $wpdb->posts, $fields, ['ID' => $id]);
}, 11, 2);
}
if(!is_null($obj->getRevisions())) {
add_filter( 'wp_revisions_to_keep', function($num, $post) use ($obj) {
if ( $post->post_type == $obj->getId() ) {
return $obj->getRevisions();
}
return $num;
}, 10, 2 );
}
if($obj->getRootSlug()) {
self::$aggregateCollection['post_type']['root_slug'][] = $obj->getId();
}
if($obj->getForceDisableGutenberg()) {
self::$aggregateCollection['post_type']['use_gutenberg'][] = $obj->getId();
}
self::setPostTypeColumns($obj);
self::postTypeFormContent($obj);
}
/**
* Add taxonomy form hooks
*
* @param Taxonomy $obj
*/
public static function taxonomyFormContent( Taxonomy $obj ) {
$callback = function( $term, $obj )
{
/** @var Taxonomy $obj */
if ( $term == $obj->getId() || $term->taxonomy == $obj->getId() ) {
$func = 'add_form_content_' . $obj->getId() . '_taxonomy';
$form = $obj->getMainForm();
if (is_callable( $form )) {
call_user_func( $form, $term );
} elseif (function_exists( $func )) {
call_user_func( $func, $term );
} elseif ( Config::get('app.debug') ) {
echo "
Add content here by defining: function {$func}() {}
";
}
}
};
if ($obj->getMainForm()) {
add_action( $obj->getId() . '_edit_form', function($term) use ($obj, $callback) {
echo BaseForm::nonceInput('hook');
echo '