id, [ $this, 'dismiss_notice' ] ); add_action( 'wp_ajax_wpuf_compatibility_' . $this->id, [ $this, 'maybe_compatible' ] ); add_action( 'wp_ajax_wpuf_migrate_' . $this->id, [ $this, 'migrate_cf_data' ] ); add_filter( 'acf/load_value', [ $this, 'load_compatible_value' ], 10, 3 ); } /** * See if ACF plugin exists * * @return bool */ public function plugin_exists() { return class_exists( 'acf' ); } /** * If the prompt is dismissed * * @return bool */ public function is_dismissed() { return 'yes' == get_option( 'wpuf_dismiss_notice_' . $this->id ); } /** * Check if * * @return bool */ public function is_compatible() { return 'yes' == wpuf_get_option( 'wpuf_compatibility_' . $this->id, 'wpuf_general', 'no' ); } /** * Check if * * @return bool */ public function is_migrated() { return 'yes' == get_option( 'wpuf_migrate_' . $this->id ); } /** * Dismiss the prompt * * @return void */ public function dismiss_prompt() { update_option( 'wpuf_dismiss_notice_' . $this->id, 'yes' ); } /** * Update option * *@return void */ public function maybe_compatible() { wpuf_update_option( 'wpuf_compatibility_' . $this->id, 'wpuf_general', 'yes' ); wp_send_json_success(); } /** * Update existing custom fields data * *@return void */ public function migrate_cf_data() { $forms = $this->get_post_forms(); if ( !empty( $forms ) ) { foreach ( $forms as $form ) { $form_id = $form->ID; $form_vars = wpuf_get_form_fields( $form_id ); $form_settings = wpuf_get_form_settings( $form_id ); $post_type = $form_settings['post_type']; foreach ( $form_vars as $attr ) { $field_type = $attr['input_type']; $meta = $attr['is_meta']; if ( $meta == 'yes' && ( $field_type == 'checkbox' || $field_type == 'multiselect' ) ) { $meta_key = $attr['name']; $args = [ 'post_type' => $post_type, 'meta_key' => '_wpuf_form_id', ]; $posts = get_posts( $args ); if ( !empty( $posts ) ) { foreach ( $posts as $post ) { $post_id = $post->ID; $separator = '| '; $meta_value = get_post_meta( $post_id, $meta_key ); if ( !empty( $meta_value ) ) { $new_value = explode( $separator, $meta_value[0] ); $new_value = maybe_serialize( $new_value ); update_post_meta( $post_id, $meta_key, $new_value ); } } } } } } } update_option( 'wpuf_migrate_' . $this->id, 'yes' ); wpuf_update_option( 'wpuf_compatibility_' . $this->id, 'wpuf_general', 'yes' ); wp_send_json_success(); } /** * Get all post form * *@return array */ public function get_post_forms() { $args = [ 'post_type' => 'wpuf_forms', 'post_status' => 'publish', ]; return $form_posts = get_posts( $args ); } /** * Dismiss the notice * * @return void */ public function dismiss_notice() { $this->dismiss_prompt(); wp_send_json_success(); } /** * Show notice if the plugin found * * @return void */ public function maybe_show_notice() { if ( !$this->plugin_exists() ) { return; } if ( $this->is_dismissed() || $this->is_compatible() || $this->is_migrated() || !current_user_can( 'manage_options' ) ) { return; } ?>
fields->get_field( 'checkbox_field' )->get_formatted_value( $value ); break; default: break; } return $value; } }