• Resolved steveshaddick

    (@steveshaddick)


    Thank you for the really nice, simple and straightforward plugin! If anyone is interested in allowing Polylang support, we made some small adjustments to the show404 function. I’ll post the whole function here, the changes are a couple lines after the WPML checks:

    function show404( $posts ) {
        global $wp_query;
        // remove the filter so we handle only the first query - no custom queries
        remove_filter( 'posts_results', array( $this, 'show404' ), 999 );
        $pageid = $this->settings['404page_page_id'];
        if ( 0 != $pageid ) {
          if ( empty( $posts ) && is_main_query() && !is_robots() && !is_home() && !is_feed() && !is_search() &&( !defined('DOING_AJAX') || !DOING_AJAX ) ) {
            // show the 404 page
            if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
              // WPML is active
              $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', true );
            } else if (function_exists('pll_get_post')) {
              // Polylang is active
              $translatedpage_id = pll_get_post($pageid);
              if (!empty($translatedpage_id) && 'publish' == get_post_status($translatedpage_id)) {
                $pageid = $translatedpage_id;
              }
            }
            $posts[] = get_post( $pageid );
            add_action( 'wp', array( $this, 'do_404_header' ) );
            add_filter( 'body_class', array( $this, 'add_404_body_class' ) );
          } elseif ( 1 == count( $posts ) && 'page' == $posts[0]->post_type ) {
            // Do a 404 if the 404 page is opened directly
            $curpageid = $posts[0]->ID;
            if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
              // WPML is active - get the post ID of the default language
              global $sitepress;
              $curpageid = apply_filters( 'wpml_object_id', $curpageid, 'page', $sitepress->get_default_language() );
              $pageid = apply_filters( 'wpml_object_id', $pageid, 'page', $sitepress->get_default_language() );
            } else if (function_exists('pll_get_post')) {
              // Polylang is active - get the post ID of the default language
              $curpageid = pll_get_post($curpageid, pll_default_language());
              $pageid = pll_get_post($pageid, pll_default_language());
            }
            if ( $pageid == $curpageid ) {
              add_action( 'wp', array( $this, 'do_404_header' ) );
              add_filter( 'body_class', array( $this, 'add_404_body_class' ) );
            }
          }
        }
        return $posts;
      }

    https://www.ads-software.com/plugins/404page/

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Polylang support’ is closed to new replies.