/** * Calls view function for specific usermeta field type. * * @global object $wpdb * * @param type $field * @param type $atts (additional attributes: user_id, user_name, user_is_author, user_current) * @return type */ function types_render_usermeta($field_id, $params, $content = null, $code = '') { global $wpcf, $post, $wpdb, $WP_Views; // HTML var holds actual output $html = ''; $current_user = wp_get_current_user(); $current_user_id = $current_user->ID; // Set post ID // user_id, user_name, user_is_author, user_current if (is_object($post)) { $post_id = $post->ID; } else { $post_id = 0; } if (isset($params['post_id']) && !empty($params['post_id'])) { $post_id = $params['post_id']; } //Get User id from views loop if (isset($WP_Views->users_data['term']->ID) && !empty($WP_Views->users_data['term']->ID)) { $params['user_id'] = $WP_Views->users_data['term']->ID; } //print_r($params);exit; //Get user By ID if (isset($params['user_id'])) { $user_id = $params['user_id']; } else { if (isset($params['user_name'])) { //Get user by login $user_id = $wpdb->get_var($wpdb->prepare("SELECT * FROM " . $wpdb->users . " WHERE user_login = %s", $params['user_name'])); } else { if (isset($params['user_is_author'])) { //Get Post author $user_id = $post->post_author; } else { if (isset($params['user_current'])) { //Get current logged user $user_id = $current_user_id; } else { //If empty get post author, if no post, return empty if (!empty($post_id)) { $user_id = $post->post_author; } else { return; } } } } } if (empty($user_id)) { return; } // Get field $field = types_get_field($field_id, 'usermeta'); // If field not found return empty string if (empty($field)) { // Log if (!function_exists('wplogger')) { require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php'; } global $wplogger; $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG); return ''; } // See if repetitive if (wpcf_admin_is_repetitive($field)) { $wpcf->usermeta_repeater->set($user_id, $field); $_meta = $wpcf->usermeta_repeater->_get_meta(); $meta = ''; if (isset($_meta['custom_order'])) { $meta = $_meta['custom_order']; } if (count($meta) == 1) { $meta_id = key($meta); $_temp = array_shift($meta); if (strval($_temp) == '') { return ''; } else { $params['field_value'] = $_temp; return types_render_field_single($field, $params, $content, $code, $meta_id); } } else { if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key); if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode(html_entity_decode($params['separator']), $output); } else { if (!empty($output)) { $output = implode('', $output); } else { return ''; } } } else { // Make sure indexed right $_index = 0; foreach ($meta as $temp_key => $temp_value) { if ($_index == $index) { $params['field_value'] = $temp_value; $output = types_render_field_single($field, $params, $content, $code, $temp_key); } $_index++; } } $html = $output; } else { return ''; } } } else { $params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if ($params['field_value'] == '' && $field['type'] != 'checkbox') { return ''; } $html = types_render_field_single($field, $params, $content, $code); } // API filter $wpcf->usermeta_field->set($user_id, $field); return $wpcf->usermeta_field->html($html, $params); }
/** * Renders meta box content (preview). * * * * @param type $post * @param type $group */ function wpcf_admin_post_meta_box_preview($post, $group, $echo = '') { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php'; global $wpcf; if (isset($group['args'])) { $fields = $group['args']['fields']; } else { $fields = $group['fields']; } if (isset($group['slug'])) { $slug = $group['slug']; $name = $group['name']; } else { $slug = $group['id']; $name = $group['title']; } /** * fake post object if need */ $post = wpcf_admin_create_fake_post_if_need($post); $group_output = ''; if (!empty($echo)) { $group_output = '<h3>This Preview generated for latest post "' . $post->post_title . '"</h3>'; $group_output .= '<div id="test-field-group" class="postbox " > <h3 class=\'hndle\'><span>' . $name . '</span></h3> <div class="inside">'; } $group_output .= '<table class="form-table fields-preview fields-preview-' . $slug . '"> <tbody>' . "\n\n"; $content = $code = ''; foreach ($fields as $field) { $html = ''; $params['separator'] = ', '; if (wpcf_admin_is_repetitive($field)) { $wpcf->repeater->set($post, $field); $_meta = $wpcf->repeater->_get_meta(); if (isset($_meta['custom_order'])) { $meta = $_meta['custom_order']; } else { $meta = array(); } $content = $code = ''; // Sometimes if meta is empty - array(0 => '') is returned if (count($meta) == 1) { $meta_id = key($meta); $_temp = array_shift($meta); if (!is_array($_temp) && strval($_temp) == '') { } else { $params['field_value'] = $_temp; if (!empty($params['field_value'])) { $html = types_render_field_single($field, $params, $content, $code, $meta_id); } } } else { if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; if (!empty($params['field_value'])) { $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key); } if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode(html_entity_decode($params['separator']), $output); } else { if (!empty($output)) { $output = implode('', $output); } } } else { // Make sure indexed right $_index = 0; foreach ($meta as $temp_key => $temp_value) { if ($_index == $index) { $params['field_value'] = $temp_value; if (!empty($params['field_value'])) { $output = types_render_field_single($field, $params, $content, $code, $temp_key); } } $_index++; } } $html = $output; } } } else { $params['field_value'] = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true); // $html = types_render_field_single( $field, $params, $content, $code ); if (!empty($params['field_value']) && $field['type'] != 'date') { $html = types_render_field_single($field, $params, $content, $code); } if ($field['type'] == 'date' && !empty($params['field_value'])) { $html = types_render_field_single($field, $params, $content, $code); if ($field['data']['date_and_time'] == 'and_time') { $html .= ' ' . date("H", $params['field_value']) . ':' . date("i", $params['field_value']); } } } // API filter $wpcf->field->set($post, $field); $field_value = $wpcf->field->html($html, array()); $group_output .= '<tr class="wpcf-profile-field-line-' . $field['slug'] . '"> <td scope="row">' . $field['name'] . '</td> <td>' . $field_value . '</td> </tr>' . "\n\n"; } $group_output .= "\n\n</tbody>\r\n</table>"; if (empty($echo)) { echo $group_output; } else { $group_output .= "\n\n</div></div>"; return $group_output; } }
function wpcf_usermeta_preview_profile($user_id, $group, $echo = '') { if (is_object($user_id)) { $user_id = $user_id->ID; } require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php'; global $wpcf; //print_r($group);exit; $fields = $group['fields']; $group_output = '<div class="wpcf-group-area wpcf-group-area-' . $group['slug'] . '">' . "\n\n"; $group_output .= '<h3 class="wpcf-group-header-' . $group['slug'] . '">' . wpcf_translate('group ' . $group['id'] . ' name', $group['name']) . '</h3>' . "\n\n"; foreach ($fields as $field) { $html = ''; $params['post_type'] = TYPES_USER_META_FIELD_GROUP_CPT_NAME; $params['option_name'] = 'wpcf-usermeta'; $params['separator'] = ', '; if (wpcf_admin_is_repetitive($field)) { $wpcf->usermeta_repeater->set($user_id, $field); $_meta = $wpcf->usermeta_repeater->_get_meta(); if (isset($_meta['custom_order'])) { $meta = $_meta['custom_order']; } else { $meta = array(); } $content = $code = ''; // Sometimes if meta is empty - array(0 => '') is returned if (count($meta) == 1) { $meta_id = key($meta); $_temp = array_shift($meta); if (!is_array($_temp) && strval($_temp) == '') { } else { $params['field_value'] = $_temp; if (!empty($params['field_value'])) { $html = types_render_field_single($field, $params, $content, $code, $meta_id); } } } else { if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; if (!empty($params['field_value'])) { $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key); } if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode(html_entity_decode($params['separator']), $output); } else { if (!empty($output)) { $output = implode(' ', $output); } } } else { // Make sure indexed right $_index = 0; foreach ($meta as $temp_key => $temp_value) { if ($_index == $index) { $params['field_value'] = $temp_value; if (!empty($params['field_value'])) { $output = types_render_field_single($field, $params, $content, $code, $temp_key); } } $_index++; } } $html = $output; } } } else { $params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if (!empty($params['field_value']) && $field['type'] != 'date') { $html = types_render_field_single($field, $params); } if ($field['type'] == 'date' && !empty($params['field_value'])) { $html = types_render_field_single($field, $params); if ($field['data']['date_and_time'] == 'and_time') { $html .= ' ' . date("H", $params['field_value']) . ':' . date("i", $params['field_value']); } } } // API filter $wpcf->usermeta_field->set($user_id, $field); $field_value = $wpcf->usermeta_field->html($html, $params); $group_output .= '<div class="wpcf-profile-field-line wpcf-profile-field-line-' . $field['slug'] . '"> <div class="wpcf-profile-line-left"> <b>' . $field['name'] . '</b> </div> <div class="wpcf-profile-line-right"> ' . $field_value . ' </div> </div>' . "\n\n"; } $group_output .= "\n\n</div>"; if (empty($echo)) { echo $group_output; } else { return $group_output; } }
/** * Calls view function for specific field type. * * @param type $field * @param type $atts * @return type */ function types_render_field($field_id = null, $params = array(), $content = null, $code = '') { if (empty($field_id)) { return ''; } global $wpcf; // HTML var holds actual output $html = ''; // Set post ID to global $post_id = get_the_ID(); // Check if other post required if (isset($params['post_id'])) { // If numeric value if (is_numeric($params['post_id'])) { $post_id = intval($params['post_id']); // WP parent } else { if ($params['post_id'] == '$parent') { $current_post = get_post($post_id); if (empty($current_post->post_parent)) { return ''; } $post_id = $current_post->post_parent; // Types parent } else { if (strpos($params['post_id'], '$') === 0) { $post_id = intval(WPCF_Relationship::get_parent($post_id, trim($params['post_id'], '$'))); } } } } if (empty($post_id)) { return ''; } // Set post $post = get_post($post_id); if (empty($post)) { return ''; } // Get field $field = types_get_field($field_id); // If field not found return empty string if (empty($field)) { // Log if (!function_exists('wplogger')) { require_once WPCF_EMBEDDED_ABSPATH . '/common/wplogger.php'; } global $wplogger; $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG); return ''; } // Set field $wpcf->field->set($post, $field); // See if repetitive if (types_is_repetitive($field)) { $wpcf->repeater->set($post_id, $field); $_meta = $wpcf->repeater->_get_meta(); $meta = $_meta['custom_order']; // Sometimes if meta is empty - array(0 => '') is returned if (count($meta) == 1 && reset($meta) == '') { return ''; } if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key); if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator']) && $params['separator'] !== '') { $output = implode(html_entity_decode($params['separator']), $output); } else { if (!empty($output)) { $output = implode(' ', $output); } else { return ''; } } } else { // Make sure indexed right $_index = 0; foreach ($meta as $temp_key => $temp_value) { if ($_index == $index) { $params['field_value'] = $temp_value; return types_render_field_single($field, $params, $content, $code, $temp_key); } $_index++; } // If missed index return ''; } $html = $output; } else { return ''; } } else { // Non-repetitive field $params['field_value'] = wpcf_get_post_meta($post_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if ($params['field_value'] == '' && $field['type'] != 'checkbox') { return ''; } $html = types_render_field_single($field, $params, $content, $code, $wpcf->field->meta_object->meta_id); } return $wpcf->field->html($html, $params); }
/** * Calls view function for specific field type. * * @param type $field * @param type $atts * @return type */ function types_render_usermeta_field($field_id, $params, $content = null, $code = '') { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; global $wpcf, $post; // HTML var holds actual output $html = ''; // Set post ID $post_id = $post->ID; if (isset($params['post_id']) && !empty($params['post_id'])) { $post_id = $params['post_id']; } // Get field $field = wpcf_fields_get_field_by_slug($field_id, 'wpcf-usermeta'); // If field not found return empty string if (empty($field)) { // Log if (!function_exists('wplogger')) { require_once WPCF_EMBEDDED_ABSPATH . '/common/wplogger.php'; } global $wplogger; $wplogger->log('types_render_usermeta_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG); return ''; } //Get user By ID if (isset($params['user_id'])) { $user_id = $params['user_id']; } else { if (isset($params['user_name'])) { //Get user by login $user_id = $wpdb->get_var("SELECT * FROM " . $wpdb->prefix . "users WHERE user_login = '******'user_name'] . "'", 0, 0); } else { if (isset($params['user_is_author'])) { //Get Post author $user_id = $post->post_author; } else { if (isset($params['user_current'])) { //Get current logged user $user_id = wpcf_usermeta_get_user(); } else { //If empty get post author, if no post, return empty if (!empty($post_id)) { $user_id = $post->post_author; } else { return; } } } } } if (empty($user_id)) { return; } // Set field $wpcf->usermeta_field->set($user_id, $field); // See if repetitive if (wpcf_admin_is_repetitive($field)) { $wpcf->usermeta_repeater->set($user_id, $field); $_meta = $wpcf->usermeta_repeater->_get_meta(); $meta = $_meta['custom_order']; // $meta = get_post_meta( $post_id, // wpcf_types_get_meta_prefix( $field ) . $field['slug'], false ); // Sometimes if meta is empty - array(0 => '') is returned if (count($meta) == 1) { $meta_id = key($meta); $_temp = array_shift($meta); if (strval($_temp) == '') { return ''; } else { $params['field_value'] = $_temp; return types_render_field_single($field, $params, $content, $code, $meta_id); } } else { if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key); if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode(html_entity_decode($params['separator']), $output); } else { if (!empty($output)) { $output = implode('', $output); } else { return ''; } } } else { // Make sure indexed right $_index = 0; foreach ($meta as $temp_key => $temp_value) { if ($_index == $index) { $params['field_value'] = $temp_value; return types_render_field_single($field, $params, $content, $code, $temp_key); } $_index++; } // If missed index return ''; } $html = $output; } else { return ''; } } } else { $params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if ($params['field_value'] == '' && $field['type'] != 'checkbox') { return ''; } $html = types_render_field_single($field, $params, $content, $code, $wpcf->usermeta_field->meta_object->umeta_id); } // API filter // $wpcf->usermeta_field->set( $user_id, $field ); return $wpcf->usermeta_field->html($html, $params); }
/** * Calls view function for specific field type. * * @param type $field * @param type $atts * @return type */ function types_render_field($field_id, $params, $content = null, $code = '') { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; global $post; // Get field $field = wpcf_fields_get_field_by_slug($field_id); if (empty($field)) { if (!function_exists('wplogger')) { require_once WPCF_EMBEDDED_ABSPATH . '/common/wplogger.php'; } global $wplogger; $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG); return ''; } // See if repetitive if (wpcf_admin_is_repetitive($field)) { $meta = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false); if (!empty($meta)) { $output = ''; if (isset($params['index'])) { $index = $params['index']; } else { $index = ''; } // Allow wpv-for-each shortcode to set the index $index = apply_filters('wpv-for-each-index', $index); if ($index === '') { $output = array(); foreach ($meta as $temp_key => $temp_value) { $params['field_value'] = $temp_value; $temp_output = types_render_field_single($field, $params, $content, $code); if (!empty($temp_output)) { $output[] = $temp_output; } } if (!empty($output) && isset($params['separator'])) { $output = implode($params['separator'], $output); } else { if (!empty($output)) { $output = implode('', $output); } else { return ''; } } } else { if (isset($meta[$index])) { $params['field_value'] = $meta[$index]; return types_render_field_single($field, $params, $content, $code); } else { return ''; } } return $output; } else { return ''; } } else { $params['field_value'] = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true); if ($params['field_value'] == '' && $field['type'] != 'checkbox') { return ''; } return types_render_field_single($field, $params, $content, $code); } }
// TODO set the field slug you want to display // Parameters that define the field $field_definition = wpcf_fields_get_field_by_slug($field_slug); if (!empty($field_definition)) { // Get the raw field data. $images = get_post_meta($post_id, "wpcf-{$field_slug}"); foreach ($images as $image_index => $image) { // Parameters for the Types field rendering mechanism. $image_parameters = array('proportional' => 'true', 'url' => 'true', 'field_value' => $image); // Get an image of specific (maximum) proportions. // NOTE: Update image size to your needs $thumbnail_parameters = array_merge($image_parameters, array('width' => '200', 'height' => '200')); $thumbnail_url = types_render_field_single($field_definition, $thumbnail_parameters, null, '', $image_index); // Get the image in full size. $fullsize_parameters = array_merge($image_parameters, array('size' => 'full')); $fullsize_url = types_render_field_single($field_definition, $fullsize_parameters, null, '', $image_index); // Append the markup (a thumbnail linking to the full image) to existing content. // NOTE: Customize the output to your needs $output .= sprintf('<div class="img"><a href=" ' . $fullsize_url . ' "><img src=" ' . $thumbnail_url . ' "></a></div>'); } } echo $output; } ?> </div><!-- .entry-content --> <!-- Continue the standard Twenty Sixteen content footer output --> <footer class="entry-footer"> <?php twentysixteen_entry_meta();