forked from inpsyde/multilingual-press
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultilingualpress.php
More file actions
178 lines (149 loc) · 5.66 KB
/
multilingualpress.php
File metadata and controls
178 lines (149 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php # -*- coding: utf-8 -*-
/*
* Plugin Name: MultilingualPress
* Plugin URI: https://wordpress.org/plugins/multilingualpress/
* Description: The multisite-based free open source plugin for your multilingual WordPress websites.
* Author: Inpsyde GmbH
* Author URI: https://inpsyde.com
* Version: 3.0.0-dev
* Text Domain: multilingualpress
* License: MIT
* Network: true
*/
namespace Inpsyde\MultilingualPress;
use Inpsyde\MultilingualPress\API\APIServiceProvider;
use Inpsyde\MultilingualPress\API\ContentRelations;
use Inpsyde\MultilingualPress\Asset\AssetServiceProvider;
use Inpsyde\MultilingualPress\Core\CoreServiceProvider;
use Inpsyde\MultilingualPress\Core\ImmutablePluginProperties;
use Inpsyde\MultilingualPress\Database\DatabaseServiceProvider;
use Inpsyde\MultilingualPress\Database\Table;
use Inpsyde\MultilingualPress\Factory\FactoryProvider;
use Inpsyde\MultilingualPress\Installation\InstallationServiceProvider;
use Inpsyde\MultilingualPress\Integration\IntegrationProvider;
use Inpsyde\MultilingualPress\Module;
use Inpsyde\MultilingualPress\NavMenu\NavMenuServiceProvider;
use Inpsyde\MultilingualPress\Relations\RelationsServiceProvider;
use Inpsyde\MultilingualPress\Service\Container;
use Inpsyde\MultilingualPress\Service\DistinctServiceProviderCollection;
use Inpsyde\MultilingualPress\Service\ServiceProviderCollection;
use Inpsyde\MultilingualPress\SiteDuplication\SiteDuplicationServiceProvider;
use Inpsyde\MultilingualPress\Translation\TranslationServiceProvider;
use Inpsyde\MultilingualPress\Widget\WidgetServiceProvider;
defined( 'ABSPATH' ) or die();
/**
* Action name.
*
* @since 3.0.0
*
* @var string
*/
const ACTION_ACTIVATION = 'multilingualpress.activation';
/**
* Action name.
*
* @since 3.0.0
*
* @var string
*/
const ACTION_ADD_SERVICE_PROVIDERS = 'multilingualpress.add_service_providers';
if ( ! class_exists( MultilingualPress::class ) && is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
/**
* MultilingualPress autoload file.
*/
require_once __DIR__ . '/vendor/autoload.php';
}
/**
* Bootstraps MultilingualPress.
*
* @since 3.0.0
* @wp-hook plugins_loaded
*
* @return bool Whether or not MultilingualPress was bootstrapped successfully.
*/
function bootstrap(): bool {
/** @var Container $container */
$container = resolve( null );
$container->share( 'multilingualpress.properties', new ImmutablePluginProperties( __FILE__ ) );
$providers = new DistinctServiceProviderCollection();
$providers
->add_service_provider( new CoreServiceProvider() )
->add_service_provider( new APIServiceProvider() )
->add_service_provider( new AssetServiceProvider() )
->add_service_provider( new DatabaseServiceProvider() )
->add_service_provider( new FactoryProvider() )
->add_service_provider( new InstallationServiceProvider() )
->add_service_provider( new IntegrationProvider() )
->add_service_provider( new Module\AlternativeLanguageTitleInAdminBar\ServiceProvider() )
->add_service_provider( new Module\CustomPostTypeSupport\ServiceProvider() )
->add_service_provider( new Module\Quicklinks\ServiceProvider() )
->add_service_provider( new Module\Redirect\ServiceProvider() )
->add_service_provider( new Module\Trasher\ServiceProvider() )
->add_service_provider( new NavMenuServiceProvider() )
->add_service_provider( new RelationsServiceProvider() )
->add_service_provider( new SiteDuplicationServiceProvider() )
->add_service_provider( new TranslationServiceProvider() )
->add_service_provider( new WidgetServiceProvider() );
$multilingualpress = new MultilingualPress( $container, $providers );
/**
* Fires right before MultilingualPress gets bootstrapped.
*
* Hook here to add custom service providers via `ServiceProviderCollection::add_service_provider()`.
*
* @since 3.0.0
*
* @param ServiceProviderCollection $providers Service provider collection instance.
*/
do_action( ACTION_ADD_SERVICE_PROVIDERS, $providers );
$bootstrapped = $multilingualpress->bootstrap();
unset( $providers );
return $bootstrapped;
}
/**
* Triggers a plugin-specific activation action third parties can listen to.
*
* @since 3.0.0
* @wp-hook activate_{$plugin}
*
* @return void
*/
function activate() {
/**
* Fires when MultilingualPress is about to be activated.
*
* @since 3.0.0
*/
do_action( ACTION_ACTIVATION );
add_action( 'activated_plugin', function ( $plugin ) {
if ( plugin_basename( __FILE__ ) === $plugin ) {
// Bootstrap MultilingualPress right now to take care of installation or upgrade routines.
bootstrap();
}
}, 0 );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\\bootstrap', 0 );
register_activation_hook( __FILE__, __NAMESPACE__ . '\\activate' );
// TODO: Eventually remove/refactor according to new architecture as soon as the old controller got replaced.
add_action( MultilingualPress::ACTION_BOOTSTRAPPED, function () {
// Advanced Translator
new \Mlp_Advanced_Translator();
// Translation Meta Box
new \Mlp_Translation_Metabox();
if ( is_admin() ) {
// Term Translator
add_action( 'wp_loaded', function () {
$taxonomy = empty( $_REQUEST['taxonomy'] ) ? '' : (string) $_REQUEST['taxonomy'];
$term_taxonomy_id = empty( $_REQUEST['tag_ID'] ) ? 0 : (int) $_REQUEST['tag_ID'];
( new \Mlp_Term_Translation_Controller(
resolve( 'multilingualpress.content_relations', ContentRelations::class ),
new Common\Nonce\WPNonce( "save_{$taxonomy}_translations_$term_taxonomy_id" )
) )->setup();
}, 0 );
}
add_action( 'wp_loaded', function () {
new \Mlp_Language_Manager_Controller(
new \Mlp_Language_Db_Access( resolve( 'multilingualpress.languages_table', Table::class )->name() ),
resolve( 'multilingualpress.wpdb', \wpdb::class )
);
} );
} );