首页 > 解决方案 > Wordpress(PHP):页面未找到标题但内容存在

问题描述

我有一个注册新端点的类,重写规则然后刷新它。它工作得很好,除了它也给出了 404 错误,使页面标题“找不到页面”并添加了一些我不想要的 css。我需要让它真正知道我的页面存在。

这是我写的课程:

<?php

use Jigoshop\Helper\Render as RenderCore;
use Jigoshop\Frontend\Page\PageInterface;
use Jigoshop\Integration\Helper\Render;


if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

class twizo_Jigoshop_TFASettings implements PageInterface
{
    function __construct()
    {
        Render::addLocation('twizo-verification', __DIR__);
        add_action('init', function () {
        add_rewrite_endpoint("twizo-verification", EP_ROOT | EP_PAGES | 
EP_PERMALINK);
        add_filter('generate_rewrite_rules', function ($rewrite) {
            $mySettings = [
                '^account/twizo-verification/?$' => 'index.php? 
pagename=twizo-verification'
            ];
            $rewrite->rules = $mySettings + $rewrite->rules;
            return $rewrite->rules;
        });
        flush_rewrite_rules();
    });
    add_filter('jigoshop.frontend.page_resolver.page', function ($args) {
        global $wp_query;
        if ($wp_query->query['pagename'] == 'twizo-verification') {
            return $this;
        }
        return $args;
    });
}

public function action()
{
    $this->renderTFASettings();
}

public function render()
{
}

public function renderTFASettings()
{
    add_action('jigoshop\template\shop\content\before', function () {        
        echo '<h1>My account &raquo; 2FA Settings</h1>';
    });
    add_action('jigoshop\template\shop\content\after', function() {
        echo '<br><a href="./" class="btn btn-default">Go back to My 
account</a>';
    });   

    switch(get_template()) {
        case "twentyfifteen":
            RenderCore::output('layout/twentyfifteen', [
                'content' => Render::get('twizo-verification', 'tfa- 
   settings-body', array())
            ]);
        break;
        case "twentysixteen":
            RenderCore::output('layout/twentysixteen', [
                'content' => Render::get('twizo-verification', 'tfa- 
   settings-body', array())
            ]);
        break;
        case "twentyseventeen":
            RenderCore::output('layout/twentyseventeen', [
                'content' => Render::get('twizo-verification', 'tfa- 
   settings-body', array())
            ]);
        break;
        default: 
            RenderCore::output('layout/default', [
                'content' => Render::get('twizo-verification', 'tfa- 
   settings-body', array())
            ]);
        break;
    }

    exit;
}
}

标签: phpwordpresshttp-status-code-404

解决方案


推荐阅读