Changeset 2950856
- Timestamp:
- 08/09/2023 04:51:09 PM (3 years ago)
- Location:
- plus-features-for-advanced-custom-fields
- Files:
-
- 90 added
- 5 edited
-
tags/1.2.0 (added)
-
tags/1.2.0/LICENSE.txt (added)
-
tags/1.2.0/README.txt (added)
-
tags/1.2.0/acfp.php (added)
-
tags/1.2.0/admin (added)
-
tags/1.2.0/admin/class-acfp-admin.php (added)
-
tags/1.2.0/admin/css (added)
-
tags/1.2.0/admin/css/acfp-admin.css (added)
-
tags/1.2.0/admin/index.php (added)
-
tags/1.2.0/admin/js (added)
-
tags/1.2.0/admin/js/acfp-admin.js (added)
-
tags/1.2.0/admin/partials (added)
-
tags/1.2.0/admin/partials/acfp-admin-display.php (added)
-
tags/1.2.0/assets (added)
-
tags/1.2.0/assets/build (added)
-
tags/1.2.0/assets/build/css (added)
-
tags/1.2.0/assets/build/css/acfp-field-dual-range-slider.min.css (added)
-
tags/1.2.0/assets/build/css/acfp-field-dual-range-slider.min.css.map (added)
-
tags/1.2.0/assets/build/css/acfp-field-dual-range-slider.scss (added)
-
tags/1.2.0/assets/build/js (added)
-
tags/1.2.0/assets/build/js/acfp-field-dual-range-slider.js (added)
-
tags/1.2.0/assets/build/js/acfp-field-dual-range-slider.min.js (added)
-
tags/1.2.0/assets/screenshot-1.png (added)
-
tags/1.2.0/assets/screenshot-2.png (added)
-
tags/1.2.0/assets/screenshot-3.png (added)
-
tags/1.2.0/includes (added)
-
tags/1.2.0/includes/acfp-utility.php (added)
-
tags/1.2.0/includes/class-acfp-activator.php (added)
-
tags/1.2.0/includes/class-acfp-deactivator.php (added)
-
tags/1.2.0/includes/class-acfp-i18n.php (added)
-
tags/1.2.0/includes/class-acfp-loader.php (added)
-
tags/1.2.0/includes/class-acfp.php (added)
-
tags/1.2.0/includes/fields (added)
-
tags/1.2.0/includes/fields/class-acfp-acf-field-dual-range-slider.php (added)
-
tags/1.2.0/includes/index.php (added)
-
tags/1.2.0/includes/renders (added)
-
tags/1.2.0/includes/renders/class-acfp-render-button-group.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-checkbox.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-dual-range-slider.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-email.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-file.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-image.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-link.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-number.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-oembed.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-radio.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-range.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-select.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-text.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-textarea.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-true-false.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-url.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render-wysiwyg.php (added)
-
tags/1.2.0/includes/renders/class-acfp-render.php (added)
-
tags/1.2.0/includes/renders/interface-acfp-render-field-type.php (added)
-
tags/1.2.0/includes/shortcodes (added)
-
tags/1.2.0/includes/shortcodes/class-acfp-shortcode.php (added)
-
tags/1.2.0/index.php (added)
-
tags/1.2.0/languages (added)
-
tags/1.2.0/languages/acfp.pot (added)
-
tags/1.2.0/public (added)
-
tags/1.2.0/public/class-acfp-public.php (added)
-
tags/1.2.0/public/css (added)
-
tags/1.2.0/public/css/acfp-public.css (added)
-
tags/1.2.0/public/index.php (added)
-
tags/1.2.0/public/js (added)
-
tags/1.2.0/public/js/acfp-public.js (added)
-
tags/1.2.0/public/partials (added)
-
tags/1.2.0/public/partials/acfp-public-display.php (added)
-
tags/1.2.0/uninstall.php (added)
-
trunk/README.txt (modified) (6 diffs)
-
trunk/acfp.php (modified) (2 diffs)
-
trunk/includes/acfp-utility.php (modified) (1 diff)
-
trunk/includes/class-acfp.php (modified) (2 diffs)
-
trunk/includes/renders (added)
-
trunk/includes/renders/class-acfp-render-button-group.php (added)
-
trunk/includes/renders/class-acfp-render-checkbox.php (added)
-
trunk/includes/renders/class-acfp-render-dual-range-slider.php (added)
-
trunk/includes/renders/class-acfp-render-email.php (added)
-
trunk/includes/renders/class-acfp-render-file.php (added)
-
trunk/includes/renders/class-acfp-render-image.php (added)
-
trunk/includes/renders/class-acfp-render-link.php (added)
-
trunk/includes/renders/class-acfp-render-number.php (added)
-
trunk/includes/renders/class-acfp-render-oembed.php (added)
-
trunk/includes/renders/class-acfp-render-radio.php (added)
-
trunk/includes/renders/class-acfp-render-range.php (added)
-
trunk/includes/renders/class-acfp-render-select.php (added)
-
trunk/includes/renders/class-acfp-render-text.php (added)
-
trunk/includes/renders/class-acfp-render-textarea.php (added)
-
trunk/includes/renders/class-acfp-render-true-false.php (added)
-
trunk/includes/renders/class-acfp-render-url.php (added)
-
trunk/includes/renders/class-acfp-render-wysiwyg.php (added)
-
trunk/includes/renders/class-acfp-render.php (added)
-
trunk/includes/renders/interface-acfp-render-field-type.php (added)
-
trunk/includes/shortcodes/class-acfp-shortcode.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plus-features-for-advanced-custom-fields/trunk/README.txt
r2936193 r2950856 4 4 Tags: acfp, plus, acf, advanced custom fields, dual, range, slider, input, dual range slider 5 5 Requires at least: 5.0 6 Tested up to: 6. 27 Stable tag: 1. 1.06 Tested up to: 6.3 7 Stable tag: 1.2.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 17 17 18 18 At the moment, the shortcode works on the current post and allows you to Display: 19 20 - Email **link** from ACF email field type.21 - URL **link** from ACF URL field type.22 - Number with **decimals and thousand separators** from ACF number field type.23 - Text from text, textarea, and range field types.24 19 25 20 == Installation == … … 57 52 } 58 53 59 = Shortcodes Examples = 54 == Objects supported by shortcode == 55 56 - Current Post (current_post)-> The current post where the field is placed on. 57 58 == Shortcode supported field types == 59 Below are the supported field types: 60 - text 61 - textarea 62 - email 63 - number 64 - range 65 - email 66 - url 67 - acfp_dual_range_slider 68 - image 69 - file 70 - WYSIWYG 71 - oembed 72 - select 73 - checkbox 74 - radio 75 76 == Shortcode Attributes == 77 78 = field = 79 Specifies field name or field key for the field to be retrieved. 80 **Supported in:** All supported fields 81 **Example:** field="field_name_or_key" 82 83 = object [Optional] = 84 The object where the shortcode should retrieve data from. 85 **Supported in:** All supported fields. 86 **Accepted values:** "current_post" 87 **Example:** object="current_post" 88 89 = field_type [Optional] = 90 Specifies the type of the field you are trying to retrieve. 91 **Supported in:** All supported fields 92 **Example:** field_type="text" 93 94 = empty_message [Optional] = 95 Alternative value when the field is empty. 96 **Supported in:** select, and checkbox 97 **Example:** empty_message ="No value selected." 98 99 = link_text [Optional] = 100 Clickable text to be displayed as a link instead of showing the URL. 101 **Supported in:** email, url, file 102 **Example:** link_text="Click here" 103 104 = format [Optional] = 105 Specifies the format of value to be displayed. 106 **Supported in:** checkbox, acfp_dual_range_slider, email, number, select, url 107 **Example:** in URL and email format="link", 108 in checkbox, select format="ordered_list" or format="unordered_list", 109 in number format="separators_decimals", 110 in acfp_dual_range_slider format="max" or format="min" 111 112 = decimals [Optional] = 113 The number of decimals. 114 **Supported in:** number 115 **Example:** decimals="4" 116 117 = decimal_separator [Optional] = 118 Character to be used in separating decimals. 119 **Supported in:** number 120 **Example:** decimal_separator="." 121 122 = thousands_separator [Optional] = 123 Character to be used in separating thousands. 124 **Supported in:** number 125 **Example:** decimal_separator="," 126 127 = alt [Optional] = 128 Alternative text in case the image fails to load. 129 **Supported in:** image 130 **Example:** image="my_image" 131 132 = width [Optional] = 133 Image width. 134 **Supported in:** image 135 **Example:** width="100px" 136 137 = height [Optional] = 138 Image height. 139 **Supported in:** image 140 **Example:** height="100px" 141 142 = style [Optional] = 143 Style attribute for wrapper tag. 144 **Supported in:** All supported fields 145 **Example:** style="color:green;text-align:center" 146 147 = media_sizes [Optional] = 148 Media sizes. 149 **Supported in:** image 150 **Example:** media_sizes="(max-width: 600px) 480px, 800px" 151 152 = tag_id [Optional] = 153 ID attribute for wrapper tag. 154 **Supported in:** All supported fields 155 **Example:** id="my-unique-id" 156 157 = tag_class [Optional] = 158 Class attribute for wrapper tag. 159 **Supported in:** All supported fields 160 **Example:** class="my-class-name" 161 162 = hide_if_empty [Optional] = 163 Determines whether list tags will not be shown when there is no selected value in the select or checkbox field type. 164 **Supported in:** checkbox, select 165 **Example:** hide_if_empty="true" 166 167 = ordered_list_type [Optional] = 168 Specifies the type of ordered list to be displayed. 169 **Supported in:** checkbox, select, 170 *Accepted values:** "1", "a" "A", "i" and "I". 171 **Example:** ordered_list_type="a" 172 173 = display [Optional] = 174 Specifies whether to display values or labels. 175 **Supported in:** button group, checkbox, radio, select, 176 *Accepted values:** "labels", "values". 177 **Example:** display="values" 178 179 = wrap_tag [Optional] = 180 Tag to wrap field content. 181 **Supported in:** All supported fields 182 **Example:** wrap_tag="div" 183 184 = checked_content [Optional] = 185 Content to be shown when a checkbox is checked. 186 **Supported in:** true_false 187 **Example:** checked_content="Field checked" 188 189 = unchecked_content [Optional] = 190 Content to be shown when a checkbox is unchecked. 191 **Supported in:** true_false 192 **Example:** checked_content="Field unchecked" 193 194 == Shortcodes Examples == 60 195 61 196 [acfp field="text_field_name" field_type="text"] … … 93 228 [acfp field="oembed_field_name" field_type="oembed" ] 94 229 230 [acfp field="select_field_name" field_type="select" ] 231 232 [acfp field="select_field_name" format="unordered_list" display="labels" field_type="select" ] 233 234 [acfp field="select_field_name" format="unordered_list" display="values" field_type="select" ] 235 236 [acfp field="select_field_name" format="ordered_list" display="labels" field_type="select" ] 237 238 [acfp field="select_field_name" format="ordered_list" display="values" field_type="select" ] 239 240 [acfp field="checkbox_field_name" format="ordered_list" display="values" field_type="checkbox" ] 241 242 [acfp field="checkbox_field_name" format="ordered_list" display="values" field_type="checkbox" ] 243 244 [acfp field="radio_button_field_name" display="values" field_type="radio" ] 245 246 [acfp field="radio_button_field_name" display="labels" field_type="radio" ] 247 248 [acfp field="button_group_field_name" display="labels" field_type="button_group" wrap_tag="div"] 249 250 [acfp field="button_group_field_name" display="values" wrap_tag="div"] 251 252 [acfp field="truefalse_field_name" field_type="true_false" wrap_tag="div"] 253 254 [acfp field="truefalse_field_name" field_type="true_false" wrap_tag="div" unchecked_content="Unchecked" checked_content="Checked"] 255 95 256 == Frequently Asked Questions == 96 257 97 = How can I utilize the values selected in dual range slider on my templates? =258 = How can I utilize the values selected in the dual range slider on my templates? = 98 259 99 260 You can add custom code in your template files as shown below: … … 128 289 == Changelog == 129 290 291 = 1.2.0 = 292 The field types below are now supported in acfp shortcode: 293 - text 294 - textarea 295 - email 296 - number 297 - range 298 - email 299 - url 300 - acfp_dual_range_slider 301 - image 302 - file 303 - WYSIWYG 304 - oembed 305 - select 306 - checkbox 307 - radio 308 130 309 = 1.1.0 = 131 310 Supports ACF shortcode security filters. 132 311 Added step settings to dual range slider. 133 Added shortcode support for ACF images, files, WYSIWYG, oEmbed.312 Added shortcode support for ACF images, files, WYSIWYG, and oEmbed. 134 313 Enhancement- Dual Range slider now has set settings. 135 314 … … 139 318 == Upgrade Notice == 140 319 141 = 1. 1.0 =142 Added shortcode support for ACF images, files, WYSIWYG, oEmbed.320 = 1.2.0 = 321 Supports more field types. -
plus-features-for-advanced-custom-fields/trunk/acfp.php
r2936193 r2950856 16 16 * Plugin URI: https://wordpress.org/plugins/plus-features-for-advanced-custom-fields 17 17 * Description: Adds extra features to Advanced Custom Fields plugin(ACF) 18 * Version: 1. 1.018 * Version: 1.2.0 19 19 * Author: the WP Catalyst 20 20 * Author URI: https://profiles.wordpress.org/thewpcatalyst/ … … 35 35 * Rename this for your plugin and update it as you release new versions. 36 36 */ 37 define( 'ACFP_VERSION', '1. 1.0' );37 define( 'ACFP_VERSION', '1.2.0' ); 38 38 39 39 /** -
plus-features-for-advanced-custom-fields/trunk/includes/acfp-utility.php
r2936193 r2950856 64 64 } 65 65 } 66 67 68 // helpers in render. 69 if ( ! function_exists( 'acfp_get_style_attr' ) ) { 70 /** 71 * Function to return style render content where possible. 72 * 73 * @since 1.2.0 74 * 75 * @param string $style tag class. 76 * @return string 77 */ 78 function acfp_get_style_attr( string $style ) { 79 if ( '' !== $style && false !== $style ) { 80 $style = 'style="' . esc_attr( $style ) . '" '; 81 } 82 return $style; 83 } 84 } 85 86 if ( ! function_exists( 'acfp_get_tag_id_attr' ) ) { 87 /** 88 * Function to return tag id render content where possible. 89 * 90 * @since 1.2.0 91 * 92 * @param string $tag_id tag id. 93 * @return string 94 */ 95 function acfp_get_tag_id_attr( string $tag_id ) { 96 if ( '' !== $tag_id && false !== $tag_id ) { 97 $tag_id = 'id="' . esc_attr( $tag_id ) . '" '; 98 } 99 return $tag_id; 100 } 101 } 102 103 if ( ! function_exists( 'acfp_get_width_attr' ) ) { 104 /** 105 * Function to return width render content where possible. 106 * 107 * @since 1.2.0 108 * 109 * @param string $width tag class. 110 * @return string 111 */ 112 function acfp_get_width_attr( string $width ) { 113 if ( '' !== $width && false !== $width ) { 114 $width = 'width="' . esc_attr( $width ) . '" '; 115 } 116 return $width; 117 } 118 } 119 120 if ( ! function_exists( 'acfp_get_height_attr' ) ) { 121 /** 122 * Function to return height render content where possible. 123 * 124 * @since 1.2.0 125 * 126 * @param string $height tag class. 127 * @return string 128 */ 129 function acfp_get_height_attr( string $height ) { 130 if ( '' !== $height && false !== $height ) { 131 $height = 'height="' . esc_attr( $height ) . '" '; 132 } 133 return $height; 134 } 135 } 136 137 if ( ! function_exists( 'acfp_get_class_attr' ) ) { 138 /** 139 * Function to return tag class render content where possible. 140 * 141 * @since 1.2.0 142 * 143 * @param array $classes tag classes. 144 * @return string 145 */ 146 function acfp_get_class_attr( array $classes ) { 147 $classes_str = ''; 148 foreach ( $classes as $class ) { 149 $class = trim( $class ); 150 if ( '' !== $class ) { 151 $classes_str .= $class . ' '; 152 } 153 } 154 $classes_str = trim( $classes_str ); 155 $tag_class = ''; 156 if ( '' !== $classes_str ) { 157 $tag_class = 'class="' . esc_attr( $classes_str ) . '" '; 158 } 159 return $tag_class; 160 } 161 } 162 163 if ( ! function_exists( 'acfp_get_type_attr' ) ) { 164 /** 165 * Function to return type render content where possible. 166 * 167 * @since 1.2.0 168 * 169 * @param string $type tag class. 170 * @return string 171 */ 172 function acfp_get_type_attr( string $type ) { 173 if ( '' !== $type && false !== $type ) { 174 $type = 'type="' . esc_attr( $type ) . '" '; 175 } 176 return $type; 177 } 178 } 179 180 if ( ! function_exists( 'acfp_get_ordered_list' ) ) { 181 /** 182 * Generates ordered list 183 * 184 * @since 1.2.0 185 * 186 * @param array $values values to be listed. 187 * @param string $id list id. 188 * @param array $classes classes for the list. 189 * @param string $style list css style. 190 * @param bool $hide_if_empty determines if list will be empty if no value is passed. 191 * @param string $type type of list item marker. Default 1. Accepted values A,a, I, and i. 192 * @return string 193 */ 194 function acfp_get_ordered_list( array $values, string $id, array $classes, string $style, bool $hide_if_empty = true, $type = '1' ) { 195 if ( empty( $values ) && $hide_if_empty ) { 196 return ''; 197 } 198 $list = '<ol ' . acfp_get_tag_id_attr( $id ) . acfp_get_class_attr( $classes ) . acfp_get_style_attr( $style ) . acfp_get_type_attr( $type ) . '>'; 199 foreach ( $values as $value ) { 200 $list .= acfp_get_li( $value ); 201 } 202 $list .= '</ol>'; 203 return $list; 204 } 205 } 206 207 if ( ! function_exists( 'acfp_get_unordered_list' ) ) { 208 /** 209 * Generates unordered list 210 * 211 * @since 1.2.0 212 * 213 * @param array $values values to be listed. 214 * @param string $id list id. 215 * @param array $classes classes for the list. 216 * @param string $style list css style. 217 * @param bool $hide_if_empty determines if list will be empty if no value is passed. 218 * @return string 219 */ 220 function acfp_get_unordered_list( array $values, string $id, array $classes, string $style, bool $hide_if_empty = true ) { 221 if ( empty( $values ) && $hide_if_empty ) { 222 return ''; 223 } 224 $list = '<ul ' . acfp_get_tag_id_attr( $id ) . acfp_get_class_attr( $classes ) . acfp_get_style_attr( $style ) . '>'; 225 foreach ( $values as $value ) { 226 $list .= acfp_get_li( $value ); 227 } 228 $list .= '</ul>'; 229 return $list; 230 } 231 } 232 233 if ( ! function_exists( 'acfp_get_li' ) ) { 234 /** 235 * Returns li element. 236 * 237 * @since 1.2.0 238 * 239 * @param string $inner_html inner html for li tag. 240 * @return string 241 */ 242 function acfp_get_li( string $inner_html ) { 243 return '<li>' . $inner_html . '</li>'; 244 } 245 } 246 247 if ( ! function_exists( 'acfp_get_wrap_tag' ) ) { 248 /** 249 * Wraps content in a tag. 250 * 251 * @since 1.2.0 252 * 253 * @param string $wrap_tag tag to wrap content. 254 * @param string $inner_html content to be wrapped. 255 * @param string $tag_class class to be added on the tag. 256 * @param string $tag_id id to be added on the tag. 257 * @param string $style style to be associated with tag. 258 * @return string 259 */ 260 function acfp_get_wrap_tag( string $wrap_tag, string $inner_html, string $tag_class, string $tag_id, string $style ) { 261 $wrap_tag = trim( $wrap_tag ); 262 if ( '' === $wrap_tag || 'false' === $wrap_tag || false === $wrap_tag ) { 263 return $inner_html; 264 } 265 return '<' . $wrap_tag . ' ' . acfp_get_class_attr( array( $tag_class ) ) . acfp_get_tag_id_attr( $tag_id ) . acfp_get_style_attr( $style ) . ' >' . $inner_html . '</' . $wrap_tag . '>'; 266 } 267 } 268 269 if ( ! function_exists( 'acfp_get_link_tag_html' ) ) { 270 /** 271 * Generates link tag html 272 * 273 * @since 1.2.0 274 * 275 * @param string $field_value Field value. 276 * @param string $link_text Link text. 277 * @param string $tag_class class to be added on the tag. 278 * @param string $tag_id id to be added on the tag. 279 * @param string $style style to be associated with tag. 280 * @return string 281 */ 282 function acfp_get_link_tag_html( string $field_value, string $link_text, string $tag_class, string $tag_id, string $style ) { 283 return '<a ' . acfp_get_class_attr( array( $tag_class ) ) . acfp_get_tag_id_attr( $tag_id ) . acfp_get_style_attr( $style ) . ' href="' . esc_url( $field_value ) . '">' . esc_html( $link_text ) . '</a>'; 284 } 285 } -
plus-features-for-advanced-custom-fields/trunk/includes/class-acfp.php
r2936193 r2950856 96 96 'number', 97 97 'range', 98 'email', 99 'url', 100 'acfp_dual_range_slider', 101 'image', 102 'file', 103 'wysiwyg', 104 'oembed', 105 'select', 106 'checkbox', 107 'radio', 98 108 ); 99 109 … … 157 167 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/acfp-utility.php'; 158 168 169 // render content. 170 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/interface-acfp-render-field-type.php'; 171 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render.php'; 172 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-link.php'; 173 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-select.php'; 174 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-checkbox.php'; 175 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-radio.php'; 176 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-number.php'; 177 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-oembed.php'; 178 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-wysiwyg.php'; 179 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-email.php'; 180 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-url.php'; 181 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-dual-range-slider.php'; 182 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-image.php'; 183 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-file.php'; 184 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-range.php'; 185 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-text.php'; 186 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-textarea.php'; 187 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-button-group.php'; 188 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/renders/class-acfp-render-true-false.php'; 159 189 $this->loader = new Acfp_Loader(); 160 161 190 } 162 191 -
plus-features-for-advanced-custom-fields/trunk/includes/shortcodes/class-acfp-shortcode.php
r2936193 r2950856 93 93 return; 94 94 } 95 $a = shortcode_atts( 96 array( 97 'field' => '', 98 'object' => 'current_post', // current_post. 99 'field_type' => '', // type of field being requested. 100 'empty_message' => '', 101 'field_type' => '', 102 'link_text' => '', // Used in email. 103 'format' => '', // Used in email: link. Used in number: separators_decimals. 104 'decimals' => 2, // used in number. 105 'decimal_separator' => '.', // used in number. 106 'thousands_separator' => ',', // used in number. 107 'alt' => '', // used in image. 108 'width' => '100px', // used in image. 109 'height' => '100px', // used in image. 110 'style' => '', // used in image. 111 'size' => '', // used in image. 112 'media_sizes' => '', // used in image. 113 'tag_id' => '', // used in image. 114 'tag_class' => '', // used in image. 115 ), 95 96 // phpcs:ignore WordPress.NamingConventions.ValidHookName 97 $access_already_prevented = apply_filters( 'acf/prevent_access_to_unknown_fields', false ); 98 $filter_applied = false; 99 100 if ( ! $access_already_prevented ) { 101 $filter_applied = true; 102 add_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' ); 103 } 104 105 $a = shortcode_atts( 106 $this->shortcode_pairs(), 116 107 $atts 117 108 ); 118 $content = ''; 119 $field = $a['field']; 120 $object = $a['object']; 121 $empty_message = $a['empty_message']; 122 $field_type = $a['field_type']; 123 $link_text = $a['link_text'];// Used in email,urls. 124 $format = $a['format'];// Used in email,url: link. Number: separators_decimals. File: to be added. 125 $decimals = $a['decimals'];// Used in number. 126 $decimal_separator = $a['decimal_separator'];// Used in number. 127 $thousands_separator = $a['thousands_separator'];// Used in number. 128 $alt = $a['alt'];// Used in image. 129 $width = $a['width'];// Used in image. 130 $height = $a['height'];// Used in image. 131 $style = $a['style'];// Used in image. 132 $size = $a['size'];// Used in image. 133 $media_sizes = $a['media_sizes'];// Used in image. 134 $tag_id = $a['tag_id'];// Used in email,url,image. 135 $tag_class = $a['tag_class'];// Used in email,url,image. 109 $content = ''; 110 $field = $a['field']; 111 $object = $a['object']; 112 $field_type = $a['field_type']; 136 113 137 114 if ( 'current_post' === $object ) { … … 140 117 if ( '' !== $field ) { 141 118 if ( function_exists( 'get_field' ) ) { 142 // phpcs:ignore WordPress.NamingConventions.ValidHookName143 $access_already_prevented = apply_filters( 'acf/prevent_access_to_unknown_fields', false );144 $filter_applied = false;145 146 if ( ! $access_already_prevented ) {147 $filter_applied = true;148 add_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' );149 }150 151 119 $field_value = get_field( $field, $post_id ); 152 153 if ( $filter_applied ) { 154 remove_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' ); 155 } 156 157 if ( $field_value ) { 120 if ( $field_value || is_bool( $field_value ) ) {// is_bool() allows true/false fields to be processed when unchecked. 158 121 if ( ! $field_type || ! in_array( $field_type, $this->acfp->get_shortcode_supported_field_types(), true ) ) { 159 122 // retrieve field type dynamically. … … 161 124 $field_type = $field_definitions['type']; 162 125 } 163 if ( 'text' === $field_type || 'textarea' === $field_type || 'range' === $field_type ) { 164 $content = $field_value; 165 } elseif ( 'number' === $field_type ) { 166 $content = $this->get_number_render_content( $format, $field_value, $decimals, $decimal_separator, $thousands_separator ); 167 } elseif ( 'email' === $field_type ) { 168 $content = $this->get_email_render_content( $format, $field_value, $link_text, $tag_class, $tag_id, $style ); 169 } elseif ( 'url' === $field_type ) { 170 $content = $this->get_url_render_content( $format, $field_value, $link_text, $tag_class, $tag_id, $style ); 171 } elseif ( 'acfp_dual_range_slider' === $field_type ) { 172 $content = $this->get_acfp_dual_range_slider_render_content( $format, $field_value ); 173 } elseif ( 'image' === $field_type ) { 174 $content = $this->get_image_render_content( $field_value, $tag_class, $tag_id, $alt, $width, $height, $style, $size, $media_sizes ); 175 } elseif ( 'file' === $field_type ) { 176 $content = $this->get_file_render_content( $field_value, $format, $link_text, $tag_class, $tag_id, $style ); 177 } elseif ( 'wysiwyg' === $field_type ) { 178 $content = $this->get_wysiwyg_render_content( $field_value ); 179 } elseif ( 'oembed' === $field_type ) { 180 $content = $this->get_oembed_render_content( $field_value ); 181 } 126 $content = $this->render_field_by_type( $field_type, $field_value, $a ); 182 127 } else { 183 128 $content = $empty_message; … … 187 132 } 188 133 } 134 135 if ( $filter_applied ) { 136 remove_filter( 'acf/prevent_access_to_unknown_fields', '__return_true' ); 137 } 138 189 139 return $content; 190 140 } 191 141 192 142 /** 193 * Renders number content 194 * 195 * @param string $format format to be displayed. 143 * Returns entire list of supported attributes and their defaults. 144 * 145 * @since 1.2.0 146 * 147 * @return array 148 */ 149 protected function shortcode_pairs() { 150 return array( 151 'field' => '', 152 'object' => 'current_post', // current_post. 153 'field_type' => '', // type of field being requested. 154 'empty_message' => '', 155 'field_type' => '', 156 'link_text' => '', // Used in email. 157 'format' => '', // Used in email: link. Used in number: separators_decimals. 158 'decimals' => 2, // used in number. 159 'decimal_separator' => '.', // used in number. 160 'thousands_separator' => ',', // used in number. 161 'alt' => '', // used in image. 162 'width' => '100px', // used in image. 163 'height' => '100px', // used in image. 164 'style' => '', // used in image. 165 'size' => '', // used in image. 166 'media_sizes' => '', // used in image. 167 'tag_id' => '', // used in image. 168 'tag_class' => '', // used in image. 169 'hide_if_empty' => true, 170 'ordered_list_type' => '1', 171 'display' => '', // used in select: values, labels. 172 'wrap_tag' => '', 173 'unchecked_content' => 'false', // used in true_false field type. 174 'checked_content' => 'true', // used in true_false field type. 175 ); 176 } 177 178 /** 179 * Function to render field by type. 180 * 181 * @since 1.2.0 182 * 183 * @param string $field_type field type. 196 184 * @param mixed $field_value field value. 197 * @param string $decimals number of decimals. 198 * @param string $decimal_separator character to be used as decimal separator. 199 * @param string $thousands_separator character to be used as thousand separator. 185 * @param array $a attributes. 200 186 * @return string 201 187 */ 202 public function get_number_render_content( $format, $field_value, $decimals, $decimal_separator, $thousands_separator ) { 203 if ( 'separators_decimals' === $format ) { 204 $content = number_format( $field_value, $decimals, $decimal_separator, $thousands_separator ); 205 } else { 206 $content = $field_value; 207 } 188 protected function render_field_by_type( string $field_type, $field_value, array $a ) { 189 $render = null; 190 $content = ''; 191 192 switch ( $field_type ) { 193 case 'text': 194 $render = new ACFP_Render_Text( $field_value, $a ); 195 break; 196 case 'textarea': 197 $render = new ACFP_Render_Textarea( $field_value, $a ); 198 break; 199 case 'range': 200 $render = new ACFP_Render_Range( $field_value, $a ); 201 break; 202 case 'number': 203 $render = new ACFP_Render_Number( $field_value, $a ); 204 break; 205 case 'email': 206 $render = new ACFP_Render_Email( $field_value, $a ); 207 break; 208 case 'url': 209 $render = new ACFP_Render_URL( $field_value, $a ); 210 break; 211 case 'acfp_dual_range_slider': 212 $render = new ACFP_Render_Dual_Range_Slider( $field_value, $a ); 213 break; 214 case 'image': 215 $render = new ACFP_Render_Image( $field_value, $a ); 216 break; 217 case 'file': 218 $render = new ACFP_Render_File( $field_value, $a ); 219 break; 220 case 'wysiwyg': 221 $render = new ACFP_Render_WYSIWYG( $field_value, $a ); 222 break; 223 case 'oembed': 224 $render = new ACFP_Render_Oembed( $field_value, $a ); 225 break; 226 case 'select': 227 $render = new ACFP_Render_Select( $field_value, $a ); 228 break; 229 case 'checkbox': 230 $render = new ACFP_Render_Checkbox( $field_value, $a ); 231 break; 232 case 'radio': 233 $render = new ACFP_Render_Radio( $field_value, $a ); 234 break; 235 case 'button_group': 236 $render = new ACFP_Render_Button_Group( $field_value, $a ); 237 break; 238 case 'true_false': 239 $render = new ACFP_Render_True_False( $field_value, $a ); 240 break; 241 } 242 243 if ( null !== $render ) { 244 $content = $render->get_html(); 245 } 246 208 247 return $content; 209 248 } 210 211 /**212 * Function to get email render content213 *214 * @since 1.0.0215 * @since 1.1.0216 * Added $tag_class,$tag_id,$style217 *218 * @param string $format format to be displayed.219 * @param string $field_value field value.220 * @param string $link_text text to be rendered on the page instead of the actual link.221 * @param string $tag_class tag class.222 * @param string $tag_id tag id.223 * @param string $style tag style.224 * @return string225 */226 public function get_email_render_content( $format, $field_value, $link_text, $tag_class, $tag_id, $style ) {227 if ( 'link' === $format ) {228 if ( ! $link_text ) {229 $link_text = $field_value;230 }231 $content = $this->get_link_tag_html( $field_value, $link_text, $tag_class, $tag_id, $style );232 } else {233 $content = $field_value;234 }235 return $content;236 }237 238 /**239 * Function to get url render content240 *241 * @since 1.0.0242 * @since 1.1.0243 * Added $tag_class,$tag_id,$style244 *245 * @param string $format format to be displayed.246 * @param string $field_value field value.247 * @param string $link_text text to be rendered on the page instead of the actual link.248 * @param string $tag_class tag class.249 * @param string $tag_id tag id.250 * @param string $style tag style.251 * @return string252 */253 public function get_url_render_content( $format, $field_value, $link_text, $tag_class, $tag_id, $style ) {254 if ( 'link' === $format ) {255 if ( ! $link_text ) {256 $link_text = $field_value;257 }258 $content = $this->get_link_tag_html( $field_value, $link_text, $tag_class, $tag_id, $style );259 } else {260 $content = $field_value;261 }262 return $content;263 }264 265 /**266 * Function to get dual range slider render content267 *268 * @since 1.0.0269 *270 * @param string $format format to be displayed.271 * @param string $field_value field value.272 * @return string273 */274 public function get_acfp_dual_range_slider_render_content( $format, $field_value ) {275 if ( 'min' === $format ) {276 if ( array_key_exists( 'min', $field_value ) ) {277 $content = esc_html( $field_value['min'] );278 } else {279 $content = '';280 }281 } elseif ( 'max' === $format ) {282 if ( array_key_exists( 'max', $field_value ) ) {283 $content = esc_html( $field_value['max'] );284 } else {285 $content = '';286 }287 } else {288 $content = implode( ', ', $field_value );289 }290 return $content;291 }292 293 /**294 * Function to get image render content295 *296 * @since 1.1.0297 *298 * @param string $field_value field value.299 * @param string $tag_class tag class.300 * @param string $tag_id tag id.301 * @param string $alt alternative text incase image fails to load.302 * @param int $width image width.303 * @param int $height image height.304 * @param string $style tag style.305 * @param string $size WordPress thumbnail size to be rendered.306 * @param string $media_sizes media sizes https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images.307 * @return string308 */309 public function get_image_render_content( $field_value, $tag_class, $tag_id, $alt, $width, $height, $style, $size, $media_sizes ) {310 $content = '';311 $image_width = $width;312 if ( is_int( $field_value ) ) {313 // image set to return Image ID.314 $field_value = acfp_get_attachment( $field_value );315 }316 317 if ( is_array( $field_value ) ) {318 $url = $field_value['url'];319 if ( '' === $alt ) {320 $alt = $field_value['alt'];321 }322 323 $sizes = $field_value['sizes'];324 $sizes = $this->group_wordpress_image_sizes_with_their_sizes( $sizes );325 $srcset = '';326 $srcset_added_widths = array();// init array of added widths to srcset.327 foreach ( $sizes as $size_array ) {328 $src_url = $size_array['value'];329 $size_from_url = $this->extract_image_size_from_url( $src_url );// size extracted from URL.330 $w = '';331 if ( $size_from_url ) {// size from url is given priority.332 $w = $size_from_url['width'] . 'w';333 } else {334 $w = $size_array['width_value'] . 'w';335 }336 if ( ! in_array( array( $src_url => $w ), $srcset_added_widths, true ) ) {337 array_push( $srcset_added_widths, array( $src_url => $w ) );338 }339 }340 $sizes_count = count( $srcset_added_widths );341 342 for ( $i = 0;$i < $sizes_count;$i++ ) {343 344 if ( 0 === $i ) {345 // first item.346 foreach ( $srcset_added_widths[ $i ] as $thumb_url => $width ) {347 $srcset .= $thumb_url . ' ' . $width;348 }349 } else {350 foreach ( $srcset_added_widths[ $i ] as $thumb_url => $width ) {351 $srcset .= ', ' . $thumb_url . ' ' . $width;352 }353 }354 }355 $content = '<img356 ' . $this->get_tag_class_render_content( $tag_class ) . '357 ' . $this->get_tag_id_render_content( $tag_id ) . '358 srcset="' . esc_attr( $srcset ) . '"359 src="' . esc_url( $url ) . '"360 alt="' . esc_attr( $alt ) . '"361 ' . $this->get_width_render_content( $image_width ) . '362 ' . $this->get_height_render_content( $height ) . '363 ' . $this->get_media_sizes_render_content( $media_sizes ) . '364 ' . $this->get_style_render_content( $style ) . '365 "/>';366 } elseif ( is_string( $field_value ) ) {367 $content = '<img368 ' . $this->get_tag_class_render_content( $tag_class ) . '369 ' . $this->get_tag_id_render_content( $tag_id ) . '370 src="' . esc_attr( $field_value ) . '"371 alt="' . esc_attr( $alt ) . '"372 ' . $this->get_width_render_content( $image_width ) . '373 ' . $this->get_height_render_content( $height ) . '374 ' . $this->get_style_render_content( $style ) . '/>';375 }376 377 return $content;378 379 }380 381 /**382 * Gets file html content to be rendered on front end.383 *384 * @since 1.1.0385 *386 * @param mixed $field_value field value.387 * @param string $format format.388 * @param string $link_text link text.389 * @param string $tag_class class.390 * @param string $tag_id tag id.391 * @param string $style tag style.392 * @return string393 */394 public function get_file_render_content( $field_value, string $format, string $link_text, string $tag_class, string $tag_id, string $style ) {395 if ( is_int( $field_value ) ) {396 // image set to return Image ID.397 $field_value = acfp_get_attachment( $field_value );398 }399 if ( is_array( $field_value ) ) {400 if ( ! $link_text ) {401 $link_text = $field_value['filename'];402 }403 ob_start();404 ?>405 <div class="acfp-file-container">406 <div class="file-icon">407 <img data-name="icon" src="<?php echo esc_url( $field_value['icon'] ); ?>" alt=""/>408 </div>409 <div class="file-info">410 <p>411 <strong data-name="title"><?php echo esc_html( $field_value['title'] ); ?></strong>412 </p>413 <p>414 <strong><?php esc_html_e( 'File name', 'acfp' ); ?>:</strong>415 <a data-name="filename" href="<?php echo esc_url( $field_value['url'] ); ?>" target="_blank"><?php echo esc_html( $link_text ); ?></a>416 </p>417 <p>418 <strong><?php esc_html_e( 'File size', 'acfp' ); ?>:</strong>419 <span data-name="filesize"><?php echo esc_html( size_format( $field_value['filesize'] ) ); ?></span>420 </p>421 </div>422 </div>423 <?php424 $content = ob_get_clean();425 426 } elseif ( is_string( $field_value ) ) {427 if ( ! $link_text ) {428 $link_text = $field_value;429 }430 $content = $this->get_link_tag_html( $field_value, $link_text, $tag_class, $tag_id, $style );431 }432 return $content;433 434 }435 436 /**437 * Gets render content for wysiwyg438 *439 * @param string $field_value field value.440 * @return string441 */442 public function get_wysiwyg_render_content( $field_value ) {443 return $field_value;444 }445 446 /**447 * Returns oembed render content.448 *449 * @since 1.1.0450 *451 * @param string $field_value field value.452 * @return string453 */454 public function get_oembed_render_content( $field_value ) {455 return $field_value;456 }457 458 459 /**460 * Groups returned images urls with their sizes.461 *462 * @since 1.1.0463 *464 * @param array $sizes sizes to be grouped.465 * @return array466 */467 public function group_wordpress_image_sizes_with_their_sizes( $sizes ) {468 $result = array();469 $keys = array_keys( $sizes );470 $count = count( $keys );471 472 for ( $i = 0; $i < $count; $i += 3 ) {473 $key = $keys[ $i ];474 $value = $sizes[ $key ];475 $width_key = $keys[ $i + 1 ];476 $width_value = $sizes[ $width_key ];477 $height_key = $keys[ $i + 2 ];478 $height_value = $sizes[ $height_key ];479 480 $result[] = array(481 'key' => $key,482 'value' => $value,483 'width_key' => $width_key,484 'width_value' => $width_value,485 'height_key' => $height_key,486 'height_value' => $height_value,487 );488 }489 490 return $result;491 }492 493 494 /**495 * Extracts image size from url.496 *497 * @since 1.1.0498 *499 * @param string $url WordPress image url.500 * @return array|false501 */502 public function extract_image_size_from_url( $url ) {503 $parsed_url = wp_parse_url( $url );504 505 // Check if the URL is valid and contains a path.506 if ( ! $parsed_url || empty( $parsed_url['path'] ) ) {507 return false;508 }509 510 // Extract the filename from the path.511 $filename = basename( $parsed_url['path'] );512 513 // Use regular expressions to extract the image size.514 if ( preg_match( '/-(\d+)x(\d+)\./i', $filename, $matches ) ) {515 $width = $matches[1];516 $height = $matches[2];517 return array(518 'width' => $width,519 'height' => $height,520 );521 } else {522 return false;523 }524 }525 526 /**527 * Function to return media size render content where possible.528 *529 * @since 1.1.0530 *531 * @param string $media_sizes media sizes.532 * @return string533 */534 public function get_media_sizes_render_content( string $media_sizes ) {535 if ( '' !== $media_sizes && false !== $media_sizes ) {536 $media_sizes = 'sizes="' . esc_attr( $media_sizes ) . '" ';537 }538 return $media_sizes;539 }540 541 /**542 * Function to return tag id render content where possible.543 *544 * @since 1.1.0545 *546 * @param string $tag_id tag id.547 * @return string548 */549 public function get_tag_id_render_content( string $tag_id ) {550 if ( '' !== $tag_id && false !== $tag_id ) {551 $tag_id = 'id="' . esc_attr( $tag_id ) . '" ';552 }553 return $tag_id;554 }555 556 /**557 * Function to return tag class render content where possible.558 *559 * @since 1.1.0560 *561 * @param string $tag_class tag class.562 * @return string563 */564 public function get_tag_class_render_content( string $tag_class ) {565 if ( '' !== $tag_class && false !== $tag_class ) {566 $tag_class = 'class="' . esc_attr( $tag_class ) . '" ';567 }568 return $tag_class;569 }570 571 /**572 * Function to return style render content where possible.573 *574 * @since 1.1.0575 *576 * @param string $style tag class.577 * @return string578 */579 public function get_style_render_content( string $style ) {580 if ( '' !== $style && false !== $style ) {581 $style = 'style="' . esc_attr( $style ) . '" ';582 }583 return $style;584 }585 586 /**587 * Function to return width render content where possible.588 *589 * @since 1.1.0590 *591 * @param string $width tag class.592 * @return string593 */594 public function get_width_render_content( string $width ) {595 if ( '' !== $width && false !== $width ) {596 $width = 'width="' . esc_attr( $width ) . '" ';597 }598 return $width;599 }600 601 /**602 * Function to return height render content where possible.603 *604 * @since 1.1.0605 *606 * @param string $height tag class.607 * @return string608 */609 public function get_height_render_content( string $height ) {610 if ( '' !== $height && false !== $height ) {611 $height = 'height="' . esc_attr( $height ) . '" ';612 }613 return $height;614 }615 616 /**617 * Generates link tag html618 *619 * @since 1.1.0620 *621 * @param string $field_value Field value.622 * @param string $link_text Link text.623 * @param string $tag_class class to be added on the tag.624 * @param string $tag_id id to be added on the tag.625 * @param string $style style to be associated with tag.626 * @return string627 */628 public function get_link_tag_html( string $field_value, string $link_text, string $tag_class, string $tag_id, string $style ) {629 return '<a ' . $this->get_tag_class_render_content( $tag_class ) . $this->get_tag_id_render_content( $tag_id ) . $this->get_style_render_content( $style ) . ' href="' . esc_url( $field_value ) . '">' . esc_html( $link_text ) . '</a>';630 }631 249 } 632
Note: See TracChangeset
for help on using the changeset viewer.