/
tabulate.php
62 lines (52 loc) · 2.06 KB
/
tabulate.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
<?php
/**
* Plugin Name: Tabulate
* Description: Manage relational tabular data within the WP admin area, using the full power of your MySQL database.
* Author: Sam Wilson
* Author URI: https://samwilson.id.au/
* License: GPL-2.0+
* Text Domain: tabulate
* Domain Path: /languages
* Version: 2.10.1
*/
define( 'TABULATE_VERSION', '2.10.1' );
define( 'TABULATE_SLUG', 'tabulate' );
// Load textdomain.
add_action( 'plugins_loaded', function() {
load_plugin_textdomain( TABULATE_SLUG, false, basename( __DIR__ ) . '/languages/' );
} );
// Make sure Composer has been set up (for installation from Git, mostly).
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
add_action( 'admin_notices', function() {
$msg = __( 'Please run <kbd>composer install</kbd> prior to using Tabulate.', 'tabulate' );
echo "<div class='error'><p>$msg</p></div>";
} );
return;
}
require __DIR__ . '/vendor/autoload.php';
// Get the global database.
// This file contains the only global variables other than in the TestBase class;
// they're injected from here to everywhere else.
global $wpdb;
// Set up the menus; their callbacks do the actual dispatching to controllers.
$menus = new \WordPress\Tabulate\Menus( $wpdb );
$menus->init();
// Add grants-checking callback.
add_filter( 'user_has_cap', '\\WordPress\\Tabulate\\DB\\Grants::check', 0, 3 );
// Activation hooks. Uninstall is handled by uninstall.php.
register_activation_hook( __FILE__, [ $menus, 'activation' ] );
// Register JSON API.
add_action( 'rest_api_init', function() use ( $wpdb ) {
$api_controller = new \WordPress\Tabulate\Controllers\ApiController( $wpdb, $_GET );
$api_controller->register_routes();
} );
// Shortcode.
$shortcode = new \WordPress\Tabulate\Controllers\ShortcodeController( $wpdb );
add_shortcode( TABULATE_SLUG, array( $shortcode, 'run' ) );
// Dashboard widget.
add_action( 'wp_dashboard_setup', function() {
wp_add_dashboard_widget( TABULATE_SLUG . 'dashboard_widget', 'Tabulate', function() {
$template = new \WordPress\Tabulate\Template( 'quick_jump.html' );
echo $template->render();
} );
} );