Home  >  Q&A  >  body text

python 有没有类似WordPress的这种库?

例如:WordPress博客这种插件Eyes Only: User Access Shortcode

https://www.wpdaxue.com/eyes-...

/**
 * WordPress 根据用户名/用户角色/能力/是否登录等隐藏部分文章内容
 * https://www.wpdaxue.com/eyes-only-user-access-shortcode.html
 */
add_shortcode('eyesonly', 'sc_eyesonly');
function sc_eyesonly($atts, $content = null) {
    extract(shortcode_atts(array('username' => null, 'level' => null, 'logged' => null,'hide' => null,),$atts));
    if (!$hide || $hide === 'no' || $hide === 'false'){$pre = null;    $thecontent = do_shortcode($content);}
    if ($hide && $hide !== 'no' && $hide !== 'false'){$pre = do_shortcode($content); $thecontent = null;}
    $showcontent = $pre;
    $current_user = wp_get_current_user();
    $users = preg_split("/[\s,]+/",$username);
    $levels = preg_split("/[\s,]+/",$level);
    foreach($users as $name){if($username && $current_user->user_login === $name){$showcontent = $thecontent;}}
    foreach($levels as $value){if($level && current_user_can($value)){$showcontent = $thecontent;}}
    if($logged && is_user_logged_in() && $logged === 'in'){$showcontent = $thecontent;}
    if($logged && !is_user_logged_in() && $logged === 'out'){$showcontent = $thecontent;}
    return $showcontent;
}

python 中怎样实现

黄舟黄舟2764 days ago439

reply all(0)I'll reply

No reply
  • Cancelreply