如何修改wordpress插件.php文件

时间:2016-04-08 04:38:20

标签: php html wordpress frontend

我在我的网站上安装了Front-End Publishing插件,它显示了以下菜单: FEP menu

  • 我想从菜单中删除'标签'和'选择精选图片'选项。
  • 由于我希望用户只为帖子内容上传媒体,我还想阻止用户在内容框中输入字词。

这是插件的submission-form.php我需要编辑哪些代码才能实现此目的? (我试图将所有代码放在代码格式中,但部分代码拒绝放入代码示例框中)

<?php
$post       = false;
$post_id    = -1;
$featured_img_html = '';
if( isset($_GET['fep_id']) && isset($_GET['fep_action']) && $_GET['fep_action'] == 'edit' ){
    $post_id            = $_GET['fep_id'];
    $p                  = get_post($post_id, 'ARRAY_A');
    if($p['post_author'] != $current_user->ID) return 'You don\'t have permission to edit this post';
    $category           = get_the_category($post_id);
    $tags               = wp_get_post_tags( $post_id, array( 'fields' => 'names' ) );
    $featured_img       = get_post_thumbnail_id( $post_id );
    $featured_img_html  = (!empty($featured_img))?wp_get_attachment_image( $featured_img, array(200,200) ):'';
    $post               = array(
                            'title'             => $p['post_title'],
                            'content'           => $p['post_content'],
                            'about_the_author'  => get_post_meta($post_id, 'about_the_author', true)
                        );
    if(isset($category[0]) && is_array($category))
        $post['category']   = $category[0]->cat_ID;
    if(isset($tags) && is_array($tags))
        $post['tags']       = implode(', ', $tags);
}
?>
此表单需要JavaScript才能正常运行。请打开JavaScript,然后重试!
<div id="fep-new-post">
<div id="fep-message" class="warning"></div>
<form id="fep-submission-form">
    <label for="fep-post-title">Title</label><br/>
    <input type="text" name="post_title" id="fep-post-title" value="<?php echo ($post) ? $post['title']:''; ?>"><br/>
    <label for="fep-post-content">Content</label><br/>
    <?php
        $enable_media = (isset($fep_roles['enable_media']) && $fep_roles['enable_media'])?current_user_can($fep_roles['enable_media']):1;
        wp_editor( $post['content'], 'fep-post-content', $settings = array('textarea_name'=>'post_content', 'textarea_rows'=> 7, 'media_buttons'=>$enable_media) );
        wp_nonce_field('fepnonce_action','fepnonce');
    ?>
    <?php if(!$fep_misc['disable_author_bio']): ?>
        <label for="fep-about">Author Bio</label><br/>
        <textarea name="about_the_author" id="fep-about" rows="5"><?php echo ($post) ? $post['about_the_author']:''; ?></textarea><br/>
    <?php else: ?>
        <input type="hidden" name="about_the_author" id="fep-about" value="-1">
    <?php endif; ?>
    <label for="fep-category">Category</label><br/>
    <?php wp_dropdown_categories(array('id'=>'fep-category', 'hide_empty' => 0, 'name' => 'post_category', 'orderby' => 'name', 'selected' => $post['category'], 'hierarchical' => true, 'show_option_none' => __('None'))); ?><br/>
    <label for="fep-tags">Tags</label><br/>
    <input type="text" name="post_tags" id="fep-tags" value="<?php echo ($post) ? $post['tags']:''; ?>"><br/>
    <div id="fep-featured-image">
        <div id="fep-featured-image-container"><?php echo $featured_img_html; ?></div>
        <a id="fep-featured-image-link" href="#">Choose Featured Image</a>
        <input type="hidden" id="fep-featured-image-id" value="<?php echo (!empty($featured_img))?$featured_img:'-1'; ?>"/>
    </div>
    <input type="hidden" name="post_id" id="fep-post-id" value="<?php echo $post_id ?>">
    <button type="button" id="fep-submit-post" class="active-btn">Submit</button><img class="fep-loading-img" src="<?php echo plugins_url( 'static/img/ajax-loading.gif', dirname(__FILE__) ); ?>"/>
</form>

1 个答案:

答案 0 :(得分:1)

问题#1:

为这些元素添加一个类(我已经调用了类removal

<label for="fep-tags" class="removal">Tags</label><br/>
<input type="text" name="post_tags" class="removal" id="fep-tags" value="<?php echo ($post) ? $post['tags']:''; ?>"><br/>
<div class="removal" id="fep-featured-image">
    <div id="fep-featured-image-container"><?php echo $featured_img_html; ?></div>
    <a id="fep-featured-image-link" href="#">Choose Featured Image</a>
    <input type="hidden" id="fep-featured-image-id" value="<?php echo (!empty($featured_img))?$featured_img:'-1'; ?>"/>
</div>

为您的主题添加自定义CSS:

.removal{
  display:none !important;
}

对于问题#2:

你可以做两件事。您可以通过在CSS中完全删除textarea来完全删除用户输入文本的功能:

#fep-about{
  display:none !important;
}

如果出于任何原因您确实需要文本框(不确定原因)。我会添加自定义Javascript来检测用户是否输入了密钥或复制并粘贴了任何文本。考虑textarea元素的ID是fep-about

var ele = document.getElementById('fep-about')

ele.addEventListener('keyup',function(){
  this.value = "";
  alert("Only direct media uploads are allowed!");
});

ele.addEventListener('onchange',function(){
  this.value = "";
  alert("Only direct media uploads are allowed!");
});

这是JSFiddle:https://jsfiddle.net/a3zsdo88/1/

兼容性问题

如果CSS类中存在某些问题而忽略了上述问题,只需将显示语句与元素内联添加:

<div id="fep-featured-image" style="display:none !important;">
    <div id="fep-featured-image-container"><?php echo $featured_img_html; ?>  </div>
    <a id="fep-featured-image-link" href="#">Choose Featured Image</a>
    <input type="hidden" id="fep-featured-image-id" value="<?php echo (!empty($featured_img))?$featured_img:'-1'; ?>"/>
</div>

看看我如何将display语句添加到父元素。为您不希望显示的元素执行此操作。

如果您无法轻松自定义Javascript,请在​​表单文件中直接在HTML中添加<script></script>块。

<script>

   var ele = document.getElementById('fep-about')

   ele.addEventListener('keyup',function(){
     this.value = "";
     alert("Only direct media uploads are allowed!");
   });

   ele.addEventListener('onchange',function(){
     this.value = "";
     alert("Only direct media uploads are allowed!");
   });

</script>