-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
154 lines (140 loc) · 5.03 KB
/
Copy pathplugin.php
File metadata and controls
154 lines (140 loc) · 5.03 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
<?php
/**
* Plugin Name: UCSC Giving Functionality
* Plugin URI: https://github.com/ucsc/ucsc-giving-functionality-plugin
* Description: Adds custom functionality to UCSC Giving Website.
* Version: 0.5.8
* Requires at least: 6.5.0
* Requires PHP: 8.1
* Author: UC Santa Cruz
* Author URI: https://github.com/ucsc
* License: GPL3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Update URI: https://github.com/ucsc/ucsc-giving-functionality-plugin/releases
* Requires Plugins: advanced-custom-fields-pro
* Text Domain: ucscgiving
*
* @package ucsc-giving-functionality
*/
defined( 'ABSPATH' ) || exit;
// Set plugin directory and base name.
define( 'UCSCGIVING_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); // Path to plugin directory.
define( 'UCSCGIVING_PLUGIN_BASE', plugin_basename( __FILE__ ) ); // Plugin base name 'plugin.php' at root.
// Include general functions.
if ( file_exists( UCSCGIVING_PLUGIN_DIR . 'lib/functions/general.php' ) ) {
require_once UCSCGIVING_PLUGIN_DIR . 'lib/functions/general.php';
}
// Include settings.
if ( file_exists( UCSCGIVING_PLUGIN_DIR . '/lib/functions/settings.php' ) ) {
include_once UCSCGIVING_PLUGIN_DIR . '/lib/functions/settings.php';
}
// Enqueue admin settings styles.
if ( ! function_exists( 'ucscgiving_enqueue_admin_styles' ) ) {
/**
* Enqueue admin settings styles
*
* @since 0.5.0
* @author UCSC
* @package ucsc-giving-functionality
*/
function ucscgiving_enqueue_admin_styles(): void {
$current_screen = get_current_screen();
// get_current_screen() returns null outside a real admin screen (ajax, customizer).
if ( ! $current_screen instanceof WP_Screen ) {
return;
}
if ( false === strpos( $current_screen->base, 'ucsc-giving-functionality-settings' ) ) {
return;
}
$settings_css = plugin_dir_url( __FILE__ ) . 'lib/css/admin-settings.css';
$plugin_data = get_plugin_data( UCSCGIVING_PLUGIN_DIR . 'plugin.php' );
$plugin_version = $plugin_data['Version'];
wp_register_style( 'ucscgiving-cf-admin-settings', $settings_css, array(), $plugin_version );
wp_enqueue_style( 'ucscgiving-cf-admin-settings' );
}
}
add_action( 'admin_enqueue_scripts', 'ucscgiving_enqueue_admin_styles' );
/**
* ACF JSON Save Point
*
* @param string $path Default ACF JSON save path.
* @return string Path to this plugin's acf-json directory.
* @package ucsc-giving-functionality
*/
function ucscgiving_acf_json_save_point( $path ) {
$path = UCSCGIVING_PLUGIN_DIR . 'acf-json';
return $path;
}
// Set plugin directory for saving ACF JSON files.
add_filter( 'acf/settings/save_json', 'ucscgiving_acf_json_save_point' );
/**
* ACF JSON Load Point
*
* @param array $paths Default ACF JSON load paths.
* @return array Load paths with this plugin's acf-json directory substituted in.
* @package ucsc-giving-functionality
*/
function ucscgiving_acf_json_load_point( $paths ) {
unset( $paths[0] );
$paths[] = UCSCGIVING_PLUGIN_DIR . 'acf-json';
return $paths;
}
// Set plugin directory for loading ACF JSON files.
add_filter( 'acf/settings/load_json', 'ucscgiving_acf_json_load_point' );
/**
* Callback function to retrieve custom template content
*
* @param string $template Template filename, relative to lib/templates/.
* @return string Rendered template markup.
* @package ucsc-giving-functionality
*/
function ucscgiving_get_template_content( $template ) {
ob_start();
include __DIR__ . "/lib/templates/{$template}";
return ob_get_clean();
}
/**
* Register Fund block templates
*
* @return void
* @package ucsc-giving-functionality
*/
function ucscgiving_register_block_templates() {
$templates = array(
'archive-fund' => array(
'title' => __( 'Fund Archives', 'ucscgiving' ),
'description' => __( 'Displays the archive template for Giving Funds.', 'ucscgiving' ),
),
'taxonomy-area' => array(
'title' => __( 'Fund Area Archives', 'ucscgiving' ),
'description' => __( 'Displays the archive template for the Fund areas.', 'ucscgiving' ),
),
'taxonomy-fund-theme' => array(
'title' => __( 'Fund Theme Archives', 'ucscgiving' ),
'description' => __( 'Displays the archive template for the Fund themes.', 'ucscgiving' ),
),
'taxonomy-fund-type' => array(
'title' => __( 'Fund Type Archives', 'ucscgiving' ),
'description' => __( 'Displays the archive template for the Fund types.', 'ucscgiving' ),
),
'taxonomy-keyword' => array(
'title' => __( 'Fund Keyword Archives', 'ucscgiving' ),
'description' => __( 'Displays the archive template for the Fund keywords.', 'ucscgiving' ),
),
'single-fund' => array(
'title' => __( 'Single Funds Posts', 'ucscgiving' ),
'description' => __( 'Displays the single post template for Funds.', 'ucscgiving' ),
),
);
foreach ( $templates as $slug => $data ) {
register_block_template(
'ucscgiving//' . $slug,
array(
'title' => $data['title'],
'description' => $data['description'],
'content' => ucscgiving_get_template_content( $slug . '.php' ),
)
);
}
}
add_action( 'init', 'ucscgiving_register_block_templates' );