Completed
Push — master ( de6a17...35dc2a )
by Sam
02:15
created

tabulate.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Plugin Name: Tabulate
4
 * Description: Manage relational tabular data within the WP admin area, using the full power of your MySQL database.
5
 * Author: Sam Wilson
6
 * Author URI: https://samwilson.id.au/
7
 * License: GPL-2.0+
8
 * Text Domain: tabulate
9
 * Domain Path: /languages
10
 * Version: 2.7.18
11
 */
12
13
define( 'TABULATE_VERSION', '2.7.18' );
14
define( 'TABULATE_SLUG', 'tabulate' );
15
16
// Load textdomain.
17
add_action( 'plugins_loaded', function() {
18
	load_plugin_textdomain( TABULATE_SLUG, false, basename( __DIR__ ) . '/languages/' );
19
} );
20
21
// Make sure Composer has been set up (for installation from Git, mostly).
22
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
23
	add_action( 'admin_notices', function() {
24
		$msg = __( 'Please run <kbd>composer install</kbd> prior to using Tabulate.', 'tabulate' );
25
		echo "<div class='error'><p>$msg</p></div>";
26
	} );
27
	return;
28
}
29
require __DIR__ . '/vendor/autoload.php';
30
31
// Get global variables and set up the filesystem.
32
// This file contains the only global usages of these (other than in the TestBase class);
33
// they're injected from here to everywhere else.
34
if ( ! function_exists( 'WP_filesystem' ) ) {
35
	include ABSPATH . "wp-admin/includes/file.php";
36
}
37
WP_Filesystem();
38
global $wpdb, $wp_filesystem;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
39
40
// Set up the menus; their callbacks do the actual dispatching to controllers.
41
$menus = new \WordPress\Tabulate\Menus( $wpdb, $wp_filesystem );
42
$menus->init();
43
44
// Add grants-checking callback.
45
add_filter( 'user_has_cap', '\\WordPress\\Tabulate\\DB\\Grants::check', 0, 3 );
46
47
// Activation hooks. Uninstall is handled by uninstall.php.
48
add_action( 'activate_' . TABULATE_SLUG, '\\WordPress\\Tabulate\\DB\\ChangeTracker::activate' );
49
add_action( 'activate_' . TABULATE_SLUG, '\\WordPress\\Tabulate\\DB\\Reports::activate' );
50
add_action( 'activate_' . TABULATE_SLUG, function() {
51
	// Clean up out-of-date option.
52
	delete_option( TABULATE_SLUG . '_managed_tables' );
53
});
54
55
// Register JSON API.
56
add_action( 'rest_api_init', function() {
57
	global $wpdb;
58
	$api_controller = new \WordPress\Tabulate\Controllers\ApiController( $wpdb, $_GET );
59
	$api_controller->register_routes();
60
} );
61
62
// Shortcode.
63
$shortcode = new \WordPress\Tabulate\Controllers\ShortcodeController( $wpdb );
64
add_shortcode( TABULATE_SLUG, array( $shortcode, 'run' ) );
65
66
// Dashboard widget.
67
add_action( 'wp_dashboard_setup', function() {
68
	wp_add_dashboard_widget( TABULATE_SLUG . 'dashboard_widget', 'Tabulate', function() {
69
		$template = new \WordPress\Tabulate\Template( 'quick_jump.html' );
70
		echo $template->render();
71
	} );
72
} );
73