admin管理员组

文章数量:1122826

I am updating our website for a Membership based organisation in which I volunteer, and we would like to streamline the sign-up process, which has been essentially totally manual/paper-based until now. I am new to WordPress, but just need to implement one semi-complex function to greatly improve the site.

Depending on the month of year, we categorise our Members into different subscriptions/Membership years -- so anyone joining in June becomes a "June Member" and is billed every end of June.

Our payment processing partner has fixed URLs for the twelve different Membership years to which Members can sign up. So, presently, we manually issue the correct one to Members.

Naturally, what I would love is if there were one Sign Up button on our website, where prospective members would click, and then this would direct them to the correct fixed link for our payment processor, depending on the month of the year. Anyone pressing the button in June gets redirected to the June sign up URL, anyone pressing the button in July gets redirected to the July sign up URL, etc.

Is it possible to have this sort of dynamic set up on a Wordpress site?

I am unsure where to start. I've read a bit about putting a PHP script in, which can pull the date and then redirect somehow, e.g.

<?php

date_default_timezone_set('Europe/London');
$month = date('m');

if($month == "01" // January
){header("Location: januaryurl");
exit();
}

elseif(
$month == "02" // February
){header("Location: februaryurl");
exit();
}

?>

but I don't know beyond that where to start...

Apologies and thanks from someone who is a little out of their depth!

I am updating our website for a Membership based organisation in which I volunteer, and we would like to streamline the sign-up process, which has been essentially totally manual/paper-based until now. I am new to WordPress, but just need to implement one semi-complex function to greatly improve the site.

Depending on the month of year, we categorise our Members into different subscriptions/Membership years -- so anyone joining in June becomes a "June Member" and is billed every end of June.

Our payment processing partner has fixed URLs for the twelve different Membership years to which Members can sign up. So, presently, we manually issue the correct one to Members.

Naturally, what I would love is if there were one Sign Up button on our website, where prospective members would click, and then this would direct them to the correct fixed link for our payment processor, depending on the month of the year. Anyone pressing the button in June gets redirected to the June sign up URL, anyone pressing the button in July gets redirected to the July sign up URL, etc.

Is it possible to have this sort of dynamic set up on a Wordpress site?

I am unsure where to start. I've read a bit about putting a PHP script in, which can pull the date and then redirect somehow, e.g.

<?php

date_default_timezone_set('Europe/London');
$month = date('m');

if($month == "01" // January
){header("Location: januaryurl");
exit();
}

elseif(
$month == "02" // February
){header("Location: februaryurl");
exit();
}

?>

but I don't know beyond that where to start...

Apologies and thanks from someone who is a little out of their depth!

Share Improve this question asked May 20, 2024 at 20:51 henreeteehenreetee 1033 bronze badges 2
  • 1 Is there any sort of pattern to the URLs? – Chris Cox Commented May 21, 2024 at 9:48
  • @ChrisCox sadly not. The stem is all the same but the final string is just random but fixed letters. – henreetee Commented May 29, 2024 at 15:50
Add a comment  | 

1 Answer 1

Reset to default 1

There are probably several ways to solve this. Here is a general outline of what popped into my mind first.

  • Create a custom plugin to house your custom feature code and to make it independent of the used theme
  • Register a custom admin menu page to serve as a settings page
  • Register a custom setting, displayed on the above page, for storing the current registration link and to allow manual override/fixing
  • Schedule a cron action to update the above setting automatically - this could be a monthly or even a daily check
  • Create a helper function to return the registration url from the setting for reuseability
  • Create a shortcode or a dynamic block for rendering the sign up button, which uses the above helper function for getting the url

If you want to make the redirect look more WordPress-y, then you could use wp_redirect(), which is a wrapper for header() with status code and X-Redirect-By added.

Personally I wouldn't write a code which computes the correct url again and again on every page load as that is a waste of resources in my opinion. Especially as the url is the same for a month at a time.

But if you want to determine the url every time, then I'd would use an array to serve as a map and pull the correct url out of it with an array key. Something along these lines.

$current_month = (int) date('n');
$monthly_urls = array(
    1 => 'januaryurl',
    2 => 'februaryurl',
    // ...
);

$this_months_url = $monthly_urls[$current_month];

本文标签: dateCoding a button linking to an external site that changes monthly