-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-text-counter.php
55 lines (41 loc) · 1.52 KB
/
wp-text-counter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
Plugin Name: Wordpress Text Counter
Plugin URI: https://www.raisachin.com.np/plugins/wp-text-counter/
Description: A simple plugin to count words or characters for given text
Version: 1.0.0
Author: sachinkiranti
Author URI: https://raisachin.com.np
Text Domain: wp-text-counter
*/
defined( 'ABSPATH' ) or die( 'No direct access!' );
// Shortcode for the Frontend UI
if (! function_exists('wp_text_counter_frontend')) :
function wp_text_counter_frontend( $atts )
{
extract( shortcode_atts(
array(
'title' => 'Enter your text here :',
), $atts )
);
$file_path = dirname(__FILE__) . '/templates/wp-text-counter-frontend.php';
ob_start();
include($file_path);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
endif;
add_shortcode( 'wp-text-counter', 'wp_text_counter_frontend' );
// Script
if (! function_exists('wp_text_counter_enqueue_scripts')) :
function wp_text_counter_enqueue_scripts()
{
global $post;
if ((is_single() || is_page()) && has_shortcode($post->post_content, 'wp-text-counter')) {
wp_enqueue_script('sachinkiranti-textual', 'https://unpkg.com/@sachinkiranti/[email protected]/dist/textual.min.js');
wp_enqueue_script('wtc-script', plugin_dir_url(__FILE__) . 'assets/wp-text-counter.js', array('jquery', 'sachinkiranti-textual'), null, true);
}
}
endif;
add_action( 'wp_enqueue_scripts', 'wp_text_counter_enqueue_scripts' );