@@ -3,136 +3,136 @@ |
||
| 3 | 3 | defined('WPINC') || die; |
| 4 | 4 | |
| 5 | 5 | if (!apply_filters('site-reviews/support/deprecated', true)) { |
| 6 | - return; |
|
| 6 | + return; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | // Unprotected review meta has been deprecated |
| 10 | 10 | add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
| 11 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
| 12 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
| 13 | - return $data; |
|
| 14 | - } |
|
| 15 | - glsr()->deprecated[] = sprintf( |
|
| 16 | - 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
| 17 | - $metaKey |
|
| 18 | - ); |
|
| 19 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
| 11 | + $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
| 12 | + if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
| 13 | + return $data; |
|
| 14 | + } |
|
| 15 | + glsr()->deprecated[] = sprintf( |
|
| 16 | + 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
| 17 | + $metaKey |
|
| 18 | + ); |
|
| 19 | + return get_post_meta($postId, '_'.$metaKey, $single); |
|
| 20 | 20 | }, 10, 4); |
| 21 | 21 | |
| 22 | 22 | // Modules/Html/Template.php |
| 23 | 23 | add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
| 24 | - $search = '{{ navigation }}'; |
|
| 25 | - if (false !== strpos($template, $search)) { |
|
| 26 | - $context['navigation'] = $context['pagination']; |
|
| 27 | - glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
| 28 | - } |
|
| 29 | - return $context; |
|
| 24 | + $search = '{{ navigation }}'; |
|
| 25 | + if (false !== strpos($template, $search)) { |
|
| 26 | + $context['navigation'] = $context['pagination']; |
|
| 27 | + glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
| 28 | + } |
|
| 29 | + return $context; |
|
| 30 | 30 | }, 10, 2); |
| 31 | 31 | |
| 32 | 32 | // Database/ReviewManager.php |
| 33 | 33 | add_action('site-reviews/review/created', function ($review) { |
| 34 | - if (has_action('site-reviews/local/review/create')) { |
|
| 35 | - glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
| 36 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
| 37 | - } |
|
| 34 | + if (has_action('site-reviews/local/review/create')) { |
|
| 35 | + glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
| 36 | + do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
| 37 | + } |
|
| 38 | 38 | }, 9); |
| 39 | 39 | |
| 40 | 40 | // Handlers/CreateReview.php |
| 41 | 41 | add_action('site-reviews/review/submitted', function ($review) { |
| 42 | - if (has_action('site-reviews/local/review/submitted')) { |
|
| 43 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
| 44 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
| 45 | - } |
|
| 46 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
| 47 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
| 48 | - } |
|
| 42 | + if (has_action('site-reviews/local/review/submitted')) { |
|
| 43 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
| 44 | + do_action('site-reviews/local/review/submitted', null, $review); |
|
| 45 | + } |
|
| 46 | + if (has_filter('site-reviews/local/review/submitted/message')) { |
|
| 47 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
| 48 | + } |
|
| 49 | 49 | }, 9); |
| 50 | 50 | |
| 51 | 51 | // Database/ReviewManager.php |
| 52 | 52 | add_filter('site-reviews/create/review-values', function ($values, $command) { |
| 53 | - if (has_filter('site-reviews/local/review')) { |
|
| 54 | - glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
| 55 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
| 56 | - } |
|
| 57 | - return $values; |
|
| 53 | + if (has_filter('site-reviews/local/review')) { |
|
| 54 | + glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
| 55 | + return apply_filters('site-reviews/local/review', $values, $command); |
|
| 56 | + } |
|
| 57 | + return $values; |
|
| 58 | 58 | }, 9, 2); |
| 59 | 59 | |
| 60 | 60 | // Handlers/EnqueuePublicAssets.php |
| 61 | 61 | add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
| 62 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
| 63 | - glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
| 64 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
| 65 | - } |
|
| 66 | - return $variables; |
|
| 62 | + if (has_filter('site-reviews/enqueue/localize')) { |
|
| 63 | + glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
| 64 | + return apply_filters('site-reviews/enqueue/localize', $variables); |
|
| 65 | + } |
|
| 66 | + return $variables; |
|
| 67 | 67 | }, 9); |
| 68 | 68 | |
| 69 | 69 | // Modules/Rating.php |
| 70 | 70 | add_filter('site-reviews/rating/average', function ($average) { |
| 71 | - if (has_filter('site-reviews/average/rating')) { |
|
| 72 | - glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
| 73 | - } |
|
| 74 | - return $average; |
|
| 71 | + if (has_filter('site-reviews/average/rating')) { |
|
| 72 | + glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
| 73 | + } |
|
| 74 | + return $average; |
|
| 75 | 75 | }, 9); |
| 76 | 76 | |
| 77 | 77 | // Modules/Rating.php |
| 78 | 78 | add_filter('site-reviews/rating/ranking', function ($ranking) { |
| 79 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
| 80 | - glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
| 81 | - } |
|
| 82 | - return $ranking; |
|
| 79 | + if (has_filter('site-reviews/bayesian/ranking')) { |
|
| 80 | + glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
| 81 | + } |
|
| 82 | + return $ranking; |
|
| 83 | 83 | }, 9); |
| 84 | 84 | |
| 85 | 85 | // Modules/Html/Partials/SiteReviews.php |
| 86 | 86 | add_filter('site-reviews/review/build/after', function ($renderedFields) { |
| 87 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
| 88 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
| 89 | - } |
|
| 90 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
| 91 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
| 92 | - } |
|
| 93 | - return $renderedFields; |
|
| 87 | + if (has_filter('site-reviews/reviews/review/text')) { |
|
| 88 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
| 89 | + } |
|
| 90 | + if (has_filter('site-reviews/reviews/review/title')) { |
|
| 91 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
| 92 | + } |
|
| 93 | + return $renderedFields; |
|
| 94 | 94 | }, 9); |
| 95 | 95 | |
| 96 | 96 | // Modules/Html/Partials/SiteReviews.php |
| 97 | 97 | add_filter('site-reviews/review/build/before', function ($review) { |
| 98 | - if (has_filter('site-reviews/rendered/review')) { |
|
| 99 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
| 100 | - } |
|
| 101 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
| 102 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
| 103 | - } |
|
| 104 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
| 105 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
| 106 | - } |
|
| 107 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
| 108 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
| 109 | - } |
|
| 110 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
| 111 | - glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
| 112 | - } |
|
| 113 | - return $review; |
|
| 98 | + if (has_filter('site-reviews/rendered/review')) { |
|
| 99 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
| 100 | + } |
|
| 101 | + if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
| 102 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
| 103 | + } |
|
| 104 | + if (has_filter('site-reviews/rendered/review/order')) { |
|
| 105 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
| 106 | + } |
|
| 107 | + if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
| 108 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
| 109 | + } |
|
| 110 | + if (has_filter('site-reviews/reviews/navigation_links')) { |
|
| 111 | + glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
| 112 | + } |
|
| 113 | + return $review; |
|
| 114 | 114 | }, 9); |
| 115 | 115 | |
| 116 | 116 | add_filter('site-reviews/validate/custom', function ($result, $request) { |
| 117 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
| 118 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
| 119 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
| 120 | - } |
|
| 121 | - return $result; |
|
| 117 | + if (has_filter('site-reviews/validate/review/submission')) { |
|
| 118 | + glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
| 119 | + return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
| 120 | + } |
|
| 121 | + return $result; |
|
| 122 | 122 | }, 9, 2); |
| 123 | 123 | |
| 124 | 124 | add_filter('site-reviews/views/file', function ($file, $view, $data) { |
| 125 | - if (has_filter('site-reviews/addon/views/file')) { |
|
| 126 | - glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
| 127 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
| 128 | - } |
|
| 129 | - return $file; |
|
| 125 | + if (has_filter('site-reviews/addon/views/file')) { |
|
| 126 | + glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
| 127 | + $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
| 128 | + } |
|
| 129 | + return $file; |
|
| 130 | 130 | }, 9, 3); |
| 131 | 131 | |
| 132 | 132 | add_action('wp_footer', function () { |
| 133 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
| 134 | - natsort($notices); |
|
| 135 | - foreach ($notices as $notice) { |
|
| 136 | - glsr_log()->warning($notice); |
|
| 137 | - } |
|
| 133 | + $notices = array_keys(array_flip(glsr()->deprecated)); |
|
| 134 | + natsort($notices); |
|
| 135 | + foreach ($notices as $notice) { |
|
| 136 | + glsr_log()->warning($notice); |
|
| 137 | + } |
|
| 138 | 138 | }); |
@@ -1,138 +1,138 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -defined('WPINC') || die; |
|
| 3 | +defined( 'WPINC' ) || die; |
|
| 4 | 4 | |
| 5 | -if (!apply_filters('site-reviews/support/deprecated', true)) { |
|
| 5 | +if( !apply_filters( 'site-reviews/support/deprecated', true ) ) { |
|
| 6 | 6 | return; |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | // Unprotected review meta has been deprecated |
| 10 | -add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
| 11 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
| 12 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
| 10 | +add_filter( 'get_post_metadata', function( $data, $postId, $metaKey, $single ) { |
|
| 11 | + $metaKeys = array_keys( glsr( 'Defaults\CreateReviewDefaults' )->defaults() ); |
|
| 12 | + if( !in_array( $metaKey, $metaKeys ) || glsr()->post_type != get_post_type( $postId ) ) { |
|
| 13 | 13 | return $data; |
| 14 | 14 | } |
| 15 | 15 | glsr()->deprecated[] = sprintf( |
| 16 | 16 | 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
| 17 | 17 | $metaKey |
| 18 | 18 | ); |
| 19 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
| 20 | -}, 10, 4); |
|
| 19 | + return get_post_meta( $postId, '_'.$metaKey, $single ); |
|
| 20 | +}, 10, 4 ); |
|
| 21 | 21 | |
| 22 | 22 | // Modules/Html/Template.php |
| 23 | -add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
| 23 | +add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) { |
|
| 24 | 24 | $search = '{{ navigation }}'; |
| 25 | - if (false !== strpos($template, $search)) { |
|
| 25 | + if( false !== strpos( $template, $search ) ) { |
|
| 26 | 26 | $context['navigation'] = $context['pagination']; |
| 27 | 27 | glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
| 28 | 28 | } |
| 29 | 29 | return $context; |
| 30 | -}, 10, 2); |
|
| 30 | +}, 10, 2 ); |
|
| 31 | 31 | |
| 32 | 32 | // Database/ReviewManager.php |
| 33 | -add_action('site-reviews/review/created', function ($review) { |
|
| 34 | - if (has_action('site-reviews/local/review/create')) { |
|
| 33 | +add_action( 'site-reviews/review/created', function( $review ) { |
|
| 34 | + if( has_action( 'site-reviews/local/review/create' ) ) { |
|
| 35 | 35 | glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
| 36 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
| 36 | + do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID ); |
|
| 37 | 37 | } |
| 38 | -}, 9); |
|
| 38 | +}, 9 ); |
|
| 39 | 39 | |
| 40 | 40 | // Handlers/CreateReview.php |
| 41 | -add_action('site-reviews/review/submitted', function ($review) { |
|
| 42 | - if (has_action('site-reviews/local/review/submitted')) { |
|
| 41 | +add_action( 'site-reviews/review/submitted', function( $review ) { |
|
| 42 | + if( has_action( 'site-reviews/local/review/submitted' ) ) { |
|
| 43 | 43 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
| 44 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
| 44 | + do_action( 'site-reviews/local/review/submitted', null, $review ); |
|
| 45 | 45 | } |
| 46 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
| 46 | + if( has_filter( 'site-reviews/local/review/submitted/message' ) ) { |
|
| 47 | 47 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
| 48 | 48 | } |
| 49 | -}, 9); |
|
| 49 | +}, 9 ); |
|
| 50 | 50 | |
| 51 | 51 | // Database/ReviewManager.php |
| 52 | -add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
| 53 | - if (has_filter('site-reviews/local/review')) { |
|
| 52 | +add_filter( 'site-reviews/create/review-values', function( $values, $command ) { |
|
| 53 | + if( has_filter( 'site-reviews/local/review' ) ) { |
|
| 54 | 54 | glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
| 55 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
| 55 | + return apply_filters( 'site-reviews/local/review', $values, $command ); |
|
| 56 | 56 | } |
| 57 | 57 | return $values; |
| 58 | -}, 9, 2); |
|
| 58 | +}, 9, 2 ); |
|
| 59 | 59 | |
| 60 | 60 | // Handlers/EnqueuePublicAssets.php |
| 61 | -add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
| 62 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
| 61 | +add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) { |
|
| 62 | + if( has_filter( 'site-reviews/enqueue/localize' ) ) { |
|
| 63 | 63 | glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
| 64 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
| 64 | + return apply_filters( 'site-reviews/enqueue/localize', $variables ); |
|
| 65 | 65 | } |
| 66 | 66 | return $variables; |
| 67 | -}, 9); |
|
| 67 | +}, 9 ); |
|
| 68 | 68 | |
| 69 | 69 | // Modules/Rating.php |
| 70 | -add_filter('site-reviews/rating/average', function ($average) { |
|
| 71 | - if (has_filter('site-reviews/average/rating')) { |
|
| 70 | +add_filter( 'site-reviews/rating/average', function( $average ) { |
|
| 71 | + if( has_filter( 'site-reviews/average/rating' ) ) { |
|
| 72 | 72 | glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
| 73 | 73 | } |
| 74 | 74 | return $average; |
| 75 | -}, 9); |
|
| 75 | +}, 9 ); |
|
| 76 | 76 | |
| 77 | 77 | // Modules/Rating.php |
| 78 | -add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
| 79 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
| 78 | +add_filter( 'site-reviews/rating/ranking', function( $ranking ) { |
|
| 79 | + if( has_filter( 'site-reviews/bayesian/ranking' ) ) { |
|
| 80 | 80 | glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
| 81 | 81 | } |
| 82 | 82 | return $ranking; |
| 83 | -}, 9); |
|
| 83 | +}, 9 ); |
|
| 84 | 84 | |
| 85 | 85 | // Modules/Html/Partials/SiteReviews.php |
| 86 | -add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
| 87 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
| 86 | +add_filter( 'site-reviews/review/build/after', function( $renderedFields ) { |
|
| 87 | + if( has_filter( 'site-reviews/reviews/review/text' ) ) { |
|
| 88 | 88 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
| 89 | 89 | } |
| 90 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
| 90 | + if( has_filter( 'site-reviews/reviews/review/title' ) ) { |
|
| 91 | 91 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
| 92 | 92 | } |
| 93 | 93 | return $renderedFields; |
| 94 | -}, 9); |
|
| 94 | +}, 9 ); |
|
| 95 | 95 | |
| 96 | 96 | // Modules/Html/Partials/SiteReviews.php |
| 97 | -add_filter('site-reviews/review/build/before', function ($review) { |
|
| 98 | - if (has_filter('site-reviews/rendered/review')) { |
|
| 97 | +add_filter( 'site-reviews/review/build/before', function( $review ) { |
|
| 98 | + if( has_filter( 'site-reviews/rendered/review' ) ) { |
|
| 99 | 99 | glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
| 100 | 100 | } |
| 101 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
| 101 | + if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) { |
|
| 102 | 102 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
| 103 | 103 | } |
| 104 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
| 104 | + if( has_filter( 'site-reviews/rendered/review/order' ) ) { |
|
| 105 | 105 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
| 106 | 106 | } |
| 107 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
| 107 | + if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) { |
|
| 108 | 108 | glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
| 109 | 109 | } |
| 110 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
| 110 | + if( has_filter( 'site-reviews/reviews/navigation_links' ) ) { |
|
| 111 | 111 | glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
| 112 | 112 | } |
| 113 | 113 | return $review; |
| 114 | -}, 9); |
|
| 114 | +}, 9 ); |
|
| 115 | 115 | |
| 116 | -add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
| 117 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
| 118 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
| 119 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
| 116 | +add_filter( 'site-reviews/validate/custom', function( $result, $request ) { |
|
| 117 | + if( has_filter( 'site-reviews/validate/review/submission' ) ) { |
|
| 118 | + glsr_log()->warning( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' ); |
|
| 119 | + return apply_filters( 'site-reviews/validate/review/submission', $result, $request ); |
|
| 120 | 120 | } |
| 121 | 121 | return $result; |
| 122 | -}, 9, 2); |
|
| 122 | +}, 9, 2 ); |
|
| 123 | 123 | |
| 124 | -add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
| 125 | - if (has_filter('site-reviews/addon/views/file')) { |
|
| 124 | +add_filter( 'site-reviews/views/file', function( $file, $view, $data ) { |
|
| 125 | + if( has_filter( 'site-reviews/addon/views/file' ) ) { |
|
| 126 | 126 | glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
| 127 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
| 127 | + $file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data ); |
|
| 128 | 128 | } |
| 129 | 129 | return $file; |
| 130 | -}, 9, 3); |
|
| 130 | +}, 9, 3 ); |
|
| 131 | 131 | |
| 132 | -add_action('wp_footer', function () { |
|
| 133 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
| 134 | - natsort($notices); |
|
| 135 | - foreach ($notices as $notice) { |
|
| 136 | - glsr_log()->warning($notice); |
|
| 132 | +add_action( 'wp_footer', function() { |
|
| 133 | + $notices = array_keys( array_flip( glsr()->deprecated ) ); |
|
| 134 | + natsort( $notices ); |
|
| 135 | + foreach( $notices as $notice ) { |
|
| 136 | + glsr_log()->warning( $notice ); |
|
| 137 | 137 | } |
| 138 | 138 | }); |
@@ -9,308 +9,308 @@ |
||
| 9 | 9 | |
| 10 | 10 | final class Application extends Container |
| 11 | 11 | { |
| 12 | - const CAPABILITY = 'edit_others_posts'; |
|
| 13 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 14 | - const ID = 'site-reviews'; |
|
| 15 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 16 | - const POST_TYPE = 'site-review'; |
|
| 17 | - const PREFIX = 'glsr_'; |
|
| 18 | - const TAXONOMY = 'site-review-category'; |
|
| 12 | + const CAPABILITY = 'edit_others_posts'; |
|
| 13 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
| 14 | + const ID = 'site-reviews'; |
|
| 15 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
| 16 | + const POST_TYPE = 'site-review'; |
|
| 17 | + const PREFIX = 'glsr_'; |
|
| 18 | + const TAXONOMY = 'site-review-category'; |
|
| 19 | 19 | |
| 20 | - public $defaults; |
|
| 21 | - public $deprecated = []; |
|
| 22 | - public $file; |
|
| 23 | - public $languages; |
|
| 24 | - public $mceShortcodes = []; //defined elsewhere |
|
| 25 | - public $name; |
|
| 26 | - public $reviewTypes; |
|
| 27 | - public $schemas = []; //defined elsewhere |
|
| 28 | - public $version; |
|
| 20 | + public $defaults; |
|
| 21 | + public $deprecated = []; |
|
| 22 | + public $file; |
|
| 23 | + public $languages; |
|
| 24 | + public $mceShortcodes = []; //defined elsewhere |
|
| 25 | + public $name; |
|
| 26 | + public $reviewTypes; |
|
| 27 | + public $schemas = []; //defined elsewhere |
|
| 28 | + public $version; |
|
| 29 | 29 | |
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - static::$instance = $this; |
|
| 33 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 34 | - $plugin = get_file_data($this->file, [ |
|
| 35 | - 'languages' => 'Domain Path', |
|
| 36 | - 'name' => 'Plugin Name', |
|
| 37 | - 'version' => 'Version', |
|
| 38 | - ], 'plugin'); |
|
| 39 | - array_walk($plugin, function ($value, $key) { |
|
| 40 | - $this->$key = $value; |
|
| 41 | - }); |
|
| 42 | - } |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + static::$instance = $this; |
|
| 33 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 34 | + $plugin = get_file_data($this->file, [ |
|
| 35 | + 'languages' => 'Domain Path', |
|
| 36 | + 'name' => 'Plugin Name', |
|
| 37 | + 'version' => 'Version', |
|
| 38 | + ], 'plugin'); |
|
| 39 | + array_walk($plugin, function ($value, $key) { |
|
| 40 | + $this->$key = $value; |
|
| 41 | + }); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function activate() |
|
| 48 | - { |
|
| 49 | - $this->make(DefaultsManager::class)->set(); |
|
| 50 | - $this->scheduleCronJob(); |
|
| 51 | - $this->upgrade(); |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function activate() |
|
| 48 | + { |
|
| 49 | + $this->make(DefaultsManager::class)->set(); |
|
| 50 | + $this->scheduleCronJob(); |
|
| 51 | + $this->upgrade(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function catchFatalError() |
|
| 58 | - { |
|
| 59 | - $error = error_get_last(); |
|
| 60 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - glsr_log()->error($error['message']); |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function catchFatalError() |
|
| 58 | + { |
|
| 59 | + $error = error_get_last(); |
|
| 60 | + if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + glsr_log()->error($error['message']); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $name |
|
| 68 | - * @return array |
|
| 69 | - */ |
|
| 70 | - public function config($name) |
|
| 71 | - { |
|
| 72 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 73 | - $config = file_exists($configFile) |
|
| 74 | - ? include $configFile |
|
| 75 | - : []; |
|
| 76 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 77 | - } |
|
| 66 | + /** |
|
| 67 | + * @param string $name |
|
| 68 | + * @return array |
|
| 69 | + */ |
|
| 70 | + public function config($name) |
|
| 71 | + { |
|
| 72 | + $configFile = $this->path('config/'.$name.'.php'); |
|
| 73 | + $config = file_exists($configFile) |
|
| 74 | + ? include $configFile |
|
| 75 | + : []; |
|
| 76 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @param string $property |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function constant($property, $className = 'static') |
|
| 84 | - { |
|
| 85 | - $constant = $className.'::'.$property; |
|
| 86 | - return defined($constant) |
|
| 87 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 88 | - : ''; |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * @param string $property |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function constant($property, $className = 'static') |
|
| 84 | + { |
|
| 85 | + $constant = $className.'::'.$property; |
|
| 86 | + return defined($constant) |
|
| 87 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 88 | + : ''; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function deactivate() |
|
| 95 | - { |
|
| 96 | - $this->unscheduleCronJob(); |
|
| 97 | - } |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function deactivate() |
|
| 95 | + { |
|
| 96 | + $this->unscheduleCronJob(); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @param string $view |
|
| 101 | - * @return void|string |
|
| 102 | - */ |
|
| 103 | - public function file($view) |
|
| 104 | - { |
|
| 105 | - $view.= '.php'; |
|
| 106 | - $filePaths = []; |
|
| 107 | - if (Str::startsWith('templates/', $view)) { |
|
| 108 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 109 | - } |
|
| 110 | - $filePaths[] = $this->path($view); |
|
| 111 | - $filePaths[] = $this->path('views/'.$view); |
|
| 112 | - foreach ($filePaths as $file) { |
|
| 113 | - if (!file_exists($file)) { |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 116 | - return $file; |
|
| 117 | - } |
|
| 118 | - } |
|
| 99 | + /** |
|
| 100 | + * @param string $view |
|
| 101 | + * @return void|string |
|
| 102 | + */ |
|
| 103 | + public function file($view) |
|
| 104 | + { |
|
| 105 | + $view.= '.php'; |
|
| 106 | + $filePaths = []; |
|
| 107 | + if (Str::startsWith('templates/', $view)) { |
|
| 108 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 109 | + } |
|
| 110 | + $filePaths[] = $this->path($view); |
|
| 111 | + $filePaths[] = $this->path('views/'.$view); |
|
| 112 | + foreach ($filePaths as $file) { |
|
| 113 | + if (!file_exists($file)) { |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | + return $file; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - public function getDefaults() |
|
| 124 | - { |
|
| 125 | - if (empty($this->defaults)) { |
|
| 126 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 127 | - $this->upgrade(); |
|
| 128 | - } |
|
| 129 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 130 | - } |
|
| 120 | + /** |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + public function getDefaults() |
|
| 124 | + { |
|
| 125 | + if (empty($this->defaults)) { |
|
| 126 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 127 | + $this->upgrade(); |
|
| 128 | + } |
|
| 129 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function getPermission($page = '') |
|
| 136 | - { |
|
| 137 | - $permissions = [ |
|
| 138 | - 'addons' => 'install_plugins', |
|
| 139 | - 'settings' => 'manage_options', |
|
| 140 | - // 'welcome' => 'activate_plugins', |
|
| 141 | - ]; |
|
| 142 | - return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 143 | - } |
|
| 132 | + /** |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function getPermission($page = '') |
|
| 136 | + { |
|
| 137 | + $permissions = [ |
|
| 138 | + 'addons' => 'install_plugins', |
|
| 139 | + 'settings' => 'manage_options', |
|
| 140 | + // 'welcome' => 'activate_plugins', |
|
| 141 | + ]; |
|
| 142 | + return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - public function hasPermission($page = '') |
|
| 149 | - { |
|
| 150 | - $isAdmin = $this->isAdmin(); |
|
| 151 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 152 | - } |
|
| 145 | + /** |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + public function hasPermission($page = '') |
|
| 149 | + { |
|
| 150 | + $isAdmin = $this->isAdmin(); |
|
| 151 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - public function init() |
|
| 158 | - { |
|
| 159 | - $this->make(Actions::class)->run(); |
|
| 160 | - $this->make(Filters::class)->run(); |
|
| 161 | - } |
|
| 154 | + /** |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + public function init() |
|
| 158 | + { |
|
| 159 | + $this->make(Actions::class)->run(); |
|
| 160 | + $this->make(Filters::class)->run(); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - public function isAdmin() |
|
| 167 | - { |
|
| 168 | - return is_admin() && !wp_doing_ajax(); |
|
| 169 | - } |
|
| 163 | + /** |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + public function isAdmin() |
|
| 167 | + { |
|
| 168 | + return is_admin() && !wp_doing_ajax(); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * @param string $file |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function path($file = '', $realpath = true) |
|
| 176 | - { |
|
| 177 | - $path = plugin_dir_path($this->file); |
|
| 178 | - if (!$realpath) { |
|
| 179 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 180 | - } |
|
| 181 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 182 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 183 | - } |
|
| 171 | + /** |
|
| 172 | + * @param string $file |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function path($file = '', $realpath = true) |
|
| 176 | + { |
|
| 177 | + $path = plugin_dir_path($this->file); |
|
| 178 | + if (!$realpath) { |
|
| 179 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 180 | + } |
|
| 181 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 182 | + return apply_filters('site-reviews/path', $path, $file); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - public function registerAddons() |
|
| 189 | - { |
|
| 190 | - do_action('site-reviews/addon/register', $this); |
|
| 191 | - } |
|
| 185 | + /** |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + public function registerAddons() |
|
| 189 | + { |
|
| 190 | + do_action('site-reviews/addon/register', $this); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @return void |
|
| 195 | - */ |
|
| 196 | - public function registerLanguages() |
|
| 197 | - { |
|
| 198 | - load_plugin_textdomain(static::ID, false, |
|
| 199 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 200 | - ); |
|
| 201 | - } |
|
| 193 | + /** |
|
| 194 | + * @return void |
|
| 195 | + */ |
|
| 196 | + public function registerLanguages() |
|
| 197 | + { |
|
| 198 | + load_plugin_textdomain(static::ID, false, |
|
| 199 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * @return void |
|
| 205 | - */ |
|
| 206 | - public function registerReviewTypes() |
|
| 207 | - { |
|
| 208 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 209 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 210 | - 'local' => __('Local', 'site-reviews'), |
|
| 211 | - ]); |
|
| 212 | - } |
|
| 203 | + /** |
|
| 204 | + * @return void |
|
| 205 | + */ |
|
| 206 | + public function registerReviewTypes() |
|
| 207 | + { |
|
| 208 | + $types = apply_filters('site-reviews/addon/types', []); |
|
| 209 | + $this->reviewTypes = wp_parse_args($types, [ |
|
| 210 | + 'local' => __('Local', 'site-reviews'), |
|
| 211 | + ]); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * @param string $view |
|
| 216 | - * @return void |
|
| 217 | - */ |
|
| 218 | - public function render($view, array $data = []) |
|
| 219 | - { |
|
| 220 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 221 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 222 | - if (!file_exists($file)) { |
|
| 223 | - glsr_log()->error('File not found: '.$file); |
|
| 224 | - return; |
|
| 225 | - } |
|
| 226 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 227 | - extract($data); |
|
| 228 | - include $file; |
|
| 229 | - } |
|
| 214 | + /** |
|
| 215 | + * @param string $view |
|
| 216 | + * @return void |
|
| 217 | + */ |
|
| 218 | + public function render($view, array $data = []) |
|
| 219 | + { |
|
| 220 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 221 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 222 | + if (!file_exists($file)) { |
|
| 223 | + glsr_log()->error('File not found: '.$file); |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 227 | + extract($data); |
|
| 228 | + include $file; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * @return void |
|
| 233 | - */ |
|
| 234 | - public function scheduleCronJob() |
|
| 235 | - { |
|
| 236 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 237 | - return; |
|
| 238 | - } |
|
| 239 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 240 | - } |
|
| 231 | + /** |
|
| 232 | + * @return void |
|
| 233 | + */ |
|
| 234 | + public function scheduleCronJob() |
|
| 235 | + { |
|
| 236 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 237 | + return; |
|
| 238 | + } |
|
| 239 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * @param string $file |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function themePath($file = '') |
|
| 247 | - { |
|
| 248 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 249 | - } |
|
| 242 | + /** |
|
| 243 | + * @param string $file |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function themePath($file = '') |
|
| 247 | + { |
|
| 248 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * @return void |
|
| 253 | - */ |
|
| 254 | - public function unscheduleCronJob() |
|
| 255 | - { |
|
| 256 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 257 | - } |
|
| 251 | + /** |
|
| 252 | + * @return void |
|
| 253 | + */ |
|
| 254 | + public function unscheduleCronJob() |
|
| 255 | + { |
|
| 256 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * @return void |
|
| 261 | - */ |
|
| 262 | - public function upgrade() |
|
| 263 | - { |
|
| 264 | - $this->make(Upgrader::class)->run(); |
|
| 265 | - } |
|
| 259 | + /** |
|
| 260 | + * @return void |
|
| 261 | + */ |
|
| 262 | + public function upgrade() |
|
| 263 | + { |
|
| 264 | + $this->make(Upgrader::class)->run(); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * @param mixed $upgrader |
|
| 269 | - * @return void |
|
| 270 | - * @action upgrader_process_complete |
|
| 271 | - */ |
|
| 272 | - public function upgraded($upgrader, array $data) |
|
| 273 | - { |
|
| 274 | - if (array_key_exists('plugins', $data) |
|
| 275 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 276 | - && 'update' === $data['action'] |
|
| 277 | - && 'plugin' === $data['type'] |
|
| 278 | - ) { |
|
| 279 | - $this->upgrade(); |
|
| 280 | - } |
|
| 281 | - } |
|
| 267 | + /** |
|
| 268 | + * @param mixed $upgrader |
|
| 269 | + * @return void |
|
| 270 | + * @action upgrader_process_complete |
|
| 271 | + */ |
|
| 272 | + public function upgraded($upgrader, array $data) |
|
| 273 | + { |
|
| 274 | + if (array_key_exists('plugins', $data) |
|
| 275 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 276 | + && 'update' === $data['action'] |
|
| 277 | + && 'plugin' === $data['type'] |
|
| 278 | + ) { |
|
| 279 | + $this->upgrade(); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * @param string $path |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - public function url($path = '') |
|
| 288 | - { |
|
| 289 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 290 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 291 | - } |
|
| 283 | + /** |
|
| 284 | + * @param string $path |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + public function url($path = '') |
|
| 288 | + { |
|
| 289 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 290 | + return apply_filters('site-reviews/url', $url, $path); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @param string $versionLevel |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public function version($versionLevel = '') |
|
| 298 | - { |
|
| 299 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
| 300 | - preg_match($pattern, $this->version, $matches); |
|
| 301 | - switch ($versionLevel) { |
|
| 302 | - case 'major': |
|
| 303 | - $version = Arr::get($matches, 1); |
|
| 304 | - break; |
|
| 305 | - case 'minor': |
|
| 306 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 307 | - break; |
|
| 308 | - case 'patch': |
|
| 309 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 310 | - break; |
|
| 311 | - } |
|
| 312 | - return empty($version) |
|
| 313 | - ? $this->version |
|
| 314 | - : $version; |
|
| 315 | - } |
|
| 293 | + /** |
|
| 294 | + * @param string $versionLevel |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public function version($versionLevel = '') |
|
| 298 | + { |
|
| 299 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
| 300 | + preg_match($pattern, $this->version, $matches); |
|
| 301 | + switch ($versionLevel) { |
|
| 302 | + case 'major': |
|
| 303 | + $version = Arr::get($matches, 1); |
|
| 304 | + break; |
|
| 305 | + case 'minor': |
|
| 306 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 307 | + break; |
|
| 308 | + case 'patch': |
|
| 309 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 310 | + break; |
|
| 311 | + } |
|
| 312 | + return empty($version) |
|
| 313 | + ? $this->version |
|
| 314 | + : $version; |
|
| 315 | + } |
|
| 316 | 316 | } |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | public function __construct() |
| 31 | 31 | { |
| 32 | 32 | static::$instance = $this; |
| 33 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
| 34 | - $plugin = get_file_data($this->file, [ |
|
| 33 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
| 34 | + $plugin = get_file_data( $this->file, [ |
|
| 35 | 35 | 'languages' => 'Domain Path', |
| 36 | 36 | 'name' => 'Plugin Name', |
| 37 | 37 | 'version' => 'Version', |
| 38 | - ], 'plugin'); |
|
| 39 | - array_walk($plugin, function ($value, $key) { |
|
| 38 | + ], 'plugin' ); |
|
| 39 | + array_walk( $plugin, function( $value, $key ) { |
|
| 40 | 40 | $this->$key = $value; |
| 41 | 41 | }); |
| 42 | 42 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function activate() |
| 48 | 48 | { |
| 49 | - $this->make(DefaultsManager::class)->set(); |
|
| 49 | + $this->make( DefaultsManager::class )->set(); |
|
| 50 | 50 | $this->scheduleCronJob(); |
| 51 | 51 | $this->upgrade(); |
| 52 | 52 | } |
@@ -57,34 +57,34 @@ discard block |
||
| 57 | 57 | public function catchFatalError() |
| 58 | 58 | { |
| 59 | 59 | $error = error_get_last(); |
| 60 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
| 60 | + if( E_ERROR !== $error['type'] || !Str::contains( $error['message'], $this->path() ) ) { |
|
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | - glsr_log()->error($error['message']); |
|
| 63 | + glsr_log()->error( $error['message'] ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * @param string $name |
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | - public function config($name) |
|
| 70 | + public function config( $name ) |
|
| 71 | 71 | { |
| 72 | - $configFile = $this->path('config/'.$name.'.php'); |
|
| 73 | - $config = file_exists($configFile) |
|
| 72 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
| 73 | + $config = file_exists( $configFile ) |
|
| 74 | 74 | ? include $configFile |
| 75 | 75 | : []; |
| 76 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
| 76 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | 80 | * @param string $property |
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | - public function constant($property, $className = 'static') |
|
| 83 | + public function constant( $property, $className = 'static' ) |
|
| 84 | 84 | { |
| 85 | 85 | $constant = $className.'::'.$property; |
| 86 | - return defined($constant) |
|
| 87 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
| 86 | + return defined( $constant ) |
|
| 87 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
| 88 | 88 | : ''; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | * @param string $view |
| 101 | 101 | * @return void|string |
| 102 | 102 | */ |
| 103 | - public function file($view) |
|
| 103 | + public function file( $view ) |
|
| 104 | 104 | { |
| 105 | - $view.= '.php'; |
|
| 105 | + $view .= '.php'; |
|
| 106 | 106 | $filePaths = []; |
| 107 | - if (Str::startsWith('templates/', $view)) { |
|
| 108 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
| 107 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
| 108 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
| 109 | 109 | } |
| 110 | - $filePaths[] = $this->path($view); |
|
| 111 | - $filePaths[] = $this->path('views/'.$view); |
|
| 112 | - foreach ($filePaths as $file) { |
|
| 113 | - if (!file_exists($file)) { |
|
| 110 | + $filePaths[] = $this->path( $view ); |
|
| 111 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
| 112 | + foreach( $filePaths as $file ) { |
|
| 113 | + if( !file_exists( $file ) ) { |
|
| 114 | 114 | continue; |
| 115 | 115 | } |
| 116 | 116 | return $file; |
@@ -122,33 +122,33 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function getDefaults() |
| 124 | 124 | { |
| 125 | - if (empty($this->defaults)) { |
|
| 126 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
| 125 | + if( empty($this->defaults) ) { |
|
| 126 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
| 127 | 127 | $this->upgrade(); |
| 128 | 128 | } |
| 129 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
| 129 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | - public function getPermission($page = '') |
|
| 135 | + public function getPermission( $page = '' ) |
|
| 136 | 136 | { |
| 137 | 137 | $permissions = [ |
| 138 | 138 | 'addons' => 'install_plugins', |
| 139 | 139 | 'settings' => 'manage_options', |
| 140 | 140 | // 'welcome' => 'activate_plugins', |
| 141 | 141 | ]; |
| 142 | - return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
| 142 | + return Arr::get( $permissions, $page, $this->constant( 'CAPABILITY' ) ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * @return bool |
| 147 | 147 | */ |
| 148 | - public function hasPermission($page = '') |
|
| 148 | + public function hasPermission( $page = '' ) |
|
| 149 | 149 | { |
| 150 | 150 | $isAdmin = $this->isAdmin(); |
| 151 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
| 151 | + return !$isAdmin || ($isAdmin && current_user_can( $this->getPermission( $page ) )); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public function init() |
| 158 | 158 | { |
| 159 | - $this->make(Actions::class)->run(); |
|
| 160 | - $this->make(Filters::class)->run(); |
|
| 159 | + $this->make( Actions::class )->run(); |
|
| 160 | + $this->make( Filters::class )->run(); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @param string $file |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function path($file = '', $realpath = true) |
|
| 175 | + public function path( $file = '', $realpath = true ) |
|
| 176 | 176 | { |
| 177 | - $path = plugin_dir_path($this->file); |
|
| 178 | - if (!$realpath) { |
|
| 179 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
| 177 | + $path = plugin_dir_path( $this->file ); |
|
| 178 | + if( !$realpath ) { |
|
| 179 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
| 180 | 180 | } |
| 181 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
| 182 | - return apply_filters('site-reviews/path', $path, $file); |
|
| 181 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
| 182 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function registerAddons() |
| 189 | 189 | { |
| 190 | - do_action('site-reviews/addon/register', $this); |
|
| 190 | + do_action( 'site-reviews/addon/register', $this ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | public function registerLanguages() |
| 197 | 197 | { |
| 198 | - load_plugin_textdomain(static::ID, false, |
|
| 199 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
| 198 | + load_plugin_textdomain( static::ID, false, |
|
| 199 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -205,26 +205,26 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function registerReviewTypes() |
| 207 | 207 | { |
| 208 | - $types = apply_filters('site-reviews/addon/types', []); |
|
| 209 | - $this->reviewTypes = wp_parse_args($types, [ |
|
| 210 | - 'local' => __('Local', 'site-reviews'), |
|
| 211 | - ]); |
|
| 208 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
| 209 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
| 210 | + 'local' => __( 'Local', 'site-reviews' ), |
|
| 211 | + ] ); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * @param string $view |
| 216 | 216 | * @return void |
| 217 | 217 | */ |
| 218 | - public function render($view, array $data = []) |
|
| 218 | + public function render( $view, array $data = [] ) |
|
| 219 | 219 | { |
| 220 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
| 221 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
| 222 | - if (!file_exists($file)) { |
|
| 223 | - glsr_log()->error('File not found: '.$file); |
|
| 220 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
| 221 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
| 222 | + if( !file_exists( $file ) ) { |
|
| 223 | + glsr_log()->error( 'File not found: '.$file ); |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
| 227 | - extract($data); |
|
| 226 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
| 227 | + extract( $data ); |
|
| 228 | 228 | include $file; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -233,19 +233,19 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | public function scheduleCronJob() |
| 235 | 235 | { |
| 236 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
| 236 | + if( wp_next_scheduled( static::CRON_EVENT ) ) { |
|
| 237 | 237 | return; |
| 238 | 238 | } |
| 239 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
| 239 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | 243 | * @param string $file |
| 244 | 244 | * @return string |
| 245 | 245 | */ |
| 246 | - public function themePath($file = '') |
|
| 246 | + public function themePath( $file = '' ) |
|
| 247 | 247 | { |
| 248 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
| 248 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function unscheduleCronJob() |
| 255 | 255 | { |
| 256 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
| 256 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function upgrade() |
| 263 | 263 | { |
| 264 | - $this->make(Upgrader::class)->run(); |
|
| 264 | + $this->make( Upgrader::class )->run(); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -269,10 +269,10 @@ discard block |
||
| 269 | 269 | * @return void |
| 270 | 270 | * @action upgrader_process_complete |
| 271 | 271 | */ |
| 272 | - public function upgraded($upgrader, array $data) |
|
| 272 | + public function upgraded( $upgrader, array $data ) |
|
| 273 | 273 | { |
| 274 | - if (array_key_exists('plugins', $data) |
|
| 275 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
| 274 | + if( array_key_exists( 'plugins', $data ) |
|
| 275 | + && in_array( plugin_basename( $this->file ), $data['plugins'] ) |
|
| 276 | 276 | && 'update' === $data['action'] |
| 277 | 277 | && 'plugin' === $data['type'] |
| 278 | 278 | ) { |
@@ -284,29 +284,29 @@ discard block |
||
| 284 | 284 | * @param string $path |
| 285 | 285 | * @return string |
| 286 | 286 | */ |
| 287 | - public function url($path = '') |
|
| 287 | + public function url( $path = '' ) |
|
| 288 | 288 | { |
| 289 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
| 290 | - return apply_filters('site-reviews/url', $url, $path); |
|
| 289 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
| 290 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * @param string $versionLevel |
| 295 | 295 | * @return string |
| 296 | 296 | */ |
| 297 | - public function version($versionLevel = '') |
|
| 297 | + public function version( $versionLevel = '' ) |
|
| 298 | 298 | { |
| 299 | 299 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
| 300 | - preg_match($pattern, $this->version, $matches); |
|
| 301 | - switch ($versionLevel) { |
|
| 300 | + preg_match( $pattern, $this->version, $matches ); |
|
| 301 | + switch( $versionLevel ) { |
|
| 302 | 302 | case 'major': |
| 303 | - $version = Arr::get($matches, 1); |
|
| 303 | + $version = Arr::get( $matches, 1 ); |
|
| 304 | 304 | break; |
| 305 | 305 | case 'minor': |
| 306 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
| 306 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
| 307 | 307 | break; |
| 308 | 308 | case 'patch': |
| 309 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
| 309 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
| 310 | 310 | break; |
| 311 | 311 | } |
| 312 | 312 | return empty($version) |
@@ -14,265 +14,265 @@ |
||
| 14 | 14 | |
| 15 | 15 | class ListTableController extends Controller |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @return void |
|
| 19 | - * @action admin_action_approve |
|
| 20 | - */ |
|
| 21 | - public function approve() |
|
| 22 | - { |
|
| 23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
| 27 | - wp_update_post([ |
|
| 28 | - 'ID' => $postId, |
|
| 29 | - 'post_status' => 'publish', |
|
| 30 | - ]); |
|
| 31 | - wp_safe_redirect(wp_get_referer()); |
|
| 32 | - exit; |
|
| 33 | - } |
|
| 17 | + /** |
|
| 18 | + * @return void |
|
| 19 | + * @action admin_action_approve |
|
| 20 | + */ |
|
| 21 | + public function approve() |
|
| 22 | + { |
|
| 23 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
| 27 | + wp_update_post([ |
|
| 28 | + 'ID' => $postId, |
|
| 29 | + 'post_status' => 'publish', |
|
| 30 | + ]); |
|
| 31 | + wp_safe_redirect(wp_get_referer()); |
|
| 32 | + exit; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param array $columns |
|
| 37 | - * @return array |
|
| 38 | - * @filter manage_.Application::POST_TYPE._posts_columns |
|
| 39 | - */ |
|
| 40 | - public function filterColumnsForPostType($columns) |
|
| 41 | - { |
|
| 42 | - $columns = Arr::consolidateArray($columns); |
|
| 43 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 44 | - foreach ($postTypeColumns as $key => &$value) { |
|
| 45 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
| 46 | - continue; |
|
| 47 | - } |
|
| 48 | - $value = $columns[$key]; |
|
| 49 | - } |
|
| 50 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
| 51 | - unset($postTypeColumns['review_type']); |
|
| 52 | - } |
|
| 53 | - return array_filter($postTypeColumns, 'strlen'); |
|
| 54 | - } |
|
| 35 | + /** |
|
| 36 | + * @param array $columns |
|
| 37 | + * @return array |
|
| 38 | + * @filter manage_.Application::POST_TYPE._posts_columns |
|
| 39 | + */ |
|
| 40 | + public function filterColumnsForPostType($columns) |
|
| 41 | + { |
|
| 42 | + $columns = Arr::consolidateArray($columns); |
|
| 43 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 44 | + foreach ($postTypeColumns as $key => &$value) { |
|
| 45 | + if (!array_key_exists($key, $columns) || !empty($value)) { |
|
| 46 | + continue; |
|
| 47 | + } |
|
| 48 | + $value = $columns[$key]; |
|
| 49 | + } |
|
| 50 | + if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
| 51 | + unset($postTypeColumns['review_type']); |
|
| 52 | + } |
|
| 53 | + return array_filter($postTypeColumns, 'strlen'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param string $status |
|
| 58 | - * @param WP_Post $post |
|
| 59 | - * @return string |
|
| 60 | - * @filter post_date_column_status |
|
| 61 | - */ |
|
| 62 | - public function filterDateColumnStatus($status, $post) |
|
| 63 | - { |
|
| 64 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
| 65 | - $status = __('Submitted', 'site-reviews'); |
|
| 66 | - } |
|
| 67 | - return $status; |
|
| 68 | - } |
|
| 56 | + /** |
|
| 57 | + * @param string $status |
|
| 58 | + * @param WP_Post $post |
|
| 59 | + * @return string |
|
| 60 | + * @filter post_date_column_status |
|
| 61 | + */ |
|
| 62 | + public function filterDateColumnStatus($status, $post) |
|
| 63 | + { |
|
| 64 | + if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
| 65 | + $status = __('Submitted', 'site-reviews'); |
|
| 66 | + } |
|
| 67 | + return $status; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @param array $hidden |
|
| 72 | - * @param WP_Screen $post |
|
| 73 | - * @return array |
|
| 74 | - * @filter default_hidden_columns |
|
| 75 | - */ |
|
| 76 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
| 77 | - { |
|
| 78 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
| 79 | - $hidden = Arr::consolidateArray($hidden); |
|
| 80 | - $hidden = array_unique(array_merge($hidden, [ |
|
| 81 | - 'email', 'ip_address', 'response', 'reviewer', |
|
| 82 | - ])); |
|
| 83 | - } |
|
| 84 | - return $hidden; |
|
| 85 | - } |
|
| 70 | + /** |
|
| 71 | + * @param array $hidden |
|
| 72 | + * @param WP_Screen $post |
|
| 73 | + * @return array |
|
| 74 | + * @filter default_hidden_columns |
|
| 75 | + */ |
|
| 76 | + public function filterDefaultHiddenColumns($hidden, $screen) |
|
| 77 | + { |
|
| 78 | + if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
| 79 | + $hidden = Arr::consolidateArray($hidden); |
|
| 80 | + $hidden = array_unique(array_merge($hidden, [ |
|
| 81 | + 'email', 'ip_address', 'response', 'reviewer', |
|
| 82 | + ])); |
|
| 83 | + } |
|
| 84 | + return $hidden; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param array $actions |
|
| 89 | - * @param WP_Post $post |
|
| 90 | - * @return array |
|
| 91 | - * @filter post_row_actions |
|
| 92 | - */ |
|
| 93 | - public function filterRowActions($actions, $post) |
|
| 94 | - { |
|
| 95 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
| 96 | - return $actions; |
|
| 97 | - } |
|
| 98 | - unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
| 99 | - $rowActions = [ |
|
| 100 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
| 101 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
| 102 | - ]; |
|
| 103 | - $newActions = []; |
|
| 104 | - foreach ($rowActions as $key => $text) { |
|
| 105 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
| 106 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
| 107 | - 'class' => 'glsr-change-status', |
|
| 108 | - 'href' => wp_nonce_url( |
|
| 109 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
| 110 | - $key.'-review_'.$post->ID |
|
| 111 | - ), |
|
| 112 | - ]); |
|
| 113 | - } |
|
| 114 | - return $newActions + Arr::consolidateArray($actions); |
|
| 115 | - } |
|
| 87 | + /** |
|
| 88 | + * @param array $actions |
|
| 89 | + * @param WP_Post $post |
|
| 90 | + * @return array |
|
| 91 | + * @filter post_row_actions |
|
| 92 | + */ |
|
| 93 | + public function filterRowActions($actions, $post) |
|
| 94 | + { |
|
| 95 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
| 96 | + return $actions; |
|
| 97 | + } |
|
| 98 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
| 99 | + $rowActions = [ |
|
| 100 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
| 101 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
| 102 | + ]; |
|
| 103 | + $newActions = []; |
|
| 104 | + foreach ($rowActions as $key => $text) { |
|
| 105 | + $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
| 106 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
| 107 | + 'class' => 'glsr-change-status', |
|
| 108 | + 'href' => wp_nonce_url( |
|
| 109 | + admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
| 110 | + $key.'-review_'.$post->ID |
|
| 111 | + ), |
|
| 112 | + ]); |
|
| 113 | + } |
|
| 114 | + return $newActions + Arr::consolidateArray($actions); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param array $columns |
|
| 119 | - * @return array |
|
| 120 | - * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
| 121 | - */ |
|
| 122 | - public function filterSortableColumns($columns) |
|
| 123 | - { |
|
| 124 | - $columns = Arr::consolidateArray($columns); |
|
| 125 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 126 | - unset($postTypeColumns['cb']); |
|
| 127 | - foreach ($postTypeColumns as $key => $value) { |
|
| 128 | - if (Str::startsWith('taxonomy', $key)) { |
|
| 129 | - continue; |
|
| 130 | - } |
|
| 131 | - $columns[$key] = $key; |
|
| 132 | - } |
|
| 133 | - return $columns; |
|
| 134 | - } |
|
| 117 | + /** |
|
| 118 | + * @param array $columns |
|
| 119 | + * @return array |
|
| 120 | + * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
| 121 | + */ |
|
| 122 | + public function filterSortableColumns($columns) |
|
| 123 | + { |
|
| 124 | + $columns = Arr::consolidateArray($columns); |
|
| 125 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 126 | + unset($postTypeColumns['cb']); |
|
| 127 | + foreach ($postTypeColumns as $key => $value) { |
|
| 128 | + if (Str::startsWith('taxonomy', $key)) { |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 131 | + $columns[$key] = $key; |
|
| 132 | + } |
|
| 133 | + return $columns; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @param string $columnName |
|
| 138 | - * @param string $postType |
|
| 139 | - * @return void |
|
| 140 | - * @action bulk_edit_custom_box |
|
| 141 | - */ |
|
| 142 | - public function renderBulkEditFields($columnName, $postType) |
|
| 143 | - { |
|
| 144 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
| 145 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
| 146 | - } |
|
| 147 | - } |
|
| 136 | + /** |
|
| 137 | + * @param string $columnName |
|
| 138 | + * @param string $postType |
|
| 139 | + * @return void |
|
| 140 | + * @action bulk_edit_custom_box |
|
| 141 | + */ |
|
| 142 | + public function renderBulkEditFields($columnName, $postType) |
|
| 143 | + { |
|
| 144 | + if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
| 145 | + glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @param string $postType |
|
| 151 | - * @return void |
|
| 152 | - * @action restrict_manage_posts |
|
| 153 | - */ |
|
| 154 | - public function renderColumnFilters($postType) |
|
| 155 | - { |
|
| 156 | - glsr(Columns::class)->renderFilters($postType); |
|
| 157 | - } |
|
| 149 | + /** |
|
| 150 | + * @param string $postType |
|
| 151 | + * @return void |
|
| 152 | + * @action restrict_manage_posts |
|
| 153 | + */ |
|
| 154 | + public function renderColumnFilters($postType) |
|
| 155 | + { |
|
| 156 | + glsr(Columns::class)->renderFilters($postType); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @param string $column |
|
| 161 | - * @param string $postId |
|
| 162 | - * @return void |
|
| 163 | - * @action manage_posts_custom_column |
|
| 164 | - */ |
|
| 165 | - public function renderColumnValues($column, $postId) |
|
| 166 | - { |
|
| 167 | - glsr(Columns::class)->renderValues($column, $postId); |
|
| 168 | - } |
|
| 159 | + /** |
|
| 160 | + * @param string $column |
|
| 161 | + * @param string $postId |
|
| 162 | + * @return void |
|
| 163 | + * @action manage_posts_custom_column |
|
| 164 | + */ |
|
| 165 | + public function renderColumnValues($column, $postId) |
|
| 166 | + { |
|
| 167 | + glsr(Columns::class)->renderValues($column, $postId); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @param int $postId |
|
| 172 | - * @return void |
|
| 173 | - * @action save_post_.Application::POST_TYPE |
|
| 174 | - */ |
|
| 175 | - public function saveBulkEditFields($postId) |
|
| 176 | - { |
|
| 177 | - if (!current_user_can('edit_posts')) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
| 181 | - if ($assignedTo && get_post($assignedTo)) { |
|
| 182 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
| 183 | - } |
|
| 184 | - } |
|
| 170 | + /** |
|
| 171 | + * @param int $postId |
|
| 172 | + * @return void |
|
| 173 | + * @action save_post_.Application::POST_TYPE |
|
| 174 | + */ |
|
| 175 | + public function saveBulkEditFields($postId) |
|
| 176 | + { |
|
| 177 | + if (!current_user_can('edit_posts')) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
| 181 | + if ($assignedTo && get_post($assignedTo)) { |
|
| 182 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @return void |
|
| 188 | - * @action pre_get_posts |
|
| 189 | - */ |
|
| 190 | - public function setQueryForColumn(WP_Query $query) |
|
| 191 | - { |
|
| 192 | - if (!$this->hasPermission($query)) { |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - $this->setMetaQuery($query, [ |
|
| 196 | - 'rating', 'review_type', |
|
| 197 | - ]); |
|
| 198 | - $this->setOrderby($query); |
|
| 199 | - } |
|
| 186 | + /** |
|
| 187 | + * @return void |
|
| 188 | + * @action pre_get_posts |
|
| 189 | + */ |
|
| 190 | + public function setQueryForColumn(WP_Query $query) |
|
| 191 | + { |
|
| 192 | + if (!$this->hasPermission($query)) { |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + $this->setMetaQuery($query, [ |
|
| 196 | + 'rating', 'review_type', |
|
| 197 | + ]); |
|
| 198 | + $this->setOrderby($query); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * @return void |
|
| 203 | - * @action admin_action_unapprove |
|
| 204 | - */ |
|
| 205 | - public function unapprove() |
|
| 206 | - { |
|
| 207 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 208 | - return; |
|
| 209 | - } |
|
| 210 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
| 211 | - wp_update_post([ |
|
| 212 | - 'ID' => $postId, |
|
| 213 | - 'post_status' => 'pending', |
|
| 214 | - ]); |
|
| 215 | - wp_safe_redirect(wp_get_referer()); |
|
| 216 | - exit; |
|
| 217 | - } |
|
| 201 | + /** |
|
| 202 | + * @return void |
|
| 203 | + * @action admin_action_unapprove |
|
| 204 | + */ |
|
| 205 | + public function unapprove() |
|
| 206 | + { |
|
| 207 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 208 | + return; |
|
| 209 | + } |
|
| 210 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
| 211 | + wp_update_post([ |
|
| 212 | + 'ID' => $postId, |
|
| 213 | + 'post_status' => 'pending', |
|
| 214 | + ]); |
|
| 215 | + wp_safe_redirect(wp_get_referer()); |
|
| 216 | + exit; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Check if the translation string can be modified. |
|
| 221 | - * @param string $domain |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - protected function canModifyTranslation($domain = 'default') |
|
| 225 | - { |
|
| 226 | - $screen = glsr_current_screen(); |
|
| 227 | - return 'default' == $domain |
|
| 228 | - && 'edit' == $screen->base |
|
| 229 | - && Application::POST_TYPE == $screen->post_type; |
|
| 230 | - } |
|
| 219 | + /** |
|
| 220 | + * Check if the translation string can be modified. |
|
| 221 | + * @param string $domain |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + protected function canModifyTranslation($domain = 'default') |
|
| 225 | + { |
|
| 226 | + $screen = glsr_current_screen(); |
|
| 227 | + return 'default' == $domain |
|
| 228 | + && 'edit' == $screen->base |
|
| 229 | + && Application::POST_TYPE == $screen->post_type; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * @return bool |
|
| 234 | - */ |
|
| 235 | - protected function hasPermission(WP_Query $query) |
|
| 236 | - { |
|
| 237 | - global $pagenow; |
|
| 238 | - return is_admin() |
|
| 239 | - && $query->is_main_query() |
|
| 240 | - && Application::POST_TYPE == $query->get('post_type') |
|
| 241 | - && 'edit.php' == $pagenow; |
|
| 242 | - } |
|
| 232 | + /** |
|
| 233 | + * @return bool |
|
| 234 | + */ |
|
| 235 | + protected function hasPermission(WP_Query $query) |
|
| 236 | + { |
|
| 237 | + global $pagenow; |
|
| 238 | + return is_admin() |
|
| 239 | + && $query->is_main_query() |
|
| 240 | + && Application::POST_TYPE == $query->get('post_type') |
|
| 241 | + && 'edit.php' == $pagenow; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
| 248 | - { |
|
| 249 | - foreach ($metaKeys as $key) { |
|
| 250 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
| 251 | - continue; |
|
| 252 | - } |
|
| 253 | - $metaQuery = (array) $query->get('meta_query'); |
|
| 254 | - $metaQuery[] = [ |
|
| 255 | - 'key' => Str::prefix('_', $key, '_'), |
|
| 256 | - 'value' => $value, |
|
| 257 | - ]; |
|
| 258 | - $query->set('meta_query', $metaQuery); |
|
| 259 | - } |
|
| 260 | - } |
|
| 244 | + /** |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
| 248 | + { |
|
| 249 | + foreach ($metaKeys as $key) { |
|
| 250 | + if (!($value = filter_input(INPUT_GET, $key))) { |
|
| 251 | + continue; |
|
| 252 | + } |
|
| 253 | + $metaQuery = (array) $query->get('meta_query'); |
|
| 254 | + $metaQuery[] = [ |
|
| 255 | + 'key' => Str::prefix('_', $key, '_'), |
|
| 256 | + 'value' => $value, |
|
| 257 | + ]; |
|
| 258 | + $query->set('meta_query', $metaQuery); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * @return void |
|
| 264 | - */ |
|
| 265 | - protected function setOrderby(WP_Query $query) |
|
| 266 | - { |
|
| 267 | - $orderby = $query->get('orderby'); |
|
| 268 | - $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 269 | - unset($columns['cb'], $columns['title'], $columns['date']); |
|
| 270 | - if (in_array($orderby, array_keys($columns))) { |
|
| 271 | - if ('reviewer' == $orderby) { |
|
| 272 | - $orderby = 'author'; |
|
| 273 | - } |
|
| 274 | - $query->set('meta_key', Str::prefix('_', $orderby, '_')); |
|
| 275 | - $query->set('orderby', 'meta_value'); |
|
| 276 | - } |
|
| 277 | - } |
|
| 262 | + /** |
|
| 263 | + * @return void |
|
| 264 | + */ |
|
| 265 | + protected function setOrderby(WP_Query $query) |
|
| 266 | + { |
|
| 267 | + $orderby = $query->get('orderby'); |
|
| 268 | + $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
| 269 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
| 270 | + if (in_array($orderby, array_keys($columns))) { |
|
| 271 | + if ('reviewer' == $orderby) { |
|
| 272 | + $orderby = 'author'; |
|
| 273 | + } |
|
| 274 | + $query->set('meta_key', Str::prefix('_', $orderby, '_')); |
|
| 275 | + $query->set('orderby', 'meta_value'); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | 278 | } |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function approve() |
| 22 | 22 | { |
| 23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 23 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
| 27 | - wp_update_post([ |
|
| 26 | + check_admin_referer( 'approve-review_'.($postId = $this->getPostId()) ); |
|
| 27 | + wp_update_post( [ |
|
| 28 | 28 | 'ID' => $postId, |
| 29 | 29 | 'post_status' => 'publish', |
| 30 | - ]); |
|
| 31 | - wp_safe_redirect(wp_get_referer()); |
|
| 30 | + ] ); |
|
| 31 | + wp_safe_redirect( wp_get_referer() ); |
|
| 32 | 32 | exit; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -37,20 +37,20 @@ discard block |
||
| 37 | 37 | * @return array |
| 38 | 38 | * @filter manage_.Application::POST_TYPE._posts_columns |
| 39 | 39 | */ |
| 40 | - public function filterColumnsForPostType($columns) |
|
| 40 | + public function filterColumnsForPostType( $columns ) |
|
| 41 | 41 | { |
| 42 | - $columns = Arr::consolidateArray($columns); |
|
| 42 | + $columns = Arr::consolidateArray( $columns ); |
|
| 43 | 43 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
| 44 | - foreach ($postTypeColumns as $key => &$value) { |
|
| 45 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
| 44 | + foreach( $postTypeColumns as $key => &$value ) { |
|
| 45 | + if( !array_key_exists( $key, $columns ) || !empty($value) ) { |
|
| 46 | 46 | continue; |
| 47 | 47 | } |
| 48 | 48 | $value = $columns[$key]; |
| 49 | 49 | } |
| 50 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
| 50 | + if( count( glsr( Database::class )->getReviewsMeta( 'review_type' ) ) < 2 ) { |
|
| 51 | 51 | unset($postTypeColumns['review_type']); |
| 52 | 52 | } |
| 53 | - return array_filter($postTypeColumns, 'strlen'); |
|
| 53 | + return array_filter( $postTypeColumns, 'strlen' ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | * @filter post_date_column_status |
| 61 | 61 | */ |
| 62 | - public function filterDateColumnStatus($status, $post) |
|
| 62 | + public function filterDateColumnStatus( $status, $post ) |
|
| 63 | 63 | { |
| 64 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
| 65 | - $status = __('Submitted', 'site-reviews'); |
|
| 64 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) ) { |
|
| 65 | + $status = __( 'Submitted', 'site-reviews' ); |
|
| 66 | 66 | } |
| 67 | 67 | return $status; |
| 68 | 68 | } |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | * @return array |
| 74 | 74 | * @filter default_hidden_columns |
| 75 | 75 | */ |
| 76 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
| 76 | + public function filterDefaultHiddenColumns( $hidden, $screen ) |
|
| 77 | 77 | { |
| 78 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
| 79 | - $hidden = Arr::consolidateArray($hidden); |
|
| 80 | - $hidden = array_unique(array_merge($hidden, [ |
|
| 78 | + if( Arr::get( $screen, 'id' ) == 'edit-'.Application::POST_TYPE ) { |
|
| 79 | + $hidden = Arr::consolidateArray( $hidden ); |
|
| 80 | + $hidden = array_unique( array_merge( $hidden, [ |
|
| 81 | 81 | 'email', 'ip_address', 'response', 'reviewer', |
| 82 | - ])); |
|
| 82 | + ] ) ); |
|
| 83 | 83 | } |
| 84 | 84 | return $hidden; |
| 85 | 85 | } |
@@ -90,28 +90,28 @@ discard block |
||
| 90 | 90 | * @return array |
| 91 | 91 | * @filter post_row_actions |
| 92 | 92 | */ |
| 93 | - public function filterRowActions($actions, $post) |
|
| 93 | + public function filterRowActions( $actions, $post ) |
|
| 94 | 94 | { |
| 95 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
| 95 | + if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) || 'trash' == $post->post_status ) { |
|
| 96 | 96 | return $actions; |
| 97 | 97 | } |
| 98 | 98 | unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
| 99 | 99 | $rowActions = [ |
| 100 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
| 101 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
| 100 | + 'approve' => esc_attr__( 'Approve', 'site-reviews' ), |
|
| 101 | + 'unapprove' => esc_attr__( 'Unapprove', 'site-reviews' ), |
|
| 102 | 102 | ]; |
| 103 | 103 | $newActions = []; |
| 104 | - foreach ($rowActions as $key => $text) { |
|
| 105 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
| 106 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
| 104 | + foreach( $rowActions as $key => $text ) { |
|
| 105 | + $newActions[$key] = glsr( Builder::class )->a( $text, [ |
|
| 106 | + 'aria-label' => sprintf( esc_attr_x( '%s this review', 'Approve the review', 'site-reviews' ), $text ), |
|
| 107 | 107 | 'class' => 'glsr-change-status', |
| 108 | 108 | 'href' => wp_nonce_url( |
| 109 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
| 109 | + admin_url( 'post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID ), |
|
| 110 | 110 | $key.'-review_'.$post->ID |
| 111 | 111 | ), |
| 112 | - ]); |
|
| 112 | + ] ); |
|
| 113 | 113 | } |
| 114 | - return $newActions + Arr::consolidateArray($actions); |
|
| 114 | + return $newActions + Arr::consolidateArray( $actions ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @return array |
| 120 | 120 | * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
| 121 | 121 | */ |
| 122 | - public function filterSortableColumns($columns) |
|
| 122 | + public function filterSortableColumns( $columns ) |
|
| 123 | 123 | { |
| 124 | - $columns = Arr::consolidateArray($columns); |
|
| 124 | + $columns = Arr::consolidateArray( $columns ); |
|
| 125 | 125 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
| 126 | 126 | unset($postTypeColumns['cb']); |
| 127 | - foreach ($postTypeColumns as $key => $value) { |
|
| 128 | - if (Str::startsWith('taxonomy', $key)) { |
|
| 127 | + foreach( $postTypeColumns as $key => $value ) { |
|
| 128 | + if( Str::startsWith( 'taxonomy', $key ) ) { |
|
| 129 | 129 | continue; |
| 130 | 130 | } |
| 131 | 131 | $columns[$key] = $key; |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * @return void |
| 140 | 140 | * @action bulk_edit_custom_box |
| 141 | 141 | */ |
| 142 | - public function renderBulkEditFields($columnName, $postType) |
|
| 142 | + public function renderBulkEditFields( $columnName, $postType ) |
|
| 143 | 143 | { |
| 144 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
| 145 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
| 144 | + if( 'assigned_to' == $columnName && Application::POST_TYPE == $postType ) { |
|
| 145 | + glsr()->render( 'partials/editor/bulk-edit-assigned-to' ); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | * @action restrict_manage_posts |
| 153 | 153 | */ |
| 154 | - public function renderColumnFilters($postType) |
|
| 154 | + public function renderColumnFilters( $postType ) |
|
| 155 | 155 | { |
| 156 | - glsr(Columns::class)->renderFilters($postType); |
|
| 156 | + glsr( Columns::class )->renderFilters( $postType ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * @return void |
| 163 | 163 | * @action manage_posts_custom_column |
| 164 | 164 | */ |
| 165 | - public function renderColumnValues($column, $postId) |
|
| 165 | + public function renderColumnValues( $column, $postId ) |
|
| 166 | 166 | { |
| 167 | - glsr(Columns::class)->renderValues($column, $postId); |
|
| 167 | + glsr( Columns::class )->renderValues( $column, $postId ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | * @return void |
| 173 | 173 | * @action save_post_.Application::POST_TYPE |
| 174 | 174 | */ |
| 175 | - public function saveBulkEditFields($postId) |
|
| 175 | + public function saveBulkEditFields( $postId ) |
|
| 176 | 176 | { |
| 177 | - if (!current_user_can('edit_posts')) { |
|
| 177 | + if( !current_user_can( 'edit_posts' ) ) { |
|
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
| 181 | - if ($assignedTo && get_post($assignedTo)) { |
|
| 182 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
| 180 | + $assignedTo = filter_input( INPUT_GET, 'assigned_to' ); |
|
| 181 | + if( $assignedTo && get_post( $assignedTo ) ) { |
|
| 182 | + glsr( Database::class )->update( $postId, 'assigned_to', $assignedTo ); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | * @action pre_get_posts |
| 189 | 189 | */ |
| 190 | - public function setQueryForColumn(WP_Query $query) |
|
| 190 | + public function setQueryForColumn( WP_Query $query ) |
|
| 191 | 191 | { |
| 192 | - if (!$this->hasPermission($query)) { |
|
| 192 | + if( !$this->hasPermission( $query ) ) { |
|
| 193 | 193 | return; |
| 194 | 194 | } |
| 195 | - $this->setMetaQuery($query, [ |
|
| 195 | + $this->setMetaQuery( $query, [ |
|
| 196 | 196 | 'rating', 'review_type', |
| 197 | - ]); |
|
| 198 | - $this->setOrderby($query); |
|
| 197 | + ] ); |
|
| 198 | + $this->setOrderby( $query ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -204,15 +204,15 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function unapprove() |
| 206 | 206 | { |
| 207 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 207 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
| 208 | 208 | return; |
| 209 | 209 | } |
| 210 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
| 211 | - wp_update_post([ |
|
| 210 | + check_admin_referer( 'unapprove-review_'.($postId = $this->getPostId()) ); |
|
| 211 | + wp_update_post( [ |
|
| 212 | 212 | 'ID' => $postId, |
| 213 | 213 | 'post_status' => 'pending', |
| 214 | - ]); |
|
| 215 | - wp_safe_redirect(wp_get_referer()); |
|
| 214 | + ] ); |
|
| 215 | + wp_safe_redirect( wp_get_referer() ); |
|
| 216 | 216 | exit; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | * @param string $domain |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - protected function canModifyTranslation($domain = 'default') |
|
| 224 | + protected function canModifyTranslation( $domain = 'default' ) |
|
| 225 | 225 | { |
| 226 | 226 | $screen = glsr_current_screen(); |
| 227 | 227 | return 'default' == $domain |
@@ -232,47 +232,47 @@ discard block |
||
| 232 | 232 | /** |
| 233 | 233 | * @return bool |
| 234 | 234 | */ |
| 235 | - protected function hasPermission(WP_Query $query) |
|
| 235 | + protected function hasPermission( WP_Query $query ) |
|
| 236 | 236 | { |
| 237 | 237 | global $pagenow; |
| 238 | 238 | return is_admin() |
| 239 | 239 | && $query->is_main_query() |
| 240 | - && Application::POST_TYPE == $query->get('post_type') |
|
| 240 | + && Application::POST_TYPE == $query->get( 'post_type' ) |
|
| 241 | 241 | && 'edit.php' == $pagenow; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | 245 | * @return void |
| 246 | 246 | */ |
| 247 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
| 247 | + protected function setMetaQuery( WP_Query $query, array $metaKeys ) |
|
| 248 | 248 | { |
| 249 | - foreach ($metaKeys as $key) { |
|
| 250 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
| 249 | + foreach( $metaKeys as $key ) { |
|
| 250 | + if( !($value = filter_input( INPUT_GET, $key )) ) { |
|
| 251 | 251 | continue; |
| 252 | 252 | } |
| 253 | - $metaQuery = (array) $query->get('meta_query'); |
|
| 253 | + $metaQuery = (array)$query->get( 'meta_query' ); |
|
| 254 | 254 | $metaQuery[] = [ |
| 255 | - 'key' => Str::prefix('_', $key, '_'), |
|
| 255 | + 'key' => Str::prefix( '_', $key, '_' ), |
|
| 256 | 256 | 'value' => $value, |
| 257 | 257 | ]; |
| 258 | - $query->set('meta_query', $metaQuery); |
|
| 258 | + $query->set( 'meta_query', $metaQuery ); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | - protected function setOrderby(WP_Query $query) |
|
| 265 | + protected function setOrderby( WP_Query $query ) |
|
| 266 | 266 | { |
| 267 | - $orderby = $query->get('orderby'); |
|
| 267 | + $orderby = $query->get( 'orderby' ); |
|
| 268 | 268 | $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
| 269 | 269 | unset($columns['cb'], $columns['title'], $columns['date']); |
| 270 | - if (in_array($orderby, array_keys($columns))) { |
|
| 271 | - if ('reviewer' == $orderby) { |
|
| 270 | + if( in_array( $orderby, array_keys( $columns ) ) ) { |
|
| 271 | + if( 'reviewer' == $orderby ) { |
|
| 272 | 272 | $orderby = 'author'; |
| 273 | 273 | } |
| 274 | - $query->set('meta_key', Str::prefix('_', $orderby, '_')); |
|
| 275 | - $query->set('orderby', 'meta_value'); |
|
| 274 | + $query->set( 'meta_key', Str::prefix( '_', $orderby, '_' ) ); |
|
| 275 | + $query->set( 'orderby', 'meta_value' ); |
|
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | } |
@@ -7,106 +7,106 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Labels |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @param string $translation |
|
| 12 | - * @param string $test |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public function filterPostStatusLabels($translation, $text) |
|
| 16 | - { |
|
| 17 | - $replacements = $this->getStatusLabels(); |
|
| 18 | - return array_key_exists($text, $replacements) |
|
| 19 | - ? $replacements[$text] |
|
| 20 | - : $translation; |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * @param string $translation |
|
| 12 | + * @param string $test |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public function filterPostStatusLabels($translation, $text) |
|
| 16 | + { |
|
| 17 | + $replacements = $this->getStatusLabels(); |
|
| 18 | + return array_key_exists($text, $replacements) |
|
| 19 | + ? $replacements[$text] |
|
| 20 | + : $translation; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return array |
|
| 25 | - */ |
|
| 26 | - public function filterUpdateMessages(array $messages) |
|
| 27 | - { |
|
| 28 | - $post = get_post(); |
|
| 29 | - if (!($post instanceof WP_Post)) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 32 | - $strings = $this->getReviewLabels(); |
|
| 33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 36 | - } |
|
| 37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 38 | - $messages[Application::POST_TYPE] = [ |
|
| 39 | - 1 => $strings['updated'], |
|
| 40 | - 4 => $strings['updated'], |
|
| 41 | - 5 => $restored, |
|
| 42 | - 6 => $strings['published'], |
|
| 43 | - 7 => $strings['saved'], |
|
| 44 | - 8 => $strings['submitted'], |
|
| 45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 46 | - 10 => $strings['draft_updated'], |
|
| 47 | - 50 => $strings['approved'], |
|
| 48 | - 51 => $strings['unapproved'], |
|
| 49 | - 52 => $strings['reverted'], |
|
| 50 | - ]; |
|
| 51 | - return $messages; |
|
| 52 | - } |
|
| 23 | + /** |
|
| 24 | + * @return array |
|
| 25 | + */ |
|
| 26 | + public function filterUpdateMessages(array $messages) |
|
| 27 | + { |
|
| 28 | + $post = get_post(); |
|
| 29 | + if (!($post instanceof WP_Post)) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + $strings = $this->getReviewLabels(); |
|
| 33 | + $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | + if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | + $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 36 | + } |
|
| 37 | + $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 38 | + $messages[Application::POST_TYPE] = [ |
|
| 39 | + 1 => $strings['updated'], |
|
| 40 | + 4 => $strings['updated'], |
|
| 41 | + 5 => $restored, |
|
| 42 | + 6 => $strings['published'], |
|
| 43 | + 7 => $strings['saved'], |
|
| 44 | + 8 => $strings['submitted'], |
|
| 45 | + 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 46 | + 10 => $strings['draft_updated'], |
|
| 47 | + 50 => $strings['approved'], |
|
| 48 | + 51 => $strings['unapproved'], |
|
| 49 | + 52 => $strings['reverted'], |
|
| 50 | + ]; |
|
| 51 | + return $messages; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function translatePostStatusLabels() |
|
| 58 | - { |
|
| 59 | - global $wp_scripts; |
|
| 60 | - $strings = [ |
|
| 61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | - 'published' => __('Approved', 'site-reviews'), |
|
| 63 | - ]; |
|
| 64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 65 | - $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
| 66 | - foreach ($strings as $search => $replace) { |
|
| 67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 54 | + /** |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function translatePostStatusLabels() |
|
| 58 | + { |
|
| 59 | + global $wp_scripts; |
|
| 60 | + $strings = [ |
|
| 61 | + 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | + 'published' => __('Approved', 'site-reviews'), |
|
| 63 | + ]; |
|
| 64 | + if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 65 | + $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
| 66 | + foreach ($strings as $search => $replace) { |
|
| 67 | + $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function getReviewLabels() |
|
| 76 | - { |
|
| 77 | - return [ |
|
| 78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | - 'view' => __('View review', 'site-reviews'), |
|
| 90 | - ]; |
|
| 91 | - } |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function getReviewLabels() |
|
| 76 | + { |
|
| 77 | + return [ |
|
| 78 | + 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | + 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | + 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | + 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | + 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | + 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | + 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | + 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | + 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | + 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | + 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | + 'view' => __('View review', 'site-reviews'), |
|
| 90 | + ]; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Store the labels to avoid unnecessary loops. |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - protected function getStatusLabels() |
|
| 98 | - { |
|
| 99 | - static $labels; |
|
| 100 | - if (empty($labels)) { |
|
| 101 | - $labels = [ |
|
| 102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 108 | - ]; |
|
| 109 | - } |
|
| 110 | - return $labels; |
|
| 111 | - } |
|
| 93 | + /** |
|
| 94 | + * Store the labels to avoid unnecessary loops. |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + protected function getStatusLabels() |
|
| 98 | + { |
|
| 99 | + static $labels; |
|
| 100 | + if (empty($labels)) { |
|
| 101 | + $labels = [ |
|
| 102 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | + 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | + 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | + 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | + 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | + 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 108 | + ]; |
|
| 109 | + } |
|
| 110 | + return $labels; |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | * @param string $test |
| 13 | 13 | * @return string |
| 14 | 14 | */ |
| 15 | - public function filterPostStatusLabels($translation, $text) |
|
| 15 | + public function filterPostStatusLabels( $translation, $text ) |
|
| 16 | 16 | { |
| 17 | 17 | $replacements = $this->getStatusLabels(); |
| 18 | - return array_key_exists($text, $replacements) |
|
| 18 | + return array_key_exists( $text, $replacements ) |
|
| 19 | 19 | ? $replacements[$text] |
| 20 | 20 | : $translation; |
| 21 | 21 | } |
@@ -23,18 +23,18 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * @return array |
| 25 | 25 | */ |
| 26 | - public function filterUpdateMessages(array $messages) |
|
| 26 | + public function filterUpdateMessages( array $messages ) |
|
| 27 | 27 | { |
| 28 | 28 | $post = get_post(); |
| 29 | - if (!($post instanceof WP_Post)) { |
|
| 29 | + if( !($post instanceof WP_Post) ) { |
|
| 30 | 30 | return; |
| 31 | 31 | } |
| 32 | 32 | $strings = $this->getReviewLabels(); |
| 33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
| 34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
| 35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
| 33 | + $restored = filter_input( INPUT_GET, 'revision' ); |
|
| 34 | + if( $revisionTitle = wp_post_revision_title( intval( $restored ), false ) ) { |
|
| 35 | + $restored = sprintf( $strings['restored'], $revisionTitle ); |
|
| 36 | 36 | } |
| 37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
| 37 | + $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date ) ); |
|
| 38 | 38 | $messages[Application::POST_TYPE] = [ |
| 39 | 39 | 1 => $strings['updated'], |
| 40 | 40 | 4 => $strings['updated'], |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | 6 => $strings['published'], |
| 43 | 43 | 7 => $strings['saved'], |
| 44 | 44 | 8 => $strings['submitted'], |
| 45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
| 45 | + 9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ), |
|
| 46 | 46 | 10 => $strings['draft_updated'], |
| 47 | 47 | 50 => $strings['approved'], |
| 48 | 48 | 51 => $strings['unapproved'], |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | global $wp_scripts; |
| 60 | 60 | $strings = [ |
| 61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
| 62 | - 'published' => __('Approved', 'site-reviews'), |
|
| 61 | + 'savePending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
| 62 | + 'published' => __( 'Approved', 'site-reviews' ), |
|
| 63 | 63 | ]; |
| 64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
| 64 | + if( isset($wp_scripts->registered['post']->extra['data']) ) { |
|
| 65 | 65 | $l10n = &$wp_scripts->registered['post']->extra['data']; |
| 66 | - foreach ($strings as $search => $replace) { |
|
| 67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n); |
|
| 66 | + foreach( $strings as $search => $replace ) { |
|
| 67 | + $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n ); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -75,18 +75,18 @@ discard block |
||
| 75 | 75 | protected function getReviewLabels() |
| 76 | 76 | { |
| 77 | 77 | return [ |
| 78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
| 79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
| 80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
| 81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
| 82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
| 83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
| 84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
| 85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
| 86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
| 87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
| 88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
| 89 | - 'view' => __('View review', 'site-reviews'), |
|
| 78 | + 'approved' => __( 'Review has been approved and published.', 'site-reviews' ), |
|
| 79 | + 'draft_updated' => __( 'Review draft updated.', 'site-reviews' ), |
|
| 80 | + 'preview' => __( 'Preview review', 'site-reviews' ), |
|
| 81 | + 'published' => __( 'Review approved and published.', 'site-reviews' ), |
|
| 82 | + 'restored' => __( 'Review restored to revision from %s.', 'site-reviews' ), |
|
| 83 | + 'reverted' => __( 'Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews' ), |
|
| 84 | + 'saved' => __( 'Review saved.', 'site-reviews' ), |
|
| 85 | + 'scheduled' => __( 'Review scheduled for: %s.', 'site-reviews' ), |
|
| 86 | + 'submitted' => __( 'Review submitted.', 'site-reviews' ), |
|
| 87 | + 'unapproved' => __( 'Review has been unapproved and is now pending.', 'site-reviews' ), |
|
| 88 | + 'updated' => __( 'Review updated.', 'site-reviews' ), |
|
| 89 | + 'view' => __( 'View review', 'site-reviews' ), |
|
| 90 | 90 | ]; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | protected function getStatusLabels() |
| 98 | 98 | { |
| 99 | 99 | static $labels; |
| 100 | - if (empty($labels)) { |
|
| 100 | + if( empty($labels) ) { |
|
| 101 | 101 | $labels = [ |
| 102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
| 103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
| 104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
| 105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
| 106 | - 'Published' => __('Approved', 'site-reviews'), |
|
| 107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
| 102 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
| 103 | + 'Pending Review' => __( 'Unapproved', 'site-reviews' ), |
|
| 104 | + 'Privately Published' => __( 'Privately Approved', 'site-reviews' ), |
|
| 105 | + 'Publish' => __( 'Approve', 'site-reviews' ), |
|
| 106 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
| 107 | + 'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
| 108 | 108 | ]; |
| 109 | 109 | } |
| 110 | 110 | return $labels; |
@@ -20,401 +20,401 @@ |
||
| 20 | 20 | |
| 21 | 21 | class EditorController extends Controller |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @param array $settings |
|
| 25 | - * @return array |
|
| 26 | - * @filter wp_editor_settings |
|
| 27 | - */ |
|
| 28 | - public function filterEditorSettings($settings) |
|
| 29 | - { |
|
| 30 | - return glsr(Customization::class)->filterEditorSettings( |
|
| 31 | - Arr::consolidateArray($settings) |
|
| 32 | - ); |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * @param array $settings |
|
| 25 | + * @return array |
|
| 26 | + * @filter wp_editor_settings |
|
| 27 | + */ |
|
| 28 | + public function filterEditorSettings($settings) |
|
| 29 | + { |
|
| 30 | + return glsr(Customization::class)->filterEditorSettings( |
|
| 31 | + Arr::consolidateArray($settings) |
|
| 32 | + ); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
| 37 | - * @param string $html |
|
| 38 | - * @return string |
|
| 39 | - * @filter the_editor |
|
| 40 | - */ |
|
| 41 | - public function filterEditorTextarea($html) |
|
| 42 | - { |
|
| 43 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
| 37 | + * @param string $html |
|
| 38 | + * @return string |
|
| 39 | + * @filter the_editor |
|
| 40 | + */ |
|
| 41 | + public function filterEditorTextarea($html) |
|
| 42 | + { |
|
| 43 | + return glsr(Customization::class)->filterEditorTextarea($html); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param bool $protected |
|
| 48 | - * @param string $metaKey |
|
| 49 | - * @param string $metaType |
|
| 50 | - * @return bool |
|
| 51 | - * @filter is_protected_meta |
|
| 52 | - */ |
|
| 53 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
| 54 | - { |
|
| 55 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
| 56 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
| 57 | - $values = Arr::prefixArrayKeys($values); |
|
| 58 | - if (array_key_exists($metaKey, $values)) { |
|
| 59 | - $protected = false; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - return $protected; |
|
| 63 | - } |
|
| 46 | + /** |
|
| 47 | + * @param bool $protected |
|
| 48 | + * @param string $metaKey |
|
| 49 | + * @param string $metaType |
|
| 50 | + * @return bool |
|
| 51 | + * @filter is_protected_meta |
|
| 52 | + */ |
|
| 53 | + public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
| 54 | + { |
|
| 55 | + if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
| 56 | + $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
| 57 | + $values = Arr::prefixArrayKeys($values); |
|
| 58 | + if (array_key_exists($metaKey, $values)) { |
|
| 59 | + $protected = false; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + return $protected; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param array $messages |
|
| 67 | - * @return array |
|
| 68 | - * @filter post_updated_messages |
|
| 69 | - */ |
|
| 70 | - public function filterUpdateMessages($messages) |
|
| 71 | - { |
|
| 72 | - return glsr(Labels::class)->filterUpdateMessages( |
|
| 73 | - Arr::consolidateArray($messages) |
|
| 74 | - ); |
|
| 75 | - } |
|
| 65 | + /** |
|
| 66 | + * @param array $messages |
|
| 67 | + * @return array |
|
| 68 | + * @filter post_updated_messages |
|
| 69 | + */ |
|
| 70 | + public function filterUpdateMessages($messages) |
|
| 71 | + { |
|
| 72 | + return glsr(Labels::class)->filterUpdateMessages( |
|
| 73 | + Arr::consolidateArray($messages) |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return void |
|
| 79 | - * @action add_meta_boxes_{Application::POST_TYPE} |
|
| 80 | - */ |
|
| 81 | - public function registerMetaBoxes($post) |
|
| 82 | - { |
|
| 83 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
| 84 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
| 85 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
| 89 | - } |
|
| 77 | + /** |
|
| 78 | + * @return void |
|
| 79 | + * @action add_meta_boxes_{Application::POST_TYPE} |
|
| 80 | + */ |
|
| 81 | + public function registerMetaBoxes($post) |
|
| 82 | + { |
|
| 83 | + add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
| 84 | + add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
| 85 | + if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - * @action admin_print_scripts |
|
| 94 | - */ |
|
| 95 | - public function removeAutosave() |
|
| 96 | - { |
|
| 97 | - glsr(Customization::class)->removeAutosave(); |
|
| 98 | - } |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + * @action admin_print_scripts |
|
| 94 | + */ |
|
| 95 | + public function removeAutosave() |
|
| 96 | + { |
|
| 97 | + glsr(Customization::class)->removeAutosave(); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return void |
|
| 102 | - * @action admin_menu |
|
| 103 | - */ |
|
| 104 | - public function removeMetaBoxes() |
|
| 105 | - { |
|
| 106 | - glsr(Customization::class)->removeMetaBoxes(); |
|
| 107 | - } |
|
| 100 | + /** |
|
| 101 | + * @return void |
|
| 102 | + * @action admin_menu |
|
| 103 | + */ |
|
| 104 | + public function removeMetaBoxes() |
|
| 105 | + { |
|
| 106 | + glsr(Customization::class)->removeMetaBoxes(); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function removePostTypeSupport() |
|
| 113 | - { |
|
| 114 | - glsr(Customization::class)->removePostTypeSupport(); |
|
| 115 | - } |
|
| 109 | + /** |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function removePostTypeSupport() |
|
| 113 | + { |
|
| 114 | + glsr(Customization::class)->removePostTypeSupport(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param WP_Post $post |
|
| 119 | - * @return void |
|
| 120 | - * @callback add_meta_box |
|
| 121 | - */ |
|
| 122 | - public function renderAssignedToMetabox($post) |
|
| 123 | - { |
|
| 124 | - if (!$this->isReviewPostType($post)) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
| 128 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
| 129 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
| 130 | - 'id' => $assignedTo, |
|
| 131 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
| 132 | - ]); |
|
| 133 | - } |
|
| 117 | + /** |
|
| 118 | + * @param WP_Post $post |
|
| 119 | + * @return void |
|
| 120 | + * @callback add_meta_box |
|
| 121 | + */ |
|
| 122 | + public function renderAssignedToMetabox($post) |
|
| 123 | + { |
|
| 124 | + if (!$this->isReviewPostType($post)) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
| 128 | + wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
| 129 | + glsr()->render('partials/editor/metabox-assigned-to', [ |
|
| 130 | + 'id' => $assignedTo, |
|
| 131 | + 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
| 132 | + ]); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param WP_Post $post |
|
| 137 | - * @return void |
|
| 138 | - * @callback add_meta_box |
|
| 139 | - */ |
|
| 140 | - public function renderDetailsMetaBox($post) |
|
| 141 | - { |
|
| 142 | - if (!$this->isReviewPostType($post)) { |
|
| 143 | - return; |
|
| 144 | - } |
|
| 145 | - $review = glsr_get_review($post); |
|
| 146 | - glsr()->render('partials/editor/metabox-details', [ |
|
| 147 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
| 148 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
| 149 | - ]); |
|
| 150 | - } |
|
| 135 | + /** |
|
| 136 | + * @param WP_Post $post |
|
| 137 | + * @return void |
|
| 138 | + * @callback add_meta_box |
|
| 139 | + */ |
|
| 140 | + public function renderDetailsMetaBox($post) |
|
| 141 | + { |
|
| 142 | + if (!$this->isReviewPostType($post)) { |
|
| 143 | + return; |
|
| 144 | + } |
|
| 145 | + $review = glsr_get_review($post); |
|
| 146 | + glsr()->render('partials/editor/metabox-details', [ |
|
| 147 | + 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
| 148 | + 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
| 149 | + ]); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * @return void |
|
| 154 | - * @action post_submitbox_misc_actions |
|
| 155 | - */ |
|
| 156 | - public function renderPinnedInPublishMetaBox() |
|
| 157 | - { |
|
| 158 | - if (!$this->isReviewPostType(get_post())) { |
|
| 159 | - return; |
|
| 160 | - } |
|
| 161 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
| 162 | - 'context' => [ |
|
| 163 | - 'no' => __('No', 'site-reviews'), |
|
| 164 | - 'yes' => __('Yes', 'site-reviews'), |
|
| 165 | - ], |
|
| 166 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
| 167 | - ]); |
|
| 168 | - } |
|
| 152 | + /** |
|
| 153 | + * @return void |
|
| 154 | + * @action post_submitbox_misc_actions |
|
| 155 | + */ |
|
| 156 | + public function renderPinnedInPublishMetaBox() |
|
| 157 | + { |
|
| 158 | + if (!$this->isReviewPostType(get_post())) { |
|
| 159 | + return; |
|
| 160 | + } |
|
| 161 | + glsr(Template::class)->render('partials/editor/pinned', [ |
|
| 162 | + 'context' => [ |
|
| 163 | + 'no' => __('No', 'site-reviews'), |
|
| 164 | + 'yes' => __('Yes', 'site-reviews'), |
|
| 165 | + ], |
|
| 166 | + 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
| 167 | + ]); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @param WP_Post $post |
|
| 172 | - * @return void |
|
| 173 | - * @callback add_meta_box |
|
| 174 | - */ |
|
| 175 | - public function renderResponseMetaBox($post) |
|
| 176 | - { |
|
| 177 | - if (!$this->isReviewPostType($post)) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - wp_nonce_field('response', '_nonce-response', false); |
|
| 181 | - glsr()->render('partials/editor/metabox-response', [ |
|
| 182 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 183 | - ]); |
|
| 184 | - } |
|
| 170 | + /** |
|
| 171 | + * @param WP_Post $post |
|
| 172 | + * @return void |
|
| 173 | + * @callback add_meta_box |
|
| 174 | + */ |
|
| 175 | + public function renderResponseMetaBox($post) |
|
| 176 | + { |
|
| 177 | + if (!$this->isReviewPostType($post)) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + wp_nonce_field('response', '_nonce-response', false); |
|
| 181 | + glsr()->render('partials/editor/metabox-response', [ |
|
| 182 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 183 | + ]); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @param WP_Post $post |
|
| 188 | - * @return void |
|
| 189 | - * @action edit_form_after_title |
|
| 190 | - */ |
|
| 191 | - public function renderReviewEditor($post) |
|
| 192 | - { |
|
| 193 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 194 | - return; |
|
| 195 | - } |
|
| 196 | - glsr()->render('partials/editor/review', [ |
|
| 197 | - 'post' => $post, |
|
| 198 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 199 | - ]); |
|
| 200 | - } |
|
| 186 | + /** |
|
| 187 | + * @param WP_Post $post |
|
| 188 | + * @return void |
|
| 189 | + * @action edit_form_after_title |
|
| 190 | + */ |
|
| 191 | + public function renderReviewEditor($post) |
|
| 192 | + { |
|
| 193 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 194 | + return; |
|
| 195 | + } |
|
| 196 | + glsr()->render('partials/editor/review', [ |
|
| 197 | + 'post' => $post, |
|
| 198 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 199 | + ]); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * @return void |
|
| 204 | - * @action admin_head |
|
| 205 | - */ |
|
| 206 | - public function renderReviewFields() |
|
| 207 | - { |
|
| 208 | - $screen = glsr_current_screen(); |
|
| 209 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
| 213 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
| 214 | - } |
|
| 202 | + /** |
|
| 203 | + * @return void |
|
| 204 | + * @action admin_head |
|
| 205 | + */ |
|
| 206 | + public function renderReviewFields() |
|
| 207 | + { |
|
| 208 | + $screen = glsr_current_screen(); |
|
| 209 | + if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
| 210 | + return; |
|
| 211 | + } |
|
| 212 | + add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
| 213 | + add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * @param WP_Post $post |
|
| 218 | - * @return void |
|
| 219 | - * @action edit_form_top |
|
| 220 | - */ |
|
| 221 | - public function renderReviewNotice($post) |
|
| 222 | - { |
|
| 223 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 224 | - return; |
|
| 225 | - } |
|
| 226 | - glsr(Notice::class)->addWarning(sprintf( |
|
| 227 | - __('%s reviews are read-only.', 'site-reviews'), |
|
| 228 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
| 229 | - )); |
|
| 230 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
| 231 | - 'context' => [ |
|
| 232 | - 'notices' => glsr(Notice::class)->get(), |
|
| 233 | - ], |
|
| 234 | - ]); |
|
| 235 | - } |
|
| 216 | + /** |
|
| 217 | + * @param WP_Post $post |
|
| 218 | + * @return void |
|
| 219 | + * @action edit_form_top |
|
| 220 | + */ |
|
| 221 | + public function renderReviewNotice($post) |
|
| 222 | + { |
|
| 223 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | + glsr(Notice::class)->addWarning(sprintf( |
|
| 227 | + __('%s reviews are read-only.', 'site-reviews'), |
|
| 228 | + glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
| 229 | + )); |
|
| 230 | + glsr(Template::class)->render('partials/editor/notice', [ |
|
| 231 | + 'context' => [ |
|
| 232 | + 'notices' => glsr(Notice::class)->get(), |
|
| 233 | + ], |
|
| 234 | + ]); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @param WP_Post $post |
|
| 239 | - * @return void |
|
| 240 | - * @see glsr_categories_meta_box() |
|
| 241 | - * @callback register_taxonomy |
|
| 242 | - */ |
|
| 243 | - public function renderTaxonomyMetabox($post) |
|
| 244 | - { |
|
| 245 | - if (!$this->isReviewPostType($post)) { |
|
| 246 | - return; |
|
| 247 | - } |
|
| 248 | - glsr()->render('partials/editor/metabox-categories', [ |
|
| 249 | - 'post' => $post, |
|
| 250 | - 'tax_name' => Application::TAXONOMY, |
|
| 251 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
| 252 | - ]); |
|
| 253 | - } |
|
| 237 | + /** |
|
| 238 | + * @param WP_Post $post |
|
| 239 | + * @return void |
|
| 240 | + * @see glsr_categories_meta_box() |
|
| 241 | + * @callback register_taxonomy |
|
| 242 | + */ |
|
| 243 | + public function renderTaxonomyMetabox($post) |
|
| 244 | + { |
|
| 245 | + if (!$this->isReviewPostType($post)) { |
|
| 246 | + return; |
|
| 247 | + } |
|
| 248 | + glsr()->render('partials/editor/metabox-categories', [ |
|
| 249 | + 'post' => $post, |
|
| 250 | + 'tax_name' => Application::TAXONOMY, |
|
| 251 | + 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
| 252 | + ]); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @return void |
|
| 257 | - * @see $this->filterUpdateMessages() |
|
| 258 | - * @action admin_action_revert |
|
| 259 | - */ |
|
| 260 | - public function revertReview() |
|
| 261 | - { |
|
| 262 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
| 266 | - glsr(ReviewManager::class)->revert($postId); |
|
| 267 | - $this->redirect($postId, 52); |
|
| 268 | - } |
|
| 255 | + /** |
|
| 256 | + * @return void |
|
| 257 | + * @see $this->filterUpdateMessages() |
|
| 258 | + * @action admin_action_revert |
|
| 259 | + */ |
|
| 260 | + public function revertReview() |
|
| 261 | + { |
|
| 262 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
| 266 | + glsr(ReviewManager::class)->revert($postId); |
|
| 267 | + $this->redirect($postId, 52); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * @param int $postId |
|
| 272 | - * @param \WP_Post $post |
|
| 273 | - * @param bool $isUpdate |
|
| 274 | - * @return void |
|
| 275 | - * @action save_post_.Application::POST_TYPE |
|
| 276 | - */ |
|
| 277 | - public function saveMetaboxes($postId, $post, $isUpdating) |
|
| 278 | - { |
|
| 279 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
| 280 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
| 281 | - if ($isUpdating) { |
|
| 282 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
| 283 | - } |
|
| 284 | - } |
|
| 270 | + /** |
|
| 271 | + * @param int $postId |
|
| 272 | + * @param \WP_Post $post |
|
| 273 | + * @param bool $isUpdate |
|
| 274 | + * @return void |
|
| 275 | + * @action save_post_.Application::POST_TYPE |
|
| 276 | + */ |
|
| 277 | + public function saveMetaboxes($postId, $post, $isUpdating) |
|
| 278 | + { |
|
| 279 | + glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
| 280 | + glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
| 281 | + if ($isUpdating) { |
|
| 282 | + do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * @param string $assignedTo |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
| 291 | - { |
|
| 292 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
| 293 | - if (!($assignedPost instanceof WP_Post)) { |
|
| 294 | - return; |
|
| 295 | - } |
|
| 296 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
| 297 | - 'context' => [ |
|
| 298 | - 'data.url' => (string) get_permalink($assignedPost), |
|
| 299 | - 'data.title' => get_the_title($assignedPost), |
|
| 300 | - ], |
|
| 301 | - ]); |
|
| 302 | - } |
|
| 286 | + /** |
|
| 287 | + * @param string $assignedTo |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
| 291 | + { |
|
| 292 | + $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
| 293 | + if (!($assignedPost instanceof WP_Post)) { |
|
| 294 | + return; |
|
| 295 | + } |
|
| 296 | + return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
| 297 | + 'context' => [ |
|
| 298 | + 'data.url' => (string) get_permalink($assignedPost), |
|
| 299 | + 'data.title' => get_the_title($assignedPost), |
|
| 300 | + ], |
|
| 301 | + ]); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 307 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
| 308 | - { |
|
| 309 | - $isModified = !Arr::compareArrays( |
|
| 310 | - [$review->title, $review->content, $review->date], |
|
| 311 | - [ |
|
| 312 | - glsr(Database::class)->get($post->ID, 'title'), |
|
| 313 | - glsr(Database::class)->get($post->ID, 'content'), |
|
| 314 | - glsr(Database::class)->get($post->ID, 'date'), |
|
| 315 | - ] |
|
| 316 | - ); |
|
| 317 | - if ($isModified) { |
|
| 318 | - $revertUrl = wp_nonce_url( |
|
| 319 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
| 320 | - 'revert-review_'.$post->ID |
|
| 321 | - ); |
|
| 322 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
| 323 | - 'class' => 'button button-large', |
|
| 324 | - 'href' => $revertUrl, |
|
| 325 | - 'id' => 'revert', |
|
| 326 | - ]); |
|
| 327 | - } |
|
| 328 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
| 329 | - 'class' => 'button-large', |
|
| 330 | - 'disabled' => true, |
|
| 331 | - 'id' => 'revert', |
|
| 332 | - ]); |
|
| 333 | - } |
|
| 304 | + /** |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | + protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
| 308 | + { |
|
| 309 | + $isModified = !Arr::compareArrays( |
|
| 310 | + [$review->title, $review->content, $review->date], |
|
| 311 | + [ |
|
| 312 | + glsr(Database::class)->get($post->ID, 'title'), |
|
| 313 | + glsr(Database::class)->get($post->ID, 'content'), |
|
| 314 | + glsr(Database::class)->get($post->ID, 'date'), |
|
| 315 | + ] |
|
| 316 | + ); |
|
| 317 | + if ($isModified) { |
|
| 318 | + $revertUrl = wp_nonce_url( |
|
| 319 | + admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
| 320 | + 'revert-review_'.$post->ID |
|
| 321 | + ); |
|
| 322 | + return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
| 323 | + 'class' => 'button button-large', |
|
| 324 | + 'href' => $revertUrl, |
|
| 325 | + 'id' => 'revert', |
|
| 326 | + ]); |
|
| 327 | + } |
|
| 328 | + return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
| 329 | + 'class' => 'button-large', |
|
| 330 | + 'disabled' => true, |
|
| 331 | + 'id' => 'revert', |
|
| 332 | + ]); |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * @param object $review |
|
| 337 | - * @return string|void |
|
| 338 | - */ |
|
| 339 | - protected function getReviewType($review) |
|
| 340 | - { |
|
| 341 | - if (count(glsr()->reviewTypes) < 2) { |
|
| 342 | - return; |
|
| 343 | - } |
|
| 344 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
| 345 | - ? glsr()->reviewTypes[$review->review_type] |
|
| 346 | - : __('Unknown', 'site-reviews'); |
|
| 347 | - if (!empty($review->url)) { |
|
| 348 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
| 349 | - 'href' => $review->url, |
|
| 350 | - 'target' => '_blank', |
|
| 351 | - ]); |
|
| 352 | - } |
|
| 353 | - return $reviewType; |
|
| 354 | - } |
|
| 335 | + /** |
|
| 336 | + * @param object $review |
|
| 337 | + * @return string|void |
|
| 338 | + */ |
|
| 339 | + protected function getReviewType($review) |
|
| 340 | + { |
|
| 341 | + if (count(glsr()->reviewTypes) < 2) { |
|
| 342 | + return; |
|
| 343 | + } |
|
| 344 | + $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
| 345 | + ? glsr()->reviewTypes[$review->review_type] |
|
| 346 | + : __('Unknown', 'site-reviews'); |
|
| 347 | + if (!empty($review->url)) { |
|
| 348 | + $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
| 349 | + 'href' => $review->url, |
|
| 350 | + 'target' => '_blank', |
|
| 351 | + ]); |
|
| 352 | + } |
|
| 353 | + return $reviewType; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * @return bool |
|
| 358 | - */ |
|
| 359 | - protected function isReviewEditable($post) |
|
| 360 | - { |
|
| 361 | - return $this->isReviewPostType($post) |
|
| 362 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
| 363 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
| 364 | - } |
|
| 356 | + /** |
|
| 357 | + * @return bool |
|
| 358 | + */ |
|
| 359 | + protected function isReviewEditable($post) |
|
| 360 | + { |
|
| 361 | + return $this->isReviewPostType($post) |
|
| 362 | + && post_type_supports(Application::POST_TYPE, 'title') |
|
| 363 | + && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * @param mixed $post |
|
| 368 | - * @return bool |
|
| 369 | - */ |
|
| 370 | - protected function isReviewPostType($post) |
|
| 371 | - { |
|
| 372 | - return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
| 373 | - } |
|
| 366 | + /** |
|
| 367 | + * @param mixed $post |
|
| 368 | + * @return bool |
|
| 369 | + */ |
|
| 370 | + protected function isReviewPostType($post) |
|
| 371 | + { |
|
| 372 | + return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * @return array |
|
| 377 | - */ |
|
| 378 | - protected function normalizeDetailsMetaBox(Review $review) |
|
| 379 | - { |
|
| 380 | - $user = empty($review->user_id) |
|
| 381 | - ? __('Unregistered user', 'site-reviews') |
|
| 382 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
| 383 | - 'href' => get_author_posts_url($review->user_id), |
|
| 384 | - ]); |
|
| 385 | - $email = empty($review->email) |
|
| 386 | - ? '—' |
|
| 387 | - : glsr(Builder::class)->a($review->email, [ |
|
| 388 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
| 389 | - ]); |
|
| 390 | - $metabox = [ |
|
| 391 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
| 392 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
| 393 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
| 394 | - __('Name', 'site-reviews') => $review->author, |
|
| 395 | - __('Email', 'site-reviews') => $email, |
|
| 396 | - __('User', 'site-reviews') => $user, |
|
| 397 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
| 398 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
| 399 | - ]; |
|
| 400 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
| 401 | - } |
|
| 375 | + /** |
|
| 376 | + * @return array |
|
| 377 | + */ |
|
| 378 | + protected function normalizeDetailsMetaBox(Review $review) |
|
| 379 | + { |
|
| 380 | + $user = empty($review->user_id) |
|
| 381 | + ? __('Unregistered user', 'site-reviews') |
|
| 382 | + : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
| 383 | + 'href' => get_author_posts_url($review->user_id), |
|
| 384 | + ]); |
|
| 385 | + $email = empty($review->email) |
|
| 386 | + ? '—' |
|
| 387 | + : glsr(Builder::class)->a($review->email, [ |
|
| 388 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
| 389 | + ]); |
|
| 390 | + $metabox = [ |
|
| 391 | + __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
| 392 | + __('Type', 'site-reviews') => $this->getReviewType($review), |
|
| 393 | + __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
| 394 | + __('Name', 'site-reviews') => $review->author, |
|
| 395 | + __('Email', 'site-reviews') => $email, |
|
| 396 | + __('User', 'site-reviews') => $user, |
|
| 397 | + __('IP Address', 'site-reviews') => $review->ip_address, |
|
| 398 | + __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
| 399 | + ]; |
|
| 400 | + return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
| 401 | + } |
|
| 402 | 402 | |
| 403 | - /** |
|
| 404 | - * @param int $postId |
|
| 405 | - * @param int $messageIndex |
|
| 406 | - * @return void |
|
| 407 | - */ |
|
| 408 | - protected function redirect($postId, $messageIndex) |
|
| 409 | - { |
|
| 410 | - $referer = wp_get_referer(); |
|
| 411 | - $hasReferer = !$referer |
|
| 412 | - || Str::contains($referer, 'post.php') |
|
| 413 | - || Str::contains($referer, 'post-new.php'); |
|
| 414 | - $redirectUri = $hasReferer |
|
| 415 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
| 416 | - : get_edit_post_link($postId); |
|
| 417 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
| 418 | - exit; |
|
| 419 | - } |
|
| 403 | + /** |
|
| 404 | + * @param int $postId |
|
| 405 | + * @param int $messageIndex |
|
| 406 | + * @return void |
|
| 407 | + */ |
|
| 408 | + protected function redirect($postId, $messageIndex) |
|
| 409 | + { |
|
| 410 | + $referer = wp_get_referer(); |
|
| 411 | + $hasReferer = !$referer |
|
| 412 | + || Str::contains($referer, 'post.php') |
|
| 413 | + || Str::contains($referer, 'post-new.php'); |
|
| 414 | + $redirectUri = $hasReferer |
|
| 415 | + ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
| 416 | + : get_edit_post_link($postId); |
|
| 417 | + wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
| 418 | + exit; |
|
| 419 | + } |
|
| 420 | 420 | } |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | * @return array |
| 26 | 26 | * @filter wp_editor_settings |
| 27 | 27 | */ |
| 28 | - public function filterEditorSettings($settings) |
|
| 28 | + public function filterEditorSettings( $settings ) |
|
| 29 | 29 | { |
| 30 | - return glsr(Customization::class)->filterEditorSettings( |
|
| 31 | - Arr::consolidateArray($settings) |
|
| 30 | + return glsr( Customization::class )->filterEditorSettings( |
|
| 31 | + Arr::consolidateArray( $settings ) |
|
| 32 | 32 | ); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * @return string |
| 39 | 39 | * @filter the_editor |
| 40 | 40 | */ |
| 41 | - public function filterEditorTextarea($html) |
|
| 41 | + public function filterEditorTextarea( $html ) |
|
| 42 | 42 | { |
| 43 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
| 43 | + return glsr( Customization::class )->filterEditorTextarea( $html ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | * @return bool |
| 51 | 51 | * @filter is_protected_meta |
| 52 | 52 | */ |
| 53 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
| 53 | + public function filterIsProtectedMeta( $protected, $metaKey, $metaType ) |
|
| 54 | 54 | { |
| 55 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
| 56 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
| 57 | - $values = Arr::prefixArrayKeys($values); |
|
| 58 | - if (array_key_exists($metaKey, $values)) { |
|
| 55 | + if( 'post' == $metaType && Application::POST_TYPE == get_post_type() ) { |
|
| 56 | + $values = glsr( CreateReviewDefaults::class )->unguarded(); |
|
| 57 | + $values = Arr::prefixArrayKeys( $values ); |
|
| 58 | + if( array_key_exists( $metaKey, $values ) ) { |
|
| 59 | 59 | $protected = false; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @return array |
| 68 | 68 | * @filter post_updated_messages |
| 69 | 69 | */ |
| 70 | - public function filterUpdateMessages($messages) |
|
| 70 | + public function filterUpdateMessages( $messages ) |
|
| 71 | 71 | { |
| 72 | - return glsr(Labels::class)->filterUpdateMessages( |
|
| 73 | - Arr::consolidateArray($messages) |
|
| 72 | + return glsr( Labels::class )->filterUpdateMessages( |
|
| 73 | + Arr::consolidateArray( $messages ) |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | * @return void |
| 79 | 79 | * @action add_meta_boxes_{Application::POST_TYPE} |
| 80 | 80 | */ |
| 81 | - public function registerMetaBoxes($post) |
|
| 81 | + public function registerMetaBoxes( $post ) |
|
| 82 | 82 | { |
| 83 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
| 84 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
| 85 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
| 83 | + add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
|
| 84 | + add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
|
| 85 | + if( 'local' != glsr( Database::class )->get( $post->ID, 'review_type' ) ) { |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
| 88 | + add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function removeAutosave() |
| 96 | 96 | { |
| 97 | - glsr(Customization::class)->removeAutosave(); |
|
| 97 | + glsr( Customization::class )->removeAutosave(); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function removeMetaBoxes() |
| 105 | 105 | { |
| 106 | - glsr(Customization::class)->removeMetaBoxes(); |
|
| 106 | + glsr( Customization::class )->removeMetaBoxes(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function removePostTypeSupport() |
| 113 | 113 | { |
| 114 | - glsr(Customization::class)->removePostTypeSupport(); |
|
| 114 | + glsr( Customization::class )->removePostTypeSupport(); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -119,17 +119,17 @@ discard block |
||
| 119 | 119 | * @return void |
| 120 | 120 | * @callback add_meta_box |
| 121 | 121 | */ |
| 122 | - public function renderAssignedToMetabox($post) |
|
| 122 | + public function renderAssignedToMetabox( $post ) |
|
| 123 | 123 | { |
| 124 | - if (!$this->isReviewPostType($post)) { |
|
| 124 | + if( !$this->isReviewPostType( $post ) ) { |
|
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
| 128 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
| 129 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
| 127 | + $assignedTo = (string)glsr( Database::class )->get( $post->ID, 'assigned_to' ); |
|
| 128 | + wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
|
| 129 | + glsr()->render( 'partials/editor/metabox-assigned-to', [ |
|
| 130 | 130 | 'id' => $assignedTo, |
| 131 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
| 132 | - ]); |
|
| 131 | + 'template' => $this->buildAssignedToTemplate( $assignedTo, $post ), |
|
| 132 | + ] ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -137,16 +137,16 @@ discard block |
||
| 137 | 137 | * @return void |
| 138 | 138 | * @callback add_meta_box |
| 139 | 139 | */ |
| 140 | - public function renderDetailsMetaBox($post) |
|
| 140 | + public function renderDetailsMetaBox( $post ) |
|
| 141 | 141 | { |
| 142 | - if (!$this->isReviewPostType($post)) { |
|
| 142 | + if( !$this->isReviewPostType( $post ) ) { |
|
| 143 | 143 | return; |
| 144 | 144 | } |
| 145 | - $review = glsr_get_review($post); |
|
| 146 | - glsr()->render('partials/editor/metabox-details', [ |
|
| 147 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
| 148 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
| 149 | - ]); |
|
| 145 | + $review = glsr_get_review( $post ); |
|
| 146 | + glsr()->render( 'partials/editor/metabox-details', [ |
|
| 147 | + 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
|
| 148 | + 'metabox' => $this->normalizeDetailsMetaBox( $review ), |
|
| 149 | + ] ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function renderPinnedInPublishMetaBox() |
| 157 | 157 | { |
| 158 | - if (!$this->isReviewPostType(get_post())) { |
|
| 158 | + if( !$this->isReviewPostType( get_post() ) ) { |
|
| 159 | 159 | return; |
| 160 | 160 | } |
| 161 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
| 161 | + glsr( Template::class )->render( 'partials/editor/pinned', [ |
|
| 162 | 162 | 'context' => [ |
| 163 | - 'no' => __('No', 'site-reviews'), |
|
| 164 | - 'yes' => __('Yes', 'site-reviews'), |
|
| 163 | + 'no' => __( 'No', 'site-reviews' ), |
|
| 164 | + 'yes' => __( 'Yes', 'site-reviews' ), |
|
| 165 | 165 | ], |
| 166 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
| 167 | - ]); |
|
| 166 | + 'pinned' => wp_validate_boolean( glsr( Database::class )->get( get_the_ID(), 'pinned' ) ), |
|
| 167 | + ] ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -172,15 +172,15 @@ discard block |
||
| 172 | 172 | * @return void |
| 173 | 173 | * @callback add_meta_box |
| 174 | 174 | */ |
| 175 | - public function renderResponseMetaBox($post) |
|
| 175 | + public function renderResponseMetaBox( $post ) |
|
| 176 | 176 | { |
| 177 | - if (!$this->isReviewPostType($post)) { |
|
| 177 | + if( !$this->isReviewPostType( $post ) ) { |
|
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | - wp_nonce_field('response', '_nonce-response', false); |
|
| 181 | - glsr()->render('partials/editor/metabox-response', [ |
|
| 182 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 183 | - ]); |
|
| 180 | + wp_nonce_field( 'response', '_nonce-response', false ); |
|
| 181 | + glsr()->render( 'partials/editor/metabox-response', [ |
|
| 182 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
| 183 | + ] ); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | * @return void |
| 189 | 189 | * @action edit_form_after_title |
| 190 | 190 | */ |
| 191 | - public function renderReviewEditor($post) |
|
| 191 | + public function renderReviewEditor( $post ) |
|
| 192 | 192 | { |
| 193 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 193 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
| 194 | 194 | return; |
| 195 | 195 | } |
| 196 | - glsr()->render('partials/editor/review', [ |
|
| 196 | + glsr()->render( 'partials/editor/review', [ |
|
| 197 | 197 | 'post' => $post, |
| 198 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
| 199 | - ]); |
|
| 198 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
| 199 | + ] ); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | public function renderReviewFields() |
| 207 | 207 | { |
| 208 | 208 | $screen = glsr_current_screen(); |
| 209 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
| 209 | + if( 'post' != $screen->base || Application::POST_TYPE != $screen->post_type ) { |
|
| 210 | 210 | return; |
| 211 | 211 | } |
| 212 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
| 213 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
| 212 | + add_action( 'edit_form_after_title', [$this, 'renderReviewEditor'] ); |
|
| 213 | + add_action( 'edit_form_top', [$this, 'renderReviewNotice'] ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * @return void |
| 219 | 219 | * @action edit_form_top |
| 220 | 220 | */ |
| 221 | - public function renderReviewNotice($post) |
|
| 221 | + public function renderReviewNotice( $post ) |
|
| 222 | 222 | { |
| 223 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
| 223 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | - glsr(Notice::class)->addWarning(sprintf( |
|
| 227 | - __('%s reviews are read-only.', 'site-reviews'), |
|
| 228 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
| 229 | - )); |
|
| 230 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
| 226 | + glsr( Notice::class )->addWarning( sprintf( |
|
| 227 | + __( '%s reviews are read-only.', 'site-reviews' ), |
|
| 228 | + glsr( Columns::class )->buildColumnReviewType( $post->ID ) |
|
| 229 | + ) ); |
|
| 230 | + glsr( Template::class )->render( 'partials/editor/notice', [ |
|
| 231 | 231 | 'context' => [ |
| 232 | - 'notices' => glsr(Notice::class)->get(), |
|
| 232 | + 'notices' => glsr( Notice::class )->get(), |
|
| 233 | 233 | ], |
| 234 | - ]); |
|
| 234 | + ] ); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | * @see glsr_categories_meta_box() |
| 241 | 241 | * @callback register_taxonomy |
| 242 | 242 | */ |
| 243 | - public function renderTaxonomyMetabox($post) |
|
| 243 | + public function renderTaxonomyMetabox( $post ) |
|
| 244 | 244 | { |
| 245 | - if (!$this->isReviewPostType($post)) { |
|
| 245 | + if( !$this->isReviewPostType( $post ) ) { |
|
| 246 | 246 | return; |
| 247 | 247 | } |
| 248 | - glsr()->render('partials/editor/metabox-categories', [ |
|
| 248 | + glsr()->render( 'partials/editor/metabox-categories', [ |
|
| 249 | 249 | 'post' => $post, |
| 250 | 250 | 'tax_name' => Application::TAXONOMY, |
| 251 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
| 252 | - ]); |
|
| 251 | + 'taxonomy' => get_taxonomy( Application::TAXONOMY ), |
|
| 252 | + ] ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -259,12 +259,12 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function revertReview() |
| 261 | 261 | { |
| 262 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
| 262 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
| 263 | 263 | return; |
| 264 | 264 | } |
| 265 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
| 266 | - glsr(ReviewManager::class)->revert($postId); |
|
| 267 | - $this->redirect($postId, 52); |
|
| 265 | + check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) ); |
|
| 266 | + glsr( ReviewManager::class )->revert( $postId ); |
|
| 267 | + $this->redirect( $postId, 52 ); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -274,12 +274,12 @@ discard block |
||
| 274 | 274 | * @return void |
| 275 | 275 | * @action save_post_.Application::POST_TYPE |
| 276 | 276 | */ |
| 277 | - public function saveMetaboxes($postId, $post, $isUpdating) |
|
| 277 | + public function saveMetaboxes( $postId, $post, $isUpdating ) |
|
| 278 | 278 | { |
| 279 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
| 280 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
| 281 | - if ($isUpdating) { |
|
| 282 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
| 279 | + glsr( Metaboxes::class )->saveAssignedToMetabox( $postId ); |
|
| 280 | + glsr( Metaboxes::class )->saveResponseMetabox( $postId ); |
|
| 281 | + if( $isUpdating ) { |
|
| 282 | + do_action( 'site-reviews/review/saved', glsr_get_review( $postId ) ); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
@@ -287,68 +287,68 @@ discard block |
||
| 287 | 287 | * @param string $assignedTo |
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
| 290 | + protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
|
| 291 | 291 | { |
| 292 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
| 293 | - if (!($assignedPost instanceof WP_Post)) { |
|
| 292 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo ); |
|
| 293 | + if( !($assignedPost instanceof WP_Post) ) { |
|
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
| 296 | + return glsr( Template::class )->build( 'partials/editor/assigned-post', [ |
|
| 297 | 297 | 'context' => [ |
| 298 | - 'data.url' => (string) get_permalink($assignedPost), |
|
| 299 | - 'data.title' => get_the_title($assignedPost), |
|
| 298 | + 'data.url' => (string)get_permalink( $assignedPost ), |
|
| 299 | + 'data.title' => get_the_title( $assignedPost ), |
|
| 300 | 300 | ], |
| 301 | - ]); |
|
| 301 | + ] ); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * @return string |
| 306 | 306 | */ |
| 307 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
| 307 | + protected function buildDetailsMetaBoxRevertButton( Review $review, WP_Post $post ) |
|
| 308 | 308 | { |
| 309 | 309 | $isModified = !Arr::compareArrays( |
| 310 | 310 | [$review->title, $review->content, $review->date], |
| 311 | 311 | [ |
| 312 | - glsr(Database::class)->get($post->ID, 'title'), |
|
| 313 | - glsr(Database::class)->get($post->ID, 'content'), |
|
| 314 | - glsr(Database::class)->get($post->ID, 'date'), |
|
| 312 | + glsr( Database::class )->get( $post->ID, 'title' ), |
|
| 313 | + glsr( Database::class )->get( $post->ID, 'content' ), |
|
| 314 | + glsr( Database::class )->get( $post->ID, 'date' ), |
|
| 315 | 315 | ] |
| 316 | 316 | ); |
| 317 | - if ($isModified) { |
|
| 317 | + if( $isModified ) { |
|
| 318 | 318 | $revertUrl = wp_nonce_url( |
| 319 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
| 319 | + admin_url( 'post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID ), |
|
| 320 | 320 | 'revert-review_'.$post->ID |
| 321 | 321 | ); |
| 322 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
| 322 | + return glsr( Builder::class )->a( __( 'Revert Changes', 'site-reviews' ), [ |
|
| 323 | 323 | 'class' => 'button button-large', |
| 324 | 324 | 'href' => $revertUrl, |
| 325 | 325 | 'id' => 'revert', |
| 326 | - ]); |
|
| 326 | + ] ); |
|
| 327 | 327 | } |
| 328 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
| 328 | + return glsr( Builder::class )->button( __( 'Nothing to Revert', 'site-reviews' ), [ |
|
| 329 | 329 | 'class' => 'button-large', |
| 330 | 330 | 'disabled' => true, |
| 331 | 331 | 'id' => 'revert', |
| 332 | - ]); |
|
| 332 | + ] ); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | 336 | * @param object $review |
| 337 | 337 | * @return string|void |
| 338 | 338 | */ |
| 339 | - protected function getReviewType($review) |
|
| 339 | + protected function getReviewType( $review ) |
|
| 340 | 340 | { |
| 341 | - if (count(glsr()->reviewTypes) < 2) { |
|
| 341 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
| 342 | 342 | return; |
| 343 | 343 | } |
| 344 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
| 344 | + $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
|
| 345 | 345 | ? glsr()->reviewTypes[$review->review_type] |
| 346 | - : __('Unknown', 'site-reviews'); |
|
| 347 | - if (!empty($review->url)) { |
|
| 348 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
| 346 | + : __( 'Unknown', 'site-reviews' ); |
|
| 347 | + if( !empty($review->url) ) { |
|
| 348 | + $reviewType = glsr( Builder::class )->a( $reviewType, [ |
|
| 349 | 349 | 'href' => $review->url, |
| 350 | 350 | 'target' => '_blank', |
| 351 | - ]); |
|
| 351 | + ] ); |
|
| 352 | 352 | } |
| 353 | 353 | return $reviewType; |
| 354 | 354 | } |
@@ -356,18 +356,18 @@ discard block |
||
| 356 | 356 | /** |
| 357 | 357 | * @return bool |
| 358 | 358 | */ |
| 359 | - protected function isReviewEditable($post) |
|
| 359 | + protected function isReviewEditable( $post ) |
|
| 360 | 360 | { |
| 361 | - return $this->isReviewPostType($post) |
|
| 362 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
| 363 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
| 361 | + return $this->isReviewPostType( $post ) |
|
| 362 | + && post_type_supports( Application::POST_TYPE, 'title' ) |
|
| 363 | + && 'local' == glsr( Database::class )->get( $post->ID, 'review_type' ); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
| 367 | 367 | * @param mixed $post |
| 368 | 368 | * @return bool |
| 369 | 369 | */ |
| 370 | - protected function isReviewPostType($post) |
|
| 370 | + protected function isReviewPostType( $post ) |
|
| 371 | 371 | { |
| 372 | 372 | return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
| 373 | 373 | } |
@@ -375,29 +375,29 @@ discard block |
||
| 375 | 375 | /** |
| 376 | 376 | * @return array |
| 377 | 377 | */ |
| 378 | - protected function normalizeDetailsMetaBox(Review $review) |
|
| 378 | + protected function normalizeDetailsMetaBox( Review $review ) |
|
| 379 | 379 | { |
| 380 | 380 | $user = empty($review->user_id) |
| 381 | - ? __('Unregistered user', 'site-reviews') |
|
| 382 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
| 383 | - 'href' => get_author_posts_url($review->user_id), |
|
| 384 | - ]); |
|
| 381 | + ? __( 'Unregistered user', 'site-reviews' ) |
|
| 382 | + : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [ |
|
| 383 | + 'href' => get_author_posts_url( $review->user_id ), |
|
| 384 | + ] ); |
|
| 385 | 385 | $email = empty($review->email) |
| 386 | 386 | ? '—' |
| 387 | - : glsr(Builder::class)->a($review->email, [ |
|
| 388 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
| 389 | - ]); |
|
| 387 | + : glsr( Builder::class )->a( $review->email, [ |
|
| 388 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ), |
|
| 389 | + ] ); |
|
| 390 | 390 | $metabox = [ |
| 391 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
| 392 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
| 393 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
| 394 | - __('Name', 'site-reviews') => $review->author, |
|
| 395 | - __('Email', 'site-reviews') => $email, |
|
| 396 | - __('User', 'site-reviews') => $user, |
|
| 397 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
| 398 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
| 391 | + __( 'Rating', 'site-reviews' ) => glsr_star_rating( $review->rating ), |
|
| 392 | + __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ), |
|
| 393 | + __( 'Date', 'site-reviews' ) => get_date_from_gmt( $review->date, 'F j, Y' ), |
|
| 394 | + __( 'Name', 'site-reviews' ) => $review->author, |
|
| 395 | + __( 'Email', 'site-reviews' ) => $email, |
|
| 396 | + __( 'User', 'site-reviews' ) => $user, |
|
| 397 | + __( 'IP Address', 'site-reviews' ) => $review->ip_address, |
|
| 398 | + __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ), |
|
| 399 | 399 | ]; |
| 400 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
| 400 | + return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review ) ); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -405,16 +405,16 @@ discard block |
||
| 405 | 405 | * @param int $messageIndex |
| 406 | 406 | * @return void |
| 407 | 407 | */ |
| 408 | - protected function redirect($postId, $messageIndex) |
|
| 408 | + protected function redirect( $postId, $messageIndex ) |
|
| 409 | 409 | { |
| 410 | 410 | $referer = wp_get_referer(); |
| 411 | 411 | $hasReferer = !$referer |
| 412 | - || Str::contains($referer, 'post.php') |
|
| 413 | - || Str::contains($referer, 'post-new.php'); |
|
| 412 | + || Str::contains( $referer, 'post.php' ) |
|
| 413 | + || Str::contains( $referer, 'post-new.php' ); |
|
| 414 | 414 | $redirectUri = $hasReferer |
| 415 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
| 416 | - : get_edit_post_link($postId); |
|
| 417 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
| 415 | + ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer ) |
|
| 416 | + : get_edit_post_link( $postId ); |
|
| 417 | + wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) ); |
|
| 418 | 418 | exit; |
| 419 | 419 | } |
| 420 | 420 | } |
@@ -11,226 +11,226 @@ |
||
| 11 | 11 | |
| 12 | 12 | abstract class Container |
| 13 | 13 | { |
| 14 | - const PROTECTED_PROPERTIES = [ |
|
| 15 | - 'instance', |
|
| 16 | - 'services', |
|
| 17 | - 'session', |
|
| 18 | - 'storage', |
|
| 19 | - ]; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var static |
|
| 23 | - */ |
|
| 24 | - protected static $instance; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * The container's bound services. |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $services = []; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $session = []; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * The container's storage items. |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $storage = []; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return static |
|
| 45 | - */ |
|
| 46 | - public static function load() |
|
| 47 | - { |
|
| 48 | - if (empty(static::$instance)) { |
|
| 49 | - static::$instance = new static(); |
|
| 50 | - } |
|
| 51 | - return static::$instance; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param string $property |
|
| 56 | - * @return mixed |
|
| 57 | - */ |
|
| 58 | - public function __get($property) |
|
| 59 | - { |
|
| 60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 61 | - return $this->$property; |
|
| 62 | - } |
|
| 63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
| 64 | - if (defined($constant)) { |
|
| 65 | - return constant($constant); |
|
| 66 | - } |
|
| 67 | - return Arr::get($this->storage, $property, null); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param string $property |
|
| 72 | - * @param string $value |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public function __set($property, $value) |
|
| 76 | - { |
|
| 77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 78 | - $this->storage[$property] = $value; |
|
| 79 | - } elseif (!isset($this->$property)) { |
|
| 80 | - $this->$property = $value; |
|
| 81 | - } else { |
|
| 82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Bind a service to the container. |
|
| 88 | - * @param string $alias |
|
| 89 | - * @param mixed $concrete |
|
| 90 | - * @return mixed |
|
| 91 | - */ |
|
| 92 | - public function bind($alias, $concrete) |
|
| 93 | - { |
|
| 94 | - $this->services[$alias] = $concrete; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Request a service from the container. |
|
| 99 | - * @param mixed $abstract |
|
| 100 | - * @return mixed |
|
| 101 | - */ |
|
| 102 | - public function make($abstract) |
|
| 103 | - { |
|
| 104 | - if (!isset($this->services[$abstract])) { |
|
| 105 | - $abstract = $this->addNamespace($abstract); |
|
| 106 | - } |
|
| 107 | - if (isset($this->services[$abstract])) { |
|
| 108 | - $abstract = $this->services[$abstract]; |
|
| 109 | - } |
|
| 110 | - if (is_callable($abstract)) { |
|
| 111 | - return call_user_func_array($abstract, [$this]); |
|
| 112 | - } |
|
| 113 | - if (is_object($abstract)) { |
|
| 114 | - return $abstract; |
|
| 115 | - } |
|
| 116 | - return $this->resolve($abstract); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public function sessionClear() |
|
| 123 | - { |
|
| 124 | - $this->session = []; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return mixed |
|
| 129 | - */ |
|
| 130 | - public function sessionGet($key, $fallback = '') |
|
| 131 | - { |
|
| 132 | - $value = Arr::get($this->session, $key, $fallback); |
|
| 133 | - unset($this->session[$key]); |
|
| 134 | - return $value; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - public function sessionSet($key, $value) |
|
| 141 | - { |
|
| 142 | - $this->session[$key] = $value; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Bind a singleton instance to the container. |
|
| 147 | - * @param string $alias |
|
| 148 | - * @param callable|string|null $binding |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function singleton($alias, $binding) |
|
| 152 | - { |
|
| 153 | - $this->bind($alias, $this->make($binding)); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Prefix the current namespace to the abstract if absent. |
|
| 158 | - * @param string $abstract |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - protected function addNamespace($abstract) |
|
| 162 | - { |
|
| 163 | - if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
| 164 | - $abstract = __NAMESPACE__.'\\'.$abstract; |
|
| 165 | - } |
|
| 166 | - return $abstract; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Resolve a service from the container. |
|
| 171 | - * @param mixed $concrete |
|
| 172 | - * @return mixed |
|
| 173 | - * @throws Exception |
|
| 174 | - */ |
|
| 175 | - protected function resolve($concrete) |
|
| 176 | - { |
|
| 177 | - if ($concrete instanceof Closure) { |
|
| 178 | - return $concrete($this); |
|
| 179 | - } |
|
| 180 | - $reflector = new ReflectionClass($concrete); |
|
| 181 | - if (!$reflector->isInstantiable()) { |
|
| 182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
| 183 | - } |
|
| 184 | - $constructor = $reflector->getConstructor(); |
|
| 185 | - if (empty($constructor)) { |
|
| 186 | - return new $concrete(); |
|
| 187 | - } |
|
| 188 | - return $reflector->newInstanceArgs( |
|
| 189 | - $this->resolveDependencies($constructor->getParameters()) |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Resolve a class based dependency from the container. |
|
| 195 | - * @return mixed |
|
| 196 | - * @throws Exception |
|
| 197 | - */ |
|
| 198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
| 199 | - { |
|
| 200 | - try { |
|
| 201 | - return $this->make($parameter->getClass()->name); |
|
| 202 | - } catch (Exception $error) { |
|
| 203 | - if ($parameter->isOptional()) { |
|
| 204 | - return $parameter->getDefaultValue(); |
|
| 205 | - } |
|
| 206 | - throw $error; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Resolve all of the dependencies from the ReflectionParameters. |
|
| 212 | - * @return array |
|
| 213 | - */ |
|
| 214 | - protected function resolveDependencies(array $dependencies) |
|
| 215 | - { |
|
| 216 | - $results = []; |
|
| 217 | - foreach ($dependencies as $dependency) { |
|
| 218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
| 219 | - ? $this->resolveClass($dependency) |
|
| 220 | - : $this->resolveDependency($dependency); |
|
| 221 | - } |
|
| 222 | - return $results; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Resolve a single ReflectionParameter dependency. |
|
| 227 | - * @return array|null |
|
| 228 | - */ |
|
| 229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
| 230 | - { |
|
| 231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
| 232 | - return $parameter->getDefaultValue(); |
|
| 233 | - } |
|
| 234 | - return null; |
|
| 235 | - } |
|
| 14 | + const PROTECTED_PROPERTIES = [ |
|
| 15 | + 'instance', |
|
| 16 | + 'services', |
|
| 17 | + 'session', |
|
| 18 | + 'storage', |
|
| 19 | + ]; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var static |
|
| 23 | + */ |
|
| 24 | + protected static $instance; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * The container's bound services. |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $services = []; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $session = []; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * The container's storage items. |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $storage = []; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return static |
|
| 45 | + */ |
|
| 46 | + public static function load() |
|
| 47 | + { |
|
| 48 | + if (empty(static::$instance)) { |
|
| 49 | + static::$instance = new static(); |
|
| 50 | + } |
|
| 51 | + return static::$instance; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param string $property |
|
| 56 | + * @return mixed |
|
| 57 | + */ |
|
| 58 | + public function __get($property) |
|
| 59 | + { |
|
| 60 | + if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 61 | + return $this->$property; |
|
| 62 | + } |
|
| 63 | + $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
| 64 | + if (defined($constant)) { |
|
| 65 | + return constant($constant); |
|
| 66 | + } |
|
| 67 | + return Arr::get($this->storage, $property, null); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param string $property |
|
| 72 | + * @param string $value |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public function __set($property, $value) |
|
| 76 | + { |
|
| 77 | + if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 78 | + $this->storage[$property] = $value; |
|
| 79 | + } elseif (!isset($this->$property)) { |
|
| 80 | + $this->$property = $value; |
|
| 81 | + } else { |
|
| 82 | + throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Bind a service to the container. |
|
| 88 | + * @param string $alias |
|
| 89 | + * @param mixed $concrete |
|
| 90 | + * @return mixed |
|
| 91 | + */ |
|
| 92 | + public function bind($alias, $concrete) |
|
| 93 | + { |
|
| 94 | + $this->services[$alias] = $concrete; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Request a service from the container. |
|
| 99 | + * @param mixed $abstract |
|
| 100 | + * @return mixed |
|
| 101 | + */ |
|
| 102 | + public function make($abstract) |
|
| 103 | + { |
|
| 104 | + if (!isset($this->services[$abstract])) { |
|
| 105 | + $abstract = $this->addNamespace($abstract); |
|
| 106 | + } |
|
| 107 | + if (isset($this->services[$abstract])) { |
|
| 108 | + $abstract = $this->services[$abstract]; |
|
| 109 | + } |
|
| 110 | + if (is_callable($abstract)) { |
|
| 111 | + return call_user_func_array($abstract, [$this]); |
|
| 112 | + } |
|
| 113 | + if (is_object($abstract)) { |
|
| 114 | + return $abstract; |
|
| 115 | + } |
|
| 116 | + return $this->resolve($abstract); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public function sessionClear() |
|
| 123 | + { |
|
| 124 | + $this->session = []; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return mixed |
|
| 129 | + */ |
|
| 130 | + public function sessionGet($key, $fallback = '') |
|
| 131 | + { |
|
| 132 | + $value = Arr::get($this->session, $key, $fallback); |
|
| 133 | + unset($this->session[$key]); |
|
| 134 | + return $value; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + public function sessionSet($key, $value) |
|
| 141 | + { |
|
| 142 | + $this->session[$key] = $value; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Bind a singleton instance to the container. |
|
| 147 | + * @param string $alias |
|
| 148 | + * @param callable|string|null $binding |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function singleton($alias, $binding) |
|
| 152 | + { |
|
| 153 | + $this->bind($alias, $this->make($binding)); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Prefix the current namespace to the abstract if absent. |
|
| 158 | + * @param string $abstract |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + protected function addNamespace($abstract) |
|
| 162 | + { |
|
| 163 | + if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
| 164 | + $abstract = __NAMESPACE__.'\\'.$abstract; |
|
| 165 | + } |
|
| 166 | + return $abstract; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Resolve a service from the container. |
|
| 171 | + * @param mixed $concrete |
|
| 172 | + * @return mixed |
|
| 173 | + * @throws Exception |
|
| 174 | + */ |
|
| 175 | + protected function resolve($concrete) |
|
| 176 | + { |
|
| 177 | + if ($concrete instanceof Closure) { |
|
| 178 | + return $concrete($this); |
|
| 179 | + } |
|
| 180 | + $reflector = new ReflectionClass($concrete); |
|
| 181 | + if (!$reflector->isInstantiable()) { |
|
| 182 | + throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
| 183 | + } |
|
| 184 | + $constructor = $reflector->getConstructor(); |
|
| 185 | + if (empty($constructor)) { |
|
| 186 | + return new $concrete(); |
|
| 187 | + } |
|
| 188 | + return $reflector->newInstanceArgs( |
|
| 189 | + $this->resolveDependencies($constructor->getParameters()) |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Resolve a class based dependency from the container. |
|
| 195 | + * @return mixed |
|
| 196 | + * @throws Exception |
|
| 197 | + */ |
|
| 198 | + protected function resolveClass(ReflectionParameter $parameter) |
|
| 199 | + { |
|
| 200 | + try { |
|
| 201 | + return $this->make($parameter->getClass()->name); |
|
| 202 | + } catch (Exception $error) { |
|
| 203 | + if ($parameter->isOptional()) { |
|
| 204 | + return $parameter->getDefaultValue(); |
|
| 205 | + } |
|
| 206 | + throw $error; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Resolve all of the dependencies from the ReflectionParameters. |
|
| 212 | + * @return array |
|
| 213 | + */ |
|
| 214 | + protected function resolveDependencies(array $dependencies) |
|
| 215 | + { |
|
| 216 | + $results = []; |
|
| 217 | + foreach ($dependencies as $dependency) { |
|
| 218 | + $results[] = !is_null($class = $dependency->getClass()) |
|
| 219 | + ? $this->resolveClass($dependency) |
|
| 220 | + : $this->resolveDependency($dependency); |
|
| 221 | + } |
|
| 222 | + return $results; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Resolve a single ReflectionParameter dependency. |
|
| 227 | + * @return array|null |
|
| 228 | + */ |
|
| 229 | + protected function resolveDependency(ReflectionParameter $parameter) |
|
| 230 | + { |
|
| 231 | + if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
| 232 | + return $parameter->getDefaultValue(); |
|
| 233 | + } |
|
| 234 | + return null; |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public static function load() |
| 47 | 47 | { |
| 48 | - if (empty(static::$instance)) { |
|
| 48 | + if( empty(static::$instance) ) { |
|
| 49 | 49 | static::$instance = new static(); |
| 50 | 50 | } |
| 51 | 51 | return static::$instance; |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | * @param string $property |
| 56 | 56 | * @return mixed |
| 57 | 57 | */ |
| 58 | - public function __get($property) |
|
| 58 | + public function __get( $property ) |
|
| 59 | 59 | { |
| 60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 60 | + if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
| 61 | 61 | return $this->$property; |
| 62 | 62 | } |
| 63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
| 64 | - if (defined($constant)) { |
|
| 65 | - return constant($constant); |
|
| 63 | + $constant = 'static::'.strtoupper( Str::snakeCase( $property ) ); |
|
| 64 | + if( defined( $constant ) ) { |
|
| 65 | + return constant( $constant ); |
|
| 66 | 66 | } |
| 67 | - return Arr::get($this->storage, $property, null); |
|
| 67 | + return Arr::get( $this->storage, $property, null ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | * @param string $value |
| 73 | 73 | * @return void |
| 74 | 74 | */ |
| 75 | - public function __set($property, $value) |
|
| 75 | + public function __set( $property, $value ) |
|
| 76 | 76 | { |
| 77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
| 77 | + if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
| 78 | 78 | $this->storage[$property] = $value; |
| 79 | - } elseif (!isset($this->$property)) { |
|
| 79 | + } elseif( !isset($this->$property) ) { |
|
| 80 | 80 | $this->$property = $value; |
| 81 | 81 | } else { |
| 82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
| 82 | + throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) ); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param mixed $concrete |
| 90 | 90 | * @return mixed |
| 91 | 91 | */ |
| 92 | - public function bind($alias, $concrete) |
|
| 92 | + public function bind( $alias, $concrete ) |
|
| 93 | 93 | { |
| 94 | 94 | $this->services[$alias] = $concrete; |
| 95 | 95 | } |
@@ -99,21 +99,21 @@ discard block |
||
| 99 | 99 | * @param mixed $abstract |
| 100 | 100 | * @return mixed |
| 101 | 101 | */ |
| 102 | - public function make($abstract) |
|
| 102 | + public function make( $abstract ) |
|
| 103 | 103 | { |
| 104 | - if (!isset($this->services[$abstract])) { |
|
| 105 | - $abstract = $this->addNamespace($abstract); |
|
| 104 | + if( !isset($this->services[$abstract]) ) { |
|
| 105 | + $abstract = $this->addNamespace( $abstract ); |
|
| 106 | 106 | } |
| 107 | - if (isset($this->services[$abstract])) { |
|
| 107 | + if( isset($this->services[$abstract]) ) { |
|
| 108 | 108 | $abstract = $this->services[$abstract]; |
| 109 | 109 | } |
| 110 | - if (is_callable($abstract)) { |
|
| 111 | - return call_user_func_array($abstract, [$this]); |
|
| 110 | + if( is_callable( $abstract ) ) { |
|
| 111 | + return call_user_func_array( $abstract, [$this] ); |
|
| 112 | 112 | } |
| 113 | - if (is_object($abstract)) { |
|
| 113 | + if( is_object( $abstract ) ) { |
|
| 114 | 114 | return $abstract; |
| 115 | 115 | } |
| 116 | - return $this->resolve($abstract); |
|
| 116 | + return $this->resolve( $abstract ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | /** |
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
| 130 | - public function sessionGet($key, $fallback = '') |
|
| 130 | + public function sessionGet( $key, $fallback = '' ) |
|
| 131 | 131 | { |
| 132 | - $value = Arr::get($this->session, $key, $fallback); |
|
| 132 | + $value = Arr::get( $this->session, $key, $fallback ); |
|
| 133 | 133 | unset($this->session[$key]); |
| 134 | 134 | return $value; |
| 135 | 135 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | /** |
| 138 | 138 | * @return void |
| 139 | 139 | */ |
| 140 | - public function sessionSet($key, $value) |
|
| 140 | + public function sessionSet( $key, $value ) |
|
| 141 | 141 | { |
| 142 | 142 | $this->session[$key] = $value; |
| 143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * @param callable|string|null $binding |
| 149 | 149 | * @return void |
| 150 | 150 | */ |
| 151 | - public function singleton($alias, $binding) |
|
| 151 | + public function singleton( $alias, $binding ) |
|
| 152 | 152 | { |
| 153 | - $this->bind($alias, $this->make($binding)); |
|
| 153 | + $this->bind( $alias, $this->make( $binding ) ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | * @param string $abstract |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - protected function addNamespace($abstract) |
|
| 161 | + protected function addNamespace( $abstract ) |
|
| 162 | 162 | { |
| 163 | - if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
| 163 | + if( !Str::contains( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) { |
|
| 164 | 164 | $abstract = __NAMESPACE__.'\\'.$abstract; |
| 165 | 165 | } |
| 166 | 166 | return $abstract; |
@@ -172,21 +172,21 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | * @throws Exception |
| 174 | 174 | */ |
| 175 | - protected function resolve($concrete) |
|
| 175 | + protected function resolve( $concrete ) |
|
| 176 | 176 | { |
| 177 | - if ($concrete instanceof Closure) { |
|
| 178 | - return $concrete($this); |
|
| 177 | + if( $concrete instanceof Closure ) { |
|
| 178 | + return $concrete( $this ); |
|
| 179 | 179 | } |
| 180 | - $reflector = new ReflectionClass($concrete); |
|
| 181 | - if (!$reflector->isInstantiable()) { |
|
| 182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
| 180 | + $reflector = new ReflectionClass( $concrete ); |
|
| 181 | + if( !$reflector->isInstantiable() ) { |
|
| 182 | + throw new Exception( 'Target ['.$concrete.'] is not instantiable.' ); |
|
| 183 | 183 | } |
| 184 | 184 | $constructor = $reflector->getConstructor(); |
| 185 | - if (empty($constructor)) { |
|
| 185 | + if( empty($constructor) ) { |
|
| 186 | 186 | return new $concrete(); |
| 187 | 187 | } |
| 188 | 188 | return $reflector->newInstanceArgs( |
| 189 | - $this->resolveDependencies($constructor->getParameters()) |
|
| 189 | + $this->resolveDependencies( $constructor->getParameters() ) |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * @return mixed |
| 196 | 196 | * @throws Exception |
| 197 | 197 | */ |
| 198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
| 198 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
| 199 | 199 | { |
| 200 | 200 | try { |
| 201 | - return $this->make($parameter->getClass()->name); |
|
| 202 | - } catch (Exception $error) { |
|
| 203 | - if ($parameter->isOptional()) { |
|
| 201 | + return $this->make( $parameter->getClass()->name ); |
|
| 202 | + } catch( Exception $error ) { |
|
| 203 | + if( $parameter->isOptional() ) { |
|
| 204 | 204 | return $parameter->getDefaultValue(); |
| 205 | 205 | } |
| 206 | 206 | throw $error; |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | * Resolve all of the dependencies from the ReflectionParameters. |
| 212 | 212 | * @return array |
| 213 | 213 | */ |
| 214 | - protected function resolveDependencies(array $dependencies) |
|
| 214 | + protected function resolveDependencies( array $dependencies ) |
|
| 215 | 215 | { |
| 216 | 216 | $results = []; |
| 217 | - foreach ($dependencies as $dependency) { |
|
| 218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
| 219 | - ? $this->resolveClass($dependency) |
|
| 220 | - : $this->resolveDependency($dependency); |
|
| 217 | + foreach( $dependencies as $dependency ) { |
|
| 218 | + $results[] = !is_null( $class = $dependency->getClass() ) |
|
| 219 | + ? $this->resolveClass( $dependency ) |
|
| 220 | + : $this->resolveDependency( $dependency ); |
|
| 221 | 221 | } |
| 222 | 222 | return $results; |
| 223 | 223 | } |
@@ -226,9 +226,9 @@ discard block |
||
| 226 | 226 | * Resolve a single ReflectionParameter dependency. |
| 227 | 227 | * @return array|null |
| 228 | 228 | */ |
| 229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
| 229 | + protected function resolveDependency( ReflectionParameter $parameter ) |
|
| 230 | 230 | { |
| 231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
| 231 | + if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) { |
|
| 232 | 232 | return $parameter->getDefaultValue(); |
| 233 | 233 | } |
| 234 | 234 | return null; |
@@ -21,110 +21,110 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Actions implements HooksContract |
| 23 | 23 | { |
| 24 | - protected $about; |
|
| 25 | - protected $admin; |
|
| 26 | - protected $app; |
|
| 27 | - protected $blocks; |
|
| 28 | - protected $console; |
|
| 29 | - protected $editor; |
|
| 30 | - protected $listtable; |
|
| 31 | - protected $menu; |
|
| 32 | - protected $main; |
|
| 33 | - protected $notices; |
|
| 34 | - protected $public; |
|
| 35 | - protected $rebusify; |
|
| 36 | - protected $review; |
|
| 37 | - protected $router; |
|
| 38 | - protected $settings; |
|
| 39 | - protected $taxonomy; |
|
| 40 | - protected $translator; |
|
| 41 | - protected $welcome; |
|
| 24 | + protected $about; |
|
| 25 | + protected $admin; |
|
| 26 | + protected $app; |
|
| 27 | + protected $blocks; |
|
| 28 | + protected $console; |
|
| 29 | + protected $editor; |
|
| 30 | + protected $listtable; |
|
| 31 | + protected $menu; |
|
| 32 | + protected $main; |
|
| 33 | + protected $notices; |
|
| 34 | + protected $public; |
|
| 35 | + protected $rebusify; |
|
| 36 | + protected $review; |
|
| 37 | + protected $router; |
|
| 38 | + protected $settings; |
|
| 39 | + protected $taxonomy; |
|
| 40 | + protected $translator; |
|
| 41 | + protected $welcome; |
|
| 42 | 42 | |
| 43 | - public function __construct(Application $app ) { |
|
| 44 | - $this->app = $app; |
|
| 45 | - $this->admin = $app->make(AdminController::class); |
|
| 46 | - $this->blocks = $app->make(BlocksController::class); |
|
| 47 | - $this->console = $app->make(Console::class); |
|
| 48 | - $this->editor = $app->make(EditorController::class); |
|
| 49 | - $this->listtable = $app->make(ListTableController::class); |
|
| 50 | - $this->main = $app->make(MainController::class); |
|
| 51 | - $this->menu = $app->make(MenuController::class); |
|
| 52 | - $this->notices = $app->make(NoticeController::class); |
|
| 53 | - $this->public = $app->make(PublicController::class); |
|
| 54 | - $this->rebusify = $app->make(RebusifyController::class); |
|
| 55 | - $this->review = $app->make(ReviewController::class); |
|
| 56 | - $this->router = $app->make(Router::class); |
|
| 57 | - $this->settings = $app->make(SettingsController::class); |
|
| 58 | - $this->taxonomy = $app->make(TaxonomyController::class); |
|
| 59 | - $this->translator = $app->make(TranslationController::class); |
|
| 60 | - $this->welcome = $app->make(WelcomeController::class); |
|
| 61 | - } |
|
| 43 | + public function __construct(Application $app ) { |
|
| 44 | + $this->app = $app; |
|
| 45 | + $this->admin = $app->make(AdminController::class); |
|
| 46 | + $this->blocks = $app->make(BlocksController::class); |
|
| 47 | + $this->console = $app->make(Console::class); |
|
| 48 | + $this->editor = $app->make(EditorController::class); |
|
| 49 | + $this->listtable = $app->make(ListTableController::class); |
|
| 50 | + $this->main = $app->make(MainController::class); |
|
| 51 | + $this->menu = $app->make(MenuController::class); |
|
| 52 | + $this->notices = $app->make(NoticeController::class); |
|
| 53 | + $this->public = $app->make(PublicController::class); |
|
| 54 | + $this->rebusify = $app->make(RebusifyController::class); |
|
| 55 | + $this->review = $app->make(ReviewController::class); |
|
| 56 | + $this->router = $app->make(Router::class); |
|
| 57 | + $this->settings = $app->make(SettingsController::class); |
|
| 58 | + $this->taxonomy = $app->make(TaxonomyController::class); |
|
| 59 | + $this->translator = $app->make(TranslationController::class); |
|
| 60 | + $this->welcome = $app->make(WelcomeController::class); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function run() |
|
| 67 | - { |
|
| 68 | - add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
| 69 | - add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
| 70 | - add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
| 71 | - add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
| 72 | - add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
| 73 | - add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
| 74 | - add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
| 75 | - add_action('upgrader_process_complete', [$this->app, 'upgraded'], 10, 2); |
|
| 76 | - add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
| 77 | - add_action('init', [$this->blocks, 'registerBlocks']); |
|
| 78 | - add_action('admin_footer', [$this->console, 'logOnce']); |
|
| 79 | - add_action('wp_footer', [$this->console, 'logOnce']); |
|
| 80 | - add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
| 81 | - add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
| 82 | - add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
| 83 | - add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
| 84 | - add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
| 85 | - add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
| 86 | - add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
| 87 | - add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
| 88 | - add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
| 89 | - add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
| 90 | - add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
| 91 | - add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
| 92 | - add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
| 93 | - add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
| 94 | - add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
| 95 | - add_action('init', [$this->main, 'registerPostType'], 8); |
|
| 96 | - add_action('init', [$this->main, 'registerShortcodes']); |
|
| 97 | - add_action('init', [$this->main, 'registerTaxonomy']); |
|
| 98 | - add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
| 99 | - add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
| 100 | - add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
| 101 | - add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
| 102 | - add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
| 103 | - add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
| 104 | - add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
| 105 | - add_action('wp_footer', [$this->public, 'renderSchema']); |
|
| 106 | - add_action('site-reviews/review/created', [$this->rebusify, 'onCreated']); |
|
| 107 | - add_action('site-reviews/review/reverted', [$this->rebusify, 'onReverted']); |
|
| 108 | - add_action('site-reviews/review/saved', [$this->rebusify, 'onSaved']); |
|
| 109 | - add_action('updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3); |
|
| 110 | - add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
| 111 | - add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
| 112 | - add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
| 113 | - add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
| 114 | - add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
| 115 | - add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
| 116 | - add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 117 | - add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 118 | - add_action('init', [$this->router, 'routePublicPostRequest']); |
|
| 119 | - add_action('admin_init', [$this->settings, 'registerSettings']); |
|
| 120 | - add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
| 121 | - add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
| 122 | - add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
| 123 | - add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
| 124 | - add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
| 125 | - add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
| 126 | - add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
| 127 | - add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
| 128 | - add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
| 129 | - } |
|
| 63 | + /** |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function run() |
|
| 67 | + { |
|
| 68 | + add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
| 69 | + add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
| 70 | + add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
| 71 | + add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
| 72 | + add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
| 73 | + add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
| 74 | + add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
| 75 | + add_action('upgrader_process_complete', [$this->app, 'upgraded'], 10, 2); |
|
| 76 | + add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
| 77 | + add_action('init', [$this->blocks, 'registerBlocks']); |
|
| 78 | + add_action('admin_footer', [$this->console, 'logOnce']); |
|
| 79 | + add_action('wp_footer', [$this->console, 'logOnce']); |
|
| 80 | + add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
| 81 | + add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
| 82 | + add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
| 83 | + add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
| 84 | + add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
| 85 | + add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
| 86 | + add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
| 87 | + add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
| 88 | + add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
| 89 | + add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
| 90 | + add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
| 91 | + add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
| 92 | + add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
| 93 | + add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
| 94 | + add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
| 95 | + add_action('init', [$this->main, 'registerPostType'], 8); |
|
| 96 | + add_action('init', [$this->main, 'registerShortcodes']); |
|
| 97 | + add_action('init', [$this->main, 'registerTaxonomy']); |
|
| 98 | + add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
| 99 | + add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
| 100 | + add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
| 101 | + add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
| 102 | + add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
| 103 | + add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
| 104 | + add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
| 105 | + add_action('wp_footer', [$this->public, 'renderSchema']); |
|
| 106 | + add_action('site-reviews/review/created', [$this->rebusify, 'onCreated']); |
|
| 107 | + add_action('site-reviews/review/reverted', [$this->rebusify, 'onReverted']); |
|
| 108 | + add_action('site-reviews/review/saved', [$this->rebusify, 'onSaved']); |
|
| 109 | + add_action('updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3); |
|
| 110 | + add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
| 111 | + add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
| 112 | + add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
| 113 | + add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
| 114 | + add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
| 115 | + add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
| 116 | + add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 117 | + add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 118 | + add_action('init', [$this->router, 'routePublicPostRequest']); |
|
| 119 | + add_action('admin_init', [$this->settings, 'registerSettings']); |
|
| 120 | + add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
| 121 | + add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
| 122 | + add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
| 123 | + add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
| 124 | + add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
| 125 | + add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
| 126 | + add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
| 127 | + add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
| 128 | + add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -40,24 +40,24 @@ discard block |
||
| 40 | 40 | protected $translator; |
| 41 | 41 | protected $welcome; |
| 42 | 42 | |
| 43 | - public function __construct(Application $app ) { |
|
| 43 | + public function __construct( Application $app ) { |
|
| 44 | 44 | $this->app = $app; |
| 45 | - $this->admin = $app->make(AdminController::class); |
|
| 46 | - $this->blocks = $app->make(BlocksController::class); |
|
| 47 | - $this->console = $app->make(Console::class); |
|
| 48 | - $this->editor = $app->make(EditorController::class); |
|
| 49 | - $this->listtable = $app->make(ListTableController::class); |
|
| 50 | - $this->main = $app->make(MainController::class); |
|
| 51 | - $this->menu = $app->make(MenuController::class); |
|
| 52 | - $this->notices = $app->make(NoticeController::class); |
|
| 53 | - $this->public = $app->make(PublicController::class); |
|
| 54 | - $this->rebusify = $app->make(RebusifyController::class); |
|
| 55 | - $this->review = $app->make(ReviewController::class); |
|
| 56 | - $this->router = $app->make(Router::class); |
|
| 57 | - $this->settings = $app->make(SettingsController::class); |
|
| 58 | - $this->taxonomy = $app->make(TaxonomyController::class); |
|
| 59 | - $this->translator = $app->make(TranslationController::class); |
|
| 60 | - $this->welcome = $app->make(WelcomeController::class); |
|
| 45 | + $this->admin = $app->make( AdminController::class ); |
|
| 46 | + $this->blocks = $app->make( BlocksController::class ); |
|
| 47 | + $this->console = $app->make( Console::class ); |
|
| 48 | + $this->editor = $app->make( EditorController::class ); |
|
| 49 | + $this->listtable = $app->make( ListTableController::class ); |
|
| 50 | + $this->main = $app->make( MainController::class ); |
|
| 51 | + $this->menu = $app->make( MenuController::class ); |
|
| 52 | + $this->notices = $app->make( NoticeController::class ); |
|
| 53 | + $this->public = $app->make( PublicController::class ); |
|
| 54 | + $this->rebusify = $app->make( RebusifyController::class ); |
|
| 55 | + $this->review = $app->make( ReviewController::class ); |
|
| 56 | + $this->router = $app->make( Router::class ); |
|
| 57 | + $this->settings = $app->make( SettingsController::class ); |
|
| 58 | + $this->taxonomy = $app->make( TaxonomyController::class ); |
|
| 59 | + $this->translator = $app->make( TranslationController::class ); |
|
| 60 | + $this->welcome = $app->make( WelcomeController::class ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,66 +65,66 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function run() |
| 67 | 67 | { |
| 68 | - add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
| 69 | - add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
| 70 | - add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
| 71 | - add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
| 72 | - add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
| 73 | - add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
| 74 | - add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
| 75 | - add_action('upgrader_process_complete', [$this->app, 'upgraded'], 10, 2); |
|
| 76 | - add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
| 77 | - add_action('init', [$this->blocks, 'registerBlocks']); |
|
| 78 | - add_action('admin_footer', [$this->console, 'logOnce']); |
|
| 79 | - add_action('wp_footer', [$this->console, 'logOnce']); |
|
| 80 | - add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
| 81 | - add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
| 82 | - add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
| 83 | - add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
| 84 | - add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
| 85 | - add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
| 86 | - add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
| 87 | - add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
| 88 | - add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
| 89 | - add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
| 90 | - add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
| 91 | - add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
| 92 | - add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
| 93 | - add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
| 94 | - add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
| 95 | - add_action('init', [$this->main, 'registerPostType'], 8); |
|
| 96 | - add_action('init', [$this->main, 'registerShortcodes']); |
|
| 97 | - add_action('init', [$this->main, 'registerTaxonomy']); |
|
| 98 | - add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
| 99 | - add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
| 100 | - add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
| 101 | - add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
| 102 | - add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
| 103 | - add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
| 104 | - add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
| 105 | - add_action('wp_footer', [$this->public, 'renderSchema']); |
|
| 106 | - add_action('site-reviews/review/created', [$this->rebusify, 'onCreated']); |
|
| 107 | - add_action('site-reviews/review/reverted', [$this->rebusify, 'onReverted']); |
|
| 108 | - add_action('site-reviews/review/saved', [$this->rebusify, 'onSaved']); |
|
| 109 | - add_action('updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3); |
|
| 110 | - add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
| 111 | - add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
| 112 | - add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
| 113 | - add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
| 114 | - add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
| 115 | - add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
| 116 | - add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 117 | - add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
| 118 | - add_action('init', [$this->router, 'routePublicPostRequest']); |
|
| 119 | - add_action('admin_init', [$this->settings, 'registerSettings']); |
|
| 120 | - add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
| 121 | - add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
| 122 | - add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
| 123 | - add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
| 124 | - add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
| 125 | - add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
| 126 | - add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
| 127 | - add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
| 128 | - add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
| 68 | + add_action( 'admin_enqueue_scripts', [$this->admin, 'enqueueAssets'] ); |
|
| 69 | + add_action( 'admin_init', [$this->admin, 'registerTinymcePopups'] ); |
|
| 70 | + add_action( 'media_buttons', [$this->admin, 'renderTinymceButton'], 11 ); |
|
| 71 | + add_action( 'plugins_loaded', [$this->app, 'getDefaults'], 11 ); |
|
| 72 | + add_action( 'plugins_loaded', [$this->app, 'registerAddons'] ); |
|
| 73 | + add_action( 'plugins_loaded', [$this->app, 'registerLanguages'] ); |
|
| 74 | + add_action( 'plugins_loaded', [$this->app, 'registerReviewTypes'] ); |
|
| 75 | + add_action( 'upgrader_process_complete', [$this->app, 'upgraded'], 10, 2 ); |
|
| 76 | + add_action( 'init', [$this->blocks, 'registerAssets'], 9 ); |
|
| 77 | + add_action( 'init', [$this->blocks, 'registerBlocks'] ); |
|
| 78 | + add_action( 'admin_footer', [$this->console, 'logOnce'] ); |
|
| 79 | + add_action( 'wp_footer', [$this->console, 'logOnce'] ); |
|
| 80 | + add_action( 'add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes'] ); |
|
| 81 | + add_action( 'admin_print_scripts', [$this->editor, 'removeAutosave'], 999 ); |
|
| 82 | + add_action( 'admin_menu', [$this->editor, 'removeMetaBoxes'] ); |
|
| 83 | + add_action( 'current_screen', [$this->editor, 'removePostTypeSupport'] ); |
|
| 84 | + add_action( 'post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox'] ); |
|
| 85 | + add_action( 'admin_head', [$this->editor, 'renderReviewFields'] ); |
|
| 86 | + add_action( 'admin_action_revert', [$this->editor, 'revertReview'] ); |
|
| 87 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3 ); |
|
| 88 | + add_action( 'admin_action_approve', [$this->listtable, 'approve'] ); |
|
| 89 | + add_action( 'bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2 ); |
|
| 90 | + add_action( 'restrict_manage_posts', [$this->listtable, 'renderColumnFilters'] ); |
|
| 91 | + add_action( 'manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2 ); |
|
| 92 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields'] ); |
|
| 93 | + add_action( 'pre_get_posts', [$this->listtable, 'setQueryForColumn'] ); |
|
| 94 | + add_action( 'admin_action_unapprove', [$this->listtable, 'unapprove'] ); |
|
| 95 | + add_action( 'init', [$this->main, 'registerPostType'], 8 ); |
|
| 96 | + add_action( 'init', [$this->main, 'registerShortcodes'] ); |
|
| 97 | + add_action( 'init', [$this->main, 'registerTaxonomy'] ); |
|
| 98 | + add_action( 'widgets_init', [$this->main, 'registerWidgets'] ); |
|
| 99 | + add_action( 'admin_menu', [$this->menu, 'registerMenuCount'] ); |
|
| 100 | + add_action( 'admin_menu', [$this->menu, 'registerSubMenus'] ); |
|
| 101 | + add_action( 'admin_init', [$this->menu, 'setCustomPermissions'], 999 ); |
|
| 102 | + add_action( 'admin_notices', [$this->notices, 'filterAdminNotices'] ); |
|
| 103 | + add_action( 'wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999 ); |
|
| 104 | + add_filter( 'site-reviews/builder', [$this->public, 'modifyBuilder'] ); |
|
| 105 | + add_action( 'wp_footer', [$this->public, 'renderSchema'] ); |
|
| 106 | + add_action( 'site-reviews/review/created', [$this->rebusify, 'onCreated'] ); |
|
| 107 | + add_action( 'site-reviews/review/reverted', [$this->rebusify, 'onReverted'] ); |
|
| 108 | + add_action( 'site-reviews/review/saved', [$this->rebusify, 'onSaved'] ); |
|
| 109 | + add_action( 'updated_postmeta', [$this->rebusify, 'onUpdatedMeta'], 10, 3 ); |
|
| 110 | + add_action( 'set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6 ); |
|
| 111 | + add_action( 'transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3 ); |
|
| 112 | + add_action( 'site-reviews/review/created', [$this->review, 'onAfterCreate'] ); |
|
| 113 | + add_action( 'before_delete_post', [$this->review, 'onBeforeDelete'] ); |
|
| 114 | + add_action( 'update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4 ); |
|
| 115 | + add_action( 'admin_init', [$this->router, 'routeAdminPostRequest'] ); |
|
| 116 | + add_action( 'wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
| 117 | + add_action( 'wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
| 118 | + add_action( 'init', [$this->router, 'routePublicPostRequest'] ); |
|
| 119 | + add_action( 'admin_init', [$this->settings, 'registerSettings'] ); |
|
| 120 | + add_action( Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents'] ); |
|
| 121 | + add_action( Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents'] ); |
|
| 122 | + add_action( Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents'] ); |
|
| 123 | + add_action( Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents'] ); |
|
| 124 | + add_action( 'restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9 ); |
|
| 125 | + add_action( 'set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6 ); |
|
| 126 | + add_action( 'admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels'] ); |
|
| 127 | + add_action( 'activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2 ); |
|
| 128 | + add_action( 'admin_menu', [$this->welcome, 'registerPage'] ); |
|
| 129 | 129 | } |
| 130 | 130 | } |
@@ -40,7 +40,8 @@ |
||
| 40 | 40 | protected $translator; |
| 41 | 41 | protected $welcome; |
| 42 | 42 | |
| 43 | - public function __construct(Application $app ) { |
|
| 43 | + public function __construct(Application $app ) |
|
| 44 | + { |
|
| 44 | 45 | $this->app = $app; |
| 45 | 46 | $this->admin = $app->make(AdminController::class); |
| 46 | 47 | $this->blocks = $app->make(BlocksController::class); |
@@ -15,73 +15,73 @@ |
||
| 15 | 15 | |
| 16 | 16 | class Filters implements HooksContract |
| 17 | 17 | { |
| 18 | - protected $admin; |
|
| 19 | - protected $app; |
|
| 20 | - protected $basename; |
|
| 21 | - protected $blocks; |
|
| 22 | - protected $editor; |
|
| 23 | - protected $listtable; |
|
| 24 | - protected $public; |
|
| 25 | - protected $rebusify; |
|
| 26 | - protected $translator; |
|
| 27 | - protected $welcome; |
|
| 18 | + protected $admin; |
|
| 19 | + protected $app; |
|
| 20 | + protected $basename; |
|
| 21 | + protected $blocks; |
|
| 22 | + protected $editor; |
|
| 23 | + protected $listtable; |
|
| 24 | + protected $public; |
|
| 25 | + protected $rebusify; |
|
| 26 | + protected $translator; |
|
| 27 | + protected $welcome; |
|
| 28 | 28 | |
| 29 | - public function __construct(Application $app) |
|
| 30 | - { |
|
| 31 | - $this->app = $app; |
|
| 32 | - $this->admin = $app->make(AdminController::class); |
|
| 33 | - $this->basename = plugin_basename($app->file); |
|
| 34 | - $this->blocks = $app->make(BlocksController::class); |
|
| 35 | - $this->editor = $app->make(EditorController::class); |
|
| 36 | - $this->listtable = $app->make(ListTableController::class); |
|
| 37 | - $this->public = $app->make(PublicController::class); |
|
| 38 | - $this->rebusify = $app->make(RebusifyController::class); |
|
| 39 | - $this->translator = $app->make(TranslationController::class); |
|
| 40 | - $this->welcome = $app->make(WelcomeController::class); |
|
| 41 | - } |
|
| 29 | + public function __construct(Application $app) |
|
| 30 | + { |
|
| 31 | + $this->app = $app; |
|
| 32 | + $this->admin = $app->make(AdminController::class); |
|
| 33 | + $this->basename = plugin_basename($app->file); |
|
| 34 | + $this->blocks = $app->make(BlocksController::class); |
|
| 35 | + $this->editor = $app->make(EditorController::class); |
|
| 36 | + $this->listtable = $app->make(ListTableController::class); |
|
| 37 | + $this->public = $app->make(PublicController::class); |
|
| 38 | + $this->rebusify = $app->make(RebusifyController::class); |
|
| 39 | + $this->translator = $app->make(TranslationController::class); |
|
| 40 | + $this->welcome = $app->make(WelcomeController::class); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function run() |
|
| 47 | - { |
|
| 48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
| 49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
| 50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
| 51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
| 52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
| 53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
| 54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
| 55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
| 56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
| 57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
| 58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
| 59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
| 60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
| 61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
| 62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
| 63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
| 64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
| 65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
| 66 | - add_filter('query_vars', [$this->public, 'filterQueryVars']); |
|
| 67 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
| 68 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
| 69 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
| 70 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
| 71 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
| 72 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
| 73 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
| 74 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
| 75 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
| 76 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
| 77 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
| 78 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
| 79 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
| 80 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 81 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 82 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
| 83 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
| 84 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
| 85 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
| 86 | - } |
|
| 43 | + /** |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function run() |
|
| 47 | + { |
|
| 48 | + add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
| 49 | + add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
| 50 | + add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
| 51 | + add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
| 52 | + add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
| 53 | + add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
| 54 | + add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
| 55 | + add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
| 56 | + add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
| 57 | + add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
| 58 | + add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
| 59 | + add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
| 60 | + add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
| 61 | + add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
| 62 | + add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
| 63 | + add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
| 64 | + add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
| 65 | + add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
| 66 | + add_filter('query_vars', [$this->public, 'filterQueryVars']); |
|
| 67 | + add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
| 68 | + add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
| 69 | + add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
| 70 | + add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
| 71 | + add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
| 72 | + add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
| 73 | + add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
| 74 | + add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
| 75 | + add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
| 76 | + add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
| 77 | + add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
| 78 | + add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
| 79 | + add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
| 80 | + add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 81 | + add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 82 | + add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
| 83 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
| 84 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
| 85 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -26,18 +26,18 @@ discard block |
||
| 26 | 26 | protected $translator; |
| 27 | 27 | protected $welcome; |
| 28 | 28 | |
| 29 | - public function __construct(Application $app) |
|
| 29 | + public function __construct( Application $app ) |
|
| 30 | 30 | { |
| 31 | 31 | $this->app = $app; |
| 32 | - $this->admin = $app->make(AdminController::class); |
|
| 33 | - $this->basename = plugin_basename($app->file); |
|
| 34 | - $this->blocks = $app->make(BlocksController::class); |
|
| 35 | - $this->editor = $app->make(EditorController::class); |
|
| 36 | - $this->listtable = $app->make(ListTableController::class); |
|
| 37 | - $this->public = $app->make(PublicController::class); |
|
| 38 | - $this->rebusify = $app->make(RebusifyController::class); |
|
| 39 | - $this->translator = $app->make(TranslationController::class); |
|
| 40 | - $this->welcome = $app->make(WelcomeController::class); |
|
| 32 | + $this->admin = $app->make( AdminController::class ); |
|
| 33 | + $this->basename = plugin_basename( $app->file ); |
|
| 34 | + $this->blocks = $app->make( BlocksController::class ); |
|
| 35 | + $this->editor = $app->make( EditorController::class ); |
|
| 36 | + $this->listtable = $app->make( ListTableController::class ); |
|
| 37 | + $this->public = $app->make( PublicController::class ); |
|
| 38 | + $this->rebusify = $app->make( RebusifyController::class ); |
|
| 39 | + $this->translator = $app->make( TranslationController::class ); |
|
| 40 | + $this->welcome = $app->make( WelcomeController::class ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -45,43 +45,43 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function run() |
| 47 | 47 | { |
| 48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
| 49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
| 50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
| 51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
| 52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
| 53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
| 54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
| 55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
| 56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
| 57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
| 58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
| 59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
| 60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
| 61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
| 62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
| 63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
| 64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
| 65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
| 66 | - add_filter('query_vars', [$this->public, 'filterQueryVars']); |
|
| 67 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
| 68 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
| 69 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
| 70 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
| 71 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
| 72 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
| 73 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
| 74 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
| 75 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
| 76 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
| 77 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
| 78 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
| 79 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
| 80 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 81 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
| 82 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
| 83 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
| 84 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
| 85 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
| 48 | + add_filter( 'map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2 ); |
|
| 49 | + add_filter( 'mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15 ); |
|
| 50 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks'] ); |
|
| 51 | + add_filter( 'dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems'] ); |
|
| 52 | + add_filter( 'block_categories', [$this->blocks, 'filterBlockCategories'] ); |
|
| 53 | + add_filter( 'classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2 ); |
|
| 54 | + add_filter( 'use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2 ); |
|
| 55 | + add_filter( 'wp_editor_settings', [$this->editor, 'filterEditorSettings'] ); |
|
| 56 | + add_filter( 'the_editor', [$this->editor, 'filterEditorTextarea'] ); |
|
| 57 | + add_filter( 'is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3 ); |
|
| 58 | + add_filter( 'post_updated_messages', [$this->editor, 'filterUpdateMessages'] ); |
|
| 59 | + add_filter( 'manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType'] ); |
|
| 60 | + add_filter( 'post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2 ); |
|
| 61 | + add_filter( 'default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2 ); |
|
| 62 | + add_filter( 'post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2 ); |
|
| 63 | + add_filter( 'manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns'] ); |
|
| 64 | + add_filter( 'script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2 ); |
|
| 65 | + add_filter( 'site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11 ); |
|
| 66 | + add_filter( 'query_vars', [$this->public, 'filterQueryVars'] ); |
|
| 67 | + add_filter( 'site-reviews/render/view', [$this->public, 'filterRenderView'] ); |
|
| 68 | + add_filter( 'site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback'] ); |
|
| 69 | + add_filter( 'site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3 ); |
|
| 70 | + add_filter( 'bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2 ); |
|
| 71 | + add_filter( 'gettext', [$this->translator, 'filterGettext'], 9, 3 ); |
|
| 72 | + add_filter( 'site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2 ); |
|
| 73 | + add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4 ); |
|
| 74 | + add_filter( 'site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3 ); |
|
| 75 | + add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 9, 5 ); |
|
| 76 | + add_filter( 'site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4 ); |
|
| 77 | + add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6 ); |
|
| 78 | + add_filter( 'site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5 ); |
|
| 79 | + add_filter( 'display_post_states', [$this->translator, 'filterPostStates'], 10, 2 ); |
|
| 80 | + add_filter( 'site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
| 81 | + add_filter( 'site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
| 82 | + add_filter( 'site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4 ); |
|
| 83 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9 ); |
|
| 84 | + add_filter( 'admin_title', [$this->welcome, 'filterAdminTitle'] ); |
|
| 85 | + add_filter( 'admin_footer_text', [$this->welcome, 'filterFooterText'] ); |
|
| 86 | 86 | } |
| 87 | 87 | } |
@@ -11,272 +11,272 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Translation |
| 13 | 13 | { |
| 14 | - const SEARCH_THRESHOLD = 3; |
|
| 14 | + const SEARCH_THRESHOLD = 3; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - protected $entries; |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + protected $entries; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $results; |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $results; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Returns all saved custom translations with translation context. |
|
| 28 | - * @return array |
|
| 29 | - */ |
|
| 30 | - public function all() |
|
| 31 | - { |
|
| 32 | - $translations = $this->translations(); |
|
| 33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 37 | - : ''; |
|
| 38 | - }); |
|
| 39 | - return $translations; |
|
| 40 | - } |
|
| 26 | + /** |
|
| 27 | + * Returns all saved custom translations with translation context. |
|
| 28 | + * @return array |
|
| 29 | + */ |
|
| 30 | + public function all() |
|
| 31 | + { |
|
| 32 | + $translations = $this->translations(); |
|
| 33 | + $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | + array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | + $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | + ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 37 | + : ''; |
|
| 38 | + }); |
|
| 39 | + return $translations; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function entries() |
|
| 46 | - { |
|
| 47 | - if (!isset($this->entries)) { |
|
| 48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 51 | - $this->entries = $entries; |
|
| 52 | - } |
|
| 53 | - return $this->entries; |
|
| 54 | - } |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function entries() |
|
| 46 | + { |
|
| 47 | + if (!isset($this->entries)) { |
|
| 48 | + $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | + $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | + $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 51 | + $this->entries = $entries; |
|
| 52 | + } |
|
| 53 | + return $this->entries; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param array|null $entriesToExclude |
|
| 58 | - * @param array|null $entries |
|
| 59 | - * @return static |
|
| 60 | - */ |
|
| 61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
| 62 | - { |
|
| 63 | - return $this->filter($entriesToExclude, $entries, false); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * @param array|null $entriesToExclude |
|
| 58 | + * @param array|null $entries |
|
| 59 | + * @return static |
|
| 60 | + */ |
|
| 61 | + public function exclude($entriesToExclude = null, $entries = null) |
|
| 62 | + { |
|
| 63 | + return $this->filter($entriesToExclude, $entries, false); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $potFile |
|
| 68 | - * @return array |
|
| 69 | - */ |
|
| 70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 71 | - { |
|
| 72 | - try { |
|
| 73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | - foreach ($potEntries as $key => $entry) { |
|
| 75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 76 | - } |
|
| 77 | - } catch (Exception $e) { |
|
| 78 | - glsr_log()->error($e->getMessage()); |
|
| 79 | - } |
|
| 80 | - return $entries; |
|
| 81 | - } |
|
| 66 | + /** |
|
| 67 | + * @param string $potFile |
|
| 68 | + * @return array |
|
| 69 | + */ |
|
| 70 | + public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 71 | + { |
|
| 72 | + try { |
|
| 73 | + $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | + foreach ($potEntries as $key => $entry) { |
|
| 75 | + $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 76 | + } |
|
| 77 | + } catch (Exception $e) { |
|
| 78 | + glsr_log()->error($e->getMessage()); |
|
| 79 | + } |
|
| 80 | + return $entries; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param array|null $filterWith |
|
| 85 | - * @param array|null $entries |
|
| 86 | - * @param bool $intersect |
|
| 87 | - * @return static |
|
| 88 | - */ |
|
| 89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 90 | - { |
|
| 91 | - if (!is_array($entries)) { |
|
| 92 | - $entries = $this->results; |
|
| 93 | - } |
|
| 94 | - if (!is_array($filterWith)) { |
|
| 95 | - $filterWith = $this->translations(); |
|
| 96 | - } |
|
| 97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 98 | - $this->results = $intersect |
|
| 99 | - ? array_intersect_key($entries, $keys) |
|
| 100 | - : array_diff_key($entries, $keys); |
|
| 101 | - return $this; |
|
| 102 | - } |
|
| 83 | + /** |
|
| 84 | + * @param array|null $filterWith |
|
| 85 | + * @param array|null $entries |
|
| 86 | + * @param bool $intersect |
|
| 87 | + * @return static |
|
| 88 | + */ |
|
| 89 | + public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 90 | + { |
|
| 91 | + if (!is_array($entries)) { |
|
| 92 | + $entries = $this->results; |
|
| 93 | + } |
|
| 94 | + if (!is_array($filterWith)) { |
|
| 95 | + $filterWith = $this->translations(); |
|
| 96 | + } |
|
| 97 | + $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 98 | + $this->results = $intersect |
|
| 99 | + ? array_intersect_key($entries, $keys) |
|
| 100 | + : array_diff_key($entries, $keys); |
|
| 101 | + return $this; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param string $template |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function render($template, array $entry) |
|
| 109 | - { |
|
| 110 | - $data = array_combine( |
|
| 111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 112 | - $entry |
|
| 113 | - ); |
|
| 114 | - $data['data.class'] = $data['data.error'] = ''; |
|
| 115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 116 | - $data['data.class'] = 'is-invalid'; |
|
| 117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 118 | - } |
|
| 119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | - 'context' => array_map('esc_html', $data), |
|
| 121 | - ]); |
|
| 122 | - } |
|
| 104 | + /** |
|
| 105 | + * @param string $template |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function render($template, array $entry) |
|
| 109 | + { |
|
| 110 | + $data = array_combine( |
|
| 111 | + array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 112 | + $entry |
|
| 113 | + ); |
|
| 114 | + $data['data.class'] = $data['data.error'] = ''; |
|
| 115 | + if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 116 | + $data['data.class'] = 'is-invalid'; |
|
| 117 | + $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 118 | + } |
|
| 119 | + return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | + 'context' => array_map('esc_html', $data), |
|
| 121 | + ]); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Returns a rendered string of all saved custom translations with translation context. |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function renderAll() |
|
| 129 | - { |
|
| 130 | - $rendered = ''; |
|
| 131 | - foreach ($this->all() as $index => $entry) { |
|
| 132 | - $entry['index'] = $index; |
|
| 133 | - $entry['prefix'] = OptionManager::databaseKey(); |
|
| 134 | - $rendered.= $this->render($entry['type'], $entry); |
|
| 135 | - } |
|
| 136 | - return $rendered; |
|
| 137 | - } |
|
| 124 | + /** |
|
| 125 | + * Returns a rendered string of all saved custom translations with translation context. |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function renderAll() |
|
| 129 | + { |
|
| 130 | + $rendered = ''; |
|
| 131 | + foreach ($this->all() as $index => $entry) { |
|
| 132 | + $entry['index'] = $index; |
|
| 133 | + $entry['prefix'] = OptionManager::databaseKey(); |
|
| 134 | + $rendered.= $this->render($entry['type'], $entry); |
|
| 135 | + } |
|
| 136 | + return $rendered; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @param bool $resetAfterRender |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function renderResults($resetAfterRender = true) |
|
| 144 | - { |
|
| 145 | - $rendered = ''; |
|
| 146 | - foreach ($this->results as $id => $entry) { |
|
| 147 | - $data = [ |
|
| 148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 149 | - 'id' => $id, |
|
| 150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 152 | - ]; |
|
| 153 | - $text = !empty($data['p1']) |
|
| 154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 155 | - : $data['s1']; |
|
| 156 | - $rendered.= $this->render('result', [ |
|
| 157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | - 'text' => wp_strip_all_tags($text), |
|
| 159 | - ]); |
|
| 160 | - } |
|
| 161 | - if ($resetAfterRender) { |
|
| 162 | - $this->reset(); |
|
| 163 | - } |
|
| 164 | - return $rendered; |
|
| 165 | - } |
|
| 139 | + /** |
|
| 140 | + * @param bool $resetAfterRender |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function renderResults($resetAfterRender = true) |
|
| 144 | + { |
|
| 145 | + $rendered = ''; |
|
| 146 | + foreach ($this->results as $id => $entry) { |
|
| 147 | + $data = [ |
|
| 148 | + 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 149 | + 'id' => $id, |
|
| 150 | + 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | + 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 152 | + ]; |
|
| 153 | + $text = !empty($data['p1']) |
|
| 154 | + ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 155 | + : $data['s1']; |
|
| 156 | + $rendered.= $this->render('result', [ |
|
| 157 | + 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | + 'text' => wp_strip_all_tags($text), |
|
| 159 | + ]); |
|
| 160 | + } |
|
| 161 | + if ($resetAfterRender) { |
|
| 162 | + $this->reset(); |
|
| 163 | + } |
|
| 164 | + return $rendered; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public function reset() |
|
| 171 | - { |
|
| 172 | - $this->results = []; |
|
| 173 | - } |
|
| 167 | + /** |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public function reset() |
|
| 171 | + { |
|
| 172 | + $this->results = []; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function results() |
|
| 179 | - { |
|
| 180 | - $results = $this->results; |
|
| 181 | - $this->reset(); |
|
| 182 | - return $results; |
|
| 183 | - } |
|
| 175 | + /** |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function results() |
|
| 179 | + { |
|
| 180 | + $results = $this->results; |
|
| 181 | + $this->reset(); |
|
| 182 | + return $results; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * @param string $needle |
|
| 187 | - * @return static |
|
| 188 | - */ |
|
| 189 | - public function search($needle = '') |
|
| 190 | - { |
|
| 191 | - $this->reset(); |
|
| 192 | - $needle = trim(strtolower($needle)); |
|
| 193 | - foreach ($this->entries() as $key => $entry) { |
|
| 194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | - if (in_array($needle, [$single, $plural])) { |
|
| 198 | - $this->results[$key] = $entry; |
|
| 199 | - } |
|
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | - $this->results[$key] = $entry; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return $this; |
|
| 205 | - } |
|
| 185 | + /** |
|
| 186 | + * @param string $needle |
|
| 187 | + * @return static |
|
| 188 | + */ |
|
| 189 | + public function search($needle = '') |
|
| 190 | + { |
|
| 191 | + $this->reset(); |
|
| 192 | + $needle = trim(strtolower($needle)); |
|
| 193 | + foreach ($this->entries() as $key => $entry) { |
|
| 194 | + $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | + $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | + if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | + if (in_array($needle, [$single, $plural])) { |
|
| 198 | + $this->results[$key] = $entry; |
|
| 199 | + } |
|
| 200 | + } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | + $this->results[$key] = $entry; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return $this; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Store the translations to avoid unnecessary loops. |
|
| 209 | - * @return array |
|
| 210 | - */ |
|
| 211 | - public function translations() |
|
| 212 | - { |
|
| 213 | - static $translations; |
|
| 214 | - if (empty($translations)) { |
|
| 215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
| 216 | - $translations = isset($settings['strings']) |
|
| 217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
| 218 | - : []; |
|
| 219 | - } |
|
| 220 | - return $translations; |
|
| 221 | - } |
|
| 207 | + /** |
|
| 208 | + * Store the translations to avoid unnecessary loops. |
|
| 209 | + * @return array |
|
| 210 | + */ |
|
| 211 | + public function translations() |
|
| 212 | + { |
|
| 213 | + static $translations; |
|
| 214 | + if (empty($translations)) { |
|
| 215 | + $settings = glsr(OptionManager::class)->get('settings'); |
|
| 216 | + $translations = isset($settings['strings']) |
|
| 217 | + ? $this->normalizeSettings((array) $settings['strings']) |
|
| 218 | + : []; |
|
| 219 | + } |
|
| 220 | + return $translations; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @param string $key |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - protected function getEntryString(array $entry, $key) |
|
| 228 | - { |
|
| 229 | - return isset($entry[$key]) |
|
| 230 | - ? implode('', (array) $entry[$key]) |
|
| 231 | - : ''; |
|
| 232 | - } |
|
| 223 | + /** |
|
| 224 | + * @param string $key |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + protected function getEntryString(array $entry, $key) |
|
| 228 | + { |
|
| 229 | + return isset($entry[$key]) |
|
| 230 | + ? implode('', (array) $entry[$key]) |
|
| 231 | + : ''; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * @return array |
|
| 236 | - */ |
|
| 237 | - protected function normalize(array $entries) |
|
| 238 | - { |
|
| 239 | - $keys = [ |
|
| 240 | - 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
| 241 | - ]; |
|
| 242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | - foreach ($keys as $key) { |
|
| 244 | - try { |
|
| 245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | - } catch (\TypeError $error) { |
|
| 247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - }); |
|
| 252 | - return $entries; |
|
| 253 | - } |
|
| 234 | + /** |
|
| 235 | + * @return array |
|
| 236 | + */ |
|
| 237 | + protected function normalize(array $entries) |
|
| 238 | + { |
|
| 239 | + $keys = [ |
|
| 240 | + 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
| 241 | + ]; |
|
| 242 | + array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | + foreach ($keys as $key) { |
|
| 244 | + try { |
|
| 245 | + $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | + } catch (\TypeError $error) { |
|
| 247 | + glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | + glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + }); |
|
| 252 | + return $entries; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @param string $key |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - protected function normalizeEntryString(array $entry, $key) |
|
| 260 | - { |
|
| 261 | - if (isset($entry[$key])) { |
|
| 262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
| 263 | - } |
|
| 264 | - return $entry; |
|
| 265 | - } |
|
| 255 | + /** |
|
| 256 | + * @param string $key |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + protected function normalizeEntryString(array $entry, $key) |
|
| 260 | + { |
|
| 261 | + if (isset($entry[$key])) { |
|
| 262 | + $entry[$key] = $this->getEntryString($entry, $key); |
|
| 263 | + } |
|
| 264 | + return $entry; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - protected function normalizeSettings(array $strings) |
|
| 271 | - { |
|
| 272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | - $strings = array_filter($strings, 'is_array'); |
|
| 274 | - foreach ($strings as &$string) { |
|
| 275 | - $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 276 | - $string = wp_parse_args($string, $defaultString); |
|
| 277 | - } |
|
| 278 | - return array_filter($strings, function ($string) { |
|
| 279 | - return !empty($string['id']); |
|
| 280 | - }); |
|
| 281 | - } |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + protected function normalizeSettings(array $strings) |
|
| 271 | + { |
|
| 272 | + $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | + $strings = array_filter($strings, 'is_array'); |
|
| 274 | + foreach ($strings as &$string) { |
|
| 275 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 276 | + $string = wp_parse_args($string, $defaultString); |
|
| 277 | + } |
|
| 278 | + return array_filter($strings, function ($string) { |
|
| 279 | + return !empty($string['id']); |
|
| 280 | + }); |
|
| 281 | + } |
|
| 282 | 282 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | public function all() |
| 31 | 31 | { |
| 32 | 32 | $translations = $this->translations(); |
| 33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
| 34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
| 35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
| 36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
| 33 | + $entries = $this->filter( $translations, $this->entries() )->results(); |
|
| 34 | + array_walk( $translations, function( &$entry ) use ($entries) { |
|
| 35 | + $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
|
| 36 | + ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
|
| 37 | 37 | : ''; |
| 38 | 38 | }); |
| 39 | 39 | return $translations; |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function entries() |
| 46 | 46 | { |
| 47 | - if (!isset($this->entries)) { |
|
| 48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
| 49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
| 50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
| 47 | + if( !isset($this->entries) ) { |
|
| 48 | + $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
|
| 49 | + $entries = $this->extractEntriesFromPotFile( $potFile ); |
|
| 50 | + $entries = apply_filters( 'site-reviews/translation/entries', $entries ); |
|
| 51 | 51 | $this->entries = $entries; |
| 52 | 52 | } |
| 53 | 53 | return $this->entries; |
@@ -58,24 +58,24 @@ discard block |
||
| 58 | 58 | * @param array|null $entries |
| 59 | 59 | * @return static |
| 60 | 60 | */ |
| 61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
| 61 | + public function exclude( $entriesToExclude = null, $entries = null ) |
|
| 62 | 62 | { |
| 63 | - return $this->filter($entriesToExclude, $entries, false); |
|
| 63 | + return $this->filter( $entriesToExclude, $entries, false ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * @param string $potFile |
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
| 70 | + public function extractEntriesFromPotFile( $potFile, array $entries = [] ) |
|
| 71 | 71 | { |
| 72 | 72 | try { |
| 73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
| 74 | - foreach ($potEntries as $key => $entry) { |
|
| 75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
| 73 | + $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
|
| 74 | + foreach( $potEntries as $key => $entry ) { |
|
| 75 | + $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry; |
|
| 76 | 76 | } |
| 77 | - } catch (Exception $e) { |
|
| 78 | - glsr_log()->error($e->getMessage()); |
|
| 77 | + } catch( Exception $e ) { |
|
| 78 | + glsr_log()->error( $e->getMessage() ); |
|
| 79 | 79 | } |
| 80 | 80 | return $entries; |
| 81 | 81 | } |
@@ -86,18 +86,18 @@ discard block |
||
| 86 | 86 | * @param bool $intersect |
| 87 | 87 | * @return static |
| 88 | 88 | */ |
| 89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
| 89 | + public function filter( $filterWith = null, $entries = null, $intersect = true ) |
|
| 90 | 90 | { |
| 91 | - if (!is_array($entries)) { |
|
| 91 | + if( !is_array( $entries ) ) { |
|
| 92 | 92 | $entries = $this->results; |
| 93 | 93 | } |
| 94 | - if (!is_array($filterWith)) { |
|
| 94 | + if( !is_array( $filterWith ) ) { |
|
| 95 | 95 | $filterWith = $this->translations(); |
| 96 | 96 | } |
| 97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
| 97 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); |
|
| 98 | 98 | $this->results = $intersect |
| 99 | - ? array_intersect_key($entries, $keys) |
|
| 100 | - : array_diff_key($entries, $keys); |
|
| 99 | + ? array_intersect_key( $entries, $keys ) |
|
| 100 | + : array_diff_key( $entries, $keys ); |
|
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,20 +105,20 @@ discard block |
||
| 105 | 105 | * @param string $template |
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | - public function render($template, array $entry) |
|
| 108 | + public function render( $template, array $entry ) |
|
| 109 | 109 | { |
| 110 | 110 | $data = array_combine( |
| 111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
| 111 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 112 | 112 | $entry |
| 113 | 113 | ); |
| 114 | 114 | $data['data.class'] = $data['data.error'] = ''; |
| 115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
| 115 | + if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) { |
|
| 116 | 116 | $data['data.class'] = 'is-invalid'; |
| 117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
| 117 | + $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
|
| 118 | 118 | } |
| 119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
| 120 | - 'context' => array_map('esc_html', $data), |
|
| 121 | - ]); |
|
| 119 | + return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
|
| 120 | + 'context' => array_map( 'esc_html', $data ), |
|
| 121 | + ] ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | public function renderAll() |
| 129 | 129 | { |
| 130 | 130 | $rendered = ''; |
| 131 | - foreach ($this->all() as $index => $entry) { |
|
| 131 | + foreach( $this->all() as $index => $entry ) { |
|
| 132 | 132 | $entry['index'] = $index; |
| 133 | 133 | $entry['prefix'] = OptionManager::databaseKey(); |
| 134 | - $rendered.= $this->render($entry['type'], $entry); |
|
| 134 | + $rendered .= $this->render( $entry['type'], $entry ); |
|
| 135 | 135 | } |
| 136 | 136 | return $rendered; |
| 137 | 137 | } |
@@ -140,25 +140,25 @@ discard block |
||
| 140 | 140 | * @param bool $resetAfterRender |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public function renderResults($resetAfterRender = true) |
|
| 143 | + public function renderResults( $resetAfterRender = true ) |
|
| 144 | 144 | { |
| 145 | 145 | $rendered = ''; |
| 146 | - foreach ($this->results as $id => $entry) { |
|
| 146 | + foreach( $this->results as $id => $entry ) { |
|
| 147 | 147 | $data = [ |
| 148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
| 148 | + 'desc' => $this->getEntryString( $entry, 'msgctxt' ), |
|
| 149 | 149 | 'id' => $id, |
| 150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
| 151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
| 150 | + 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
|
| 151 | + 's1' => $this->getEntryString( $entry, 'msgid' ), |
|
| 152 | 152 | ]; |
| 153 | 153 | $text = !empty($data['p1']) |
| 154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
| 154 | + ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
|
| 155 | 155 | : $data['s1']; |
| 156 | - $rendered.= $this->render('result', [ |
|
| 157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
| 158 | - 'text' => wp_strip_all_tags($text), |
|
| 159 | - ]); |
|
| 156 | + $rendered .= $this->render( 'result', [ |
|
| 157 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
| 158 | + 'text' => wp_strip_all_tags( $text ), |
|
| 159 | + ] ); |
|
| 160 | 160 | } |
| 161 | - if ($resetAfterRender) { |
|
| 161 | + if( $resetAfterRender ) { |
|
| 162 | 162 | $this->reset(); |
| 163 | 163 | } |
| 164 | 164 | return $rendered; |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * @param string $needle |
| 187 | 187 | * @return static |
| 188 | 188 | */ |
| 189 | - public function search($needle = '') |
|
| 189 | + public function search( $needle = '' ) |
|
| 190 | 190 | { |
| 191 | 191 | $this->reset(); |
| 192 | - $needle = trim(strtolower($needle)); |
|
| 193 | - foreach ($this->entries() as $key => $entry) { |
|
| 194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
| 195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
| 196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
| 197 | - if (in_array($needle, [$single, $plural])) { |
|
| 192 | + $needle = trim( strtolower( $needle ) ); |
|
| 193 | + foreach( $this->entries() as $key => $entry ) { |
|
| 194 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 195 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 196 | + if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
|
| 197 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 198 | 198 | $this->results[$key] = $entry; |
| 199 | 199 | } |
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 200 | + } elseif( Str::contains( sprintf( '%s %s', $single, $plural ), $needle ) ) { |
|
| 201 | 201 | $this->results[$key] = $entry; |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -211,10 +211,10 @@ discard block |
||
| 211 | 211 | public function translations() |
| 212 | 212 | { |
| 213 | 213 | static $translations; |
| 214 | - if (empty($translations)) { |
|
| 215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
| 214 | + if( empty($translations) ) { |
|
| 215 | + $settings = glsr( OptionManager::class )->get( 'settings' ); |
|
| 216 | 216 | $translations = isset($settings['strings']) |
| 217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
| 217 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
| 218 | 218 | : []; |
| 219 | 219 | } |
| 220 | 220 | return $translations; |
@@ -224,28 +224,28 @@ discard block |
||
| 224 | 224 | * @param string $key |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - protected function getEntryString(array $entry, $key) |
|
| 227 | + protected function getEntryString( array $entry, $key ) |
|
| 228 | 228 | { |
| 229 | 229 | return isset($entry[$key]) |
| 230 | - ? implode('', (array) $entry[$key]) |
|
| 230 | + ? implode( '', (array)$entry[$key] ) |
|
| 231 | 231 | : ''; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * @return array |
| 236 | 236 | */ |
| 237 | - protected function normalize(array $entries) |
|
| 237 | + protected function normalize( array $entries ) |
|
| 238 | 238 | { |
| 239 | 239 | $keys = [ |
| 240 | 240 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 241 | 241 | ]; |
| 242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
| 243 | - foreach ($keys as $key) { |
|
| 242 | + array_walk( $entries, function( &$entry ) use ($keys) { |
|
| 243 | + foreach( $keys as $key ) { |
|
| 244 | 244 | try { |
| 245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
| 246 | - } catch (\TypeError $error) { |
|
| 247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
| 248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
| 245 | + $entry = $this->normalizeEntryString( $entry, $key ); |
|
| 246 | + } catch( \TypeError $error ) { |
|
| 247 | + glsr_log()->once( 'error', 'Translation/normalize', $error ); |
|
| 248 | + glsr_log()->once( 'debug', 'Translation/normalize', $entry ); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | }); |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | * @param string $key |
| 257 | 257 | * @return array |
| 258 | 258 | */ |
| 259 | - protected function normalizeEntryString(array $entry, $key) |
|
| 259 | + protected function normalizeEntryString( array $entry, $key ) |
|
| 260 | 260 | { |
| 261 | - if (isset($entry[$key])) { |
|
| 262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
| 261 | + if( isset($entry[$key]) ) { |
|
| 262 | + $entry[$key] = $this->getEntryString( $entry, $key ); |
|
| 263 | 263 | } |
| 264 | 264 | return $entry; |
| 265 | 265 | } |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * @return array |
| 269 | 269 | */ |
| 270 | - protected function normalizeSettings(array $strings) |
|
| 270 | + protected function normalizeSettings( array $strings ) |
|
| 271 | 271 | { |
| 272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
| 273 | - $strings = array_filter($strings, 'is_array'); |
|
| 274 | - foreach ($strings as &$string) { |
|
| 272 | + $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
|
| 273 | + $strings = array_filter( $strings, 'is_array' ); |
|
| 274 | + foreach( $strings as &$string ) { |
|
| 275 | 275 | $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
| 276 | - $string = wp_parse_args($string, $defaultString); |
|
| 276 | + $string = wp_parse_args( $string, $defaultString ); |
|
| 277 | 277 | } |
| 278 | - return array_filter($strings, function ($string) { |
|
| 278 | + return array_filter( $strings, function( $string ) { |
|
| 279 | 279 | return !empty($string['id']); |
| 280 | 280 | }); |
| 281 | 281 | } |
@@ -74,7 +74,8 @@ discard block |
||
| 74 | 74 | foreach ($potEntries as $key => $entry) { |
| 75 | 75 | $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
| 76 | 76 | } |
| 77 | - } catch (Exception $e) { |
|
| 77 | + } |
|
| 78 | + catch (Exception $e) { |
|
| 78 | 79 | glsr_log()->error($e->getMessage()); |
| 79 | 80 | } |
| 80 | 81 | return $entries; |
@@ -197,7 +198,8 @@ discard block |
||
| 197 | 198 | if (in_array($needle, [$single, $plural])) { |
| 198 | 199 | $this->results[$key] = $entry; |
| 199 | 200 | } |
| 200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | + } |
|
| 202 | + elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
| 201 | 203 | $this->results[$key] = $entry; |
| 202 | 204 | } |
| 203 | 205 | } |
@@ -243,7 +245,8 @@ discard block |
||
| 243 | 245 | foreach ($keys as $key) { |
| 244 | 246 | try { |
| 245 | 247 | $entry = $this->normalizeEntryString($entry, $key); |
| 246 | - } catch (\TypeError $error) { |
|
| 248 | + } |
|
| 249 | + catch (\TypeError $error) { |
|
| 247 | 250 | glsr_log()->once('error', 'Translation/normalize', $error); |
| 248 | 251 | glsr_log()->once('debug', 'Translation/normalize', $entry); |
| 249 | 252 | } |