Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into v2.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
adammacias committed Jul 2, 2015
2 parents 4a721e8 + e8ea610 commit a91f143
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tmtags
nbproject/*
.ftppass
.sftp-config.json
sftp-config.json

# Project
src/.sass-cache/*
Expand Down
96 changes: 90 additions & 6 deletions core/classes/class-metabox.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<?php
/**
* Odin_Metabox class.
Expand Down Expand Up @@ -45,6 +46,11 @@ public function __construct( $id, $title, $post_type = 'post', $context = 'norma

// Load scripts.
add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );

// Add post type columns
add_filter( 'manage_edit-' . $post_type . '_columns', array($this, 'add_columns' ));
// Set post type columns value
add_action( 'manage_' . $post_type . '_posts_custom_column', array($this, 'set_columns_value'), 10,2);
}

/**
Expand Down Expand Up @@ -123,6 +129,39 @@ public function set_fields( $fields = array() ) {
$this->fields = $fields;
}

/**
* Get field type by field ID
*
* @param string $field_id Field ID
*
* @return string Field type
*/
protected function get_field_type_by_id( $field_id ) {
foreach ( $this->fields as $field ) {
if ( $field['id'] == $field_id ) {
return $field['type'];
}
}

return '';
}

/**
* Check if index add_column is true
*
*
* @return bool Field type
*/
protected function check_field_is_column() {
foreach ( $this->fields as $field ) {
if ( isset( $field['add_column'] ) && $field['add_column'] ) {
return true;
}
}

return false;
}

/**
* Metabox view.
*
Expand Down Expand Up @@ -252,6 +291,51 @@ protected function build_field_attributes( $attrs ) {
return $attributes;
}

/**
* Add post columns
*
* @param array $columns Default WordPress Columns
*
* @return array Columns
*/
public function add_columns( $columns ) {
foreach ( $this->fields as $key => $field ) {
if ( isset( $field['add_column'] ) && $field['add_column'] ) {
$columns[ $field['id'] ] = $field['label'];
}
}

return $columns;
}

/**
* Set value for each column
*
* @param string $column $column
* @param int $column $post_id
*
* @return string Value
*/
public function set_columns_value( $column , $post_id ) {
$type = $this->get_field_type_by_id( $column );
$is_column = $this->check_field_is_column();
if ( ! $is_column ) {
return;
}

switch ( $type ) {
case 'image' :
case 'image_plupload' :
$value = wp_get_attachment_image( get_post_meta( $post_id, $column, true ) , array( 50, 50 ) );
break;
default :
$value = apply_filters( 'admin_post_column_value_' . $this->post_type . '_' . $column, get_post_meta( $post_id, $column, true ) );
break;
}

echo $value;
}

/**
* Input field.
*
Expand Down Expand Up @@ -339,15 +423,14 @@ protected function field_select( $id, $current, $options, $attrs ) {
*/
protected function is_selected( $current, $key ) {
$selected = false;
if( is_array( $current ) ) {
for( $i = 0; $i < count( $current ); $i++ ) {
if( selected( $current[ $i ], $key, false ) ) {
if ( is_array( $current ) ) {
for ( $i = 0; $i < count( $current ); $i++ ) {
if ( selected( $current[ $i ], $key, false ) ) {
$selected = selected( $current[ $i ], $key, false );
break 1;
}
}
}
else {
} else {
$selected = selected( $current, $key, false );
}

Expand All @@ -367,8 +450,9 @@ protected function is_selected( $current, $key ) {
protected function field_radio( $id, $current, $options, $attrs ) {
$html = '';

foreach ( $options as $key => $label )
foreach ( $options as $key => $label ) {
$html .= sprintf( '<input type="radio" id="%1$s_%2$s" name="%1$s" value="%2$s"%3$s%5$s /><label for="%1$s_%2$s"> %4$s</label><br />', $id, $key, checked( $current, $key, false ), $label, $this->build_field_attributes( $attrs ) );
}

echo $html;
}
Expand Down
6 changes: 3 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function odin_enqueue_scripts() {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
// Bootstrap.
wp_enqueue_script( 'bootstrap', $template_url . '/assets/js/libs/bootstrap.min.js', array(), null, true );

// FitVids.
wp_enqueue_script( 'fitvids', $template_url . '/assets/js/libs/jquery.fitvids.js', array(), null, true );

Expand All @@ -232,7 +232,7 @@ function odin_enqueue_scripts() {
} else {
// Grunt main file with Bootstrap, FitVids and others libs.
wp_enqueue_script( 'odin-main-min', $template_url . '/assets/js/main.min.js', array(), null, true );
}
}

// Grunt watch livereload in the browser.
// wp_enqueue_script( 'odin-livereload', 'http://localhost:35729/livereload.js?snipver=1', array(), null, true );
Expand Down Expand Up @@ -306,5 +306,5 @@ function is_woocommerce_activated() {
add_theme_support( 'woocommerce' );
require get_template_directory() . '/inc/woocommerce/hooks.php';
require get_template_directory() . '/inc/woocommerce/functions.php';
require get_template_directory() . '/inc/woocommerce/template-tags.php';
require get_template_directory() . '/inc/woocommerce/template-tags.php';
}

0 comments on commit a91f143

Please sign in to comment.