/** * Delete post from Elastica Client. * * @param object $post Post to delete * * @since 3.0.0 */ public function postDelete($post) { //Get configs $ctn = $this->getConfig(); //Check post integrity if (null == $post || !in_array($post->post_type, $ctn['posttypes'])) { return; } //Get index $index = $this->getIndex(); //Get type $type = $index->getType($post->post_type); //Try to delete post try { //Delete post by its ID $type->deleteById($post->ID); //Update counter $index = Search::getIndex(); $count = TeaThemeOptions::getConfigs($index . '-count'); $count = empty($count) ? 0 : $count[0] - 1; //Save in DB TeaThemeOptions::setConfigs($index . '-count', $count); } catch (NotFoundException $ex) { } }
/** * Build terms. * * @param array $terms Contains all terms. * @uses add_action() * * @since 3.3.6 */ public function setTerms($terms) { $this->terms = $terms; //Add WP Hooks add_action('init', function () { //Check post types if (empty($this->terms)) { return; } //Register post type foreach ($this->terms as $term) { $t = $this->registerTerm($term); if (empty($t) || empty($t[0])) { unset($this->terms[$term['slug']]); continue; } //Get all admin details if (TTO_IS_ADMIN) { //Display custom fields add_action($t[1] . '_edit_form_fields', array(&$this, 'hookFieldsDisplay'), 10, 1); //add_action($t[1].'_add_form_fields', array(&$this, 'hookFieldsDisplay'), 10, 1); //Save custom fields add_action('created_' . $t[1], array(&$this, 'hookFieldsSave'), 10, 2); add_action('edited_' . $t[1], array(&$this, 'hookFieldsSave'), 10, 2); //Display custom columns add_filter('manage_edit-' . $t[1] . '_columns', array(&$this, 'hookColumns'), 10); add_filter('manage_' . $t[1] . '_custom_column', array(&$this, 'hookCustomColumn'), 11, 3); //Special case: single choice on post edit page if (isset($term['choice']) && 'single' === $term['choice']) { //Define slug $termslug = $t[1]; //Apply filter add_filter('wp_terms_checklist_args', function ($args, $post_id) use($termslug) { //Check taxonomy if (isset($args['taxonomy']) && $termslug === $args['taxonomy']) { $args['walker'] = new WalkerSingle(); $args['popular_cats'] = array(); $args['checked_ontop'] = false; } return $args; }, 10, 2); } } $this->terms[$term['slug']] = $t[0]; } //Admin panel if (TTO_IS_ADMIN) { //Update DB TeaThemeOptions::setConfigs(Engine::getIndex(), $this->terms); //Flush all rewrite rules //flush_rewrite_rules(); } }, 10, 1); }
/** * Register $_POST and $_FILES into transients. * * @uses wp_handle_upload() * @param array $request Contains all data in $_REQUEST * @param array $files Contains all data in $_FILES * * @since 3.3.0 */ protected function updateSettings($request, $files) { //Admin panel if (!TTO_IS_ADMIN) { return; } //Check request if (empty($request)) { return; } //Set all options foreach ($request as $k => $v) { //Don't register this default value if (in_array($k, array('do', 'from', 'updated', 'submit'))) { continue; } //Check the key for special "NONE" value $v = 'NONE' == $v || empty($v) ? '' : $v; //Check settings if (preg_match('/^tto-configs-/', $k)) { $k = str_replace('tto-configs-', '', $k); TeaThemeOptions::setConfigs($k, $v); } else { /** * Fires for each data saved in DB. * * @param string $k Option's name * @param string $v Option's value * * @since 3.3.0 */ do_action('tto_action_update_settings', $k, $v); //Register option TeaThemeOptions::setOption($k, $v); } } //Check if files are attempting to be uploaded if (!empty($files)) { //Get required files require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; //Set all URL in transient foreach ($files as $k => $v) { //Don't do nothing if no file is defined if (empty($v['tmp_name'])) { continue; } //Do the magic $file = wp_handle_upload($v, array('test_form' => false)); //Register option and transient TeaThemeOptions::setOption($k, $file['url']); } } //Notify TeaThemeOptions::notify('updated', TeaThemeOptions::__('The Tea Theme Options is updated.')); }
/** * Build post types. * * @param array $pts Contains all post types. * @uses add_action() * * @since 3.3.6 */ public function setPostTypes($pts) { //Define post types $this->posttypes = $pts; //Add WP Hooks add_action('init', function () { //Check post types if (empty($this->posttypes)) { return; } //Get all registered post types $posttypes = array(); //Register post type foreach ($this->posttypes as $pt) { $p = $this->registerPostType($pt); if (empty($p) || empty($p[0])) { unset($this->posttypes[$pt['slug']]); continue; } //Manage columns if (TTO_IS_ADMIN) { add_filter('manage_edit-' . $p[1] . '_columns', array(&$this, 'hookColumns'), 10); add_action('manage_' . $p[1] . '_posts_custom_column', array(&$this, 'hookCustomColumn'), 11, 2); } $this->posttypes[$pt['slug']] = $p[0]; } //Update DB if (TTO_IS_ADMIN) { TeaThemeOptions::setConfigs(Engine::getIndex(), $this->posttypes); } //Permalink structures add_action('post_type_link', array(&$this, 'hookPermalinkMake'), 10, 3); if (TTO_IS_ADMIN) { //Display post type's custom fields add_action('admin_init', array(&$this, 'hookFieldsDisplay')); //Display settings in permalinks page add_action('admin_init', array(&$this, 'hookFieldsPermalink')); //Save post type's custom fields add_action('save_post', array(&$this, 'hookFieldsSave')); } }, 10, 1); }
/** * Index all search datas. * * @since 3.0.0 */ public function makeIndex() { //Admin panel if (!TTO_IS_ADMIN) { return; } //Index contents $count = $this->search->getEngine()->indexContents(); //Update counter $index = Search::getIndex(); TeaThemeOptions::setConfigs($index . '-count', $count); }