Custom Editors
-
One thing missing from WP User Frontend is the ability to easily add customerized editors without modifying the core files. This would be highly desireable.
To make it easy to add customized editors I have modified the file wpuf-add-post.php. The Edit Post page code will also have to be modified as well.
Here’s the original code for wpuf-add-post.php
function post_form( $post_type ) { ..... $editor = wpuf_get_option( 'editor_type' ); if ( $editor == 'full' ) { ?> <div style="float:left;"> <?php wp_editor( $description, 'new-post-desc', array('textarea_name' => 'wpuf_post_content', 'editor_class' => 'requiredField', 'teeny' => false, 'textarea_rows' => 8) ); ?> </div> <?php } else if ( $editor == 'rich' ) { ?> <div style="float:left;"> <?php wp_editor( $description, 'new-post-desc', array('textarea_name' => 'wpuf_post_content', 'editor_class' => 'requiredField', 'teeny' => true, 'textarea_rows' => 8) ); ?> </div> <?php } else { ?> <textarea name="wpuf_post_content" class="requiredField" id="new-post-desc" cols="60" rows="8"><?php echo esc_textarea( $description ); ?></textarea> <?php } ?> ..... }
Here’s the replacement
function post_form( $post_type ) { ..... $editor = wpuf_get_option( 'editor_type' ); //Filter $editor. Useful for adding custom editors or assigning editors according to users.. $editor = apply_filters( 'wpuf_editor_type', $editor ); if ( $editor == 'full' ) { ?> <div style="float:left;"> <?php wp_editor( $description, 'new-post-desc', array('textarea_name' => 'wpuf_post_content', 'editor_class' => 'requiredField', 'teeny' => false, 'textarea_rows' => 8) ); ?> </div> <?php } else if ( $editor == 'rich' ) { ?> <div style="float:left;"> <?php wp_editor( $description, 'new-post-desc', array('textarea_name' => 'wpuf_post_content', 'editor_class' => 'requiredField', 'teeny' => true, 'textarea_rows' => 8) ); ?> </div> <?php } else if ( $editor == 'plain' ) { ?> <textarea name="wpuf_post_content" class="requiredField" id="new-post-desc" cols="60" rows="8"><?php echo esc_textarea( $description ); ?></textarea> <?php } else { //Use custom editor. //Two ways to enable. //1. wpuf_editor_type filter above. //2. showtime_wpuf_options_frontend filter. do_action('wpuf_custom_editor', $editor, $description, 'new-post-desc', 'wpuf_post_content'); } ?> ..... }
And here’s an example of it’s use.
showtime.php
============//Add custom editor for WP User Frontend function showtime_wpuf_custom_editor($editor, $description, $editor_id, $textarea_name) { echo '<div>'; wp_editor( $description, $editor_id, array( 'textarea_name' => $textarea_name, 'editor_class' => 'requiredField', 'teeny' => true, 'textarea_rows' => 8, 'quicktags' => false, 'tinymce' => array( 'theme_advanced_statusbar_location' => 'bottom', 'theme_advanced_path' => false, 'theme_advanced_resizing' => true, 'theme_advanced_resize_horizontal' => false, 'plugins' => 'inlinepopups,spellchecker,tabfocus,paste,media,fullscreen,wordpress,wpeditimage,wpgallery,wplink,wpdialogs', 'paste_text_sticky' => true, 'paste_text_sticky_default' => true, 'theme_advanced_buttons1' => 'bold,italic,underline,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,blockquote,wp_more,charmap,spellchecker,link,unlink,undo,redo' ) ) ); echo '</div>'; } add_action('wpuf_custom_editor', 'showtime_wpuf_custom_editor', 10, 4); //Add Showtime Custom Basic Editor to WP User FrontEnd options function showtime_wpuf_options_frontend_map($element) { if ($element['name'] == 'editor_type') { $element['options']['basic'] = __( 'Rich Text (basic)', 'wpuf'); } return $element; } function showtime_wpuf_options_frontend($options) { return array_map('showtime_wpuf_options_frontend_map', $options); } add_filter('wpuf_options_frontend', 'showtime_wpuf_options_frontend', 10, 1 );
Now all that’s still missing is the ability for users to select their editor preference in their Profile but that’s another story :).
Cheers
The Professorhttps://www.ads-software.com/extend/plugins/wp-user-frontend/
- The topic ‘Custom Editors’ is closed to new replies.