Fixes indentations and more refactors

This commit is contained in:
Rodrigo de Oliveira 2021-03-12 02:35:42 -03:00
parent 246e5b92d3
commit 5fe6c41546
2 changed files with 21 additions and 22 deletions

View File

@ -44,8 +44,8 @@ class Taxonomy extends Entity {
*/
static $db_identifier_prefix = 'tnc_tax_';
public function __toString(){
return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this);
public function __toString() {
return (string) apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this);
}
/**
@ -54,18 +54,19 @@ class Taxonomy extends Entity {
* @return bool
*/
function tainacan_register_taxonomy() {
$labels = array(
'name' => $this->get_name(),
'singular_name' => $this->get_name(),
'search_items' => __( sprintf('Search terms in %s', $this->get_name()), 'tainacan' ),
'all_items' => __( sprintf('All terms in %s', $this->get_name()), 'tainacan' ),
$taxonomy_name = $this->get_name();
$labels = array(
'name' => $taxonomy_name,
'singular_name' => $taxonomy_name,
'search_items' => __( sprintf('Search terms in %s', $taxonomy_name), 'tainacan' ),
'all_items' => __( sprintf('All terms in %s', $taxonomy_name), 'tainacan' ),
'parent_item' => __( 'Parent term', 'tainacan' ),
'parent_item_colon' => __( 'Parent term:', 'tainacan' ),
'edit_item' => __( 'Edit term', 'tainacan' ),
'update_item' => __( 'Update term', 'tainacan' ),
'add_new_item' => __( 'Add New term', 'tainacan' ),
'new_item_name' => __( 'New Genre term', 'tainacan' ),
'menu_name' => $this->get_name(),
'menu_name' => $taxonomy_name,
);
$enabled_post_types = $this->get_enabled_post_types();
@ -88,8 +89,6 @@ class Taxonomy extends Entity {
unregister_taxonomy($this->get_db_identifier());
}
register_taxonomy(
$this->get_db_identifier(),
$enabled_post_types,

View File

@ -144,10 +144,10 @@ abstract class Repository {
}
$obj->WP_Post->post_type = $obj::get_post_type();
if ( $obj instanceof Entities\Taxonomy ) {
$sanitized = $this->sanitize_value($obj->get('name'));
$obj->WP_Post->post_title = $sanitized;
}
if ( $obj instanceof Entities\Taxonomy ) {
$sanitized = $this->sanitize_value($obj->get('name'));
$obj->WP_Post->post_title = $sanitized;
}
if ( $obj instanceof Entities\Log && ! ( isset( $obj->WP_Post->post_status ) && in_array( $obj->WP_Post->post_status, [
'publish',
@ -157,8 +157,8 @@ abstract class Repository {
}
if ( $obj instanceof Entities\Item ) {
$sanitized_title = $this->sanitize_value($obj->get('title'));
$sanitized_desc = $this->sanitize_value($obj->get('description'));
$sanitized_title = $this->sanitize_value($obj->get('title'));
$sanitized_desc = $this->sanitize_value($obj->get('description'));
// get collection to determine post type
$collection = $obj->get_collection();
@ -169,21 +169,21 @@ abstract class Repository {
$post_t = $collection->get_db_identifier();
$obj->WP_Post->post_type = $post_t;
$obj->WP_Post->post_title = $sanitized_title;
$obj->WP_Post->post_content = $sanitized_desc;
$obj->WP_Post->post_title = $sanitized_title;
$obj->WP_Post->post_content = $sanitized_desc;
$obj_post_type = 'tainacan-item';
do_action( "tainacan-pre-insert-$obj_post_type", $obj );
}
if ($obj instanceof Entities\Collection || $obj instanceof Entities\Metadatum) {
$sanitized = $this->sanitize_value($obj->get('name'));
$obj->WP_Post->post_title = $sanitized;
}
$sanitized = $this->sanitize_value($obj->get('name'));
$obj->WP_Post->post_title = $sanitized;
}
$id = wp_insert_post( $obj->WP_Post );
if ($id instanceof \WP_Error || 0 === $id) {
return false;
}
}
// reset object
$obj->WP_Post = get_post( $id );