Passed
Push — master ( 5e727b...fa3796 )
by Paul
07:53
created

deprecated.php (12 issues)

Labels
Severity
1
<?php
2
3
use GeminiLabs\SiteReviews\Defaults\CreateReviewDefaults;
4
use GeminiLabs\SiteReviews\Helpers\Str;
5
use GeminiLabs\SiteReviews\Modules\Backtrace;
6
7
defined('ABSPATH') || die;
8
9
add_action('plugins_loaded', function () {
0 ignored issues
show
The function add_action 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

9
/** @scrutinizer ignore-call */ 
10
add_action('plugins_loaded', function () {
Loading history...
10
    if (!glsr()->filterBool('support/deprecated/v5', true)) {
11
        return;
12
    }
13
    /**
14
     * Review meta data has been deprecated
15
     * @since 5.0.0
16
     */
17
    add_filter('get_post_metadata', function ($data, $postId, $metaKey) {
0 ignored issues
show
The function add_filter 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

17
    /** @scrutinizer ignore-call */ 
18
    add_filter('get_post_metadata', function ($data, $postId, $metaKey) {
Loading history...
18
        if (glsr()->post_type !== get_post_type($postId)) {
0 ignored issues
show
The function get_post_type 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

18
        if (glsr()->post_type !== /** @scrutinizer ignore-call */ get_post_type($postId)) {
Loading history...
19
            return $data;
20
        }
21
        $metaKey = Str::removePrefix($metaKey, '_');
22
        $metaKeys = [
23
            'assigned_to', 'author', 'avatar', 'content', 'date', 'email', 
24
            'ip_address', 'pinned', 'rating', 'review_id', 'review_type', 
25
            'title', 'url',
26
        ];
27
        if (!in_array($metaKey, $metaKeys)) {
28
            return $data;
29
        }
30
        $message = 'Site Reviews no longer stores the "'.$metaKey.'" review value as meta data. Please use the glsr_get_review() helper function instead.';
31
        glsr()->append('deprecated', $message);
32
        return glsr_get_review($postId)->{$metaKey};
33
    }, 10, 3);
34
35
    /**
36
     * Application
37
     * @since 5.0.0
38
     */
39
    add_filter('site-reviews/config/forms/review-form', function ($config) {
40
        if (has_filter('site-reviews/config/forms/submission-form')) {
0 ignored issues
show
The function has_filter 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

40
        if (/** @scrutinizer ignore-call */ has_filter('site-reviews/config/forms/submission-form')) {
Loading history...
41
            $message = 'The "site-reviews/config/forms/submission-form" hook has been deprecated. Please use the "site-reviews/config/forms/review-form" hook instead.';
42
            glsr()->append('deprecated', $message);
43
            return apply_filters('site-reviews/config/forms/submission-form', $config);
0 ignored issues
show
The function apply_filters 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

43
            return /** @scrutinizer ignore-call */ apply_filters('site-reviews/config/forms/submission-form', $config);
Loading history...
44
        }
45
        return $config;
46
    }, 9);
47
48
    /**
49
     * Modules\Html\ReviewsHtml
50
     * @since 5.0.0
51
     */
52
    add_filter('site-reviews/rendered/template/reviews', function ($html) {
53
        if (has_filter('site-reviews/reviews/reviews-wrapper')) {
0 ignored issues
show
The function has_filter 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

53
        if (/** @scrutinizer ignore-call */ has_filter('site-reviews/reviews/reviews-wrapper')) {
Loading history...
54
           $message = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use a custom "reviews.php" template instead.';
55
           glsr()->append('deprecated', $message);
56
        }
57
        return $html;
58
    });
59
60
    /**
61
     * Controllers\PublicController
62
     * @since 5.0.0
63
     */
64
    add_filter('site-reviews/review-form/order', function ($order) {
65
        if (has_filter('site-reviews/submission-form/order')) {
0 ignored issues
show
The function has_filter 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

65
        if (/** @scrutinizer ignore-call */ has_filter('site-reviews/submission-form/order')) {
Loading history...
66
            $message = 'The "site-reviews/submission-form/order" hook has been deprecated. Please use the "site-reviews/review-form/order" hook instead.';
67
            glsr()->append('deprecated', $message);
68
            return apply_filters('site-reviews/submission-form/order', $order);
0 ignored issues
show
The function apply_filters 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

68
            return /** @scrutinizer ignore-call */ apply_filters('site-reviews/submission-form/order', $order);
Loading history...
69
        }
70
        return $order;
71
    }, 9);
72
});
73
74
/**
75
 * @return void
76
 * @since 5.0.0
77
 */
78
function glsr_calculate_ratings() {
79
    _deprecated_function('glsr_calculate_ratings', '5.0 (of Site Reviews)');
0 ignored issues
show
The function _deprecated_function 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

79
    /** @scrutinizer ignore-call */ 
80
    _deprecated_function('glsr_calculate_ratings', '5.0 (of Site Reviews)');
Loading history...
80
    glsr_log()->error(sprintf(
81
        __('%s is <strong>deprecated</strong> since version %s with no alternative available.', 'site-reviews'),
0 ignored issues
show
The function __ 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

81
        /** @scrutinizer ignore-call */ 
82
        __('%s is <strong>deprecated</strong> since version %s with no alternative available.', 'site-reviews'),
Loading history...
82
        'glsr_calculate_ratings',
83
        '5.0'
84
    ));
85
}
86
87
/**
88
 * @return object
89
 * @since 5.0.0
90
 */
91
function glsr_get_rating($args = array()) {
92
    _deprecated_function('glsr_get_rating', '5.0 (of Site Reviews)', 'glsr_get_ratings');
0 ignored issues
show
The function _deprecated_function 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

92
    /** @scrutinizer ignore-call */ 
93
    _deprecated_function('glsr_get_rating', '5.0 (of Site Reviews)', 'glsr_get_ratings');
Loading history...
93
    glsr_log()->warning(sprintf(
94
        __('%s is <strong>deprecated</strong> since version %s! Use %s instead.', 'site-reviews'),
0 ignored issues
show
The function __ 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

94
        /** @scrutinizer ignore-call */ 
95
        __('%s is <strong>deprecated</strong> since version %s! Use %s instead.', 'site-reviews'),
Loading history...
95
        'glsr_get_rating',
96
        '5.0',
97
        'glsr_get_ratings'
98
    ));
99
    return glsr_get_ratings($args);
100
}
101
102
function glsr_log_deprecated_notices() {
103
    $notices = (array) glsr()->retrieve('deprecated', []);
104
    $notices = array_keys(array_flip(array_filter($notices)));
105
    natsort($notices);
106
    foreach ($notices as $notice) {
107
        trigger_error($notice, E_USER_DEPRECATED);
108
        glsr_log()->warning($notice);
109
    }
110
}
111
add_action('admin_footer', 'glsr_log_deprecated_notices');
112
add_action('wp_footer', 'glsr_log_deprecated_notices');
113