/** * Print tab content and provide two hooks. * * @return void */ public function render_content() { ?> <form action="<?php print $this->page_data->get_form_action(); ?> " method="post"> <input type="hidden" name="action" value="<?php echo $this->page_data->get_action_name(); ?> " /> <input type="hidden" name="id" value="<?php echo $this->blog_id; ?> " /> <?php wp_nonce_field($this->page_data->get_nonce_action(), $this->page_data->get_nonce_name()); $siteoption = get_site_option('inpsyde_multilingual', array()); $languages = $this->language_api->get_db()->get_items(array('page' => -1)); print '<table class="form-table mlp-admin-settings-table">'; $this->show_language_options($siteoption, $languages); $this->show_blog_relationships($siteoption, $languages); /** * Runs at the end of but still inside the site settings table. * * @param int $blog_id Blog ID. */ do_action('mlp_blogs_add_fields', $this->blog_id); if (has_action('mlp_blogs_add_fields_secondary')) { _doing_it_wrong('mlp_blogs_add_fields_secondary', 'mlp_blogs_add_fields_secondary is deprecated, use mlp_blogs_add_fields instead.', '2.1'); } /** * @see mlp_blogs_add_fields * @deprecated */ do_action('mlp_blogs_add_fields_secondary', $this->blog_id); print '</table>'; submit_button(); ?> </form> <?php }
/** * Update option WPLANG in DB for new sites. * * @param int $blog_id * @return void */ private function update_wplang($blog_id) { $posted = $this->get_posted_language(); if (!$posted) { return; } // search for wp_locale where search = $http_name $search = array('fields' => array('wp_locale'), 'where' => array(array('field' => 'http_name', 'search' => $posted))); $available_language = $this->language_api->get_db()->get_items($search, OBJECT); // no results found? -> return if (empty($available_language)) { return; } // getting the first wp_locale $wp_locale = $available_language[0]->wp_locale; $available_lang_files = get_available_languages(); if (!in_array($wp_locale, $available_lang_files)) { return; } update_blog_option($blog_id, 'WPLANG', $wp_locale); }
/** * Print tab content and provide two hooks. * * @return void */ public function render_content() { $languages = $this->language_api->get_db()->get_items(array('page' => -1)); ob_start(); ?> <h3>MultilingualPress</h3> <table class="form-table"> <tr class="form-field"> <td> <label for="inpsyde_multilingual_lang"> <?php esc_html_e('Language', 'multilingualpress'); ?> </label> </td> <td> <select name="inpsyde_multilingual_lang" id="inpsyde_multilingual_lang"> <option value="-1"><?php esc_html_e('Choose language', 'multilingualpress'); ?> </option> <?php foreach ($languages as $language) { // missing HTTP code if (empty($language->http_name)) { continue; } echo '<option value="' . esc_attr($language->http_name) . '">' . $language->english_name . '/' . $language->native_name . '</option>'; } ?> </select> </td> </tr> <tr class="form-field"> <td> <label for="inpsyde_multilingual_text"> <?php esc_html_e('Alternative language title', 'multilingualpress'); ?> </label> </td> <td> <input class="regular-text" type="text" id="inpsyde_multilingual_text" name="inpsyde_multilingual_text" /> <p class="description"><?php esc_html_e('Enter a title here that you want to be displayed in the frontend instead of the default one (i.e. "My English Site")', 'multilingualpress'); ?> </p> </td> </tr> <tr class="form-field"> <td> <label for="inpsyde_multilingual_text"> <?php esc_html_e('Relationships', 'multilingualpress'); ?> </label> </td> <td><?php $site_option = get_site_option('inpsyde_multilingual', array()); foreach ($site_option as $blog_id => $meta) { $blog_id = (int) $blog_id; // Get blog display name switch_to_blog($blog_id); $blog_name = esc_html(get_bloginfo('Name')); restore_current_blog(); $id = "related_blog_{$blog_id}"; ?> <p> <label for="<?php echo $id; ?> "> <input style="width:auto;" id="<?php echo $id; ?> " type="checkbox" name="related_blogs[]" value="<?php echo $blog_id; ?> " /> <?php echo $blog_name; ?> - <?php echo Mlp_Helpers::get_blog_language($blog_id); ?> </label> </p> <?php } ?> <p class="description"> <?php esc_html_e('You can connect this site only to sites with an assigned language. Other sites will not show up here.', 'multilingualpress'); ?> </p> </td> </tr> <?php do_action('mlp_after_new_blog_fields'); ?> </table> <?php $template = ob_get_contents(); ob_end_clean(); ?> <script> ( function( $ ) { $(document).ready( function(){ var submit = $( 'form' ).find( '.submit' ), template = '<?php echo str_replace("\n", "", $template); ?> ' ; submit.before( template ); } ); } )( jQuery ); </script> <?php }
/** * Prints the template for the MultilingualPress table, and fires an action to inject markup. * * @wp-hook admin_footer * * @return void */ public function print_template() { global $hook_suffix; if ('site-new.php' !== $hook_suffix) { return; } $db = $this->language_api->get_db(); $languages = $db->get_items(array('page' => -1)); ?> <script type="text/html" id="mlp-add-new-site-template"> <h3> <?php esc_html_e('MultilingualPress', 'multilingual-press'); ?> </h3> <table class="form-table"> <tr class="form-field"> <td> <label for="mlp-site-language"> <?php esc_html_e('Language', 'multilingual-press'); ?> </label> </td> <td> <select name="inpsyde_multilingual_lang" id="mlp-site-language" autocomplete="off"> <option value="-1"> <?php esc_html_e('Choose language', 'multilingual-press'); ?> </option> <?php foreach ($languages as $language) { ?> <?php $this->render_language_option($language); ?> <?php } ?> </select> </td> </tr> <tr class="form-field"> <td> <label for="inpsyde_multilingual_text"> <?php esc_html_e('Alternative language title', 'multilingual-press'); ?> </label> </td> <td> <input type="text" name="inpsyde_multilingual_text" class="regular-text" id="inpsyde_multilingual_text"> <p class="description"> <?php esc_html_e('Enter a title here that you want to be displayed in the frontend instead of the default one (i.e. "My English Site")', 'multilingual-press'); ?> </p> </td> </tr> <tr class="form-field"> <td> <label for="inpsyde_multilingual_text"> <?php esc_html_e('Relationships', 'multilingual-press'); ?> </label> </td> <td> <?php $this->render_relationships(); ?> <p class="description"> <?php esc_html_e('You can connect this site only to sites with an assigned language. Other sites will not show up here.', 'multilingual-press'); ?> </p> </td> </tr> <?php /** * Runs at the end but still inside the new blog fields table. */ do_action('mlp_after_new_blog_fields'); ?> </table> </script> <?php }