PluginProbe
Bogo / 2.4.1
Bogo v2.4.1
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / admin / admin.php

admin.php in Bogo 2.4.1, at admin/admin.php

188 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php';
4 require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
5 require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
6 require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
7
8 add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
9
10 function bogo_admin_enqueue_scripts( $hook_suffix ) {
11 if ( false !== strpos( $hook_suffix, 'bogo-tools' )
12 || 'widgets.php' == $hook_suffix
13 || 'user-edit.php' == $hook_suffix ) {
14 wp_enqueue_style( 'bogo-admin',
15 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
16 array(), BOGO_VERSION, 'all' );
17
18 return;
19 }
20
21 if ( 'nav-menus.php' == $hook_suffix ) {
22 $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
23 $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
24 $locales = array();
25
26 foreach ( (array) $nav_menu_items as $item ) {
27 $locales[$item->db_id] = $item->bogo_locales;
28 }
29
30 $prefix = 'menu-item-bogo-locale';
31
32 wp_enqueue_script( 'bogo-admin',
33 plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
34 array( 'jquery' ),
35 BOGO_VERSION, true );
36
37 wp_localize_script( 'bogo-admin', '_bogo', array(
38 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
39 'locales' => $locales,
40 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
41 'cbPrefix' => $prefix ) );
42
43 wp_enqueue_style( 'bogo-admin',
44 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
45 array(), BOGO_VERSION, 'all' );
46
47 return;
48 }
49
50 if ( 'options-general.php' == $hook_suffix ) {
51 wp_enqueue_script( 'bogo-admin',
52 plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
53 array( 'jquery' ),
54 BOGO_VERSION, true );
55
56 wp_localize_script( 'bogo-admin', '_bogo', array(
57 'defaultLocale' => bogo_get_default_locale() ) );
58
59 return;
60 }
61 }
62
63 add_action( 'admin_menu', 'bogo_admin_menu' );
64
65 function bogo_admin_menu() {
66 $tools = add_management_page(
67 __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ),
68 'update_core', 'bogo-tools', 'bogo_tools_page' );
69
70 add_action( 'load-' . $tools, 'bogo_load_tools_page' );
71 }
72
73 function bogo_load_tools_page() {
74 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
75
76 $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
77
78 if ( 'install_translation' == $action ) {
79 check_admin_referer( 'bogo-tools' );
80
81 if ( ! current_user_can( 'update_core' ) ) {
82 wp_die( __( 'You are not allowed to install translations.', 'bogo' ) );
83 }
84
85 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
86
87 if ( wp_download_language_pack( $locale ) ) {
88 $redirect_to = add_query_arg(
89 array( 'locale' => $locale, 'message' => 'success' ),
90 menu_page_url( 'bogo-tools', false ) );
91 } else {
92 $redirect_to = add_query_arg(
93 array( 'locale' => $locale, 'message' => 'failed' ),
94 menu_page_url( 'bogo-tools', false ) );
95 }
96
97 wp_safe_redirect( $redirect_to );
98 exit();
99 }
100 }
101
102 function bogo_tools_page() {
103 $message = "";
104
105 if ( isset( $_GET['message'] ) ) {
106 if ( 'success' == $_GET['message'] ) {
107 $message = __( "Translation installed successfully.", 'bogo' );
108 } elseif ( 'failed' == $_GET['message'] ) {
109 $message = __( "Translation install failed.", 'bogo' );
110 }
111 }
112
113 ?>
114 <div class="wrap">
115
116 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
117
118 <?php if ( ! empty( $message ) ) : ?>
119 <div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
120 <?php endif; ?>
121
122 <?php
123 bogo_toolbox_installed_translations();
124 bogo_toolbox_add_translations();
125 ?>
126
127 </div>
128 <?php
129 }
130
131 function bogo_toolbox_installed_translations() {
132 $title = __( 'Available Languages', 'bogo' );
133
134 $default_locale = bogo_get_default_locale();
135 $languages = array( $default_locale => bogo_get_language( $default_locale ) )
136 + bogo_available_languages();
137 ?>
138 <div class="tool-box">
139 <h3 class="title"><?php echo esc_html( $title ); ?></h3>
140 <ul id="translations">
141 <?php
142 foreach ( $languages as $locale => $language ) {
143 echo sprintf( '<li>%s</li>', esc_html( $language ) );
144 }
145 ?>
146 </ul>
147 </div>
148 <?php
149 }
150
151 function bogo_toolbox_add_translations() {
152 if ( ! wp_can_install_language_pack() ) {
153 return;
154 }
155
156 $title = __( 'Add Languages', 'bogo' );
157
158 $available_translations = wp_get_available_translations();
159 $languages = array_diff( bogo_languages(), bogo_available_languages() );
160
161 ?>
162 <div class="tool-box">
163 <h3 class="title"><?php echo esc_html( $title ); ?></h3>
164 <ul id="translations">
165 <?php
166 foreach ( $languages as $locale => $language ) {
167 if ( isset( $available_translations[$locale] ) ) {
168 $install_link = menu_page_url( 'bogo-tools', false );
169 $install_link = add_query_arg(
170 array( 'action' => 'install_translation', 'locale' => $locale ),
171 $install_link );
172 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
173 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
174 $install_link, __( 'Install', 'bogo' ) );
175
176 echo sprintf( '<li>%1$s %2$s</li>',
177 esc_html( $language ), $install_link );
178 } else {
179 echo sprintf( '<li>%s</li>', esc_html( $language ) );
180 }
181 }
182 ?>
183 </ul>
184 </div>
185 <?php
186 }
187
188 ?>