1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\HooksContract; |
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\AdminController; |
7
|
|
|
use GeminiLabs\SiteReviews\Controllers\BlocksController; |
8
|
|
|
use GeminiLabs\SiteReviews\Controllers\BulkEditorController; |
9
|
|
|
use GeminiLabs\SiteReviews\Controllers\EditorController; |
10
|
|
|
use GeminiLabs\SiteReviews\Controllers\ListTableController; |
11
|
|
|
use GeminiLabs\SiteReviews\Controllers\MainController; |
12
|
|
|
use GeminiLabs\SiteReviews\Controllers\MenuController; |
13
|
|
|
use GeminiLabs\SiteReviews\Controllers\MetaboxController; |
14
|
|
|
use GeminiLabs\SiteReviews\Controllers\NoticeController; |
15
|
|
|
use GeminiLabs\SiteReviews\Controllers\PrivacyController; |
16
|
|
|
use GeminiLabs\SiteReviews\Controllers\PublicController; |
17
|
|
|
use GeminiLabs\SiteReviews\Controllers\ReviewController; |
18
|
|
|
use GeminiLabs\SiteReviews\Controllers\RevisionController; |
19
|
|
|
use GeminiLabs\SiteReviews\Controllers\SettingsController; |
20
|
|
|
use GeminiLabs\SiteReviews\Controllers\ToolsController; |
21
|
|
|
use GeminiLabs\SiteReviews\Controllers\TranslationController; |
22
|
|
|
use GeminiLabs\SiteReviews\Controllers\WelcomeController; |
23
|
|
|
use GeminiLabs\SiteReviews\Database\SqlSchema; |
24
|
|
|
use GeminiLabs\SiteReviews\Modules\Translation; |
25
|
|
|
|
26
|
|
|
class Hooks implements HooksContract |
27
|
|
|
{ |
28
|
|
|
protected $admin; |
29
|
|
|
protected $basename; |
30
|
|
|
protected $blocks; |
31
|
|
|
protected $bulkeditor; |
32
|
|
|
protected $editor; |
33
|
|
|
protected $listtable; |
34
|
|
|
protected $main; |
35
|
|
|
protected $menu; |
36
|
|
|
protected $metabox; |
37
|
|
|
protected $notices; |
38
|
|
|
protected $privacy; |
39
|
|
|
protected $public; |
40
|
|
|
protected $review; |
41
|
|
|
protected $revisions; |
42
|
|
|
protected $router; |
43
|
|
|
protected $settings; |
44
|
|
|
protected $tools; |
45
|
|
|
protected $translator; |
46
|
|
|
protected $welcome; |
47
|
|
|
|
48
|
|
|
public function __construct() |
49
|
|
|
{ |
50
|
|
|
$this->admin = glsr(AdminController::class); |
51
|
|
|
$this->basename = plugin_basename(glsr()->file); |
52
|
|
|
$this->blocks = glsr(BlocksController::class); |
53
|
|
|
$this->bulkeditor = glsr(BulkEditorController::class); |
54
|
|
|
$this->editor = glsr(EditorController::class); |
55
|
|
|
$this->listtable = glsr(ListTableController::class); |
56
|
|
|
$this->main = glsr(MainController::class); |
57
|
|
|
$this->menu = glsr(MenuController::class); |
58
|
|
|
$this->metabox = glsr(MetaboxController::class); |
59
|
|
|
$this->notices = glsr(NoticeController::class); |
60
|
|
|
$this->privacy = glsr(PrivacyController::class); |
61
|
|
|
$this->public = glsr(PublicController::class); |
62
|
|
|
$this->review = glsr(ReviewController::class); |
63
|
|
|
$this->revisions = glsr(RevisionController::class); |
64
|
|
|
$this->router = glsr(Router::class); |
65
|
|
|
$this->settings = glsr(SettingsController::class); |
66
|
|
|
$this->tools = glsr(ToolsController::class); |
67
|
|
|
$this->translator = glsr(TranslationController::class); |
68
|
|
|
$this->welcome = glsr(WelcomeController::class); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function addActions() |
75
|
|
|
{ |
76
|
|
|
add_action('plugins_loaded', [glsr(), 'getDefaultSettings'], 11); |
77
|
|
|
add_action('plugins_loaded', [glsr(), 'registerAddons']); |
78
|
|
|
add_action('plugins_loaded', [glsr(), 'registerLanguages']); |
79
|
|
|
add_action('plugins_loaded', [glsr(), 'registerReviewTypes']); |
80
|
|
|
add_action('admin_init', [glsr(), 'setDefaultSettings']); |
81
|
|
|
add_action('plugins_loaded', [$this, 'myIsamFallback']); |
82
|
|
|
add_action('load-edit.php', [$this, 'translateAdminEditPage']); |
83
|
|
|
add_action('load-post.php', [$this, 'translateAdminPostPage']); |
84
|
|
|
add_action('plugins_loaded', [$this, 'translatePlugin']); |
85
|
|
|
add_action('site-reviews/export/cleanup', [$this->admin, 'cleanupAfterExport']); |
86
|
|
|
add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
87
|
|
|
add_action('admin_head', [$this->admin, 'printInlineStyle']); |
88
|
|
|
add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
89
|
|
|
add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
90
|
|
|
add_action('import_end', [$this->admin, 'onImportEnd']); |
91
|
|
|
add_action('site-reviews/route/ajax/search-posts', [$this->admin, 'searchPostsAjax']); |
92
|
|
|
add_action('site-reviews/route/ajax/search-translations', [$this->admin, 'searchTranslationsAjax']); |
93
|
|
|
add_action('site-reviews/route/ajax/search-users', [$this->admin, 'searchUsersAjax']); |
94
|
|
|
add_action('site-reviews/route/ajax/toggle-pinned', [$this->admin, 'togglePinnedAjax']); |
95
|
|
|
add_action('site-reviews/route/ajax/toggle-status', [$this->admin, 'toggleStatusAjax']); |
96
|
|
|
add_action('init', [$this->blocks, 'registerAssets'], 9); |
97
|
|
|
add_action('init', [$this->blocks, 'registerBlocks']); |
98
|
|
|
add_action('bulk_edit_custom_box', [$this->bulkeditor, 'renderBulkEditFields'], 10, 2); |
99
|
|
|
add_action('site-reviews/route/ajax/mce-shortcode', [$this->editor, 'mceShortcodeAjax']); |
100
|
|
|
add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
101
|
|
|
add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
102
|
|
|
add_action('admin_head', [$this->editor, 'renderReviewFields']); |
103
|
|
|
add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
104
|
|
|
add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
105
|
|
|
add_action('manage_'.glsr()->post_type.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
106
|
|
|
add_action('admin_footer', [$this->main, 'logOnce']); |
107
|
|
|
add_action('wp_footer', [$this->main, 'logOnce']); |
108
|
|
|
add_action('init', [$this->main, 'registerPostType'], 8); |
109
|
|
|
add_action('init', [$this->main, 'registerShortcodes']); |
110
|
|
|
add_action('init', [$this->main, 'registerTaxonomy']); |
111
|
|
|
add_action('widgets_init', [$this->main, 'registerWidgets']); |
112
|
|
|
add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
113
|
|
|
add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
114
|
|
|
add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
115
|
|
|
add_action('add_meta_boxes_'.glsr()->post_type, [$this->metabox, 'registerMetaBoxes']); |
116
|
|
|
add_action('do_meta_boxes', [$this->metabox, 'removeMetaBoxes']); |
117
|
|
|
add_action('post_submitbox_misc_actions', [$this->metabox, 'renderPinnedInPublishMetaBox']); |
118
|
|
|
add_action('admin_notices', [$this->notices, 'adminNotices']); |
119
|
|
|
add_action('site-reviews/route/admin/dismiss-notice', [$this->notices, 'dismissNotice']); |
120
|
|
|
add_action('site-reviews/route/ajax/dismiss-notice', [$this->notices, 'dismissNoticeAjax']); |
121
|
|
|
add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
122
|
|
|
add_action('site-reviews/route/ajax/fetch-paged-reviews', [$this->public, 'fetchPagedReviewsAjax']); |
123
|
|
|
add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
124
|
|
|
add_action('wp_footer', [$this->public, 'renderSchema']); |
125
|
|
|
add_action('site-reviews/route/public/submit-review', [$this->public, 'submitReview']); |
126
|
|
|
add_action('site-reviews/route/ajax/submit-review', [$this->public, 'submitReviewAjax']); |
127
|
|
|
add_action('admin_init', [$this->privacy, 'privacyPolicyContent']); |
128
|
|
|
add_action('admin_action_approve', [$this->review, 'approve']); |
129
|
|
|
add_action('the_posts', [$this->review, 'filterPostsToCacheReviews']); |
130
|
|
|
add_action('set_object_terms', [$this->review, 'onAfterChangeAssignedTerms'], 10, 6); |
131
|
|
|
add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
132
|
|
|
add_action('site-reviews/review/updated/post_ids', [$this->review, 'onChangeAssignedPosts'], 10, 2); |
133
|
|
|
add_action('site-reviews/review/updated/user_ids', [$this->review, 'onChangeAssignedUsers'], 10, 2); |
134
|
|
|
add_action('site-reviews/review/created', [$this->review, 'onCreatedReview'], 10, 2); |
135
|
|
|
add_action('site-reviews/review/create', [$this->review, 'onCreateReview'], 10, 2); |
136
|
|
|
add_action('edit_post_'.glsr()->post_type, [$this->review, 'onEditReview']); |
137
|
|
|
add_action('admin_action_unapprove', [$this->review, 'unapprove']); |
138
|
|
|
add_action('wp_restore_post_revision', [$this->revisions, 'restoreRevision'], 10, 2); |
139
|
|
|
add_action('_wp_put_post_revision', [$this->revisions, 'saveRevision']); |
140
|
|
|
add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
141
|
|
|
add_action('wp_ajax_'.glsr()->prefix.'action', [$this->router, 'routeAjaxRequest']); |
142
|
|
|
add_action('wp_ajax_nopriv_'.glsr()->prefix.'action', [$this->router, 'routeAjaxRequest']); |
143
|
|
|
add_action('init', [$this->router, 'routePublicPostRequest']); |
144
|
|
|
add_action('admin_init', [$this->settings, 'registerSettings']); |
145
|
|
|
add_action('site-reviews/route/admin/clear-console', [$this->tools, 'clearConsole']); |
146
|
|
|
add_action('site-reviews/route/ajax/clear-console', [$this->tools, 'clearConsoleAjax']); |
147
|
|
|
add_action('site-reviews/route/admin/detect-ip-address', [$this->tools, 'detectIpAddress']); |
148
|
|
|
add_action('site-reviews/route/ajax/detect-ip-address', [$this->tools, 'detectIpAddressAjax']); |
149
|
|
|
add_action('site-reviews/route/admin/download-console', [$this->tools, 'downloadConsole']); |
150
|
|
|
add_action('site-reviews/route/admin/download-system-info', [$this->tools, 'downloadSystemInfo']); |
151
|
|
|
add_action('site-reviews/route/admin/fetch-console', [$this->tools, 'fetchConsole']); |
152
|
|
|
add_action('site-reviews/route/ajax/fetch-console', [$this->tools, 'fetchConsoleAjax']); |
153
|
|
|
add_action('site-reviews/route/admin/migrate-plugin', [$this->tools, 'migratePlugin']); |
154
|
|
|
add_action('site-reviews/route/ajax/migrate-plugin', [$this->tools, 'migratePluginAjax']); |
155
|
|
|
add_action('site-reviews/route/admin/export-settings', [$this->tools, 'exportSettings']); |
156
|
|
|
add_action('site-reviews/route/admin/import-reviews', [$this->tools, 'importReviews']); |
157
|
|
|
add_action('site-reviews/route/admin/import-settings', [$this->tools, 'importSettings']); |
158
|
|
|
add_action('site-reviews/route/admin/reset-assigned-meta', [$this->tools, 'resetAssignedMeta']); |
159
|
|
|
add_action('site-reviews/route/ajax/reset-assigned-meta', [$this->tools, 'resetAssignedMetaAjax']); |
160
|
|
|
add_action('site-reviews/route/admin/reset-permissions', [$this->tools, 'resetPermissions']); |
161
|
|
|
add_action('site-reviews/route/ajax/reset-permissions', [$this->tools, 'resetPermissionsAjax']); |
162
|
|
|
add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
163
|
|
|
add_action('admin_menu', [$this->welcome, 'registerPage']); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return void |
168
|
|
|
*/ |
169
|
|
|
public function addFilters() |
170
|
|
|
{ |
171
|
|
|
add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
172
|
|
|
add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
173
|
|
|
add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
174
|
|
|
add_filter('export_args', [$this->admin, 'filterExportArgs'], 11); |
175
|
|
|
add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
176
|
|
|
add_filter('allowed_block_types', [$this->blocks, 'filterAllowedBlockTypes'], 10, 2); |
177
|
|
|
add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
178
|
|
|
add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
179
|
|
|
add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
180
|
|
|
add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
181
|
|
|
add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
182
|
|
|
add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
183
|
|
|
add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
184
|
|
|
add_filter('manage_'.glsr()->post_type.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
185
|
|
|
add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
186
|
|
|
add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
187
|
|
|
add_filter('posts_clauses', [$this->listtable, 'filterPostClauses'], 10, 2); |
188
|
|
|
add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
189
|
|
|
add_filter('manage_edit-'.glsr()->post_type.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
190
|
|
|
add_filter('site-reviews/config/forms/metabox-fields', [$this->metabox, 'filterFieldOrder'], 11); |
191
|
|
|
add_filter('wp_privacy_personal_data_erasers', [$this->privacy, 'filterPersonalDataErasers']); |
192
|
|
|
add_filter('wp_privacy_personal_data_exporters', [$this->privacy, 'filterPersonalDataExporters']); |
193
|
|
|
add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScriptTags'], 10, 2); |
194
|
|
|
add_filter('site-reviews/config/forms/review-form', [$this->public, 'filterFieldOrder'], 11); |
195
|
|
|
add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
196
|
|
|
add_filter('wp_save_post_revision_check_for_changes', [$this->revisions, 'filterCheckForChanges'], 99, 3); |
197
|
|
|
add_filter('wp_save_post_revision_post_has_changed', [$this->revisions, 'filterReviewHasChanged'], 10, 3); |
198
|
|
|
add_filter('wp_get_revision_ui_diff', [$this->revisions, 'filterRevisionUiDiff'], 10, 3); |
199
|
|
|
add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 11); |
200
|
|
|
add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
201
|
|
|
add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return void |
206
|
|
|
*/ |
207
|
|
|
public function myIsamFallback() |
208
|
|
|
{ |
209
|
|
|
if (!glsr(SqlSchema::class)->isInnodb('posts')) { |
210
|
|
|
add_action('deleted_post', [$this->review, 'onDeletePost'], 10, 2); |
211
|
|
|
} |
212
|
|
|
if (!glsr(SqlSchema::class)->isInnodb('users')) { |
213
|
|
|
add_action('deleted_user', [$this->review, 'onDeleteUser'], 10); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return void |
219
|
|
|
*/ |
220
|
|
|
public function run() |
221
|
|
|
{ |
222
|
|
|
$this->addActions(); |
223
|
|
|
$this->addFilters(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return void |
228
|
|
|
* @action load-edit.php |
229
|
|
|
*/ |
230
|
|
|
public function translateAdminEditPage() |
231
|
|
|
{ |
232
|
|
|
if (glsr()->post_type === glsr_current_screen()->post_type) { |
233
|
|
|
add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
234
|
|
|
add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
235
|
|
|
add_filter('gettext_default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
236
|
|
|
add_filter('ngettext_default', [$this->translator, 'filterPostStatusText'], 10, 4); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @return void |
242
|
|
|
* @action load-post.php |
243
|
|
|
*/ |
244
|
|
|
public function translateAdminPostPage() |
245
|
|
|
{ |
246
|
|
|
if (glsr()->post_type === glsr_current_screen()->post_type) { |
247
|
|
|
add_filter('gettext_default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
248
|
|
|
add_action('admin_print_scripts-post.php', [$this->translator, 'translatePostStatusLabels']); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @return void |
254
|
|
|
* @action plugins_loaded |
255
|
|
|
*/ |
256
|
|
|
public function translatePlugin() |
257
|
|
|
{ |
258
|
|
|
if (!empty(glsr(Translation::class)->translations())) { |
259
|
|
|
add_filter('gettext_'.glsr()->id, [$this->translator, 'filterGettext'], 10, 2); |
260
|
|
|
add_filter('gettext_with_context_'.glsr()->id, [$this->translator, 'filterGettextWithContext'], 10, 3); |
261
|
|
|
add_filter('ngettext_'.glsr()->id, [$this->translator, 'filterNgettext'], 10, 4); |
262
|
|
|
add_filter('ngettext_with_context_'.glsr()->id, [$this->translator, 'filterNgettextWithContext'], 10, 5); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|