post_type ) && ( $post->post_type === 'wplng_translation' || $post->post_type === 'wplng_slug' ) ) { return true; } return false; } /** * Add wpLingua admin menu when API Key is not registered * * @return void */ function wplng_create_menu_register() { add_menu_page( __( 'wpLingua: Register', 'wplingua' ), __( 'wpLingua', 'wplingua' ), 'edit_posts', 'wplingua-settings', 'wplng_option_page_register', 'dashicons-translation', 31 ); } /** * Create wpLingua admin menu. */ function wplng_create_menu() { /* * Main wpLingua menu */ add_menu_page( __( 'wpLingua: Settings', 'wplingua' ), __( 'wpLingua', 'wplingua' ), 'edit_posts', 'wplingua-settings', '', 'dashicons-translation', 31 ); /* * Settings * * This is the visible entry used as the parent * for all wpLingua option pages. */ add_submenu_page( 'wplingua-settings', __( 'wpLingua: Settings', 'wplingua' ), __( 'Settings', 'wplingua' ), 'edit_posts', 'wplingua-settings', 'wplng_option_page_settings' ); /* * Hidden option pages * * These pages remain registered as children of * wplingua-settings, but their menu entries are * hidden later with CSS. */ add_submenu_page( 'wplingua-settings', __( 'wpLingua: Switcher', 'wplingua' ), __( 'Switcher', 'wplingua' ), 'edit_posts', 'wplingua-switcher', 'wplng_option_page_switcher' ); add_submenu_page( 'wplingua-settings', __( 'wpLingua: Exclusion', 'wplingua' ), __( 'Exclusion', 'wplingua' ), 'edit_posts', 'wplingua-exclusions', 'wplng_option_page_exclusions' ); add_submenu_page( 'wplingua-settings', __( 'wpLingua: Dictionary', 'wplingua' ), __( 'Dictionary', 'wplingua' ), 'edit_posts', 'wplingua-dictionary', 'wplng_option_page_dictionary' ); add_submenu_page( 'wplingua-settings', __( 'wplingua: Links & Medias', 'wplingua' ), __( 'Links & Medias', 'wplingua' ), 'edit_posts', 'wplingua-link-media', 'wplng_option_page_link_media' ); /* * Visible custom post type pages */ add_submenu_page( 'wplingua-settings', __( 'wpLingua: Website slugs', 'wplingua' ), __( 'Website slugs', 'wplingua' ), 'edit_posts', 'edit.php?post_type=wplng_slug', false ); add_submenu_page( 'wplingua-settings', __( 'wpLingua: Translations', 'wplingua' ), __( 'All translations', 'wplingua' ), 'edit_posts', 'edit.php?post_type=wplng_translation', false ); } /** * Keep wpLingua as the active parent menu * on all wpLingua option pages. * * @param string $parent_file The current parent menu file. * * @return string The parent menu file. */ function wplng_option_page_parent_file( $parent_file ) { if ( wplng_is_wplingua_settings_page() ) { return 'wplingua-settings'; } return $parent_file; } /** * Keep "Settings" as the active submenu * on all wpLingua option pages. * * @param string $submenu_file The current submenu file. * * @return string The submenu file. */ function wplng_option_page_submenu_file( $submenu_file ) { if ( wplng_is_wplingua_settings_page() ) { return 'wplingua-settings'; } return $submenu_file; } /** * Hide the option pages from the wpLingua submenu. * * The pages themselves remain registered in WordPress. * Therefore, they are still accessible directly by URL * and remain correctly associated with the wpLingua menu. */ function wplng_option_page_hide_submenu() { $css = ''; echo $css; } /** * Generates the navigation menu for wpLingua option pages. * * Creates a list of links to the different wpLingua settings pages, * highlighting the current page with the `button-primary` class. * * @param bool $display_none Whether to hide the menu by default. * * @return string The HTML markup for the option pages navigation menu. */ function wplng_option_page_settings_menu( $display_none = false ) { $data = array( array( 'page' => 'wplingua-settings', 'title' => __( 'General settings', 'wplingua' ), 'dashicon' => 'dashicons-admin-generic', ), array( 'page' => 'wplingua-switcher', 'title' => __( 'Language switcher', 'wplingua' ), 'dashicon' => 'dashicons-admin-settings', ), array( 'page' => 'wplingua-exclusions', 'title' => __( 'Exclusion', 'wplingua' ), 'dashicon' => 'dashicons-filter', ), array( 'page' => 'wplingua-dictionary', 'title' => __( 'Dictionary', 'wplingua' ), 'dashicon' => 'dashicons-book', ), array( 'page' => 'wplingua-link-media', 'title' => __( 'Links & Medias', 'wplingua' ), 'dashicon' => 'dashicons-format-gallery', ), ); $style = ''; if ( $display_none === true ) { $style = ' style="display: none;"'; } $html = '
'; $html .= ''; $html .= '
'; // End .wplng-option-page-menu return $html; } /** * Customize the admin footer text displayed on wpLingua option pages. * * @param string $text The default footer text. * @return string The customized footer text for wpLingua pages. */ function wplng_admin_footer_text( $text ) { if ( wplng_is_wplingua_admin_page() ) { $text = ' '; if ( empty( wplng_get_api_data() ) ) { $text .= esc_html__( 'Thank you for choosing wpLingua!', 'wplingua' ); } else { $text .= sprintf( esc_html__( 'If you like wpLingua please leave us a %1$s rating. A huge thanks!', 'wplingua' ), '★★★★★' ); } } return $text; } /** * Set custom update_footer text on wpLingua options pages * * @param string $text The default footer text to be modified. * @return string The customized footer text for wpLingua pages. */ function wplng_update_footer( $text ) { if ( wplng_is_wplingua_admin_page() ) { $text = ''; $text .= 'wplingua.com'; $text .= ' | '; $text .= ''; $text .= 'GitHub'; $text .= ' | '; $text .= esc_html__( 'Version', 'wplingua' ); $text .= ' ' . esc_html( WPLNG_PLUGIN_VERSION ); } return $text; } /** * Add 'Settings' link on wpLingua in the plugin list * * @param array $settings * @return array */ function wplng_settings_link( $settings ) { $url = add_query_arg( 'page', 'wplingua-settings', get_admin_url() . 'admin.php' ); $link = ''; $link .= esc_html__( 'Settings', 'wplingua' ); $link .= ''; $settings[] = $link; return $settings; } /** * Redirect to the wpLingua settings page upon plugin activation. * * @param string $plugin The plugin file path that was activated. * @return void */ function wplng_plugin_activation_redirect( $plugin ) { if ( ! wp_doing_ajax() && WPLNG_PLUGIN_FILE === $plugin ) { wp_safe_redirect( admin_url( 'admin.php?page=wplingua-settings' ) ); exit(); } } /** * Display a notice if the plugin is activate but not configured * * @return void */ function wplng_admin_notice_no_key_set() { $url = add_query_arg( 'page', 'wplingua-settings', get_admin_url() . 'admin.php' ); $html = '
'; $html .= '

'; $html .= ' '; $html .= esc_html__( 'wpLingua - Translation solution for multilingual website', 'wplingua' ); $html .= '

'; $html .= '

'; $html .= esc_html__( 'wpLingua is installed, but not yet configured. You are just a few clicks away from making your website multilingual!', 'wplingua' ); $html .= '
'; $html .= ''; $html .= esc_html__( 'Go to the configuration page', 'wplingua' ); $html .= ''; $html .= '

'; $html .= '
'; echo $html; } /** * Get the list of activated incompatible plugins * * @return array [Plugin name => Plugin file] */ function wplng_get_incompatible_plugins() { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; } /** * Get incompatible plugins */ $incompatible_list = array( 'Automatic Translator' => 'auto-translate/auto-translate.php', 'Autoglot' => 'autoglot/autoglot.php', 'clonable' => 'clonable/clonable-wp.php', 'ConveyThis Translate' => 'conveythis-translate/index.php', 'Falang' => 'falang/falang.php', 'Google Translator' => 'google-language-translator/google-language-translator.php', 'Google Website Translator' => 'google-website-translator/google-website-translator.php', 'Gtranslate' => 'gtranslate/gtranslate.php', 'linguise' => 'linguise/linguise.php', 'Lokalise' => 'lokalise/lokalise.php', 'localizejs' => 'localizejs/localizejs.php', 'Multilanguage' => 'multilanguage/multilanguage.php', 'Polylang' => 'polylang/polylang.php', 'TranslatePress' => 'translatepress-multilingual/index.php', 'WEGLOT' => 'weglot/weglot.php', 'WPML' => 'sitepress-multilingual-cms/sitepress.php', 'WP Multilang' => 'wp-multilang/wp-multilang.php', ); $incompatible_detected = array(); foreach ( $incompatible_list as $name => $file ) { if ( is_plugin_active( $file ) ) { $incompatible_detected[ $name ] = $file; } } return $incompatible_detected; } /** * Display a notice if an incompatible plugin is detected. * * @return void|string Outputs the admin notice or returns nothing if no conflicts are found. */ function wplng_admin_notice_incompatible_plugin() { $incompatible_plugins = wplng_get_incompatible_plugins(); if ( empty( $incompatible_plugins ) ) { return; } $html = '
$file ) { $deactivate_url = wp_nonce_url( add_query_arg( array( 'action' => 'deactivate', 'plugin' => urlencode( $file ), ), get_admin_url() . 'plugins.php' ), 'deactivate-plugin_' . $file ); $deactivate_title = sprintf( esc_html__( 'Deactivate plugin: %1$s', 'wplingua' ), $name ); $html .= '
  • '; $html .= '' . esc_html( $name ) . ' | '; $html .= ''; $html .= esc_html__( 'Deactivate', 'wplingua' ); $html .= ''; $html .= '
  • '; } $html .= ''; $html .= '

    '; $url_manage_plugins = add_query_arg( 'plugin_status', 'active', get_admin_url() . 'plugins.php' ); $html .= '= 0 ) { return; } $html = '