WordPress.org

Plugin Directory

Changeset 438312


Ignore:
Timestamp:
09/15/11 01:40:21 (3 years ago)
Author:
GregLone
Message:

Version 0.5 : modify readme.txt, sf-pages-for-custom-posts.php in trunk.

Location:
sf-pages-for-custom-posts/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sf-pages-for-custom-posts/trunk/readme.txt

    r437800 r438312  
    44Requires at least: 3.0 
    55Tested up to: 3.2.1 
    6 Stable tag: 0.4 
     6Stable tag: 0.5 
    77License: GPLv2 
    88 
     
    3333 
    3434== Frequently Asked Questions == 
    35 * Well, still in beta, so no Frequently Asked Questions for now ;) 
    36 * A little help is provided in the "Help" toggle on the plugin settings page. 
    37 * Eventually, check out [my blog](http://scri.in/pfcp) (sorry, it's in french) 
     35= What is the best setting for the template option? = 
     36It depends of your theme, but generally : 
     37* If the post type is displayed in any normal page, you won't have to set a template, leave this empty. 
     38* If the post type is displayed in the front page, the best choices are probably "Page" or "Home Page". 
     39 
     40Eventually, check out [my blog](http://scri.in/pfcp) (sorry, it's in french) 
    3841 
    3942== Screenshots == 
     
    4245== Changelog == 
    4346 
     47= 0.5 = 
     48* 09/15/2011 
     49* Major rewrite, stability improvement 
     50* Todo : settings page will be rewriten in the next release, you'll can choose a post type for each page, instead of the inverse 
     51 
    4452= 0.4 = 
    45 * 12/09/2011 
     53* 09/12/2011 
    4654* First public release 
     55* Thanks to Juliobox for the security review 
    4756 
    4857== Upgrade Notice == 
  • sf-pages-for-custom-posts/trunk/sf-pages-for-custom-posts.php

    r437798 r438312  
    44Plugin URI: http://scri.in/pfcp 
    55Description: Allows you to easily assign to a page your custom post types with a settings panel, like you can do with normal posts. 
    6 Version: 0.4 
     6Version: 0.5 
    77Author: Grégory Viguier 
    88Author URI: http://www.screenfeed.fr/ 
     
    2828} 
    2929 
    30 /* Tweak the initial query of the page */ 
    31 function sf_pfcp_set_query($query) { 
     30/* Set the request at the very beginning */ 
     31function sf_pfcp_parse_request($req) { 
    3232    $pfcp = get_option( 'sf_pfcp_options' ); 
    3333 
    34     if ( !count($pfcp) || empty($pfcp) ) 
     34    if ( empty($pfcp) ) 
    3535        return; 
    3636 
    37     // Get the current page ID : $query->queried_object->ID for rewrite mode, $query->query_vars['page_id'] if no rewrite 
    38     $page_id = ((isset($query->queried_object->ID) && $query->queried_object->ID > 0) ? $query->queried_object->ID : $query->query_vars['page_id']); 
     37    global $wp_query; 
     38    $page_id = 0; 
     39    $original_queried_object = ''; 
     40 
     41    if ( '' != $req->query_vars['pagename'] ) {                                 // Grab page ID with rewrite 
     42        $original_queried_object = get_page_by_path($req->query_vars['pagename']); 
     43        if ( !empty($original_queried_object) ) 
     44            $page_id = $original_queried_object->ID; 
     45    } 
     46    elseif ( '' != $req->query_vars['page_id'] ) {                              // Grab page ID without rewrite 
     47        $page_id = $req->query_vars['page_id']; 
     48    } 
     49    elseif ( 'page' == get_option('show_on_front') && isset($pfcp[get_option('page_on_front')])) {      // We want a custom post type on the front page but we don't know if we actually are on it 
     50        $page_id = sf_check_if_front_page($req); 
     51    } 
    3952 
    4053    if ( $page_id && isset($pfcp[$page_id]) && isset($pfcp[$page_id]['post_type']) && $pfcp[$page_id]['post_type'] ) {      // If we have a winner! 
     54        // On 'pre_get_posts' we won't have the page ID or its name, so we need to transmit the entire queried object into a custom field 
     55        if ( !empty($original_queried_object) ) 
     56            $req->query_vars['original_queried_object'] = $original_queried_object; 
     57        else 
     58            $req->query_vars['original_queried_object'] = get_page($page_id); 
    4159 
    4260        // We hook in get_header if we didn't choose "Page" template and we're not in the front-page : set "is_page" to 1, so we can have the good page title and good current item in menus (we display the template we've chosen, but is_page is true) 
     
    4563        } 
    4664 
    47         // Reset templates 
    48         $query->is_singular                     = ''; 
    49         $query->is_page                         = ''; 
     65        $req->query_vars['page_id']         = 0;                                // Used when rewrite is not active 
     66        $req->query_vars['pagename']        = '';                               // Used when rewrite is active 
    5067 
    51         // New template if needed 
    52         if (isset($pfcp[$page_id]['template']) && $pfcp[$page_id]['template']) { 
    53             $query->$pfcp[$page_id]['template'] = 1; 
    54  
    55             // Some other tweaks for home 
    56             if ($pfcp[$page_id]['template'] == 'is_home') { 
    57                 $query->is_posts_page           = 1; 
    58                 $query->query = array( 'Ugly tweak' );                          // Otherwise WP will generate again $query->query_vars['page_id'] and run a 404 error 
    59             } 
    60  
    61             unset($pfcp[$page_id]['template']); 
     68        // New query vars 
     69        unset($pfcp[$page_id]['template']); 
     70        foreach($pfcp[$page_id] as $k => $v) {                                  // post type and posts per page (and other if hooked) 
     71            $req->query_vars[$k]            = $v; 
    6272        } 
    6373 
    64         // New query vars 
    65         foreach($pfcp[$page_id] as $k => $v) {                                  // post type and posts per page (and other if hooked) 
    66             $query->query_vars[$k]              = $v; 
     74        add_action('pre_get_posts', 'sf_pfcp_set_query'); 
     75    } 
     76} 
     77 
     78/* Set the template and other stuff */ 
     79function sf_pfcp_set_query($q) { 
     80    $pfcp = get_option( 'sf_pfcp_options' ); 
     81 
     82    $q->queried_object = $q->query_vars['original_queried_object']; 
     83    unset($q->query_vars['original_queried_object']); 
     84    unset($q->query['original_queried_object']); 
     85    $q->queried_object_id = (int) $q->queried_object->ID;                       // Useful for current menu item 
     86    $page_id = $q->queried_object_id; 
     87 
     88    $q->is_home                             = ''; 
     89 
     90    // New template if needed 
     91    if (isset($pfcp[$page_id]['template']) && $pfcp[$page_id]['template']) { 
     92        $q->$pfcp[$page_id]['template']     = 1; 
     93        if ( 'page' == get_option('show_on_front') && $page_id == get_option('page_for_posts') ) { 
     94            $q->is_posts_page               = 1; 
    6795        } 
    68         $query->query_vars['post_status']       = 'publish'; 
    69         if ( empty($query->query_vars['paged'])) 
    70             $query->query_vars['paged']     = $query->query_vars['page'];       // Otherwise navigation could not work in some cases 
     96    } 
     97} 
    7198 
    72         if ($query->query_vars['pagename'] != '') {                             // Rewrite mode is active 
    73             $query->query_vars['pagename']      = ''; 
    74         } else {                                                                // No rewrite mode 
    75             $page_data = get_page( $page_id ); 
    76             $query->query_vars['page_id']       = 0; 
    77             $query->queried_object              = $page_data; 
    78             $query->queried_object_id           = $page_id; 
     99/* Check if we're in the front page and return the page ID if so */ 
     100function sf_check_if_front_page($req) { 
     101    global $wp_query; 
     102    $query = $wp_query; 
     103    $qv = $req->query_vars; 
     104    $front_page = 0; 
     105 
     106    if (empty($qv))                                                             // query_vars is empty : we're in the front page 
     107        $front_page = 1; 
     108    else { 
     109        $query->parse_tax_query( $qv ); 
     110 
     111        foreach ( $query->tax_query->queries as $tax_query ) { 
     112            if ( 'NOT IN' != $tax_query['operator'] ) { 
     113                $qv['is_tax'] = true; 
     114            } 
     115        } 
     116        unset( $tax_query ); 
     117 
     118        if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { 
     119            $post_type_obj = get_post_type_object( $qv['post_type'] ); 
     120            if ( ! empty( $post_type_obj->has_archive ) ) 
     121                $qv['is_post_type_archive'] = true; 
    79122        } 
    80123 
    81         if ($page_id != get_option('page_on_front') && 'page' == get_option('show_on_front')) 
    82             $query->queried_object->ID          = 0;                            // Enable navigation 
     124        if ( !( $qv['post_type'] || $qv['p'] || $qv['name'] || $qv['static'] || $qv['pagename'] || $qv['page_id'] || $qv['subpost'] || $qv['attachment'] || $qv['subpost_id'] || 
     125            $qv['attachment_id'] || $qv['is_post_type_archive'] || $qv['second'] || $qv['minute'] || $qv['hour'] || $qv['day'] || $qv['monthnum'] || $qv['year'] || $qv['m'] || $qv['w'] || 
     126            !(empty($qv['author']) || ($qv['author'] == '0')) ||$qv['author_name'] || $qv['is_tax'] || $qv['s'] || $qv['feed'] || $qv['tb'] || 
     127            ( '404' == $qv['error'] ) || is_admin() || $qv['comments_popup'] || $qv['robots'] ) ) {                     // None of these are true, it's front page 
     128            $front_page = 1; 
     129        } 
     130    } 
     131    unset($query); 
    83132 
    84                                                                                 //global $toto; $toto = $query; add_action('wp_head', function() { global $toto; print_r($toto); }); 
    85         return $query; 
    86     } 
     133    if ($front_page) 
     134        return get_option('page_on_front');                                     // It's front_page, so we return the 'page_on_front' ID 
     135    else return 0; 
    87136} 
    88137 
     
    100149} 
    101150else { 
    102     add_action( 'pre_get_posts', 'sf_pfcp_set_query' ); 
     151    add_action('parse_request', 'sf_pfcp_parse_request'); 
    103152} 
    104153 
Note: See TracChangeset for help on using the changeset viewer.