-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
126 lines (119 loc) · 3.74 KB
/
bootstrap.php
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
<?php
/**
* This file is where you should put the code that bootstraps your plugin
*/
/**
* --- DEFINE PLUGIN CONSTANTS ---
*/
// Plugin name
define( 'SUPPLANG_NAME', 'supplang' );
// ID for the custom taxonomy
define( 'SUPPLANG_LANG_TAX_ID', 'supplang_lang' );
// Prefix that should be used by all plugin classes
define( 'SUPPLANG_CLASS_PREFIX', 'Supplang' );
// Name of the Supplang option group
define( 'SUPPLANG_OPTION_GROUP', 'supplang' );
// Name of the admin settings page
define( 'SUPPLANG_ADMIN_PAGE_NAME', 'supplang_admin_settings' );
// Name of the setting that list available languages for the site UI
define( 'SUPPLANG_AVAILABLE_UIL', 'supplang_available_uil' );
// Name of the GET param for changing the UI language
define( 'SUPPLANG_GET_PARAM', 'uil' );
// List of available languages
// Add a new array to add a new language
define(
'SUPPLANG_LANGUAGES', array(
array(
'name' => 'Français',
'locale' => 'fr_FR',
'desc' => 'Apply this to french written articles',
'slug' => 'fr',
),
array(
'name' => 'Italiano',
'locale' => 'it_IT',
'desc' => 'Apply this to italian written articles',
'slug' => 'it',
),
array(
'name' => 'Deutsch',
'locale' => 'de_DE',
'desc' => 'Apply this to german written articles',
'slug' => 'de',
),
array(
'name' => 'Rumansch',
'locale' => 'rm_CH',
'desc' => 'Apply this to romansch written articles',
'slug' => 'rm',
),
array(
'name' => 'English',
'locale' => 'en_GB',
'desc' => 'Apply this to english written articles',
'slug' => 'en',
),
)
);
/**
* Returns the registered languages.
* You can register new languages by using the `supplang_register_languages` filter.
* This is a low-level function that is called by all other functions relying on the list of languages.
* This way, the languages added through the filter are taken into account.
* @return array
*/
function supplang_registered_languages() {
/**
* Filters the registered languages array.
*
* @since 2.3.0
*
* @param array The default languages
*/
$languages = apply_filters( 'supplang_register_languages', SUPPLANG_LANGUAGES );
// To prevent error when add_filter do not return the languages
return empty( $languages ) ? array() : $languages;
}
/**
* --- REGISTER AUTOLOADER ---
* Expect all classe names and files to respect the WordPress naming style
* Does not process $class_name not beginning with the SUPPLANG_CLASS_PREFIX constant value.
*/
spl_autoload_register(
function( $class_name ) {
$class_name_parts = explode( '_', $class_name );
if ( SUPPLANG_CLASS_PREFIX === $class_name_parts[0] ) {
$classes_dir = realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR;
$class_file = strtolower( 'class-' . implode( '-', $class_name_parts ) . '.php' );
require_once $classes_dir . $class_file;
}
}
);
/**
* --- Instanciate the new taxonomy manager
*/
$supplang_lang_tax = new Supplang_Language_Taxonomy();
/**
* --- LOAD ACTIVATION/DEACTIVATION HOOKS ---
*/
register_activation_hook( SUPPLANG_MAIN_FILE, array( $supplang_lang_tax, 'activate' ) );
register_deactivation_hook( SUPPLANG_MAIN_FILE, array( $supplang_lang_tax, 'deactivate' ) );
/**
* --- REGISTER CUSTOM TAXONOMY ---
*/
add_action( 'init', array( $supplang_lang_tax, 'register_taxonomy' ) );
add_action( 'restrict_manage_posts', array( $supplang_lang_tax, 'add_admin_filter_dropdown' ) );
add_filter( 'parse_query', array( $supplang_lang_tax, 'admin_filter_posts' ) );
/**
* --- LOAD PLUGIN FILES ---
*/
if ( is_admin() ) {
// Load the admin features
new Supplang_Admin_Page();
} else {
// Load the frontend features
require_once 'frontend/api.php';
new Supplang_Link_Manager();
new Supplang_Locale_Manager();
new Supplang_Api();
}