Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
363 lines (323 loc) · 12.4 KB
/
Copy pathfunctions.php
File metadata and controls
363 lines (323 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
// =============================================================================
// FUNCTIONS.PHP - Theme Setup and Features
// =============================================================================
?>
<?php
/**
* Cornerstone Theme Functions
*/
if (!defined('ABSPATH')) {
exit;
}
// Theme setup
function cornerstone_setup() {
// Add theme support for various features
add_theme_support('automatic-feed-links');
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_theme_support('responsive-embeds');
add_theme_support('wp-block-styles');
add_theme_support('align-wide');
add_theme_support('custom-background');
add_theme_support('custom-header');
add_theme_support('custom-logo');
add_theme_support('customize-selective-refresh-widgets');
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
));
add_theme_support('post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat'
));
// Add custom image sizes
/// add_image_size('featured-image', 1200, 600, true);
add_image_size('featured-image', 1200, 9999, false);
// Register navigation menus
register_nav_menus(array(
'primary' => __('Primary Menu', 'cornerstone'),
'footer' => __('Footer Menu', 'cornerstone'),
));
// Load text domain for translations
load_theme_textdomain('cornerstone', get_template_directory() . '/languages');
}
add_action('after_setup_theme', 'cornerstone_setup');
// Enqueue styles and scripts
function cornerstone_scripts() {
$theme = wp_get_theme();
wp_enqueue_style('cornerstone-style', get_stylesheet_uri(), array(), $theme->get('Version'));
wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css', array(), '6.6.0');
wp_style_add_data('font-awesome', 'integrity', 'sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==');
wp_style_add_data('font-awesome', 'crossorigin', 'anonymous');
wp_enqueue_script('cornerstone-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true);
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'cornerstone_scripts');
// Widget areas
function cornerstone_widgets_init() {
register_sidebar(array(
'name' => __('Footer Widget Area 1', 'cornerstone'),
'id' => 'footer-1',
'description' => __('Add widgets here to appear in the footer.', 'cornerstone'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => __('Footer Widget Area 2', 'cornerstone'),
'id' => 'footer-2',
'description' => __('Add widgets here to appear in the footer.', 'cornerstone'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar(array(
'name' => __('Footer Widget Area 3', 'cornerstone'),
'id' => 'footer-3',
'description' => __('Add widgets here to appear in the footer.', 'cornerstone'),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
}
add_action('widgets_init', 'cornerstone_widgets_init');
// Add IndieWeb rel=me links
function cornerstone_add_rel_me() {
$social_links = get_theme_mod('social_links', array());
foreach ($social_links as $link) {
if (!empty($link)) {
echo '<link rel="me" href="' . esc_url($link) . '">' . "\n";
}
}
}
add_action('wp_head', 'cornerstone_add_rel_me');
// Add webmention endpoint discovery
function cornerstone_webmention_discovery() {
if (function_exists('webmention_discovery')) {
webmention_discovery();
}
}
add_action('wp_head', 'cornerstone_webmention_discovery');
// Customize excerpt length
function cornerstone_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'cornerstone_excerpt_length');
// Custom excerpt more
function cornerstone_excerpt_more($more) {
return '…';
}
add_filter('excerpt_more', 'cornerstone_excerpt_more');
// Get social media platform from URL
function cornerstone_get_social_platform($url) {
$url = strtolower($url);
$platforms = array(
'mastodon' => 'Mastodon',
'twitter.com' => 'Twitter',
'x.com' => 'X',
'linkedin' => 'LinkedIn',
'facebook' => 'Facebook',
'instagram' => 'Instagram',
'github' => 'GitHub',
'youtube' => 'YouTube',
'tiktok' => 'TikTok',
'threads' => 'Threads',
'bluesky' => 'Bluesky',
'pixelfed' => 'Pixelfed',
'peertube' => 'PeerTube',
'lastfm' => 'Last.fm',
'spotify' => 'Spotify',
'flickr' => 'Flickr',
'unsplash' => 'Unsplash',
'reddit' => 'Reddit',
'tumblr' => 'Tumblr',
'medium' => 'Medium',
'dev.to' => 'Dev.to',
'ko-fi' => 'Ko-fi',
'patreon' => 'Patreon',
);
foreach ($platforms as $domain => $name) {
if (strpos($url, $domain) !== false) {
return $name;
}
}
// Fallback: extract domain from URL
$parsed = parse_url($url);
if (isset($parsed['host'])) {
return str_replace('www.', '', $parsed['host']);
}
return 'Social Profile';
}
// Get Font Awesome icon class for social platform
function cornerstone_get_social_icon($url) {
$url = strtolower($url);
$icons = array(
'mastodon.social' => 'fab fa-mastodon',
'fosstodon.org' => 'fab fa-mastodon',
'indieweb.social' => 'fab fa-mastodon',
'bsky.app' => 'fab fa-bluesky',
'twitter.com' => 'fab fa-twitter',
'x.com' => 'fab fa-x-twitter',
'linkedin' => 'fab fa-linkedin',
'facebook' => 'fab fa-facebook',
'instagram' => 'fab fa-instagram',
'github' => 'fab fa-github',
'youtube' => 'fab fa-youtube',
'tiktok' => 'fab fa-tiktok',
'threads' => 'fab fa-threads',
'pixelfed' => 'fab fa-pixelfed',
'peertube' => 'fab fa-peertube',
'lastfm' => 'fab fa-lastfm',
'spotify' => 'fab fa-spotify',
'flickr' => 'fab fa-flickr',
'unsplash' => 'fab fa-unsplash',
'reddit' => 'fab fa-reddit',
'tumblr' => 'fab fa-tumblr',
'medium' => 'fab fa-medium',
'dev.to' => 'fab fa-dev',
'ko-fi' => 'fab fa-kofi',
'patreon' => 'fab fa-patreon',
);
foreach ($icons as $domain => $icon) {
if (strpos($url, $domain) !== false) {
return $icon;
}
}
// Fallback icon
return 'fas fa-link';
}
/**
* Get ActivityPub avatar URL for a comment.
*
* This function retrieves the Fediverse avatar from the ActivityPub plugin's
* stored data. It checks multiple possible meta keys where the avatar URL
* might be stored, and falls back to Gravatar if none are found.
*
* @param int $comment_id The comment ID.
* @param string $email The comment author email (for Gravatar fallback).
* @param int $size The avatar size in pixels.
* @return string The avatar URL.
*/
function cornerstone_get_activitypub_avatar($comment_id, $email, $size = 32) {
// Try to get the avatar from ActivityPub plugin's comment meta
// The ActivityPub plugin may store avatar URLs in different meta keys
$avatar_url = '';
// Check for ActivityPub actor icon (newer versions of the plugin)
$actor_icon = get_comment_meta($comment_id, 'activitypub_actor_icon', true);
if (!empty($actor_icon)) {
// The icon might be stored as an array with 'url' key or as a direct URL
if (is_array($actor_icon) && isset($actor_icon['url'])) {
$avatar_url = $actor_icon['url'];
} elseif (is_string($actor_icon)) {
$avatar_url = $actor_icon;
}
}
// Check for avatar_url meta (alternative storage)
if (empty($avatar_url)) {
$avatar_url = get_comment_meta($comment_id, 'avatar_url', true);
}
// Check for protocol meta that might contain avatar info
if (empty($avatar_url)) {
$protocol = get_comment_meta($comment_id, 'protocol', true);
if ($protocol === 'activitypub') {
// Try to get avatar from actor data
$actor = get_comment_meta($comment_id, 'activitypub_actor', true);
if (!empty($actor) && is_array($actor)) {
if (isset($actor['icon']['url'])) {
$avatar_url = $actor['icon']['url'];
} elseif (isset($actor['icon']) && is_string($actor['icon'])) {
$avatar_url = $actor['icon'];
}
}
}
}
// Check for webmention source avatar (if using Webmention plugin together)
if (empty($avatar_url)) {
$avatar_url = get_comment_meta($comment_id, 'semantic_linkbacks_avatar', true);
}
// If still no avatar found, try using the comment object with get_avatar_url
// This allows the ActivityPub plugin's filters to work
if (empty($avatar_url)) {
$comment = get_comment($comment_id);
if ($comment) {
// Use get_avatar_url which goes through WordPress filters
// The ActivityPub plugin hooks into 'pre_get_avatar_data'
$avatar_url = get_avatar_url($comment, array('size' => $size));
}
}
// Final fallback to Gravatar using email
if (empty($avatar_url) || strpos($avatar_url, 'gravatar.com/avatar/?') !== false) {
// Check if it's a mystery person/blank gravatar, use a better default
$hash = md5(strtolower(trim($email)));
$avatar_url = 'https://www.gravatar.com/avatar/' . $hash . '?s=' . $size . '&d=mp';
}
return $avatar_url;
}
// Clear cached ActivityPub reactions when a like/repost comment changes
function cornerstone_clear_ap_reactions_cache($comment_id) {
$comment = get_comment($comment_id);
if ($comment && in_array($comment->comment_type, array('like', 'repost'), true)) {
delete_transient('cornerstone_ap_reactions_' . $comment->comment_post_ID);
}
}
add_action('comment_post', 'cornerstone_clear_ap_reactions_cache');
add_action('deleted_comment', 'cornerstone_clear_ap_reactions_cache');
add_action('transition_comment_status', function($new_status, $old_status, $comment) {
if (in_array($comment->comment_type, array('like', 'repost'), true)) {
delete_transient('cornerstone_ap_reactions_' . $comment->comment_post_ID);
}
}, 10, 3);
// Theme Customizer
function cornerstone_customize_register($wp_customize) {
// Social Links Section
$wp_customize->add_section('social_links', array(
'title' => __('Social Links', 'cornerstone'),
'priority' => 130,
));
// Add social link fields
for ($i = 1; $i <= 5; $i++) {
$wp_customize->add_setting("social_link_$i", array(
'default' => '',
'sanitize_callback' => 'esc_url_raw',
));
$wp_customize->add_control("social_link_$i", array(
'label' => sprintf(__('Social Link %d', 'cornerstone'), $i),
'section' => 'social_links',
'type' => 'url',
));
}
// Author Bio Section
$wp_customize->add_section('author_bio', array(
'title' => __('Author Bio', 'cornerstone'),
'priority' => 140,
));
$wp_customize->add_setting('show_author_bio', array(
'default' => true,
'sanitize_callback' => 'wp_validate_boolean',
));
$wp_customize->add_control('show_author_bio', array(
'label' => __('Show Author Bio', 'cornerstone'),
'section' => 'author_bio',
'type' => 'checkbox',
));
}
add_action('customize_register', 'cornerstone_customize_register');
?>