-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhf-accountability.php
150 lines (124 loc) · 5.15 KB
/
hf-accountability.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/*
Plugin Name: HabitFree Accountability
Description: Keeps people accountable.
Author: Nathan Arthur
Version: 1.0
Author URI: http://NathanArthur.com/
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
register_activation_hook( __FILE__, "hfActivate" );
register_deactivation_hook( __FILE__, "hfDeactivate" );
function hfActivate() {
$Factory = new HfFactory();
$Database = $Factory->makeDatabase();
$UserManager = $Factory->makeUserManager();
wp_clear_scheduled_hook( 'hfEmailCronHook' );
wp_schedule_event( time(), 'daily', 'hfEmailCronHook' );
$Database->installDb();
add_action( 'shutdown', array( $UserManager, 'processAllUsers' ) );
error_log( "my plugin activated", 0 );
}
function hfDeactivate() {
wp_clear_scheduled_hook( 'hfEmailCronHook' );
}
function hfAutoload( $folder ) {
foreach ( scandir( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $folder ) as $filename ) {
$path = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename;
if ( is_file( $path ) ) {
require_once $path;
}
}
}
hfAutoload( 'interfaces' );
hfAutoload( 'abstractClasses' );
hfAutoload( 'classes' );
date_default_timezone_set( 'America/Chicago' );
$HfFactory = new HfFactory();
$HfGoals = $HfFactory->makeGoals();
$HfUserManager = $HfFactory->makeUserManager();
$HfAdminPanel = $HfFactory->makeAdminPanel();
$HfLoginForm = $HfFactory->makeLoginForm();
add_action( 'after_setup_theme', array( $HfLoginForm, 'attemptLogin' ) );
add_action( 'hfEmailCronHook', array( $HfGoals, 'sendReportRequestEmails' ) );
add_action( 'user_register', array( $HfUserManager, 'processNewUser' ) );
add_action( 'init', array( $HfAdminPanel, 'registerCustomPostTypes' ) );
add_action( 'admin_menu', array( $HfAdminPanel, 'registerAdminPages' ) );
add_action( 'admin_head', array( $HfAdminPanel, 'addToAdminHead' ) );
add_action( 'init', 'hfRegisterShortcodes' );
add_action( 'init', 'hfAddPostTypes' );
add_filter( 'user_can_richedit', 'hfDisableWysiwygForQuotes' );
add_filter( 'enter_title_here', 'hfChangeEditTitleLabelForQuotations' );
function hfRegisterShortcodes() {
$Factory = new HfFactory();
$SettingsShortcode = $Factory->makeSettingsShortcode();
$GoalsShortcode = $Factory->makeGoalsShortcode();
$AuthenticateShortcode = $Factory->makeAuthenticateShortcode();
$UserButtonsShortcode = $Factory->makeUserButtonsShortcode();
$InvitePartnerShortcode = $Factory->makeInvitePartnerShortcode();
$PartnerListShortcode = $Factory->makePartnerListShortcode();
$ManagePartnersShortcode = $Factory->makeManagePartnersShortcode();
add_shortcode( 'hfSettings', array( $SettingsShortcode, 'getOutput' ) );
add_shortcode( 'hfGoals', array( $GoalsShortcode, 'getOutput' ) );
add_shortcode( 'hfUserButtons', array( $UserButtonsShortcode, 'getOutput' ) );
add_shortcode( 'hfAuthenticate', array( $AuthenticateShortcode, 'getOutput' ) );
add_shortcode( 'hfInvitePartner', array( $InvitePartnerShortcode, 'getOutput' ) );
add_shortcode( 'hfPartnerList', array( $PartnerListShortcode, 'getOutput' ) );
add_shortcode( 'hfManagePartners', array( $ManagePartnersShortcode, 'getOutput' ) );
}
function hfAddPostTypes() {
register_post_type( 'hf_quotation',
array(
'labels' => array(
'name' => 'Quotations',
'singular_name' => 'Quotation',
'menu_name' => 'Quotations',
'parent_item_colon' => 'Parent Quotation:',
'all_items' => 'All Quotations',
'view_item' => 'View Quotation',
'add_new_item' => 'Add New Quotation',
'edit_item' => 'Edit Quotation',
'update_item' => 'Update Quotation',
'search_items' => 'Search Quotation'
),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-format-quote'
)
);
register_taxonomy(
'hfContext',
'hf_quotation',
array(
'label' => __( 'Context' ),
'rewrite' => array( 'slug' => 'context' ),
'hierarchical' => true,
'capabilities' => array(
'manage_terms' => 'noone',
'edit_terms' => 'noone',
'delete_terms' => 'noone',
'assign_terms' => 'edit_posts'
)
)
);
$taxonomy = 'hfContext';
wp_insert_term( 'For Success', $taxonomy, $args = array() );
wp_insert_term( 'For Setback', $taxonomy, $args = array() );
wp_insert_term( 'For Mentor', $taxonomy, $args = array() );
}
function hfDisableWysiwygForQuotes( $default ) {
global $post;
if ( 'hf_quotation' == get_post_type( $post ) ) {
return false;
}
return $default;
}
function hfChangeEditTitleLabelForQuotations( $title ) {
$screen = get_current_screen();
if ( 'hf_quotation' == $screen->post_type ) {
$title = 'Enter source / reference here';
}
return $title;
}