wordpress常用函数-get_currentuserinfo()

说明

检索当前登录用户的相关信息,并将信息置入$userdata全局变量。函数属性直接映射到数据库(参见 Database Description)中的wp_usrs表格。

同样也将个体属性放置到以下独立全局变量中:

  • $user_login
  • $user_level
  • $user_ID
  • $user_email
  • $user_url(用户在用户资料中输入的网址)
  • $user_pass_md5 (用户密码的md5 hash——一种几乎无法解密(不是完全无法解密)的编码,可比较输入提示口令与实际用户密码的不同)
  • $display_name(用户名,根据'How to display name'用户选项结果进行显示)

用法

<?php get_currentuserinfo(); ?>

示例

缺省用法

调用get_currentuserinfo()将当前用户信息放入$userdata,可用成员变量在$userdata中检索用户信息。

<?php global $current_user;
      get_currentuserinfo();          

      echo('Username: ' . $current_user->user_login . "\n");
      echo('User email: ' . $current_user->user_email . "\n");
      echo('User level: ' . $current_user->user_level . "\n");
      echo('User first name: ' . $current_user->user_firstname . "\n");
      echo('User last name: ' . $current_user->user_lastname . "\n");
      echo('User display name: ' . $current_user->display_name . "\n");
      echo('User ID: ' . $current_user->ID . "\n");
?>

Username: Zedd
User email: my@email.com
User level: 10
User first name: John
User last name: Doe
User display name: John Doe

User ID: 1

使用独立全局变量

用户资料大多存放在单个全局变量中,可直接访问。

<?php global $display_name , $user_email;
      get_currentuserinfo();          

      echo($display_name . "'s email address is: " . $user_email);
?>

Zedd's email address is: fake@email.com

注意:$display_name似乎无法在2.5以上版本中运行。$user_login运行良好。

<?php global $user_login , $user_email;
      get_currentuserinfo();          

      echo($user_login . "'s email address is: " . $user_email);
?>

参数

该函数不接受任何参数。

检查当前是否有已登录用户,执行以下代码:

<?php global $user_ID;
      get_currentuserinfo();          

      if ('' == $user_ID) {
         //no user logged in
      }
?>

下面仍然是一个IF STATEMENT示例,用在侧边条中,参照ttp://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts 中的"My Fav"插件。

<?php if ( $user_ID ) { ?>
<!-- enter info that logged in users will see -->
<!-- in this case im running a bit of php to a plugin -->    

<?php mfp_display(); ?>    

<?php } else {   ?>
<!-- here is a paragraph that is shown to anyone not logged in -->   

<p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, you can save your favorite
posts for future reference.</p>    

<?php } ?>

转载于:https://my.oschina.net/shunshun/blog/82485

<template> <div class="cmp-office-list-box" v-if="dataList.length > 0"> <el-scrollbar :style="isCollapse ? 'border: 1px solid rgb(221 221 221 / 61%);height: 750px' : 'height: 750px'"> <!-- 文件列表 --> <div :class="isCollapse ? 'cmp-office-list' : 'cmp-office-list-is-collapse'"> <div class="list"> <div class="list-des-wrap"> <!-- :hid-upload="true" 传true,就是将录入的时候只显示协作文档上传,传了true, 如果不传没有上传入口,那么删除按钮也不需要展示了 --> <div v-for="(item, index) in dataList" :key="item" @click="activateChange(index)"> <iteration-card :isCollaborateForm="isCollaborateForm" :iteration="item" :class="{ active: activeIndex === index }" :hid-upload="hidUpload" :collaborateFileId="collaborateFileId" :dataList="dataList" @save="handleSave" @created="handleCreated" @version="openVersion" @compare="openCompare" @openRecord="openRecord" @lock="handleLock" @unlock="handleUnLock" @delete="handleDelete" @download="handleDownload" > </iteration-card> </div> </div> </div> </div> </el-scrollbar> <div :class="collapseText" @click="isCollapse = !isCollapse" :data-title="isCollapse?'收起':'展开'"></div> <!-- class="custom-tooltip" data-title="提示" --> </div> </template> <script> import bus from '../../../../common/bus'; export default { props: { width: { type: String, default: "290px", }, title: { type: String, default: "合同文档", }, dataList: { type: Array, default: () => [], }, hidUpload: { type: Boolean, default: false, }, isCollaborateForm: { type: Object, default: {}, }, }, data() { return { activeIndex: 0, collaborateFileId: null, isCollapse: true, isInitialized: false, // 监听是否确认最终版 }; }, created() { bus.$on('setMainFile', (data) => { const index = this.dataList.findIndex(item => item.collaborateFileId === data.collaborateFileId); // 神奇逻辑,如果dataList改变会把你设置的activeIndex - 1所以这里加一传入就是正确的索引 this.activateChange(index); }); }, methods: { activateChange(index) { // 每次预览的是新的文件,需要重新加载 if (this.activeIndex !== index && index !== -1) { this.activeIndex = index; this.collaborateFileId = this.dataList[this.activeIndex].collaborateFileId; this.$emit("handleFileIdCallback", this.collaborateFileId); } }, openVersion(iteration){ this.$emit('version', iteration) }, openCompare(iteration){ this.$emit('compare', iteration) }, openRecord(iteration){ this.$emit('openRecord', iteration) }, handleSave(iteration){ this.$emit('save', iteration) }, handleCreated(iteration){ this.$emit('created', iteration) }, async handleLock(iteration) { try { if(iteration.collaborateFileId) { await this.$axios.post(`/composition/collaborate/files/lock/${iteration.collaborateFileId}`, { hideLoading: false }); // 加载协同文件列表 bus.$emit('initCollaborateList') } } catch (error) { console.log(error) } }, async handleUnLock(iteration) { try { if(iteration.collaborateFileId) { await this.$axios.post(`/composition/collaborate/files/unlock/${iteration.collaborateFileId}`, { hideLoading: false }); // 加载协同文件列表 bus.$emit('initCollaborateList') } } catch (error) { console.log(error) } }, handleDelete(iteration) { const { contractId, contractNo } = this.$route.query; // 判断是否是录入页面(区别于草稿页面 草稿页面!==录入页面 const idDraft = contractId || contractNo const { baseInfo , baseInfoData } = this.$store.getters.getInitModel || {} const { agreementType = 0} = baseInfo || baseInfoData || {} const agreementFlag = [1, 2].includes(agreementType); if(idDraft) { const isMainFile = iteration.isMainAttachment === 'Y' const confirmDelete = isMainFile && (contractId || contractNo) && !agreementFlag ? this.$t("message.document.scan.confirmDeleteMain") : this.$t("message.document.scan.confirmDelete") this.$confirm(confirmDelete, this.$t('message.document.borrow.notice'), { confirmButtonText: this.$t('message.document.borrow.confirm'), cancelButtonText: this.$t('message.document.borrow.cancel'), lockScroll:false, type: 'warning' }).then(async () => { // this.$axios.put(`/composition/collaborate/files/delete/${iteration.collaborateFileId}`,{},{ // hideLoading: true // }).then(res=>{ // if( res.data.status === 0 ){ // this.$emit('collaborateDel', iteration) // if(contractId && isMainFile){ // this.$axios.post(`/ai/risk/collaborate/delete/${contractId}`,{ // hideLoading: true // }).then(res=>{ // }) // } // } // }) const delete1 = this.$axios.put(`/composition/collaborate/files/delete/${iteration.collaborateFileId}`,{},{ hideLoading: true }) let delete2 = null; if(contractId && contractNo) { const attachmentList = this.dataList.filter(item=>item.attachmentId !== iteration.attachmentId) const data = { contractId: this.$route.query.contractId, contractNo: this.$route.query.contractNo, attachmentList, } delete2 = this.$axios.post(`/composition/collaborate/batchUpdateAtt`, data) } const deleteReqArr = delete2 ? [delete1, delete2] : [delete1] await Promise.all(deleteReqArr).then(res=>{ const resFlag = res.every(item=> item.data.status === 0) if( resFlag ){ this.$emit('collaborateDel', iteration) if(contractId && isMainFile && !agreementFlag){ this.$axios.post(`/ai/risk/collaborate/delete/${contractId}`,{ hideLoading: true }).then(res=>{ }) } } }) // this.$message.success(this.$t('message.composition.field.delete1')) }).catch(() => { }); } else { this.$emit('collaborateDel', iteration) } }, handleDownload(iteration, type) { if(iteration.collaborateFileId) { const fileType = type ? `&fileType=${type}`: "" this.$axios .post(`/composition/collaborate/files/download/?fileId=${iteration.collaborateFileId}${fileType}`).then((res)=>{ window.open(res.data.data.url); }) } }, }, watch: { dataList: { deep: true, handler(newVal, oldVal) { this.collaborateFileId = null; if (!newVal || newVal.length === 0) { this.activeIndex = -1; this.isInitialized = false; } else { /** * * 修正 activeIndex:向前移一位,但确保在合法范围内 * newVal,activeIndex 表示当前“激活”的文件在列表中的位置。每当文件列表有变化(比如删除了一个文件), * 让激活的文件向前移动一位,但又不能越界(不能小于0,也不能超过最后一个文件)。 * * */ this.activeIndex = Math.max(0, Math.min(this.activeIndex - 1, newVal.length - 1)); const activeItem = newVal[this.activeIndex]; this.collaborateFileId = activeItem.collaborateFileId; this.isInitialized = activeItem.isFinalized; } if(oldVal.length === 0){ const index = newVal.findIndex(item => item.isMainAttachment === 'Y'); this.activateChange(index); } // 触发事件 this.$emit("handleFileIdCallback", this.collaborateFileId); this.$emit("isFinalizedChange", this.isInitialized); bus.$emit('contractFileUploadChange', newVal); }, }, }, computed: { isCreaterOrOwner() { const { ownerId = '', creatorId = '' } = this.$store.getters.getInitModel.baseInfo || {} const { user = {} } = this.$store.state.currentUserInfo return user.id === ownerId || user.id === creatorId }, collapseText() { return this.isCollapse ? 'el-icon-arrow-left headline-wrapper-show custom-tooltip' : 'el-icon-arrow-right headline-wrapper-show custom-tooltip'; }, cmpOfficeListTips_1() { const tipsContent = this.$store.getters.getTooltipConfig( "cmpOfficeListTips_1" ); if (tipsContent.content) { return tipsContent.content; } else { return "空配置,请全局消息配置cmpOfficeListTips_1"; } }, } }; </script> <style> /* 隐藏横向滚动条 */ .cmp-office-list-box .el-scrollbar__bar.is-horizontal { display: none !important; } .cmp-office-list-box .el-scrollbar__wrap { scrollbar-width: none; /* 去掉Firefox默认滚动条 */ } .cmp-office-list-box .el-scrollbar__bar.is-vertical { opacity: 1; } </style> <style scoped> /* 基础样式 */ .cmp-office-list-box { height: 750px; display: flex; } .cmp-office-list { width: 240px; height: 100%; background: color(display-p3 1 1 1); border-radius: 4px; transition: width 0.3s ease; } .cmp-office-list-is-collapse { width: 0px; overflow: hidden; transition: width 0.3s ease; } .list { height: 100%; } .headline-wrapper-show { cursor: pointer; font-size: 12px; font-weight: 500; opacity: 1; height: 40px; line-height: 40px; background: #e5e5e5; color: #ffffff; border: 1px solid transparent; transition: width 0.3s ease; border-right: 1px solid #82828224; margin-top: 377px; transform: translateX(-10px); /* el-scrollbar 会遮住,导致按钮小角落点不了 */ z-index: 999; } .headline-wrapper-show:hover { border: 1px solid #3a8ee6; } .el-icon-arrow-left { left: 0; border-top-left-radius: 4px; border-bottom-left-radius: 4px; } .el-icon-arrow-right { left: 286px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; } .title { font-size: 16px; font-weight: bold; color: #333; padding: 5px 0; letter-spacing: -1px; } .icon { display: flex; justify-content: center; align-items: center; border-radius: 4px; margin-right: 8px; flex-shrink: 0; } .list-des-wrap { width: 100%; height: 100%; border: 1px solid #b2b1b129; transition: width 0.3s ease; } .list-des { height: 68px; display: flex; align-items: center; border-bottom: 1px solid #b2b1b129; padding: 5px 10px; cursor: pointer; box-sizing: content-box; } .list-des.active { display: flex; border-radius: 4px; background: linear-gradient(90deg, color(display-p3 0.2235 0.5059 0.9412) 0%, color(display-p3 0.298 0.6627 0.9725) 100%); } .list-des.active * { color: #fff; } /* 文档名称 start */ .doc-name-item-box { display: flex; } .cmp-office-icon-right-text { width: 100%; } .custom-tooltip:hover::after { /* css接收dom传参 */ content: attr(data-title); background-color: #333; color: #fff; padding: 5px 10px; border-radius: 5px; white-space: nowrap; position: absolute; transform: translateX(5px); } /* end*/ </style> 如果当前激活项是 const index = newVal.findIndex(item => item.isMainAttachment === 'Y'); 则激活这个条件对应的this.activeIndex, 如果handleDelete方法触发删除, 还是保持Y所在的this.activeIndex 如果用户切换了文件, 比如切换了第三个文件,将第二个文件进行删除, 则需要this.activeIndex -1 操作 根据我描述对handleDelete进行修改
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值