关于 if 和 else if 语句的 functions.php 中的 Wordpress PHP 问题 [英] Wordpress PHP issue in functions.php regarding if and else if statement

查看:41
本文介绍了关于 if 和 else if 语句的 functions.php 中的 Wordpress PHP 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主页是一个静态的自定义登录页面,用于网络多站点,带有运行 Divi 子主题的 Theme-my-login 插件.在登录页面上,登录本身可以正常工作,下面是注册"和丢失密码"的两个操作链接".我有两个自定义页面可以链接到这两个链接.

My Home page is a static custom Login Page for a network multisite with the Theme-my-login plugin running om a Divi child theme. On the login page there is the login itself which works fine, and below that two "action links" for "Register" and "Lost Password". I have two custom pages to link to for both links.

所以我编辑了子主题的functions.php 文件.假设您想将默认注册操作链接更改为不同的 URL:

So I edit the child theme's functions.php file. Let’s say you wanted to change the default Register action link to a different URL:

function tml_action_url( $url, $action, $instance ) {
    if ( 'register' == $action )
        $url = 'YOUR REGISTRATION URL HERE';
    return $url;
}
add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );

效果很好.但是,如果我也想包含丢失的密码链接:

That works perfectly. If I want to include the lost password link too however:

function tml_action_url( $url, $action, $instance ) {
    if ( 'register' == $action )
        $url = 'YOUR REGISTRATION URL HERE';
    else if ( 'lost password' == $action )
        $url = 'YOUR LOST PASSWORD URL HERE';
    return $url;
}
add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );

由于某种原因它坏了.非常感谢任何帮助.我有一种感觉,我没有使用正确的语法或其他东西.TIA.吉姆

it breaks for some reason. Any help much appreciated. I have a feeling I'm not using the correct syntax or something. TIA. Jim

推荐答案

来自文档

注意 elseif 和 else if 只会在使用大括号时被认为完全相同.使用冒号定义 if/elseif 条件时,不得将 else if 分隔成两个词,否则 PHP 将因解析错误而失败.

Note that elseif and else if will only be considered exactly the same when using curly brackets. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

或者使用 elseif 而不是 else if 或者像这样使用大括号:

Either use elseif instead of else if or use curly brackets like so:

function tml_action_url( $url, $action, $instance ) 
{
    if ( 'register' == $action )
    {
        $url = 'YOUR REGISTRATION URL HERE';
    }
    else if ( 'lost password' == $action )
    {
        $url = 'YOUR LOST PASSWORD URL HERE';'
    }
    return $url;
}

这篇关于关于 if 和 else if 语句的 functions.php 中的 Wordpress PHP 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆