Location Pages Project | Custom Page Generator Plugin
Version 1.0
Version 1.0
Custom Page Generator Plugin
Built to be the Wordpress companion plugin to the Location Pages Project, this plugin handles the uploading and parsing the page data created by Austin's AI script.
Requirements
- Secure Custom Fields Plugin by Wordpress
- Formatted CSV file with proper layout
(Layout can be provided by plugin's example CSV file)
Prerequisite Procedure
- Install the plugin to the wordpress site
- Using Secure Custom Fields plugin, create two field groups one for the "Location Page" layout and one for the "Service in Location Page" layout.
- All links created will need to be URL Types
- Both should have a field named "video_link"
- "Location Page" should have "service_1", "service_2", and so on for as many service pages that will be created for every location.
- "Location Page" should have Location Rules set, so that it shows if Page Parent = whatever the locations page is called
- "Service in Location Page" should have Location Rules set, so that it shows if Page Type = child & Page Parent does not equal whatever the locations page is called. If other pages will have children and may use the custom fields, it may be beneficial to also exclude those.
- Create a new Beaver Themer Layout for each page type, try to use the same names that were used for the SCF field groups for consistency.
- "Location Page" layout should have location rules of
Page Parent = whatever the locations page is called- When building the page, add a video component set the "Video Type" to embed
- In the code section hit the plus button to the right
- Scroll down to ACF Post Field or the first option under Advanced Custom fields, and click on either the text or connect button
("ACF" may become "SCF" & "Advanced Custom Fields" may become "Secure Custom Fields") - In "Detected Fields" select "Video Link" which you would have created before for both Field Groups
- Similarly, for each service offered, create the links/CTAs to the child pages, using each service_X in the link field per element.
- "Service in Location Page" layout should have location rules of
Page Ancestor = whatever the locations page is called
Exclusion rule of Page Parent = whatever the locations page is called- When building the page, add a video component in the same way that the previous layout would create it.
- "Location Page" layout should have location rules of
Using the Plugin
At a glance
Looking at the main page of the plugin, currently you will see three options.
The first thing you can do is download an example of the format your CSV will need to be on import, Austin's system should automatically match this format so more often than not, you will not need this.
The second thing you can do is "Choose File." Selecting this will open your file browser. The plugin will only accept the CSV format, this is where you will import the CSV containing all of the page data that our AI model will output.
Simply choosing the file does not start any actions within the plugin, that is why you'll need to use the third option, "Upload File."
Preview
Upon uploading the file the plugin will generate a table of all of the pages that will be created.
The table will have headers that correspond to the value that will be uploaded to the database.
The header "Number of Services" behaves a little differently though.
If our clients offer many services, for example 20, it would take up more screen real-estate to display all of the links to those services, both vertically or horizontally. To simplify this I put a counter, so at a glance you can see that there are a certain amount of records. A link is also generated, so that you may click to see the service links within a modal.
The "Content" column also features this link to open a modal, to see how the content would render on the screen.
Creating the pages
Scroll down to the bottom of the page and click the "Create Pages" button. This will begin the insertion process, where the plugin tells the database to add the pages, it also has to ask the databse to look for the parent pages for the relations, and returns the id of the parent to insert into the database.
The page should update and a page header should say, "Pages have been successfully created from the CSV!" from there you should be able to preview any of the pages and see that they have been populated properly.
After the pages have been made
After you have created the pages, you should remove the plugin from the site, do not remove SCF. However, if you forget to remove the plugin, our clients would have to remove some code in order to get it to work without the "@virteom.com" email address.
Not frequently asked but expected questions
I see an error that says "Secure Custom Fields by WordPress.org is required for the Custom Page Creator plugin to work. Please install and activate SCF."
This plugin needs the SCF plugin in order to work, but good news if you click "install" that should be the first plugin to show up. However what the plugin is actually checking for is a function that is part of SCF "get_field" so there is a possibility that the function is renamed or replaced, and that could cause some issues. In that case, try installing an older version of the plugin where the function exists while you give me time to update the plugin so that it will work with newer versions of SCF.
// Check if SCF/ACF is installed and active
function custom_page_creator_check_acf() {
if (!function_exists('get_field')) {
add_action('admin_notices', 'acf_not_installed_notice');
deactivate_plugins(plugin_basename(__FILE__));
}
}
The plugin isn't showing up in the left menu, but it is installed and activated, is something wrong?
Your user account must be your "@virteom.com" email. If you are not logged into the site with an account using your Virteom email address, you must add yourself as a user with an account that uses your Virteom email address. This is setup like this so that our clients can't mass upload pages by themselves. They are free to add as many pages as they want but just not with our in-house plugins.
// Check if the user's email contains '@virteom.com'
if (strpos($current_user->user_email, '@virteom.com') === false) {
// Display a message if the email doesn't contain '@virteom.com'
echo '<div class="wrap"><h1>Access Denied</h1><p>You do not have permission to access this page. Please use a valid Virteom email address.</p></div>';
return; // Stop further execution of the page
}
// Check if the user's email contains '@virteom.com'
if (strpos($current_user->user_email, '@virteom.com') !== false) {
// Add the menu only if the user's email is valid
I added the pages and setup the page layouts correctly, but the links and videos aren't populating, did I do something wrong?
You possibly did. The SCF field groups likely weren't created before page imports. You will have to delete all of the pages and reimport them. If that doesn't work, it is likely you spelled something wrong. The video field name needs to be video_link that is how the plugin writes it. The services need to be service_{number}. The php will not change the fields, it creates them in this function:
// Helper function to update SCF fields or post meta fields for a page
function update_custom_fields($post_id, $page)
{
// Update the video link field (if applicable)
if (!empty($page['video'])) {
update_field('video_link', $page['video'], $post_id);
}
// Update service-related fields
foreach ($page as $key => $value) {
if (strpos($key, 'service_') === 0 && !empty($value)) {
update_field($key, $value, $post_id);
}
}
}
You can see that "video_link" is explicit, and "service_" is attached to a loop appending the iteration to it.
If changing that doesn't help check that the CSV headers match the example CSV that is included in the plugin.
Future Goals
In future updates, I would like to have custom field names set by the user, or the plugin could read existing field names from SCF.
I would also like to have Dynamic CSV header mapping, so that the CSV doesn't need to be so strict to the plugin's current formatting.
I think it might be cool to prompt our AI models to modify content from the plugin, but that would require storing our ChatGPT credentials on each site we use.