0

I am new to wordpress development and am trying to write a plugin. Following the recommendations in the book Professional Wordpress Plugin Development, I created a test page and placed it in the wordpress root directory. When I include wp-admin/admin.php to test the admin functionality of this plugin, I get routed to the login page. From there, after supplying the appropriate credentials, I get redirected to the same page. If I don't require wp-admin/admin.php this doesn't happen. I don't know where to begin troubleshooting this. Here is the very basic script they recommend:
<?php require('./wp-load.php'); require_once('./wp-admin/admin.php'); ?> <pre> <?php //code to test here var_dump(is_admin()); ?> </pre>
Here is the redirect url that keeps appearing:

http://mysite.com/wp-login.php?redirect_to=http%3A%2F%2Fmysite.com%2Ftest.php&reauth=1

Thanks for any help!

1 Answer 1

1

Plugins don't live in the root directory, and they don't include wp-load.php or the admin.php files directly. Plugins live in the wp-content/plugins directory, and have a specific form of header, and they don't need to include anything because WordPress includes them.

You're doing it the wrong way around, basically. A plugin would not include/require WordPress's files.

Oh, and your code doesn't work because you're trying to include admin files from outside the admin directory, which means that the admin-specific cookies can't be set correctly. There are workarounds, but if you're starting off trying to develop plugins, then this is entirely the wrong approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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