Spaces:
No application file
No application file
File size: 5,036 Bytes
209ce8e | 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 115 116 117 118 119 120 121 122 123 124 | <?php
/**
* Plugin Name: DevOps & Infrastructure Invoice and Payment WordPress Plugin
* Description: Generate invoices, accept payments, track revenue, and automate receipts for DevOps & Infrastructure. All-in-one financial management for DevOps & Infrastructure sites.
* Version: 1.0.0
* Author: Digital Forge
* Text Domain: cb077b0d
* License: GPL-2.0+
*/
if ( ! defined( 'ABSPATH' ) ) exit;
define( 'CB077B0D_VERSION', '1.0.0' );
define( 'CB077B0D_DIR', plugin_dir_path( __FILE__ ) );
class Cb077b0d {
private static $instance = null;
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action( 'init', [ $this, 'init' ] );
add_action( 'admin_menu', [ $this, 'admin_menu' ] );
add_action( 'admin_init', [ $this, 'settings_init' ] );
add_action( 'rest_api_init', [ $this, 'register_routes' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
load_plugin_textdomain( 'cb077b0d', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
public function init() {}
public function admin_menu() {
add_options_page(
esc_html__( 'DevOps & Infrastructure Invoice and Payment WordPress Plugin Settings', 'cb077b0d' ),
esc_html__( 'DevOps & Infrastructure Invoice and Payment WordPress Plugin', 'cb077b0d' ),
'manage_options',
'cb077b0d-settings',
[ $this, 'settings_page' ]
);
}
public function settings_init() {
register_setting( 'cb077b0d_options', 'cb077b0d_options', [ $this, 'sanitize_options' ] );
add_settings_section( 'cb077b0d_main', '', '__return_false', 'cb077b0d-settings' );
add_settings_field( 'enabled', esc_html__( 'Enable', 'cb077b0d' ), [ $this, 'field_enabled' ], 'cb077b0d-settings', 'cb077b0d_main' );
}
public function sanitize_options( $input ) {
$clean = [];
$clean['enabled'] = ! empty( $input['enabled'] ) ? 1 : 0;
return $clean;
}
public function field_enabled() {
$opts = get_option( 'cb077b0d_options', [] );
$val = ! empty( $opts['enabled'] ) ? 1 : 0;
echo '<input type="checkbox" name="cb077b0d_options[enabled]" value="1"' . checked( $val, 1, false ) . ' />';
}
public function settings_page() {
if ( ! current_user_can( 'manage_options' ) ) return;
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form method="post" action="options.php">
<?php settings_fields( 'cb077b0d_options' ); ?>
<?php do_settings_sections( 'cb077b0d-settings' ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
public function register_routes() {
register_rest_route( 'cb077b0d/v1', '/data', [
[ 'methods' => 'GET', 'callback' => [ $this, 'rest_get' ], 'permission_callback' => '__return_true' ],
[ 'methods' => 'POST', 'callback' => [ $this, 'rest_post' ], 'permission_callback' => function() { return current_user_can( 'manage_options' ); } ],
] );
}
public function rest_get( $request ) {
return rest_ensure_response( [ 'status' => 'ok', 'plugin' => 'cb077b0d' ] );
}
public function rest_post( $request ) {
$data = $request->get_json_params();
return rest_ensure_response( [ 'received' => $data ] );
}
public function enqueue_admin_assets( $hook ) {
if ( 'settings_page_cb077b0d-settings' !== $hook ) return;
wp_enqueue_style( 'cb077b0d-admin', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css', [], '1.0.0' );
wp_enqueue_script( 'cb077b0d-admin', plugin_dir_url( __FILE__ ) . 'assets/js/admin.js', [ 'jquery' ], '1.0.0', true );
wp_localize_script( 'cb077b0d-admin', 'cb077b0d_vars', [ 'nonce' => wp_create_nonce( 'cb077b0d-nonce' ), 'ajax_url' => admin_url( 'admin-ajax.php' ) ] );
}
public static function activate() {
global $wpdb;
$table = $wpdb->prefix . 'cb077b0d';
$charset = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table (
id bigint(20) NOT NULL AUTO_INCREMENT,
data longtext NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) $charset;";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
add_option( 'cb077b0d_db_version', '1.0.0' );
}
public static function deactivate() {}
}
register_activation_hook( __FILE__, [ 'Cb077b0d', 'activate' ] );
register_deactivation_hook( __FILE__, [ 'Cb077b0d', 'deactivate' ] );
Cb077b0d::instance();
|