2023-11-24 15:36:51 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2023-11-25 12:05:12 +01:00
|
|
|
* Plugin Name: ActivityPub Transformers for Events
|
2023-11-24 15:36:51 +01:00
|
|
|
* Description: Custom ActivityPub Transformers for Events
|
|
|
|
* Plugin URI: https://event-federation.eu/
|
|
|
|
* Version: 1.0.0
|
|
|
|
* Author: André Menrath
|
|
|
|
* Author URI: https://graz.social/@linos
|
|
|
|
* Text Domain: activitypub-event-transformers
|
2023-12-04 19:27:57 +01:00
|
|
|
* License: AGPL-3.0-or-later
|
2023-11-24 15:36:51 +01:00
|
|
|
*
|
2024-01-03 19:14:12 +01:00
|
|
|
* ActivityPub tested up to: 1.3.0
|
2023-11-27 19:18:06 +01:00
|
|
|
*
|
|
|
|
* @package activitypub-event-transformer
|
2023-12-04 19:27:57 +01:00
|
|
|
* @license AGPL-3.0-or-later
|
2023-11-24 15:36:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-03 19:14:12 +01:00
|
|
|
* Add the custom transformers for the events of several WordPress event plugins.
|
|
|
|
*/
|
|
|
|
add_filter(
|
|
|
|
'activitypub_transformer',
|
|
|
|
function( $transformer, $object, $object_class ) {
|
|
|
|
/**
|
|
|
|
* VS Event List
|
|
|
|
* @see https://wordpress.org/plugins/very-simple-event-list/
|
|
|
|
*/
|
2024-01-03 19:18:13 +01:00
|
|
|
if ( $object->post_type === 'event' ) {
|
2024-01-04 11:25:29 +01:00
|
|
|
require_once __DIR__ . '/includes/activitypub/transformer/class-vs-event.php';
|
2024-01-03 19:14:12 +01:00
|
|
|
return new \VS_Event( $object );
|
|
|
|
}
|
|
|
|
// Return the default transformer.
|
|
|
|
return $transformer;
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
3
|
|
|
|
);
|
|
|
|
|
2024-01-04 11:25:29 +01:00
|
|
|
/**
|
|
|
|
* Add admin notices for improved usability.
|
|
|
|
*/
|
|
|
|
function check_some_other_plugin() {
|
2024-01-04 14:50:29 +01:00
|
|
|
if ( is_plugin_active( 'activitypub/activitypub.php' ) ) {
|
|
|
|
if ( is_plugin_active( 'very-simple-event-list/vsel.php' ) ) {
|
2024-01-04 11:25:29 +01:00
|
|
|
add_action( 'admin_notices', 'vsel_admin_notices' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'admin_init', 'check_some_other_plugin' );
|
|
|
|
|
|
|
|
function vsel_admin_notices() {
|
2024-01-04 14:50:29 +01:00
|
|
|
$is_vsel_edit_page = isset( $_GET['post_type'] ) && $_GET['post_type'] === 'event';
|
|
|
|
$is_vsel_settings_page = strpos( $_SERVER['REQUEST_URI'], '/wp-admin/options-general.php?page=vsel' ) !== false;
|
|
|
|
$is_vsel_page = $is_vsel_edit_page || $is_vsel_settings_page;
|
|
|
|
$vsel_post_type_is_activitypub_enabeld = in_array( 'event', get_option( 'activitypub_support_post_types' ) );
|
2024-01-04 11:25:29 +01:00
|
|
|
if ( $is_vsel_page && ! $vsel_post_type_is_activitypub_enabeld ) {
|
|
|
|
$vsel_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/very-simple-event-list/vsel.php' );
|
|
|
|
$activitypub_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php' );
|
|
|
|
$notice = sprintf(
|
|
|
|
_x(
|
|
|
|
'You have installed the %1$s plugin, but the event post type of %2$s is not enabled in the <a href="%3$s">%1$s settings</a>.',
|
|
|
|
'admin notice',
|
|
|
|
'your-text-domain'
|
|
|
|
),
|
|
|
|
$activitypub_plugin_data['Name'],
|
|
|
|
$vsel_plugin_data['Name'],
|
2024-01-04 14:50:29 +01:00
|
|
|
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
2024-01-04 11:25:29 +01:00
|
|
|
);
|
|
|
|
wp_admin_notice(
|
|
|
|
$notice,
|
|
|
|
array(
|
|
|
|
'type' => 'warning',
|
|
|
|
'dismissible' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 19:31:01 +01:00
|
|
|
/**
|
|
|
|
* Add a filter for http_request_host_is_external
|
|
|
|
*
|
|
|
|
* TODO: Remove this.
|
|
|
|
*
|
|
|
|
* @todo This filter is temporary code needed to do local testing.
|
|
|
|
*/
|
|
|
|
add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 );
|
2023-12-12 17:27:43 +01:00
|
|
|
|
2024-01-03 19:31:01 +01:00
|
|
|
// Your custom callback function
|
|
|
|
function custom_http_request_host_is_external( $is_external, $host, $url ) {
|
|
|
|
$is_external = true;
|
2023-12-12 17:27:43 +01:00
|
|
|
|
2024-01-03 19:31:01 +01:00
|
|
|
return $is_external;
|
|
|
|
}
|
2023-12-12 17:27:43 +01:00
|
|
|
|
2024-01-03 19:31:01 +01:00
|
|
|
/**
|
|
|
|
* Don't verify ssl certs for testing.
|
|
|
|
*
|
|
|
|
* TODO: Remove this.
|
|
|
|
*
|
|
|
|
* @todo This filter is temporary code needed to do local testing.
|
|
|
|
*/
|
|
|
|
add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 );
|
2023-12-12 17:27:43 +01:00
|
|
|
|
2024-01-03 19:31:01 +01:00
|
|
|
function dont_verify_local_dev_https( $url ) {
|
|
|
|
return false;
|
|
|
|
}
|