$box ) { add_meta_box( slt_cf_prefix( 'post' ) . $box['id'], $box['title'], 'slt_cf_display_box', $post_type, $box['context'], $box['priority'], array( 'box' => $box_key ) ); } } // Inline scripting for moving boxes above content add_action( 'admin_head-post.php', 'slt_cf_move_metaboxes' ); add_action( 'admin_head-post-new.php', 'slt_cf_move_metaboxes' ); function slt_cf_move_metaboxes() { global $slt_custom_fields; $output = array(); foreach ( $slt_custom_fields['boxes'] as $box_key => $box ) { if ( array_key_exists( 'above_content', $box ) && $box['above_content'] ) $output[] = 'slt_cf_metaboxes_above_content.push( "' . slt_cf_prefix( 'post' ) . $box['id'] . '" );'; } if ( ! empty( $output ) ) { ?> $box ) slt_cf_display_box( $user, $box_key, 'user' ); } /* Add fields to an attachment screen * No boxes / sections, just loop through all fields ***************************************************************************/ function slt_cf_add_attachment_fields( $form_fields, $post ) { global $slt_custom_fields; foreach ( $slt_custom_fields['boxes'] as $box_key => $box ) { foreach ( $box['fields'] as $field ) { // Only certain fields types allowed for now if ( ! in_array( $field['type'], array( 'text', 'select' ) ) ) continue; // Add into form fields array $field_name = slt_cf_prefix( 'attachment' ) . $field['name']; $form_fields[ $field_name ] = array(); $form_fields[ $field_name ]['label'] = $field['label']; $form_fields[ $field_name ]['value'] = slt_cf_field_value( $field['name'], 'attachment', $post->ID, '', '', false, $field['single'] ); $form_fields[ $field_name ]['input'] = 'html'; $input_field_name = "attachments[{$post->ID}][{$field_name}]"; switch ( $field['type'] ) { case 'select': { $form_fields[ $field_name ]['html'] = slt_cf_input_select( $input_field_name, $form_fields[ $field_name ]['value'], $field['input_prefix'], $field['input_suffix'], array(), array(), false, $field['options'], $field['multiple'], ( $field['options_type'] != 'static' && ! $field['required'] ), $field['empty_option_text'], $field['no_options'] ); break; } case 'text': { $form_fields[ $field_name ]['html'] = slt_cf_input_text( $input_field_name, $form_fields[ $field_name ]['value'], $field['prefix'], $field['suffix'], array(), array(), false ); break; } } if ( $field['description'] ) $form_fields[ $field_name ]['helps'] = $field['description']; } } return $form_fields; } /* Display a box's fields ***************************************************************************/ function slt_cf_display_box( $object, $custom_data, $request_type = 'post' ) { global $slt_custom_fields; static $date_output = false; // Initialize switch ( $request_type ) { case 'post': { // Get the key of the box we're in from the args $box_key = $custom_data['args']['box']; // Nonce for security wp_nonce_field( slt_cf_prefix( 'post' ) . $slt_custom_fields['boxes'][$box_key]['id'] . '_save', $slt_custom_fields['prefix'] . $slt_custom_fields['boxes'][$box_key]['id'] . '_wpnonce', false, true ); break; } case 'user': { // Get box key and output initial markup $box_key = $custom_data; echo '
| '; $after_label = ' | '; $before_input = ''; $after_input = ' | '; break; } } // Cloning // [under development] /*if ( $field['cloning'] ) { $after_input = '
|---|
' . $no_options . '
'; $output .= ''; } else { if ( $multiple ) { $input_styles[] = 'height:auto'; } else if ( $prefix ) { $output .= $prefix . ' '; } $output .= ''; if ( ! $multiple && $suffix ) $output .= ' ' . $suffix; } if ( $echo ) echo $output; else return $output; }