Plugin Directory

Changeset 816333


Ignore:
Timestamp:
12/07/2013 06:20:34 AM (12 years ago)
Author:
iamntz
Message:

tweaked code a little & removed PHP notices & warnings

Location:
page-siblings/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • page-siblings/trunk/page-siblings.php

    r621162 r816333  
    1 <?php 
     1<?php
    22/*
    33Plugin Name: Page Siblings
     
    55Description: Add a metabox with all page edit (and any other hierarchal post types) that display an edit link to its siblings.
    66Author: Ionuț Staicu
    7 Version: 1.0.1
     7Version: 1.0.2
    88Author URI: http://iamntz.com
    99*/
     
    3030
    3131        add_action('restrict_manage_posts', array( &$this, 'add_column_filters' ) );
    32         add_filter( 'request', array( &$this, 'alter_query' ) );
     32        add_filter( 'parse_query', array( &$this, 'alter_query' ) );
    3333      }
    3434    }
     
    3737
    3838  public function add_column_filters(){
    39     $current_setting = (int) $_GET['display_only_parents'];
     39    $current_setting = isset( $_GET['display_only_parents'] ) ? (int) $_GET['display_only_parents'] : 0;
    4040    ?>
    4141    <select name="display_only_parents">
    42       <option value="0" <?php selected( $current_setting, 0 ); ?>>Display Only Parent Posts</option>
    43       <option value="1" <?php selected( $current_setting, 1 ); ?>>No</option>
    44       <option value="2" <?php selected( $current_setting, 2 ); ?>>Yes</option>
     42      <option value="all" <?php selected( $current_setting, 1 ); ?>>Show Parents And Children</option>
     43      <option value="parents_only" <?php selected( $current_setting, 2 ); ?>>Show Only Parents</option>
    4544    </select>
    46     <?php 
     45    <?php
    4746  } // add_column_filters
    4847
    4948
    50   public function alter_query( $vars = '' ){
    51     if ( isset( $_GET['display_only_parents'] ) && $_GET['display_only_parents'] == 2 ) {
    52       $vars = array_merge( $vars, array(
    53         "post_parent" => 0
    54       ) );
     49  public function alter_query( $query ){
     50    if ( isset( $_GET['display_only_parents'] ) && $_GET['display_only_parents'] == 'parents_only' ) {
     51      $query_vars = &$query->query_vars;
     52      $query_vars['post_parent'] = 0;
    5553    }
    56     return $vars;
    5754  } // alter_query
    5855
     
    6865    </style>
    6966    <ul>
    70     <?php 
     67    <?php
    7168
    7269    if( $post_data->post_parent > 0 ){
     
    7976    $parent = get_post( $parent_id );
    8077
    81     if( $parent > 0 ){
     78    if( $parent ){
    8279      $this->print_child( $parent );
    8380      $this->loop_through_children( $parent_id, $post_type );
     81    }else {
     82      echo "<li>This entry doesn't have any siblings</li>";
    8483    }
    8584    echo "</ul>";
     
    118117      ( !empty( $prefix ) ? "<span class='pipe'>|</span>{$prefix}" : '' ),
    119118      get_edit_post_link( $child->ID ),
    120       ( $child->ID == $_GET['post'] ? 'font-weight:700;' : '' ),
     119      ( isset( $_GET['post'] ) && $child->ID == $_GET['post'] ? 'font-weight:700;' : '' ),
    121120      esc_attr( $child->post_title )
    122121    );
  • page-siblings/trunk/readme.txt

    r621162 r816333  
    3838= 1.0.1 =
    3939* added a filtering option to page editing, so you can only display parent pages
     40
     41= 1.0.2 =
     42* tweaked code a little & removed PHP notices & warnings
Note: See TracChangeset for help on using the changeset viewer.