-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithook.php
89 lines (77 loc) · 2.19 KB
/
githook.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
<?php
/**
* The GitHook plugin
*
* This is a simple plugin to automatically sync plugins and themes
* using GitHub API.
*
* @link https://anspress.io
* @since 1.0.0
* @package GitHook
*
* @wordpress-plugin
* Plugin Name: GitHook
* Description: Plugin to auto sync with github repo.
* Version: 1.0.0
* Author: Rahul Aryan
* Author URI: https://anspress.io
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: githook
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Load plugin class .
*/
function load_githook() {
// Return if not GitHook action.
if ( ! isset( $_GET['githook_action'] ) ) {
return;
}
$options = get_option( 'githook_settings', [] );
/**
* Filter allows changing default GitHook secret key.
*
* @return string
* @since 1.0.0
*/
$secret = apply_filters( 'githook_secret', $options['webhook_secret'] );
// Define GitHook secret so that it can be used after this point.
define( 'GITHOOK_SECRET', $secret );
// Check secret key.
if ( empty( $_GET['secret'] ) || $_GET['secret'] !== $secret ) {
wp_die( esc_attr__( 'Trying to cheat?', 'githook' ), 401 );
}
require_once plugin_dir_path( __FILE__ ) . '/class-githook.php';
// Get the instance.
GitHook::get_instance();
die( esc_attr__( 'End of the life!', 'githook' ) );
}
add_action( 'template_redirect', 'load_githook' );
/**
* Register GitHook settings page.
*
* @return void
*/
function githook_admin() {
// Require admin settings.
require_once plugin_dir_path( __FILE__ ) . '/admin/class-admin.php';
add_options_page( __( 'GitHook settings page', 'githook' ), __( 'GitHook', 'githook' ), 'manage_options', 'githook', [ 'GitHook\Admin', 'page' ] );
}
add_action( 'admin_menu', 'githook_admin' );
/**
* Save GitHook settings
*
* @return void
*/
function githook_settings() {
// Require admin settings.
require_once plugin_dir_path( __FILE__ ) . '/admin/class-admin.php';
GitHook\Admin::get_instance()->save_settings();
die();
}
add_action( 'admin_action_githook_settings', 'githook_settings' );