Changeset 1101510
- Timestamp:
- 02/27/2015 09:34:08 PM (11 years ago)
- Location:
- enhanced-category-pages
- Files:
-
- 2 added
- 1 deleted
- 5 edited
-
assets/icon-128x128.png (added)
-
assets/icon-256x256.png (added)
-
trunk/classes/ecp/Enhanced_Category.php (modified) (12 diffs)
-
trunk/classes/ecp/WP_Custom_Post.php (modified) (1 diff)
-
trunk/classes/ecp/WP_Integration.php (modified) (9 diffs)
-
trunk/enhanced-category-pages.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/scripts (deleted)
Legend:
- Unmodified
- Added
- Removed
-
enhanced-category-pages/trunk/classes/ecp/Enhanced_Category.php
r1091705 r1101510 30 30 $post = array( 31 31 'post_name' => $cat->slug, 32 'post_title' => $cat-> cat_name,32 'post_title' => $cat->name, 33 33 #'post_category' => array($cat->cat_ID), 34 34 'post_status' => 'publish', 35 35 'post_type' => $this->_name, 36 'post_content' => $cat-> category_description,37 'post_excerpt' => $cat-> category_description,36 'post_content' => $cat->description, 37 'post_excerpt' => $cat->description, 38 38 ); 39 39 40 //var_dump($cat);die; 41 40 42 $post_id = wp_insert_post($post, false); 41 43 42 44 //insert into correlation table 43 $this->_insert_into_ecp_x_category($cat-> cat_ID, $post_id);45 $this->_insert_into_ecp_x_category($cat->term_id, $post_id, $cat->taxonomy); 44 46 45 47 return $post_id; 46 48 } 47 49 48 private function _insert_into_ecp_x_category($cat_id, $post_id ) {50 private function _insert_into_ecp_x_category($cat_id, $post_id, $taxonomy) { 49 51 global $wpdb; 50 52 $table_name = $wpdb->prefix . $this->_table_categories_posts; … … 55 57 'category_id' => $cat_id, 56 58 'post_id' => $post_id, 59 'taxonomy' => $taxonomy 57 60 ) 58 61 ); … … 60 63 } 61 64 62 public function delete_category($cat_id ) {63 $post_id = $this->get_first_or_create_for_category($cat_id );65 public function delete_category($cat_id, $taxonomy) { 66 $post_id = $this->get_first_or_create_for_category($cat_id, $taxonomy); 64 67 if ($post_id > 0) { 65 68 wp_delete_post($post_id, true); … … 82 85 global $wpdb; 83 86 84 $category = null; 85 86 $category_id = $wpdb->get_var($wpdb->prepare( 87 $category = $wpdb->get_row($wpdb->prepare( 87 88 " 88 SELECT category_id 89 SELECT category_id, taxonomy 89 90 FROM {$wpdb->prefix}{$this->_table_categories_posts} 90 91 WHERE post_id = %d … … 93 94 )); 94 95 95 return $category_id; 96 96 //requried by update from 0.2 to 1.0 97 //fill empty taxonomy name 98 if (empty($category->taxonomy)) { 99 $category->taxonomy = $this->fill_empty_taxonomy($category->category_id); 100 } 101 102 return $category; 103 } 104 105 private function fill_empty_taxonomy($category_id) { 106 107 global $wpdb; 108 109 $taxonomy = $wpdb->get_var($wpdb->prepare( 110 " 111 SELECT taxonomy 112 FROM {$wpdb->prefix}term_taxonomy 113 WHERE term_id = %d 114 ", 115 $category_id 116 )); 117 118 if ( !empty($taxonomy) ) { 119 $wpdb->update( $wpdb->prefix.$this->_table_categories_posts, array('taxonomy' => $taxonomy), array('category_id' => $category_id) ); 120 } 121 122 return $taxonomy; 97 123 } 98 124 … … 104 130 $posts_array = array(); 105 131 106 $ post_id= $wpdb->get_var($wpdb->prepare(132 $categories_posts_row = $wpdb->get_var($wpdb->prepare( 107 133 " 108 SELECT post_id 134 SELECT post_id, taxonomy 109 135 FROM {$wpdb->prefix}{$this->_table_categories_posts} 110 136 WHERE category_id = %d … … 113 139 )); 114 140 141 $post_id = $categories_posts_row->post_id; 142 143 //requried by update from 0.2 to 1.0 144 //fill empty taxonomy name 145 if (empty($categories_posts_row->taxonomy)) { 146 $this->fill_empty_taxonomy($category_id); 147 } 148 115 149 if (!empty($post_id)) { 116 150 $posts_array = get_posts(array( … … 123 157 } 124 158 125 public function get_first_or_create_for_category($category_id ) {159 public function get_first_or_create_for_category($category_id, $taxonomy) { 126 160 127 161 $posts_array = $this->get_by_category($category_id); … … 129 163 if (empty($posts_array)) { 130 164 //if the post does not already exist, we create it 131 $cat = get_ category($category_id);165 $cat = get_term($category_id, $taxonomy); 132 166 $post_id = $this->add_new_from_category($cat); 133 167 } else { … … 143 177 } 144 178 $post = get_post($post_id); 145 $category_ id= $this->get_by_post($post_id);146 147 if ( $category_id > 0) {179 $category_r = $this->get_by_post($post_id); 180 181 if (!empty($category_r)) { 148 182 $category = array( 149 ' cat_ID' => $category_id,150 ' category_nicename' => $post->post_name,151 ' cat_name' => $post->post_title,152 ' category_description' => $post->post_excerpt,183 'term_id' => $category_r->category_id, 184 'slug' => $post->post_name, 185 'name' => $post->post_title, 186 'description' => $post->post_excerpt, 153 187 ); 154 188 155 189 $this->_prevent_update = true; 156 wp_update_ category($category);190 wp_update_term($category_r->category_id, $category_r->taxonomy, $category); 157 191 } 158 192 } … … 163 197 return; 164 198 } 165 $post_id = $this->get_first_or_create_for_category($category->term_id );199 $post_id = $this->get_first_or_create_for_category($category->term_id, $category->taxonomy); 166 200 167 201 if ($post_id > 0) { … … 169 203 'ID' => $post_id, 170 204 'post_name' => $category->slug, 171 'post_title' => $category-> cat_name,172 'post_excerpt' => $category-> category_description,205 'post_title' => $category->name, 206 'post_excerpt' => $category->description, 173 207 ); 174 208 -
enhanced-category-pages/trunk/classes/ecp/WP_Custom_Post.php
r1091245 r1101510 54 54 $messages[$this->get_safe_name()] = array( 55 55 0 => '', // Unused. Messages start at index 1. 56 1 => $this->translate(' %s updated. <!--a href="%s">View %s</a-->', $_uname, esc_url(get_permalink($post_ID)), $this->_name),56 1 => $this->translate('Successfully updated. <!--a href="%s">View</a-->', $_uname, esc_url(get_permalink($post_ID)), $this->_name), 57 57 2 => __('Custom field updated.'), 58 58 3 => __('Custom field deleted.'), 59 4 => $this->translate(' %supdated', $_uname),60 5 => isset($_GET['revision']) ? $this->translate(' %s restored to revision from %s', $_uname, wp_post_revision_title((int) $_GET['revision'], false)) : false,61 6 => $this->translate(' %s published. <a href="%s">View %s</a>', $_uname, esc_url(get_permalink($post_ID)), $this->_name),62 7 => $this->translate(' %s saved.', $_uname),63 8 => $this->translate(' %s submitted. <a target="_blank" href="%s">Preview %s</a>', $_uname, esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $this->_name),64 9 => $this->translate(' %s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', $_uname, date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID)), $this->_name),65 10 => $this->translate(' %s draft updated. <a target="_blank" href="%s">Preview %s</a>', $_uname, esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $this->_name),59 4 => $this->translate('Successfully updated', $_uname), 60 5 => isset($_GET['revision']) ? $this->translate('Restored to revision from %s', $_uname, wp_post_revision_title((int) $_GET['revision'], false)) : false, 61 6 => $this->translate('Published. <a href="%s">View</a>', $_uname, esc_url(get_permalink($post_ID)), $this->_name), 62 7 => $this->translate('Saved.', $_uname), 63 8 => $this->translate('Submitted. <a target="_blank" href="%s">Preview</a>', $_uname, esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $this->_name), 64 9 => $this->translate('Scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview</a>', $_uname, date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID)), $this->_name), 65 10 => $this->translate('Draft updated. <a target="_blank" href="%s">Preview</a>', $_uname, esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))), $this->_name), 66 66 ); 67 67 -
enhanced-category-pages/trunk/classes/ecp/WP_Integration.php
r1091245 r1101510 48 48 category_id bigint(9) UNSIGNED NOT NULL UNIQUE, 49 49 post_id bigint(9) UNSIGNED NOT NULL UNIQUE, 50 taxonomy varchar(100) NOT NULL, 50 51 PRIMARY KEY id (id) 51 52 ) $charset_collate;"; … … 70 71 add_action("init", array(&$this, "register_custom_post")); 71 72 add_filter("tag_row_actions", array(&$this, 'add_ec_edit_link'), 10, 2); 72 add_action("create_ category", array(&$this, 'add_category'));73 add_action('edit_category_form_fields', array(&$this, 'category_edit_form_fields')); 73 add_action("create_term", array(&$this, 'add_category'), 10, 3); 74 74 75 add_action("pre_delete_term", array(&$this, 'delete_category'), 10, 2); 75 add_action("edited_ category", array(&$this, 'update_category'));76 add_action("edited_term", array(&$this, 'update_category'), 10, 3); 76 77 add_action("post_updated", array(&$this, 'update_post')); 77 78 //customize admin area 78 add_action("admin_init", array(&$this, 'admin_init') );79 add_action("admin_init", array(&$this, 'admin_init'), 10000); 79 80 } 80 81 … … 82 83 $url = $this->get_enhanced_category_edit_url($tag); 83 84 echo '<input type="hidden" id="enhanced_category_edit_url" value="' . esc_url($url) . '" />'; 85 86 $enhanced_edit_text = __("Enhanced Edit", $this->_translation_domain); 87 echo <<<STR 88 <script type="text/javascript"> 89 (function($) { 90 var url = $('#enhanced_category_edit_url').val(); 91 if (url) { 92 $('.edit-tags-php .wrap > h2').append( 93 '<a href="' + url + '" class="add-new-h2 back-to-categories">{$enhanced_edit_text}</a>' 94 ); 95 } 96 })(jQuery); 97 </script> 98 99 STR; 100 84 101 } 85 102 … … 88 105 89 106 $this->register_scripts(); 107 108 109 //register for all taxonomies 110 $taxonomies = $this->get_enabled_taxonomies(); 111 112 //add hidden input url on edit term page 113 foreach ($taxonomies as $taxonomy_name) { 114 add_action("{$taxonomy_name}_edit_form_fields", array(&$this, 'category_edit_form_fields')); 115 } 116 117 118 //add hidden link to go back to taxonomy list edit 119 add_action('edit_form_top', array(&$this, 'ecp_edit_back_taxonomy')); 120 121 } 122 123 public function ecp_edit_back_taxonomy($post) { 124 125 //do only for ecp posts 126 if ( $post->post_type == $this->_enhanced_category->get_safe_name()) { 127 128 $post_id = $post->ID; 129 $category = $this->_enhanced_category->get_by_post($post_id); 130 $taxonomy = get_taxonomy($category->taxonomy); 131 132 $a = '<a class="add-new-h2 back-to-categories" href="' 133 . esc_url(admin_url("edit-tags.php?taxonomy={$category->taxonomy}")) . '">' 134 . __("Back to {$taxonomy->labels->name}", $this->_translation_domain) . "</a>"; 135 136 echo '<input type="hidden" id="enhanced_category_list_edit_url" value="' . htmlentities($a) . '" />'; 137 138 echo '<input type="hidden" id="taxonomy_single_name" value="' . htmlentities($taxonomy->labels->singular_name) . '" />'; 139 140 //HACK: added here for responsivness - no delay when replacing 141 $post_type_name = $post->post_type; 142 echo <<<STR 143 <script type="text/javascript"> 144 (function($) { 145 $('.post-php.post-type-{$post_type_name} .wrap > h2').append( 146 $('#enhanced_category_list_edit_url').val() 147 ); 148 149 //replace taxonomy Category with custom taxonomy name 150 var h2 = $('h2'); 151 var html = h2.html().replace('Category', $('#taxonomy_single_name').val()); 152 h2.html(html); 153 })(jQuery); 154 </script> 155 156 STR; 157 } 90 158 } 91 159 92 160 public function register_scripts() { 93 // Register the script 94 $js_handle = 'ecp-admin'; 95 96 wp_register_script($js_handle, $this->_plugin_url . '/scripts/admin.js'); 97 98 // Localize the script with new data 99 $translation_array = array( 100 'back_to_categories' => __('Back to categories', $this->_translation_domain), 101 'back_to_categories_url' => esc_url(admin_url("edit-tags.php?taxonomy=category")), 102 'post_type_name' => $this->_enhanced_category->get_safe_name(), 103 'edit_enhanced' => __("Enhanced Edit", $this->_translation_domain), 104 ); 105 106 wp_localize_script($js_handle, 'ecp_js_l10n', $translation_array); 107 108 wp_enqueue_script($js_handle); 161 //EMPTY since 1.0 109 162 } 110 163 … … 114 167 115 168 public function register_custom_post() { 169 116 170 $this->_enhanced_category = new Enhanced_Category($this->_translation_domain, $this->_table_name); 117 171 … … 123 177 public function add_ec_edit_link($actions, $tag) { 124 178 125 if ($tag->taxonomy !== 'category') { 126 return $actions; 127 } 128 129 $actions['_enhanced_category_edit'] = $this->get_enhanced_category_edit_link($tag); 179 if ($this->is_valid_taxonomy($tag->taxonomy)) { 180 $actions['_enhanced_category_edit'] = $this->get_enhanced_category_edit_link($tag); 181 } 130 182 131 183 return $actions; … … 139 191 $url = ""; 140 192 141 $post_id = $this->_enhanced_category->get_first_or_create_for_category($tag->term_id );193 $post_id = $this->_enhanced_category->get_first_or_create_for_category($tag->term_id, $tag->taxonomy); 142 194 143 195 if (!empty($post_id)) { … … 148 200 } 149 201 150 public function add_category($category_id) { 151 $cat = get_category($category_id); 152 return $this->_enhanced_category->add_new_from_category($cat); 202 public function add_category($term_id, $tt_id, $taxonomy) { 203 204 $term = get_term($term_id, $taxonomy); 205 206 return $this->_enhanced_category->add_new_from_category($term); 153 207 } 154 208 155 209 public function delete_category($category_id, $taxonomy) { 156 if ($taxonomy !== 'category') { 157 return; 158 } 159 $this->_enhanced_category->delete_category($category_id); 160 } 161 162 public function update_category($category_id) { 163 $cat = get_category($category_id); 210 $this->_enhanced_category->delete_category($category_id, $taxonomy); 211 } 212 213 public function update_category($category_id, $tt_id, $taxonomy) { 214 $cat = get_term($category_id, $taxonomy); 164 215 165 216 //always update title and slug using the category … … 173 224 } 174 225 } 226 227 //returns all taxonomies that are enabled for this plugin to enhance 228 private function get_enabled_taxonomies() { 229 230 //get taxonomies names 231 $taxonomies = get_taxonomies(NULL, 'names'); 232 233 $taxonomies = array_filter($taxonomies, array($this, 'is_valid_taxonomy')); 234 235 return $taxonomies; 236 } 237 238 private function is_valid_taxonomy($taxonomy_name) { 239 //always true for the moment 240 //TODO: should check the user settings 241 return true; 242 } 175 243 } -
enhanced-category-pages/trunk/enhanced-category-pages.php
r1091705 r1101510 4 4 Description: Create custom enhanced pages for categories. Manage category page as a custom post. 5 5 Author: Ciprian Amariei, Diana Amitroaei 6 Version: 0.26 Version: 1.0 7 7 Text Domain: enhanced-category-pages 8 8 Text Path: languages -
enhanced-category-pages/trunk/readme.txt
r1091705 r1101510 1 1 === Enhanced Category Pages === 2 2 Contributors: cip, dioneea 3 Tags: categories, page, enhanced, custom post, custom post type, category, featured image,3 Tags: categories, taxonomy, term, page, enhanced, custom post, custom post type, category, featured image 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=7K3XA4WQ2BUVJ&lc=US&item_name=Enhanced%20Category%20Wordpress%20Plugin&item_number=Support%20Open%20Source¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted 5 5 Requires at least: 3.0.1 6 Tested up to: 4.1 7 Stable tag: 0.26 Tested up to: 4.1.1 7 Stable tag: 1.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 13 13 == Description == 14 14 15 Enhanced Category Pages allows you to create custom category pages and manage them bya special custom post type.15 Enhanced Category Pages allows you to create custom category and term pages by managing them using a special custom post type. 16 16 17 17 **Features** 18 18 19 * **NEW** Enhance any taxonomy: edit a term from **any taxonomy** as a custom post 19 20 * edit category as a custom post - *Enhanced Category* 20 21 * automatically generates *Enhanced Category* post type for each category … … 28 29 * customize *Enhanced Category* custom post type capabilities via plugin options 29 30 * manual selection on enhanced categories 30 * enhance any taxonomy31 32 31 33 32 … … 92 91 * Make php 5.3 compatible. 93 92 93 = 1.0 = 94 * Enhance any taxonomy 95 96 94 97 == Upgrade Notice == 95 98 96 99 = 0.2 = 97 100 * This version adds support for 5.3 101 102 = 1.0 = 103 * Enhance a term from any taxonomy
Note: See TracChangeset
for help on using the changeset viewer.