This commit is contained in:
nikitozzzzzzz
2017-10-30 14:14:19 +02:00
4 changed files with 104 additions and 3 deletions
+70
View File
@@ -187,6 +187,76 @@ if ( ! class_exists( 'UM_Functions' ) ) {
return apply_filters( 'um_excluded_taxonomies', $taxes );
}
/**
* Output templates
*
* @access public
* @param string $template_name
* @param string $path (default: '')
* @param array $t_args (default: array())
* @param bool $echo
*
* @return string|void
*/
function get_template( $template_name, $basename = '', $t_args = array(), $echo = false ) {
if ( ! empty( $t_args ) && is_array( $t_args ) ) {
extract( $t_args );
}
$path = '';
if( $basename ) {
$array = explode( '/', trim( $basename, '/' ) );
$path = $array[0];
}
$located = $this->locate_template( $template_name, $path );
if ( ! file_exists( $located ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
return;
}
$located = apply_filters( 'um_get_template', $located, $template_name, $path, $t_args );
ob_start();
do_action( 'um_before_template_part', $template_name, $path, $located, $t_args );
include( $located );
do_action( 'um_after_template_part', $template_name, $path, $located, $t_args );
$html = ob_get_clean();
if ( ! $echo ) {
return $html;
} else {
echo $html;
}
}
/**
* Locate a template and return the path for inclusion.
*
* @access public
* @param string $template_name
* @param string $path (default: '')
* @return string
*/
function locate_template( $template_name, $path = '' ) {
// check if there is template at theme folder
$template = locate_template( array(
trailingslashit( 'ultimate-member/' . $path ) . $template_name
) );
if( !$template ) {
if( $path ) {
$template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path );
} else {
$template = trailingslashit( um_path );
}
$template .= 'templates/' . $template_name;
}
// Return what we found.
return apply_filters( 'um_locate_template', $template, $template_name, $path );
}
}
}
+11 -2
View File
@@ -477,6 +477,12 @@
return $value;
} else if( isset( UM()->user()->profile[$key] ) ){
$value = UM()->user()->profile[$key];
$value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
return $value;
} else if ($default) {
$default = apply_filters( "um_field_default_value", $default, $data, $type );
@@ -1326,7 +1332,7 @@
$number_limit .= " max=\"{$max}\" ";
}
$output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="number" name="' . $key . UM()->form()->form_suffix . '" id="' . $key . UM()->form()->form_suffix . '" value="' . htmlspecialchars( $this->field_value( $key, $default, $data ) ) . '" placeholder="' . $placeholder . '" data-validate="' . $validate . '" data-key="' . $key . '" {$number_limit} />
$output .= '<input ' . $disabled . ' class="' . $this->get_class( $key, $data ) . '" type="number" name="' . $key . UM()->form()->form_suffix . '" id="' . $key . UM()->form()->form_suffix . '" value="' . htmlspecialchars( $this->field_value( $key, $default, $data ) ) . '" placeholder="' . $placeholder . '" data-validate="' . $validate . '" data-key="' . $key . '" '.$number_limit.' />
</div>';
@@ -2594,7 +2600,10 @@
if (in_array( $type, array( 'block', 'shortcode', 'spacing', 'divider', 'group' ) )) {
} else {
if (!$this->field_value( $key, $default, $data )) return;
$_field_value = $this->field_value( $key, $default, $data );
if ( ! isset($_field_value) || $_field_value == '') return;
}
if (!um_can_view_field( $data )) return;
+2 -1
View File
@@ -144,7 +144,8 @@ if ( ! class_exists( 'Members' ) ) {
* @since 1.3.83
*/
function um_search_select_fields( $attrs ) {
if( strstr( $attrs['metakey'], 'role_' ) ){
if( !empty($attrs['metakey']) && strstr( $attrs['metakey'], 'role_' ) ){
$shortcode_roles = get_post_meta( UM()->shortcodes()->form_id, '_um_roles', true );
$um_roles = UM()->roles()->get_roles( false );
+21
View File
@@ -482,3 +482,24 @@
return $value;
}
/**
* add role_select and role_radio to the $post_form
* It is necessary for that if on these fields the conditional logic
* @param $post_form array
* @param $mode
*
* @return $post_form
* @uses hook filters: um_submit_form_data
*/
function um_submit_form_data_role_fields( $post_form, $mode ) {
$custom_fields = unserialize( $post_form['custom_fields'] );
if ( ! empty( $post_form['role'] ) && array_key_exists( 'role_select', $custom_fields ) ) {
$post_form['role_select'] = $post_form['role'];
}
if (! empty( $post_form['role'] ) && array_key_exists( 'role_radio', $custom_fields ) ) {
$post_form['role_radio'] = $post_form['role'];
}
return $post_form;
}
add_filter( 'um_submit_form_data', 'um_submit_form_data_role_fields', 10, 2 );