Issues (76)

Components/GridPostsArchive/functions.php (8 issues)

1
<?php
2
3
namespace Flynt\Components\GridPostsArchive;
4
5
use Flynt\FieldVariables;
0 ignored issues
show
The type Flynt\FieldVariables was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Flynt\Utils\Options;
7
use Timber\Term;
8
9
const POST_TYPE = 'post';
10
const FILTER_BY_TAXONOMY = 'category';
11
12
add_filter('Flynt/addComponentData?name=GridPostsArchive', function ($data) {
13
    $postType = POST_TYPE;
14
    $taxonomy = FILTER_BY_TAXONOMY;
15
    $terms = get_terms([
16
        'taxonomy' => $taxonomy,
17
        'hide_empty' => true,
18
    ]);
19
    $queriedObject = get_queried_object();
20
    if (count($terms) > 1) {
0 ignored issues
show
$terms of type WP_Error is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
    if (count(/** @scrutinizer ignore-type */ $terms) > 1) {
Loading history...
21
        $data['terms'] = array_map(function ($term) use ($queriedObject) {
22
            $timberTerm = new Term($term);
23
            if ($queriedObject) {
24
                $timberTerm->isActive = $queriedObject->taxonomy === $term->taxonomy && $queriedObject->term_id === $term->term_id;
0 ignored issues
show
The property isActive does not seem to exist on Timber\Term.
Loading history...
The property term_id does not seem to exist on WP_Post_Type.
Loading history...
The property taxonomy does not exist on WP_Post_Type. Did you mean taxonomies?
Loading history...
25
            }
26
            return $timberTerm;
27
        }, $terms);
0 ignored issues
show
$terms of type WP_Error is incompatible with the type array expected by parameter $array of array_map(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        }, /** @scrutinizer ignore-type */ $terms);
Loading history...
28
        // Add item for all posts
29
        array_unshift($data['terms'], [
30
            'link' => get_post_type_archive_link($postType),
31
            'title' => $data['labels']['allPosts'],
32
            'isActive' => is_home() || is_post_type_archive($postType),
33
        ]);
34
    }
35
36
    if (is_home()) {
37
        $data['isHome'] = true;
38
        $data['title'] = $queriedObject->post_title ?? get_bloginfo('name');
0 ignored issues
show
The property post_title does not seem to exist on WP_Post_Type.
Loading history...
39
    } else {
40
        $data['title'] =  get_the_archive_title();
41
        $data['description'] = get_the_archive_description();
42
    }
43
44
45
    return $data;
46
});
47
48
Options::addGlobal('GridPostsArchive', [
49
    [
50
        'label' => __('Load More Button?', 'flynt'),
51
        'name' => 'loadMore',
52
        'type' => 'true_false',
53
        'default_value' => 0,
54
        'ui' => 1
55
    ],
56
]);
57
Options::addTranslatable('GridPostsArchive', [
58
    [
59
        'label' => __('General', 'flynt'),
60
        'name' => 'general',
61
        'type' => 'tab',
62
        'placement' => 'top',
63
        'endpoint' => 0,
64
    ],
65
    [
66
        'label' => __('Title', 'flynt'),
67
        'name' => 'preContentHtml',
68
        'type' => 'wysiwyg',
69
        'instructions' => __('Want to add a headline? And a paragraph? Go ahead! Or just leave it empty and nothing will be shown.', 'flynt'),
70
        'tabs' => 'visual,text',
71
        'media_upload' => 0,
72
        'delay' => 1,
73
    ],
74
    [
75
        'label' => __('Labels', 'flynt'),
76
        'name' => 'labelsTab',
77
        'type' => 'tab',
78
        'placement' => 'top',
79
        'endpoint' => 0
80
    ],
81
    [
82
        'label' => '',
83
        'name' => 'labels',
84
        'type' => 'group',
85
        'sub_fields' => [
86
            [
87
                'label' => __('Previous', 'flynt'),
88
                'name' => 'previous',
89
                'type' => 'text',
90
                'default_value' => 'Prev',
91
                'required' => 1,
92
                'wrapper' => [
93
                    'width' => '50',
94
                ],
95
            ],
96
            [
97
                'label' => __('Next', 'flynt'),
98
                'name' => 'next',
99
                'type' => 'text',
100
                'default_value' => 'Next',
101
                'required' => 1,
102
                'wrapper' => [
103
                    'width' => '50',
104
                ],
105
            ],
106
            [
107
                'label' => __('Load More', 'flynt'),
108
                'name' => 'loadMore',
109
                'type' => 'text',
110
                'default_value' => 'Load more',
111
                'required' => 1,
112
                'wrapper' => [
113
                    'width' => '50',
114
                ],
115
            ],
116
            [
117
                'label' => __('No Posts Found Text', 'flynt'),
118
                'name' => 'noPostsFound',
119
                'type' => 'text',
120
                'default_value' => 'No posts found.',
121
                'required' => 1,
122
                'wrapper' => [
123
                    'width' => '50',
124
                ],
125
            ],
126
            [
127
                'label' => __('All Posts', 'flynt'),
128
                'name' => 'allPosts',
129
                'type' => 'text',
130
                'default_value' => 'All',
131
                'required' => 1,
132
                'wrapper' => [
133
                    'width' => '50',
134
                ],
135
            ],
136
            [
137
                'label' => __('Read More', 'flynt'),
138
                'name' => 'readMore',
139
                'type' => 'text',
140
                'default_value' => 'Read More',
141
                'required' => 1,
142
                'wrapper' => [
143
                    'width' => '50',
144
                ],
145
            ]
146
        ],
147
    ],
148
    [
149
        'label' => __('Options', 'flynt'),
150
        'name' => 'optionsTab',
151
        'type' => 'tab',
152
        'placement' => 'top',
153
        'endpoint' => 0
154
    ],
155
    [
156
        'label' => '',
157
        'name' => 'options',
158
        'type' => 'group',
159
        'layout' => 'row',
160
        'sub_fields' => [
161
            FieldVariables\getTheme()
0 ignored issues
show
The function getTheme was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

161
            /** @scrutinizer ignore-call */ 
162
            FieldVariables\getTheme()
Loading history...
162
        ]
163
    ],
164
]);
165