Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/modules/ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Ajax {
*
* @since NEXT
*/
protected function add_hooks() {
protected function add_hooks(): void {
add_action( 'wp_ajax_anys', [ $this, 'handle_request' ] );
add_action( 'wp_ajax_nopriv_anys', [ $this, 'handle_request' ] );
}
Expand All @@ -31,7 +31,7 @@ protected function add_hooks() {
*
* @since NEXT
*/
public function handle_request() {
public function handle_request(): void {
// Verifies the nonce.
check_ajax_referer( 'anys_nonce' );

Expand Down
10 changes: 5 additions & 5 deletions includes/modules/assets/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Assets {
*
* @since NEXT
*/
protected function add_hooks() {
protected function add_hooks(): void {
add_action( 'init', [ $this, 'register_assets' ] );
add_action( 'wp_head', [ $this, 'localize_data' ] );

Expand All @@ -33,7 +33,7 @@ protected function add_hooks() {
*
* @since NEXT
*/
protected function get_assets() {
protected function get_assets(): array {
$assets = [
'styles' => [
'anys-utilities' => [
Expand Down Expand Up @@ -69,7 +69,7 @@ protected function get_assets() {
*
* @since NEXT
*/
public function register_assets() {
public function register_assets(): void {
$assets = $this->get_assets();

// Registers styles.
Expand Down Expand Up @@ -109,7 +109,7 @@ public function register_assets() {
*
* @since NEXT
*/
public function localize_data() {
public function localize_data(): void {
?>
<script>
window.anysData = <?php echo wp_json_encode( [
Expand All @@ -127,7 +127,7 @@ public function localize_data() {
*
* @since NEXT
*/
public function force_module_type( $tag, $handle, $src ) {
public function force_module_type( string $tag, string $handle, string $src ): string {
if ( $handle === 'anys-spoilerjs' ) {
// If type attr is missing, inject it.
if ( strpos( $tag, ' type=' ) === false ) {
Expand Down
12 changes: 6 additions & 6 deletions includes/modules/elementor/shortcode-tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Shortcode_Tag extends Tag {
*
* @return string
*/
public function get_name() {
public function get_name(): string {
return 'anys-shortcode';
}

Expand All @@ -29,7 +29,7 @@ public function get_name() {
*
* @return string
*/
public function get_title() {
public function get_title(): string {
return esc_html__( 'Anything Shortcodes', 'anys' );
}

Expand All @@ -38,7 +38,7 @@ public function get_title() {
*
* @return string
*/
public function get_group() {
public function get_group(): string {
return 'anything-shortcodes';
}

Expand All @@ -47,7 +47,7 @@ public function get_group() {
*
* @return array
*/
public function get_categories() {
public function get_categories(): array {
return [ Dynamic_Tags_Module::TEXT_CATEGORY ];
}

Expand All @@ -56,7 +56,7 @@ public function get_categories() {
*
* @return void
*/
protected function register_controls() {
protected function register_controls(): void {
$this->add_control(
'anys_shortcode',
[
Expand All @@ -74,7 +74,7 @@ protected function register_controls() {
*
* @return void
*/
public function render() {
public function render(): void {
$raw = trim( (string) $this->get_settings( 'anys_shortcode' ) );

// Skips empty or invalid shortcode.
Expand Down
6 changes: 3 additions & 3 deletions includes/modules/nav-menu/nav-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Nav_Menu {
*
* @since 1.4.0
*/
protected function add_hooks() {
protected function add_hooks(): void {
add_filter( 'wp_nav_menu_objects', [ $this, 'process_menu_shortcodes' ] );

// Temporarily disabled admin preview — until further decision.
Expand All @@ -37,7 +37,7 @@ protected function add_hooks() {
*
* @return array
*/
public function process_menu_shortcodes( $items ) {
public function process_menu_shortcodes( array $items ): array {
foreach ( $items as $item ) {
if ( ! is_object( $item ) ) {
continue;
Expand Down Expand Up @@ -76,7 +76,7 @@ public function process_menu_shortcodes( $items ) {
* @param int $depth
* @param array $args
*/
public function admin_menu_item_preview( $item_id, $item, $depth, $args ) {
public function admin_menu_item_preview( int $item_id, \WP_Post $item, int $depth, array $args ): void {
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
return;
}
Expand Down
22 changes: 13 additions & 9 deletions includes/modules/shortcodes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Shortcodes {
*
* @since 1.0.0
*/
protected function add_hooks() {
protected function add_hooks(): void {
add_action( 'init', [ $this, 'register_shortcode' ] );
}

Expand All @@ -31,7 +31,7 @@ protected function add_hooks() {
*
* @since 1.0.0
*/
public function register_shortcode() {
public function register_shortcode(): void {
// Requires the Base class before registering the shortcode.
$base_file = ANYS_MODULES_PATH . 'shortcodes/types/base.php';

Expand All @@ -47,12 +47,12 @@ public function register_shortcode() {
*
* @since 1.0.0
*
* @param array $attributes Shortcode attributes.
* @param string $content Shortcode content.
* @param array<string,mixed> $attributes Shortcode attributes.
* @param string|null $content Shortcode content.
*
* @return string
* @return string Final rendered output.
*/
public function render_shortcode( array $attributes, string $content = '' ) {
public function render_shortcode( array $attributes, ?string $content = '' ): string {
/**
* Filters the shortcode attributes before processing.
*
Expand Down Expand Up @@ -120,7 +120,11 @@ public function render_shortcode( array $attributes, string $content = '' ) {
require_once $file;

// Build the class name based on the file type.
$class_name = '\\AnyS\\Modules\\Shortcodes\\Types\\' . str_replace( '-', '_', ucfirst( $attributes['type'] ) . '_Type' );
$class_name = '\\AnyS\\Modules\\Shortcodes\\Types\\' . str_replace(
'-',
'_',
ucfirst( $attributes['type'] ) . '_Type'
);

// Check if the class exists before calling render().
if ( ! class_exists( $class_name ) ) {
Expand Down Expand Up @@ -190,8 +194,8 @@ public function render_shortcode( array $attributes, string $content = '' ) {
$content
);

// Returns the final output.
return $output;
// Returns the final output as string.
return (string) $output;
}
}

Expand Down
14 changes: 7 additions & 7 deletions includes/modules/shortcodes/types/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ abstract class Base {
*
* @return string
*/
abstract public function get_type();
abstract public function get_type(): string;

/**
* Returns the default shortcode attributes.
*
* @since NEXT
*
* @return array
* @return array<string,mixed>
*/
protected function get_defaults() {
protected function get_defaults(): array {
return [];
}

Expand All @@ -38,11 +38,11 @@ protected function get_defaults() {
*
* @since NEXT
*
* @param array $attributes Raw attributes.
* @param array<string,mixed> $attributes Raw attributes.
*
* @return array Merged attributes.
* @return array<string,mixed> Merged attributes.
*/
protected function get_attributes( array $attributes ) {
protected function get_attributes( array $attributes ): array {
$defaults = $this->get_defaults();

$attributes = wp_parse_args(
Expand All @@ -63,5 +63,5 @@ protected function get_attributes( array $attributes ) {
*
* @return string
*/
abstract public function render( array $attributes, string $content );
abstract public function render( array $attributes, string $content ): string;
}
25 changes: 14 additions & 11 deletions includes/modules/shortcodes/types/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class Function_Type extends Base {
*
* @return string
*/
public function get_type() {
public function get_type(): string {
return 'function';
}

Expand All @@ -32,9 +32,9 @@ public function get_type() {
*
* @since NEXT
*
* @return array
* @return array<string,mixed>
*/
protected function get_defaults() {
protected function get_defaults(): array {
return [
'name' => '',
'before' => '',
Expand All @@ -50,12 +50,12 @@ protected function get_defaults() {
* @since 1.1.0
* @since NEXT Moved to class-based structure.
*
* @param array $attributes Shortcode attributes.
* @param string $content Enclosed content (optional).
* @param array<string,mixed> $attributes Shortcode attributes.
* @param string|null $content Enclosed content (optional).
*
* @return string
*/
public function render( array $attributes, string $content ) {
public function render( array $attributes, ?string $content = '' ): string {
$attributes = $this->get_attributes( $attributes );

// Parses dynamic attributes.
Expand All @@ -70,7 +70,7 @@ public function render( array $attributes, string $content ) {
return '';
}

// Validates function existence
// Validates function existence.
if ( ! function_exists( $function ) ) {
if ( current_user_can( 'manage_options' ) ) {
return sprintf(
Expand Down Expand Up @@ -104,8 +104,9 @@ public function render( array $attributes, string $content ) {
// Resolves arguments.
$tokens = $args_raw !== '' ? array_map( 'trim', explode( '|', $args_raw ) ) : [];
$cache = [];
$args = array_map(
static function ( $t ) use ( &$cache ) {

$args = array_map(
static function ( string $t ) use ( &$cache ): mixed {
return anys_parse_dynamic_value( $t, $cache );
},
$tokens
Expand All @@ -115,14 +116,16 @@ static function ( $t ) use ( &$cache ) {
$args = array_values(
array_filter(
$args,
static function ( $a ) { return $a !== ''; }
static function ( mixed $a ): bool {
return $a !== '';
}
)
);

try {
// Executes target function.
$value = call_user_func_array( $function, $args );
} catch ( \Throwable ) {
} catch ( \Throwable $e ) {
$value = '';
}

Expand Down
Loading