Skip to content

Commit

Permalink
3.9.1
Browse files Browse the repository at this point in the history
COMMENT EDITOR

- Changed the conditional for Comment Editor from `h-comment` to `h-comment-editor`
- Added conditional so the script is only enqueued if comment status is open.
- Removed `h-wp.js` because most of its script are moved to this Comment module
- Updated hEditor from 1.1.1 to 1.1.2
  • Loading branch information
hrsetyono committed May 22, 2020
1 parent 47989c0 commit 4aa5975
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 81 deletions.
2 changes: 1 addition & 1 deletion edje-wp-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* License: MIT
* Author: Pixel Studio
* Author URI: https://pixelstudio.id
* Version: 3.9.0
* Version: 3.9.1
*/

if( !defined( 'WPINC' ) ) { die; } // exit if accessed directly
Expand Down
40 changes: 28 additions & 12 deletions module-comment/_index.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?php

add_action( 'after_setup_theme', function() {
if( get_theme_support( 'h-comment' ) ) {
new H_Comment();
}
}, 9999 );


if( !class_exists( 'H_Comment' ) ) {
/**
* Add toolbar to Comment Form and parse the markdown
*/
class H_Comment {
function __construct() {
add_action( 'after_setup_theme', [$this, 'init'], 9999 );
add_action( 'wp_enqueue_scripts', [$this, 'enqueue_scripts'] );
}


/**
* @action after_setup_theme
*/
function init() {
if( !get_theme_support( 'h-comment-editor' ) ) { return; }

remove_filter( 'comment_text', 'make_clickable', 9 );
remove_filter( 'comment_text', 'wptexturize', 10 );

if( !is_admin() ) {
remove_filter( 'comment_text', 'make_clickable', 9 );
remove_filter( 'comment_text', 'wpautop', 30 );
add_filter( 'comment_text', [$this, 'parse_markdown' ] );
}
Expand All @@ -27,11 +30,22 @@ function __construct() {
* @action wp_enqueue_scripts
*/
function enqueue_scripts() {
$css_dir = plugin_dir_url(__FILE__) . 'assets';
$js_dir = plugin_dir_url(__FILE__) . 'assets';
global $post;
$is_comment_open = isset( $post->comment_status ) && $post->comment_status == 'open';

// Enable comment's reply form
if( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}

// If supported, add the editor
if( get_theme_support( 'h-comment-editor' ) && $is_comment_open ) {
$css_dir = plugin_dir_url(__FILE__) . 'assets';
$js_dir = plugin_dir_url(__FILE__) . 'assets';

wp_enqueue_style( 'h-editor', $css_dir . '/h-editor.css', [], '1.1.1' );
wp_enqueue_script( 'h-editor', $js_dir . '/h-editor.js', [], '1.1.1', true );
wp_enqueue_style( 'h-editor', $css_dir . '/h-editor.css', [], '1.1.2' );
wp_enqueue_script( 'h-editor', $js_dir . '/h-editor.js', [], '1.1.2', true );
}
}

/**
Expand All @@ -44,3 +58,5 @@ function parse_markdown( $text ) {
}
}

new H_Comment();
}
2 changes: 1 addition & 1 deletion module-comment/assets/h-editor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4aa5975

Please sign in to comment.