Plugin Directory

Changeset 1101510


Ignore:
Timestamp:
02/27/2015 09:34:08 PM (11 years ago)
Author:
cip
Message:

version 1.0 - add support for any taxonomy and add plugin icons

Location:
enhanced-category-pages
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • enhanced-category-pages/trunk/classes/ecp/Enhanced_Category.php

    r1091705 r1101510  
    3030        $post = array(
    3131            'post_name' => $cat->slug,
    32             'post_title' => $cat->cat_name,
     32            'post_title' => $cat->name,
    3333            #'post_category' => array($cat->cat_ID),
    3434            'post_status' => 'publish',
    3535            '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,
    3838        );
    3939
     40        //var_dump($cat);die;
     41
    4042        $post_id = wp_insert_post($post, false);
    4143
    4244        //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);
    4446
    4547        return $post_id;
    4648    }
    4749
    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) {
    4951        global $wpdb;
    5052        $table_name = $wpdb->prefix . $this->_table_categories_posts;
     
    5557                    'category_id' => $cat_id,
    5658                    'post_id' => $post_id,
     59                    'taxonomy' => $taxonomy
    5760                )
    5861            );
     
    6063    }
    6164
    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);
    6467        if ($post_id > 0) {
    6568            wp_delete_post($post_id, true);
     
    8285        global $wpdb;
    8386
    84         $category = null;
    85 
    86         $category_id = $wpdb->get_var($wpdb->prepare(
     87        $category = $wpdb->get_row($wpdb->prepare(
    8788            "
    88                 SELECT category_id
     89                SELECT category_id, taxonomy
    8990                FROM {$wpdb->prefix}{$this->_table_categories_posts}
    9091                WHERE post_id = %d
     
    9394        ));
    9495
    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;
    97123    }
    98124
     
    104130        $posts_array = array();
    105131
    106         $post_id = $wpdb->get_var($wpdb->prepare(
     132        $categories_posts_row = $wpdb->get_var($wpdb->prepare(
    107133            "
    108                 SELECT post_id
     134                SELECT post_id, taxonomy
    109135                FROM {$wpdb->prefix}{$this->_table_categories_posts}
    110136                WHERE category_id = %d
     
    113139        ));
    114140
     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
    115149        if (!empty($post_id)) {
    116150            $posts_array = get_posts(array(
     
    123157    }
    124158
    125     public function get_first_or_create_for_category($category_id) {
     159    public function get_first_or_create_for_category($category_id, $taxonomy) {
    126160
    127161        $posts_array = $this->get_by_category($category_id);
     
    129163        if (empty($posts_array)) {
    130164            //if the post does not already exist, we create it
    131             $cat = get_category($category_id);
     165            $cat = get_term($category_id, $taxonomy);
    132166            $post_id = $this->add_new_from_category($cat);
    133167        } else {
     
    143177        }
    144178        $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)) {
    148182            $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,
    153187            );
    154188
    155189            $this->_prevent_update = true;
    156             wp_update_category($category);
     190            wp_update_term($category_r->category_id, $category_r->taxonomy, $category);
    157191        }
    158192    }
     
    163197            return;
    164198        }
    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);
    166200
    167201        if ($post_id > 0) {
     
    169203                'ID' => $post_id,
    170204                '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,
    173207            );
    174208
  • enhanced-category-pages/trunk/classes/ecp/WP_Custom_Post.php

    r1091245 r1101510  
    5454        $messages[$this->get_safe_name()] = array(
    5555            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),
    5757            2 => __('Custom field updated.'),
    5858            3 => __('Custom field deleted.'),
    59             4 => $this->translate('%s updated', $_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),
    6666        );
    6767
  • enhanced-category-pages/trunk/classes/ecp/WP_Integration.php

    r1091245 r1101510  
    4848          category_id bigint(9) UNSIGNED NOT NULL UNIQUE,
    4949          post_id bigint(9) UNSIGNED NOT NULL UNIQUE,
     50          taxonomy varchar(100) NOT NULL,
    5051          PRIMARY KEY  id (id)
    5152        ) $charset_collate;";
     
    7071        add_action("init", array(&$this, "register_custom_post"));
    7172        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
    7475        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);
    7677        add_action("post_updated", array(&$this, 'update_post'));
    7778        //customize admin area
    78         add_action("admin_init", array(&$this, 'admin_init'));
     79        add_action("admin_init", array(&$this, 'admin_init'), 10000);
    7980    }
    8081
     
    8283        $url = $this->get_enhanced_category_edit_url($tag);
    8384        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
     99STR;
     100
    84101    }
    85102
     
    88105
    89106        $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
     156STR;
     157        }
    90158    }
    91159
    92160    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
    109162    }
    110163
     
    114167
    115168    public function register_custom_post() {
     169
    116170        $this->_enhanced_category = new Enhanced_Category($this->_translation_domain, $this->_table_name);
    117171
     
    123177    public function add_ec_edit_link($actions, $tag) {
    124178
    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        }
    130182
    131183        return $actions;
     
    139191        $url = "";
    140192
    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);
    142194
    143195        if (!empty($post_id)) {
     
    148200    }
    149201
    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);
    153207    }
    154208
    155209    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);
    164215
    165216        //always update title and slug using the category
     
    173224        }
    174225    }
     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    }
    175243}
  • enhanced-category-pages/trunk/enhanced-category-pages.php

    r1091705 r1101510  
    44Description: Create custom enhanced pages for categories. Manage category page as a custom post.
    55Author: Ciprian Amariei, Diana Amitroaei
    6 Version: 0.2
     6Version: 1.0
    77Text Domain: enhanced-category-pages
    88Text Path: languages
  • enhanced-category-pages/trunk/readme.txt

    r1091705 r1101510  
    11=== Enhanced Category Pages ===
    22Contributors: cip, dioneea
    3 Tags: categories, page, enhanced, custom post, custom post type, category, featured image,
     3Tags: categories, taxonomy, term, page, enhanced, custom post, custom post type, category, featured image
    44Donate 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&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
    55Requires at least: 3.0.1
    6 Tested up to: 4.1
    7 Stable tag: 0.2
     6Tested up to: 4.1.1
     7Stable tag: 1.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1313== Description ==
    1414
    15 Enhanced Category Pages allows you to create custom category pages and manage them by a special custom post type.
     15Enhanced Category Pages allows you to create custom category and term pages by managing them using a special custom post type.
    1616
    1717**Features**
    1818
     19* **NEW** Enhance any taxonomy: edit a term from **any taxonomy** as a custom post
    1920* edit category as a custom post - *Enhanced Category*
    2021* automatically generates *Enhanced Category* post type for each category
     
    2829* customize *Enhanced Category* custom post type capabilities via plugin options
    2930* manual selection on enhanced categories
    30 * enhance any taxonomy
    31 
    3231
    3332
     
    9291* Make php 5.3 compatible.
    9392
     93= 1.0 =
     94* Enhance any taxonomy
     95
     96
    9497== Upgrade Notice ==
    9598
    9699= 0.2 =
    97100* 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.