• Varun Sridharan's avatar
    WooCommerce Quick Donation 1.3.x Beta Version · 9c660c91
    Varun Sridharan authored
    Redeveloping The Plugin.
    Created Custom Post Type
    Created Custom Taxonomy {Category & Tags}
    Created Short code
    Project Output Like Select , Radio [Single or grouped]
    Price Box Output
    Customization Template
    
    [admin/class-admin-init.php]
    
    Added woocommerce_screen_ids
    Removed Admin Notice Handler Class Init
    Added Plugins Settings Page ID To WC Screen ID
    
    [admin/class-admin-settings.php & admin/class-donation-settings.php]
    
    Working To Get A Prefect Settings Page
    
    [admin/includes/class-admin-functions.php]
    
    Changed WC_QD()->donation_id to WC_QD_ID
    
    [includes/class-quick-donation-process.php]
    
    Created Class To Process Front End Donation Form
    
    [includes/class-shortcode-handler.php]
    
    Created 2 Actions
    wc_quick_donation_before_donation_form
    wc_quick_donation_after_donation_form
    
    [woocommerce-quick-donation.php]
    
    Changed $donation_id from dynimic to static
    Added WC_QD_ID defined variable
    
    Rearranged Few Loading Files
    
    Added Donation Processing Email
    Added Prefect Settings Framework
    Added Seperate Page For Listing Donations
    9c660c91
user.php 2.28 KB
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;

// Make sure "select" field is loaded
require_once WCQD_METABOX_FIELDS_DIR . 'select-advanced.php';

if ( ! class_exists( 'WCQD_METABOX_User_Field' ) )
{
	class WCQD_METABOX_User_Field extends WCQD_METABOX_Select_Advanced_Field
	{
		/**
		 * Get field HTML
		 *
		 * @param mixed $meta
		 * @param array $field
		 *
		 * @return string
		 */
		static function html( $meta, $field )
		{
			$field['options'] = self::get_options( $field );
			switch ( $field['field_type'] )
			{
				case 'select':
					return WCQD_METABOX_Select_Field::html( $meta, $field );
					break;
				case 'select_advanced':
				default:
					return WCQD_METABOX_Select_Advanced_Field::html( $meta, $field );
			}
		}

		/**
		 * Normalize parameters for field
		 *
		 * @param array $field
		 *
		 * @return array
		 */
		static function normalize_field( $field )
		{
			$field = wp_parse_args( $field, array(
				'field_type' => 'select_advanced',
				'parent'     => false,
				'query_args' => array(),
			) );

			$field['std'] = empty( $field['std'] ) ? __( 'Select an user', 'meta-box' ) : $field['std'];

			$field['query_args'] = wp_parse_args( $field['query_args'], array(
				'orderby' => 'display_name',
				'order'   => 'asc',
				'role'    => '',
				'fields'  => 'all',
			) );

			switch ( $field['field_type'] )
			{
				case 'select':
					return WCQD_METABOX_Select_Field::normalize_field( $field );
					break;
				case 'select_advanced':
				default:
					return WCQD_METABOX_Select_Advanced_Field::normalize_field( $field );
			}
		}

		/**
		 * Get users
		 *
		 * @param array $field
		 *
		 * @return array
		 */
		static function get_options( $field )
		{
			$results = get_users( $field['query_args'] );
			$options = array();
			foreach ( $results as $result )
			{
				$options[$result->ID] = $result->display_name;
			}

			return $options;
		}

		/**
		 * Get option label to display in the frontend
		 *
		 * @param int   $value Option value
		 * @param int   $index Array index
		 * @param array $field Field parameter
		 *
		 * @return string
		 */
		static function get_option_label( &$value, $index, $field )
		{
			$user  = get_userdata( $value );
			$value = '<a href="' . get_author_posts_url( $value ) . '">' . $user->display_name . '</a>';
		}
	}
}