Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently extending my pagination plugin, after a hint by @toscho. So the plugin will now use the same filters, hooks and arguments as the native wordpress pagination functions.

My problem is that the different wp functions name their arguments ... different.

Example:

This is how you change the text for the "Next" link.

  • wp_link_page() = 'nextpagelink'
  • paginate_links() = 'next_text'

After retrieving the input in the class, I wp_parse_args( $args, $this->defaults ); my arguments and then extract them.

Problem:

When I now allow both 'nextpagelink' & 'next_text' as valid arguments, how would i deal with them? Which would I check first? Do I need to set some priority, so one overrules (if both are set) the other?

Example:

This example shows my dilemmas:

  • Which one has the higher priority? How can I avoid deciding?
  • It's really long code just for deciding what to do with 2 vars.

Code:

if ( $nextpagelink && $next_text ) 
{
    // CASE 1: both are set
    // which one should I take now?
}
elseif ( $nextpagelink )
{
    // CASE 2: only one is set - should this one override the next one?
    // set something
}
elseif ( $next_text )
{
    // CASE 3: only one is set - should this be overridden by the previous one?
    // set
}
else
{
    // CASE 4: none is set - apply default
    // set default
}
share|improve this question

2 Answers 2

up vote 2 down vote accepted

wp_link_pages() and paginate_links() work in different contexts: The first on a single paginated page, the latter on an archive. So is_archive() should be your criterion to decide which text you use, or better: which filter you use in apply_filters().

share|improve this answer
    
Perfect answer. Thanks. +1 –  kaiser May 23 '11 at 11:25

Since both of them need to exist to get in to the first if statement, couldn't you do something like this?

if ( $nextpagelink && $next_text ) {
   // set both variables
}else {
   // set default
}

or if you wanted to only work with one, regardless as to whether the other exists you could do this:

if ( $nextpagelink || $next_text ) {
   if ( $nextpagelink ) {
       // set something
   }

   if ( $next_text ) {
       // set
   }
}else {
   // set default
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.