create(); if ( $is_admin === true || $http_referer->is_rest_request_called_from_post_edit_page() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { $wpml_post_translations = new WPML_Admin_Post_Actions( $settings, $wpdb ); } else { $wpml_post_translations = new WPML_Frontend_Post_Actions( $settings, $wpdb ); wpml_load_frontend_tax_filters (); } $wpml_post_translations->init(); } function wpml_load_request_handler( $is_admin, $active_language_codes, $default_language ) { global $wpml_request_handler, $wpml_url_converter; if ( ! isset( $wpml_request_handler ) ) { require WPML_PLUGIN_PATH . '/inc/request-handling/wpml-request.class.php'; require WPML_PLUGIN_PATH . '/inc/request-handling/wpml-backend-request.class.php'; } $wpml_cookie = new WPML_Cookie(); $wp_api = new WPML_WP_API(); if ( $is_admin === true ) { $wpml_request_handler = new WPML_Backend_Request( $wpml_url_converter, $active_language_codes, $default_language, $wpml_cookie, $wp_api ); } else { $wpml_request_handler = new WPML_Frontend_Request( $wpml_url_converter, $active_language_codes, $default_language, $wpml_cookie, $wp_api ); } return $wpml_request_handler; } function wpml_load_query_filter( $installed ) { global $wpml_query_filter, $sitepress, $wpdb, $wpml_post_translations, $wpml_term_translations; $wpml_query_filter = $wpml_query_filter ? $wpml_query_filter : new WPML_Query_Filter( $sitepress, $wpdb, $wpml_post_translations, $wpml_term_translations ); if ( $installed ) { if ( ! has_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ) ) ) { add_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ), 10, 2 ); add_filter( 'posts_where', array( $wpml_query_filter, 'posts_where_filter' ), 10, 2 ); } } } function load_wpml_url_converter( $settings, $domain_validation, $default_lang_code ) { /** * @var WPML_URL_Converter $wpml_url_converter * @var WPML_Language_Resolution $wpml_language_resolution */ global $wpml_url_converter, $wpml_language_resolution; $url_type = isset( $settings['language_negotiation_type'] ) ? $settings['language_negotiation_type'] : false; $url_type = $domain_validation ? $domain_validation : $url_type; $active_language_codes = $wpml_language_resolution->get_active_language_codes(); $factory = new WPML_URL_Converter_Factory( $settings, $default_lang_code, $active_language_codes ); $wpml_url_converter = $factory->create( (int) $url_type ); return $wpml_url_converter; } /** * @param string $req_uri * @param WPML_URL_Converter $wpml_url_converter * @param bool $directory * * @return string */ function wpml_validate_host( $req_uri, $wpml_url_converter, $directory = true ) { if ( $directory === true ) { $req_uri_parts = array_filter ( explode ( '/', $req_uri ) ); $lang_slug = array_pop ( $req_uri_parts ); if ( strpos ( $lang_slug, '?' ) === 0 ) { $lang_slug = array_pop ( $req_uri_parts ); } elseif ( strpos ( $lang_slug, '?' ) !== false ) { $parts = explode ( '?', $lang_slug ); $lang_slug = array_shift ( $parts ); } } else { $lang_slug = ''; } return ''; } /** * Checks if a given taxonomy is currently translated * * @param string $taxonomy name/slug of a taxonomy * @return bool true if the taxonomy is currently set to being translatable in WPML */ function is_taxonomy_translated( $taxonomy ) { return in_array( $taxonomy, array( 'category', 'post_tag', 'nav_menu' ), true ) || in_array( $taxonomy, array_keys( array_filter( icl_get_setting( 'taxonomies_sync_option', array() ) ) ) ); } /** * Checks if a given post_type is currently translated * * @param string $post_type name/slug of a post_type * @return bool true if the post_type is currently set to being translatable in WPML */ function is_post_type_translated( $post_type ) { return 'nav_menu_item' === $post_type || in_array( $post_type, array_keys( array_filter( icl_get_setting( 'custom_posts_sync_option', array() ) ) ) ); } function setup_admin_menus() { global $pagenow, $sitepress; if ( $pagenow === 'edit-tags.php' || $pagenow === 'term.php' ) { maybe_load_translated_tax_screen (); $wpml_term_translation_help_notice = new WPML_Taxonomy_Translation_Help_Notice( wpml_get_admin_notices(), $sitepress ); $wpml_term_translation_help_notice->add_hooks(); } } function maybe_load_translated_tax_screen() { $taxonomy_get = (string) filter_input( INPUT_GET, 'taxonomy' ); $taxonomy_get = $taxonomy_get ? $taxonomy_get : 'post_tag'; if ( is_taxonomy_translated( $taxonomy_get ) ) { global $wpdb, $sitepress; require WPML_PLUGIN_PATH . '/menu/term-taxonomy-menus/wpml-tax-menu-loader.class.php'; new WPML_Tax_Menu_Loader( $wpdb, $sitepress, $taxonomy_get ); } } function wpml_reload_active_languages_setting( $override = false ) { global $wpdb, $sitepress_settings; if ( true === (bool) $sitepress_settings && ( $override || wpml_get_setting_filter( false, 'setup_complete' ) ) ) { if ( $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}icl_languages'") ) { $active_languages = $wpdb->get_col( " SELECT code FROM {$wpdb->prefix}icl_languages WHERE active = 1" ); } else { $active_languages = array(); } $sitepress_settings['active_languages'] = $active_languages; icl_set_setting( 'active_languages', $active_languages, true ); } else { $active_languages = array(); } return (array) $active_languages; } /** * Returns and if necessary instantiates an instance of the WPML_Installation Class * * @return \WPML_Installation */ function wpml_get_setup_instance() { global $wpml_installation, $wpdb, $sitepress; if ( ! isset( $wpml_installation ) ) { require WPML_PLUGIN_PATH . '/inc/setup/wpml-installation.class.php'; $wpml_installation = new WPML_Installation( $wpdb, $sitepress ); } return $wpml_installation; } function wpml_load_admin_files() { require_once WPML_PLUGIN_PATH . '/menu/wpml-troubleshooting-terms-menu.class.php'; require_once WPML_PLUGIN_PATH . '/inc/wpml-post-edit-ajax.class.php'; require_once WPML_PLUGIN_PATH . '/menu/wpml-post-status-display.class.php'; require_once WPML_PLUGIN_PATH . '/inc/utilities/wpml-color-picker.class.php'; } function wpml_get_post_status_helper() { global $wpml_post_status, $wpdb, $sitepress; if ( ! isset( $wpml_post_status ) ) { $wpml_post_status = new WPML_Post_Status( $wpdb, $sitepress->get_wp_api() ); } return $wpml_post_status; } function wpml_get_create_post_helper() { global $wpml_create_post_helper, $sitepress; if ( ! isset( $wpml_create_post_helper ) ) { require WPML_PLUGIN_PATH . '/inc/post-translation/wpml-create-post-helper.class.php'; $wpml_create_post_helper = new WPML_Create_Post_Helper( $sitepress ); } return $wpml_create_post_helper; } /** * @return \TranslationManagement */ function wpml_load_core_tm() { global $iclTranslationManagement; if ( !isset( $iclTranslationManagement ) ) { require_once WPML_PLUGIN_PATH . '/inc/translation-management/translation-management.class.php'; $iclTranslationManagement = new TranslationManagement(); } return $iclTranslationManagement; } function wpml_get_langs_in_dirs_val( $http_client, $wpml_url_converter, $posted_url = false ) { global $sitepress; require_once WPML_PLUGIN_PATH . '/inc/url-handling/wpml-lang-url-validator.class.php'; $posted_url = $posted_url ? $posted_url : (string) filter_input ( INPUT_POST, 'url' ); return new WPML_Lang_URL_Validator( $http_client, $wpml_url_converter, $posted_url, $sitepress ); } function wpml_get_root_page_actions_obj() { global $wpml_root_page_actions, $sitepress_settings; if ( !isset( $wpml_root_page_actions ) ) { require_once WPML_PLUGIN_PATH . '/inc/post-translation/wpml-root-page-actions.class.php'; $wpml_root_page_actions = new WPML_Root_Page_Actions( $sitepress_settings ); } return $wpml_root_page_actions; } function wpml_get_hierarchy_sync_helper( $type = 'post' ) { global $wpdb; if ( $type === 'post' ) { require_once WPML_PLUGIN_PATH . '/inc/post-translation/wpml-post-hierarchy-sync.class.php'; $hierarchy_helper = new WPML_Post_Hierarchy_Sync( $wpdb ); } elseif ( $type === 'term' ) { require_once WPML_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-term-hierarchy-sync.class.php'; $hierarchy_helper = new WPML_Term_Hierarchy_Sync( $wpdb ); } else { $hierarchy_helper = false; } return $hierarchy_helper; } function wpml_maybe_setup_post_edit() { global $pagenow, $sitepress, $post_edit_screen; if ( in_array( $pagenow, array( 'post.php', 'post-new.php', 'edit.php' ), true ) || defined( 'DOING_AJAX' ) ) { $post_edit_screen = new WPML_Post_Edit_Screen( $sitepress ); add_action( 'admin_head', array( $sitepress, 'post_edit_language_options' ) ); } } /** * @return \WPML_Frontend_Tax_Filters */ function wpml_load_frontend_tax_filters() { global $wpml_term_filters; if ( !isset( $wpml_term_filters ) ) { require WPML_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-frontend-tax-filters.class.php'; $wpml_term_filters = new WPML_Frontend_Tax_Filters(); } return $wpml_term_filters; } /** * @return \WPML_Settings_Helper */ function wpml_load_settings_helper() { global $wpml_settings_helper, $sitepress, $wpml_post_translations; if ( ! isset( $wpml_settings_helper ) ) { $wpml_settings_helper = new WPML_Settings_Helper( $wpml_post_translations, $sitepress ); } return $wpml_settings_helper; } function wpml_get_term_translation_util() { global $sitepress; require_once WPML_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-term-translation-utils.class.php'; return new WPML_Term_Translation_Utils( $sitepress ); } /** * @return \WPML_Term_Filters */ function wpml_load_term_filters() { global $wpml_term_filters_general, $sitepress, $wpdb; if ( ! isset( $wpml_term_filters_general ) ) { require WPML_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-term-filters.class.php'; $wpml_term_filters_general = new WPML_Term_Filters( $wpdb, $sitepress ); $wpml_term_filters_general->init(); } return $wpml_term_filters_general; } function wpml_show_user_options() { global $sitepress, $current_user, $user_id, $pagenow; if ( ! isset( $user_id ) && 'profile.php' === $pagenow ) { $user_id = $current_user->ID; } $user = new WP_User( $user_id ); $user_options_menu = new WPML_User_Options_Menu( $sitepress, $user ); echo $user_options_menu->render(); } if ( is_admin() ) { add_action( 'personal_options', 'wpml_show_user_options' ); }