$option ) );
}
function paf_option_return_title( $option_def ) {
$option_id = key( $option_def );
$option = $option_def[ $option_id ];
$title = K::get_var( 'title', $option, $option_id );
$subtitle = K::get_var( 'subtitle', $option );
$return =
$title
. ( $subtitle
? '
' . $subtitle . ''
: ''
)
;
return $return;
}
function paf_option_return_format( $option_type = 'input' ) {
switch ( $option_type ) {
case 'media':
return '
| %s | :input%s %s |
|---|
| %s | :' . $option_type . ' %s |
|---|
', 'html_after' => '', 'in' => 'code', 'return' => true, ) ); // Remove white space before 'array (' $dump = preg_replace( '/=>\s+array \(/s', '=> array (', $dump ); // Replace 2 spaces with 4 spaces $pattern = "/((?: )+)(\d+|'|array|\))/"; $dump = preg_replace( $pattern, '\1\1\2', $dump ); return $dump; } function paf_print_option_type_text( $option_def ) { $option_id = key( $option_def ); $option = $option_def[ $option_id ]; K::input( 'paf[' . $option_id . ']' , array( 'class' => 'regular-text', 'placeholder' => K::get_var( 'placeholder', $option ), 'value' => isset( $option[ 'value' ] ) ? $option[ 'value' ] : paf( $option_id ) , 'data-paf-conditions' => K::get_var( 'conditions', $option ) ? urlencode( json_encode( K::get_var( 'conditions', $option ), JSON_FORCE_OBJECT ) ) : null , 'data-paf-default' => K::get_var( 'default', $option ), ) , array( 'colorpicker' => K::get_var( 'colorpicker', $option, FALSE ), 'format' => sprintf( paf_option_return_format() , paf_option_return_title( $option_def ) , K::get_var( 'description', $option, '' ) ) ) ); } function paf_print_option_type_textarea( $option_def ) { $option_id = key( $option_def ); $option = $option_def[ $option_id ]; if( '~' === K::get_var( 'description', $option ) ) { $option[ 'description' ] = paf_option_return_dump( $option_id ); } $style = ''; foreach( array( 'height', 'width' ) as $prop ) { $style .= K::get_var( $prop, $option ) ? sprintf( '%:%;', $prop, $option[ $prop ] ) : '' ; } K::textarea( 'paf[' . $option_id . ']' , array( 'class' => K::get_var( 'cols', $option ) ? '' : 'large-text', 'cols' => K::get_var( 'cols', $option ), 'rows' => K::get_var( 'rows', $option ), 'style' => $style, 'data-paf-conditions' => K::get_var( 'conditions', $option ) ? urlencode( json_encode( K::get_var( 'conditions', $option ), JSON_FORCE_OBJECT ) ) : null , 'data-paf-default' => K::get_var( 'default', $option ), ) , array( 'value' => isset( $option[ 'value' ] ) ? $option[ 'value' ] : paf( $option_id ) , 'editor' => K::get_var( 'editor', $option, FALSE ), 'editor_height' => K::get_var( 'editor_height', $option ), 'format' => sprintf( paf_option_return_format( 'textarea' ) , paf_option_return_title( $option_def ) , K::get_var( 'description', $option, '' ) ), 'media_buttons' => K::get_var( 'media_buttons', $option, TRUE ), 'teeny' => K::get_var( 'teeny', $option ), 'textarea_rows' => K::get_var( 'textarea_rows', $option, 20 ), ) ); } function paf_print_option_type_select( $option_def ) { $option_id = key( $option_def ); $option = $option_def[ $option_id ]; if( '~' === K::get_var( 'description', $option ) ) { $option[ 'description' ] = paf_option_return_dump( $option_id ); } $is_radio = 'radio' === $option[ 'type' ]; $is_checkbox = 'checkbox' === $option[ 'type' ]; $is_select = 'select' === $option[ 'type' ]; $is_multiple = $is_checkbox || K::get_var( 'multiple', $option ); // Enqueue select 2 if( ! $is_checkbox && ! $is_radio ) { $protocol = is_ssl() ? 'https' : 'http'; wp_enqueue_script( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js' ); wp_enqueue_style( 'select2', $protocol . '://cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.min.css' ); } $options = array(); switch ( K::get_var( 'options', $option, array() ) ) { case 'posts': $posts = query_posts( K::get_var( 'args', $option, '' ) ); foreach ( $posts as $post ) { $options[ $post->ID ] = $post->post_title; } if ( $is_select && ! $is_multiple ) { $options = array( '' ) + $options; } break; case 'terms': $taxonomies = K::get_var( 'taxonomies', $option, 'category,post_tag,link_category,post_format' ); if ( ! is_array( $taxonomies ) ) { $taxonomies = explode( ',', $taxonomies ); } $args = K::get_var( 'args', $option, array() ); $terms = get_terms( $taxonomies, $args ); foreach ( $terms as $term ) { $options[ $term->term_id ] = $term->name; } if ( $is_select && ! $is_multiple ) { $options = array( '' ) + $options; } break; default: $options = K::get_var( 'options', $option, array() ); break; } // Add an empty option to prevent auto-selecting the first radio if( $is_radio ) { $options = array( '__none__' => '' ) + $options; } // Escape HTML foreach ( $options as $k => $v ) { $options[ $k ] = htmlspecialchars( $v ); } K::select( 'paf[' . $option_id . ']' , array( 'class' => 'paf-option-type-' . $option[ 'type' ], 'data-paf-separator' => K::get_var( 'separator', $option, '
' . __( 'The option type %s is not yet implemented' ) . '