REMOVE Delete unused block and CollectiveAccess API integration files
This commit is contained in:
parent
6fe9f321d0
commit
872d2196ea
|
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
// ##### Blocks Category 🡒 Déclaration de la catégorie de blocks custom
|
||||
function client_add_block_categories($categories)
|
||||
{
|
||||
return array_merge(
|
||||
|
||||
[
|
||||
[
|
||||
'slug' => 'client-blocks',
|
||||
'title' => 'Client Generic Blocks ',
|
||||
'icon' => 'heart',
|
||||
],
|
||||
[
|
||||
'slug' => 'client-pages',
|
||||
'title' => 'Client Specific Page Blocks ',
|
||||
'icon' => 'admin-page',
|
||||
],
|
||||
],
|
||||
$categories
|
||||
);
|
||||
}
|
||||
add_action('block_categories_all', 'client_add_block_categories', 10, 2);
|
||||
|
||||
|
||||
// ##### Blocks 🡒 Déclaration des blocks acf custom
|
||||
|
||||
function acf_custom_client_blocks_init()
|
||||
{
|
||||
if (function_exists('acf_register_block_type')) {
|
||||
|
||||
// // ##### Home 🡒 Hero Section
|
||||
// acf_register_block_type(array(
|
||||
// 'name' => 'home_header',
|
||||
// 'title' => __("Home — Section d'accueil"),
|
||||
// 'description' => __("Brique pour la section d'acccueil"),
|
||||
// 'render_template' => 'template-blocks/home/home_header/home_header.php',
|
||||
// 'category' => 'client-blocks',
|
||||
// 'multiple' => false,
|
||||
// 'mode' => 'auto',
|
||||
// 'align' => 'full',
|
||||
// 'icon' => 'schedule',
|
||||
// 'supports' => array(
|
||||
// 'multiple' => false,
|
||||
// 'align' => ['full'],
|
||||
// 'jsx' => true
|
||||
// ),
|
||||
// // 'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.css',
|
||||
// // 'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.js',
|
||||
// // 'enqueue_assets' => function(){
|
||||
// // wp_enqueue_script( 'latest_articles_js', get_stylesheet_directory_uri() . '/template-parts/blocks/home/latest_articles/latest_articles.js');
|
||||
// // },
|
||||
|
||||
// ));
|
||||
|
||||
// ##### Home 🡒 Latest Articles
|
||||
acf_register_block_type(array(
|
||||
'name' => 'latest_articles',
|
||||
'title' => __("Derniers Articles"),
|
||||
'description' => __("Brique pour afficher les derniers articles publiés sur le site"),
|
||||
'render_template' => 'template-blocks/generics/latest-post-query.php',
|
||||
'category' => 'client-blocks',
|
||||
'multiple' => false,
|
||||
'mode' => 'auto',
|
||||
'align' => 'wide',
|
||||
'icon' => 'schedule',
|
||||
// 'enqueue_style' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.css',
|
||||
// 'enqueue_script' => get_template_directory_uri() . '/template-parts/blocks/testimonial/testimonial.js',
|
||||
// 'enqueue_assets' => function(){
|
||||
// wp_enqueue_script( 'latest_articles_js', get_stylesheet_directory_uri() . '/template-parts/blocks/home/latest_articles/latest_articles.js');
|
||||
// },
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
add_action('acf/init', 'acf_custom_client_blocks_init');
|
||||
|
||||
|
||||
function mywp_register_acf_blocks()
|
||||
{
|
||||
// Check availability of block editor
|
||||
if (!function_exists('register_block_type')) {
|
||||
return;
|
||||
}
|
||||
register_block_type(get_template_directory() . '/template-blocks/home/home-header');
|
||||
}
|
||||
add_action('init', 'mywp_register_acf_blocks');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ##### Blocks style 🡒 Re-enqueue d'un style dans l'éditeur
|
||||
|
||||
|
||||
// function block_newsfeed_add_editor_styles() {
|
||||
// add_editor_style( get_stylesheet_directory_uri() . '/template-parts/blocks/editor.css' );
|
||||
// }
|
||||
// add_action( 'admin_init', 'block_newsfeed_add_editor_styles' );
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* CollectiveAccess API Integration
|
||||
*
|
||||
* This file contains functions to interact with a CollectiveAccess instance via its API.
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to the CollectiveAccess API
|
||||
*
|
||||
* @param string $endpoint The API endpoint to request
|
||||
* @param array $params Query parameters for the request
|
||||
* @param string $method HTTP method (GET, POST, etc.)
|
||||
* @return array|WP_Error Response data or WP_Error on failure
|
||||
*/
|
||||
function carhop_ca_api_request($endpoint, $params = array(), $method = 'GET')
|
||||
{
|
||||
// Base URL of the McCord Museum's CollectiveAccess instance
|
||||
$base_url = 'https://collections.musee-mccord.qc.ca';
|
||||
|
||||
// Build the full URL
|
||||
$url = trailingslashit($base_url) . 'api/' . ltrim($endpoint, '/');
|
||||
|
||||
// Add query parameters if they exist
|
||||
if (!empty($params)) {
|
||||
$url = add_query_arg($params, $url);
|
||||
}
|
||||
|
||||
// Set up the request arguments
|
||||
$args = array(
|
||||
'method' => $method,
|
||||
'timeout' => 30,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
);
|
||||
|
||||
// Make the request
|
||||
$response = wp_remote_request($url, $args);
|
||||
|
||||
// Check for errors
|
||||
if (is_wp_error($response)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Get the response body
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
|
||||
// Decode the JSON response
|
||||
$data = json_decode($body, true);
|
||||
|
||||
// Check if JSON decoding failed
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return new WP_Error('json_decode_error', 'Failed to decode JSON response');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of objects from CollectiveAccess
|
||||
*
|
||||
* @param array $params Query parameters for filtering results
|
||||
* @return array|WP_Error List of objects or WP_Error on failure
|
||||
*/
|
||||
function carhop_ca_get_objects($params = array())
|
||||
{
|
||||
return carhop_ca_api_request('objects', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single object by ID from CollectiveAccess
|
||||
*
|
||||
* @param int $object_id The ID of the object to retrieve
|
||||
* @param array $params Additional query parameters
|
||||
* @return array|WP_Error Object data or WP_Error on failure
|
||||
*/
|
||||
function carhop_ca_get_object($object_id, $params = array())
|
||||
{
|
||||
return carhop_ca_api_request("objects/{$object_id}", $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of collections from CollectiveAccess
|
||||
*
|
||||
* @param array $params Query parameters for filtering results
|
||||
* @return array|WP_Error List of collections or WP_Error on failure
|
||||
*/
|
||||
function carhop_ca_get_collections($params = array())
|
||||
{
|
||||
return carhop_ca_api_request('collections', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single collection by ID from CollectiveAccess
|
||||
*
|
||||
* @param int $collection_id The ID of the collection to retrieve
|
||||
* @param array $params Additional query parameters
|
||||
* @return array|WP_Error Collection data or WP_Error on failure
|
||||
*/
|
||||
function carhop_ca_get_collection($collection_id, $params = array())
|
||||
{
|
||||
return carhop_ca_api_request("collections/{$collection_id}", $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Example usage function to test the API
|
||||
*/
|
||||
function carhop_test_ca_api()
|
||||
{
|
||||
// Test getting objects
|
||||
$objects = carhop_ca_get_objects([
|
||||
'limit' => 5,
|
||||
'page' => 1
|
||||
]);
|
||||
|
||||
if (is_wp_error($objects)) {
|
||||
error_log('CollectiveAccess API Error: ' . $objects->get_error_message());
|
||||
return;
|
||||
}
|
||||
|
||||
// Log the results
|
||||
error_log('CollectiveAccess API Test Results: ' . print_r($objects, true));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user