1 <?php
2 /**
3 * HTML elements
4 *
5 * A helper class for outputting common HTML elements, such as product drop downs
6 *
7 * @package EDD
8 * @subpackage Classes/HTML
9 * @copyright Copyright (c) 2012, Pippin Williamson
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.5
12 */
13
14 // Exit if accessed directly
15 if ( ! defined( 'ABSPATH' ) ) exit;
16
17 /**
18 * EDD_HTML_Elements Class
19 *
20 * @since 1.5
21 */
22 class EDD_HTML_Elements {
23 /**
24 * Renders an HTML Dropdown of all the Products (Downloads)
25 *
26 * @access public
27 * @since 1.5
28 * @param string $name Name attribute of the dropdown
29 * @param int $selected Download to select automatically
30 * @return string $output Product dropdown
31 */
32 public function product_dropdown( $name = 'edd_products', $selected = 0 ) {
33 $products = get_posts( array( 'post_type' => 'download', 'nopaging' => true ) );
34
35 $output = '<select name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '">';
36
37 if ( $products ) {
38 foreach ( $products as $product ) {
39 $output .= '<option value="' . absint( $product->ID ) . '"' . selected( $selected, $product->ID, false ) . '>' . esc_html( get_the_title( $product->ID ) ) . '</option>';
40 }
41 } else {
42 $output .= '</option value="0">' . __( 'No products found', 'edd' ) . '</option>';
43 }
44
45 $output .= '</select>';
46
47 return $output;
48 }
49 }