I'm putting together a WordPress site for a charity organization which upgrades the look & feel of their existing site. Their existing site had a few PHP scripts and an events database for their project listings and I changed the output so that the script emulates the WordPress UI using:
define( 'WP_USE_THEMES', true );
require_once "wp-load.php";
The site uses the Monarch social plugin to enable sharing and I need to have that work on the emulated project page.
I haven't been able to find what I should include.
I tried adding both of these lines, separately, but they had no affect:
require_once "wp-content/plugins/monarch/monarch.php";
require_once "wp-content/plugins/monarch/core/init.php";
Upon looking at the code and trying to call functions that looked like potential functions to execute it, they resulted in an error or does nothing.
As someone completely unfamiliar with the intricacies of WordPress doing a pro bono favor for a charity organization, I did not realize that page templates could be used as the destination for custom PHP code accessing a non-WordPress database, etc.
The solution steps (which may hopefully help someone else equally unaware of WordPress) are as follows:
Use the page template page as reference to create a page template.
I added my page template to the same location as the theme's page.php template
Then create a page in WordPress and specify its template as the one just created.
Call that new page with whatever parameters after ?xyz=value;abc=etc. as needed
This may be basic for people who live in WordPress but it wasn't immediately clear to me.
Thanks to the comments by #ChrisHaas!
Related
I am trying to understand a bit about how WordPress works in development..
I already created some shortcodes that I can just edit in on my page and some WIdgets that seem to display on every site or blog post that I created...
My question is: What is the general scope of the widgets or plugins in WordPress that I create? I know there are hooks and WordPress API functions to only show them on specific parts of WordPress, e.g on the admin-panel, or just in the widget sidebar of a page...
But are there some good sources about the architecture and scopes of how and where to use your plugins? Are they kind of injected into every page I create on my WP pages? (e.g with enqueue_scripts or so?). It's just a bit too overwhelming for me as a beginner to get a good overview...
And how are those functions from WP API made accessible in my plugin files/folders when I never imported them? I guess it's based on some module technique but no idea how..
It's good to delve your feet into the WordPress (WP) new concept called blocks you can find all the details here: Block Documentation
Creating widgets and shortcodes is a way older process nowadays most people keep their eyes on WordPress Blocks and especially FSE (Full Site Editor) therefore I would suggest you start learning that thing ASAP.
Let's come to your queries:
How WordPress works technically
Go to your WordPress directory you will find the file called index.php which is responsible for bootstrapping your application
Along with the index.php you will find a few directories called
wp-admin
wp-includes
wp-content
wp-admin
Where WP have all functionalities happening in the admin part are executed by accessing classes and functions present inside of this directory
wp-includes
This directory has all the utility and helper classes and functions
wp-content
This is the only directory developer can add/edit the files which store all of your plugins, themes, uploads, and other custom directories if your
code or any other plugin code created
For more details on how WP works
It's quite a challenge to explain all the ins and outs WP in a single post but you can find the detailed explanation in the official documentation
WordPress mainly depends on hooks and hooks are come under any of these two categories:
action hook
filter hook
For more details on WP hooks
How do plugins or themes work?
Both plugins and themes have a terminology called headers using that header metadata WP fills all the details in the plugins listing admin page and in themes listing page
For more details on header
Themes mainly depend on the concept called loops which responsible for fetching the posts data and build the necessary details using template tags and iterate them using the loop. Based on the type of page the user visited WP uses the template hierarchy to render the page as per the request that happened on the client end.
For more details on how WP loops works
For more details on how template hierarchy works
Headless CMS
Yes, you can make your complete WP into a headless CMS with the help of WP REST API. The REST API is used to access WordPress outside of the WP for e.g. if your android app need to fetch any posts or categories or user from WP using this REST API it can do that. Also you can create your custom endpoints too
Additionally, try to explore WP CLI
I believe that I covered most of the things required to understand how WP works, to be clear this post abstracted many of the things to make it as compact as possible for anyone who started entering into the WP development.
If you like to know more of these abstract explanation in a detailed way then always visit the official documentation
If your ide have an auto-complete feature please try to explore all of these functions (wildcard list) which contains most of the security functions provided by WP
is_*
exists_*
validate_*
sanitize_*
esc_*
*kses*
*nonce*
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
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
*/
I am building a plugin for the first time and I have setup my rewrite rules to call a PHP file I have located in my plugin folder and this is working but all I have it output just now is "test"
I wanted to ask, is there is a way of pulling in the existing theme and using this as the basis for the page, then I can have my plugin just output the page content area so to speak.
My plugin is quite big in terms of the amount of data it handles so I would like to be able to use a menu link to the aforementioned file and this file can then output all the sub pages of content but still using the default theme (theme I have made) and fill the content area only is this possible and if so is there anything to explain this already available because I couldn't see it.
Any help with this would be much appreciated.
Edit: I have tried including a file from my current theme but this will give me a 500 error so I assume its not as simple as this.
Have you thought about using custom post types for your plugin content rather than relying on custom tables and separate code?
Other than that, you could use a shortcode (just one) and have users insert that into a regular WP page, the shortcode then displays all of your various plugin stuff.
It's hard to be more specific without understanding why you've done it this way.
im looking easy steps for convert any html/php template into a very simple wordpress theme for personal use. I have a site, in there i want news at the begining using the wordpress interface, i worked a lot with wordpress and i made some themes, but modifing already made ones, so i didnt care a lot about the code.
So, lookin in internet i dint found a good step by step tutorial in order to create a simple theme in wordpress from 0. Remember that i dont need sidebars, widgets and soo, i only need "the loop", or, the last 3 post made.
It's as simple as installing wordpress correctly and then including the wp-blog-header file into your pages. Doing so will give you access to all of WP's functions.
require('/path/to/wp-blog-header.php');
$posts = get_posts('arguments');