'', 'data_type' => 'serialize', 'priority' => 'default', 'show_reset' => false, 'show_restore' => false, 'nav' => 'normal', 'theme' => 'dark', 'class' => '', 'defaults' => array(), ); // run comment metabox construct public function __construct( $key, $params = array() ) { $this->unique = $key; $this->args = apply_filters( "csf_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this ); $this->sections = apply_filters( "csf_{$this->unique}_sections", $params['sections'], $this ); $this->pre_fields = $this->pre_fields( $this->sections ); add_action( 'add_meta_boxes_comment', array( $this, 'add_comment_meta_box' ) ); add_action( 'edit_comment', array( $this, 'save_comment_meta_box' ) ); if ( ! empty( $this->args['class'] ) ) { add_filter( 'postbox_classes_comment_'. $this->unique, array( $this, 'add_comment_metabox_classes' ) ); } } // instance public static function instance( $key, $params = array() ) { return new self( $key, $params ); } public function add_comment_metabox_classes( $classes ) { if ( ! empty( $this->args['class'] ) ) { $classes[] = $this->args['class']; } return $classes; } // add comment metabox public function add_comment_meta_box( $post_type ) { add_meta_box( $this->unique, $this->args['title'], array( $this, 'add_comment_meta_box_content' ), 'comment', 'normal', $this->args['priority'], $this->args ); } // get default value public function get_default( $field ) { $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default; return $default; } // get meta value public function get_meta_value( $comment_id, $field ) { $value = null; if ( ! empty( $comment_id ) && ! empty( $field['id'] ) ) { if ( $this->args['data_type'] !== 'serialize' ) { $meta = get_comment_meta( $comment_id, $field['id'] ); $value = ( isset( $meta[0] ) ) ? $meta[0] : null; } else { $meta = get_comment_meta( $comment_id, $this->unique, true ); $value = ( isset( $meta[$field['id']] ) ) ? $meta[$field['id']] : null; } } $default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : ''; $value = ( isset( $value ) ) ? $value : $default; return $value; } // add comment metabox content public function add_comment_meta_box_content( $comment, $callback ) { $has_nav = ( count( $this->sections ) > 1 ) ? true : false; $show_all = ( ! $has_nav ) ? ' csf-show-all' : ''; $errors = ( is_object ( $comment ) ) ? get_comment_meta( $comment->comment_ID, '_csf_errors_'. $this->unique, true ) : array(); $errors = ( ! empty( $errors ) ) ? $errors : array(); $theme = ( $this->args['theme'] ) ? ' csf-theme-'. $this->args['theme'] : ''; $nav_type = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal'; if ( is_object( $comment ) && ! empty( $errors ) ) { delete_comment_meta( $comment->comment_ID, '_csf_errors_'. $this->unique ); } wp_nonce_field( 'csf_comment_metabox_nonce', 'csf_comment_metabox_nonce'. $this->unique ); echo '
'; $tab_key = 1; foreach ( $this->sections as $section ) { $tab_icon = ( ! empty( $section['icon'] ) ) ? '' : ''; $tab_error = ( ! empty( $errors['sections'][$tab_key] ) ) ? '!' : ''; echo '- '. $tab_icon . $section['title'] . $tab_error .'
';
$tab_key++;
}
echo '
'; echo ''. $section_icon . $section_title .'