Rui Zhe
Rui Zhe

Reputation: 38

How to edit wordpress plugin .php file

I installed the Front-End Publishing plugin on my website, and it displays this menu: FEP menu

This is the plugin's submission-form.php What code do I have to edit to achive this? (I tried to put all the code in code format but part of the code refused to be put in the code sample box)

<?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);
}
?>
This form needs JavaScript to function properly. Please turn on JavaScript and try again!
<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>

Upvotes: 1

Views: 165

Answers (1)

A.Sharma
A.Sharma

Reputation: 2799

For Question # 1:

Add a class to these elements (I have called the class 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>

Add custom CSS to your theme:

.removal{
  display:none !important;
}

For Question # 2:

You can do two things. You can completely remove the user's ability to type text in by removing the textarea altogether in CSS:

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

If for any reason you actually need the text box (not sure why). I would add custom Javascript to detect if the user has entered a key or copy and pasted any text. Considering the ID of the textarea element is 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!");
});

Here is the JSFiddle for this: https://jsfiddle.net/a3zsdo88/1/

Compatibility Issues

If there are some sort of issues in CSS classes overriding the above ones, just add the display statements inline with the elements:

<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>

See how I added the display statement to the parent element. Do that for the elements you do not want shown.

If you don't have a way to customize your Javascript easily, then add a <script></script> block directly in your HTML in your form file.

<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>

Upvotes: 1

Related Questions