Skip to content

Commit

Permalink
Tags Suggestion
Browse files Browse the repository at this point in the history
Now fully working, suggestions autocomplete style for the tags input field. Also, intsllations instructions cleaned up.
  • Loading branch information
cogdog committed Dec 26, 2020
1 parent 055042f commit 2c8bc34
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 104 deletions.
57 changes: 24 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,31 @@ And if you make a TRU Writer site, please please pretty please fork this repo to

If you have problems, feature suggestions, small bags of gold coin for me, please [contact me via the issues area](https://github.com/cogdog/truwriter/issues) on this repo.

## Installing in One Click From Reclaim Hosting (and automatic updates!)
Note that TRU Writer is a child theme based on [the free and elegant Radcliffe theme by Anders Noren](https://wordpress.org/themes/radcliffe). Install this theme first from within the Wordpress Dashboard under **Appearance** -- **Themes** searching on `Radcliffe`. Just install it, no need to activate.

If you are wise enough to host your web sites at [Reclaim Hosting](http://reclaimhosting.com/) you have the option of installing a fully functioning site with this theme ([a copy of the demo site](http://lab.cogdogblog.com/writer/)) including recommended plugins, configured settings and sample content, all done in one click. *But wait there is more!* With this method of installing your site, future updates to the theme are automatically added to your site.
## Installing TRU Writer

In your cpanel, under **Applications** go to **All Applications**. This theme is available listed under Fratured Applications; just install from there.
Using this theme requires a self-hosted--or institutionally hosted (lucky you)-- Wordpress site (the kind that you download from [wordpress.org](http://www.wordpress.org). You cannot use this theme on the free "wordpress.com" site unless you have a business plan. Maybe check out [Reclaim Hosting](https://reclaimhosting.com/) if you need to set up your own hosting space.

![](images/reclaim-featured.jpg "Reclaim Hosting Featured Applications")
The TRU Writer is a child theme based on [the free and elegant Radcliffe theme by Anders Noren](https://wordpress.org/themes/radcliffe). Install this theme first from within the Wordpress Dashboard under **Appearance** -- **Themes** searching on `Radcliffe`.

*Note that unlike other WordPress installs, this one will not preserve your username/password, so be sure to save that information.* When it's done, log into your new site and start making it your own.
### Installing TRU Writer From Scratch

You can download a ZIP file of this theme via the green **Code*" button above (use the Download Zip option).

The zip can be uploaded directly to your site via **Themes** in the Wordpress dashboard, then **Add Theme** and finally **Upload Theme**. If you run into size upload limits or just prefer going old school like me, unzip the package and ftp the entire folder into your `wp-content/themes` directory.

** Installing TRU Writer in One Click with WP Pusher (and automatic updates!)
To get the TRU Writer working all you need to do is activate the "TRU Writer" theme when it appears in the Wordpress dashboard under **Appearance** --> **Themes**.

If all downloading and uploading is making you dizzy, I recommend trying the [WP Pusher plugin](https://wppusher.com/) which makes it easier to install themes and plugins that are published in GitHub. It takes a few steps to set up, but it's a thing of beauty when done.
### Updating the TRU Writer Theme (manually)

Not that TRU Writer is a child theme based on [the free and elegant Radcliffe theme by Anders Noren](https://wordpress.org/themes/radcliffe). Install this theme first from within the Wordpress Dashboard under **Appearance** -- **Themes** searching on `Radcliffe`. Just install it, no need to activate.
As of WordPress version 5.5, themes uploaded as .ZIP files can now be updated the same way you installed it. Just download the newest version, and update it by going to **Themes** in the Wordpress dashboard, then **Add Theme** and finally **Upload Theme**. You will be asked to confirm updating the theme with the newer version.

To use WP-Pusher you will need to have or create an account on [GitHub](https://github.com/) (free). Log in. Groovy?
### Installing TRU Writer in One Click with WP Pusher (get automatic updates!)

To have your site stay up to date automatically, I recommend trying the [WP Pusher plugin](https://wppusher.com/) which makes it easier to install themes and plugins that are published in GitHub. It takes a few steps to set up, but it's a thing of beauty when done.

To use WP-Pusher you will need to have or create an account on [GitHub](https://github.com/) (free). Log in.

Next [download WP Pusher plugin](https://wppusher.com/download) as a ZIP file. From the plugins area of your Wordpress dashboard, click the **Upload Plugin** button, select that zip file to upload, and activate the plugin.

Expand All @@ -118,27 +125,15 @@ Woah Neo?

Not only does this install the theme without any messy download/uploads, each time I update the theme on GitHub, your site will be automatically updated to the newest version.

### Installing in One Click From Reclaim Hosting (get automatic updates!)

### Installing TRU Writer from Scratch

Using this theme requires a self-hosted--or institutionally hosted (lucky you)-- Wordpress site (the kind that you download from [wordpress.org](http://www.wordpress.org). You cannot use this theme on the free "wordpress.com" site. Maybe check out [Reclaim Hosting](https://reclaimhosting.com/) if you need to set up your own hosting space.

The TRU Writer is a child theme based on [the free and elegant Radcliffe theme by Anders Noren](https://wordpress.org/themes/radcliffe). Install this theme first from within the Wordpress Dashboard under **Appearance** -- **Themes** searching on `Radcliffe`.

You can download a ZIP file of this theme via the green **Code*" button above (use the Download Zip option).

The zip can be uploaded directly to your site via **Themes** in the Wordpress dashboard, then **Add Theme** and finally **Upload Theme**. If you run into size upload limits or just prefer going old school like me, unzip the package and ftp the entire folder into your `wp-content/themes` directory.

To get the TRU Writer working all you need to do is activate the "TRU Writer" theme when it appears in your Wordpress dashboard under **Appearance** --> **Themes**.

### Updating the TRU Writer Theme (manually)

As of WordPress version 5.5 themes uploaded as .ZIP files can now be updated the same way you installed it; just download the newest version, and update it via **Themes** in the Wordpress dashboard, then **Add Theme** and finally **Upload Theme**. You will be asked to confirm updating the theme with the newer version.
If you are wise enough to host your web sites at [Reclaim Hosting](http://reclaimhosting.com/) you have the option of installing a fully functioning site with this theme ([a copy of the demo site](http://lab.cogdogblog.com/writer/)) including recommended plugins, configured settings and sample content, all done in one click. *But wait there is more!* With this method of installing your site, future updates to the theme are automatically added to your site (though not as frequently as the WP Pusher method).

If you have ftp/sftp access to your site (or this can be done in a cpanel file manager), simply upload the new theme files to the `wp-content/themes` directory that includes the older version theme.
In your cpanel, under **Applications** go to **All Applications**. This theme is available listed under Fratured Applications; just install from there.

For those that lack direct file upload access or maybe that idea sends shivers down the spine, upload and activate the [Easy Theme and Plugin Upgrades](https://wordpress.org/plugins/easy-theme-and-plugin-upgrades/) plugin -- this will allow you to upload a newer version of a theme as a ZIP archive, the same way you add a theme by uploading.
![](images/reclaim-featured.jpg "Reclaim Hosting Featured Applications")

*Note that unlike other WordPress installs, this one will not preserve your username/password, so be sure to save that information.* When it's done, log into your new site and start making it your own.

## Inserting Demo Content

Expand All @@ -148,13 +143,8 @@ Install all content by [downloading the WordPress export for that site](https://

You can also get a copy of the Widgets used on that site too. First intall/activate the [Widget Importer & Exporter plugin](https://wordpress.org/plugins/widget-importer-exporter/). Download the [Writer Widgets data file](https://github.com/cogdog/truwriter/blob/master/data/writer-widgets.wie). Look under the **Tools** menu for **[Widget Importer & Exporter** and use the Import Widgets section to upload the data file. Boom! You got my widgets.



## Troubleshooting

*Note (Dec 11, 2018) If your site's featured images are blank, it's likely because of a change to the parent Radcliffe theme that was automatically updated on your site. An update to TRU Writer version 1.2 or later will fix this issue.*


If you are updating a site built with a previous version of the theme and something wonky happens after an update, try the following:

* Don't panic!
Expand All @@ -172,12 +162,11 @@ Now that you've installed TRU Writer and can see the barebones theme staring bac

While your doing all that uploading, you should know that this theme uses the [Reading Time WP plugin](https://wordpress.org/plugins/reading-time-wp/) to insert those commonplace estimates of reading time -- blame [Medium](http://www.medium.com) if you hate knowing how long a post might take to read.


### Page Setup

This theme has one special page for your writing form that must be created; associated with a specific template that provides it's functionality. Activating the theme *should* create the page for you when the theme is activated, but if not, create them as described below. You can edit the content of the **Write** page to customize the welcome seen by writers on your site.

If the theme does not do so automatically (and it should) create this Wordpress **Page**. As of version 1.8, you can edit the url short name as well.
If the theme does not do so automatically (and it should) create this Wordpress **Page**.

* **Write** -- The page that provides the writing form, see [http://splot.ca/writer/write](http://splot.ca/writer/write). Whatever you include in the body (not required) is added to the top of the form, maybe for extra instructions.e.g. for a site at `http://coolest.site.org/` the page can be published at `http://coolest.site.org/writing` When you create a Writing Form page, under **Page Atributes**, select the Template named `Writing Pad`

Expand Down Expand Up @@ -363,6 +352,8 @@ You can copy and paste from that .txt file into the import field of the settings

## Relatively Cool New Features & Updates

* **Tag Suggestions** Tags entry field provides autocomplete suggestions.

**Alternative Text For Header Images** Optional field added that should be used! Provide an alternative text for an image for better web accessibility.

**Header Image and Caption Options** New theme options to make thes fields required (default), optional, or not used. Sometimes people don't want images atop their writing or used on archive listings.
Expand Down
Binary file removed images/autoembed-splot-editor.gif
Binary file not shown.
Binary file removed images/default-image.jpg
Binary file not shown.
Binary file removed images/est-reading-time.jpg
Binary file not shown.
Binary file removed images/menus.jpg
Binary file not shown.
Binary file removed images/publish-options1.jpg
Binary file not shown.
Binary file removed images/publish-options2.jpg
Binary file not shown.
Binary file removed images/publish-options3.jpg
Binary file not shown.
165 changes: 98 additions & 67 deletions includes/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function truwriter_write_director() {
}
}

// prevent posts from being saved to /random (reserved for random post generator)
// prevent posts from being saved to /random (reserved for random post generator

add_action( 'save_post', 'splot_save_post_random_check' );

Expand All @@ -183,8 +183,6 @@ function splot_save_post_random_check( $post_id ) {

$new_post = get_post( $post_id );
if ( ! wp_is_post_revision( $post_id ) and $new_post->post_name == 'random' ) {


// unhook this function to prevent infinite looping
remove_action( 'save_post', 'splot_save_post_random_check' );

Expand All @@ -209,12 +207,15 @@ function splot_save_post_random_check( $post_id ) {
add_filter('comment_form_defaults', 'truwriter_comment_mod');

function truwriter_comment_mod( $defaults ) {
$defaults['title_reply'] = 'Provide Feedback';
$defaults['title_reply'] = get_truwriter_comment_title();
$defaults['title_reply_after'] = '</h3>' . get_truwriter_comment_extra_intro();
$defaults['logged_in_as'] = '';
$defaults['title_reply_to'] = 'Provide Feedback for %s';
$defaults['label_submit'] = get_truwriter_comment_button_label();
return $defaults;
}


// possibly add writer email to comment notifications
// add_filter( 'comment_moderation_recipients', 'truwriter_comment_notification_recipients', 15, 2 );
add_filter( 'comment_notification_recipients', 'truwriter_comment_notification_recipients', 15, 2 );
Expand Down Expand Up @@ -349,7 +350,7 @@ function truwriter_tinymce_2_buttons( $buttons) {
}


// this is the handler used in the tiny_mce editor to manage iage upload
// this is the handler used in the tiny_mce editor to manage image upload
add_action( 'wp_ajax_nopriv_truwriter_upload_action', 'truwriter_upload_action' ); //allow on front-end
add_action( 'wp_ajax_truwriter_upload_action', 'truwriter_upload_action' );

Expand Down Expand Up @@ -438,14 +439,14 @@ function add_truwriter_scripts() {

if ( is_page( truwriter_get_write_page() ) ) { // use on just our form page

// add media scripts if we are on our maker page and not an admin
// after http://wordpress.stackexchange.com/a/116489/14945

if (! is_admin() ) wp_enqueue_media();
if (! is_admin() ) {
// add media scripts if we are on our collect page and not an admin
// after http://wordpress.stackexchange.com/a/116489/14945
wp_enqueue_media();


// Build in tag auto complete script
wp_enqueue_script( 'suggest' );
// Build in tag auto complete script
wp_enqueue_script( 'suggest' );
}

// Autoembed functionality in rich text editor
// needs dependency on tiny_mce
Expand All @@ -460,7 +461,7 @@ function add_truwriter_scripts() {
add_filter('mce_buttons_2','truwriter_tinymce_2_buttons');

// custom jquery for the uploader on the form
wp_register_script( 'jquery.writer' , get_stylesheet_directory_uri() . '/js/jquery.writer.js', array( 'suggest') , '1.8', TRUE );
wp_register_script( 'jquery.writer' , get_stylesheet_directory_uri() . '/js/jquery.writer.js', array( 'suggest') , false, true );

// add a local variable for the site's home url
wp_localize_script(
Expand Down Expand Up @@ -490,6 +491,90 @@ function add_truwriter_scripts() {
}
}

# -----------------------------------------------------------------
# Tag Search
# -----------------------------------------------------------------


add_filter( 'wp_headers', 'splot_send_cors_headers', 11, 1 );

function splot_send_cors_headers( $headers ) {
if ( is_page( truwriter_get_write_page() ) ) {
$headers['Access-Control-Allow-Origin'] = '*';
}
return $headers;
}

// this is the handler used in the tiny_mce editor to manage image upload
add_action( 'wp_ajax_nopriv_splot_ajax_tag_search', 'splot_ajax_tag_search' ); //allow on front-end
add_action( 'wp_ajax_splot_ajax_tag_search', 'splot_ajax_tag_search' );


/* local version of wp_ajax_ajax_tag_search without exit for user capabilties
(this requires a logged in user which we do not always have
modified from
https://developer.wordpress.org/reference/functions/wp_ajax_ajax_tag_search
*/

function splot_ajax_tag_search() {
if ( ! isset( $_GET['tax'] ) ) {
wp_die( 0 );
}

$taxonomy = sanitize_key( $_GET['tax'] );
$tax = get_taxonomy( $taxonomy );

if ( ! $tax ) {
wp_die( 0 );
}

$s = wp_unslash( $_GET['q'] );

$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma ) {
$s = str_replace( $comma, ',', $s );
}

if ( false !== strpos( $s, ',' ) ) {
$s = explode( ',', $s );
$s = $s[ count( $s ) - 1 ];
}

$s = trim( $s );

/**
* Filters the minimum number of characters required to fire a tag search via Ajax.
*
* @since 4.0.0
*
* @param int $characters The minimum number of characters required. Default 2.
* @param WP_Taxonomy $tax The taxonomy object.
* @param string $s The search term.
*/
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );

/*
* Require $term_search_min_chars chars for matching (default: 2)
* ensure it's a non-negative, non-zero integer.
*/
if ( ( 0 == $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) {
wp_die();
}

$results = get_terms(
array(
'taxonomy' => $taxonomy,
'name__like' => $s,
'fields' => 'names',
'hide_empty' => false,
)
);

echo implode( "\n", $results );
wp_die();
}


# -----------------------------------------------------------------
# Grab Bag
Expand All @@ -505,8 +590,6 @@ function my_default_image_size () {
return 'large';
}



function truwriter_show_drafts( $query ) {
// show drafts only for single previews
if ( is_user_logged_in() || is_feed() || !is_single() )
Expand Down Expand Up @@ -603,56 +686,4 @@ function splot_default_menu() {

return ( '<li><a href="' . $splot_home . '">Home</a></li><li><a href="' . $splot_home . truwriter_get_write_page() . '">Write</a></li><li><a href="' . $splot_home . 'random' . '">Random</a></li>' );
}

/**
* This function assumes you have a Customizer export file in your theme directory
* at 'data/customizer.dat'. That file must be created using the Customizer Export/Import
* plugin found here... https://wordpress.org/plugins/customizer-export-import/
* h/t - https://gist.github.com/fastlinemedia/9a8070b9a636e38b510f
*/

add_action( 'after_switch_theme', 'splot_import_customizer_settings' );

function splot_import_customizer_settings()
{
// Check to see if the settings have already been imported.
$template = get_template();
$imported = get_option( $template . '_customizer_import', false );

// Bail if already imported.
if ( $imported ) {
return;
}

// Get the path to the customizer export file.
$path = trailingslashit( get_stylesheet_directory() ) . 'data/customizer.dat';

// Return if the file doesn't exist.
if ( ! file_exists( $path ) ) {
return;
}

// Get the settings data.
$data = @unserialize( file_get_contents( $path ) );

// Return if something is wrong with the data.
if ( 'array' != gettype( $data ) || ! isset( $data['mods'] ) ) {
return;
}

// Import options.
if ( isset( $data['options'] ) ) {
foreach ( $data['options'] as $option_key => $option_value ) {
update_option( $option_key, $option_value );
}
}

// Import mods.
foreach ( $data['mods'] as $key => $val ) {
set_theme_mod( $key, $val );
}

// Set the option so we know these have already been imported.
update_option( $template . '_customizer_import', true );
}
?>
3 changes: 2 additions & 1 deletion js/jquery.writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

jQuery('#wTags').suggest( writerObject.siteURL + "/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag", {multiple:true, multipleSep: ","});

jQuery('#wTags').suggest( writerObject.ajaxUrl + "?action=splot_ajax_tag_search&tax=post_tag", {multiple:true, multipleSep: ","});

jQuery(document).ready(function() {
// called for change in input drop zone (or click)
Expand Down
3 changes: 1 addition & 2 deletions page-write.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
if ( isset( $wEmail ) and !$linkEmailed ) truwriter_mail_edit_link( $post_id, 'draft' );


$feedback_msg = 'Your edits have been updated and are still saved as a draft mode. You can <a href="'. site_url() . '/?p=' . $post_id . 'preview=true&ispre=1' . '" target="_blank">preview it now</a> (opens in a new window), or make edits, review again, or if you are ready, submit it for publishing. ';
$feedback_msg = 'Your edits have been updated and are still saved as a draft mode. You can <a href="'. site_url() . '/?p=' . $post_id . 'preview=true&ispre=1' . '" target="_blank">preview it now</a> (opens in a new window), or make edits, review again, and if you are ready, submit it for publishing. ';

if ( $wEmail != '' ) $feedback_msg .= ' Since you provided an email address, you should receive a message that provides instructions on how to return and make edits in a later session.';

Expand Down Expand Up @@ -759,7 +759,6 @@
}

?>

</fieldset>

<?php endif?>
Expand Down
Loading

0 comments on commit 2c8bc34

Please sign in to comment.