Created
June 26, 2023 08:36
-
-
Save ihslimn/5626b6e5d8a8eae6fc94d2eb1b8a8157 to your computer and use it in GitHub Desktop.
JetSmartFilters Meta Dynamic Visibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'jet-smart-filters/query/meta-query-row', function( $row ) { | |
| if ( in_array( $row['key'], array( '__reload_provider' ) ) ) { | |
| $row = array(); | |
| } | |
| return $row; | |
| } ); | |
| add_action( 'jet-engine/register-macros', function(){ | |
| class JSF_Dynamic_Visibility_Meta extends \Jet_Engine_Base_Macros { | |
| public function macros_tag() { | |
| return 'jsf_dynamic_visibility_meta'; | |
| } | |
| public function macros_name() { | |
| return 'JSF Dynamic Visibility Meta'; | |
| } | |
| public function macros_args() { | |
| return array( | |
| 'jsf_dv_type' => array( | |
| 'label' => 'Type', | |
| 'type' => 'select', | |
| 'options' => array( | |
| 'plain' => 'Plain value', | |
| 'meta' => 'Meta' | |
| ), | |
| ), | |
| 'jsf_param' => array( | |
| 'label' => 'Parameter', | |
| 'type' => 'text', | |
| ), | |
| ); | |
| } | |
| public function macros_callback( $args = array() ) { | |
| $type = ! empty( $args['jsf_dv_type'] ) ? $args['jsf_dv_type'] : 'plain'; | |
| $param = ! empty( $args['jsf_param'] ) ? $args['jsf_param'] : ''; | |
| if ( ! $param ) { | |
| return; | |
| } | |
| if ( $type === 'plain' ) { | |
| return $param; | |
| } | |
| $result = ''; | |
| if ( isset( $_REQUEST['query'][ '_meta_query_' . $param ] ) ) { | |
| return $_REQUEST['query'][ '_meta_query_' . $param ] ?? ''; | |
| } | |
| $meta = $_GET['meta'] ?? ''; | |
| if ( empty( $meta ) ) { | |
| return $result; | |
| } | |
| foreach ( explode( ';', $meta ) as $pair ) { | |
| $params = explode( ':', $pair ); | |
| if ( $params[0] === $param ) { | |
| return $params[1]; | |
| } | |
| } | |
| return $result; | |
| } | |
| } | |
| new JSF_Dynamic_Visibility_Meta(); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment