Is there access a php script on a wordpress theme - php

i have tried to load a flat panel write on PHP i put in a wordpress theme.
for alone the script run great but i want run that on wordpress theme.
problem in them routing. for example:
site/wp-content/themes/admin/dashboard/
site/wp-content/themes/admin/dashboard/sprofile
site/wp-content/themes/admin/dashboard/rprofile
can not access above route.
i think this solve with .htaccess file but don't know how !?
is there any way?!

If you're using wordpress you may want to create a shortcode for your script but, in case you don't want to, you can also use .htaccess with the rewrite module to redirect a url and access your panel.
Here are two examples that I hope will help you:
.htaccess rewrite examples
Shortcode examples

If I understood your situation correctly, you want to run a piece of PHP code which prints stuff inside the page as a feature in your WP theme. Not knowing the details, i can give you a couple of ideas:
If you need to embed that in an existing page (or s a new page itself), you need to create a template/template part and manage it trough wordpress's apis (which includes, as said, shipping it as a template part or a template itself, See codex)
If you need to create a new page with custom logic which is more suitable to be written as a plugin, consider adding a rewrite rule to a custom route (See this section of the codex and take a look at this article)

that is i want
when enter to
site/wp-content/themes/admin/dashboard/login
rewrite to
site/wp-content/themes/admin/dashboard/?url=login
login not static
now i use this to htaccess but don't work :
RewriteRule ^wp-content/themes/bluetheme/dashboard/(.*)$ /subdirectory/wp-content/themes/bluetheme/dashboard?url=$1 [L,NC,QSA]

Don't try cheating on WP, by smuggling your php file in some dir and trying to call it from there, by tweaking .htaccess file and similar. Look for system way to create custom WP page. I.e.
https://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/

Related

Replace user-edit.php page within WordPress admin

I need to replace the page template used for the user-edit.php view within the WordPress admin interface.
I am not looking to change any core files, however I am wanting to create my own user-edit.php to be called instead.
So far I have tried creating the user-edit.php file and placing it in my child theme.
Can this be done with a custom plugin?
The WordPress admin pages don't really use templates in the same way that themes do. So, there isn't really a template to replace.
That being said, here are your options to accomplish replacing the default WordPress user-edit.php page.
[brute force method] straight up replace the core wp-admin/user-edit.php file with your own. I know you already said you don't want to replace core files; I'm just listing this for others who show up here. Obviously, this is not ideal because your file would get overwritten any time you update WordPress.
[server redirect method] you could add the appropriate entry in your site's .htaccess file to redirect calls for https://yourdomain.tld/wp-admin/user-edit.php to your new page/file. Also not ideal because if your site ever switches to a new theme that doesn't have the replacement file, that redirect link would be broken.
[additive method] Leave the existing core/default Users menu alone and just add your own admin menu (via add_menu_page) to include your new page(s). Then, just know that you just have to use that new menu instead of the Users menu. Better, but not ideal either since any links on other admin pages that point to user-edit.php would still point there and take admin users to the old/core page.
[php intercept method] intercept calls to wp-admin/user-edit.php in your theme's php code and load your replacement file instead. This is probably the best method, although not the easiest to pull off. And you have to make sure that your replacement page still allows any plugins to function properly that might also use the user-edit page filters and hooks.
To accomplish #4 [php intercept]:
The first thing the core user-edit.php file does is loads wp-admin/admin.php. That file loads all the relevant admin stuff and eventually hands control back to user-edit.php. But, right BEFORE it does, it fires the action "load-user-edit.php"
So, in your theme's functions.php file, use a function like this to intercept the request and redirect to your file:
function scottfive_override_user_edit(){
require_once( get_template_directory() . '/myadminfiles/user-edit-replacement.php' );
die();
}
add_action( 'load-user-edit.php', 'scottfive_override_user_edit', 1 );
Note that this method replaces the entire file, along with all of its functionality and security. I suggest taking a look at the original core user-edit.php and duplicate the authentication/authorization code to make sure your file is at least as secure as the original.
Happy coding! :D

Wordpress loads wrong template with URL parameters

I have a strange problem with my site. It is a wordpress site working for a while now, and our company started some Adwords campaigns to boost views. Google Adwords adds a gclid parameter to the URL when clicked, and the site is loading another template (the default post template) instead of the template for the homepage.
I'd like to know, where to start searching for the faulthy parts? Any ideas?
Thanks!
PS: Not just the gclid parameter does this, but all other fake parameters too. Strange thing is that only the homepage does this, the other pages with structured URL-s are not doing so. The site uses Visual Composer plugin, if it is important. We tried to solve the problem by .htaccess file, but the redirect causes an error in Analytics tracking of Adwords visitors, so it is not a solution.
Finally, we found a solution!
The theme lacked the front-page.php template for the homepage (read more about wordpress template structure!), so I created it with the correct template HTML code according to the correct layout variable values, and it loads just fine. The URL parameters are not affecting the permalink structure anymore, because now we have a template for the homepage too.
This is better than doing hours of research for redirect- or permalink method workarounds...
if everything fails please use template_redirect hook to load any template you want... template_redirect hook
Also you have to send a 200 OK header there if you simply load file and exit.

URL rewrite for one page

I have a bilingual wordpress site that adds the language subdomain into the URL (e.g., mysite.com/en/first-page/. I am trying to find a simple way (can it be done via the functions.php file?) to rewrite the URL to have it remove the /en/, making the URL mysite.com/first-page/. Is this possible? I've looked at some tuts and a lot of them focus on stuff like archives and categories and I'm not sure they can help me.
Since you asked for a functions.php solution, you may be able to use add_rewrite_rule(). Something like:
add_rewrite_rule('^first-page/?', 'en/first-page/');
If that doesn't work, you should consider adding a rule to .htaccess.

Wordpress - creating custom pages with php code

I need to add few additional pages to my wordpress site.
These pages should not be "part of the site", ie they should not be linked somewhere from the posts and so on.
However, they should have the same header/footer as the rest of the site ( I am using custom theme ). And they should be accessible via url.
The final requirement is, I should be able to code in php.
At the moment, I tried to create a new "Page" in my admin console. And then write some php-code inside. However, all my php code gets commented and since not executed.
I don't think that installing plugins such as Exec-PHP is a good idea, so I am trying to find other solutions.
Any comments/advice/suggestions how to make it?
I would be grateful if you give me some how-to link.
Thank you in advance.
You can use a custom page template in your theme for this and just keep the site empty in the admin panel:
http://codex.wordpress.org/Theme_Development#Custom_Page_Templates
By using Template tag's you can create custom page.
write this code on the top of your php file....
/*
Template Name: Your Template Name
*/

Create a custom wordpress plugin than can be called directly like mydomain.com/mytemplate.php?id=xx

I need to create a template, which is done by now, but i want to call it directly without have to create any page that use my file as the template.
The idea was having a specific template to show some custom information and call it like: http://mydomain.com/mycustomtemplate.php?id=7777
I try to call it like it is and doesn't work... says file or directoy not found
Anyone has a sugestion or been through this?
Thanks i advance!
I think you need to elaborate a little more on this. Is the idea to have a custom template for only certain pages?
Wordpress themes (or templates as you are reffing to them as) don't work in the manner that you are referring to:
http://mydomain.com/mycustomtemplate.php?id=7777
The link above refers to a file outside of the whole Wordpress Theme hierarchy.
Please be more clear on what you are trying to accomplish.
You want to have a template, but no file that actually uses it? You'd need some hack up Wordpress's standard RewriteRules to detect a URL that should use your template and redirect the request somewhere that is aware of the template.
You're basically saying "I want to have a car, but I don't want to actually HAVE a car, how can I have a car?"

Categories