'key'|'text'|'bool' */ public function filter_keys() { return array( 'search' => 'text' ); } /** * Field definitions, filterable. * * @return array */ public function fields() { if ( null === $this->fields ) { $this->fields = (array) apply_filters( 'bdbe_' . $this->key() . '_fields', $this->build_fields(), $this ); } return $this->fields; } /** * One field definition. * * @param string $key Field key. * @return array|null */ public function field( $key ) { $fields = $this->fields(); return isset( $fields[ $key ] ) ? $fields[ $key ] : null; } /** * Whether the current user can edit this record. * * @param object $object Record. * @return bool */ public function can_edit( $object ) { unset( $object ); return current_user_can( 'manage_woocommerce' ); } /** * Cross-field validation after values are set (before saving). * * @param object $object Record with new values applied. * @param array $touched Field keys that changed. * @return array field => error message. */ public function validate( $object, array $touched ) { unset( $object, $touched ); return array(); } /** * Called once after a batch of records was saved. * * @param object[] $objects Saved records. */ public function after_save( array $objects ) { unset( $objects ); } /** * Row identity and links for the grid. * * @param object $object Record. * @return array */ abstract protected function row_meta( $object ); /** * Row payload for the grid. * * @param object $object Record. * @return array */ public function row( $object ) { $row = array_merge( array( 'id' => 0, 'kind' => $this->key(), 'parent' => 0, 'title' => '', 'edit' => '', 'view' => '', 'cells' => array(), 'locked' => array(), 'display' => array(), ), $this->row_meta( $object ) ); foreach ( $this->fields() as $key => $def ) { if ( isset( $def['column'] ) && false === $def['column'] ) { continue; } $value = isset( $def['get'] ) && is_callable( $def['get'] ) ? call_user_func( $def['get'], $object ) : ''; $row['cells'][ $key ] = null === $value ? '' : (string) $value; if ( ! BDBE_Fields::editable( $def, $object ) ) { $row['locked'][] = $key; } if ( isset( $def['display'] ) && is_callable( $def['display'] ) ) { $text = call_user_func( $def['display'], $object ); if ( null !== $text && '' !== $text ) { $row['display'][ $key ] = (string) $text; } } } return $row; } /** * Expand a page of objects into rows (Pro adds variation rows here). * * @param object[] $objects Records. * @param array $args Query args. * @return array Rows. */ public function rows( array $objects, array $args ) { $rows = array(); foreach ( $objects as $object ) { $rows[] = $this->row( $object ); } return (array) apply_filters( 'bdbe_' . $this->key() . '_rows', $rows, $objects, $args, $this ); } /** * IDs matching a filter (for bulk actions), oldest first. * * @param array $filters Sanitised filters. * @return int[] */ public function matching_ids( array $filters ) { unset( $filters ); return array(); } }