array(), 'name' => null, 'class' => '', 'id' => '', 'selected' => 0, 'chosen' => false, 'placeholder' => null, 'multiple' => false, 'show_option_all' => _x( 'All', 'all dropdown items', 'easy-digital-downloads' ), 'show_option_none' => _x( 'None', 'no dropdown items', 'easy-digital-downloads' ) ); $args = wp_parse_args( $args, $defaults ); if( $args['multiple'] ) { $multiple = ' MULTIPLE'; } else { $multiple = ''; } if( $args['chosen'] ) { $args['class'] .= ' adsensei-select-chosen'; } if( $args['placeholder'] ) { $placeholder = $args['placeholder']; } else { $placeholder = ''; } $output = ''; return $output; } /** * Renders an HTML Checkbox * * @since 0.9.0 * * @param array $args * * @return string */ public function checkbox( $args = array() ) { $defaults = array( 'name' => null, 'current' => null, 'class' => 'adsensei-checkbox', 'value' => "1", 'options' => array( 'disabled' => false, 'readonly' => false ) ); $args = wp_parse_args( $args, $defaults ); $options = ''; if ( ! empty( $args['options']['disabled'] ) ) { $options .= ' disabled="disabled"'; } elseif ( ! empty( $args['options']['readonly'] ) ) { $options .= ' readonly'; } $output = ''; return $output; } /** * Renders an HTML Text field * * @since 0.9.0 * * @param array $args Arguments for the text field * @return string Text field */ public function text( $args = array() ) { // Backwards compatabliity if ( func_num_args() > 1 ) { $args = func_get_args(); $name = $args[0]; $value = isset( $args[1] ) ? $args[1] : ''; $label = isset( $args[2] ) ? $args[2] : ''; $desc = isset( $args[3] ) ? $args[3] : ''; } $defaults = array( 'id' => '', 'name' => isset( $name ) ? $name : 'text', 'value' => isset( $value ) ? $value : null, 'label' => isset( $label ) ? $label : null, 'desc' => isset( $desc ) ? $desc : null, 'placeholder' => '', 'class' => isset( $args['class'] ) ? 'regular-text ' . $args['class'] : 'regular-text', 'disabled' => false, 'autocomplete' => '', 'data' => false ); $args = wp_parse_args( $args, $defaults ); $disabled = ''; if( $args['disabled'] ) { $disabled = ' disabled="disabled"'; } $data = ''; if ( ! empty( $args['data'] ) ) { foreach ( $args['data'] as $key => $value ) { $data .= 'data-' . $key . '="' . $value . '" '; } } $output = ''; $output .= ''; if ( ! empty( $args['desc'] ) ) { $output .= '' . esc_html( $args['desc'] ) . ''; } $output .= ''; $output .= ''; return $output; } /** * Renders a date picker * * @since 0.9.0 * * @param array $args Arguments for the text field * @return string Datepicker field */ public function date_field( $args = array() ) { if( empty( $args['class'] ) ) { $args['class'] = 'adsensei_datepicker'; } elseif( ! strpos( $args['class'], 'adsensei_datepicker' ) ) { $args['class'] .= ' adsensei_datepicker'; } return $this->text( $args ); } /** * Renders an HTML textarea * * @since 0.9.0 * * @param array $args Arguments for the textarea * @return string textarea */ public function textarea( $args = array() ) { $defaults = array( 'name' => 'textarea', 'value' => null, 'label' => null, 'desc' => null, 'class' => 'large-text', 'disabled' => false, 'placeholder' => '', ); $args = wp_parse_args( $args, $defaults ); $disabled = ''; if( $args['disabled'] ) { $disabled = ' disabled="disabled"'; } $output = ''; $output .= ''; $output .= ''; if ( ! empty( $args['desc'] ) ) { $output .= '' . esc_html( $args['desc'] ) . ''; } $output .= ''; return $output; } /** * Renders an HTML Dropdown of years * * @access public * @since 0.9.0 * @param string $name Name attribute of the dropdown * @param int $selected Year to select automatically * @param int $years_before Number of years before the current year the dropdown should start with * @param int $years_after Number of years after the current year the dropdown should finish at * @return string $output Year dropdown */ public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { $current = date( 'Y' ); $start_year = $current - absint( $years_before ); $end_year = $current + absint( $years_after ); $selected = empty( $selected ) ? date( 'Y' ) : $selected; $options = array(); while ( $start_year <= $end_year ) { $options[ absint( $start_year ) ] = $start_year; $start_year++; } $output = $this->select( array( 'name' => $name, 'selected' => $selected, 'options' => $options, 'show_option_all' => false, 'show_option_none' => false ) ); return $output; } /** * Renders an HTML Dropdown of months * * @access public * @since 0.9.0 * @param string $name Name attribute of the dropdown * @param int $selected Month to select automatically * @return string $output Month dropdown */ public function month_dropdown( $name = 'month', $selected = 0 ) { $month = 1; $options = array(); $selected = empty( $selected ) ? date( 'n' ) : $selected; while ( $month <= 12 ) { $options[ absint( $month ) ] = adsensei_month_num_to_name( $month ); $month++; } $output = $this->select( array( 'name' => $name, 'selected' => $selected, 'options' => $options, 'show_option_all' => false, 'show_option_none' => false ) ); return $output; } }