Added Demo posts inserter
This commit is contained in:
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-1.jpg
Normal file
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 723 KiB |
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-2.jpg
Normal file
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 875 KiB |
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-3.jpg
Normal file
BIN
assets/img/demo-post-thumbnails/demo-post-thumbnail-3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 698 KiB |
33
assets/js/demo-posts-import.js
Normal file
33
assets/js/demo-posts-import.js
Normal file
@ -0,0 +1,33 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Check if the button exists before adding the event listener
|
||||
const importButton = document.getElementById('import-demo-posts');
|
||||
if (importButton) {
|
||||
importButton.addEventListener('click', function () {
|
||||
const formData = new FormData();
|
||||
|
||||
// Append action and nonce to the form data
|
||||
formData.append('action', 'lcp_import_demo_posts');
|
||||
formData.append('lcp_import_nonce', lcp_ajax_obj.nonce); // Add the nonce passed by wp_localize_script
|
||||
|
||||
// Send the AJAX request
|
||||
fetch(lcp_ajax_obj.ajax_url, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(data.data); // Success message
|
||||
} else {
|
||||
alert('Error: ' + (data.data || 'Unknown error')); // Error message
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('An error occurred while processing your request.');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.warn('Import button not found.');
|
||||
}
|
||||
});
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Path to your icons.json file
|
||||
$filePath = 'output.json';
|
||||
|
||||
// Read the content of the JSON file
|
||||
$jsonData = file_get_contents($filePath);
|
||||
|
||||
// Decode the JSON data into a PHP array
|
||||
$iconsData = json_decode($jsonData, true);
|
||||
|
||||
// Check if the data is decoded successfully
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
die('Error decoding JSON data: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
// Check if the data contains a 'family' key (indicating it has families with SVGs)
|
||||
if (isset($iconsData[0]['family'])) {
|
||||
// Handle the case with families and svgs (structure 1)
|
||||
foreach ($iconsData as &$family) {
|
||||
if (isset($family['svgs']) && is_array($family['svgs'])) {
|
||||
// Sort the 'svgs' array alphabetically by the 'name' field
|
||||
usort($family['svgs'], function($a, $b) {
|
||||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the families by the 'family' field (if needed)
|
||||
usort($iconsData, function($a, $b) {
|
||||
return strcmp($a['family'], $b['family']);
|
||||
});
|
||||
|
||||
} else {
|
||||
// Handle the case without families (structure 2)
|
||||
// Sort the flat array of icons alphabetically by the 'name' field
|
||||
usort($iconsData, function($a, $b) {
|
||||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
}
|
||||
|
||||
// Encode the sorted data back to JSON
|
||||
$sortedJsonData = json_encode($iconsData, JSON_PRETTY_PRINT);
|
||||
|
||||
// Check if encoding was successful
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
die('Error encoding JSON data: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
// Write the sorted JSON data back to the file
|
||||
if (file_put_contents($filePath, $sortedJsonData)) {
|
||||
echo "The icons data has been sorted and saved successfully!";
|
||||
} else {
|
||||
echo "Error writing the sorted data to the file.";
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Function to generate a UUID (compliant with MySQL UUID)
|
||||
function generateUUID() {
|
||||
return bin2hex(random_bytes(16)); // Generate a random UUID
|
||||
}
|
||||
|
||||
// Function to convert the raw SVG to JSON format
|
||||
function convertSymbolsToJSON($svgContent) {
|
||||
// Match all <symbol> elements and extract them
|
||||
preg_match_all('/<symbol[^>]*>[\s\S]*?<\/symbol>/', $svgContent, $matches);
|
||||
|
||||
$jsonData = [];
|
||||
|
||||
foreach ($matches[0] as $symbol) {
|
||||
// Extract 'id', 'viewBox', and 'path' attributes
|
||||
preg_match('/id="([^"]+)"/', $symbol, $idMatches);
|
||||
preg_match('/viewBox="([^"]+)"/', $symbol, $viewBoxMatches);
|
||||
preg_match('/<path[^>]*d="([^"]+)"/', $symbol, $pathMatches);
|
||||
|
||||
// If we have a valid symbol, process it
|
||||
if (isset($idMatches[1]) && isset($viewBoxMatches[1]) && isset($pathMatches[1])) {
|
||||
// Generate a UUID for the symbol
|
||||
$uniqueId = generateUUID();
|
||||
|
||||
// Capitalize the name by replacing hyphens with spaces and capitalizing each word
|
||||
$name = ucwords(str_replace('-', ' ', $idMatches[1]));
|
||||
|
||||
// Build the symbol JSON object
|
||||
$symbolJSON = [
|
||||
"id" => $uniqueId,
|
||||
"name" => $name,
|
||||
"viewBox" => $viewBoxMatches[1],
|
||||
"path" => "<path d='" . $pathMatches[1] . "'/>"
|
||||
];
|
||||
|
||||
// Add the symbol JSON to the data array
|
||||
$jsonData[] = $symbolJSON;
|
||||
}
|
||||
}
|
||||
|
||||
return $jsonData;
|
||||
}
|
||||
|
||||
// Read the SVG file (assumes it's in the same directory)
|
||||
$svgFilePath = 'input.svg'; // The input SVG file
|
||||
if (file_exists($svgFilePath)) {
|
||||
$svgContent = file_get_contents($svgFilePath);
|
||||
|
||||
// Convert symbols to JSON
|
||||
$symbolsJson = convertSymbolsToJSON($svgContent);
|
||||
|
||||
// Output the JSON data to a file
|
||||
$outputFilePath = 'output.json';
|
||||
file_put_contents($outputFilePath, json_encode($symbolsJson, JSON_PRETTY_PRINT));
|
||||
|
||||
echo "JSON file has been created successfully: $outputFilePath\n";
|
||||
} else {
|
||||
echo "Error: SVG file not found.\n";
|
||||
}
|
||||
?>
|
||||
57
assets/json/demo-posts.json
Normal file
57
assets/json/demo-posts.json
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"posts": [
|
||||
{
|
||||
"title": "Mysterious Weather Patterns Reported in Faketown",
|
||||
"content": "Faketown, USA — In what can only be described as a strange turn of events, Faketown residents have been experiencing unpredictable weather patterns. Local meteorologists have been baffled as sudden temperature shifts have been occurring at all hours of the day. One moment, the sun is shining brightly, and the next, it's snowing. This bizarre occurrence is leaving many questioning whether this is a sign of something more ominous. 'I’ve lived here my entire life, and I’ve never seen anything like this,' said local resident Jane Doe.",
|
||||
"excerpt": "Faketown residents have been experiencing unpredictable weather patterns, baffling local meteorologists.",
|
||||
"category": "Local News",
|
||||
"tags": ["weather", "Faketown", "mystery"],
|
||||
"date": "2025-01-01",
|
||||
"status": "publish",
|
||||
"thumbnail": "demo-post-thumbnail-1.jpg"
|
||||
},
|
||||
{
|
||||
"title": "Faketown Mayor Announces New Green Initiative",
|
||||
"content": "In a recent press conference, Faketown’s mayor, John Smith, unveiled an ambitious plan to tackle climate change within the city. The initiative aims to reduce carbon emissions by 40% over the next 10 years, primarily by encouraging the use of electric vehicles and expanding the city's public transportation system. 'We are committed to making Faketown a greener place,' said Mayor Smith. 'Our children and grandchildren deserve a sustainable future.' The plan includes installing charging stations for electric cars across the city and offering tax incentives for green energy solutions.",
|
||||
"excerpt": "Faketown’s mayor unveils a new green initiative to reduce carbon emissions by 40%.",
|
||||
"category": "Politics",
|
||||
"tags": ["green", "climate change", "Faketown"],
|
||||
"date": "2025-01-02",
|
||||
"status": "publish",
|
||||
"thumbnail": "demo-post-thumbnail-2.jpg"
|
||||
},
|
||||
{
|
||||
"title": "Local Chef Opens Revolutionary Restaurant in Faketown",
|
||||
"content": "Faketown, USA — In a culinary first for Faketown, renowned chef Sarah Bellamy has opened a new restaurant that combines traditional American cuisine with exotic flavors from around the world. Located in the heart of Faketown, Bellamy’s restaurant has already become the talk of the town. The menu features a variety of dishes, including 'Fusion Fries' and 'Sushi Burger.' 'I wanted to create something completely unique, a blend of cultures,' said Bellamy. The restaurant offers both dine-in and delivery services, with plans to expand its menu soon.",
|
||||
"excerpt": "Faketown's new restaurant is offering a fusion of global flavors with a local twist.",
|
||||
"category": "Food & Drink",
|
||||
"tags": ["restaurant", "food", "Faketown"],
|
||||
"date": "2025-01-03",
|
||||
"status": "publish",
|
||||
"thumbnail": "demo-post-thumbnail-3.jpg"
|
||||
},
|
||||
{
|
||||
"title": "Strange Creatures Spotted in Faketown's Forests",
|
||||
"content": "In the deep forests surrounding Faketown, local hikers have begun reporting sightings of strange creatures. Descriptions vary, but many claim to have seen large, mysterious beings with glowing eyes. Some hikers have even reported hearing unusual sounds that have no obvious explanation. 'I was out for a hike last week when I saw something huge moving through the trees,' said Greg Johnson, a local resident. 'I don’t know what it was, but it wasn’t a bear.' Authorities are urging hikers to stay on well-trodden paths and report any strange occurrences.",
|
||||
"excerpt": "Faketown residents report strange creatures spotted in nearby forests, baffling experts.",
|
||||
"category": "Strange Happenings",
|
||||
"tags": ["mystery", "Faketown", "creatures"],
|
||||
"date": "2025-01-04",
|
||||
"status": "publish",
|
||||
"thumbnail": "demo-post-thumbnail-1.jpg"
|
||||
|
||||
},
|
||||
{
|
||||
"title": "Faketown's Annual Festival Breaks Attendance Records",
|
||||
"content": "This year's annual Faketown Festival was a resounding success, breaking all previous attendance records. Held in the town square, the festival featured local bands, food trucks, and street performances. The highlight of the event was the traditional 'Faketown Parade,' which saw thousands of people lining the streets. 'We’ve never seen this many people come out,' said event coordinator Lisa Thompson. The festival’s success has sparked excitement about next year’s event, with many suggesting that Faketown could become a regional hub for arts and culture.",
|
||||
"excerpt": "Faketown’s annual festival saw record-breaking attendance, with thousands of people participating.",
|
||||
"category": "Community Events",
|
||||
"tags": ["festival", "community", "Faketown"],
|
||||
"date": "2025-01-05",
|
||||
"status": "publish",
|
||||
"thumbnail": "demo-post-thumbnail-2.jpg"
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Path to the input JSON file
|
||||
$inputFile = 'font-awesome-v6.1.7-solid-svgs.json';
|
||||
|
||||
// Step 1: Load the JSON data
|
||||
$jsonData = file_get_contents($inputFile);
|
||||
|
||||
// Check if the file was read successfully
|
||||
if ($jsonData === false) {
|
||||
die("Error reading the JSON file.");
|
||||
}
|
||||
|
||||
// Step 2: Decode the JSON data into a PHP array
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
// Check if JSON decoding was successful
|
||||
if ($data === null) {
|
||||
die("Error decoding the JSON data.");
|
||||
}
|
||||
|
||||
// Step 3: Modify the structure by extracting the 'd' value and formatting the 'paths' tag
|
||||
foreach ($data as $index => $iconSet) {
|
||||
if (isset($iconSet['svgs']) && is_array($iconSet['svgs'])) {
|
||||
foreach ($iconSet['svgs'] as $svgIndex => $svg) {
|
||||
// Check if 'path' exists
|
||||
if (isset($svg['path'])) {
|
||||
// Extract the 'd' attribute value from the nested path string
|
||||
preg_match('/d=[\'"]([^\'"]+)[\'"]/i', $svg['path'], $matches);
|
||||
|
||||
// If we found the 'd' value, format the paths correctly
|
||||
if (isset($matches[1])) {
|
||||
$dValue = $matches[1]; // Get the actual 'd' value from the path
|
||||
|
||||
// Escape the 'd' value for JSON format (escape double quotes inside the string)
|
||||
$escapedDValue = str_replace('"', '\\"', $dValue);
|
||||
|
||||
// Now, add the proper <path> tag to the 'paths' field
|
||||
$svg['paths'] = "<path d=\"{$escapedDValue}\"/>";
|
||||
}
|
||||
|
||||
unset($svg['path']); // Optionally remove the original 'path' key
|
||||
}
|
||||
// Save the modified svg back to the array
|
||||
$data[$index]['svgs'][$svgIndex] = $svg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: Save the modified JSON to a new file
|
||||
$outputFile = 'solid-fixed-paths.json';
|
||||
file_put_contents($outputFile, json_encode($data, JSON_PRETTY_PRINT));
|
||||
|
||||
// Output the success message
|
||||
echo "Successfully modified and saved the JSON file with 'path' converted to 'paths'.\n";
|
||||
|
||||
?>
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Path to the input JSON file
|
||||
$inputFile = 'material-icons-twotone.json';
|
||||
// Path to the output JSON file
|
||||
$outputFile = 'material-icons-twotone-unescaped-with-ids.json';
|
||||
|
||||
// Function to generate a MySQL-style UUID
|
||||
function generateUUID() {
|
||||
// Generates a version 4 UUID (random)
|
||||
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0x0fff) | 0x4000,
|
||||
mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
|
||||
// Step 1: Load the JSON data
|
||||
$jsonData = file_get_contents($inputFile);
|
||||
|
||||
// Check if the file was read successfully
|
||||
if ($jsonData === false) {
|
||||
die("Error reading the JSON file.");
|
||||
}
|
||||
|
||||
// Step 2: Decode the JSON data into a PHP array
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
// Check if JSON decoding was successful
|
||||
if ($data === null) {
|
||||
die("Error decoding the JSON data.");
|
||||
}
|
||||
|
||||
// Step 3: Iterate through each item and unescape the 'paths' key, and generate a new 'id'
|
||||
foreach ($data as &$icon) {
|
||||
// Unescape only HTML entities (without affecting forward slashes)
|
||||
$icon['paths'] = html_entity_decode($icon['paths'], ENT_QUOTES | ENT_HTML5);
|
||||
|
||||
// Generate a new MySQL-style UUID for each 'id'
|
||||
$icon['id'] = generateUUID();
|
||||
}
|
||||
|
||||
// Step 4: Encode the modified data back into JSON format
|
||||
$newJsonData = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
|
||||
// Check if encoding was successful
|
||||
if ($newJsonData === false) {
|
||||
die("Error encoding the JSON data.");
|
||||
}
|
||||
|
||||
// Step 5: Save the modified JSON data to the output file
|
||||
file_put_contents($outputFile, $newJsonData);
|
||||
|
||||
// Check if file writing was successful
|
||||
if (file_put_contents($outputFile, $newJsonData) === false) {
|
||||
die("Error saving the modified JSON data.");
|
||||
}
|
||||
|
||||
echo "Paths have been unescaped, IDs have been added, and saved to '$outputFile'.\n";
|
||||
|
||||
?>
|
||||
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Function to capitalize the 'name' field (capitalizes acronyms fully)
|
||||
function capitalizeName($name) {
|
||||
// Define a pattern to match acronyms (words in uppercase with no spaces)
|
||||
$acronymPattern = '/\b[A-Z]{2,}\b/';
|
||||
|
||||
// Capitalize each word, and keep acronyms fully uppercase
|
||||
$name = preg_replace_callback('/\b\w+\b/', function ($matches) use ($acronymPattern) {
|
||||
$word = $matches[0];
|
||||
// If it's an acronym (all uppercase), return as is
|
||||
if (preg_match($acronymPattern, $word)) {
|
||||
return strtoupper($word);
|
||||
}
|
||||
// Otherwise capitalize the first letter of each word and lowercase the rest
|
||||
return ucfirst(strtolower($word));
|
||||
}, $name);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
// Function to generate a MySQL UUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
|
||||
function generateMysqlUuid() {
|
||||
// Generate a UUID using PHP's random_bytes for a total of 16 random bytes
|
||||
$data = random_bytes(16);
|
||||
|
||||
// Set the version to 4 (random UUID)
|
||||
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // Version 4
|
||||
// Set the variant to RFC4122
|
||||
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // RFC4122 variant
|
||||
|
||||
// Now unpack the data into 5 parts for formatting as UUID
|
||||
$hexData = unpack('H8a/H4b/H4c/H4d/H12e', $data);
|
||||
|
||||
// Return the UUID in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
return $hexData['a'] . '-' . $hexData['b'] . '-' . $hexData['c'] . '-' . $hexData['d'] . '-' . $hexData['e'];
|
||||
}
|
||||
|
||||
// Get the current directory of the script
|
||||
$currentDir = __DIR__;
|
||||
|
||||
// Get all JSON files in the current directory
|
||||
$jsonFiles = glob($currentDir . '/*.json');
|
||||
|
||||
// Iterate over each JSON file
|
||||
foreach ($jsonFiles as $file) {
|
||||
// Read the content of the file
|
||||
$jsonContent = file_get_contents($file);
|
||||
|
||||
// Decode JSON to array
|
||||
$data = json_decode($jsonContent, true);
|
||||
|
||||
// Check if the data is valid
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
// Process each SVG object
|
||||
foreach ($data as &$set) {
|
||||
if (isset($set['svgs'])) {
|
||||
foreach ($set['svgs'] as &$svg) {
|
||||
// Capitalize the 'name' field
|
||||
if (isset($svg['name'])) {
|
||||
$svg['name'] = capitalizeName($svg['name']);
|
||||
}
|
||||
|
||||
// Generate a new MySQL UUID for the 'id' field
|
||||
if (isset($svg['id'])) {
|
||||
$svg['id'] = generateMysqlUuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-encode the modified data to JSON
|
||||
$newJsonContent = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
// Define the output file name (you can change this as needed)
|
||||
$outputFile = $currentDir . '/modified_' . basename($file);
|
||||
|
||||
// Save the updated content back to a new file
|
||||
file_put_contents($outputFile, $newJsonContent);
|
||||
|
||||
echo "Processed and saved to: " . basename($outputFile) . "\n";
|
||||
} else {
|
||||
echo "Invalid JSON in file: " . basename($file) . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
192
functions.php
192
functions.php
@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
include get_template_directory() . '/includes/classes/wp-hooks.php';
|
||||
include get_template_directory() . '/includes/classes/lcp-newsletters.php';
|
||||
|
||||
|
||||
//include get_template_directory(). '/includes/blocks/lcp-gallery/lcp-gallery.php';
|
||||
include get_template_directory() . '/includes/classes/blocks.php';
|
||||
@ -49,10 +49,19 @@ function lcp_backend_enqueue() {
|
||||
// Enqueue the theme's main stylesheet (style.css)
|
||||
wp_enqueue_style('lcp-style', get_stylesheet_uri());
|
||||
wp_enqueue_script('lcp-script', get_template_directory_uri() . '/script.js');
|
||||
wp_enqueue_script('lcp-ui', get_template_directory_uri() . '/assets/js/lcp-ui.js');
|
||||
|
||||
// Enqueue custom script to handle the Demo post import AJAX request
|
||||
wp_enqueue_script('lcp-import-demo-posts-ajax', get_template_directory_uri() . '/assets/js/demo-posts-import.js', array(), null, true);
|
||||
|
||||
// Add the AJAX URL and nonce as JavaScript variables
|
||||
wp_localize_script('lcp-import-demo-posts-ajax', 'lcp_ajax_obj', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php'), // This is the URL that we’ll send the AJAX request to
|
||||
'nonce' => wp_create_nonce('lcp_import_demo_posts_nonce') // Security nonce for validation
|
||||
));
|
||||
}
|
||||
|
||||
add_action('admin_enqueue_scripts', 'lcp_enqueue');
|
||||
add_action('admin_enqueue_scripts', 'lcp_backend_enqueue');
|
||||
|
||||
|
||||
/* KEY POINTS */
|
||||
@ -180,26 +189,26 @@ function drop_lcp_icons_table() {
|
||||
|
||||
/* BACKEND ICON ADDER */
|
||||
// Register the dashboard page in the admin menu
|
||||
function mytheme_register_dashboard_page() {
|
||||
function lcp_register_dashboard_page() {
|
||||
add_menu_page(
|
||||
'Icon Management', // Page Title
|
||||
'Icon Management', // Menu Title
|
||||
'manage_options', // Capability
|
||||
'icon-management', // Menu Slug
|
||||
'mytheme_dashboard_page', // Callback function
|
||||
'lcp_dashboard_page', // Callback function
|
||||
'dashicons-images-alt2', // Icon for the menu item
|
||||
60 // Position
|
||||
);
|
||||
}
|
||||
add_action('admin_menu', 'mytheme_register_dashboard_page');
|
||||
add_action('admin_menu', 'lcp_register_dashboard_page');
|
||||
|
||||
// Callback function to display the dashboard page content
|
||||
function mytheme_dashboard_page() {
|
||||
function lcp_dashboard_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e('Icon Management Dashboard', 'mytheme'); ?></h1>
|
||||
<h1><?php esc_html_e('Icon Management Dashboard', 'lcp'); ?></h1>
|
||||
<div id="icon-dashboard-container">
|
||||
<?php mytheme_display_icon_sets(); ?>
|
||||
<?php lcp_display_icon_sets(); ?>
|
||||
</div> <!-- This will be populated by PHP -->
|
||||
</div>
|
||||
<?php
|
||||
@ -207,7 +216,7 @@ function mytheme_dashboard_page() {
|
||||
|
||||
// Function to read and display icon sets from the JSON file
|
||||
// Function to read and display icon sets from the JSON file
|
||||
function mytheme_display_icon_sets() {
|
||||
function lcp_display_icon_sets() {
|
||||
// Path to the JSON file
|
||||
$json_path = get_template_directory() . '/assets/json/icons/icon-definitions.json';
|
||||
|
||||
@ -238,16 +247,16 @@ function mytheme_display_icon_sets() {
|
||||
|
||||
|
||||
// Enqueue the dashboard styles only on the icon-management page
|
||||
function mytheme_enqueue_dashboard_styles($hook) {
|
||||
function lcp_enqueue_dashboard_styles($hook) {
|
||||
|
||||
|
||||
// Enqueue CSS for the dashboard
|
||||
wp_enqueue_style(
|
||||
'mytheme-dashboard-css',
|
||||
'lcp-dashboard-css',
|
||||
get_template_directory_uri() . '/assets/css/dashboard.css'
|
||||
);
|
||||
}
|
||||
add_action('admin_enqueue_scripts', 'mytheme_enqueue_dashboard_styles');
|
||||
add_action('admin_enqueue_scripts', 'lcp_enqueue_dashboard_styles');
|
||||
|
||||
|
||||
// Handle the AJAX request for installing icon sets
|
||||
@ -311,7 +320,7 @@ function lcp_install_icon_set($defaults = false) {
|
||||
$icon_set_id = intval($_POST['icon_set_id']);
|
||||
|
||||
// Create the database table if it doesn't exist
|
||||
mytheme_create_icons_table();
|
||||
lcp_create_icons_table();
|
||||
|
||||
// Read the icon definitions JSON file
|
||||
if (file_exists($json_path)) {
|
||||
@ -384,7 +393,7 @@ add_action('wp_ajax_install_icon_set', 'lcp_install_icon_set');
|
||||
|
||||
|
||||
// Function to create the icons table in the database if it doesn't exist
|
||||
function mytheme_create_icons_table() {
|
||||
function lcp_create_icons_table() {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'lcp_icons';
|
||||
@ -409,7 +418,7 @@ function mytheme_create_icons_table() {
|
||||
}
|
||||
|
||||
|
||||
function mytheme_enqueue_dashboard_scripts($hook) {
|
||||
function lcp_enqueue_dashboard_scripts($hook) {
|
||||
// Only load the script on the icon-management page
|
||||
|
||||
|
||||
@ -423,15 +432,15 @@ function mytheme_enqueue_dashboard_scripts($hook) {
|
||||
);
|
||||
|
||||
// Pass the AJAX URL to the script
|
||||
wp_localize_script('icon-import-script', 'mytheme_ajax', array(
|
||||
wp_localize_script('icon-import-script', 'lcp_ajax', array(
|
||||
'ajax_url' => admin_url('admin-ajax.php')
|
||||
));
|
||||
}
|
||||
add_action('admin_enqueue_scripts', 'mytheme_enqueue_dashboard_scripts');
|
||||
add_action('admin_enqueue_scripts', 'lcp_enqueue_dashboard_scripts');
|
||||
|
||||
|
||||
// Handle the AJAX request for uninstalling icon sets
|
||||
function mytheme_uninstall_icon_set() {
|
||||
function lcp_uninstall_icon_set() {
|
||||
// Ensure icon set ID is passed in the request
|
||||
if (!isset($_POST['icon_set_id'])) {
|
||||
wp_send_json_error(array('message' => 'Invalid icon set ID.'));
|
||||
@ -460,6 +469,151 @@ function mytheme_uninstall_icon_set() {
|
||||
}
|
||||
}
|
||||
|
||||
add_action('wp_ajax_uninstall_icon_set', 'mytheme_uninstall_icon_set');
|
||||
add_action('wp_ajax_uninstall_icon_set', 'lcp_uninstall_icon_set');
|
||||
|
||||
/* Import Demo Posts */
|
||||
function lcp_import_demo_posts() {
|
||||
$json_data = file_get_contents(get_template_directory() . '/assets/json/demo-posts.json');
|
||||
|
||||
// Check if the JSON data is successfully fetched and decoded
|
||||
if (empty($json_data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$posts = json_decode($json_data, true)['posts'];
|
||||
|
||||
if (empty($posts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrays to store post IDs and media (thumbnail) IDs
|
||||
$post_ids = [];
|
||||
$media_ids = [];
|
||||
|
||||
foreach ($posts as $post) {
|
||||
// Prepare post data
|
||||
$post_data = array(
|
||||
'post_title' => wp_strip_all_tags($post['title']),
|
||||
'post_content' => $post['content'],
|
||||
'post_excerpt' => isset($post['excerpt']) ? $post['excerpt'] : '',
|
||||
'post_status' => isset($post['status']) ? $post['status'] : 'draft', // Default to 'draft' if no status
|
||||
'post_date' => isset($post['date']) ? $post['date'] : current_time('mysql'),
|
||||
'post_type' => 'post',
|
||||
'post_author' => 1, // Change if you have specific user IDs
|
||||
);
|
||||
|
||||
// Insert the post into the database
|
||||
$post_id = wp_insert_post($post_data);
|
||||
|
||||
// If there was an issue inserting the post, skip this one
|
||||
if (is_wp_error($post_id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store the post ID in the array
|
||||
$post_ids[] = $post_id;
|
||||
|
||||
// Assign categories (if they exist)
|
||||
if (!empty($post['category'])) {
|
||||
$category = term_exists($post['category'], 'category');
|
||||
if ($category) {
|
||||
wp_set_post_terms($post_id, array($category['term_id']), 'category');
|
||||
} else {
|
||||
// If category doesn't exist, create it
|
||||
$category_id = wp_create_term($post['category'], 'category');
|
||||
wp_set_post_terms($post_id, array($category_id['term_id']), 'category');
|
||||
}
|
||||
}
|
||||
|
||||
// Assign tags (if they exist)
|
||||
if (!empty($post['tags'])) {
|
||||
wp_set_post_terms($post_id, $post['tags'], 'post_tag');
|
||||
}
|
||||
|
||||
// Handle thumbnail (featured image)
|
||||
if (!empty($post['thumbnail'])) {
|
||||
$thumbnail_url = get_template_directory_uri() . '/assets/img/demo-post-thumbnails/' . $post['thumbnail'];
|
||||
|
||||
// Download the image and add it to the media library
|
||||
$thumbnail_id = media_handle_sideload(
|
||||
array(
|
||||
'name' => basename($thumbnail_url),
|
||||
'tmp_name' => download_url($thumbnail_url)
|
||||
),
|
||||
$post_id
|
||||
);
|
||||
|
||||
// If the image was uploaded successfully, set it as the post's featured image
|
||||
if (!is_wp_error($thumbnail_id)) {
|
||||
set_post_thumbnail($post_id, $thumbnail_id);
|
||||
// Store the media ID in the array
|
||||
$media_ids[] = $thumbnail_id;
|
||||
}
|
||||
}
|
||||
|
||||
// You can add additional meta fields if necessary
|
||||
// Example:
|
||||
// update_post_meta($post_id, 'some_meta_key', 'some_value');
|
||||
}
|
||||
|
||||
// After all posts are imported, update the 'lcp_demo_posts' option
|
||||
$demo_posts_data = array(
|
||||
'post_ids' => $post_ids,
|
||||
'media_ids' => $media_ids,
|
||||
);
|
||||
update_option('lcp_demo_posts', $demo_posts_data);
|
||||
|
||||
// Optionally, you can log the post and media IDs
|
||||
// var_dump($post_ids, $media_ids); // Uncomment this line if you need to inspect the result
|
||||
}
|
||||
|
||||
|
||||
/* Delete the Demo Posts */
|
||||
// Get the lcp_demo_posts option and delete all the posts from there
|
||||
function lcp_delete_demo_posts() {
|
||||
// Get the lcp_demo_posts option
|
||||
$demo_posts_data = get_option('lcp_demo_posts');
|
||||
|
||||
// Check if the option exists and contains data
|
||||
if (!empty($demo_posts_data) && isset($demo_posts_data['post_ids']) && isset($demo_posts_data['media_ids'])) {
|
||||
// Loop through and delete posts
|
||||
foreach ($demo_posts_data['post_ids'] as $post_id) {
|
||||
// Delete post, force delete if necessary (set true for delete permanently)
|
||||
wp_delete_post($post_id, true); // true will permanently delete
|
||||
}
|
||||
|
||||
// Loop through and delete media (attachments)
|
||||
foreach ($demo_posts_data['media_ids'] as $media_id) {
|
||||
// Delete attachment (media file)
|
||||
wp_delete_attachment($media_id, true); // true will permanently delete
|
||||
}
|
||||
|
||||
// After deletion, remove the option from wp_options table
|
||||
delete_option('lcp_demo_posts');
|
||||
|
||||
// Optionally, you can log the deletion for confirmation
|
||||
// error_log('Demo posts and media have been deleted.');
|
||||
} else {
|
||||
// If the option doesn't exist, or it's empty
|
||||
error_log('No demo posts data found or already deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Localize */
|
||||
add_action('wp_ajax_lcp_import_demo_posts', 'lcp_import_demo_posts_ajax_handler');
|
||||
|
||||
// Define the function to handle the AJAX request
|
||||
function lcp_import_demo_posts_ajax_handler() {
|
||||
// Check for permissions (optional: can be used to ensure only admins can trigger this)
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error('You do not have sufficient permissions to perform this action.');
|
||||
}
|
||||
|
||||
// Call the existing function that imports the demo posts
|
||||
lcp_import_demo_posts();
|
||||
|
||||
// Send a success response back to the browser
|
||||
wp_send_json_success('Demo posts imported successfully.');
|
||||
}
|
||||
|
||||
|
||||
@ -247,6 +247,7 @@ function render_lcp_theme_settings_page() {
|
||||
<li class="tab-link active" data-tab="custom-meta">Custom Meta</li>
|
||||
<li class="tab-link" data-tab="icons">Icons</li>
|
||||
<li class="tab-link" data-tab="custom-code">Custom Code</li>
|
||||
<li class="tab-link" data-tab="misc">Miscellaneous</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab Panes -->
|
||||
@ -258,7 +259,7 @@ function render_lcp_theme_settings_page() {
|
||||
<?php
|
||||
// Output necessary settings fields for the 'Icons' tab
|
||||
// This outputs all the fields defined by add_settings_field
|
||||
mytheme_display_icon_sets();
|
||||
lcp_display_icon_sets();
|
||||
?>
|
||||
|
||||
|
||||
@ -300,6 +301,14 @@ function render_lcp_theme_settings_page() {
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="misc" class="tab-pane">
|
||||
<!-- Misc Settings -->
|
||||
<h2>Miscellaneous Settings</h2>
|
||||
|
||||
<!-- Button to trigger the AJAX import demo posts -->
|
||||
<button id="import-demo-posts" class="button button-primary">Import Demo Posts</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
1
parts/footer.html
Normal file
1
parts/footer.html
Normal file
@ -0,0 +1 @@
|
||||
<!-- wp:pattern {"slug":"twentytwentyfive/footer"} /-->
|
||||
1
parts/header.html
Normal file
1
parts/header.html
Normal file
@ -0,0 +1 @@
|
||||
<!-- wp:pattern {"slug":"twentytwentyfive/header"} /-->
|
||||
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Title: Viewport With Sidecontent
|
||||
* Slug: localcontentpro/viewport-with-sidecontent
|
||||
* Categories: banner
|
||||
* Description: A viewport with side content
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Local_Content_Pro
|
||||
* @since Local Content Pro 1.0
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
Theme Name: Local Content Pro
|
||||
Theme URI: https://localcontentpro.com
|
||||
Description: A simple Block Theme for local content publishers.
|
||||
Version: 1.0
|
||||
Version: 0.0.1
|
||||
*/
|
||||
|
||||
/* Main viewport container */
|
||||
|
||||
@ -14,7 +14,8 @@ const excludedDirs = [
|
||||
'package-lock.json',
|
||||
'theme.zip',
|
||||
'.git',
|
||||
'react'
|
||||
'react',
|
||||
'zip-theme.js'
|
||||
];
|
||||
|
||||
// Helper function to check if a file or directory should be excluded
|
||||
|
||||
Reference in New Issue
Block a user