Comments (9)
Alright, this depends on some careful cooperation of the WordPressIgniter settings and CodeIgniter's config/routes.php settings. Since both WordPress and CodeIgniter each have their own 404 handling methods, they both need some attention. In the plugin settings, there are two checkboxes: "Divert 404s to WordPressIgniter" and "CodeIgniter grabs all SEO urls (use with caution!!)".
"Divert 404s to WordPressIgniter" UNCHECKED:
Any url that WordPress can't resolve gets the WordPress 404 page rendered out, even if it was a valid CodeIgniter url. If it was a valid CodeIgniter url, that CodeIgniter url and route gets executed normally, but the user is still shown the WordPress 404 page, whatever it may be in the configured template, etc.
"Divert 404s to WordPressIgniter" CHECKED:
Any url that WordPress can't resolve gets the CodeIgniter output rendered out using the configured Page Override page.
"CodeIgniter grabs all SEO urls" UNCHECKED:
The plugin caches the contents of $_SERVER['REQUEST_URI']
and temporarily sets it to '/' to force CodeIgniter to load its default controller and index function. By default this is 'welcome/index'. CodeIgniter's routing is doing practically nothing in this case. Using this setting unchecked makes CodeIgniter pretty useless unless you have everything happening in the default controller's index function, or maybe you're doing routing with the url parameters the old fashioned way etc.
"CodeIgniter grabs all SEO urls" CHECKED:
Here's where things get the most useful. But, you must have a sort of a "do nothing" 404 override set in your config/routes.php. This function will get called every time a WordPress post, category, or anything is accessed by a SEO url. If you have this setting checked, but no $route['404_override'] set, then CodeIgniter's 404 page will show even on valid WordPress urls (because they're not valid CodeIgniter urls!!).
Sorry if I'm not good at explaining, some of this you're probably going to need to experiment with yourself, but trust me I've spent many long hours with lots of different methods to arrive at what we have now. Probably the bottom line understanding is that when the plugin is enabled, CodeIgniter ALWAYS runs. Depending on those two settings described above, and the configuration in config/routes.php, CodeIgniter WILL do one of these 4 things:
- Run the default controller and function set by $route['default_controller']
- Run the controller and function determined by the url path.
- Run the "catch all" controller and function set by $route['404_override']
- Show its own 404 error, completely overriding WordPress
Again, with this plugin enabled, CodeIgniter WILL do one of the 4 things above, even if its output isn't rendered out to the user. This theoretically can result in some special circumstances. Say you have a path collision, perchance that you have a CodeIgniter controller and method (or custom route) that responds to /categories/uncategorized . The specific CI controller and method will run, even though WordPress renders out its own category view. This is for two reasons: 1. It wasn't a WordPress 404 and 2. It wasn't a CodeIgniter 404. So just be careful to avoid this kind of CodeIgniter routing collisions (unless you really intended it).
from wordpressigniter.
Hey Dan
thanks for the explanation, and for the good job. I will expriment those options carefully later.
cheers
from wordpressigniter.
Dear Dan,
Thank you for the great plug-in. I just wanted to inform you of a bug:
I created the controll sum.php that has the function my_sum($a,$b)
I wanted to try to call a controller with parameters .
I called it from the url: http://localhost/wp/sum/my_sum/1/2/
I got the result that is shown in the image
It shows that it throws an < h1 > tag with the word wordpressigniter in it
Source code that being rendered by the browser is like the following:
< h1 class="entry-title">WordPressIgnition!
But thank you for the nice plug-in
from wordpressigniter.
Thanks for this great plugin, just working my way through the code.
Some useful tips for anyone wanting to use this.
- All WordPress functions, hooks and filters are available to you in your Codeigniter Controllers and Models.
- You can use either or both $db (need to setup your database ci config as usual) and $wpdb ( global $wpdb). Really handy if you want to keep database code in two tables.
- You must remove headers and footers in you ci views ( use the wordpress template system ).
- You can enqueue scripts through either your wp theme or CI app.
from wordpressigniter.
Dear Dan,
Great job!
could you please help us to understand what do you mean when you say "have a sort of a "do nothing" 404 override".
How can do that?
How can redirect the WP URL to WP?
Thank you very much.
from wordpressigniter.
How did you manage to use wordpress functions in CI, i tired calling them directly , they do not generate an error but i have no output.
Any help on this would be highly appreciated.
thx
Hakim
from wordpressigniter.
It could be a problem with output buffering. I tend to use logging to tackle this kind of problem. Can you write something to a log to see what the functions are doing, i.e. by assigning their return value to a $variable and then echoing it to a log? I know your hosting may not give you very ready access to the logs but I depend heavily on logging in most aspects of my work. :)
from wordpressigniter.
Think of CodeIgniter always running even if it's not a match for the currently loading page in WordPress. It will throw its own internal 404 error on every page that doesn't match a CodeIgniter route. You just won't see anything on pages that WordPressIgniter doesn't catch as a CI-integrated page. I'm more comfortable knowing exactly where CodeIgniter's execution path will go in those situations so I like to use a "catch all, do nothing 404 page".
from wordpressigniter.
You are probably echoing the function's output. Try assigning the function's return value to the $CI_OUTPUT global variable. (Remember to say global $CI_OUTPUT
in your function.)
from wordpressigniter.
Related Issues (12)
- management session HOT 5
- How to use WP function inside CI Controller or CI View HOT 4
- is possibel wpigniter preventing wp to send a lost password message?
- Question about the installation.
- $CI_USER always returns NULL and is_admin() function always returns false :( HOT 1
- How to remove the standart title HOT 3
- Provide an example of routes file HOT 4
- Register Shortcode HOT 1
- Access WP session variable in CI HOT 4
- Facebook Share Issue HOT 4
- Does this Plugin work with CI version 3.0 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpressigniter.