Plugin Directory

Changeset 1160098


Ignore:
Timestamp:
05/14/2015 03:43:06 AM (11 years ago)
Author:
webdeveric
Message:

tagging version 0.3.2

Location:
get-post-content-shortcode
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • get-post-content-shortcode/tags/0.3.2/get-post-content-shortcode.php

    r1152503 r1160098  
    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.1
     7Version: 0.3.2
    88Author: Eric King
    99Author URI: http://webdeveric.com/
     
    3131endif;
    3232
     33function 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 ) ) {
     38        $valid_fields[] = $default_status;
     39    }
     40
     41    return $valid_fields;
     42}
     43
     44function wde_post_content_field( $field, $default_field = 'post_content' )
     45{
     46    $allowed_fields = apply_filters(
     47        'post-content-allowed-fields',
     48        array(
     49            'post_author',
     50            'post_date',
     51            'post_date_gmt',
     52            'post_content',
     53            'post_title',
     54            'post_excerpt',
     55            'post_status',
     56            'comment_status',
     57            'ping_status',
     58            'post_name',
     59            'to_ping',
     60            'pinged',
     61            'post_modified',
     62            'post_modified_gmt',
     63            'post_content_filtered',
     64            'post_parent',
     65            'guid',
     66            'menu_order',
     67            'post_type',
     68            'post_mime_type',
     69            'comment_count'
     70        )
     71    );
     72
     73    foreach ( array( $field, 'post_' . $field ) as $field_name ) {
     74        if ( in_array( $field_name, $allowed_fields ) ) {
     75            return $field_name;
     76        }
     77    }
     78
     79    return $default_field;
     80}
     81
    3382function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' )
    3483{
     
    4089            'autop'     => true,
    4190            'shortcode' => true,
     91            'field'     => 'post_content',
    4292            'status'    => 'publish'
    4393        ),
     
    4898    $atts['autop']     = is_yes( $atts['autop'] );
    4999    $atts['shortcode'] = is_yes( $atts['shortcode'] );
    50     $atts['status']    = split_comma( $atts['status'] );
     100    $atts['field']     = wde_post_content_field( $atts['field'] );
     101    $atts['status']    = wde_post_content_status( $atts['status'] );
    51102
    52103    if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) {
     
    60111        if ( is_a( $post, 'WP_Post' ) ) {
    61112
    62             $content = $post->post_content;
     113            $content = get_post_field( $atts['field'], $post->ID );
    63114
    64             if ($atts['shortcode']) {
    65                 $content = do_shortcode($content);
    66             }
     115            if ( ! empty( $content ) ) {
    67116
    68             if ($atts['autop']) {
    69                 $content = wpautop($content);
     117                if ( $atts['shortcode'] ) {
     118                    $content = do_shortcode( $content );
     119                }
     120
     121                if ( $atts['autop'] ) {
     122                    $content = wpautop( $content );
     123                }
     124
    70125            }
    71126
     
    79134    return '';
    80135}
     136
    81137add_shortcode('post-content', 'wde_get_post_content_shortcode');
  • get-post-content-shortcode/tags/0.3.2/readme.txt

    r1152503 r1160098  
    44Requires at least: 3.0.0
    55Tested up to: 4.2.0
    6 Stable tag: 0.3.1
     6Stable tag: 0.3.2
    77
    88This plugin provides a shortcode to get the content of a post based on ID number.
     
    1313The content will be passed through wpautop and do_shortcode unless you tell it not to.
    1414
    15 **Examples:**
     15= Examples =
    1616
    1717`[post-content id="42"]`
     
    2929`[post-content id="42" status="publish,future"]`
    3030This gets the content of post 42 only if the post_status is "publish" or "future".
    31 If you omit the status, it will default to "publish".
    3231
    33 The possible statuses are: publish, pending, draft, auto-draft, future, private, inherit, trash
     32`[post-content id="42" field="excerpt"]`
     33This gets the excerpt of post 42.
    3434
    3535**Note:**
    3636The containing post may still have wpautop called on it's content.
     37
     38= Attributes =
     39
     401. **id** - integer
     41
     42   The post ID
     43
     441. **autop** - boolean - default: true
     45
     46   The following values equal true: true, 1, yes. All other values equal false.
     47
     481. **shortcode** - boolean - default: true
     49
     50   The following values equal true: true, 1, yes. All other values equal false.
     51
     521. **status** - text - default: publish
     53
     54   Any default or custom WordPress status value (publish, draft, future, etc.).
     55
     56   The default value will be used if the status is not registered with WordPress.
     57
     581. **field** - text - default: post_content
     59
     60   The name of the database column you want to retrieve.
     61
     62   This default value will be used if the column name is not in the array of allowed field names.
     63
     64= Filters =
     65
     66You can modify the fields that are allowed to be retrieved with this filter.
     67
     68`add_filter('post-content-allowed-fields', function( $allowed_fields ) {
     69    // Do your filtering here.
     70    return $allowed_fields;
     71});`
    3772
    3873== Installation ==
     
    4378
    4479== Changelog ==
     80
     81= 0.3.2 =
     82* Added `field` attribute so you can specify what content to return.
    4583
    4684= 0.3.1 =
  • get-post-content-shortcode/trunk/get-post-content-shortcode.php

    r1152503 r1160098  
    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.1
     7Version: 0.3.2
    88Author: Eric King
    99Author URI: http://webdeveric.com/
     
    3131endif;
    3232
     33function 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 ) ) {
     38        $valid_fields[] = $default_status;
     39    }
     40
     41    return $valid_fields;
     42}
     43
     44function wde_post_content_field( $field, $default_field = 'post_content' )
     45{
     46    $allowed_fields = apply_filters(
     47        'post-content-allowed-fields',
     48        array(
     49            'post_author',
     50            'post_date',
     51            'post_date_gmt',
     52            'post_content',
     53            'post_title',
     54            'post_excerpt',
     55            'post_status',
     56            'comment_status',
     57            'ping_status',
     58            'post_name',
     59            'to_ping',
     60            'pinged',
     61            'post_modified',
     62            'post_modified_gmt',
     63            'post_content_filtered',
     64            'post_parent',
     65            'guid',
     66            'menu_order',
     67            'post_type',
     68            'post_mime_type',
     69            'comment_count'
     70        )
     71    );
     72
     73    foreach ( array( $field, 'post_' . $field ) as $field_name ) {
     74        if ( in_array( $field_name, $allowed_fields ) ) {
     75            return $field_name;
     76        }
     77    }
     78
     79    return $default_field;
     80}
     81
    3382function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' )
    3483{
     
    4089            'autop'     => true,
    4190            'shortcode' => true,
     91            'field'     => 'post_content',
    4292            'status'    => 'publish'
    4393        ),
     
    4898    $atts['autop']     = is_yes( $atts['autop'] );
    4999    $atts['shortcode'] = is_yes( $atts['shortcode'] );
    50     $atts['status']    = split_comma( $atts['status'] );
     100    $atts['field']     = wde_post_content_field( $atts['field'] );
     101    $atts['status']    = wde_post_content_status( $atts['status'] );
    51102
    52103    if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) {
     
    60111        if ( is_a( $post, 'WP_Post' ) ) {
    61112
    62             $content = $post->post_content;
     113            $content = get_post_field( $atts['field'], $post->ID );
    63114
    64             if ($atts['shortcode']) {
    65                 $content = do_shortcode($content);
    66             }
     115            if ( ! empty( $content ) ) {
    67116
    68             if ($atts['autop']) {
    69                 $content = wpautop($content);
     117                if ( $atts['shortcode'] ) {
     118                    $content = do_shortcode( $content );
     119                }
     120
     121                if ( $atts['autop'] ) {
     122                    $content = wpautop( $content );
     123                }
     124
    70125            }
    71126
     
    79134    return '';
    80135}
     136
    81137add_shortcode('post-content', 'wde_get_post_content_shortcode');
  • get-post-content-shortcode/trunk/readme.txt

    r1152503 r1160098  
    44Requires at least: 3.0.0
    55Tested up to: 4.2.0
    6 Stable tag: 0.3.1
     6Stable tag: 0.3.2
    77
    88This plugin provides a shortcode to get the content of a post based on ID number.
     
    1313The content will be passed through wpautop and do_shortcode unless you tell it not to.
    1414
    15 **Examples:**
     15= Examples =
    1616
    1717`[post-content id="42"]`
     
    2929`[post-content id="42" status="publish,future"]`
    3030This gets the content of post 42 only if the post_status is "publish" or "future".
    31 If you omit the status, it will default to "publish".
    3231
    33 The possible statuses are: publish, pending, draft, auto-draft, future, private, inherit, trash
     32`[post-content id="42" field="excerpt"]`
     33This gets the excerpt of post 42.
    3434
    3535**Note:**
    3636The containing post may still have wpautop called on it's content.
     37
     38= Attributes =
     39
     401. **id** - integer
     41
     42   The post ID
     43
     441. **autop** - boolean - default: true
     45
     46   The following values equal true: true, 1, yes. All other values equal false.
     47
     481. **shortcode** - boolean - default: true
     49
     50   The following values equal true: true, 1, yes. All other values equal false.
     51
     521. **status** - text - default: publish
     53
     54   Any default or custom WordPress status value (publish, draft, future, etc.).
     55
     56   The default value will be used if the status is not registered with WordPress.
     57
     581. **field** - text - default: post_content
     59
     60   The name of the database column you want to retrieve.
     61
     62   This default value will be used if the column name is not in the array of allowed field names.
     63
     64= Filters =
     65
     66You can modify the fields that are allowed to be retrieved with this filter.
     67
     68`add_filter('post-content-allowed-fields', function( $allowed_fields ) {
     69    // Do your filtering here.
     70    return $allowed_fields;
     71});`
    3772
    3873== Installation ==
     
    4378
    4479== Changelog ==
     80
     81= 0.3.2 =
     82* Added `field` attribute so you can specify what content to return.
    4583
    4684= 0.3.1 =
Note: See TracChangeset for help on using the changeset viewer.