Changeset 1160098
- Timestamp:
- 05/14/2015 03:43:06 AM (11 years ago)
- Location:
- get-post-content-shortcode
- Files:
-
- 4 edited
- 1 copied
-
tags/0.3.2 (copied) (copied from get-post-content-shortcode/trunk)
-
tags/0.3.2/get-post-content-shortcode.php (modified) (6 diffs)
-
tags/0.3.2/readme.txt (modified) (4 diffs)
-
trunk/get-post-content-shortcode.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
get-post-content-shortcode/tags/0.3.2/get-post-content-shortcode.php
r1152503 r1160098 5 5 Plugin URI: http://phplug.in/ 6 6 Description: This plugin provides a shortcode to get the content of a post based on ID number. 7 Version: 0.3. 17 Version: 0.3.2 8 8 Author: Eric King 9 9 Author URI: http://webdeveric.com/ … … 31 31 endif; 32 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 ) ) { 38 $valid_fields[] = $default_status; 39 } 40 41 return $valid_fields; 42 } 43 44 function 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 33 82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' ) 34 83 { … … 40 89 'autop' => true, 41 90 'shortcode' => true, 91 'field' => 'post_content', 42 92 'status' => 'publish' 43 93 ), … … 48 98 $atts['autop'] = is_yes( $atts['autop'] ); 49 99 $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'] ); 51 102 52 103 if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) { … … 60 111 if ( is_a( $post, 'WP_Post' ) ) { 61 112 62 $content = $post->post_content;113 $content = get_post_field( $atts['field'], $post->ID ); 63 114 64 if ($atts['shortcode']) { 65 $content = do_shortcode($content); 66 } 115 if ( ! empty( $content ) ) { 67 116 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 70 125 } 71 126 … … 79 134 return ''; 80 135 } 136 81 137 add_shortcode('post-content', 'wde_get_post_content_shortcode'); -
get-post-content-shortcode/tags/0.3.2/readme.txt
r1152503 r1160098 4 4 Requires at least: 3.0.0 5 5 Tested up to: 4.2.0 6 Stable tag: 0.3. 16 Stable tag: 0.3.2 7 7 8 8 This plugin provides a shortcode to get the content of a post based on ID number. … … 13 13 The content will be passed through wpautop and do_shortcode unless you tell it not to. 14 14 15 **Examples:** 15 = Examples = 16 16 17 17 `[post-content id="42"]` … … 29 29 `[post-content id="42" status="publish,future"]` 30 30 This 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".32 31 33 The possible statuses are: publish, pending, draft, auto-draft, future, private, inherit, trash 32 `[post-content id="42" field="excerpt"]` 33 This gets the excerpt of post 42. 34 34 35 35 **Note:** 36 36 The containing post may still have wpautop called on it's content. 37 38 = Attributes = 39 40 1. **id** - integer 41 42 The post ID 43 44 1. **autop** - boolean - default: true 45 46 The following values equal true: true, 1, yes. All other values equal false. 47 48 1. **shortcode** - boolean - default: true 49 50 The following values equal true: true, 1, yes. All other values equal false. 51 52 1. **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 58 1. **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 66 You 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 });` 37 72 38 73 == Installation == … … 43 78 44 79 == Changelog == 80 81 = 0.3.2 = 82 * Added `field` attribute so you can specify what content to return. 45 83 46 84 = 0.3.1 = -
get-post-content-shortcode/trunk/get-post-content-shortcode.php
r1152503 r1160098 5 5 Plugin URI: http://phplug.in/ 6 6 Description: This plugin provides a shortcode to get the content of a post based on ID number. 7 Version: 0.3. 17 Version: 0.3.2 8 8 Author: Eric King 9 9 Author URI: http://webdeveric.com/ … … 31 31 endif; 32 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 ) ) { 38 $valid_fields[] = $default_status; 39 } 40 41 return $valid_fields; 42 } 43 44 function 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 33 82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' ) 34 83 { … … 40 89 'autop' => true, 41 90 'shortcode' => true, 91 'field' => 'post_content', 42 92 'status' => 'publish' 43 93 ), … … 48 98 $atts['autop'] = is_yes( $atts['autop'] ); 49 99 $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'] ); 51 102 52 103 if ( isset( $post, $post->ID ) && $post->ID != $atts['id'] && in_array( get_post_status( $atts['id'] ), $atts['status'] ) ) { … … 60 111 if ( is_a( $post, 'WP_Post' ) ) { 61 112 62 $content = $post->post_content;113 $content = get_post_field( $atts['field'], $post->ID ); 63 114 64 if ($atts['shortcode']) { 65 $content = do_shortcode($content); 66 } 115 if ( ! empty( $content ) ) { 67 116 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 70 125 } 71 126 … … 79 134 return ''; 80 135 } 136 81 137 add_shortcode('post-content', 'wde_get_post_content_shortcode'); -
get-post-content-shortcode/trunk/readme.txt
r1152503 r1160098 4 4 Requires at least: 3.0.0 5 5 Tested up to: 4.2.0 6 Stable tag: 0.3. 16 Stable tag: 0.3.2 7 7 8 8 This plugin provides a shortcode to get the content of a post based on ID number. … … 13 13 The content will be passed through wpautop and do_shortcode unless you tell it not to. 14 14 15 **Examples:** 15 = Examples = 16 16 17 17 `[post-content id="42"]` … … 29 29 `[post-content id="42" status="publish,future"]` 30 30 This 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".32 31 33 The possible statuses are: publish, pending, draft, auto-draft, future, private, inherit, trash 32 `[post-content id="42" field="excerpt"]` 33 This gets the excerpt of post 42. 34 34 35 35 **Note:** 36 36 The containing post may still have wpautop called on it's content. 37 38 = Attributes = 39 40 1. **id** - integer 41 42 The post ID 43 44 1. **autop** - boolean - default: true 45 46 The following values equal true: true, 1, yes. All other values equal false. 47 48 1. **shortcode** - boolean - default: true 49 50 The following values equal true: true, 1, yes. All other values equal false. 51 52 1. **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 58 1. **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 66 You 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 });` 37 72 38 73 == Installation == … … 43 78 44 79 == Changelog == 80 81 = 0.3.2 = 82 * Added `field` attribute so you can specify what content to return. 45 83 46 84 = 0.3.1 =
Note: See TracChangeset
for help on using the changeset viewer.