/** * Add custom image sizes. * * @return \Themosis\Config\Images */ public function make() { // Add registered image sizes. $this->addImages(); // Add sizes to the media attachment settings dropdown list. $this->filter->add('image_size_names_choose', [$this, 'addImagesToDropDownList']); return $this; }
/** * Init the page template module. * * @return \Themosis\Config\Template */ public function make() { // Set an empty value for no templates. $templates = $this->names(); $this->filter->add('theme_page_templates', function ($registeredTemplates) use($templates) { return array_merge($registeredTemplates, $templates); }); return $this; }
/** * Load the widgets. * * @return \Themosis\Load\ILoader */ public function load() { parent::load(); foreach ($this->files as $file) { if (!in_array($file['name'], $this->excludedWidgets)) { $name = $file['name'] . '_Widget'; $this->widgets[] = $name; } } $this->filter->add('widgets_init', [$this, 'install']); return $this; }
/** * Build an Asset instance. * * @param string $type * @param array $args * @param \Themosis\Hook\IHook $action * @param \Themosis\Html\HtmlBuilder $html * @param \Themosis\Hook\IHook $filter */ public function __construct($type, array $args, IHook $action, HtmlBuilder $html, IHook $filter) { $this->type = $type; $this->args = $this->parse($args); $this->key = strtolower(trim($args['handle'])); $this->action = $action; $this->html = $html; $this->filter = $filter; $this->registerInstance(); // Listen to WordPress asset events. $action->add('wp_enqueue_scripts', [$this, 'install']); $action->add('admin_enqueue_scripts', [$this, 'install']); $action->add('login_enqueue_scripts', [$this, 'install']); $action->add('customize_preview_init', [$this, 'install']); }
/** * Register/display taxonomy custom fields. * Can be called without the need to create a custom taxonomy previously (pass taxonomy name as second * parameter to the method). * * @param array $fields A list of custom fields to use. * @param string $taxonomy The taxonomy name used to attach the fields to. * * @return \Themosis\Taxonomy\TaxonomyBuilder */ public function addFields(array $fields, $taxonomy = '') { // Check taxonomy. if (empty($taxonomy) && isset($this->datas['name'])) { $taxonomy = $this->datas['name']; } // Second check if $taxonomy has been omitted. if (empty($taxonomy)) { return $this; } // Save fields with the instance. $this->fields = $fields; /* * Let's initialize term meta... */ $current = current_filter(); if ('init' === $current) { // If inside an `init` action, simply call the method. $this->registerFields(); } else { // Out of an `init` action, call the hook. $this->action->add('init', [$this, 'registerFields']); } /* * Let's add the fields... */ $this->action->add($taxonomy . '_add_form_fields', [$this, 'displayAddFields']); $this->action->add($taxonomy . '_edit_form_fields', [$this, 'displayEditFields']); /* * Let's handle the save... */ $this->action->add('create_' . $taxonomy, [$this, 'save']); $this->action->add('edit_' . $taxonomy, [$this, 'save']); return $this; }
/** * Add settings to the page. Define settings per section * by setting the 'key' name equal to a registered section and * pass it an array of 'settings' fields. * * @param array $settings The page settings. * * @return \Themosis\Page\PageBuilder */ public function addSettings(array $settings = []) { $this->settings = $settings; // Trigger the 'admin_init' action. $this->action->add('admin_init', [$this, 'installSettings']); return $this; }
/** * Handle output of custom statuses to admin JS object. */ protected function exposeStatuses() { $self = $this; $this->filter->add('themosisAdminGlobalObject', function ($data) use($self) { $cpt = new \stdClass(); // Add the defined statuses. $cpt->statuses = $self->status; $data['_themosisPostTypes'][$self->get('name')] = $cpt; return $data; }); }
/** * Register custom fields for users. * * @param array $fields The user custom fields. By sections or not. * @param string $capability The minimum capability required to save user custom fields data. * * @return \Themosis\User\IUser */ public function addFields(array $fields, $capability = 'edit_users') { $this->fields = $fields; $this->capability = $capability; // Check if there are sections before going further. $this->isUsingSections($fields); // User "display" events. // When adding/creating a new user. $this->action->add('user_new_form', [$this, 'displayFields']); // When editing another user profile. $this->action->add('edit_user_profile', [$this, 'displayFields']); // When editing its own profile. $this->action->add('show_user_profile', [$this, 'displayFields']); // User "save" events. $this->action->add('user_register', [$this, 'saveFields']); $this->action->add('profile_update', [$this, 'saveFields']); return $this; }
/** * Map a meta key to a current post data. Be careful as you might override * important post data. Use it with precaution. * * @param array $mappings A list of key/value pairs defining the mappings. Key is the meta_key and its value is the post data name/key. */ public function map(array $mappings) { $this->mappings = $this->parseMappings($mappings); $this->filter->add('wp_insert_post_data', [$this, 'map_metadata'], 10, 2); }