PHP -覆盖一个输出,多个配置


PHP - override an output, multiple config

我有一个echo:

echo 'Hello world';

有两个地方我可以管理这个echo是否可见,我可以使用

检查它们:
global_option('show_echo');

post_option('show_echo');

请告诉如何从post_option覆盖global_option,如:

global_option('show_echo')中回声设置为隐藏,在post_option('show_echo');中可见,然后输出回声。

如何使else if优先于post_option,意味着post_option可以覆盖global_option

建议我一个最简单的方法来实现这个

听起来你需要一个实现优先级排序的函数:

function check_config( $key) {
    // Your question is unclear as to the exact logic necessary here
    $post = post_option( $key);
    if( isset( $post)) return $post;
    $global = global_option( $key);
    if( isset( $global)) return $global;
    return false;
}

然后用:

if( check_config( 'show_echo')) {
}