V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
vfans
V2EX  ›  WordPress

关于 WordPress 插件问题,如果不填某个值,其他填了的信息也不会显示

  •  
  •   vfans · 2019-01-16 00:45:17 +08:00 · 694 次点击
    这是一个创建于 1920 天前的主题,其中的信息可能已经有所发展或是发生改变。

    各位大佬请指教,下面这个小插件会给 wordpress 增加一个独立下载页面,但是在发文章时如果不填$url 这个值的话,其他比如$title,$size 之类信息即使我填了也不会在前台页面显示。

    请问怎么才能取消这个条件判断?就是即使我只填写了 title 一项也会在前面显示出来。 谢了啊

    我觉得这个判断可能是在 front.class.php 这个文件里,虽然代码一共也没几条,不过我基本也看不懂代码。。。删删减减弄了很久也无效啊,不是导致页面无法访问就是无效。

    插件地址: https://cn.wordpress.org/plugins/download-info-page/

    front.class.php

    <?php
    
    
    class DLIP_DownLoadFront{	
    	
    	public function __construct(){	
    		
    		$this->init();
    	}
    	public function init(){
    		add_filter('the_content',array($this,'the_content'));
    		add_action('wp_footer', array($this,'downStyle'));
    		
    		add_action('dlip_down_page',array($this,'down'));
    	}
    	function tourl(){
    		global $postId;
    		if($postId){
    			$url = get_permalink($postId);
    		}else{
    			$url = get_option('siteurl');
    		}
    		wp_redirect($url);
    	}
    	public function down($data){
    		global $current_user, $display_name , $user_email;
    		$op_sets = get_option( DLIP_DownLoadCommon::$optionName );
    		if(isset($op_sets['need_member']) && $op_sets['need_member']){
    			$user_id = $current_user->ID;
    			if(!$user_id)$this->tourl();		
    		}
    	}
    	public function the_content($content){
    	  if(is_single()) {     
    		$content .= $this->downHtml();
    	  }
    	  return $content;
    	}
    	
    	private function downHtml(){
    		
    		global $current_user;
    		
    		//配置
    		$op_sets = get_option( DLIP_DownLoadCommon::$optionName );
    		$tpl = $this->defaultTpl();
    		if(isset($op_sets['downtpl']) && $op_sets['downtpl']){
    			$tpl = $op_sets['downtpl'];
    		}
    		if(isset($op_sets['need_member']) && $op_sets['need_member']){
    			if(!$current_user || !$current_user->ID){
    				$tpl = isset($op_sets['usrdowntpl']) && $op_sets['usrdowntpl'] ?$op_sets['usrdowntpl'] : $this->defaultUsrTpl();
    			}
    		}
    		$tpl = apply_filters('dlip_down_tpl',$tpl);
    		$datas = $this->metadata(true);
    		
    		
    		return $this->parseTpl($tpl,$datas);
    		
    	}
    	
    	public function metadata($isDown = false){
    		$postId = get_the_ID();		
    		//字段
    		$fields = DLIP_DownLoadCommon::fields();
    		$prefix = DLIP_DownLoadCommon::$mataPrefix;
    		//字段值
    		$datas = array();		
    		if(is_array($fields))foreach($fields as $k=>$v){
    			$field = $prefix.$k;
    			$datas[$k] = get_post_meta( $postId,$field , true );
    		}
    		if(isset($datas['url']))$datas['org_url'] = $datas['url'];
    		if($isDown && $datas['url']){
    			//配置
    			$op_sets = get_option( DLIP_DownLoadCommon::$optionName );
    			if($op_sets['domain']){
    				$datas['url'] = $op_sets['domain'].'/down.php?id='.$postId;
    			}else if($siteurl = get_option('siteurl')){
    				$datas['url'] = $siteurl.'/down.php?id='.$postId;
    			}
    		}
    		return $datas;
    	}
    	
    	
    
    	private function parseTpl($tpl,$datas){
    		if(!$tpl)return '';
    		if(!$datas['url'])return '';
    		if(is_array($datas))foreach($datas as $k=>$v){
    			if(!$v){
    				$tpl = preg_replace('#{if '.$k.'}.+?{/if}#s','',$tpl);
    				continue;
    			}
    			//preg_match('#{if '.$k.'}(.+?){/if}#s',$tpl,$m);		
    			$tpl = preg_replace('#{if '.$k.'}(.+?){/if}#s','$1',$tpl);
    			$tpl = str_replace('{'.$k.'}',$v,$tpl);
    		}
    		return $tpl;
    	}
    	private function defaultUsrTpl(){
    		$reg = get_option('siteurl').'/wp-login.php?action=register';
    		$login = get_option('siteurl').'/wp-login.php';
    		$tpl = '<style>.wbolt-btn, a.wbolt-btn{min-width:58px;}a.wbolt-btn.wbolt-btn-outline{ border:1px solid #cecece;background-color:#fff;color:#3a4258 !important}</style>
    <div class="wbolt-box">
        <h3 class="wb-title">下载信息</h3>
        <div class="txtc">
            <p>-------[<span class="hl">下载</span>需要登录]-------</p>
            <a class="wbolt-btn wbolt-btn-outline" href="'.$login.'">登录</a>
            <a class="wbolt-btn" href="'.$reg.'">免费注册</a>
        </div>
    </div>';
    		
    		return $tpl;
    	}
    	private function defaultTpl(){
    
    		$tpl = '<div class="download-info">
    		<h3>下载信息</h3>
    		<ul>
    		{if title}<li>名称:<b>{title}</b></li>{/if}
    		{if format}<li>格式:<b>{format}</b></li>{/if}
    		{if version}<li>版本:<b>{version}</b></li>{/if}
    		{if size}<li>大小:<b>{size}</b></li>{/if}
    		</ul>
    		{if url}<p><a class="btn-download" href="{url}" target="_blank" rel="nofollow"><i class="icon-download"></i> <span>点击下载</span></a></p>{/if}
    		</div>';
    		
    		return $tpl;
    	}
    	
    	//内容下载样式
    	function downStyle(){	
    	?>
    	<style>	
    	a.btn-download{
    		display:inline-block;
    		*display:inline;
    		*zoom:1;
    		min-width:100px;
    		line-height:16px;
    		background-color:#79b1ef !important; /*按钮默认底色*/
    		padding:8px 10px;
    		text-align:center;
    		color:#fff !important; /*按钮默认字体颜色*/
    		font-size:12px;
    		border-radius:4px;
    		margin:15px 0 0 16px;
    		text-decoration:none;
    	}
    	a.btn-download:hover{
    		background-color:#6598d0 !important; /*按钮鼠标经过底色*/
    	}
    	
    	a.btn-download span{
    		display:block;
    	}
    	
    	a.btn-download .icon-download{
    		display:inline-block;
    		*display:inline;
    		*zoom:1;
    		width:28px;
    		height:28px;
    		background:url(<?php echo plugins_url("images/icon-download-sm.png", DLIPP_BASE_FILE)?>) no-repeat; /*旧版浏览器图标*/
    	}
    	:root a.btn-download .icon-download{
    		background:url(<?php echo plugins_url("images/icon-download.png", DLIPP_BASE_FILE)?>) no-repeat; /*现代浏览器图标*/
    		background-size:28px 28px;
    	}
    	</style>
    	<?php
    	}
    
    }
    
    vfans
        1
    vfans  
    OP
       2019-01-17 14:32:06 +08:00
    已解决
    ...
    if(!$datas['url'])return '';
    ...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2468 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:50 · PVG 23:50 · LAX 08:50 · JFK 11:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.