Have created a custom template page on my wordpress file folder through cpanel named user-dashboard and it includes 5 files on .php so, how do I make sure that every guest accessing any page on user-dashboard folder (e.g user-dashboard/settings.php) will be redirected to example.com/login and login wordpress account.
after your page creation process complete you add the below lines in function.php file
function user_default_page() {
return '/user-dashboard';
}
add_filter('login_redirect', 'user_default_page');
One more thing is set your page can view after session set and your page path should equal of return path.
Related
is_user_logged_in()
I am trying to track if user is logged in or not, but above code only works if I will open my wordpress admin panel, is there any possible ways to check if user is logged in but not necessary he need to open his admin panel as well.
Try to wrap your code inside init action.
add_action('init', 'bks_run_code');
function bks_run_code()
{
$logged_in = is_user_logged_in();
}
You need to make sure that wp functions are loaded and then you actually run the code you want. You can call other function inside bks_run_code().
The code goes inside your functions.php file of your theme(child theme)
How can I redirect to another directory view
I have two directories in views directory as
views->
public->
login.php
admin->
admin_panel.php
in the controller, I want to redirect page if successful then
admin->adminpanel.php
else
public->login
if($this->form_validation->run()){
$this->load->view('admin/admin_panel');
}
else{
$this->load->view('public/admin_login');
}
You would do something like:
if($this->form_validation->run()){
// redirect to admin panel controller
redirect('admin/admin_panel', 'refresh');
}
// load this pages views
$this->load->view('public/header_view');
$this->load->view('public/admin_login_view');
$this->load->view('public/footer_view');
The redirect stops execution of the current controller so no need for an else statement here.
You should only code your header or footer or any common block once (except your admin panel will probably have it's own different header view file). You can then chain your load view calls to create a page of any layout re using blocks used on other pages if required.
The 'refresh' in the redirect just means that the url will also change as if the user had actually clicked a link with that url on it. Without it the original form_post url will show.
Hope that helps,
Paul.
First I place header and footer inside admin_panel.php
admin->admin_panel.php
<?php include('../public/public_header.php');?>
<h5 class="lead">Admin Panel</h5>
<?php include('../public/public_footer.php');?>
now I remove the header and footer line from above file
and put this in Controller file
if($this->form_validation->run()){
$this->load->view('public/public_header');
$this->load->view('admin/admin_panel');
$this->load->view('public/public_footer');
}else{
$this->load->view('public/admin_login');
}
In wordpress how can we use functions like is_user_logged_in(), we can use this function in any page like header.php , sidebar.php
In wordpress page we are making a form which will be submitted using ajax. Suppose we are gatering form's data on a page 'submitform.php' whose url is www.mysite.com/submitform.php which is totally a custom page.
Now how will I be able to know using is_user_logged_in(); function whether user is logged in or not. because submitform.php is a simple page outside wordpress.
At the top of your custom PHP file, use the following to load WordPress core functionality. This assumes your file is in the root of the installation:
define('WP_USE_THEMES', false);
require('wp-blog-header.php');
I send a special url to my users who want to register on my wordpress website. So, I want to send them a url with a variable invited=true appended in it like: http://example.com/wp-login.php?action=register&invited=true so that only those who have this url can register otherwise they are redirected to main page.
So if invited=true is in the url of registration page then go ahead, otherwise redirect to main website page. like:
if (!isset(GET('invited'))
redirect $website_name;
if (GET('invited') != true)
redirect $website_name;
//go ahead with the rest of the registration page code
where do I put this validation code? and what is the variable in WordPress for website name? so that I can put it in redirect instead of hard coding my website domain.
Please do not worry if someone else uses the url with variable, that is not an issue.
If you are using a theme you "own", like a custom theme or a childtheme, you can hook this function to the login_head hook from your themes functions.php:
https://codex.wordpress.org/Plugin_API/Action_Reference/login_head
If you don't "own" the theme, this will be overwritten the next time you update and in this case you will be looking at writing a plugin, which is a fair bit more complicated...:
https://codex.wordpress.org/Writing_a_Plugin
Try this code in your theme functions.php:
add_action('init','redirectUrl');
function redirectUrl(){
if($_request['invited'] != true){
$url = 'exampleurl.com';
wp_redirect($url):
}
}
I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";