Plugin Directory

source: multilanguage/trunk/includes/class-mltlngg-settings.php

Last change on this file was 3356543, checked in by bestwebsoft, 3 months ago

"V1.5.1 - * The compatibility with new WordPress version updated. "

  • Property svn:executable set to *
File size: 18.2 KB
Line 
1<?php
2/**
3 * Displays the content on the plugin settings page
4 */
5
6if ( ! defined( 'ABSPATH' ) ) {
7        exit;
8}
9
10if ( ! class_exists( 'Mltlngg_Settings_Tabs' ) ) {
11        class Mltlngg_Settings_Tabs extends Bws_Settings_Tabs {
12                /**
13                 * Name for language switcher
14                 *
15                 * @var string
16                 */
17                private $language_switcher_name;
18                /**
19                 * Constructor.
20                 *
21                 * @access public
22                 *
23                 * @see Bws_Settings_Tabs::__construct() for more information on default arguments.
24                 *
25                 * @param string $plugin_basename Plugin basename.
26                 */
27                public function __construct( $plugin_basename ) {
28                        global $mltlngg_options, $mltlngg_plugin_info, $wp_roles;
29
30                        $tabs = array(
31                                'settings'    => array( 'label' => esc_html__( 'Settings', 'multilanguage' ) ),
32                                'misc'        => array( 'label' => esc_html__( 'Misc', 'multilanguage' ) ),
33                                'custom_code' => array( 'label' => esc_html__( 'Custom Code', 'multilanguage' ) ),
34                                'license'     => array( 'label' => esc_html__( 'License Key', 'multilanguage' ) ),
35                        );
36
37                        parent::__construct(
38                                array(
39                                        'plugin_basename'    => $plugin_basename,
40                                        'plugins_info'       => $mltlngg_plugin_info,
41                                        'prefix'             => 'mltlngg',
42                                        'default_options'    => mltlngg_get_options_default(),
43                                        'options'            => $mltlngg_options,
44                                        'is_network_options' => is_network_admin(),
45                                        'tabs'               => $tabs,
46                                        'doc_link'           => 'https://bestwebsoft.com/documentation/multilanguage/multilanguage-user-guide/',
47                                        'wp_slug'            => 'multilanguage',
48                                        'link_key'           => 'fa164f00821ed3a87e6f78cb3f5c277b',
49                                        'link_pn'            => '143',
50                                )
51                        );
52
53                        $this->language_switcher_name = array(
54                                'drop-down-list'   => esc_html__( 'Drop-down list (flag + title)', 'multilanguage' ),
55                                'drop-down-titles' => esc_html__( 'Drop-down list (title)', 'multilanguage' ),
56                                'drop-down-icons'  => esc_html__( 'Drop-down list (flag)', 'multilanguage' ),
57                                'list-flag-title'  => esc_html__( 'List (flag + title)', 'multilanguage' ),
58                                'list-titles'      => esc_html__( 'List (title)', 'multilanguage' ),
59                                'list-short-title' => esc_html__( 'List (short title)', 'multilanguage' ),
60                                'flags-icons'      => esc_html__( 'Flag', 'multilanguage' ),
61                                'gt'               => esc_html__( 'Google Auto Translate (drop-down only)', 'multilanguage' ),
62                                'gt-horizontal'    => esc_html__( 'Google Auto Translate (horizontal)', 'multilanguage' ),
63                                'gt-vertical'      => esc_html__( 'Google Auto Translate (vertical)', 'multilanguage' ),
64                        );
65
66                        $enabled_roles = array();
67                        $roles         = $wp_roles->roles;
68                        foreach ( $roles as $key => $role ) {
69                                if ( ! empty( $role['capabilities']['edit_posts'] ) ) {
70                                        $enabled_roles[ $key ] = $role;
71                                }
72                        }
73                        $this->enabled_roles = $enabled_roles;
74
75                        add_filter( get_parent_class( $this ) . '_additional_restore_options', array( $this, 'additional_restore_options' ) );
76                        add_action( get_parent_class( $this ) . '_display_metabox', array( $this, 'display_metabox' ) );
77                        add_action( get_parent_class( $this ) . '_display_custom_messages', array( $this, 'display_custom_messages' ) );
78                        add_action( get_parent_class( $this ) . '_additional_misc_options_affected', array( $this, 'additional_misc_options_affected' ) );
79                }
80
81                /**
82                 * Save plugin options to the database
83                 *
84                 * @access public
85                 * @return array    The action results
86                 */
87                public function save_options() {
88                        global $wpdb;
89
90                        $message = '';
91                        $notice  = '';
92                        $error   = '';
93
94                        if ( isset( $_POST['mltlngg_nonce_admin'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['mltlngg_nonce_admin'] ) ), plugin_basename( __FILE__ ) ) ) {
95
96                                $this->options['language_switcher'] = ( isset( $_POST['mltlngg_language_switcher'] ) &&
97                                        array_key_exists( sanitize_text_field( wp_unslash( $_POST['mltlngg_language_switcher'] ) ), $this->language_switcher_name )
98                                ) ? sanitize_text_field( wp_unslash( $_POST['mltlngg_language_switcher'] ) ) : 'drop-down-list';
99
100                                $this->options['hide_link_slug']           = isset( $_POST['mltlngg_hide_link_slug'] ) ? 0 : 1;
101                                $this->options['wp_localization']          = isset( $_POST['mltlngg_wp_localization'] ) ? 1 : 0;
102                                $this->options['google_auto_translate']    = isset( $_POST['mltlngg_google_auto_translate'] ) ? 1 : 0;
103                                $this->options['translate_open_graph']     = isset( $_POST['mltlngg_translate_open_graph'] ) ? 1 : 0;
104                                $this->options['display_alternative_link'] = isset( $_POST['mltlngg_display_alternative_link'] ) ? 1 : 0;
105                                $this->options['save_mode']                = isset( $_POST['mltlngg_save_mode'] ) && 'ajax' === sanitize_text_field( wp_unslash( $_POST['mltlngg_save_mode'] ) ) ? 'ajax' : 'manual';
106                                $this->options['search']                   = isset( $_POST['mltlngg_search'] ) && in_array( sanitize_text_field( wp_unslash( $_POST['mltlngg_search'] ) ), array( 'single', 'all' ), true ) ? sanitize_text_field( wp_unslash( $_POST['mltlngg_search'] ) ) : 'single';
107                                $this->options['enabled_roles']            = isset( $_POST['mltlngg_enabled_roles'] ) ? array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['mltlngg_enabled_roles'] ) ) : array();
108
109                                $message = esc_html__( 'Settings saved.', 'multilanguage' );
110
111                                update_option( 'mltlngg_options', $this->options );
112                        }
113
114                        return compact( 'message', 'notice', 'error' );
115                }
116
117                /**
118                 * Display Settings tab
119                 */
120                public function tab_settings() { ?>
121                        <h3 class="bws_tab_label"><?php esc_html_e( 'Multilanguage Settings', 'multilanguage' ); ?></h3>
122                        <?php $this->help_phrase(); ?>
123                        <hr>
124                        <table class="form-table">
125                                <tr>
126                                        <th><?php esc_html_e( 'Google Auto Translate', 'multilanguage' ); ?></th>
127                                        <td>
128                                                <input type="checkbox" name="mltlngg_google_auto_translate"  value="1" <?php checked( 1, $this->options['google_auto_translate'] ); ?> /> <span class="bws_info"><?php esc_html_e( 'Enable to activate webpages auto translate. When google auto translate is enabled, a Google language switcher is displayed on the page allowing visitors to translate the page content automatically.', 'multilanguage' ); ?></span>
129                                        </td>
130                                </tr>
131                                <tr>
132                                        <th><?php esc_html_e( 'Default Language Switcher Type (for shortcode only)', 'multilanguage' ); ?></th>
133                                                <td>
134                                                        <select name="mltlngg_language_switcher">
135                                                                <?php foreach ( $this->language_switcher_name as $key => $value ) { ?>
136                                                                                <option <?php selected( $this->options['language_switcher'], $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></option>
137                                                                <?php } ?>
138                                                        </select>
139                                                </td>
140                                </tr>
141                        </table>
142                        <?php if ( ! $this->hide_pro_tabs ) { ?>
143                                <div class="bws_pro_version_bloc">
144                                        <div class="bws_pro_version_table_bloc">
145                                                <button type="submit" name="bws_hide_premium_options" class="notice-dismiss bws_hide_premium_options" title="<?php esc_html_e( 'Close', 'multilanguage' ); ?>"></button>
146                                                <div class="bws_table_bg"></div>
147                                                <table class="form-table bws_pro_version">
148                                                        <tr>
149                                                                <th><?php esc_html_e( 'Switch Language Automatically', 'multilanguage' ); ?></th>
150                                                                <td>
151                                                                        <input type="checkbox" <?php disabled( true ); ?> /> <span class="bws_info"><?php esc_html_e( 'Enable to identify user IP and switch website language automatically based on the location.', 'multilanguage' ); ?></span>
152                                                                </td>
153                                                        </tr>
154                                                        <tr>
155                                                                <th><?php esc_html_e( 'Slug Position in the URL', 'multilanguage' ); ?></th>
156                                                                <td>
157                                                                        <fieldset class="mltlngg_slug_position">
158                                                                                <?php
159                                                                                global $mltlngg_current_language;
160                                                                                $posts = get_posts(
161                                                                                        array(
162                                                                                                'post_type' => 'page',
163                                                                                                'posts_per_page' => 1,
164                                                                                        )
165                                                                                );
166                                                                                $url   = ( ! empty( $posts ) ) ? get_permalink( $posts[0] ) : home_url();
167                                                                                $args  = array(
168                                                                                        'url'   => $url,
169                                                                                        'force' => 'display',
170                                                                                );
171                                                                                ?>
172                                                                                <label>
173                                                                                        <input type="radio"
174                                                                                        <?php
175                                                                                        disabled( true );
176                                                                                        checked( false );
177                                                                                        ?>
178                                                                                         />
179                                                                                        <?php
180                                                                                        esc_html_e( 'Before', 'multilanguage' );
181                                                                                        printf(
182                                                                                                '&ensp;<code>%s</code>',
183                                                                                                esc_url( preg_replace( '~(://)~', '$0<b>en.</b>', $url ) )
184                                                                                        );
185                                                                                        ?>
186                                                                                </label>
187                                                                                <br>
188                                                                                <label>
189                                                                                        <input type="radio"
190                                                                                        <?php
191                                                                                        disabled( true );
192                                                                                        checked( true );
193                                                                                        ?>
194                                                                                        />
195                                                                                        <?php
196                                                                                        esc_html_e( 'After', 'multilanguage' );
197                                                                                        printf(
198                                                                                                '&ensp;<code>%s</code>',
199                                                                                                esc_url( preg_replace( '~(?<=[/=])(' . $mltlngg_current_language . ')(?![\w\d-])~', '<b>en</b>', mltlngg_get_lang_link( $args ) ) )
200                                                                                        );
201                                                                                        ?>
202                                                                                </label>
203                                                                        </fieldset>
204                                                                </td>
205                                                        </tr>
206                                                        <tr>
207                                                                <th><?php esc_html_e( 'Permalink Translation', 'multilanguage' ); ?></th>
208                                                                <td>
209                                                                        <input type="checkbox" <?php disabled( true ); ?> /> <span class="bws_info"><?php esc_html_e( 'Enable to translate pages, posts, and custom posts slugs in different languages.', 'multilanguage' ); ?></span>
210                                                                </td>
211                                                        </tr>
212                                                </table>
213                                        </div>
214                                        <?php $this->bws_pro_block_links(); ?>
215                                </div>
216                        <?php } ?>
217                        <table class="form-table">
218                                <tr>
219                                        <th><?php esc_html_e( 'Default Language Slug', 'multilanguage' ); ?></th>
220                                        <td>
221                                                <input type="checkbox" name="mltlngg_hide_link_slug" value="1" <?php checked( 0, $this->options['hide_link_slug'] ); ?> /> <span class="bws_info"><?php esc_html_e( 'Enable to show default language slug in the URL.', 'multilanguage' ); ?></span>
222                                        </td>
223                                </tr>
224                                <tr>
225                                        <th><?php esc_html_e( 'WordPress Language', 'multilanguage' ); ?></th>
226                                        <td>
227                                                <input name="mltlngg_wp_localization" type="checkbox" value="1" <?php checked( 1, $this->options['wp_localization'] ); ?>> <span class="bws_info"><?php esc_html_e( 'Enable to switch WordPress language automatically when the language is changed in the front-end. Installed WordPress language packs are required. To install a new language simply go to the Settings > General and choose it in the Site Language option.', 'multilanguage' ); ?></span>
228                                        </td>
229                                </tr>
230                                <tr>
231                                        <th><?php esc_html_e( 'Open Graph Markup', 'multilanguage' ); ?></th>
232                                        <td>
233                                                <input type="checkbox" name="mltlngg_translate_open_graph" value="1" <?php checked( $this->options['translate_open_graph'] ); ?> />
234                                                <span class="bws_info">
235                                                        <?php
236                                                        printf(
237                                                                esc_html__( 'Enable to add the ability to translate %s.', 'multilanguage' ) . ' ',
238                                                                '<a href="http://ogp.me/" target="_blank">' . esc_html__( 'open graph meta tags', 'multilanguage' ) . '</a>'
239                                                        );
240                                                        printf(
241                                                                esc_html__( 'This option automatically adds metadata for each language in the %s section. Facebook and other social networks use this data when your pages are shared.', 'multilanguage' ),
242                                                                '&lt;head&gt;'
243                                                        );
244                                                        ?>
245                                                </span>
246                                        </td>
247                                </tr>
248                                <tr>
249                                        <th><?php esc_html_e( 'Hreflang Attribute', 'multilanguage' ); ?></th>
250                                        <td>
251                                                <input type="checkbox" name="mltlngg_display_alternative_link" value="1" <?php checked( 1, $this->options['display_alternative_link'] ); ?> /> <span class="bws_info"><?php printf( esc_html__( 'Enable to add hreflang attribute used by search engines and display the correct language or regional URL in search results. This option inserts automatically the respective link for each language within the %s section.', 'multilanguage' ), '&lt;head&gt;' ); ?></span>
252                                        </td>
253                                </tr>
254                                <?php if ( ! defined( 'ET_BUILDER_THEME' ) && ! defined( 'WPB_VC_VERSION' ) ) { ?>
255                                        <tr>
256                                                <th><?php esc_html_e( 'Translation Saving Mode for Classic Editor', 'multilanguage' ); ?></th>
257                                                <td>
258                                                        <fieldset>
259                                                                <label>
260                                                                        <input name="mltlngg_save_mode" type="radio" value="ajax" <?php checked( 'ajax', $this->options['save_mode'] ); ?> />
261                                                                        <?php esc_html_e( 'Auto', 'multilanguage' ); ?> (AJAX) <span class="bws_info"><?php esc_html_e( 'If this option is selected, there may be a problem with custom post types.', 'multilanguage' ); ?></span>
262                                                                </label>
263                                                                <br>
264                                                                <label>
265                                                                        <input name="mltlngg_save_mode" type="radio" value="manual" <?php checked( 'manual', $this->options['save_mode'] ); ?> />
266                                                                        <?php esc_html_e( 'Manual (Save Changes button)', 'multilanguage' ); ?> (<?php esc_html_e( 'Recommended', 'multilanguage' ); ?>)
267                                                                </label>
268                                                        </fieldset>
269                                                        <span class="bws_info"><?php esc_html_e( 'Enable Manual mode if you have some problems with translations saving using Auto mode.', 'multilanguage' ); ?></span>
270                                                </td>
271                                        </tr>
272                                <?php } ?>
273                                <tr>
274                                        <th><?php esc_html_e( 'Default Search by', 'multilanguage' ); ?></th>
275                                        <td>
276                                                <fieldset>
277                                                        <label>
278                                                                <input type="radio" name="mltlngg_search" value="single" <?php checked( 'single', $this->options['search'] ); ?> /> <?php esc_html_e( 'Current language', 'multilanguage' ); ?>
279                                                        </label>
280                                                        <br>
281                                                        <label>
282                                                                <input type="radio" name="mltlngg_search" value="all" <?php checked( 'all', $this->options['search'] ); ?> /> <?php esc_html_e( 'All active languages', 'multilanguage' ); ?>
283                                                        </label>
284                                                </fieldset>
285                                        </td>
286                                </tr>
287                                <tr>
288                                        <th><?php esc_html_e( 'Enable translate for', 'multilanguage' ); ?></th>
289                                        <td>
290                                                <fieldset>
291                                                        <label class=hide-if-no-js>
292                                                                <input type="checkbox" class="mltlngg_select_all" /><strong><?php esc_html_e( 'All', 'multilanguage' ); ?></strong>
293                                                        </label><br />
294                                                        <?php
295                                                        foreach ( $this->enabled_roles as $role => $fields ) {
296                                                                printf(
297                                                                        '<label><input type="checkbox" name="mltlngg_enabled_roles[]" class="mltlngg_role" value="%1$s" %2$s /> %3$s</label><br/>',
298                                                                        esc_attr( $role ),
299                                                                        checked( in_array( $role, $this->options['enabled_roles'] ), true, false ),
300                                                                        esc_attr( translate_user_role( $fields['name'] ) )
301                                                                );
302                                                        }
303                                                        ?>
304                                                </fieldset>
305                                        </td>
306                                </tr>
307                        </table><!-- .form-table -->
308                        <?php
309                        wp_nonce_field( plugin_basename( __FILE__ ), 'mltlngg_nonce_admin', true, true );
310                }
311
312                /**
313                 * Display custom options on the 'misc' tab
314                 *
315                 * @access public
316                 */
317                public function additional_misc_options_affected() {
318                        do_action( 'mltlngg_settings_page_misc_action', $this->options );
319                        ?>
320                        </table>
321                        <!-- pls -->
322                        <?php if ( ! $this->hide_pro_tabs ) { ?>
323                                <div class="bws_pro_version_bloc">
324                                        <div class="bws_pro_version_table_bloc">
325                                                <button type="submit" name="bws_hide_premium_options" class="notice-dismiss bws_hide_premium_options" title="<?php esc_html_e( 'Close', 'limit-attempts' ); ?>"></button>
326                                                <div class="bws_table_bg"></div>
327                                                <table class="form-table bws_pro_version">
328                                                        <tr>
329                                                                <th><?php esc_html_e( 'Import Database', 'multilanguage' ); ?></th>
330                                                                <td>
331                                                                        <fieldset>
332                                                                                <?php if ( $this->is_multisite && ! is_network_admin() ) { ?>
333                                                                                        <p class="update-nag" style="padding: 3px;font-size: 12px;"><?php printf( esc_html__( 'This option is common to all subdomains.%sWe recommend you do not change this option without the consent of the administrator of your network.', 'multilanguage' ), '<br/>' ); ?></p>
334                                                                                <?php } ?>
335                                                                                <p id="bwscntrtbl_message" class="bws_info_small"><?php printf( esc_html__( 'Please upload the files manually using the following link %s.', 'multilanguage' ), '<a href="https://dev.maxmind.com/geoip/geolite2-free-geolocation-data" target="_blank">http://geolite.maxmind.com</a>' ); ?>                                           
336                                                                                </p>
337                                                                                <div>
338                                                                                        <input <?php disabled( true ); ?> type="file" name="bwscntrtbl_upload_file" />
339                                                                                        <br>
340                                                                                        <input type="submit" name="bwscntrtbl_button_import" <?php disabled( true ); ?> class="button button-secondary" value="<?php esc_html_e( 'Import Now', 'multilanguage' ); ?>" />
341                                                                                </div>
342                                                                                <div class="bws_info">
343                                                                                        <?php esc_html_e( 'Receive an information about each IP address, and to which country it belongs to.', 'multilanguage' ); ?>
344                                                                                </div>
345                                                                                <div class="bws_info">
346                                                                                        <?php echo esc_html__( 'Follow this instruction to download or update the country table', 'multilanguage' ) . '&nbsp;-&nbsp;<a href="https://bestwebsoft.com/documentation/admin-panel-issues/how-to-import-or-update-the-country-table/" target="_blank">' . esc_html__( 'How to import or update the Country Table', 'multilanguage' ) . '</a>'; ?>
347                                                                                </div>
348                                                                        </fieldset>
349                                                                </td>
350                                                        </tr>
351                                                </table>
352                                        </div>
353                                        <?php $this->bws_pro_block_links(); ?>
354                                </div>
355                        <?php } ?>
356                        <!-- end pls -->
357                        <table class="form-table">
358                        <?php
359                }
360
361                /**
362                 * Custom functions for "Restore plugin options to defaults"
363                 *
364                 * @access public
365                 * @param array $default_options Default options.
366                 */
367                public function additional_restore_options( $default_options ) {
368                        $default_options['list_of_languages'] = $this->options['list_of_languages'];
369                        return $default_options;
370                }
371
372                /**
373                 * Display custom metabox
374                 *
375                 * @access public
376                 */
377                public function display_metabox() {
378                        ?>
379                        <div class="postbox">
380                                <h3 class="hndle">
381                                        <?php esc_html_e( 'Language Switcher', 'multilanguage' ); ?>
382                                </h3>
383                                <div class="inside">
384                                        <p><?php esc_html_e( 'Add "Multilanguage Switcher" to a widget.', 'multilanguage' ); ?> <a href="widgets.php"><?php esc_html_e( 'Navigate to Widgets', 'multilanguage' ); ?></a></p>
385                                        <p><?php esc_html_e( 'Add "Multilanguage Switcher" to a menu.', 'multilanguage' ); ?> <a href="nav-menus.php"><?php esc_html_e( 'Navigate to Menus', 'multilanguage' ); ?></a></p>
386                                        <?php esc_html_e( 'Add a language switcher to your posts, pages or custom post types by using the following shortcode:', 'multilanguage' ); ?>
387                                        <?php bws_shortcode_output( '[multilanguage_switcher]' ); ?>
388                                        <p><?php esc_html_e( 'Add a language switcher to PHP template files by using the following code', 'multilanguage' ); ?>:</p>
389                                        <code>&#60;?php if ( function_exists( 'mltlngg_display_switcher' ) ) mltlngg_display_switcher(); ?&#62;</code>
390                                </div>
391                        </div>
392                        <?php
393                }
394
395                /**
396                 * Display custom message
397                 *
398                 * @access public
399                 */
400                public function display_custom_messages() {
401                        ?>
402                        <noscript>
403                                <div class="error below-h2">
404                                        <p><strong><?php esc_html_e( 'Please enable JavaScript in your browser.', 'multilanguage' ); ?></strong></p>
405                                </div>
406                        </noscript>
407                        <?php
408                }
409        }
410}
Note: See TracBrowser for help on using the repository browser.