/** * Create module Backbone template * for administration * * @since 2.0 * @return void */ public function template_condition() { if (WPCACore::post_types()->has(get_post_type())) { echo WPCAView::make("module/condition_template", array('id' => $this->id, 'placeholder' => $this->placeholder, 'default' => $this->default_value))->render(); } }
/** * Create module Backbone template * for administration * * @since 2.0 * @return void */ public function template_condition() { if (WPCACore::post_types()->has(get_post_type())) { foreach ($this->_post_types()->get_all() as $post_type) { if ($this->type_display) { $placeholder = $post_type->has_archive ? "/" . sprintf(__("%s Archives", WPCACore::DOMAIN), $post_type->labels->singular_name) : ""; $placeholder = $post_type->name == "post" ? "/" . __("Blog Page", WPCACore::DOMAIN) : $placeholder; $placeholder = $post_type->labels->all_items . $placeholder; } echo WPCAView::make("module/condition_" . $this->id . "_template", array('id' => $this->id, 'placeholder' => $placeholder, 'post_type' => $post_type->name, 'autoselect' => WPCACore::PREFIX . 'sub_' . $post_type->name))->render(); } } }
/** * Create module Backbone template * for administration * * @since 2.0 * @return void */ public function template_condition() { if (WPCACore::post_types()->has(get_post_type())) { foreach ($this->_get_taxonomies() as $taxonomy) { if ($this->type_display) { $placeholder = "/" . sprintf(__("%s Archives", WPCACore::DOMAIN), $taxonomy->labels->singular_name); $placeholder = $taxonomy->labels->all_items . $placeholder; } echo WPCAView::make("module/condition_" . $this->id . "_template", array('id' => $this->id, 'placeholder' => $placeholder, 'taxonomy' => $taxonomy->name, 'autoselect' => WPCACore::PREFIX . 'sub_' . $taxonomy->name))->render(); } } }
/** * Add meta box to manage condition groups * * @since 1.0 * @param string $post_type * @param WP_Post $post */ public static function add_group_meta_box($post_type, $post) { if (self::post_types()->has($post_type)) { $post_type_obj = self::post_types()->get($post_type); $options = apply_filters("wpca/modules/list", array()); $view = WPCAView::make("meta_box", array('post_type' => $post_type, 'title' => isset($post_type_obj->labels->ca_title) ? $post_type_obj->labels->ca_title : "", 'nonce' => wp_nonce_field(self::PREFIX . get_the_ID(), self::NONCE, true, false), 'options' => $options)); add_meta_box('cas-rules', __('Conditional Logic', self::DOMAIN), array($view, 'render'), $post_type, 'normal', 'default'); $template = WPCAView::make("group_template", array('post_type' => $post_type, 'options' => $options)); add_action("admin_footer", array($template, "render")); } }
/** * Meta box content * * @global WP_Post $post * @since 1.0 * @return void */ public function meta_box_content() { global $post; $screen = get_current_screen(); $hidden_columns = get_hidden_columns($screen->id); foreach ($this->_post_types()->get_all() as $post_type) { $recent_posts = $this->_get_content(array('post_type' => $post_type->name)); $panels = ""; if ($post_type->hierarchical) { $panels .= '<ul><li>' . "\n"; $panels .= '<label><input type="checkbox" name="cas_condition[' . $this->id . '][]" value="' . WPCACore::PREFIX . 'sub_' . $post_type->name . '" /> ' . __('Automatically add new children of a selected ancestor', WPCACore::DOMAIN) . '</label>' . "\n"; $panels .= '</li></ul>' . "\n"; } if ($this->type_display) { $archive_label = $post_type->has_archive ? "/" . sprintf(__("%s Archives", WPCACore::DOMAIN), $post_type->labels->singular_name) : ""; $archive_label = $post_type->name == "post" ? "/" . __("Blog Page", WPCACore::DOMAIN) : $archive_label; $panels .= '<ul><li>' . "\n"; $panels .= '<label><input class="cas-chk-all" type="checkbox" name="cas_condition[' . $this->id . '][]" value="' . $post_type->name . '" /> ' . $post_type->labels->all_items . $archive_label . '</label>' . "\n"; $panels .= '</li></ul>' . "\n"; } if (!$recent_posts) { $panels .= '<p>' . __('No items.') . '</p>'; } else { //No need to use two queries before knowing there are items if (count($recent_posts) < 20) { $posts = $recent_posts; } else { $posts = $this->_get_content(array('post_type' => $post_type->name, 'orderby' => 'title', 'order' => 'ASC')); } $tabs = array(); $tabs['most-recent'] = array('title' => __('Most Recent'), 'status' => true, 'content' => $this->term_checklist($post_type->name, $recent_posts)); $tabs['all'] = array('title' => __('View All'), 'status' => false, 'content' => $this->term_checklist($post_type->name, $posts, true)); if ($this->searchable) { $tabs['search'] = array('title' => __('Search'), 'status' => false, 'content' => '', 'content_before' => '<p><input data-cas-item_object="' . $post_type->name . '" class="cas-autocomplete-' . $this->id . ' cas-autocomplete quick-search" id="cas-autocomplete-' . $this->id . '-' . $post_type->name . '" type="search" name="cas-autocomplete" value="" placeholder="' . __('Search') . '" autocomplete="off" /><span class="spinner"></span></p>'); } $panels .= $this->create_tab_panels($this->id . '-' . $post_type->name, $tabs); } WPCAView::make("module.meta_box", array('hidden' => in_array('box-' . $this->id . '-' . $post_type->name, $hidden_columns) ? ' hide-if-js' : '', 'id' => $this->id . '-' . $post_type->name, 'module' => $this->id, 'description' => "", 'name' => $post_type->label, 'panels' => $panels))->render(); } }
/** * Add meta box to manage condition groups * * @since 1.0 * @param string $post_type * @param WP_Post $post */ public static function add_group_meta_box($post_type, $post) { if (self::post_types()->has($post_type)) { $post_type_obj = self::post_types()->get($post_type); $view = WPCAView::make("meta_box", array('title' => isset($post_type_obj->labels->ca_title) ? $post_type_obj->labels->ca_title : "", 'no_groups' => isset($post_type_obj->labels->ca_not_found) ? $post_type_obj->labels->ca_not_found : __('No Groups found', self::DOMAIN), 'groups' => self::_get_condition_groups(null, false), 'nonce' => wp_nonce_field(self::PREFIX . get_the_ID(), self::NONCE, true, false))); add_meta_box('cas-rules', __('Content', self::DOMAIN), array($view, 'render'), $post_type, 'normal', 'default'); } }
/** * Print saved condition data for a group * * @since 1.0 * @param int $post_id * @return void */ public function print_group_data($post_id) { $data = get_post_custom_values(WPCACore::PREFIX . $this->id, $post_id); if ($data) { WPCAView::make('module.group', array('id' => $this->id, 'name' => $this->name, 'data' => $data, 'checkboxes' => $this->_get_checkboxes($this->_get_content(array('include' => $data)), false, true)))->render(); } }