From 4cf341e890a10f60102f4fa5bdb910a224a18057 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 27 Nov 2018 14:21:27 +0200 Subject: [PATCH] - added code snippet for WPML integration with Forms translations; - removed some old commented code; --- includes/core/class-external-integrations.php | 36 +++++++++++++++ includes/core/class-form.php | 5 ++- includes/core/class-shortcodes.php | 16 +++---- includes/core/um-actions-register.php | 45 ------------------- 4 files changed, 47 insertions(+), 55 deletions(-) diff --git a/includes/core/class-external-integrations.php b/includes/core/class-external-integrations.php index 914f2e9f..aa21e625 100644 --- a/includes/core/class-external-integrations.php +++ b/includes/core/class-external-integrations.php @@ -32,10 +32,46 @@ if ( ! class_exists( 'um\core\External_Integrations' ) ) { add_filter( 'um_localize_permalink_filter', array( &$this, 'um_localize_permalink_filter' ), 10, 2 ); add_filter( 'icl_ls_languages', array( &$this, 'um_core_page_wpml_permalink' ), 10, 1 ); + /** + * @todo Customize this form metadata + */ + //add_filter( 'um_pre_args_setup', array( &$this, 'shortcode_pre_args_setup' ), 20, 1 ); + $this->plugins_loaded(); } + /** + * UM filter - Restore original arguments on translated page + * + * @description Restore original arguments on load shortcode if they are missed in the WPML translation + * @hook um_pre_args_setup + * + * @global \SitePress $sitepress + * @param array $args + * @return array + */ + function shortcode_pre_args_setup( $args ) { + if ( UM()->external_integrations()->is_wpml_active() ) { + global $sitepress; + + $original_form_id = $sitepress->get_object_id( $args['form_id'], 'post', true, $sitepress->get_default_language() ); + + if ( $original_form_id != $args['form_id'] ) { + $original_post_data = UM()->query()->post_data( $original_form_id ); + + foreach ( $original_post_data as $key => $value ) { + if ( ! isset( $args[ $key ] ) ) { + $args[ $key ] = $value; + } + } + } + } + + return $args; + } + + /** * Gravity forms role capabilities compatibility */ diff --git a/includes/core/class-form.php b/includes/core/class-form.php index 59c5d8e7..ee8aef77 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -481,8 +481,11 @@ if ( ! class_exists( 'um\core\Form' ) ) { $global_role = $um_global_role; // Form Global settings } - $mode = $this->form_type( $post_id ); + + /** + * @todo WPML integration to get role from original if it's empty + */ $use_custom = get_post_meta( $post_id, "_um_{$mode}_use_custom_settings", true ); if ( $use_custom ) { // Custom Form settings $role = get_post_meta( $post_id, "_um_{$mode}_role", true ); diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 070b27c5..d4e7ddd5 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -558,7 +558,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } // get data into one global array - $post_data = UM()->query()->post_data($this->form_id); + $post_data = UM()->query()->post_data( $this->form_id ); ob_start(); @@ -589,23 +589,22 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args['template'] = ''; } - if (isset($post_data['template']) && $post_data['template'] != $args['template']) { + if ( isset( $post_data['template'] ) && $post_data['template'] != $args['template'] ) { $args['template'] = $post_data['template']; } - if (!$this->template_exists($args['template'])) { + if ( ! $this->template_exists( $args['template'] ) ) { $args['template'] = $post_data['mode']; } - if (!isset($post_data['template'])) { + if ( ! isset( $post_data['template'] ) ) { $post_data['template'] = $post_data['mode']; } - if( 'directory' != $args['mode'] ) { - + if ( 'directory' != $args['mode'] ) { $args = array_merge( $post_data, $args ); - if (empty( $args['use_custom_settings'] )) { + if ( empty( $args['use_custom_settings'] ) ) { $args = array_merge( $args, $this->get_css_args( $args ) ); } else { $args = array_merge( $this->get_css_args( $args ), $args ); @@ -648,8 +647,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { // for profiles only if ( $mode == 'profile' && um_profile_id() ) { - $use_custom = get_post_meta( $this->form_id, "_um_{$mode}_use_custom_settings", true ); - if ( $use_custom ) { // Custom Form settings + if ( ! empty( $args['use_custom_settings'] ) ) { // Custom Form settings $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() ); //backward compatibility between single/multi role form's setting diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 3e163100..5fe71b58 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -452,51 +452,6 @@ function um_submit_form_register( $args ) { add_action( 'um_submit_form_register', 'um_submit_form_register', 10 ); -/** - * Register user with predefined role in options - * - * @param $args - */ -function um_add_user_role( $args ) { - - if ( isset( $args['custom_fields']['role_select'] ) || isset( $args['custom_fields']['role_radio'] ) ) return; - - $use_custom_settings = get_post_meta( $args['form_id'], '_um_register_use_custom_settings', true ); - - $role = apply_filters( 'um_registration_user_role', UM()->form()->assigned_role( UM()->form()->form_id ), $args ); - - if ( empty( $use_custom_settings ) || empty( $role ) ) return; - - /** - * UM hook - * - * @type filter - * @title um_register_hidden_role_field - * @description Display hidden role field - * @input_vars - * [{"var":"$role","type":"string","desc":"Hidden user role"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $role = apply_filters( 'um_register_hidden_role_field', $role ); - if ( $role ) { - echo ''; - } - -} -//add_action( 'um_after_register_fields', 'um_add_user_role', 10, 1 ); - - /** * Show the submit button *