diff --git a/assets/js/rules.js b/assets/js/rules.js new file mode 100755 index 0000000..8335dca --- /dev/null +++ b/assets/js/rules.js @@ -0,0 +1,92 @@ + +console.log( 'TEST'); + +var addRuleTypeCategory = BBLogic.api.addRuleTypeCategory, + addRuleType = BBLogic.api.addRuleType, + getFormPreset = BBLogic.api.getFormPreset, + __ = BBLogic.i18n.__; + + +addRuleTypeCategory('pods', { + label: __('Pods') +}); + + +addRuleType('pods/settings-field', { + label: __('Pods Settings Field'), + category: 'pods', + form: getFormPreset('key-value'), // string,date,number,string +}); + + +addRuleType('pods/date-field', { + label: __('Pods Date Field'), + category: 'pods', + form: function ( props ) { + var rule = props.rule; + var post_type = rule.post_type; + var taxonomy = rule.taxonomy; + + console.log( props ); + + return { + post_type: { + type: 'select', + route: 'bb-logic/v1/wordpress/post-types' + }, + key: { + type: 'text', + placeholder: __('Key') + }, + operator: { + type: 'operator', + operators: ['equals', 'does_not_equal'] + }, + taxonomy: { + type: 'select', + route: 'bb-logic/v1/wordpress/taxonomies' + }, + term: { + type: 'select', + route: taxonomy ? 'bb-logic/v1/wordpress/terms?taxonomy=' + taxonomy : null, + visible: taxonomy + } + }; + } // string,date,number,string +}); + + +// Test / Example +addRuleType( 'pods/user-post-count', { + label: __( 'User Post Count' ), + category: 'user', + form: { + operator: { + type: 'operator', + operators: [ + 'equals', + 'does_not_equal', + 'is_less_than', + 'is_greater_than', + ], + }, + count: { //compare + type: 'number', + defaultValue: '0', + }, + my_select: { + type: 'select', + // route: 'bb-logic/v1/wordpress/taxonomies', + options: [ + { + label: 'Option 1', + value: '1', + }, + { + label: 'Option 2', + value: '2', + }, + ], + }, + }, +} ) diff --git a/classes/class-pods-beaver-page-data.php b/classes/class-pods-beaver-page-data.php index 27bdc31..66ad59e 100644 --- a/classes/class-pods-beaver-page-data.php +++ b/classes/class-pods-beaver-page-data.php @@ -554,13 +554,13 @@ public static function pods_get_settings_fields( $field_options = array() ) { ), 'type' => array( 'type' => 'select', - 'label' => __( 'User "type"', 'pods-beaver-builder-themer-add-on' ), + 'label' => __( 'Select User "type"', 'pods-beaver-builder-themer-add-on' ), 'options' => array( 'author' => __( 'Author (post_author)', 'pods-beaver-builder-themer-add-on' ), 'modified' => __( 'Author (last modified) ', 'pods-beaver-builder-themer-add-on' ), 'logged_in' => __( 'Logged in User', 'pods-beaver-builder-themer-add-on' ), ), - 'description' => __( 'Only affects user fields', 'pods-beaver-builder-themer-add-on' ), + 'description' => __( 'Not needed for Settings Pod', 'pods-beaver-builder-themer-add-on' ), ), ); @@ -617,6 +617,10 @@ private static function recurse_pod_fields( $pod_name, $field_options = array(), $all_pod_fields = $pod->fields(); +/* if ( isset( $pod->pod_data['object_fields'] ) ) { + $all_pod_fields = array_merge( $all_pod_fields, $pod->pod_data['object_fields'] ); + }*/ + /*if ( isset( $pod->pod_data['object_fields']['post_author'] ) ) { $all_pod_fields['post_author'] = $pod->pod_data['object_fields']['post_author']; }*/ diff --git a/includes/rules.php b/includes/rules.php new file mode 100755 index 0000000..92798cb --- /dev/null +++ b/includes/rules.php @@ -0,0 +1,125 @@ + __CLASS__ . '::archive_field', + 'pods/option-field' => __CLASS__ . '::option_field', + 'pods/post-field' => __CLASS__ . '::post_field', + 'pods/post-author-field' => __CLASS__ . '::post_author_field', + 'pods/user-field' => __CLASS__ . '::user_field', + ) ); + } + + /** + * Process an Pods rule based on the object ID of the + * field location such as archive, post or user. + * + * @since 0.1 + * @param string $object_id + * @param object $rule + * @return bool + */ + static public function evaluate_rule( $object_id = false, $rule ) { + $value = get_field( $rule->key, $object_id ); + + if ( is_array( $value ) ) { + $value = empty( $value ) ? 0 : 1; + } elseif ( is_object( $value ) ) { + $value = 1; + } + + return BB_Logic_Rules::evaluate_rule( array( + 'value' => $value, + 'operator' => $rule->operator, + 'compare' => $rule->compare, + 'isset' => $value, + ) ); + } + + /** + * Archive field rule. + * + * @since 0.1 + * @param object $rule + * @return bool + */ + static public function archive_field( $rule ) { + $object = get_queried_object(); + + if ( ! is_object( $object ) || ! isset( $object->taxonomy ) || ! isset( $object->term_id ) ) { + $id = 'archive'; + } else { + $id = $object->taxonomy . '_' . $object->term_id; + } + + return self::evaluate_rule( $id, $rule ); + } + + /** + * Option field rule. + * + * @since 0.1 + * @param object $rule + * @return bool + */ + static public function option_field( $rule ) { + return self::evaluate_rule( 'option', $rule ); + } + + /** + * Post field rule. + * + * @since 0.1 + * @param object $rule + * @return bool + */ + static public function post_field( $rule ) { + global $post; + $id = is_object( $post ) ? $post->ID : 0; + return self::evaluate_rule( $id, $rule ); + } + + /** + * Post author field rule. + * + * @since 0.1 + * @param object $rule + * @return bool + */ + static public function post_author_field( $rule ) { + global $post; + $id = is_object( $post ) ? $post->post_author : 0; + return self::evaluate_rule( 'user_' . $id, $rule ); + } + + /** + * User field rule. + * + * @since 0.1 + * @param object $rule + * @return bool + */ + static public function user_field( $rule ) { + $user = wp_get_current_user(); + return self::evaluate_rule( 'user_' . $user->ID, $rule ); + } +} + +BB_Logic_Rules_Pods::init(); diff --git a/pods-beaver-themer.php b/pods-beaver-themer.php index 82aa6de..d63dabc 100644 --- a/pods-beaver-themer.php +++ b/pods-beaver-themer.php @@ -3,7 +3,7 @@ * Plugin Name: Pods Beaver Themer Add-On * Plugin URI: http://pods.io/ * Description: Integration with Beaver Builder Themer (https://www.wpbeaverbuilder.com). Provides a UI for mapping Field Connections with Pods - * Version: 1.3.4 + * Version: 1.4-a-1 * Author: Quasel, Pods Framework Team * Author URI: http://pods.io/about/ * Text Domain: pods-beaver-builder-themer-add-on @@ -30,7 +30,7 @@ * @package Pods\Beaver Themer */ -define( 'PODS_BEAVER_VERSION', '1.3.4' ); +define( 'PODS_BEAVER_VERSION', '1.4-a-1' ); define( 'PODS_BEAVER_FILE', __FILE__ ); define( 'PODS_BEAVER_DIR', plugin_dir_path( PODS_BEAVER_FILE ) ); define( 'PODS_BEAVER_URL', plugin_dir_url( PODS_BEAVER_FILE ) ); @@ -75,6 +75,19 @@ function pods_beaver_init() { add_action( 'fl_page_data_add_properties', 'pods_beaver_init' ); +/** + * Add support for the new bb_logic + * Server Side Rule Processing + * Frontend Rule Registration + * + * @since 1.4 + */ +if ( defined( 'FL_THEME_BUILDER_VERSION' ) && version_compare( FL_THEME_BUILDER_VERSION, '1.1', '>' ) ) { + add_action( 'bb_logic_init', 'pods_beaver_bb_logic_init'); + add_action( 'bb_logic_enqueue_scripts', 'pods_beaver_bb_logic_enqueue' ); +} + + /** * Admin nag if Pods or Beaver Builder are not activated. * @@ -165,6 +178,34 @@ function pods_beaver_fake_loop_false() { } +/** + * Server Side Rule Processing + * + * @return void + * @since 1.4 + */ +function pods_beaver_bb_logic_init() { + require_once PODS_BEAVER_DIR . 'includes/rules.php'; +} + +/** + * Frontend Rule Registration + * Handles enqueuing css and js assets + * + * @return void + * @since 1.4 + */ +function pods_beaver_bb_logic_enqueue() { + wp_enqueue_script( + 'bb-logic-rules-pods', + PODS_BEAVER_URL . 'assets/js/rules.js', + array( 'bb-logic-core' ), + '', + true + ); +} + + /** * Adds the custom code settings for custom post module layouts. * diff --git a/readme.txt b/readme.txt index e158163..c72e423 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: pods, beaver builder, beaver themer Requires at least: 4.4 Tested up to: 5.5 Requires PHP: 5.4 -Stable tag: 1.3.4 +Stable tag: 1.4-a-1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html