-
Notifications
You must be signed in to change notification settings - Fork 4
/
beans-visual-hook-guide.php
executable file
·132 lines (118 loc) · 3.12 KB
/
beans-visual-hook-guide.php
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
<?php
/**
* Loads the Beans Visual Hook Guide plugin.
*
* @package LearningCurve\BeansVisualHookGuide
* @since 1.1.0
* @author Jeff Cleverley
* @link https://learningcurve.xyz
* @license GNU-2.0+
*
* @wordpress-plugin
* Plugin Name: Beans Visual Hook Guide
* Plugin URI: https://github.com/JeffCleverley/Beans-Visual-Hook-Guide
* Description: Find Beans Hooks (HTML API created action hooks only at the moment) quickly and easily by seeing
* their actual locations inside your theme.
* Version: 1.1.0
* Author: Jeff Cleverley
* Author URI: https://learningcurve.xyz
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: beans-visual-hook-guide
* Requires WP: 4.6
* Requires PHP: 5.6
*/
/**
* Special thanks to:
*
* This plugin was inspired by Christopher Cochran's Genesis Visual Hook Guide, one of my favourite plugins for
* Genesis Development. I started with his plugin and went from there.... Thank you very much Christopher!
*
* Links to Christopher:
* - https://genesistutorials.com/visual-hook-guide/
* - https://github.com/christophercochran/Genesis-Visual-Hook-Guide
* - http://christophercochran.me
*/
namespace LearningCurve\BeansVisualHookGuide;
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Hello, Hello, Hello, what\'s going on here then?' );
}
/**
* Gets this plugin's absolute directory path.
*
* @since 1.0.0
* @ignore
* @access private
*
* @return string
*/
function _get_plugin_directory() {
return __DIR__;
}
/**
* Gets this plugin's URL.
*
* @since 1.1.0
* @ignore
* @access private
*
* @return string
*/
function _get_plugin_url() {
static $plugin_url;
if ( empty( $plugin_url ) ) {
$plugin_url = plugins_url( null, __FILE__ );
}
return $plugin_url;
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\deactivate_when_beans_not_activated_theme' );
add_action( 'switch_theme', __NAMESPACE__ . '\deactivate_when_beans_not_activated_theme' );
/**
* If Beans is not the activated theme, deactivate this plugin and pop a die message when not switching themes.
*
* @since 1.0.0
*
* @return void
*/
function deactivate_when_beans_not_activated_theme() {
// If Beans is the active theme, bail out.
$theme = wp_get_theme();
if ( in_array( $theme->template, array( 'beans', 'tm-beans' ), true ) ) {
return;
}
deactivate_plugins( plugin_basename( __FILE__ ) );
if ( current_filter() !== 'switch_theme' ) {
$message = __( 'Sorry, you can\'t activate this plugin unless the <a href="https://www.getbeans.io" target="_blank">Beans</a> framework is installed and a child theme is activated.', 'beans-visual-hook-guide' );
wp_die( wp_kses_post( $message ) );
}
}
/**
* Autoload the plugin's files.
*
* @since 1.1.0
*
* @return void
*/
function autoload_files() {
$files = array(
'markup/handler.php',
'admin/admin-bar.php',
'admin/notices.php',
'asset/ajax.php',
'asset/handler.php',
'plugin.php',
);
foreach ( $files as $file ) {
require __DIR__ . '/src/' . $file;
}
}
/**
* Launch the plugin.
*
* @since 1.1.0
*
* @return void
*/
function launch() {
autoload_files();
}
launch();