Changeset 3432845
- Timestamp:
- 01/05/2026 03:24:04 PM (6 weeks ago)
- Location:
- block-logic
- Files:
-
- 2 edited
-
tags/2.1.1/README.txt (modified) (3 diffs)
-
trunk/README.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
block-logic/tags/2.1.1/README.txt
r3432839 r3432845 75 75 * `is_user_logged_in() && WC()->cart && WC()->cart->get_cart_contents_count() > 0` -- logged-in user and cart has items 76 76 77 5. ** ACF Checks (Read-only)**77 5. **ACF Checks (Read-only)** 78 78 * `get_field('featured') == true` -- ACF field “featured” is true 79 79 * `get_sub_field('discount') > 0` -- ACF subfield “discount” has a value … … 116 116 * `in_array($post->ID, get_post_ancestors($post)) && is_user_logged_in()` 117 117 118 2. **Allowed Functions** 119 * A wide selection of safe WordPress, WooCommerce, ACF, and PHP functions are allowed. Extend this list via the `block_logic_allowed_functions` filter. 120 * Core WordPress Functions 121 * `current_user_can('administrator')` -- check user capabilities 122 * `get_current_user_id()` -- current user ID 123 * `get_option('blogname')` -- get site title 124 * `get_post_meta(get_the_ID(), 'featured', true)` -- read post meta 125 * `get_post_type()` -- post type slug 126 * `get_the_ID()` -- current post ID 127 * `has_post_thumbnail()` -- check if post has featured image 128 * `is_page('about')` -- check if current page is "about" 129 130 * Example usage: 131 * `is_page('about') && has_post_thumbnail()` 132 133 ##### ACF Functions (Read-only) 134 * `get_field('featured')` -- read ACF field value 135 * `get_sub_field('discount')` -- read subfield in repeater 136 * `get_row()` -- number of repeater rows 137 * `get_field_object('product_info')['value']` -- field object value 138 139 Example usage: 140 * `get_field('featured') == true && get_sub_field('discount') > 0` 141 142 ##### WooCommerce Functions 143 * `wc_get_cart_contents_count()` -- number of items in cart 144 * `wc_get_cart_total()` -- cart total 145 * `wc_get_cart_subtotal()` -- cart subtotal 146 * `wc_cart_is_empty()` -- TRUE if cart is empty 147 * `wc_customer_get_id()` -- current customer ID 148 * `wc_customer_get_billing_email()` -- customer billing email 149 * `wc_customer_get_shipping_country()` -- shipping country 150 * `wc_customer_get_shipping_state()` -- shipping state 151 * `wc_customer_get_shipping_postcode()` -- shipping postcode 152 * `wc_get_product($product_id)` -- get WC_Product object 153 154 Example usage: 155 * `wc_get_cart_contents_count() > 0 && wc_get_cart_total() > 50` 156 157 ##### PHP Helpers 158 * `strpos($haystack, $needle)` 159 * `in_array($needle, $array)` 160 * `empty($var)` 161 * `isset($var)` 162 * `count($array)` 163 * `strlen($string)` 164 * `preg_match($pattern, $subject)` 165 * `current_time('timestamp')` 166 * `strtotime($string)` 167 * `date($format, $timestamp)` 168 * `time()` 169 * `number_format($number, $decimals)` 170 * `round($number)` 171 172 Example usage: 173 * `count(WC()->cart->get_cart()) > 1 && time() > strtotime('2026-01-01')` 118 2. **Allowed WordPress Functions** 119 * Overview 120 * `current_user_can('administrator')` -- check user capabilities 121 * `get_current_user_id()` -- current user ID 122 * `get_option('blogname')` -- get site title 123 * `get_post_meta(get_the_ID(), 'featured', true)` -- read post meta 124 * `get_post_type()` -- post type slug 125 * `get_the_ID()` -- current post ID 126 * `has_post_thumbnail()` -- check if post has featured image 127 * `is_page('about')` -- check if current page is "about" 128 129 * Example usage: 130 * `is_page('about') && has_post_thumbnail()` 131 132 3. **ACF Functions** 133 * Overview 134 * `get_field('featured')` -- read ACF field value 135 * `get_sub_field('discount')` -- read subfield in repeater 136 * `get_row()` -- number of repeater rows 137 * `get_field_object('product_info')['value']` -- field object value 138 139 * Example usage: 140 * `get_field('featured') == true && get_sub_field('discount') > 0` 141 142 4. **WooCommerce Functions** 143 * Overview 144 * `wc_get_cart_contents_count()` -- number of items in cart 145 * `wc_get_cart_total()` -- cart total 146 * `wc_get_cart_subtotal()` -- cart subtotal 147 * `wc_cart_is_empty()` -- TRUE if cart is empty 148 * `wc_customer_get_id()` -- current customer ID 149 * `wc_customer_get_billing_email()` -- customer billing email 150 * `wc_customer_get_shipping_country()` -- shipping country 151 * `wc_customer_get_shipping_state()` -- shipping state 152 * `wc_customer_get_shipping_postcode()` -- shipping postcode 153 * `wc_get_product($product_id)` -- get WC_Product object 154 155 * Example usage: 156 * `wc_get_cart_contents_count() > 0 && wc_get_cart_total() > 50` 157 158 5. **PHP Helpers** 159 * Overview 160 * `strpos($haystack, $needle)` 161 * `in_array($needle, $array)` 162 * `empty($var)` 163 * `isset($var)` 164 * `count($array)` 165 * `strlen($string)` 166 * `preg_match($pattern, $subject)` 167 * `current_time('timestamp')` 168 * `strtotime($string)` 169 * `date($format, $timestamp)` 170 * `time()` 171 * `number_format($number, $decimals)` 172 * `round($number)` 173 174 * Example usage: 175 * `count(WC()->cart->get_cart()) > 1 && time() > strtotime('2026-01-01')` 174 176 175 177 = Extending the list of allowed functions = … … 177 179 Block Logic provides four filters that developers can use to safely extend which functions, globals, and superglobals are available inside block logic expressions. 178 180 179 ### Add custom functions 180 Use the `block_logic_allowed_functions` filter to make additional functions available in block logic expressions. 181 182 Example: allow a helper function to check WooCommerce cart items: 183 184 ` 185 add_filter('block_logic_allowed_functions', function($allowed) { 186 $allowed[] = 'my_cart_has_items'; 187 return $allowed; 188 }); 189 190 function my_cart_has_items() { 191 return WC()->cart && WC()->cart->get_cart_contents_count() > 0; 192 }` 181 1. Add custom functions 182 * Use the `block_logic_allowed_functions` filter to make additional functions available in block logic expressions. 183 * Example: allow a helper function to check WooCommerce cart items: 184 * `add_filter('block_logic_allowed_functions', function($allowed) { 185 $allowed[] = 'my_cart_has_items'; 186 return $allowed; 187 }); 188 189 function my_cart_has_items() { 190 return WC()->cart && WC()->cart->get_cart_contents_count() > 0; 191 }` 193 192 194 193 Usage in a block logic field: 195 my_cart_has_items() 194 `my_cart_has_items()` 196 195 197 196 ### Add extra superglobals -
block-logic/trunk/README.txt
r3432839 r3432845 75 75 * `is_user_logged_in() && WC()->cart && WC()->cart->get_cart_contents_count() > 0` -- logged-in user and cart has items 76 76 77 5. ** ACF Checks (Read-only)**77 5. **ACF Checks (Read-only)** 78 78 * `get_field('featured') == true` -- ACF field “featured” is true 79 79 * `get_sub_field('discount') > 0` -- ACF subfield “discount” has a value … … 116 116 * `in_array($post->ID, get_post_ancestors($post)) && is_user_logged_in()` 117 117 118 2. **Allowed Functions** 119 * A wide selection of safe WordPress, WooCommerce, ACF, and PHP functions are allowed. Extend this list via the `block_logic_allowed_functions` filter. 120 * Core WordPress Functions 121 * `current_user_can('administrator')` -- check user capabilities 122 * `get_current_user_id()` -- current user ID 123 * `get_option('blogname')` -- get site title 124 * `get_post_meta(get_the_ID(), 'featured', true)` -- read post meta 125 * `get_post_type()` -- post type slug 126 * `get_the_ID()` -- current post ID 127 * `has_post_thumbnail()` -- check if post has featured image 128 * `is_page('about')` -- check if current page is "about" 129 130 * Example usage: 131 * `is_page('about') && has_post_thumbnail()` 132 133 ##### ACF Functions (Read-only) 134 * `get_field('featured')` -- read ACF field value 135 * `get_sub_field('discount')` -- read subfield in repeater 136 * `get_row()` -- number of repeater rows 137 * `get_field_object('product_info')['value']` -- field object value 138 139 Example usage: 140 * `get_field('featured') == true && get_sub_field('discount') > 0` 141 142 ##### WooCommerce Functions 143 * `wc_get_cart_contents_count()` -- number of items in cart 144 * `wc_get_cart_total()` -- cart total 145 * `wc_get_cart_subtotal()` -- cart subtotal 146 * `wc_cart_is_empty()` -- TRUE if cart is empty 147 * `wc_customer_get_id()` -- current customer ID 148 * `wc_customer_get_billing_email()` -- customer billing email 149 * `wc_customer_get_shipping_country()` -- shipping country 150 * `wc_customer_get_shipping_state()` -- shipping state 151 * `wc_customer_get_shipping_postcode()` -- shipping postcode 152 * `wc_get_product($product_id)` -- get WC_Product object 153 154 Example usage: 155 * `wc_get_cart_contents_count() > 0 && wc_get_cart_total() > 50` 156 157 ##### PHP Helpers 158 * `strpos($haystack, $needle)` 159 * `in_array($needle, $array)` 160 * `empty($var)` 161 * `isset($var)` 162 * `count($array)` 163 * `strlen($string)` 164 * `preg_match($pattern, $subject)` 165 * `current_time('timestamp')` 166 * `strtotime($string)` 167 * `date($format, $timestamp)` 168 * `time()` 169 * `number_format($number, $decimals)` 170 * `round($number)` 171 172 Example usage: 173 * `count(WC()->cart->get_cart()) > 1 && time() > strtotime('2026-01-01')` 118 2. **Allowed WordPress Functions** 119 * Overview 120 * `current_user_can('administrator')` -- check user capabilities 121 * `get_current_user_id()` -- current user ID 122 * `get_option('blogname')` -- get site title 123 * `get_post_meta(get_the_ID(), 'featured', true)` -- read post meta 124 * `get_post_type()` -- post type slug 125 * `get_the_ID()` -- current post ID 126 * `has_post_thumbnail()` -- check if post has featured image 127 * `is_page('about')` -- check if current page is "about" 128 129 * Example usage: 130 * `is_page('about') && has_post_thumbnail()` 131 132 3. **ACF Functions** 133 * Overview 134 * `get_field('featured')` -- read ACF field value 135 * `get_sub_field('discount')` -- read subfield in repeater 136 * `get_row()` -- number of repeater rows 137 * `get_field_object('product_info')['value']` -- field object value 138 139 * Example usage: 140 * `get_field('featured') == true && get_sub_field('discount') > 0` 141 142 4. **WooCommerce Functions** 143 * Overview 144 * `wc_get_cart_contents_count()` -- number of items in cart 145 * `wc_get_cart_total()` -- cart total 146 * `wc_get_cart_subtotal()` -- cart subtotal 147 * `wc_cart_is_empty()` -- TRUE if cart is empty 148 * `wc_customer_get_id()` -- current customer ID 149 * `wc_customer_get_billing_email()` -- customer billing email 150 * `wc_customer_get_shipping_country()` -- shipping country 151 * `wc_customer_get_shipping_state()` -- shipping state 152 * `wc_customer_get_shipping_postcode()` -- shipping postcode 153 * `wc_get_product($product_id)` -- get WC_Product object 154 155 * Example usage: 156 * `wc_get_cart_contents_count() > 0 && wc_get_cart_total() > 50` 157 158 5. **PHP Helpers** 159 * Overview 160 * `strpos($haystack, $needle)` 161 * `in_array($needle, $array)` 162 * `empty($var)` 163 * `isset($var)` 164 * `count($array)` 165 * `strlen($string)` 166 * `preg_match($pattern, $subject)` 167 * `current_time('timestamp')` 168 * `strtotime($string)` 169 * `date($format, $timestamp)` 170 * `time()` 171 * `number_format($number, $decimals)` 172 * `round($number)` 173 174 * Example usage: 175 * `count(WC()->cart->get_cart()) > 1 && time() > strtotime('2026-01-01')` 174 176 175 177 = Extending the list of allowed functions = … … 177 179 Block Logic provides four filters that developers can use to safely extend which functions, globals, and superglobals are available inside block logic expressions. 178 180 179 ### Add custom functions 180 Use the `block_logic_allowed_functions` filter to make additional functions available in block logic expressions. 181 182 Example: allow a helper function to check WooCommerce cart items: 183 184 ` 185 add_filter('block_logic_allowed_functions', function($allowed) { 186 $allowed[] = 'my_cart_has_items'; 187 return $allowed; 188 }); 189 190 function my_cart_has_items() { 191 return WC()->cart && WC()->cart->get_cart_contents_count() > 0; 192 }` 181 1. Add custom functions 182 * Use the `block_logic_allowed_functions` filter to make additional functions available in block logic expressions. 183 * Example: allow a helper function to check WooCommerce cart items: 184 * `add_filter('block_logic_allowed_functions', function($allowed) { 185 $allowed[] = 'my_cart_has_items'; 186 return $allowed; 187 }); 188 189 function my_cart_has_items() { 190 return WC()->cart && WC()->cart->get_cart_contents_count() > 0; 191 }` 193 192 194 193 Usage in a block logic field: 195 my_cart_has_items() 194 `my_cart_has_items()` 196 195 197 196 ### Add extra superglobals
Note: See TracChangeset
for help on using the changeset viewer.