mautic-wordpress icon indicating copy to clipboard operation
mautic-wordpress copied to clipboard

[feature request] shortcode for user counter

Open valessiobrito opened this issue 4 years ago • 5 comments

A code which can show the total number of users in a segment or tag, or platform total.

Inspired in https://wordpress.org/plugins/contacts-in-mautic/

Eg.

[mautic tagscount=2]

[mautic segmentcount=1]

[mautic contactscount]


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

valessiobrito avatar Jun 11 '21 17:06 valessiobrito

Hello !

This seems an interesting idea, if you want to contribute, I'll be glad to review your code ^^

shulard avatar Oct 04 '21 14:10 shulard

im willing do this, when i find time

weismannweb avatar Nov 25 '21 15:11 weismannweb

So i was thinking of:

I think this can ALL be done with this mautic api call and ONE wordpress shortcode: https://developer.mautic.org/#list-contacts

[mautic type="contacts" search="thesearchstring" display="list" limit="10" where="where_x=y|where_x=y|where_x=y|where_x=y|where_x=y" orderBy="first_name" orderbydir="desc"]

[mautic type="contacts" search="thesearchstring" display="count" where="where_x=y|where_x=y|where_x=y|where_x=y|where_x=y" orderBy="first_name" ]

I would extrapolate that one shortcode and function to create these shorter shortcodes but that one function above would handle these too:

[mautic type="tags" display="list" ids="2.4,6" limit="10" ...] [mautic type="segment" display="list" ids="2.4,6" limit="10" ...] [mautic type="tags" display="count" ids="2.4,6" ...] [mautic type="segment" display="count" ids="2.4,6" ...] [mautic type="points" display="count"]

ids: can be id or name (if api call supports both)

Have a default style and allow developers to use a template include wp hook to change the style.

Finally too boot lets allow this function I create to return an array for developers who want to use it:

function mautic_search(,,,,,,,,,,,$return_type)

The only crappy part of this, correct me if im wrong, is I think we need to have an oauth 2.0 authentication feature to do this. The shortcode is quite simple but oauth is a ui feature and a 3 step process plus a cron to keep the token fresh.

FYI, I assume this is what can be done with that api call search param: Search Operators:

  • (plus sign) - Search for the exact string (i.e. if admin, then administrator will not match) ! (exclamation mark) - Not equals string " " (double quotes) - Search by phrase ( ) (parentheses) - Group expressions together. OR - By default the expressions will be joined as AND statements. Use the OR operator to change that. % - Use the % as a wildcard to search for specific names or values in a phrase (i.e. to find all companies with the word ‘Technologies’ then type %technologies%)

Search commands is:anonymous is:unowned is:mine email:* segment:{segment_alias} name:* company:* owner:* ip:* ids:ID1,ID2 (comma separated IDs, no spaces) common:{segment_alias} + {segment_alias} + ... tag:* stage:* email_sent:EMAIL_ID email_read:EMAIL_ID email_queued:EMAIL_ID email_pending:EMAIL_ID

weismannweb avatar Nov 25 '21 16:11 weismannweb

Ok, this looks good. However, the main point is not implementing the Shortcode for me. If we introduce this feature, we'll require to add an HTTP client to communicate with the Mautic API. That's my main concern here, today we don't use this API in the plugin so be careful if you work on an implementation to clearly decouple the API call from the code itself.

shulard avatar Nov 25 '21 16:11 shulard

I decouple/loosely couple everything I do lol. I can implement a simple api call using curl. I don't even need to introduce a dependency. The oauth part is the part im not sure how to decouple. I was actually thinking of creating a seperate oauth authentication plugin for all wordpress devs who need it. Then have hooks for devs to use it. We could do that and require this for that plugin to work? Seems a bit obtuse to do that. So maybe if you want to keep it totally separate I can make this another plugin for your plugin and have both oauth and this search in that new child plugin and we can maintain it separately? I may need a single hooks from you to get it done such as grabbing the mautic url but i will use it only if your plugin is installed....otherwise i will have my own mautic url field too.

weismannweb avatar Nov 25 '21 17:11 weismannweb