@@ -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 | } |
@@ -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 | } |
@@ -28,26 +28,26 @@ |
||
28 | 28 | /** |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function relative($date) |
|
31 | + public function relative( $date ) |
|
32 | 32 | { |
33 | - $diff = time() - strtotime($date); |
|
34 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
35 | - if ($diff > $timePeriod[0]) { |
|
33 | + $diff = time() - strtotime( $date ); |
|
34 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
35 | + if( $diff > $timePeriod[0] ) { |
|
36 | 36 | continue; |
37 | 37 | } |
38 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
38 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
39 | 39 | $relativeDates = [ |
40 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
41 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
42 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
43 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
44 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
45 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
46 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
40 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
41 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
42 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
43 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
44 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
45 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
46 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
47 | 47 | ]; |
48 | 48 | $relativeDate = $relativeDates[$i]; |
49 | - return Str::contains($relativeDate, '%s') |
|
50 | - ? sprintf($relativeDate, $unit) |
|
49 | + return Str::contains( $relativeDate, '%s' ) |
|
50 | + ? sprintf( $relativeDate, $unit ) |
|
51 | 51 | : $relativeDate; |
52 | 52 | } |
53 | 53 | } |
@@ -66,14 +66,14 @@ discard block |
||
66 | 66 | * @param mixed $data |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function validate($data, array $rules = []) |
|
69 | + public function validate( $data, array $rules = [] ) |
|
70 | 70 | { |
71 | - $this->normalizeData($data); |
|
72 | - $this->setRules($rules); |
|
73 | - foreach ($this->rules as $attribute => $rules) { |
|
74 | - foreach ($rules as $rule) { |
|
75 | - $this->validateAttribute($attribute, $rule); |
|
76 | - if ($this->shouldStopValidating($attribute)) { |
|
71 | + $this->normalizeData( $data ); |
|
72 | + $this->setRules( $rules ); |
|
73 | + foreach( $this->rules as $attribute => $rules ) { |
|
74 | + foreach( $rules as $rule ) { |
|
75 | + $this->validateAttribute( $attribute, $rule ); |
|
76 | + if( $this->shouldStopValidating( $attribute ) ) { |
|
77 | 77 | break; |
78 | 78 | } |
79 | 79 | } |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | * @return void |
89 | 89 | * @throws BadMethodCallException |
90 | 90 | */ |
91 | - public function validateAttribute($attribute, $rule) |
|
91 | + public function validateAttribute( $attribute, $rule ) |
|
92 | 92 | { |
93 | - list($rule, $parameters) = $this->parseRule($rule); |
|
94 | - if ('' == $rule) { |
|
93 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
94 | + if( '' == $rule ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | - $value = $this->getValue($attribute); |
|
98 | - if (!method_exists($this, $method = 'validate'.$rule)) { |
|
99 | - throw new BadMethodCallException("Method [$method] does not exist."); |
|
97 | + $value = $this->getValue( $attribute ); |
|
98 | + if( !method_exists( $this, $method = 'validate'.$rule ) ) { |
|
99 | + throw new BadMethodCallException( "Method [$method] does not exist." ); |
|
100 | 100 | } |
101 | - if (!$this->$method($value, $attribute, $parameters)) { |
|
102 | - $this->addFailure($attribute, $rule, $parameters); |
|
101 | + if( !$this->$method( $value, $attribute, $parameters ) ) { |
|
102 | + $this->addFailure( $attribute, $rule, $parameters ); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | * @param string $rule |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - protected function addError($attribute, $rule, array $parameters) |
|
112 | + protected function addError( $attribute, $rule, array $parameters ) |
|
113 | 113 | { |
114 | - $message = $this->getMessage($attribute, $rule, $parameters); |
|
114 | + $message = $this->getMessage( $attribute, $rule, $parameters ); |
|
115 | 115 | $this->errors[$attribute][] = $message; |
116 | 116 | } |
117 | 117 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param string $rule |
122 | 122 | * @return void |
123 | 123 | */ |
124 | - protected function addFailure($attribute, $rule, array $parameters) |
|
124 | + protected function addFailure( $attribute, $rule, array $parameters ) |
|
125 | 125 | { |
126 | - $this->addError($attribute, $rule, $parameters); |
|
126 | + $this->addError( $attribute, $rule, $parameters ); |
|
127 | 127 | $this->failedRules[$attribute][$rule] = $parameters; |
128 | 128 | } |
129 | 129 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param string $attribute |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - protected function getAttributeType($attribute) |
|
135 | + protected function getAttributeType( $attribute ) |
|
136 | 136 | { |
137 | - return !$this->hasRule($attribute, $this->numericRules) |
|
137 | + return !$this->hasRule( $attribute, $this->numericRules ) |
|
138 | 138 | ? 'length' |
139 | 139 | : ''; |
140 | 140 | } |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | * @param string $rule |
146 | 146 | * @return string|null |
147 | 147 | */ |
148 | - protected function getMessage($attribute, $rule, array $parameters) |
|
148 | + protected function getMessage( $attribute, $rule, array $parameters ) |
|
149 | 149 | { |
150 | - if (in_array($rule, $this->sizeRules)) { |
|
151 | - return $this->getSizeMessage($attribute, $rule, $parameters); |
|
150 | + if( in_array( $rule, $this->sizeRules ) ) { |
|
151 | + return $this->getSizeMessage( $attribute, $rule, $parameters ); |
|
152 | 152 | } |
153 | - $lowerRule = Str::snakeCase($rule); |
|
154 | - return $this->translator($lowerRule, $parameters); |
|
153 | + $lowerRule = Str::snakeCase( $rule ); |
|
154 | + return $this->translator( $lowerRule, $parameters ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | * @param string|array $rules |
161 | 161 | * @return array|null |
162 | 162 | */ |
163 | - protected function getRule($attribute, $rules) |
|
163 | + protected function getRule( $attribute, $rules ) |
|
164 | 164 | { |
165 | - if (!array_key_exists($attribute, $this->rules)) { |
|
165 | + if( !array_key_exists( $attribute, $this->rules ) ) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | - $rules = (array) $rules; |
|
169 | - foreach ($this->rules[$attribute] as $rule) { |
|
170 | - list($rule, $parameters) = $this->parseRule($rule); |
|
171 | - if (in_array($rule, $rules)) { |
|
168 | + $rules = (array)$rules; |
|
169 | + foreach( $this->rules[$attribute] as $rule ) { |
|
170 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
171 | + if( in_array( $rule, $rules ) ) { |
|
172 | 172 | return [$rule, $parameters]; |
173 | 173 | } |
174 | 174 | } |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | * @param mixed $value |
181 | 181 | * @return mixed |
182 | 182 | */ |
183 | - protected function getSize($attribute, $value) |
|
183 | + protected function getSize( $attribute, $value ) |
|
184 | 184 | { |
185 | - $hasNumeric = $this->hasRule($attribute, $this->numericRules); |
|
186 | - if (is_numeric($value) && $hasNumeric) { |
|
185 | + $hasNumeric = $this->hasRule( $attribute, $this->numericRules ); |
|
186 | + if( is_numeric( $value ) && $hasNumeric ) { |
|
187 | 187 | return $value; |
188 | - } elseif (is_array($value)) { |
|
189 | - return count($value); |
|
188 | + } elseif( is_array( $value ) ) { |
|
189 | + return count( $value ); |
|
190 | 190 | } |
191 | - return function_exists('mb_strlen') |
|
192 | - ? mb_strlen($value) |
|
193 | - : strlen($value); |
|
191 | + return function_exists( 'mb_strlen' ) |
|
192 | + ? mb_strlen( $value ) |
|
193 | + : strlen( $value ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $rule |
200 | 200 | * @return string|null |
201 | 201 | */ |
202 | - protected function getSizeMessage($attribute, $rule, array $parameters) |
|
202 | + protected function getSizeMessage( $attribute, $rule, array $parameters ) |
|
203 | 203 | { |
204 | - $type = $this->getAttributeType($attribute); |
|
205 | - $lowerRule = Str::snakeCase($rule.$type); |
|
206 | - return $this->translator($lowerRule, $parameters); |
|
204 | + $type = $this->getAttributeType( $attribute ); |
|
205 | + $lowerRule = Str::snakeCase( $rule.$type ); |
|
206 | + return $this->translator( $lowerRule, $parameters ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | * @param string $attribute |
212 | 212 | * @return mixed |
213 | 213 | */ |
214 | - protected function getValue($attribute) |
|
214 | + protected function getValue( $attribute ) |
|
215 | 215 | { |
216 | - if (isset($this->data[$attribute])) { |
|
216 | + if( isset($this->data[$attribute]) ) { |
|
217 | 217 | return $this->data[$attribute]; |
218 | 218 | } |
219 | 219 | } |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | * @param string|array $rules |
225 | 225 | * @return bool |
226 | 226 | */ |
227 | - protected function hasRule($attribute, $rules) |
|
227 | + protected function hasRule( $attribute, $rules ) |
|
228 | 228 | { |
229 | - return !is_null($this->getRule($attribute, $rules)); |
|
229 | + return !is_null( $this->getRule( $attribute, $rules ) ); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | * @param mixed $data |
235 | 235 | * @return void |
236 | 236 | */ |
237 | - protected function normalizeData($data) |
|
237 | + protected function normalizeData( $data ) |
|
238 | 238 | { |
239 | - $this->data = is_object($data) |
|
240 | - ? get_object_vars($data) |
|
239 | + $this->data = is_object( $data ) |
|
240 | + ? get_object_vars( $data ) |
|
241 | 241 | : $data; |
242 | 242 | } |
243 | 243 | |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | * @param string $parameter |
248 | 248 | * @return array |
249 | 249 | */ |
250 | - protected function parseParameters($rule, $parameter) |
|
250 | + protected function parseParameters( $rule, $parameter ) |
|
251 | 251 | { |
252 | - return 'regex' == strtolower($rule) |
|
252 | + return 'regex' == strtolower( $rule ) |
|
253 | 253 | ? [$parameter] |
254 | - : str_getcsv($parameter); |
|
254 | + : str_getcsv( $parameter ); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -259,14 +259,14 @@ discard block |
||
259 | 259 | * @param string $rule |
260 | 260 | * @return array |
261 | 261 | */ |
262 | - protected function parseRule($rule) |
|
262 | + protected function parseRule( $rule ) |
|
263 | 263 | { |
264 | 264 | $parameters = []; |
265 | - if (Str::contains($rule, ':')) { |
|
266 | - list($rule, $parameter) = explode(':', $rule, 2); |
|
267 | - $parameters = $this->parseParameters($rule, $parameter); |
|
265 | + if( Str::contains( $rule, ':' ) ) { |
|
266 | + list($rule, $parameter) = explode( ':', $rule, 2 ); |
|
267 | + $parameters = $this->parseParameters( $rule, $parameter ); |
|
268 | 268 | } |
269 | - $rule = Str::camelCase($rule); |
|
269 | + $rule = Str::camelCase( $rule ); |
|
270 | 270 | return [$rule, $parameters]; |
271 | 271 | } |
272 | 272 | |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | * Set the validation rules. |
275 | 275 | * @return void |
276 | 276 | */ |
277 | - protected function setRules(array $rules) |
|
277 | + protected function setRules( array $rules ) |
|
278 | 278 | { |
279 | - foreach ($rules as $key => $rule) { |
|
280 | - $rules[$key] = is_string($rule) |
|
281 | - ? explode('|', $rule) |
|
279 | + foreach( $rules as $key => $rule ) { |
|
280 | + $rules[$key] = is_string( $rule ) |
|
281 | + ? explode( '|', $rule ) |
|
282 | 282 | : $rule; |
283 | 283 | } |
284 | 284 | $this->rules = $rules; |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | * @param string $attribute |
290 | 290 | * @return bool |
291 | 291 | */ |
292 | - protected function shouldStopValidating($attribute) |
|
292 | + protected function shouldStopValidating( $attribute ) |
|
293 | 293 | { |
294 | - return $this->hasRule($attribute, $this->implicitRules) |
|
294 | + return $this->hasRule( $attribute, $this->implicitRules ) |
|
295 | 295 | && isset($this->failedRules[$attribute]) |
296 | - && array_intersect(array_keys($this->failedRules[$attribute]), $this->implicitRules); |
|
296 | + && array_intersect( array_keys( $this->failedRules[$attribute] ), $this->implicitRules ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | * @param string $attribute |
303 | 303 | * @return void|string |
304 | 304 | */ |
305 | - protected function translator($key, array $parameters) |
|
305 | + protected function translator( $key, array $parameters ) |
|
306 | 306 | { |
307 | - $strings = glsr(ValidationStringsDefaults::class)->defaults(); |
|
308 | - if (isset($strings[$key])) { |
|
309 | - return $this->replace($strings[$key], $parameters); |
|
307 | + $strings = glsr( ValidationStringsDefaults::class )->defaults(); |
|
308 | + if( isset($strings[$key]) ) { |
|
309 | + return $this->replace( $strings[$key], $parameters ); |
|
310 | 310 | } |
311 | 311 | return 'error'; |
312 | 312 | } |
@@ -11,31 +11,31 @@ discard block |
||
11 | 11 | * @param string $domain |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function translate($original, $domain, array $args) |
|
14 | + public function translate( $original, $domain, array $args ) |
|
15 | 15 | { |
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
16 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
17 | + if( !in_array( $domain, $domains ) ) { |
|
18 | 18 | return $original; |
19 | 19 | } |
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
20 | + $args = $this->normalizeTranslationArgs( $args ); |
|
21 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
22 | + if( empty($strings) ) { |
|
23 | 23 | return $original; |
24 | 24 | } |
25 | - $string = current($strings); |
|
25 | + $string = current( $strings ); |
|
26 | 26 | return 'plural' == $string['type'] |
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
27 | + ? $this->translatePlural( $domain, $string, $args ) |
|
28 | + : $this->translateSingle( $domain, $string, $args ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Used when search/replacing a default text-domain translation |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function getTranslation(array $args) |
|
35 | + public function getTranslation( array $args ) |
|
36 | 36 | { |
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
37 | + $args = $this->normalizeTranslationArgs( $args ); |
|
38 | + return get_translations_for_domain( Application::ID )->translate_plural( $args['single'], $args['plural'], $args['number'] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | * @param string $plural |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - protected function getTranslationStrings($single, $plural) |
|
46 | + protected function getTranslationStrings( $single, $plural ) |
|
47 | 47 | { |
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
48 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
50 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
51 | 51 | }); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function normalizeTranslationArgs(array $args) |
|
57 | + protected function normalizeTranslationArgs( array $args ) |
|
58 | 58 | { |
59 | 59 | $defaults = [ |
60 | 60 | 'context' => '', |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | 'plural' => '', |
63 | 63 | 'single' => '', |
64 | 64 | ]; |
65 | - return shortcode_atts($defaults, $args); |
|
65 | + return shortcode_atts( $defaults, $args ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param string $domain |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - protected function translatePlural($domain, array $string, array $args) |
|
72 | + protected function translatePlural( $domain, array $string, array $args ) |
|
73 | 73 | { |
74 | - if (!empty($string['s2'])) { |
|
74 | + if( !empty($string['s2']) ) { |
|
75 | 75 | $args['single'] = $string['s2']; |
76 | 76 | } |
77 | - if (!empty($string['p2'])) { |
|
77 | + if( !empty($string['p2']) ) { |
|
78 | 78 | $args['plural'] = $string['p2']; |
79 | 79 | } |
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
80 | + return get_translations_for_domain( $domain )->translate_plural( |
|
81 | 81 | $args['single'], |
82 | 82 | $args['plural'], |
83 | 83 | $args['number'], |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | * @param string $domain |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - protected function translateSingle($domain, array $string, array $args) |
|
92 | + protected function translateSingle( $domain, array $string, array $args ) |
|
93 | 93 | { |
94 | - if (!empty($string['s2'])) { |
|
94 | + if( !empty($string['s2']) ) { |
|
95 | 95 | $args['single'] = $string['s2']; |
96 | 96 | } |
97 | - return get_translations_for_domain($domain)->translate( |
|
97 | + return get_translations_for_domain( $domain )->translate( |
|
98 | 98 | $args['single'], |
99 | 99 | $args['context'] |
100 | 100 | ); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public $translator; |
17 | 17 | |
18 | - public function __construct(Translator $translator) |
|
18 | + public function __construct( Translator $translator ) |
|
19 | 19 | { |
20 | 20 | $this->translator = $translator; |
21 | 21 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | * @return array |
26 | 26 | * @filter bulk_post_updated_messages |
27 | 27 | */ |
28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
28 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
29 | 29 | { |
30 | - $messages = Arr::consolidateArray($messages); |
|
30 | + $messages = Arr::consolidateArray( $messages ); |
|
31 | 31 | $messages[Application::POST_TYPE] = [ |
32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
32 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
33 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
34 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
35 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
36 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
37 | 37 | ]; |
38 | 38 | return $messages; |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @return string |
46 | 46 | * @filter gettext |
47 | 47 | */ |
48 | - public function filterGettext($translation, $text, $domain) |
|
48 | + public function filterGettext( $translation, $text, $domain ) |
|
49 | 49 | { |
50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
50 | + return apply_filters( 'site-reviews/gettext/'.$domain, $translation, $text ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | * @filter site-reviews/gettext/site-reviews |
58 | 58 | */ |
59 | - public function filterGettextSiteReviews($translation, $text) |
|
59 | + public function filterGettextSiteReviews( $translation, $text ) |
|
60 | 60 | { |
61 | - return $this->translator->translate($translation, Application::ID, [ |
|
61 | + return $this->translator->translate( $translation, Application::ID, [ |
|
62 | 62 | 'single' => $text, |
63 | - ]); |
|
63 | + ] ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @return string |
72 | 72 | * @filter gettext_with_context |
73 | 73 | */ |
74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
74 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
75 | 75 | { |
76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
76 | + return apply_filters( 'site-reviews/gettext_with_context/'.$domain, $translation, $text, $context ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return string |
84 | 84 | * @filter site-reviews/gettext_with_context/site-reviews |
85 | 85 | */ |
86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
86 | + public function filterGettextWithContextSiteReviews( $translation, $text, $context ) |
|
87 | 87 | { |
88 | - return $this->translator->translate($translation, Application::ID, [ |
|
88 | + return $this->translator->translate( $translation, Application::ID, [ |
|
89 | 89 | 'context' => $context, |
90 | 90 | 'single' => $text, |
91 | - ]); |
|
91 | + ] ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | * @filter ngettext |
102 | 102 | */ |
103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
103 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
104 | 104 | { |
105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
105 | + return apply_filters( 'site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * @return string |
114 | 114 | * @filter site-reviews/ngettext/site-reviews |
115 | 115 | */ |
116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
116 | + public function filterNgettextSiteReviews( $translation, $single, $plural, $number ) |
|
117 | 117 | { |
118 | - return $this->translator->translate($translation, Application::ID, [ |
|
118 | + return $this->translator->translate( $translation, Application::ID, [ |
|
119 | 119 | 'number' => $number, |
120 | 120 | 'plural' => $plural, |
121 | 121 | 'single' => $single, |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | * @filter ngettext_with_context |
134 | 134 | */ |
135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
135 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
136 | 136 | { |
137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
137 | + return apply_filters( 'site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | * @return string |
147 | 147 | * @filter site-reviews/ngettext_with_context/site-reviews |
148 | 148 | */ |
149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
149 | + public function filterNgettextWithContextSiteReviews( $translation, $single, $plural, $number, $context ) |
|
150 | 150 | { |
151 | - return $this->translator->translate($translation, Application::ID, [ |
|
151 | + return $this->translator->translate( $translation, Application::ID, [ |
|
152 | 152 | 'context' => $context, |
153 | 153 | 'number' => $number, |
154 | 154 | 'plural' => $plural, |
155 | 155 | 'single' => $single, |
156 | - ]); |
|
156 | + ] ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @return array |
163 | 163 | * @filter display_post_states |
164 | 164 | */ |
165 | - public function filterPostStates($postStates, $post) |
|
165 | + public function filterPostStates( $postStates, $post ) |
|
166 | 166 | { |
167 | - $postStates = Arr::consolidateArray($postStates); |
|
168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
167 | + $postStates = Arr::consolidateArray( $postStates ); |
|
168 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
169 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
170 | 170 | } |
171 | 171 | return $postStates; |
172 | 172 | } |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @filter site-reviews/gettext/default |
179 | 179 | * @filter site-reviews/gettext_with_context/default |
180 | 180 | */ |
181 | - public function filterPostStatusLabels($translation, $text) |
|
181 | + public function filterPostStatusLabels( $translation, $text ) |
|
182 | 182 | { |
183 | 183 | return $this->canModifyTranslation() |
184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
184 | + ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text ) |
|
185 | 185 | : $translation; |
186 | 186 | } |
187 | 187 | |
@@ -193,22 +193,22 @@ discard block |
||
193 | 193 | * @return string |
194 | 194 | * @filter site-reviews/ngettext/default |
195 | 195 | */ |
196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
196 | + public function filterPostStatusText( $translation, $single, $plural, $number ) |
|
197 | 197 | { |
198 | - if ($this->canModifyTranslation()) { |
|
198 | + if( $this->canModifyTranslation() ) { |
|
199 | 199 | $strings = [ |
200 | - 'Published' => __('Approved', 'site-reviews'), |
|
201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
200 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
201 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
202 | 202 | ]; |
203 | - foreach ($strings as $search => $replace) { |
|
204 | - if (!Str::contains($single, $search)) { |
|
203 | + foreach( $strings as $search => $replace ) { |
|
204 | + if( !Str::contains( $single, $search ) ) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | - return $this->translator->getTranslation([ |
|
207 | + return $this->translator->getTranslation( [ |
|
208 | 208 | 'number' => $number, |
209 | - 'plural' => str_replace($search, $replace, $plural), |
|
210 | - 'single' => str_replace($search, $replace, $single), |
|
211 | - ]); |
|
209 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
210 | + 'single' => str_replace( $search, $replace, $single ), |
|
211 | + ] ); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | return $translation; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function translatePostStatusLabels() |
222 | 222 | { |
223 | - if ($this->canModifyTranslation()) { |
|
224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
223 | + if( $this->canModifyTranslation() ) { |
|
224 | + glsr( Labels::class )->translatePostStatusLabels(); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -232,6 +232,6 @@ discard block |
||
232 | 232 | { |
233 | 233 | $screen = glsr_current_screen(); |
234 | 234 | return Application::POST_TYPE == $screen->post_type |
235 | - && in_array($screen->base, ['edit', 'post']); |
|
235 | + && in_array( $screen->base, ['edit', 'post'] ); |
|
236 | 236 | } |
237 | 237 | } |
@@ -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,42 +45,42 @@ 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('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
68 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
69 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
70 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
71 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
72 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
73 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
74 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
75 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
76 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
77 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
78 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
79 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
80 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
81 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
82 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
83 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
84 | - 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( 'site-reviews/render/view', [$this->public, 'filterRenderView'] ); |
|
67 | + add_filter( 'site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback'] ); |
|
68 | + add_filter( 'site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3 ); |
|
69 | + add_filter( 'bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2 ); |
|
70 | + add_filter( 'gettext', [$this->translator, 'filterGettext'], 9, 3 ); |
|
71 | + add_filter( 'site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2 ); |
|
72 | + add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4 ); |
|
73 | + add_filter( 'site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3 ); |
|
74 | + add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 9, 5 ); |
|
75 | + add_filter( 'site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4 ); |
|
76 | + add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6 ); |
|
77 | + add_filter( 'site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5 ); |
|
78 | + add_filter( 'display_post_states', [$this->translator, 'filterPostStates'], 10, 2 ); |
|
79 | + add_filter( 'site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
80 | + add_filter( 'site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
81 | + add_filter( 'site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4 ); |
|
82 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9 ); |
|
83 | + add_filter( 'admin_title', [$this->welcome, 'filterAdminTitle'] ); |
|
84 | + add_filter( 'admin_footer_text', [$this->welcome, 'filterFooterText'] ); |
|
85 | 85 | } |
86 | 86 | } |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | * @return string |
29 | 29 | * @filter script_loader_tag |
30 | 30 | */ |
31 | - public function filterEnqueuedScripts($tag, $handle) |
|
31 | + public function filterEnqueuedScripts( $tag, $handle ) |
|
32 | 32 | { |
33 | 33 | $scripts = [Application::ID.'/google-recaptcha']; |
34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
34 | + if( in_array( $handle, apply_filters( 'site-reviews/async-scripts', $scripts ) ) ) { |
|
35 | + $tag = str_replace( ' src=', ' async src=', $tag ); |
|
36 | 36 | } |
37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
37 | + if( in_array( $handle, apply_filters( 'site-reviews/defer-scripts', $scripts ) ) ) { |
|
38 | + $tag = str_replace( ' src=', ' defer src=', $tag ); |
|
39 | 39 | } |
40 | 40 | return $tag; |
41 | 41 | } |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | * @return array |
45 | 45 | * @filter site-reviews/config/forms/submission-form |
46 | 46 | */ |
47 | - public function filterFieldOrder(array $config) |
|
47 | + public function filterFieldOrder( array $config ) |
|
48 | 48 | { |
49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
49 | + $order = (array)apply_filters( 'site-reviews/submission-form/order', array_keys( $config ) ); |
|
50 | + return array_intersect_key( array_merge( array_flip( $order ), $config ), $config ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | * @return string |
56 | 56 | * @filter site-reviews/render/view |
57 | 57 | */ |
58 | - public function filterRenderView($view) |
|
58 | + public function filterRenderView( $view ) |
|
59 | 59 | { |
60 | - return glsr(Style::class)->filterView($view); |
|
60 | + return glsr( Style::class )->filterView( $view ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @return void |
65 | 65 | * @action site-reviews/builder |
66 | 66 | */ |
67 | - public function modifyBuilder(Builder $instance) |
|
67 | + public function modifyBuilder( Builder $instance ) |
|
68 | 68 | { |
69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
69 | + call_user_func_array( [glsr( Style::class ), 'modifyField'], [$instance] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function renderSchema() |
77 | 77 | { |
78 | - glsr(Schema::class)->render(); |
|
78 | + glsr( Schema::class )->render(); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @return CreateReview |
83 | 83 | */ |
84 | - public function routerSubmitReview(array $request) |
|
84 | + public function routerSubmitReview( array $request ) |
|
85 | 85 | { |
86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | - $command = new CreateReview($validated->request); |
|
88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | - $this->execute($command); |
|
86 | + $validated = glsr( ValidateReview::class )->validate( $request ); |
|
87 | + $command = new CreateReview( $validated->request ); |
|
88 | + if( empty($validated->error) && !$validated->recaptchaIsUnset ) { |
|
89 | + $this->execute( $command ); |
|
90 | 90 | } |
91 | 91 | return $command; |
92 | 92 | } |
@@ -11,24 +11,24 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function getCloudflareIps() |
13 | 13 | { |
14 | - if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
15 | - $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
16 | - foreach (array_keys($ipAddresses) as $version) { |
|
14 | + if( false === ($ipAddresses = get_transient( Application::ID.'_cloudflare_ips' )) ) { |
|
15 | + $ipAddresses = array_fill_keys( ['v4', 'v6'], [] ); |
|
16 | + foreach( array_keys( $ipAddresses ) as $version ) { |
|
17 | 17 | $url = 'https://www.cloudflare.com/ips-'.$version; |
18 | - $response = wp_remote_get($url, ['sslverify' => false]); |
|
19 | - if (is_wp_error($response)) { |
|
20 | - glsr_log()->error($response->get_error_message()); |
|
18 | + $response = wp_remote_get( $url, ['sslverify' => false] ); |
|
19 | + if( is_wp_error( $response ) ) { |
|
20 | + glsr_log()->error( $response->get_error_message() ); |
|
21 | 21 | continue; |
22 | 22 | } |
23 | - if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
24 | - glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
23 | + if( '200' != ($statusCode = wp_remote_retrieve_response_code( $response )) ) { |
|
24 | + glsr_log()->error( 'Unable to connect to '.$url.' ['.$statusCode.']' ); |
|
25 | 25 | continue; |
26 | 26 | } |
27 | 27 | $ipAddresses[$version] = array_filter( |
28 | - (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
28 | + (array)preg_split( '/\R/', wp_remote_retrieve_body( $response ) ) |
|
29 | 29 | ); |
30 | 30 | } |
31 | - set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
31 | + set_transient( Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS ); |
|
32 | 32 | } |
33 | 33 | return $ipAddresses; |
34 | 34 | } |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * @param string $metaKey |
38 | 38 | * @return array |
39 | 39 | */ |
40 | - public function getReviewCountsFor($metaKey) |
|
40 | + public function getReviewCountsFor( $metaKey ) |
|
41 | 41 | { |
42 | - $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
43 | - if (false === $counts) { |
|
42 | + $counts = wp_cache_get( Application::ID, $metaKey.'_count' ); |
|
43 | + if( false === $counts ) { |
|
44 | 44 | $counts = []; |
45 | - $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
46 | - foreach ($results as $result) { |
|
45 | + $results = glsr( SqlQueries::class )->getReviewCountsFor( $metaKey ); |
|
46 | + foreach( $results as $result ) { |
|
47 | 47 | $counts[$result->name] = $result->num_posts; |
48 | 48 | } |
49 | - wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
49 | + wp_cache_set( Application::ID, $counts, $metaKey.'_count' ); |
|
50 | 50 | } |
51 | 51 | return $counts; |
52 | 52 | } |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getRemotePostTest() |
58 | 58 | { |
59 | - if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
60 | - $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
61 | - $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
59 | + if( false === ($test = get_transient( Application::ID.'_remote_post_test' )) ) { |
|
60 | + $response = wp_remote_post( 'https://api.wordpress.org/stats/php/1.0/' ); |
|
61 | + $test = !is_wp_error( $response ) && in_array( $response['response']['code'], range( 200, 299 ) ) |
|
62 | 62 | ? 'Works' |
63 | 63 | : 'Does not work'; |
64 | - set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
64 | + set_transient( Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS ); |
|
65 | 65 | } |
66 | 66 | return $test; |
67 | 67 | } |