2

I have a php script that I'd like to utilize within my wordpress theme. I'd like to restrict access to the page based on users belonging to particular groups so it's important to keep it within wordpress for that reason.

I've tried at least 9 different plugins and the closest one I could find was a plugin that wrapped the code into a unique shortcode to be placed on page. However, the script wasn't functioning as it should. Lastly, it's important that I do NOT display the php code for users to view in page source.

Can this be accomplished and if so, how?

Thanks so much!

3

PHP does not ever display in source, if things are working correctly. PHP executes on the server. If things are working the way they should you never see the PHP source.

I don't know what your conditions are for this project, but the most straightforward way to access a script is to make a custom page template for it.

You would ...

  1. create your template,
  2. add your script to that template,
  3. create a page from the backend
  4. and assign that page to the template you created

The second way to access your script would be to create a shortcode. It sounds like you have already come across this solution but were trying to use a plugin. I expect it was some kind of "execute this PHP" shortcode, which is overly complicated. Creating a shortcode is easy. A bare-bones shortcode would look like:

function bare_bones_sample_shortcode($atts,$content) {
   return "test simple shortcode";
}
add_shortcode('bbss', 'bare_bones_sample_shortcode');

You would then write [bbss] in your post body and "test simple shortcode" should show up. In your case you'd want to put your script in place of that return. The $atts and $content let you do things like `[bbss id="abc"]This is cool content[/bbss]. I don't know enough about your script to write anything more elaborate though.

There may be other ways to trigger that script, such as hooking it to something-- the_content maybe-- but again, without knowing more about the script I can't really elaborate. You could even access it over AJAX.

  • Thank you very much for taking the time to respond to this. I've decided to try our first suggested method. This is all quite new to me but that documentation is great. The script asks the user to enter data, then utilizes an Amazon API to return information. If you forsee any problems with the first method given that information please let me know. I'll update this thread with the result. Thanks again! – Norm May 5 '13 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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