-
Notifications
You must be signed in to change notification settings - Fork 1
/
quantimodo.php
97 lines (80 loc) · 3.01 KB
/
quantimodo.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
<?php
/*
* Plugin Name: QuantiModo
* Version: 0.6.8
* Description: Allow your users to record, aggregate, analyze and visualize their health and life-tracking data.
* Author: QuantiModo
* Author URI: https://quantimo.do
* Plugin URI: https://quantimo.do
*/
// Prevent Direct Access
defined('ABSPATH') or die("Restricted access!");
define('QUANTIMODO_4f050d29b8BB9_DIR', plugin_dir_path(__FILE__));
define('QUANTIMODO_4f050d29b8BB9_URL', plugin_dir_url(__FILE__));
defined('QUANTIMODO_4f050d29b8BB9_PATH') or define('QUANTIMODO_4f050d29b8BB9_PATH', untrailingslashit(plugins_url('', __FILE__)));
const APP_BUILDER_URL = 'https://builder.quantimo.do';
require_once(QUANTIMODO_4f050d29b8BB9_DIR . 'includes/core.php');
require_once plugin_dir_path(__FILE__) . 'includes/access_token.php';
require_once plugin_dir_path(__FILE__) . 'includes/qm_url.php';
require_once(QUANTIMODO_4f050d29b8BB9_DIR . 'includes/menus.php');
require_once(QUANTIMODO_4f050d29b8BB9_DIR . 'includes/admin.php');
require_once(QUANTIMODO_4f050d29b8BB9_DIR . 'includes/fab.php' );
require_once plugin_dir_path( __FILE__ ) . 'includes/qm_iframe_shortcode.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/qm_redirect_shortcode.php';
require_once plugin_dir_path(__FILE__) . 'petition-the-government.php';
function enqueue_qm_block_assets() {
wp_enqueue_script(
'qm-block',
plugins_url('build/index.js', __FILE__),
array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor'),
true
);
}
add_action('enqueue_block_editor_assets', 'enqueue_qm_block_assets');
function redirect_to_login_if_necessary(): void {
// Check if user is logged in
if ( ! is_user_logged_in() ) {
// If user is not logged in, redirect to login page
auth_redirect();
}
// Get the user's access token
$access_token = get_qm_access_token();
if ( ! $access_token ) {
qm_error( 'No QM access token found' );
}
}
function render_qm_iframe_block($attributes, $content) {
redirect_to_login_if_necessary();
// Your shortcode function here
return qm_iframe_func($attributes);
}
function register_qm_iframe_block() {
if (function_exists('register_block_type')) {
register_block_type('quantimodo/qm-iframe', array(
'attributes' => array(
// Define your block's attributes here, if any
),
'render_callback' => 'render_qm_iframe_block',
));
}
}
add_action('init', 'register_qm_iframe_block');
function render_qm_redirect_block($attributes, $content) {
redirect_to_login_if_necessary();
// Your shortcode function here
return qm_redirect_func($attributes);
}
/**
* @return void
*/
function register_qm_redirect_block() {
if (function_exists('register_block_type')) {
register_block_type('quantimodo/qm-redirect', array(
'attributes' => array(
// Define your block's attributes here, if any
),
'render_callback' => 'render_qm_redirect_block',
));
}
}
add_action('init', 'register_qm_redirect_block');