fix: refactor php

This commit is contained in:
vnmedeiros 2021-04-27 14:19:14 -03:00
parent 408ac263eb
commit 2706a5693e
3 changed files with 48 additions and 57 deletions

View File

@ -28,9 +28,8 @@ function tainacan_blocksy_enqueue_scripts() {
// This should only happen if we have Tainacan plugin installed // This should only happen if we have Tainacan plugin installed
if ( defined ('TAINACAN_VERSION') ) { if ( defined ('TAINACAN_VERSION') ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers(); // $collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$post_type = get_post_type(); // $post_type = get_post_type();
wp_enqueue_script( 'tainacan-blocksy-scripts', TAINACAN_BLOCKSY_PLUGIN_URL_PATH . '/js/scripts.js', array(), TAINACAN_BLOCKSY_VERSION, true ); wp_enqueue_script( 'tainacan-blocksy-scripts', TAINACAN_BLOCKSY_PLUGIN_URL_PATH . '/js/scripts.js', array(), TAINACAN_BLOCKSY_VERSION, true );
} }
} }

View File

@ -6,27 +6,26 @@
* I renamed the usage from 'fn' to 'fnc' to avoid future conflicts * I renamed the usage from 'fn' to 'fnc' to avoid future conflicts
*/ */
if (! function_exists('blc_call_fnc')) { if (! function_exists('blc_call_fnc')) {
function blc_call_fnc($args = [], ...$params) { function blc_call_fnc($args = [], ...$params) {
$args = wp_parse_args( $args = wp_parse_args(
$args, $args,
[ [
'fnc' => null, 'fnc' => null,
// string | null | array
'default' => ''
]
);
// string | null | array if (! $args['fnc']) {
'default' => '' throw new Error('$fnc must be specified!');
] }
);
if (! $args['fnc']) { if (! function_exists($args['fnc'])) {
throw new Error('$fnc must be specified!'); return $args['default'];
} }
if (! function_exists($args['fnc'])) { return call_user_func($args['fnc'], ...$params);
return $args['default']; }
}
return call_user_func($args['fnc'], ...$params);
}
} }
/** /**

View File

@ -134,8 +134,6 @@ if ( !function_exists('blocksy_default_post_navigation') ) {
] ]
)); ));
$home_page_url = get_home_url();
$post_slug = get_post_type() === 'post' ? __( 'Post', 'blocksy' ) : get_post_type_object( get_post_type() )->labels->singular_name; $post_slug = get_post_type() === 'post' ? __( 'Post', 'blocksy' ) : get_post_type_object( get_post_type() )->labels->singular_name;
$post_slug = '<span>' . $post_slug . '</span>'; $post_slug = '<span>' . $post_slug . '</span>';
@ -188,14 +186,14 @@ if ( !function_exists('blocksy_default_post_navigation') ) {
?> ?>
<nav class="<?php echo esc_attr( $container_class ); ?>"> <nav class="<?php echo esc_attr( $container_class ); ?>">
<?php if ($next_post) { ?> <?php if ($next_post): ?>
<a href="<?php echo esc_url(get_permalink($next_post)); ?>" class="nav-item-prev"> <a href="<?php echo esc_url(get_permalink($next_post)); ?>" class="nav-item-prev">
<?php if ($has_thumb) { ?> <?php if ($has_thumb): ?>
<?php <?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $next_post_image_output; echo $next_post_image_output;
?> ?>
<?php } ?> <?php endif; ?>
<div class="item-content"> <div class="item-content">
<span class="item-label"> <span class="item-label">
@ -208,19 +206,19 @@ if ( !function_exists('blocksy_default_post_navigation') ) {
?> ?>
</span> </span>
<?php if ( ! empty( $next_title ) ) { ?> <?php if ( ! empty( $next_title ) ): ?>
<span class="item-title"> <span class="item-title">
<?php echo wp_kses_post($next_title); ?> <?php echo wp_kses_post($next_title); ?>
</span> </span>
<?php } ?> <?php endif; ?>
</div> </div>
</a> </a>
<?php } else { ?> <?php else: ?>
<div class="nav-item-prev"></div> <div class="nav-item-prev"></div>
<?php } ?> <?php endif; ?>
<?php if ( $previous_post ) { ?> <?php if ( $previous_post ) : ?>
<a href="<?php echo esc_url( get_permalink( $previous_post ) ); ?>" class="nav-item-next"> <a href="<?php echo esc_url( get_permalink( $previous_post ) ); ?>" class="nav-item-next">
<div class="item-content"> <div class="item-content">
<span class="item-label"> <span class="item-label">
@ -233,22 +231,20 @@ if ( !function_exists('blocksy_default_post_navigation') ) {
?> ?>
</span> </span>
<?php if ( ! empty( $previous_title ) ) { ?> <?php if ( ! empty( $previous_title ) ) : ?>
<span class="item-title"> <span class="item-title">
<?php echo wp_kses_post($previous_title); ?> <?php echo wp_kses_post($previous_title); ?>
</span> </span>
<?php } ?> <?php endif; ?>
</div> </div>
<?php if ($has_thumb) { ?> <?php if ($has_thumb) : ?>
<?php <?php echo $previous_post_image_output; ?>
echo $previous_post_image_output; <?php endif; ?>
?>
<?php } ?>
</a> </a>
<?php } else { ?> <?php else : ?>
<div class="nav-item-next"></div> <div class="nav-item-next"></div>
<?php } ?> <?php endif; ?>
</nav> </nav>
@ -296,23 +292,20 @@ if ( !function_exists('tainacan_blocksy_item_navigation') ) {
$next = $adjacent_links['next']; $next = $adjacent_links['next'];
} }
?> if ($previous !== '' || $next !== '') {
<?php if ($previous !== '' || $next !== '') : ?> echo '<nav class="' . esc_attr( $container_class ) . '">';
<nav class="<?php echo esc_attr( $container_class ); ?>"> if ( $previous !== '' ) {
<?php if ( $previous !== '' ) { echo $previous;
echo $previous; } else {
} else { ?> echo '<div class="nav-item-prev"></div>';
<div class="nav-item-prev"></div> }
<?php } ?> if ( $next !== '' ) {
echo $next;
<?php if ( $next !== '' ) { } else {
echo $next; echo '<div class="nav-item-next"></div>';
} else { ?> }
<div class="nav-item-next"></div> echo '</nav>';
<?php } ?> };
</nav>
<?php endif; ?>
<?
} }
} }