Last active
August 29, 2015 13:56
-
-
Save wpsmith/9176980 to your computer and use it in GitHub Desktop.
PHP: Extends Display Posts Shortcode to add a 'not_in' attribute for 'post__not_in' in WP_Query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'update_option_active_sitewide_plugins', 'dpse_deactivate_self', 10, 2 ); | |
add_action( 'update_option_active_plugins', 'dpse_deactivate_self', 10, 2 ); | |
/** | |
* Deactivate ourself if Addthis is deactivated. | |
*/ | |
function dpse_deactivate_self( $plugin, $network_deactivating ) { | |
if ( !is_plugin_active( 'addthis/addthis_social_widget.php' ) ) { | |
deactivate_plugins( plugin_basename( __FILE__ ), true ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'display_posts_shortcode_args', 'dpse_shortcode_exclude_posts', 10, 2 ); | |
/** | |
* Add "not_in" arg to Display Posts Shortcode | |
* | |
* @since 1.0.0 | |
* | |
* @param array $args Default Display Posts Shortcode args. | |
* @param array $atts Original shortcode attributes. | |
* @return array $args Modified Display Posts Shortcode args. | |
*/ | |
function dpse_shortcode_exclude_posts( $args, $atts ) { | |
if( isset( $atts['not_in'] ) ) { | |
$args['post__not_in'] = explode( ',', $atts['not_in'] ); | |
} | |
return $args; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display Posts Shortcode Extension Plugin | |
* | |
* @package DT_Display_Posts | |
* @author Travis Smith <t@wpsmith.net> | |
* @license GPL-2.0+ | |
* @link http://wpsmith.net | |
* @link http://wordpress.org/plugins/display-posts-shortcode/ | |
* @copyright 2014 Travis Smith | |
* | |
* @wordpress-plugin | |
* Plugin Name: Display Posts Shortcode - My Extension | |
* Plugin URI: http://www.wpsmith.net | |
* Description: Extends Display Posts Shortcode | |
* Version: 1.0.0 | |
* Author: Travis Smith | |
* Author URI: http://www.wpsmith.net | |
* Text Domain: displayposts-ext | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Domain Path: /languages | |
*/ | |
add_filter( 'display_posts_shortcode_args', 'dpse_shortcode_exclude_posts', 10, 2 ); | |
/** | |
* Add "not_in" arg to Display Posts Shortcode | |
* | |
* @since 1.0.0 | |
* | |
* @param array $args Default Display Posts Shortcode args. | |
* @param array $atts Original shortcode attributes. | |
* @return array $args Modified Display Posts Shortcode args. | |
*/ | |
function dpse_shortcode_exclude_posts( $args, $atts ) { | |
if( isset( $atts['not_in'] ) ) { | |
$args['post__not_in'] = explode( ',', $atts['not_in'] ); | |
} | |
return $args; | |
} | |
add_action( 'update_option_active_sitewide_plugins', 'dpse_deactivate_self', 10, 2 ); | |
add_action( 'update_option_active_plugins', 'dpse_deactivate_self', 10, 2 ); | |
/** | |
* Deactivate ourself if Addthis is deactivated. | |
*/ | |
function dpse_deactivate_self( $plugin, $network_deactivating ) { | |
if ( !is_plugin_active( 'display-posts-shortcode/display-posts-shortcode.php' ) ) { | |
deactivate_plugins( plugin_basename( __FILE__ ), true ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display Posts Shortcode Extension Plugin | |
* | |
* @package DT_Display_Posts | |
* @author Travis Smith <t@wpsmith.net> | |
* @license GPL-2.0+ | |
* @link http://wpsmith.net | |
* @link http://wordpress.org/plugins/display-posts-shortcode/ | |
* @copyright 2014 Travis Smith | |
* | |
* @wordpress-plugin | |
* Plugin Name: Display Posts Shortcode - My Extension | |
* Plugin URI: http://www.wpsmith.net | |
* Description: Extends Display Posts Shortcode | |
* Version: 1.0.0 | |
* Author: Travis Smith | |
* Author URI: http://www.wpsmith.net | |
* Text Domain: displayposts-ext | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
* Domain Path: /languages | |
*/ | |
add_filter( 'display_posts_shortcode_args', 'dpse_shortcode_exclude_posts', 10, 2 ); | |
/** | |
* Add "not_in" arg to Display Posts Shortcode | |
* | |
* @since 1.0.0 | |
* | |
* @param array $args Default Display Posts Shortcode args. | |
* @param array $atts Original shortcode attributes. | |
* @return array $args Modified Display Posts Shortcode args. | |
*/ | |
function dpse_shortcode_exclude_posts( $args, $atts ) { | |
if( isset( $atts['not_in'] ) ) { | |
$args['post__not_in'] = explode( ',', $atts['not_in'] ); | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See the two part tutorials here: http://wpsmith.net/2014/wp/extending-modifying-plugin/ & http://wpsmith.net/2014/wp/deactivate-plugin-extension-extended-plugin/