fix: standardize name of hooks

This commit is contained in:
vnmedeiros 2023-07-26 15:45:44 -03:00
parent f97ed4b98c
commit 9fa4a54ac5
11 changed files with 38 additions and 19 deletions

View File

@ -765,9 +765,11 @@ class Item extends Entity {
$before = str_replace('$id', ' id="metadata-id-' . $item_metadatum->get_metadatum()->get_id() . '"', $before); $before = str_replace('$id', ' id="metadata-id-' . $item_metadatum->get_metadatum()->get_id() . '"', $before);
// Let theme authors tweak the wrapper opener // Let theme authors tweak the wrapper opener
$metadata_type = $item_metadatum->get_metadatum()->get_metadata_type();
$metadatum_id = $item_metadatum->get_metadatum()->get_id();
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before', $before, $item_metadatum ); $before = apply_filters( 'tainacan-get-item-metadatum-as-html-before', $before, $item_metadatum );
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--type-' . $item_metadatum->get_metadatum()->get_metadata_type(), $before, $item_metadatum ); $before = apply_filters( "tainacan-get-item-metadatum-as-html-before--type-$metadata_type", $before, $item_metadatum );
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--id-' . $item_metadatum->get_metadatum()->get_id(), $before, $item_metadatum ); $before = apply_filters( "tainacan-get-item-metadatum-as-html-before--id-$metadatum_id", $before, $item_metadatum );
if ( is_numeric($metadatum_index) ) { if ( is_numeric($metadatum_index) ) {
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--index-' . $metadatum_index, $before, $item_metadatum ); $before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--index-' . $metadatum_index, $before, $item_metadatum );
} }
@ -795,8 +797,10 @@ class Item extends Entity {
if ( is_numeric($metadatum_index) ) { if ( is_numeric($metadatum_index) ) {
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--index-' . $metadatum_index, $after, $item_metadatum ); $after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--index-' . $metadatum_index, $after, $item_metadatum );
} }
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--id-' . $item_metadatum->get_metadatum()->get_id(), $after, $item_metadatum ); $metadata_type = $item_metadatum->get_metadatum()->get_metadata_type();
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--type-' . $item_metadatum->get_metadatum()->get_metadata_type(), $after, $item_metadatum ); $metadatum_id = $item_metadatum->get_metadatum()->get_id();
$after = apply_filters( "tainacan-get-item-metadatum-as-html-after--id-$metadatum_id", $after, $item_metadatum );
$after = apply_filters( "tainacan-get-item-metadatum-as-html-after--type-$metadata_type", $after, $item_metadatum );
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after', $after, $item_metadatum ); $after = apply_filters( 'tainacan-get-item-metadatum-as-html-after', $after, $item_metadatum );
// Closes the wrapper // Closes the wrapper

View File

@ -27,7 +27,8 @@ class Collections extends Repository {
* @see \Tainacan\Repositories\Repository::get_map() * @see \Tainacan\Repositories\Repository::get_map()
*/ */
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Name', 'tainacan' ), 'title' => __( 'Name', 'tainacan' ),

View File

@ -29,7 +29,8 @@ class Filters extends Repository {
} }
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Name', 'tainacan' ), 'title' => __( 'Name', 'tainacan' ),

View File

@ -32,7 +32,8 @@ class Items extends Repository {
} }
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'title' => [ 'title' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Title', 'tainacan' ), 'title' => __( 'Title', 'tainacan' ),

View File

@ -46,7 +46,8 @@ class Logs extends Repository {
} }
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'title' => [ 'title' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Title', 'tainacan' ), 'title' => __( 'Title', 'tainacan' ),

View File

@ -33,7 +33,8 @@ class Metadata_Sections extends Repository {
* @see \Tainacan\Repositories\Repository::get_map() * @see \Tainacan\Repositories\Repository::get_map()
*/ */
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Name', 'tainacan' ), 'title' => __( 'Name', 'tainacan' ),

View File

@ -51,7 +51,8 @@ class Metadata extends Repository {
* @see \Tainacan\Repositories\Repository::get_map() * @see \Tainacan\Repositories\Repository::get_map()
*/ */
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Name', 'tainacan' ), 'title' => __( 'Name', 'tainacan' ),

View File

@ -56,10 +56,11 @@ abstract class Repository {
* Register hooks * Register hooks
*/ */
protected function __construct() { protected function __construct() {
$name = $this->get_name();
add_action( 'init', array( &$this, 'register_post_type' ) ); add_action( 'init', array( &$this, 'register_post_type' ) );
add_action( 'init', array( &$this, 'init_objects' ) ); add_action( 'init', array( &$this, 'init_objects' ) );
add_filter( 'tainacan-get-map-' . $this->get_name(), array( $this, 'get_default_properties' ) ); add_filter( "tainacan-get-map-$name", array( $this, 'get_default_properties' ) );
} }
public function init_objects() { public function init_objects() {
@ -630,8 +631,9 @@ abstract class Repository {
*/ */
public function delete( Entities\Entity $entity, $permanent = true ) { public function delete( Entities\Entity $entity, $permanent = true ) {
$post_type = $entity->get_post_type();
do_action( 'tainacan-pre-delete', $entity, $permanent ); do_action( 'tainacan-pre-delete', $entity, $permanent );
do_action( 'tainacan-pre-delete-' . $entity->get_post_type(), $entity, $permanent ); do_action( "tainacan-pre-delete-$post_type", $entity, $permanent );
if ($permanent === true) { if ($permanent === true) {
$return = wp_delete_post( $entity->get_id(), $permanent ); $return = wp_delete_post( $entity->get_id(), $permanent );
@ -642,8 +644,9 @@ abstract class Repository {
if ( $return instanceof \WP_Post && $this->use_logs ) { if ( $return instanceof \WP_Post && $this->use_logs ) {
$post_type = $entity->get_post_type();
do_action( 'tainacan-deleted', $entity, $permanent ); do_action( 'tainacan-deleted', $entity, $permanent );
do_action( 'tainacan-deleted-' . $entity->get_post_type(), $entity, $permanent ); do_action( "tainacan-deleted-$post_type", $entity, $permanent );
$return = $this->get_entity_by_post($return); $return = $this->get_entity_by_post($return);

View File

@ -32,7 +32,8 @@ class Taxonomies extends Repository {
} }
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity", [
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'title' => __( 'Name', 'tainacan' ), 'title' => __( 'Name', 'tainacan' ),

View File

@ -30,7 +30,8 @@ class Terms extends Repository {
} }
protected function _get_map() { protected function _get_map() {
return apply_filters( 'tainacan-get-map-' . $this->get_name(), [ $entity = $this->get_name();
return apply_filters( "tainacan-get-map-$entity" , [
'term_id' => [ 'term_id' => [
'map' => 'term_id', 'map' => 'term_id',
'title' => __( 'ID', 'tainacan' ), 'title' => __( 'ID', 'tainacan' ),

View File

@ -1742,9 +1742,11 @@ class Theme_Helper {
$before = str_replace('$id', ' id="metadata-id-' . $metadatum->get_id() . '"', $before); $before = str_replace('$id', ' id="metadata-id-' . $metadatum->get_id() . '"', $before);
// Let theme authors tweak the wrapper opener // Let theme authors tweak the wrapper opener
$metadata_type = $metadatum->get_metadata_type();
$metadatum_id = $metadatum->get_id();
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before', $before, $item_metadatum ); $before = apply_filters( 'tainacan-get-item-metadatum-as-html-before', $before, $item_metadatum );
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--type-' . $metadatum->get_metadata_type(), $before, $item_metadatum ); $before = apply_filters( "tainacan-get-item-metadatum-as-html-before--type-$metadata_type", $before, $item_metadatum );
$before = apply_filters( 'tainacan-get-item-metadatum-as-html-before--id-' . $metadatum->get_id(), $before, $item_metadatum ); $before = apply_filters( "tainacan-get-item-metadatum-as-html-before--id-$metadatum_id", $before, $item_metadatum );
// Renders the metadatum opener // Renders the metadatum opener
$return .= $before; $return .= $before;
@ -1766,8 +1768,10 @@ class Theme_Helper {
$after = $args['after']; $after = $args['after'];
// Let theme authors tweak the wrapper closer // Let theme authors tweak the wrapper closer
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--id-' . $metadatum->get_id(), $after, $item_metadatum ); $metadatum_id = $metadatum->get_id();
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after--type-' . $metadatum->get_metadata_type(), $after, $item_metadatum ); $metadata_type = $metadatum->get_metadata_type();
$after = apply_filters( "tainacan-get-item-metadatum-as-html-after--id-$metadatum_id", $after, $item_metadatum );
$after = apply_filters( "tainacan-get-item-metadatum-as-html-after--type-$metadata_type", $after, $item_metadatum );
$after = apply_filters( 'tainacan-get-item-metadatum-as-html-after', $after, $item_metadatum ); $after = apply_filters( 'tainacan-get-item-metadatum-as-html-after', $after, $item_metadatum );
// Closes the wrapper // Closes the wrapper