Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-08-29 15:47:20

glenelkins2
New Member
Registered: 2008-08-29
Posts: 4

Adding Sections To Admin

Hi

How do I go about adding a new Tab in the admin area under the ADMIN tab?

I have looked around a few files and noticed i can add to some files but it doesnt work like i expect

Any tutorials?

thnx

Offline

#2 2008-08-29 16:36:28

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: Adding Sections To Admin

Until someone with a tut shows up, have a look at the source code of e.g. smd_where_used. The first occurrence of “extension” says “make a new tab in extensions”. Just change that to “admin”.
Please post questions concerning the development of plugins in Plugin Development.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2008-08-29 16:44:26

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: Adding Sections To Admin

Maybe this it’s useful

Offline

#4 2008-09-01 13:48:41

glenelkins2
New Member
Registered: 2008-08-29
Posts: 4

Re: Adding Sections To Admin

Hi

Ok i looked at the smd_where_used and see this as the first piece of code

[code]
if (@txpinterface == ‘admin’) { add_privs(‘smd_wu’,‘1,2’);

// Extensions tab register_tab(‘extensions’, ‘smd_wu’, smd_wu_gTxt(‘smd_wu’)); register_callback(‘smd_wu’, ‘smd_wu’);
}
[/code]

Now I understand that register_tab(‘extensions’, ‘smd_wu’, smd_wu_gTxt(‘smd_wu’)); is what adds the tab. And If i change ‘extensions’ to ‘admin’ it sure enough ads the tab under Admin

But what from here? How do I make a functional page with this? For example, what is “smd_wu” smd_wu_gTxt(“smd_wu” )) what does all that do?

And what does register_callback(‘smd_wu’, ‘smd_wu’); do?

All I want to do is add a tab so i can program in some php code to take values from a specific database table iv created, then display it

thanks

Last edited by glenelkins2 (2008-09-01 13:48:54)

Offline

#5 2008-09-01 13:58:10

glenelkins2
New Member
Registered: 2008-08-29
Posts: 4

Re: Adding Sections To Admin

here look at this quick testing modification iv made:

[code]
if (@txpinterface == “admin” ) { add_privs ( “smd_wu”,“1,2” );

// Subscribers Tab register_tab( “admin”, “smd_wu”, “Subscribers” ); register_callback(‘smd_testing’, ‘smd_wu’); }

function smd_testing ( $event, $step ) { if ( !$step || !in_array ( $step, array (‘smd_wu_search’) ) ) { echo “TESTING”; } else $step();
}
[/code]

Now this works it shows TESTING at the top of the page… but for some reason the rest of the layout including navigation has vanished. All i see is a white page with TESTING then a drop down box saying Go… and then a load of sections

Offline

#6 2008-09-01 14:02:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,453
Website GitHub

Re: Adding Sections To Admin

glenelkins2 wrote:

what is “smd_wu” smd_wu_gTxt(“smd_wu” )) what does all that do?

smd_wu is just the name of the ‘event’ I’m looking for.

The smd_wu_gTxt(‘something’) is just a call to a convenience lookup function (at the very bottom of the code) that translates ‘something’ into a piece of text. If people want to take the plugin and localise it for different languages they only need to edit the text strings in the gTxt() function and not worry about the rest of the code.

And what does register_callback(‘smd_wu’, ‘smd_wu’); do?

That’s the magic part :-) In the URL bar when you click around the admin interface it says things like ?event=files or ?event=admin. That’s what that line is looking for; it associates my plugin (the function smd_wu) with the ?event=smd_wu, which is the name given in the register_tab() call. So every time textpattern visits a page with that matching event, my code gets called.

In your case you’ll want something like:

register_tab('admin', 'your_event', 'My Page, yay!');
register_callback('display_stuff', 'your_event');

function display_stuff() {
  pagetop();
  echo "Hello world";
}

EDIT: I see you have already made progress here. I’ll shut up now :-)
EDIT2: In order to see the header of the page, you’ll need to call pagetop(); cos your code is now the only thing that’s executing for that event. You need to insert the standard bits and pieces around your code. pagetop() is the key part. From memory I think pageend() (or its equivalent) is called automatically for you.
EDIT3: smd_ is my plugin prefix You’ll need to make up your own TLA that’s not been taken and stick to it :-D

Last edited by Bloke (2008-09-01 14:12:59)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB