-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeer-slurper.php
114 lines (98 loc) · 3.79 KB
/
beer-slurper.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
<?php
/**
* Plugin Name: Beer Slurper
* Plugin URI: https://kraft.im/beer-slurper/
* Description: Slurp data from Untappd into your site!
* Version: 0.1.0
* Author: Brandon Kraft
* Author URI: https://kraft.im/
* License: GPLv2+
* Text Domain: beer_slurper
* Domain Path: /languages
*/
/**
* Copyright (c) 2015 Brandon Kraft (email : public@brandonkraft.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Built using yo wp-make:plugin
* Copyright (c) 2015 10up, LLC
* https://github.com/10up/generator-wp-make
*/
// Useful global constants
define( 'BEER_SLURPER_VERSION', '0.1.0' );
define( 'BEER_SLURPER_URL', plugin_dir_url( __FILE__ ) );
define( 'BEER_SLURPER_PATH', dirname( __FILE__ ) . '/' );
define( 'BEER_SLURPER_INC', BEER_SLURPER_PATH . 'includes/' );
// temporary constants
if ( ! defined( 'BEER_SLURPER_CPT' ) ) {
define( 'BEER_SLURPER_CPT', 'beerlog_beer');
}
if ( ! defined( 'BEER_SLURPER_TAX_STYLE') ) {
define( 'BEER_SLURPER_TAX_STYLE', 'beerlog_style' );
}
if ( ! defined( 'BEER_SLURPER_TAX_BREWERY') ) {
define( 'BEER_SLURPER_TAX_BREWERY', 'beerlog_brewery' );
}
// Include files
require_once BEER_SLURPER_INC . 'functions/core.php';
require_once BEER_SLURPER_INC . 'functions/cpt.php';
require_once BEER_SLURPER_INC . 'functions/brewery.php';
require_once BEER_SLURPER_INC . 'functions/api.php';
require_once BEER_SLURPER_INC . 'functions/post.php';
require_once BEER_SLURPER_INC . 'functions/walker.php';
function bs_test_insert( $user = 'kraft' ){
// add validation
$checkin = \Kraft\Beer_Slurper\API\get_latest_checkin( $user );
\Kraft\Beer_Slurper\Post\insert_beer( $checkin );
}
function bs_start_import( $user = null ){
if ( ! $user ){
return "No user indicated.";
}
// @todo check for other user options. No need to restart the import if options suggest it has been done.
update_option( 'beer_slurper_' . $user . '_import', true, false );
if (! wp_next_scheduled( 'bs_hourly_importer', array( $user ) ) ) {
wp_schedule_event( time(), 'hourly', 'bs_hourly_importer', array( $user ) );
}
}
function bs_import( $user = null ){ // used to start backflow imports. need to add checks for new beer too and/or split.
if ( ! $user ){
return "No user indicated.";
}
if ( get_option( 'beer_slurper_' . $user . '_import' ) ) {
// If we are still backfilling, call in the next batch of 25 checkins.
\Kraft\Beer_Slurper\Walker\import_old( $user );
}
if ( get_option( 'beer_slurper_' . $user . '_since' ) ) {
// If we have pulled in at least one batch of old checkins, check for ones newer than the most recent.
\Kraft\Beer_Slurper\Walker\import_new( $user );
}
return "All done.";
}
add_action('bs_hourly_importer', 'bs_import', 10, 2 );
// Activation/Deactivation
register_activation_hook( __FILE__, '\Kraft\Beer_Slurper\Core\activate' );
register_deactivation_hook( __FILE__, '\Kraft\Beer_Slurper\Core\deactivate' );
// Temporary function to add [gallery] to each beer post. Will be migrated once the beer CPT code is merged in.
add_filter( 'the_content', function( $content ){
if ( is_singular( BEER_SLURPER_CPT ) ) {
$content .= "[gallery]";
}
return $content;
} );
// Bootstrap
Kraft\Beer_Slurper\Core\setup();