Changeset 1399901
- Timestamp:
- 04/20/2016 04:45:47 AM (10 years ago)
- Location:
- get-post-content-shortcode
- Files:
-
- 2 added
- 6 edited
- 1 copied
-
tags/0.4.0 (copied) (copied from get-post-content-shortcode/trunk)
-
tags/0.4.0/.editorconfig (modified) (1 diff)
-
tags/0.4.0/composer.json (added)
-
tags/0.4.0/get-post-content-shortcode.php (modified) (3 diffs)
-
tags/0.4.0/readme.txt (modified) (4 diffs)
-
trunk/.editorconfig (modified) (1 diff)
-
trunk/composer.json (added)
-
trunk/get-post-content-shortcode.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
get-post-content-shortcode/tags/0.4.0/.editorconfig
r1152503 r1399901 5 5 insert_final_newline = true 6 6 indent_style = space 7 indent_size = 2 8 trim_trailing_whitespace = true 9 10 [*.php] 7 11 indent_size = 4 8 trim_trailing_whitespace = true -
get-post-content-shortcode/tags/0.4.0/get-post-content-shortcode.php
r1160098 r1399901 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.27 Version: 0.4.0 8 8 Author: Eric King 9 9 Author URI: http://webdeveric.com/ 10 10 */ 11 11 12 if ( ! function_exists('is_yes') ): 12 if (! 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 } 13 21 14 function is_yes( $arg ) 22 if (! function_exists('split_comma')) { 23 function split_comma($csv) 15 24 { 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)); 20 26 } 27 } 21 28 22 endif; 29 function wde_post_content_status($status = '', $default_status = 'publish') 30 { 31 $valid_fields = array_intersect(split_comma($status), get_post_stati()); 23 32 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)) { 38 34 $valid_fields[] = $default_status; 39 35 } … … 42 38 } 43 39 44 function wde_post_content_field( $field, $default_field = 'post_content')40 function wde_post_content_field($field) 45 41 { 46 42 $allowed_fields = apply_filters( … … 71 67 ); 72 68 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)) { 75 71 return $field_name; 76 72 } 77 73 } 78 74 79 return $default_field;75 return false; 80 76 } 81 77 82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' ) 78 function 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 106 function wde_get_post_content_shortcode($attributes, $shortcode_content = null, $code = '') 83 107 { 84 108 global $post; 85 109 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); 96 112 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'])) { 105 114 $original_post = $post; 106 115 107 $post = get_post( $atts['id']);116 $post = get_post($attributes['id']); 108 117 109 $content = ''; 118 if (is_a($post, 'WP_Post')) { 119 $content = get_post_field($attributes['field'], $post->ID); 110 120 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); 119 124 } 120 125 121 if ( $atts['autop']) {122 $content = wpautop( $content);126 if ($attributes['autop']) { 127 $content = wpautop($content); 123 128 } 124 125 129 } 126 127 130 } 128 131 129 132 $post = $original_post; 130 131 return $content;132 133 } 133 134 134 return '';135 return $content; 135 136 } 136 137 -
get-post-content-shortcode/tags/0.4.0/readme.txt
r1302719 r1399901 2 2 Contributors: webdeveric 3 3 Tags: post content, shortcode 4 Requires at least: 3. 0.05 Tested up to: 4. 4.06 Stable tag: 0. 3.24 Requires at least: 3.6.0 5 Tested up to: 4.5.0 6 Stable tag: 0.4.0 7 7 8 8 This plugin provides a shortcode to get the content of a post based on ID number. … … 11 11 12 12 This 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.13 By 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. 14 14 15 15 = Examples = … … 64 64 = Filters = 65 65 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.** 67 67 68 `add_filter('post-content-allowed-fields', function( $allowed_fields) {68 `add_filter('post-content-allowed-fields', function($allowed_fields) { 69 69 // Do your filtering here. 70 70 return $allowed_fields; 71 71 });` 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);` 72 86 73 87 == Installation == … … 78 92 79 93 == Changelog == 94 95 = 0.4.0 = 96 * Added a filter to allow you to specify the default values for the shortcode attributes. 80 97 81 98 = 0.3.2 = -
get-post-content-shortcode/trunk/.editorconfig
r1152503 r1399901 5 5 insert_final_newline = true 6 6 indent_style = space 7 indent_size = 2 8 trim_trailing_whitespace = true 9 10 [*.php] 7 11 indent_size = 4 8 trim_trailing_whitespace = true -
get-post-content-shortcode/trunk/get-post-content-shortcode.php
r1160098 r1399901 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.27 Version: 0.4.0 8 8 Author: Eric King 9 9 Author URI: http://webdeveric.com/ 10 10 */ 11 11 12 if ( ! function_exists('is_yes') ): 12 if (! 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 } 13 21 14 function is_yes( $arg ) 22 if (! function_exists('split_comma')) { 23 function split_comma($csv) 15 24 { 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)); 20 26 } 27 } 21 28 22 endif; 29 function wde_post_content_status($status = '', $default_status = 'publish') 30 { 31 $valid_fields = array_intersect(split_comma($status), get_post_stati()); 23 32 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)) { 38 34 $valid_fields[] = $default_status; 39 35 } … … 42 38 } 43 39 44 function wde_post_content_field( $field, $default_field = 'post_content')40 function wde_post_content_field($field) 45 41 { 46 42 $allowed_fields = apply_filters( … … 71 67 ); 72 68 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)) { 75 71 return $field_name; 76 72 } 77 73 } 78 74 79 return $default_field;75 return false; 80 76 } 81 77 82 function wde_get_post_content_shortcode( $atts, $shortcode_content = null, $code = '' ) 78 function 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 106 function wde_get_post_content_shortcode($attributes, $shortcode_content = null, $code = '') 83 107 { 84 108 global $post; 85 109 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); 96 112 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'])) { 105 114 $original_post = $post; 106 115 107 $post = get_post( $atts['id']);116 $post = get_post($attributes['id']); 108 117 109 $content = ''; 118 if (is_a($post, 'WP_Post')) { 119 $content = get_post_field($attributes['field'], $post->ID); 110 120 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); 119 124 } 120 125 121 if ( $atts['autop']) {122 $content = wpautop( $content);126 if ($attributes['autop']) { 127 $content = wpautop($content); 123 128 } 124 125 129 } 126 127 130 } 128 131 129 132 $post = $original_post; 130 131 return $content;132 133 } 133 134 134 return '';135 return $content; 135 136 } 136 137 -
get-post-content-shortcode/trunk/readme.txt
r1302719 r1399901 2 2 Contributors: webdeveric 3 3 Tags: post content, shortcode 4 Requires at least: 3. 0.05 Tested up to: 4. 4.06 Stable tag: 0. 3.24 Requires at least: 3.6.0 5 Tested up to: 4.5.0 6 Stable tag: 0.4.0 7 7 8 8 This plugin provides a shortcode to get the content of a post based on ID number. … … 11 11 12 12 This 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.13 By 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. 14 14 15 15 = Examples = … … 64 64 = Filters = 65 65 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.** 67 67 68 `add_filter('post-content-allowed-fields', function( $allowed_fields) {68 `add_filter('post-content-allowed-fields', function($allowed_fields) { 69 69 // Do your filtering here. 70 70 return $allowed_fields; 71 71 });` 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);` 72 86 73 87 == Installation == … … 78 92 79 93 == Changelog == 94 95 = 0.4.0 = 96 * Added a filter to allow you to specify the default values for the shortcode attributes. 80 97 81 98 = 0.3.2 =
Note: See TracChangeset
for help on using the changeset viewer.