'Veelgestelde vragen', 'en' => AIPROFILE_INSIDE_DEFAULT_TITLE, 'de' => 'Häufige Fragen', 'fr' => 'Questions fréquentes', 'es' => 'Preguntas frecuentes', 'it' => 'Domande frequenti', ); } /** * The page title in a language: from the list above, else the plugin's * translation in the site's language, else English. * * @param string $lang Two or three letters; '' for the site's language. * @return string */ function aiprofile_inside_page_title( $lang = '' ) { $lang = '' !== (string) $lang ? strtolower( (string) $lang ) : aiprofile_inside_lang( '', '' ); $titles = aiprofile_inside_page_titles(); if ( isset( $titles[ $lang ] ) ) { return $titles[ $lang ]; } $switched = switch_to_locale( get_locale() ); $title = __( 'Frequently asked questions', 'aiprofile-inside' ); if ( $switched ) { restore_previous_locale(); } return $title; } /** * The language the answers on the page are in: the language AiProfile served * the connected profile in, else the site's language. * * @param string $key Profile key. * @param bool $fetch Ask AiProfile when no copy is kept (at "Connect"); false reads only the kept copy. * @return string */ function aiprofile_inside_answers_lang( $key, $fetch = false ) { $site_lang = aiprofile_inside_lang( '', '' ); $key = aiprofile_inside_normalize_key( $key ); if ( '' === $key ) { return $site_lang; } $copy = get_transient( aiprofile_inside_cache_key( $key, $site_lang ) . '_good' ); if ( ( ! is_array( $copy ) || empty( $copy['html'] ) ) && $fetch ) { $copy = aiprofile_inside_get( $key, $site_lang ); } $lang = is_array( $copy ) && ! empty( $copy['html'] ) ? aiprofile_inside_html_lang( $copy['html'] ) : ''; return '' !== $lang ? $lang : $site_lang; } /** * Clear the sitemap caches we know, so the answers page is in the sitemap * search engines get: * * - Yoast SEO: WPSEO_Sitemaps_Cache::invalidate( 'page' ) (the page sitemap * and the index). * - Rank Math: \RankMath\Sitemap\Cache::invalidate_storage() (its cached * sitemap files). * - All in One SEO and WordPress's own wp-sitemap.xml build the sitemap on * every request: nothing to clear. * - Page caches: the sitemap addresses of WordPress, Yoast, Rank Math and All * in One SEO, through aiprofile_inside_purge_url() (includes/page-cache.php). */ function aiprofile_inside_refresh_sitemaps() { if ( class_exists( 'WPSEO_Sitemaps_Cache' ) && method_exists( 'WPSEO_Sitemaps_Cache', 'invalidate' ) ) { WPSEO_Sitemaps_Cache::invalidate( 'page' ); } if ( class_exists( '\RankMath\Sitemap\Cache' ) && method_exists( '\RankMath\Sitemap\Cache', 'invalidate_storage' ) ) { \RankMath\Sitemap\Cache::invalidate_storage(); } if ( ! function_exists( 'aiprofile_inside_purge_url' ) ) { return; } foreach ( array( 'wp-sitemap.xml', 'wp-sitemap-posts-page-1.xml', 'sitemap_index.xml', 'sitemap.xml', 'page-sitemap.xml' ) as $path ) { aiprofile_inside_purge_url( home_url( '/' . $path ) ); } } /** * The one-time steps after an update, on the first request after it. Since * 1.3.6: purge the answers page from the page caches. From 1.3.5 (for a site * coming from an older version): the page title in the language of the * answers, and the sitemap caches; only for a site with a connected profile * and a page this plugin made * itself (not one the owner made and the plugin adopted). Reads only kept * copies, never asks AiProfile, so a visitor's request does not wait. */ function aiprofile_inside_upgrade() { $done = (string) get_option( AIPROFILE_INSIDE_UPGRADED_OPTION, '0' ); if ( version_compare( $done, '1.3.6', '>=' ) ) { return; } // First, so a slow or failing step below is not repeated on every request. update_option( AIPROFILE_INSIDE_UPGRADED_OPTION, AIPROFILE_INSIDE_VERSION ); // 1.3.6: purge the answers page from the page caches once, so a copy made // before the update (on a theme that left out the answers) does not hide // the page from the layout check (includes/layout.php) until it expires. $settings = aiprofile_inside_settings(); if ( ! empty( $settings['page_id'] ) && function_exists( 'aiprofile_inside_purge_page' ) ) { aiprofile_inside_purge_page( (int) $settings['page_id'] ); } if ( version_compare( $done, '1.3.5', '>=' ) ) { return; } // 1.3.5: the page title in the language of the answers, and the sitemaps. $page_id = isset( $settings['page_id'] ) ? (int) $settings['page_id'] : 0; if ( empty( $settings['key'] ) || ! $page_id || ! empty( $settings['adopted'] ) || 'publish' !== get_post_status( $page_id ) ) { return; } $title = aiprofile_inside_page_title( aiprofile_inside_answers_lang( $settings['key'] ) ); if ( AIPROFILE_INSIDE_DEFAULT_TITLE === get_post_field( 'post_title', $page_id, 'raw' ) && AIPROFILE_INSIDE_DEFAULT_TITLE !== $title ) { // Only the title changes; the content goes back as it is stored, so // kses on a visitor's request cannot strip anything of the owner's. $had_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ); kses_remove_filters(); wp_update_post( wp_slash( array( 'ID' => $page_id, 'post_title' => $title, ) ) ); if ( $had_kses ) { kses_init_filters(); } } aiprofile_inside_refresh_sitemaps(); } add_action( 'init', 'aiprofile_inside_upgrade', 20 );