function wpv_get_filter_users_summary_txt_addon($view_settings)
{
    $output = '';
    $summary = '';
    foreach (array_keys($view_settings) as $key) {
        if (strpos($key, 'usermeta-field-') === 0 && strpos($key, '_compare') === strlen($key) - strlen('_compare')) {
            $name = substr($key, 0, strlen($key) - strlen('_compare'));
            if ($summary != '') {
                if ($view_settings['usermeta_fields_relationship'] == 'OR') {
                    $summary .= __(' OR', 'wpv-views');
                } else {
                    $summary .= __(' AND', 'wpv-views');
                }
            }
            $summary .= wpv_get_usermeta_field_summary($name, $view_settings);
        }
    }
    if (!empty($summary)) {
        $output .= __(' and ', 'wpv-views') . $summary;
    }
    if (isset($view_settings['users_orderby'])) {
        $output .= __(' ordered by ', 'wpv-views') . $view_settings['users_orderby'];
    }
    $order = __('descending', 'wpv-views');
    if (isset($view_settings['users_order']) && $view_settings['users_order'] == 'ASC') {
        $order = __('ascending', 'wpv-views');
    }
    $output .= ', ' . $order;
    if (isset($view_settings['users_limit']) && intval($view_settings['users_limit']) != -1) {
        if (intval($view_settings['users_limit']) == 1) {
            $output .= __(', limit to 1 item', 'wpv-views');
        } else {
            $output .= sprintf(__(', limit to %d items', 'wpv-views'), intval($view_settings['users_limit']));
        }
    }
    if (isset($view_settings['users_limit']) && intval($view_settings['users_offset']) != 0) {
        if (intval($view_settings['users_limit']) == 1) {
            $output .= __(', skip first item', 'wpv-views');
        } else {
            $output .= sprintf(__(', skip %d items', 'wpv-views'), intval($view_settings['users_offset']));
        }
    }
    return $output;
}
Exemplo n.º 2
0
/**
* wpv_get_filter_usermeta_field_summary_txt
*
* Returns the usermeta fields filter summary for a View
*
* @param $view_settings
*
* @returns (string) $summary
*
* @since unknown
*/

function wpv_get_filter_usermeta_field_summary_txt( $view_settings ) {
	$result = '';
	if ( isset( $view_settings['query_type'] ) && $view_settings['query_type'][0] == 'users' ) {
		$count = 0;
		foreach ( array_keys( $view_settings ) as $key ) {
			if ( strpos( $key, 'usermeta-field-' ) === 0 && strpos( $key, '_compare' ) === strlen( $key ) - strlen( '_compare' ) ) {
				$name = substr( $key, 0, strlen( $key ) - strlen( '_compare' ) );
				$count++;
				if ( $result != '' ) {
					if ( isset( $view_settings['usermeta_fields_relationship'] ) && $view_settings['usermeta_fields_relationship'] == 'OR' ) {
						$result .= __( ' OR', 'wpv-views' );
					} else {
						$result .= __( ' AND', 'wpv-views' );
					}
				}
				$result .= wpv_get_usermeta_field_summary( $name, $view_settings );
			}
		}
	}
	return $result;
}
 static function wpv_filter_usermeta_field_update_callback()
 {
     if (!current_user_can('manage_options')) {
         $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'wpv-views'));
         wp_send_json_error($data);
     }
     if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'wpv_view_filter_usermeta_field_nonce')) {
         $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'wpv-views'));
         wp_send_json_error($data);
     }
     if (!isset($_POST["id"]) || !is_numeric($_POST["id"]) || intval($_POST['id']) < 1) {
         $data = array('type' => 'id', 'message' => __('Wrong or missing ID.', 'wpv-views'));
         wp_send_json_error($data);
     }
     if (empty($_POST['filter_usermeta_fields'])) {
         $data = array('type' => 'data_missing', 'message' => __('Wrong or missing data.', 'wpv-views'));
         wp_send_json_error($data);
     }
     $change = false;
     $view_id = $_POST['id'];
     parse_str($_POST['filter_usermeta_fields'], $filter_usermeta_fields);
     $view_array = get_post_meta($view_id, '_wpv_settings', true);
     $summary = __('Select users with usermeta field: ', 'wpv-views');
     $result = '';
     foreach ($filter_usermeta_fields as $filter_key => $filter_data) {
         if (!isset($view_array[$filter_key]) || $filter_data != $view_array[$filter_key]) {
             if (is_array($filter_data)) {
                 $filter_data = array_map('sanitize_text_field', $filter_data);
                 $filter_data = array_map(array('WPV_Usermeta_Field_Filter', 'fix_lower_saving'), $filter_data);
             } else {
                 $filter_data = sanitize_text_field($filter_data);
                 $filter_data = WPV_Usermeta_Field_Filter::fix_lower_saving($filter_data);
             }
             $change = true;
             $view_array[$filter_key] = $filter_data;
         }
     }
     if (!isset($view_array['usermeta_fields_relationship'])) {
         $view_array['usermeta_fields_relationship'] = 'AND';
         $change = true;
     }
     if ($change) {
         update_post_meta($view_id, '_wpv_settings', $view_array);
         do_action('wpv_action_wpv_save_item', $view_id);
     }
     foreach (array_keys($view_array) as $key) {
         if (strpos($key, 'usermeta-field-') === 0 && strpos($key, '_compare') === strlen($key) - strlen('_compare')) {
             $name = substr($key, 0, strlen($key) - strlen('_compare'));
             if ($result != '') {
                 if ($view_array['usermeta_fields_relationship'] == 'OR') {
                     $result .= __(' OR', 'wpv-views');
                 } else {
                     $result .= __(' AND', 'wpv-views');
                 }
             }
             $result .= wpv_get_usermeta_field_summary($name, $view_array);
         }
     }
     $summary .= $result;
     $data = array('id' => $view_id, 'message' => __('Usermeta field filter saved', 'wpv-views'), 'summary' => $summary);
     wp_send_json_success($data);
 }