hooks();
( new Cron() )->hooks();
( new Privacy() )->hooks();
( new Frontend() )->hooks();
if ( is_admin() ) {
( new Admin() )->hooks();
}
add_filter( 'plugin_action_links_' . plugin_basename( TABLEENGINE_FILE ), array( $this, 'action_links' ) );
do_action( 'tableengine_loaded', $this );
}
/**
* Scripts shared by the booking widget and admin screens: the hooks bus
* (window.tableengine.hooks) and the floor plan renderer.
*/
public static function register_shared_scripts() {
if ( wp_script_is( 'tableengine-hooks', 'registered' ) ) {
return;
}
wp_register_script( 'tableengine-hooks', TABLEENGINE_URL . 'assets/js/hooks.js', array( 'wp-hooks' ), self::ver( 'assets/js/hooks.js' ), true );
wp_register_script( 'tableengine-render', TABLEENGINE_URL . 'assets/js/render.js', array( 'tableengine-hooks' ), self::ver( 'assets/js/render.js' ), true );
}
/**
* Dependencies for a TableEngine script. Extensions add their own handles here so
* their hooks are registered before the app boots.
*/
public static function script_deps( $handle, array $deps ) {
return array_values( array_unique( (array) apply_filters( 'tableengine_script_dependencies', $deps, $handle ) ) );
}
public function action_links( $links ) {
array_unshift(
$links,
'' . esc_html__( 'Settings', 'tableengine' ) . '',
'' . esc_html__( 'Floor plans', 'tableengine' ) . ''
);
return $links;
}
/**
* Asset version that changes whenever the file does (cache busting).
*/
public static function ver( $rel ) {
$file = TABLEENGINE_DIR . $rel;
return TABLEENGINE_VERSION . ( file_exists( $file ) ? '.' . filemtime( $file ) : '' );
}
/**
* Areas of the plugin with their own permission.
*/
const AREAS = array( 'bookings', 'floorplans', 'guests', 'reports', 'payments', 'settings' );
/**
* Capability required for an area: bookings (dashboard, seating), floorplans (editing rooms),
* guests, reports, payments (refunds, deleting bookings) or settings. All areas default to
* manage_options; extensions map them to finer capabilities (staff roles).
*/
public static function cap( $area = 'bookings' ) {
return apply_filters( 'tableengine_capability', 'manage_options', $area );
}
/** Can the current user use an area? */
public static function can( $area = 'bookings' ) {
return current_user_can( self::cap( $area ) );
}
}