Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter KeanuTang

    (@tedtang)

    Modified the JavaScript to work with removing filters:

                            <script>
    
                                jQuery(document).ready( function() {
    
                                    jQuery( document.body ).on( 'blur', '.um-directory .um-search-filter.um-text-filter-type input[type="text"]', function() {
    
                                        queryString = '';
    
                                        if (window.location.href.includes('?')) {
    
                                            queryString = window.location.href.slice(window.location.href.indexOf('?') + 1);
    
                                        }
    
                                        jQuery('#download-as-csv').attr('href', 'download.csv?' + queryString);
    
                                    });
    
                                    wp.hooks.addFilter( 'um_member_directory_ignore_after_search', 'namespace', function( ){
    
                                        queryString = '';
    
                                        if (window.location.href.includes('?')) {
    
                                            queryString = window.location.href.slice(window.location.href.indexOf('?') + 1);
    
                                        }
    
                                        jQuery('#download-as-csv').attr('href', 'download.csv?' + queryString);
    
                                    } );
    
                                });
    
                            </script>
    Thread Starter KeanuTang

    (@tedtang)

    And the full approach…

    In /ultimate-member/templates/members.php:

                            <div>
    
                                <a id="download-as-csv" href="download.csv?<?php echo $query; ?>">Download as CSV</a>
    
                            </div>
    
                            <script>
    
                                jQuery( document.body ).on( 'blur', '.um-directory .um-search-filter.um-text-filter-type input[type="text"]', function() {
    
                                    queryString = window.location.href.slice(window.location.href.indexOf('?') + 1);
    
                                    jQuery('#download-as-csv').attr('href', 'download.csv?' + queryString);
    
                                });
    
                            </script>

    In my theme’s functions.php file:

    <?php
    
    add_action('template_redirect','download_directory_as_csv');
    
    function download_directory_as_csv() {
    
      if (is_user_logged_in() && str_starts_with($_SERVER['REQUEST_URI'], '/path-to-directory/download.csv?')) {
    
        include 'inc/generate_directory_csv.php';
    
        exit();
    
      }
    
    }

    In inc/generate_directory_csv.php:

    <?php
    
    if (!is_user_logged_in()) {
    
    ? ? exit();
    
    }
    
    $form_id = 494; ?
    
    global $wpdb;
    
    $field_prefix = 'filter_';
    
    $field_suffix = '_ddb1c';
    
    //Headers
    
    header("Content-type: application/x-msdownload",true,200);
    
    header("Content-Disposition: attachment; filename=download.csv");
    
    header("Pragma: no-cache");
    
    header("Expires: 0");
    
    ob_start();
    
    $df = fopen("php://output", 'w');
    
    // Get the fields in a sorted array
    
    $fields = get_post_meta( $form_id, '_um_custom_fields', true );
    
    if ( ! empty( $fields ) && is_array( $fields ) ) {
    
    ? ? foreach ( $fields as $field_key => $field ) {
    
    ? ? ? ? if (isset($field["position"])) {
    
    ? ? ? ? ? ? $field_array[$field["position"]] = $field_key;
                $field_names[$field_key] = $field["label"];
    
    ? ? ? ? }
    
    ? ? }
    
    ? ? ksort($field_array, SORT_NUMERIC);
    
    }
    
    // Build the header
    
    $header = array();
    
    foreach ( $field_array as $key => $field ) {
    
    ? ? $header[] = $field_names[$field];
    
    }
    
    fputcsv($df, $header);
    
    // Reproduce the search query and select the right user IDs
    
    $joins = array();
    
    $where_clauses = array();
    
    foreach ($_GET as $key => $value) {
    
    ? ? if (str_starts_with($key, $field_prefix) && str_ends_with($key, $field_suffix)) {
    
    ? ? ? ? $field = $key;
    
    ? ? ? ? $field = str_replace($field_prefix, '', $field);
    
    ? ? ? ? $field = str_replace($field_suffix, '', $field);
    
    ? ? ? ? $joins[] = "LEFT JOIN {$wpdb->usermeta} {$field} ON {$field}.user_id = u.ID";
    
    ? ? ? ? $where_clauses[] = $wpdb->prepare( "{$field}.meta_key = %s and {$field}.meta_value LIKE '%%%s%%'", $field, $value ); ? ?
    
    ? ? }
    
    }
    
    $joins[] = "LEFT JOIN {$wpdb->usermeta} role ON role.user_id = u.ID";
    
    $where_clauses[] = $wpdb->prepare( "role.meta_key = %s and role.meta_value LIKE '%%%s%%'", ($wpdb->get_blog_prefix( $blog_id ) . "capabilities"), "directory_member_role" );
    
    $sql_join = implode( ' ', $joins );
    
    $sql_where = implode( ' AND ', $where_clauses );
    
    $sql_where = ! empty( $sql_where ) ? 'AND ' . $sql_where : '';
    
    $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
    
    $user_ids = $wpdb->get_results(
    
    ? ? "SELECT DISTINCT u.ID
    
    ? ? FROM {$wpdb->users} AS u
    
    ? ? {$sql_join}
    
    ? ? WHERE 1=1 {$sql_where}"
    
    );
    
    // Get the data for each user
    
    foreach ($user_ids as $user_id) {
    
    ? ? $id = $user_id->ID;
    
    ? ? $wpdb->query( 'SET SQL_BIG_SELECTS=1' );
    
    ? ? $user_data = $wpdb->get_results(
    
    ? ? ? ? "SELECT meta_key,meta_value
    
    ? ? ? ? FROM {$wpdb->usermeta} AS um
    
    ? ? ? ? WHERE {$wpdb->prepare( "um.user_id = %s", $id )}"
    
    ? ? );
    
    ? ? //Translate to an array for easy access
    
    ? ? $user_array = array();
    
    ? ? foreach ($user_data as $row_data) {
    
    ? ? ? ? $user_array[$row_data->meta_key] = $row_data->meta_value;
    
    ? ? }
    
    ? ? $row = array();
    
    ? ? foreach ( $field_array as $key => $field ) {
    
    ? ? ? ? $data = maybe_unserialize($user_array[$field]);
    
    ? ? ? ? if (is_array($data)) {
    
    ? ? ? ? ? ? $data = implode(',', $data);
    
    ? ? ? ? }
    
    ? ? ? ? $row[] = $data;
    
    ? ? }
    
    ? ? fputcsv($df, $row);
    
    }
    
    fclose($df);
    
    echo ob_get_clean();
    • This reply was modified 1 year, 3 months ago by KeanuTang.
    • This reply was modified 1 year, 3 months ago by KeanuTang.
    Thread Starter KeanuTang

    (@tedtang)

    If anyone is interested, this is what I used to get the form’s fields in sorted order:

    $form_id = 494;
    $fields = get_post_meta( $form_id, '_um_custom_fields', true );
    if ( ! empty( $fields ) && is_array( $fields ) ) {
    foreach ( $fields as $field_key => $field ) {
    if (isset($field["position"])) {
    $field_array[$field["position"]] = $field_key;
    }
    }

    ksort($field_array, SORT_NUMERIC);

    }

    • This reply was modified 1 year, 3 months ago by KeanuTang.
    • This reply was modified 1 year, 3 months ago by KeanuTang.
    Thread Starter KeanuTang

    (@tedtang)

    I ended up doing this:

    /* When filtering on class number, perform an exact match */
    add_action("um_user_before_query","um_exact_class_number_match", 10, 2 );
    function um_exact_class_number_match( $query_args, $obj ){
    ? ? foreach ($obj->query_args['meta_query'] as $key1 => $value1) {
    ? ? ? ? foreach ($obj->query_args['meta_query'][$key1] as $key2 => $value2) {
    ? ? ? ? ? ? if ($obj->query_args['meta_query'][$key1][$key2]['key'] == 'x_ClassNumber') {
    ? ? ? ? ? ? ? ? $obj->query_args['meta_query'][$key1][$key2]['compare'] = '=';
    ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? }
    }
    • This reply was modified 1 year, 6 months ago by KeanuTang.

    Could you explain why adding that line of code fixes the problem? I want to make sure it doesn’t break something else.

    I second this. It sure does bust buttons. I just updated a website and it seemed to also break Containers, especially the background image and background overlay of Containers.

    Did you get this resolved? Are you using the Gutenberg block editor? You could try this plugin:

    https://www.ads-software.com/plugins/display-a-meta-field-as-block/

    If you need to use a shortcode, I ran into this issue and put together this plugin. You only need the build folder and .php file to get it running. KeanuTang/query-loop-shortcode: WordPress Plugin for Gutenberg Shortcode Block to Work Within Query Loops (github.com)

    I ran into this issue as well. I slapped together this plugin to address it. You just need the build folder and query-loop-shortcode.php:

    KeanuTang/query-loop-shortcode: WordPress Plugin for Gutenberg Shortcode Block to Work Within Query Loops (github.com)

    Thread Starter KeanuTang

    (@tedtang)

    For reference, I ran into this as I was investigating this post: Adding a download .ics link | www.ads-software.com

    Thread Starter KeanuTang

    (@tedtang)

    For reference, to my question of “what’s the functional difference?” this may be one reason why I don’t see a difference: Bug in “Export Outlook .ics file” | www.ads-software.com

    Thread Starter KeanuTang

    (@tedtang)

    This doesn’t seem to be documented anywhere, but you can hide the iCalendar option with this line of code. We’re worried it’ll be confusing to end users what the difference between iCalendar and export .ics will be:

    add_filter( 'tec_views_v2_subscribe_link_ical_visibility', '__return_false' );

    Thread Starter KeanuTang

    (@tedtang)

    I figured out that I can use the newer subscribe format and add Export options using this code:

    add_filter( 'tec_views_v2_subscribe_link_ics_visibility', '__return_true' );
    add_filter( 'tec_views_v2_subscribe_link_outlook-ics_visibility', '__return_true' );

    My follow-up question is: What’s the functional difference between the two export options? Why is Outlook somehow different?

    Thread Starter KeanuTang

    (@tedtang)

    I just tried this, but it still skips 960. Before any changes, I had it set to 1000px.

    Thanks for all your help!

    Thread Starter KeanuTang

    (@tedtang)

    Thank you, that was helpful. I was able to use your CSS example to adjust the profile image size at different widths. Everything worked except for the class for uimob960. For some reason, that selector doesn’t seem to be applying. As I’m inspecting, I see uimob800 but never see uimob960. This is what I ended up using:

    /* profile photo size for medium devices (Tablet) */
    .uimob960.um.um-profile .um-header .um-profile-photo .um-profile-photo-img{
        width: 300px !important;
        height: 300px !important;
        max-width: 300px !important;
    }
    .uimob800.um.um-profile .um-header .um-profile-photo .um-profile-photo-img{
        width: 250px !important;
        height: 250px !important;
        max-width: 250px !important;
    }
    /* profile photo size for small devices (Mobile) */
    .uimob500.um.um-profile .um-header .um-profile-photo .um-profile-photo-img{
        width: 200px !important;
        height: 200px !important;
        max-width: 200px !important;
    }
    .uimob340.um.um-profile .um-header .um-profile-photo .um-profile-photo-img{
        width: 150px !important;
        height: 150px !important;
        max-width: 150px !important;
    }
Viewing 14 replies - 1 through 14 (of 14 total)