Plugin Directory

Changeset 1399901


Ignore:
Timestamp:
04/20/2016 04:45:47 AM (10 years ago)
Author:
webdeveric
Message:

Tagging version 0.4.0

Location:
get-post-content-shortcode
Files:
2 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • get-post-content-shortcode/tags/0.4.0/.editorconfig

    r1152503 r1399901  
    55insert_final_newline = true
    66indent_style = space
     7indent_size = 2
     8trim_trailing_whitespace = true
     9
     10[*.php]
    711indent_size = 4
    8 trim_trailing_whitespace = true
  • get-post-content-shortcode/tags/0.4.0/get-post-content-shortcode.php

    r1160098 r1399901  
    55Plugin URI: http://phplug.in/
    66Description: This plugin provides a shortcode to get the content of a post based on ID number.
    7 Version: 0.3.2
     7Version: 0.4.0
    88Author: Eric King
    99Author URI: http://webdeveric.com/
    1010*/
    1111
    12 if ( ! function_exists('is_yes') ):
     12if (! function_exists('is_yes')) {
     13    function is_yes($arg)
     14    {
     15        if (is_string($arg)) {
     16            $arg = strtolower($arg);
     17        }
     18        return in_array($arg, array( true, 'true', 'yes', 'y', '1', 1 ), true);
     19    }
     20}
    1321
    14     function is_yes( $arg )
     22if (! function_exists('split_comma')) {
     23    function split_comma($csv)
    1524    {
    16         if ( is_string($arg ) ) {
    17             $arg = strtolower( $arg );
    18         }
    19         return in_array( $arg, array( true, 'true', 'yes', 'y', '1', 1 ), true );
     25        return array_map('trim', explode(',', $csv));
    2026    }
     27}
    2128
    22 endif;
     29function wde_post_content_status($status = '', $default_status = 'publish')
     30{
     31    $valid_fields = array_intersect(split_comma($status), get_post_stati());
    2332
    24 if ( ! function_exists('split_comma') ):
    25 
    26     function split_comma( $csv )
    27     {
    28         return array_map( 'trim', explode( ',', $csv ) );
    29     }
    30 
    31 endif;
    32 
    33 function wde_post_content_status( $status = '', $default_status = 'publish' )
    34 {
    35     $valid_fields = array_intersect( split_comma( $status ), get_post_stati() );
    36 
    37     if ( empty( $valid_fields ) ) {
     33    if (empty($valid_fields)) {
    3834        $valid_fields[] = $default_status;
    3935    }
     
    4238}
    4339
    44 function wde_post_content_field( $field, $default_field = 'post_content' )
     40function wde_post_content_field($field)
    4541{
    4642    $allowed_fields = apply_filters(
     
    7167    );
    7268
    73     foreach ( array( $field, 'post_' . $field ) as $field_name ) {
    74         if ( in_array( $field_name, $allowed_fields ) ) {
     69    foreach (array( $field, 'post_' . $field ) as $field_name) {
     70        if (in_array($field_name, $allowed_fields)) {
    7571            return $field_name;
    7672        }
    7773    }
    7874
    79     return $default_field;
     75    return false;
    8076}
    8177
    82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' )
     78function wde_get_post_content_shortcode_attributes($attributes = array())
     79{
     80    $default_attributes = array(
     81        'id'        => 0,
     82        'autop'     => true,
     83        'shortcode' => true,
     84        'field'     => 'post_content',
     85        'status'    => 'publish'
     86    );
     87
     88    $attributes = shortcode_atts(
     89        array_merge(
     90            $default_attributes,
     91            apply_filters('post-content-default-attributes', $default_attributes)
     92        ),
     93        $attributes,
     94        'post-content'
     95    );
     96
     97    return array(
     98        'id'        => (int)$attributes['id'],
     99        'autop'     => is_yes($attributes['autop']),
     100        'shortcode' => is_yes($attributes['shortcode']),
     101        'field'     => wde_post_content_field($attributes['field']),
     102        'status'    => wde_post_content_status($attributes['status'])
     103    );
     104}
     105
     106function wde_get_post_content_shortcode($attributes, $shortcode_content = null, $code = '')
    83107{
    84108    global $post;
    85109
    86     $atts = shortcode_atts(
    87         array(
    88             'id'        => 0,
    89             'autop'     => true,
    90             'shortcode' => true,
    91             'field'     => 'post_content',
    92             'status'    => 'publish'
    93         ),
    94         $atts
    95     );
     110    $content = '';
     111    $attributes = wde_get_post_content_shortcode_attributes($attributes);
    96112
    97     $atts['id']        = (int)$atts['id'];
    98     $atts['autop']     = is_yes( $atts['autop'] );
    99     $atts['shortcode'] = is_yes( $atts['shortcode'] );
    100     $atts['field']     = wde_post_content_field( $atts['field'] );
    101     $atts['status']    = wde_post_content_status( $atts['status'] );
    102 
    103     if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) {
    104 
     113    if ($attributes['field'] && get_the_ID() !== $attributes['id'] && in_array(get_post_status($attributes['id']), $attributes['status'])) {
    105114        $original_post = $post;
    106115
    107         $post = get_post( $atts['id'] );
     116        $post = get_post($attributes['id']);
    108117
    109         $content = '';
     118        if (is_a($post, 'WP_Post')) {
     119            $content = get_post_field($attributes['field'], $post->ID);
    110120
    111         if ( is_a( $post, 'WP_Post' ) ) {
    112 
    113             $content = get_post_field( $atts['field'], $post->ID );
    114 
    115             if ( ! empty( $content ) ) {
    116 
    117                 if ( $atts['shortcode'] ) {
    118                     $content = do_shortcode( $content );
     121            if (! empty($content)) {
     122                if ($attributes['shortcode']) {
     123                    $content = do_shortcode($content);
    119124                }
    120125
    121                 if ( $atts['autop'] ) {
    122                     $content = wpautop( $content );
     126                if ($attributes['autop']) {
     127                    $content = wpautop($content);
    123128                }
    124 
    125129            }
    126 
    127130        }
    128131
    129132        $post = $original_post;
    130 
    131         return $content;
    132133    }
    133134
    134     return '';
     135    return $content;
    135136}
    136137
  • get-post-content-shortcode/tags/0.4.0/readme.txt

    r1302719 r1399901  
    22Contributors: webdeveric
    33Tags: post content, shortcode
    4 Requires at least: 3.0.0
    5 Tested up to: 4.4.0
    6 Stable tag: 0.3.2
     4Requires at least: 3.6.0
     5Tested up to: 4.5.0
     6Stable tag: 0.4.0
    77
    88This plugin provides a shortcode to get the content of a post based on ID number.
     
    1111
    1212This plugin provides a shortcode to get the content of a post based on ID number.
    13 The content will be passed through wpautop and do_shortcode unless you tell it not to.
     13By default, the content will be passed through `wpautop()` and `do_shortcode()` unless you tell it not to by using attributes or filters as shown below.
    1414
    1515= Examples =
     
    6464= Filters =
    6565
    66 You can modify the fields that are allowed to be retrieved with this filter.
     66**You can modify the fields that are allowed to be retrieved with this filter.**
    6767
    68 `add_filter('post-content-allowed-fields', function( $allowed_fields ) {
     68`add_filter('post-content-allowed-fields', function($allowed_fields) {
    6969    // Do your filtering here.
    7070    return $allowed_fields;
    7171});`
     72
     73**You can specify the default shortcode attribute values.**
     74
     75`add_filter('post-content-default-attributes', function ($default_attributes) {
     76    // Your code here.
     77    return $default_attributes;
     78});`
     79
     80**You can filter attributes per shortcode usage**
     81
     82`add_filter('shortcode_atts_post-content', function ($out, $pairs, $attributes) {
     83    // Your code here.
     84    return $out;
     85}, 10, 3);`
    7286
    7387== Installation ==
     
    7892
    7993== Changelog ==
     94
     95= 0.4.0 =
     96* Added a filter to allow you to specify the default values for the shortcode attributes.
    8097
    8198= 0.3.2 =
  • get-post-content-shortcode/trunk/.editorconfig

    r1152503 r1399901  
    55insert_final_newline = true
    66indent_style = space
     7indent_size = 2
     8trim_trailing_whitespace = true
     9
     10[*.php]
    711indent_size = 4
    8 trim_trailing_whitespace = true
  • get-post-content-shortcode/trunk/get-post-content-shortcode.php

    r1160098 r1399901  
    55Plugin URI: http://phplug.in/
    66Description: This plugin provides a shortcode to get the content of a post based on ID number.
    7 Version: 0.3.2
     7Version: 0.4.0
    88Author: Eric King
    99Author URI: http://webdeveric.com/
    1010*/
    1111
    12 if ( ! function_exists('is_yes') ):
     12if (! function_exists('is_yes')) {
     13    function is_yes($arg)
     14    {
     15        if (is_string($arg)) {
     16            $arg = strtolower($arg);
     17        }
     18        return in_array($arg, array( true, 'true', 'yes', 'y', '1', 1 ), true);
     19    }
     20}
    1321
    14     function is_yes( $arg )
     22if (! function_exists('split_comma')) {
     23    function split_comma($csv)
    1524    {
    16         if ( is_string($arg ) ) {
    17             $arg = strtolower( $arg );
    18         }
    19         return in_array( $arg, array( true, 'true', 'yes', 'y', '1', 1 ), true );
     25        return array_map('trim', explode(',', $csv));
    2026    }
     27}
    2128
    22 endif;
     29function wde_post_content_status($status = '', $default_status = 'publish')
     30{
     31    $valid_fields = array_intersect(split_comma($status), get_post_stati());
    2332
    24 if ( ! function_exists('split_comma') ):
    25 
    26     function split_comma( $csv )
    27     {
    28         return array_map( 'trim', explode( ',', $csv ) );
    29     }
    30 
    31 endif;
    32 
    33 function wde_post_content_status( $status = '', $default_status = 'publish' )
    34 {
    35     $valid_fields = array_intersect( split_comma( $status ), get_post_stati() );
    36 
    37     if ( empty( $valid_fields ) ) {
     33    if (empty($valid_fields)) {
    3834        $valid_fields[] = $default_status;
    3935    }
     
    4238}
    4339
    44 function wde_post_content_field( $field, $default_field = 'post_content' )
     40function wde_post_content_field($field)
    4541{
    4642    $allowed_fields = apply_filters(
     
    7167    );
    7268
    73     foreach ( array( $field, 'post_' . $field ) as $field_name ) {
    74         if ( in_array( $field_name, $allowed_fields ) ) {
     69    foreach (array( $field, 'post_' . $field ) as $field_name) {
     70        if (in_array($field_name, $allowed_fields)) {
    7571            return $field_name;
    7672        }
    7773    }
    7874
    79     return $default_field;
     75    return false;
    8076}
    8177
    82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' )
     78function wde_get_post_content_shortcode_attributes($attributes = array())
     79{
     80    $default_attributes = array(
     81        'id'        => 0,
     82        'autop'     => true,
     83        'shortcode' => true,
     84        'field'     => 'post_content',
     85        'status'    => 'publish'
     86    );
     87
     88    $attributes = shortcode_atts(
     89        array_merge(
     90            $default_attributes,
     91            apply_filters('post-content-default-attributes', $default_attributes)
     92        ),
     93        $attributes,
     94        'post-content'
     95    );
     96
     97    return array(
     98        'id'        => (int)$attributes['id'],
     99        'autop'     => is_yes($attributes['autop']),
     100        'shortcode' => is_yes($attributes['shortcode']),
     101        'field'     => wde_post_content_field($attributes['field']),
     102        'status'    => wde_post_content_status($attributes['status'])
     103    );
     104}
     105
     106function wde_get_post_content_shortcode($attributes, $shortcode_content = null, $code = '')
    83107{
    84108    global $post;
    85109
    86     $atts = shortcode_atts(
    87         array(
    88             'id'        => 0,
    89             'autop'     => true,
    90             'shortcode' => true,
    91             'field'     => 'post_content',
    92             'status'    => 'publish'
    93         ),
    94         $atts
    95     );
     110    $content = '';
     111    $attributes = wde_get_post_content_shortcode_attributes($attributes);
    96112
    97     $atts['id']        = (int)$atts['id'];
    98     $atts['autop']     = is_yes( $atts['autop'] );
    99     $atts['shortcode'] = is_yes( $atts['shortcode'] );
    100     $atts['field']     = wde_post_content_field( $atts['field'] );
    101     $atts['status']    = wde_post_content_status( $atts['status'] );
    102 
    103     if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) {
    104 
     113    if ($attributes['field'] && get_the_ID() !== $attributes['id'] && in_array(get_post_status($attributes['id']), $attributes['status'])) {
    105114        $original_post = $post;
    106115
    107         $post = get_post( $atts['id'] );
     116        $post = get_post($attributes['id']);
    108117
    109         $content = '';
     118        if (is_a($post, 'WP_Post')) {
     119            $content = get_post_field($attributes['field'], $post->ID);
    110120
    111         if ( is_a( $post, 'WP_Post' ) ) {
    112 
    113             $content = get_post_field( $atts['field'], $post->ID );
    114 
    115             if ( ! empty( $content ) ) {
    116 
    117                 if ( $atts['shortcode'] ) {
    118                     $content = do_shortcode( $content );
     121            if (! empty($content)) {
     122                if ($attributes['shortcode']) {
     123                    $content = do_shortcode($content);
    119124                }
    120125
    121                 if ( $atts['autop'] ) {
    122                     $content = wpautop( $content );
     126                if ($attributes['autop']) {
     127                    $content = wpautop($content);
    123128                }
    124 
    125129            }
    126 
    127130        }
    128131
    129132        $post = $original_post;
    130 
    131         return $content;
    132133    }
    133134
    134     return '';
     135    return $content;
    135136}
    136137
  • get-post-content-shortcode/trunk/readme.txt

    r1302719 r1399901  
    22Contributors: webdeveric
    33Tags: post content, shortcode
    4 Requires at least: 3.0.0
    5 Tested up to: 4.4.0
    6 Stable tag: 0.3.2
     4Requires at least: 3.6.0
     5Tested up to: 4.5.0
     6Stable tag: 0.4.0
    77
    88This plugin provides a shortcode to get the content of a post based on ID number.
     
    1111
    1212This plugin provides a shortcode to get the content of a post based on ID number.
    13 The content will be passed through wpautop and do_shortcode unless you tell it not to.
     13By default, the content will be passed through `wpautop()` and `do_shortcode()` unless you tell it not to by using attributes or filters as shown below.
    1414
    1515= Examples =
     
    6464= Filters =
    6565
    66 You can modify the fields that are allowed to be retrieved with this filter.
     66**You can modify the fields that are allowed to be retrieved with this filter.**
    6767
    68 `add_filter('post-content-allowed-fields', function( $allowed_fields ) {
     68`add_filter('post-content-allowed-fields', function($allowed_fields) {
    6969    // Do your filtering here.
    7070    return $allowed_fields;
    7171});`
     72
     73**You can specify the default shortcode attribute values.**
     74
     75`add_filter('post-content-default-attributes', function ($default_attributes) {
     76    // Your code here.
     77    return $default_attributes;
     78});`
     79
     80**You can filter attributes per shortcode usage**
     81
     82`add_filter('shortcode_atts_post-content', function ($out, $pairs, $attributes) {
     83    // Your code here.
     84    return $out;
     85}, 10, 3);`
    7286
    7387== Installation ==
     
    7892
    7993== Changelog ==
     94
     95= 0.4.0 =
     96* Added a filter to allow you to specify the default values for the shortcode attributes.
    8097
    8198= 0.3.2 =
Note: See TracChangeset for help on using the changeset viewer.