Plugin Directory

Changeset 359355


Ignore:
Timestamp:
03/12/2011 09:51:36 PM (15 years ago)
Author:
blepoxp
Message:

3.1 compatability, inline docs, option to donate

Location:
no-sub-category-posts-in-loop
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • no-sub-category-posts-in-loop/tags/0.4/ft-no-subcats-in-loop.php

    r93181 r359355  
    11<?php
     2/**
     3 * Removes subcategory posts from category arhcives
     4 *
     5 * @package No_Sub_Category_Posts_In_Loop
     6 * @version 0.4
    27/*
    38Plugin Name: No Sub-Category Posts in Loop
    49Plugin URI: http://fullthrottledevelopment.com/no-sub-category-posts-in-loop/
    510Description: This plugin allows you to only display post from the current category in your loop (no posts from sub cats)
    6 Version: 0.3
     11Version: 0.4
    712Author: FullThrottle Development
    813Author URI: http://fullthrottledevelopment.com/
    914*/
    1015
    11 //Primary Developer : Glenn Ansley (http://glennansley.com)
     16// Primary Developer : Glenn Ansley (http://glennansley.com)
    1217
    13 /*Copyright 2009 Glenn Ansley
     18// Copyright 2009-2011 Glenn Ansley. GPL
    1419
    1520/* Release History
     21 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
    1622 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin
    1723 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!)
     
    1925*/
    2026
    21 define( 'FT_NSCP_Version' , '0.3' );
     27/**
     28 * Constant holding the version number
     29 * @since 0.1
     30 */
     31define( 'FT_NSCP_Version' , '0.4' );
    2232
    23 // Define plugin path
    24 if ( !defined('WP_CONTENT_DIR') ) {
    25     define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content');
    26 }
     33/**
     34 * Constant holding the plugin directory path
     35 * @since 0.1
     36 */
    2737define('FT_NSCP_PATH' , WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)) );
    2838
    29 // Define plugin URL
    30 if ( !defined('WP_CONTENT_URL') ) {
    31     define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' );
    32 }
     39/**
     40 * Constant holding the plugin directory URL
     41 */
    3342define( 'FT_NSCP_URL' , WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)) );
    3443
     
    4554}
    4655
     56/**
     57 * Filter's the query's where clause
     58
     59 * @param str incoming WHERE clause
     60 * @global $wp_query WordPress query object
     61 * @global $wpdb WordPress database access object
     62 * @global $wp_version WordPress version number
     63 * @retuns str Modified or original WHERE clause
     64 * @since 0.1
     65 */
    4766function ft_nscp_mod_where( $where ){
    48     global $wp_query,$wpdb;
     67    global $wp_query, $wpdb, $wp_version;
    4968
    5069    // Fire off if we're viewing a category archive
     
    5271       
    5372        // Get children categories of current cat if they exist
    54         if ( $excludes = get_categories("child_of=".$wp_query->get('cat')) ){
     73        if ( $excludes = get_categories( "child_of=" . $wp_query->get( 'cat' ) ) ) {
    5574           
    5675            // For each child, add just the ID to an array
    57             foreach ( $excludes as $key => $value ){
     76            foreach ( $excludes as $key => $value ) {
     77
    5878                $exs[] = $value->cat_ID;
     79           
    5980            }
     81       
    6082        }
    6183       
    6284        // If array exists, remove posts in child categories from query.
    63         if ( isset($exs) && is_array($exs) ){
    64             $where .= " AND ".$wpdb->prefix."term_taxonomy.term_id NOT IN (".implode(",",$exs).") ";
     85        if ( isset( $exs ) && is_array( $exs ) ) {
     86
     87            // WP Query changed in 3.1
     88            if ( version_compare( $wp_version, 3.1, '<' ) )
     89                $where .= " AND " . $wpdb->prefix . "term_taxonomy.term_id NOT IN ( ". implode( ",", $exs ) . " ) ";
     90            else
     91                $where .= " AND " . $wpdb->prefix . "term_relationships.term_taxonomy_id NOT IN ( ". implode( ",", $exs ) . " ) ";
     92
    6593        }
    6694    }
    67    
     95
    6896    return $where;
     97
    6998}
    7099
    71 if ( !is_admin() ){
    72     add_action('posts_where','ft_nscp_mod_where');
     100/**
     101 * Removes the filter after the main query has been built to not interfere with widgets
     102 *
     103 * @since 0.4
     104 */
     105function ft_nscp_remove_filter() {
     106
     107    remove_filter( 'posts_where', 'ft_nscp_mod_where' );
     108
    73109}
     110
     111if ( ! is_admin() ) {
     112
     113    add_filter( 'posts_where', 'ft_nscp_mod_where' );
     114    add_action( 'template_redirect', 'ft_nscp_remove_filter' );
     115
     116}
     117
     118/**
     119 * Adds ability to donate to plugin development
     120 *
     121 * @since 0.4
     122 */
     123function ft_ncsp_donate() {
     124
     125    // Kill notice
     126    if ( isset( $_GET['remove_ncsp_donate'] ) )
     127        update_option( 'ft_ncsp_show_donate', '0.4' );
     128
     129    // Look for wp_option
     130    if ( ! $show_donation_link = get_option( 'ft_ncsp_show_donate' ) ) {
     131        update_option( 'ft_nscp_show_donate', 'yes' );
     132        $show_donation_link = 'yes';
     133    }
     134
     135    if ( 'yes' == $show_donation_link )
     136        add_action( 'admin_notices', 'ft_ncsp_donate_notice' );
     137
     138}
     139add_action( 'admin_init', 'ft_ncsp_donate' );
     140
     141/**
     142 * This displays the option to donate via paypal
     143 *
     144 * @since 0.4
     145 */
     146function ft_ncsp_donate_notice() {
     147
     148    $paypal_link = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MD85KZY5SAYLA';
     149    $no_thanks = esc_url( admin_url( 'plugins.php?remove_ncsp_donate=true' ) );
     150    echo "<div class='update-nag'>" . sprintf( __( "Thanks for upgrading the 'No subcats in loops' plugin. Would you consider sending the developer $5.00 USD to sustain development? <a href='%s'>Yes, take me to PayPal</a> | <a href='%s'>No thanks</a> | <a href='%s'>I already did</a>." ), $paypal_link, $no_thanks, $no_thanks ) . "</div>";
     151
     152}
  • no-sub-category-posts-in-loop/tags/0.4/readme.txt

    r116455 r359355  
    44Tags: loop, categories, cats, posts
    55Requires at least: 2.7
    6 Tested up to: 2.7.1
    7 Stable tag: 0.3
     6Tested up to: 3.1
     7Stable tag: 0.4
    88
    99Once activated, only posts from the current category are displayed in your loop (no posts from sub cats).
     
    1414That's all it does. No options. If you find you need options, let me know and I'll build them into it.
    1515
    16 = Version History =
     16As of 0.4 I remove the filter after the main query is built so that it doesn't interfere with widgets.
     17If you have a custom query or call wp_query on a category archive template, you'll need to add and remove the filters before and after your query. Below is an example of how to do this if you use wp_query. Again, this is not necessary unless you have modified queries in a template file.
    1718
     19`
     20add_filter( 'posts_where', 'ft_nscp_mod_where' );
     21query_posts( array( 'your-custom' => 'args' ) );
     22remove_filter( 'posts_where', 'ft_nscp_mod_where' );
     23`
     24
     25Its important that you remove what you add.
     26
     27== Changelog ==
     28
     29* 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
    1830* 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin
    1931* 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!)
     
    3042
    3143http://fullthrottledevelopment.com/no-sub-category-posts-in-loop
     44
     45== Upgrade Notice ==
     46Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
  • no-sub-category-posts-in-loop/trunk/ft-no-subcats-in-loop.php

    r93181 r359355  
    11<?php
     2/**
     3 * Removes subcategory posts from category arhcives
     4 *
     5 * @package No_Sub_Category_Posts_In_Loop
     6 * @version 0.4
    27/*
    38Plugin Name: No Sub-Category Posts in Loop
    49Plugin URI: http://fullthrottledevelopment.com/no-sub-category-posts-in-loop/
    510Description: This plugin allows you to only display post from the current category in your loop (no posts from sub cats)
    6 Version: 0.3
     11Version: 0.4
    712Author: FullThrottle Development
    813Author URI: http://fullthrottledevelopment.com/
    914*/
    1015
    11 //Primary Developer : Glenn Ansley (http://glennansley.com)
     16// Primary Developer : Glenn Ansley (http://glennansley.com)
    1217
    13 /*Copyright 2009 Glenn Ansley
     18// Copyright 2009-2011 Glenn Ansley. GPL
    1419
    1520/* Release History
     21 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
    1622 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin
    1723 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!)
     
    1925*/
    2026
    21 define( 'FT_NSCP_Version' , '0.3' );
     27/**
     28 * Constant holding the version number
     29 * @since 0.1
     30 */
     31define( 'FT_NSCP_Version' , '0.4' );
    2232
    23 // Define plugin path
    24 if ( !defined('WP_CONTENT_DIR') ) {
    25     define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content');
    26 }
     33/**
     34 * Constant holding the plugin directory path
     35 * @since 0.1
     36 */
    2737define('FT_NSCP_PATH' , WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)) );
    2838
    29 // Define plugin URL
    30 if ( !defined('WP_CONTENT_URL') ) {
    31     define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' );
    32 }
     39/**
     40 * Constant holding the plugin directory URL
     41 */
    3342define( 'FT_NSCP_URL' , WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)) );
    3443
     
    4554}
    4655
     56/**
     57 * Filter's the query's where clause
     58
     59 * @param str incoming WHERE clause
     60 * @global $wp_query WordPress query object
     61 * @global $wpdb WordPress database access object
     62 * @global $wp_version WordPress version number
     63 * @retuns str Modified or original WHERE clause
     64 * @since 0.1
     65 */
    4766function ft_nscp_mod_where( $where ){
    48     global $wp_query,$wpdb;
     67    global $wp_query, $wpdb, $wp_version;
    4968
    5069    // Fire off if we're viewing a category archive
     
    5271       
    5372        // Get children categories of current cat if they exist
    54         if ( $excludes = get_categories("child_of=".$wp_query->get('cat')) ){
     73        if ( $excludes = get_categories( "child_of=" . $wp_query->get( 'cat' ) ) ) {
    5574           
    5675            // For each child, add just the ID to an array
    57             foreach ( $excludes as $key => $value ){
     76            foreach ( $excludes as $key => $value ) {
     77
    5878                $exs[] = $value->cat_ID;
     79           
    5980            }
     81       
    6082        }
    6183       
    6284        // If array exists, remove posts in child categories from query.
    63         if ( isset($exs) && is_array($exs) ){
    64             $where .= " AND ".$wpdb->prefix."term_taxonomy.term_id NOT IN (".implode(",",$exs).") ";
     85        if ( isset( $exs ) && is_array( $exs ) ) {
     86
     87            // WP Query changed in 3.1
     88            if ( version_compare( $wp_version, 3.1, '<' ) )
     89                $where .= " AND " . $wpdb->prefix . "term_taxonomy.term_id NOT IN ( ". implode( ",", $exs ) . " ) ";
     90            else
     91                $where .= " AND " . $wpdb->prefix . "term_relationships.term_taxonomy_id NOT IN ( ". implode( ",", $exs ) . " ) ";
     92
    6593        }
    6694    }
    67    
     95
    6896    return $where;
     97
    6998}
    7099
    71 if ( !is_admin() ){
    72     add_action('posts_where','ft_nscp_mod_where');
     100/**
     101 * Removes the filter after the main query has been built to not interfere with widgets
     102 *
     103 * @since 0.4
     104 */
     105function ft_nscp_remove_filter() {
     106
     107    remove_filter( 'posts_where', 'ft_nscp_mod_where' );
     108
    73109}
     110
     111if ( ! is_admin() ) {
     112
     113    add_filter( 'posts_where', 'ft_nscp_mod_where' );
     114    add_action( 'template_redirect', 'ft_nscp_remove_filter' );
     115
     116}
     117
     118/**
     119 * Adds ability to donate to plugin development
     120 *
     121 * @since 0.4
     122 */
     123function ft_ncsp_donate() {
     124
     125    // Kill notice
     126    if ( isset( $_GET['remove_ncsp_donate'] ) )
     127        update_option( 'ft_ncsp_show_donate', '0.4' );
     128
     129    // Look for wp_option
     130    if ( ! $show_donation_link = get_option( 'ft_ncsp_show_donate' ) ) {
     131        update_option( 'ft_nscp_show_donate', 'yes' );
     132        $show_donation_link = 'yes';
     133    }
     134
     135    if ( 'yes' == $show_donation_link )
     136        add_action( 'admin_notices', 'ft_ncsp_donate_notice' );
     137
     138}
     139add_action( 'admin_init', 'ft_ncsp_donate' );
     140
     141/**
     142 * This displays the option to donate via paypal
     143 *
     144 * @since 0.4
     145 */
     146function ft_ncsp_donate_notice() {
     147
     148    $paypal_link = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MD85KZY5SAYLA';
     149    $no_thanks = esc_url( admin_url( 'plugins.php?remove_ncsp_donate=true' ) );
     150    echo "<div class='update-nag'>" . sprintf( __( "Thanks for upgrading the 'No subcats in loops' plugin. Would you consider sending the developer $5.00 USD to sustain development? <a href='%s'>Yes, take me to PayPal</a> | <a href='%s'>No thanks</a> | <a href='%s'>I already did</a>." ), $paypal_link, $no_thanks, $no_thanks ) . "</div>";
     151
     152}
  • no-sub-category-posts-in-loop/trunk/readme.txt

    r116455 r359355  
    44Tags: loop, categories, cats, posts
    55Requires at least: 2.7
    6 Tested up to: 2.7.1
    7 Stable tag: 0.3
     6Tested up to: 3.1
     7Stable tag: 0.4
    88
    99Once activated, only posts from the current category are displayed in your loop (no posts from sub cats).
     
    1414That's all it does. No options. If you find you need options, let me know and I'll build them into it.
    1515
    16 = Version History =
     16As of 0.4 I remove the filter after the main query is built so that it doesn't interfere with widgets.
     17If you have a custom query or call wp_query on a category archive template, you'll need to add and remove the filters before and after your query. Below is an example of how to do this if you use wp_query. Again, this is not necessary unless you have modified queries in a template file.
    1718
     19`
     20add_filter( 'posts_where', 'ft_nscp_mod_where' );
     21query_posts( array( 'your-custom' => 'args' ) );
     22remove_filter( 'posts_where', 'ft_nscp_mod_where' );
     23`
     24
     25Its important that you remove what you add.
     26
     27== Changelog ==
     28
     29* 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
    1830* 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin
    1931* 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!)
     
    3042
    3143http://fullthrottledevelopment.com/no-sub-category-posts-in-loop
     44
     45== Upgrade Notice ==
     46Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
Note: See TracChangeset for help on using the changeset viewer.