Fixes indentations and more refactors
This commit is contained in:
parent
246e5b92d3
commit
5fe6c41546
|
@ -44,8 +44,8 @@ class Taxonomy extends Entity {
|
||||||
*/
|
*/
|
||||||
static $db_identifier_prefix = 'tnc_tax_';
|
static $db_identifier_prefix = 'tnc_tax_';
|
||||||
|
|
||||||
public function __toString(){
|
public function __toString() {
|
||||||
return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this);
|
return (string) apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,18 +54,19 @@ class Taxonomy extends Entity {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function tainacan_register_taxonomy() {
|
function tainacan_register_taxonomy() {
|
||||||
$labels = array(
|
$taxonomy_name = $this->get_name();
|
||||||
'name' => $this->get_name(),
|
$labels = array(
|
||||||
'singular_name' => $this->get_name(),
|
'name' => $taxonomy_name,
|
||||||
'search_items' => __( sprintf('Search terms in %s', $this->get_name()), 'tainacan' ),
|
'singular_name' => $taxonomy_name,
|
||||||
'all_items' => __( sprintf('All terms in %s', $this->get_name()), 'tainacan' ),
|
'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' => __( 'Parent term', 'tainacan' ),
|
||||||
'parent_item_colon' => __( 'Parent term:', 'tainacan' ),
|
'parent_item_colon' => __( 'Parent term:', 'tainacan' ),
|
||||||
'edit_item' => __( 'Edit term', 'tainacan' ),
|
'edit_item' => __( 'Edit term', 'tainacan' ),
|
||||||
'update_item' => __( 'Update term', 'tainacan' ),
|
'update_item' => __( 'Update term', 'tainacan' ),
|
||||||
'add_new_item' => __( 'Add New term', 'tainacan' ),
|
'add_new_item' => __( 'Add New term', 'tainacan' ),
|
||||||
'new_item_name' => __( 'New Genre 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();
|
$enabled_post_types = $this->get_enabled_post_types();
|
||||||
|
@ -88,8 +89,6 @@ class Taxonomy extends Entity {
|
||||||
unregister_taxonomy($this->get_db_identifier());
|
unregister_taxonomy($this->get_db_identifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
register_taxonomy(
|
register_taxonomy(
|
||||||
$this->get_db_identifier(),
|
$this->get_db_identifier(),
|
||||||
$enabled_post_types,
|
$enabled_post_types,
|
||||||
|
|
|
@ -144,10 +144,10 @@ abstract class Repository {
|
||||||
}
|
}
|
||||||
$obj->WP_Post->post_type = $obj::get_post_type();
|
$obj->WP_Post->post_type = $obj::get_post_type();
|
||||||
|
|
||||||
if ( $obj instanceof Entities\Taxonomy ) {
|
if ( $obj instanceof Entities\Taxonomy ) {
|
||||||
$sanitized = $this->sanitize_value($obj->get('name'));
|
$sanitized = $this->sanitize_value($obj->get('name'));
|
||||||
$obj->WP_Post->post_title = $sanitized;
|
$obj->WP_Post->post_title = $sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $obj instanceof Entities\Log && ! ( isset( $obj->WP_Post->post_status ) && in_array( $obj->WP_Post->post_status, [
|
if ( $obj instanceof Entities\Log && ! ( isset( $obj->WP_Post->post_status ) && in_array( $obj->WP_Post->post_status, [
|
||||||
'publish',
|
'publish',
|
||||||
|
@ -157,8 +157,8 @@ abstract class Repository {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $obj instanceof Entities\Item ) {
|
if ( $obj instanceof Entities\Item ) {
|
||||||
$sanitized_title = $this->sanitize_value($obj->get('title'));
|
$sanitized_title = $this->sanitize_value($obj->get('title'));
|
||||||
$sanitized_desc = $this->sanitize_value($obj->get('description'));
|
$sanitized_desc = $this->sanitize_value($obj->get('description'));
|
||||||
|
|
||||||
// get collection to determine post type
|
// get collection to determine post type
|
||||||
$collection = $obj->get_collection();
|
$collection = $obj->get_collection();
|
||||||
|
@ -169,21 +169,21 @@ abstract class Repository {
|
||||||
|
|
||||||
$post_t = $collection->get_db_identifier();
|
$post_t = $collection->get_db_identifier();
|
||||||
$obj->WP_Post->post_type = $post_t;
|
$obj->WP_Post->post_type = $post_t;
|
||||||
$obj->WP_Post->post_title = $sanitized_title;
|
$obj->WP_Post->post_title = $sanitized_title;
|
||||||
$obj->WP_Post->post_content = $sanitized_desc;
|
$obj->WP_Post->post_content = $sanitized_desc;
|
||||||
$obj_post_type = 'tainacan-item';
|
$obj_post_type = 'tainacan-item';
|
||||||
do_action( "tainacan-pre-insert-$obj_post_type", $obj );
|
do_action( "tainacan-pre-insert-$obj_post_type", $obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($obj instanceof Entities\Collection || $obj instanceof Entities\Metadatum) {
|
if ($obj instanceof Entities\Collection || $obj instanceof Entities\Metadatum) {
|
||||||
$sanitized = $this->sanitize_value($obj->get('name'));
|
$sanitized = $this->sanitize_value($obj->get('name'));
|
||||||
$obj->WP_Post->post_title = $sanitized;
|
$obj->WP_Post->post_title = $sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = wp_insert_post( $obj->WP_Post );
|
$id = wp_insert_post( $obj->WP_Post );
|
||||||
if ($id instanceof \WP_Error || 0 === $id) {
|
if ($id instanceof \WP_Error || 0 === $id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset object
|
// reset object
|
||||||
$obj->WP_Post = get_post( $id );
|
$obj->WP_Post = get_post( $id );
|
||||||
|
|
Loading…
Reference in New Issue