# Wp-discourse-shortcodes plugin

**URL:** https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910
**Category:** Extras
**Created:** [August 20, 2016, 1:41am UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910 "2016-08-20T01:41:38Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 20, 2016, 1:41am UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/1 "2016-08-20T01:41:38Z")

</div>

This is a simple plugin that extends the wp-discourse plugin by adding shortcodes for creating links from WordPress to your Discourse forum.

It adds shortcodes for `[discourse_link]` , for creating a login link to a specific endpoint on your forum, `[discourse_topic]` for beginning a pre-filled topic, and `[discourse_message]` for beginning a private message. See the plugin’s readme for more details. This plugin is only lightly tested, so let me know if you run into problems with it.

[https://github.com/scossar/wp-discourse-shortcodes](https://github.com/scossar/wp-discourse-shortcodes)

 ![](https://global.discourse-cdn.com/meta/original/3X/e/5/e57d477263573b96bb369786ee3f2427d600160d.png)

* * *

edit:

I’ve added a `[discourse_latest]` shortcode. At this point it takes one parameter, `max_topics`. The topics are cached for 10 minutes. I’m still playing around with the formatting.

 ![](https://global.discourse-cdn.com/meta/original/3X/3/7/377a0114464cba9f156bca2bfd65894dd1e0b1dd.png)

The `[discourse_groups]` shortcode retrieves and displays all groups that are not `automatic` and _are_ `visible`. It adds a ‘Request to join’ link at the bottom of each group that creates a private message to the group’s owners. If no owner exists, the request is sent to a site admin. Results are cached for 1 hour, that can be made to be configurable. I’ll add an option to not display the ‘Request to join’ link for specific groups. The plugin’s error handling needs to be improved. There are no styles associated with the plugin. It’s up to the site’s theme to supply them.

The group description is created by creating a topic on Discourse with a title that follows the format ‘About the {group name} group’.

 ![](https://global.discourse-cdn.com/meta/original/3X/d/f/df0683c7079f9b1842c7b180b7a0b64cb7fcc00f.png)

## open issues

- `[discourse_topics]` shortcodes with different categories do not work correctly.
- top does not work together with filtering on category

## features (roadmap)

- option to open links in new tab
- support for filtering by tag

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [August 24, 2016, 6:37pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/2 "2016-08-24T18:37:37Z")

</div>

Nice work really like the groups functionality.

Although I am having an issue with that shortcode. It does not seem to update when i make changes to the groups, I also tried adding a description post for and exsiting one and it is not showing up either. Does the plugin cache the information from discourse?

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [August 24, 2016, 6:42pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/3 "2016-08-24T18:42:32Z")

</div>

> [@simon](#):
>
> Results are cached for 1 hour, that can be made to be configurable

Nevermind just saw this. 😁

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 24, 2016, 7:59pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/4 "2016-08-24T19:59:51Z")

</div>

I’m going to add a `cache_time` option to the `[discourse_groups]` and `[discourse_latest]` shortcodes. The groups shortcode needs better error handling. I’ll do it soon because this is something I want to use on a website. I’ll add a `[discourse_categories]` shortcode later this week.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [August 25, 2016, 3:42pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/5 "2016-08-25T15:42:15Z")

</div>

I would like to make a request to be able to hide some groups from view.

---

<div class="post-metadata">

### Author: ![charles](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@charles](https://meta.discourse.org/u/charles)
#### Post date: [August 26, 2016, 8:42pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/6 "2016-08-26T20:42:30Z")

</div>

Haven’t tried it yet but thanks for this plugin @simon

Instead of just groups, can this plugin also populate posts from discourse using the same group layout?

For example: mark a popular discussion within discourse and get it “pushed” to the frontpage of wp to be shown just like [discourse\_groups] with image and teaser intro text.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [September 29, 2016, 12:38pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/8 "2016-09-29T12:38:03Z")

</div>

It seems the lastest version of the WP-Discourse plugin has broke this one. From what I can tell, based on the error i am seeing, is becuase some functions were moved and/or renamed and this plugin is looking in the wrong place for them.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 29, 2016, 4:07pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/9 "2016-09-29T16:07:05Z")

</div>

Thanks, I forgot about that. I’ll fix it today.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 29, 2016, 6:02pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/10 "2016-09-29T18:02:51Z")

</div>

It’s should be working now with the latest release of the wp-discourse plugin. Let me know if you have any problems with it.

I’m going to do some more work on the shortcodes plugin today. The changes will be in the ‘beta’ branch on github.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 4, 2016, 9:10am UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/11 "2016-10-04T09:10:53Z")

</div>

I’ve done some work on this over the past couple of days. All new work is in the ‘beta’ branch. You can see it here: [GitHub - communiteq/wp-discourse-shortcodes at beta · GitHub](https://github.com/scossar/wp-discourse-shortcodes/tree/beta)

Messages are now created on the WordPress site and sent to Discourse using the API. Messages sent from email addresses that are already associated with a Discourse user are sent from that user. Messages that are sent from email addresses that is not associated with a Discourse user create a new ‘staged’ user. To avoid sending activation emails to the new staged users, I am using this Discourse plugin on my forum: [GitHub - scossar/discourse-staged-user-activation: Don't send an activation email to staged users that are created through the API · GitHub](https://github.com/scossar/discourse-staged-user-activation).

The wp-discourse-shortcodes plugin now has four shortcodes, `[discourse_link]`, `[discourse_remote_message]`, `[discourse_groups]`, and `[discourse_latest]`. See the [README](https://github.com/scossar/wp-discourse-shortcodes/blob/beta/README.md) for more details.

**NOTE:** This is still under development, so use at your own risk for now. It’s something that I have some use for. I’ll be working on it as time permits.

 ![](https://global.discourse-cdn.com/meta/original/3X/d/d/dd2f349081b240c24f2e4e8e6857580db7abe44d.png)

 ![](https://global.discourse-cdn.com/meta/original/3X/f/3/f3da138aa46abbc8eddaf3152e253aaed01818ee.png)

 ![](https://global.discourse-cdn.com/meta/original/3X/a/3/a361bcbc3758e808b0f37365219269b70db03f31.png)

 ![](https://global.discourse-cdn.com/meta/original/3X/2/a/2a0f5e26bab308340bac8aa7fa847b59b4708b48.png)

Edit: I’m going to change the way the plugin deals with active, non-staged users. It seems wrong to assume that just because someone knows a user’s email address they really are that user.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [October 4, 2016, 2:43pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/12 "2016-10-04T14:43:22Z")

</div>

I actually have the groups page only visible to members so the direct pm button is a bit easier instead of the user having to fill out a form. Is there an option to use the previous method?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 4, 2016, 8:40pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/13 "2016-10-04T20:40:18Z")

</div>

> [@Grex315](#):
>
> Is there an option to use the previous method?

Yes, that can be done if your site is using SSO with the wp-discourse plugin. Set the ‘remote\_message’ attribute to ‘false’. That will add a link to Discourse at the bottom of each group that starts a private message to the group in the Discourse Composer.

Example: ` [discourse_groups button_text="Join Now" group_list="blues_society,mountain_biking" invite="true" remote_message="false"]`

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 5, 2016, 2:34am UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/14 "2016-10-05T02:34:43Z")

</div>

I’ve updated the way the `discourse_remote_message` shortcode handles existing users who are active on the forum. If a form is submitted by an existing, active user, it is not posted through the API, instead, if SSO is enabled, a prefilled message link is created and the user is asked to submit that instead. If SSO is not enabled, the user is instructed to log into the forum to complete their request. The `discourse_groups` shortcode has the same behaviour - it uses the `discourse_remote_message` code.  
Staged users can still submit forms repeatedly from the WordPress site.

A form that has been completed by an active user:

 ![](https://global.discourse-cdn.com/meta/original/3X/e/8/e8edb8159ccdb5ab7b06ff3937c180a9c9209040.png)

Because the user is active, instead of posting the form, a message link is created from the its contents.

 ![](https://global.discourse-cdn.com/meta/original/3X/2/8/28619e0d19f7a55584f2587a12e25300d170ad7d.png)

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [October 5, 2016, 4:58pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/15 "2016-10-05T16:58:38Z")

</div>

Awesome work on the plugin. Two things I noticed.

1. For some reason my First Group on the list does not show the signup section. Just the group info.
2. using the shortcode you provided with the Remote message turned off the class for the join link has what looks like a double post of the “class” with a space and an extra set of quotes causing the class name to be not recognized so I cannot style it.

It comes up as such:

```
<a class="class=" wpdc-shortcodes-message-link""="" href="https://forums.grimreapergamers.com/session/sso?return_path=https%3A%2F%2Fforums.grimreapergamers.com%2Fnew-message%3Fgroupname%3DBattlefieldPlayers%26title%3DRequest+to+join+the+BattlefieldPlayers+group">Join Now</a>

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 5, 2016, 5:26pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/16 "2016-10-05T17:26:26Z")

</div>

> [@Grex315](#):
>
> For some reason my First Group on the list does not show the signup section. Just the group info.

Only ‘mentionable’ groups will display a signup form. The cache period for getting the groups is now set to 24 hours. If you make any changes to the groups you will need to add `clear_cache="true"` to the shortcode attributes for one request.

> [@Grex315](#):
>
> with the Remote message turned off the class for the join link has what looks like a double post of the “class” with a space and an extra set of quotes causing the class name to be not recognized so I cannot style it.

I think I’ve fixed that in the latest version.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [October 29, 2016, 7:45pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/17 "2016-10-29T19:45:56Z")

</div>

For the discourse\_groups shortcode I noticed that if I set invite to true and remote message to false the plugin pm’s the groupname so all members of the group get a pm, whereas in a previous version it pm’d just the owner of the group. Is there a way to go back to that? I dont want the enitire group getting a pm when someone requests to join.

Thanks

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 29, 2016, 7:59pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/18 "2016-10-29T19:59:55Z")

</div>

Yes, that will cause problems. I’ll change it back to the way it was.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [October 30, 2016, 12:04am UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/19 "2016-10-30T00:04:41Z")

</div>

Thanks. Much appreciated.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 30, 2016, 9:17pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/20 "2016-10-30T21:17:29Z")

</div>

Is your forum set up to allow users to create topics and message by email? It seems that the plugin could take care of all possible use cases if it relied on this.

I’m going to do some work on it tomorrow.

---

<div class="post-metadata">

### Author: ![Grex315](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grex315/32/115868_2.png) [@Grex315](https://meta.discourse.org/u/Grex315)
#### Post date: [October 30, 2016, 11:07pm UTC](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910/21 "2016-10-30T23:07:20Z")

</div>

My forum is setup for reply via email but not create via email. I dont have an issue with turning the later on as well.

[Next page](https://meta.discourse.org/t/wp-discourse-shortcodes-plugin/48910.md?page=2)
