Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-08-09 13:35:00

xjosie729
Member
From: Framingham, MA
Registered: 2006-07-22
Posts: 39
Website

How do I make a simple plugin?

Hi

I’d like to make a very simple plugin that displays your name. (The reason I want to make this is because I want to learn how to make plugins for textpattern.) I know some PHP.

I want it to be something like this: <txp:123_testplugin name="Blah" /> which will output the name “Blah”.
I think it’s very simple for most of you but I have no idea how to make it.


Josie

Offline

#2 2006-08-09 13:41:32

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: How do I make a simple plugin?

I am in the same boat xjosie, though I wish I had more PHP experience to fall back on..

This is very helpful

Offline

#3 2006-08-09 14:27:20

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: How do I make a simple plugin?

Here, this should work…..

<pre>
<code>
&#60;&#63;php

&#36;plugin[‘version’] = ‘0.1’;
&#36;plugin[‘author’] = ‘Josie’;
&#36;plugin[‘author_uri’] = ‘http://www.whitehouse.gov’;
&#36;plugin[‘description’] = ‘Display your name.’;

&#63;plugin[‘type’] = 0;

&#64;include_once(‘zem_tpl.php’);

if (0) {

?&#62;
&#35; —- BEGIN PLUGIN HELP —- h1. Josie’s Name

Put this tag in:

<code> &#60;txp:jsi_display name=”“ /&#62; </code>

And put the name you wish to display in the name=”“ attribute.

&#35; —- END PLUGIN HELP —-
&#60;&#63;php

}

&#35; —- BEGIN PLUGIN CODE —-
function jsi_display(&#36;atts) { global &#36;prefs; global &#36;permlink_mode; global &#36;thisarticle; global &#36;img_dir;

extract(lAtts(array( ‘name’=> (!empty($prefs[‘jsi_display_name’]))?&#36;prefs[‘jsi_display_name’]:‘No name given!’ ),&#36;atts));

return $name
}

&#35; —- END PLUGIN CODE —-
}
?&#62;
</code>
</pre>

Now you just need to download the zem_tpl.php file (from here ) and compile it. (by simply loading this file in your browser from a php server.

Last edited by Walker (2006-08-09 14:33:10)

Offline

#4 2006-08-09 14:34:06

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: How do I make a simple plugin?

Shit. That took way too many edits to get it to display the code right. Anyone (mary), is there an official Textpattern pastebin?

Offline

#5 2006-08-09 15:13:39

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: How do I make a simple plugin?

No, there isn’t, I’m afraid – at present.

Offline

#6 2006-08-09 16:27:57

Inspired
Plugin Author
From: Kiev, Ukraine
Registered: 2005-01-28
Posts: 87
Website

Re: How do I make a simple plugin?

xjosie729, you can as well use a more “visual” way with the plugin composer. Here’s what you should do:

- install the plugin ied_plugin_composer

- in the “plugin composer” panel enter “xxx_testplugin” and hit “create new plugin”

- enter the code:

<pre>
<code>
function xxx_display($atts) {

extract(lAtts(array( ‘name’=> ‘No name given!’ ),$atts));

return $name;
}
</code>
</pre>

(Simplified Walker’s code with trailing ;)

- check “enable plugin”

- since your plugin doesn’t do anything to the admin panel you can leave “plugin uses admin side” unchecked.

- fill the other fields, or do it later (but before you decide to share your plugin with others)

- hit “save”

- test the tag: <txp:xxx_display name="Blah" />

- when you are ready to share your plugin with others, scroll down and hit save as xxx_testplugin_v0.1.txt (for distribution) link


Plugin Composer — admin plugin to write your own plugins

Offline

#7 2006-08-09 22:19:46

xjosie729
Member
From: Framingham, MA
Registered: 2006-07-22
Posts: 39
Website

Re: How do I make a simple plugin?

Thanks!


Josie

Offline

Board footer

Powered by FluxBB