Skip to content

Instantly share code, notes, and snippets.

@BHWD
Created June 2, 2016 09:32
Show Gist options
  • Save BHWD/b3f43f58b7c9ee2096369f2c88713847 to your computer and use it in GitHub Desktop.
Save BHWD/b3f43f58b7c9ee2096369f2c88713847 to your computer and use it in GitHub Desktop.
//Prints Note field in front end and retieves exisintg note as placeholder
function nt_course_note_entry_field() {
global $post;
//ID's
$current_user = get_current_user_id();
$current_lesson_id = $post->ID;
$current_post_type = get_post_type();
//Checks if note exists and changes title and body variables accordingly
$args = array(
'post_type' => 'coursenote',
'post_status' => array( 'draft', 'publish' ),
'meta_query' => array(
//'relation' => 'AND',
array(
'key' => 'nt-note-current-lessson-id',
'value' => $current_lesson_id,
'compare' => '=',
)
),
'author' => $current_user
);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()){
while ( $the_query->have_posts() ) : $the_query->the_post();
//$title = get_the_title();
$body = get_the_content();
//var_dump( $body );
endwhile;
wp_reset_postdata();
} else {
//$title = __( 'Note Title', 'sfwd-lms' );
$body = __( '', 'sfwd-lms' );
}
// get the course title or custom field if it exisists
if( get_field('reflective_learning_question', $current_lesson_id) ) {
$title = get_field('reflective_learning_question', $current_lesson_id);
} else {
$title = get_the_title($current_lesson_id);
//$title = __( 'Note Title', 'sfwd-lms' );
//$body = __( '', 'sfwd-lms' );
}
?>
<div id="nt_note_cont" class="note-container">
<div class="nt-note-wrapper">
<div class="note-header">
<div class="note-header-title">
<span class="nt-close-icon">x</span>
<?php _e( 'Reflective Learning', 'sfwd-lms' ); ?>
</div>
<div class="note-header-actions"></div>
</div> <!--/note-header-->
<div id="apf-response"></div>
<div class="note-body">
<form id="nt-course-note" action="" method="post">
<?php wp_nonce_field( basename(__FILE__), 'nt-course-note-nonce') ?>
<input type="text" name="nt-note-title hide-me" id="nt-note-title" value="<?php echo esc_attr( $title ); ?>" placeholder="" >
<p name="nt-note-title" id="nt-note-title-display"><?php echo esc_attr( $title ); ?></p>
<input type="hidden" name="nt-note-user-id" id="nt-note-user-id" value="<?php echo esc_attr( $current_user ); ?>">
<input type="hidden" name="nt-note-current-lesson-id" id="nt-note-current-lessson-id" value="<?php echo esc_attr( $current_lesson_id ); ?>">
<input type="hidden" name="nt-note-current-post-type" id="nt-note-current-post-type" value="<?php echo esc_attr( $current_post_type ); ?>">
<textarea type="text" name="nt-note-body-custom" id="nt-note-body-custom" value="<?php echo $body; ?>" placeholder="" ><?php echo $body; ?></textarea>
<?php
$args = array(
'media_buttons' => false,
'textarea_name' => 'nt-note-body',
'editor_height' => 175,
'quicktags' => false,
'teeny' => true,
);
add_filter( 'teeny_mce_buttons', 'nt_tiny_mce_buttons', 10, 2);
wp_editor( $body, 'nt-note-body', $args );
remove_filter( 'teeny_mce_buttons', 'nt_tiny_mce_buttons' ); ?>
<br>
<input type="text" id="xyz" name="<?php echo apply_filters( 'honeypot_name', 'date-submitted') ?>" value="" style="display:none">
<ul id="nt-note-actions">
<li><a href="#" class="learndash-notes-print-modal" data-note="<?php the_ID(); ?>"><i class="nticon-print"></i></a></li>
<li><a href="#" class="learndash-notes-download-modal" data-note="<?php the_ID(); ?>"><i class="nticon-file-word"></i></a></li>
</ul>
<input type="submit" id="nt-note-submit" value="<?php esc_attr_e( 'Save', 'sfwd-lms' ); ?>"/>
<p class="nt-reset-dimensions"></p>
</form>
</div> <!--/.note-body-->
</div> <!--/.nt-note-wrapper-->
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment