Completed
Push — environmentTesting ( 0dad9d...e29acf )
by Wahiba
03:20
created

functions.php ➔ getPasswordContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Components\LayoutMultiplePosts;
4
5
use Timber\Timber;
6
use Flynt\Features\Components\Component;
7
8
add_action('wp_enqueue_scripts', function () {
9
    Component::enqueueAssets('LayoutMultiplePosts');
10
});
11
12
add_filter('Flynt/addComponentData?name=LayoutMultiplePosts', function ($data) {
13
    $query = !empty($data['query']) ? $data['query'] : false;
14
    $posts = Timber::get_posts($query);
15
    if (!empty($posts)) {
16
        $posts = array_map(function ($post) {
17
            $fields = get_fields($post->id);
18
            $post->fields = $fields === false ? [] : $fields;
19
            return $post;
20
        }, $posts);
21
    }
22
    $context = [
23
        'posts' => $posts,
24
        'pagination' => Timber::get_pagination()
25
    ];
26
    return array_merge(getPasswordContext(), $context, $data);
27
});
28
29 View Code Duplication
function getPasswordContext($postId = null)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
    $passwordProtected = post_password_required($postId);
32
    return [
33
        'passwordProtected' => $passwordProtected,
34
        'passwordForm' => $passwordProtected ? get_the_password_form() : ''
35
    ];
36
}
37