WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#34230 reopened defect (bug)

Wordcount broken in frontend (v. 4.3)

Reported by: finnj Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.3
Component: Editor Keywords: 2nd-opinion
Focuses: Cc:

Description

With the update of wordcount in version 4.3, wordcount stopped working in frontend.

I am the author of Frontier Post plugin, and users have reported this. To check I have made the below simple plugin, and tested it with version 4.2.5 & 4.3.1. wordcount works with 4.2.5, and not with 4.3.1.

Steps to reproduce:

  1. Install attached plugin.
  2. Create a page with [frontier-test-wordcount]
  3. View the page, and write a couple of lines of text
<?php
/*
Plugin Name: Frontier Test Wordcount
Plugin URI: http://wordpress.org/extend/plugins/
Description: Test wordcount
Author: finnj
Version: 1.0.0
Author URI: http://wpfrontier.com
*/


function frontier_test_wordcount()
	{
	$frontier_permalink = get_permalink();
	$tmp_text			= "Test";
	
	ob_start();
	
	//***************************************************************************************
	//* Start form
	//***************************************************************************************

	echo '<div class="frontier_post_form"> ';
	echo '<form action="'.$frontier_permalink.'" method="post" name="frontier_test_wordcount" id="frontier_test_wordcount" enctype="multipart/form-data" >';
	
	echo '<table ><tbody><tr>';
		echo '<td >';

		wp_editor($tmp_text, 'test_wordcount', array('dfw' => false, 'editor_height' => 300, 'drag_drop_upload' => true ));	
	
		printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' );
		
		
		echo '</td></tr></table>';
	echo '<button class="button" type="submit" name="user_post_submit" 	id="user_post_submit" 	value="savereturn">Submit</button>';
	
	echo '</td></tr></table>';
	echo '</form>'; 

	
	// end form file	
	$fp_content = ob_get_contents();
	ob_end_clean();
	return $fp_content;

	}

add_shortcode("frontier-test-wordcount","frontier_test_wordcount");

//*******************************************************************************************	
// Load wordcount
//*******************************************************************************************

function frontier_enqueue_test_wordcount()
	{
	wp_enqueue_script( 'word-count' );
	} 

add_action("wp_enqueue_scripts","frontier_enqueue_test_wordcount");  
?>

Change History (3)

#1 follow-up: @iseulde
2 years ago

  • Component changed from TinyMCE to Editor
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

You'll have to initialise the counter yourself now. It's not part of wp_editor and the word count script was only meant to be used with the main editor. You could use the script now though, it's more abstract and might be moved to wp-includes. See #30966 for more background and take a look at wp-admin/js/post.js for an example on how to use it with wp_editor. If you're using scrips under wp-admin on the front-end, you'll have to keep up with the development of them.

#2 in reply to: ↑ 1 @finnj
2 years ago

Replying to iseulde:

You'll have to initialise the counter yourself now. It's not part of wp_editor and the word count script was only meant to be used with the main editor. You could use the script now though, it's more abstract and might be moved to wp-includes. See #30966 for more background and take a look at wp-admin/js/post.js for an example on how to use it with wp_editor. If you're using scrips under wp-admin on the front-end, you'll have to keep up with the development of them.

That was a rough answer!
This has worked for years in the frontend, just using:

printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' );

I am sorry but I am not able to keep up with all wordpress scripts.
And I do not understand your point on it should just work for the main editor.
I can load the wordcount plugin from tinymce (works fine), but that adds overhead, which I do not like.
As you do not see this as a bug, do I need to open a enhancement request ?

#3 @iseulde
2 years ago

  • Keywords 2nd-opinion added
  • Milestone set to Awaiting Review
  • Resolution invalid deleted
  • Status changed from closed to reopened
Note: See TracTickets for help on using tickets.