-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoc-builder-by-robertivan.php
More file actions
79 lines (65 loc) · 2.07 KB
/
toc-builder-by-robertivan.php
File metadata and controls
79 lines (65 loc) · 2.07 KB
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
<?php
/**
* Plugin Name: TOC Builder by RobertIvan
* Plugin URI:
* Description: An ultra-advanced Table of Contents generator with smooth scroll, Gutenberg support, and high configurability.
* Version: 1.3.0
* Author: Robert Ivan
* Author URI: https://github.com/robertivan/
* License: GPLv2 or later
* Text Domain: toc-builder-by-robertivan
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Define Constants
define( 'TBRV_VERSION', '1.3.0' );
define( 'TBRV_PATH', plugin_dir_path( __FILE__ ) );
define( 'TBRV_URL', plugin_dir_url( __FILE__ ) );
// Include Classes
require_once TBRV_PATH . 'includes/class-toc-settings.php';
require_once TBRV_PATH . 'includes/class-toc-generator.php';
require_once TBRV_PATH . 'includes/class-toc-block.php';
/**
* Main Plugin Class
*/
class TBRV_Plugin {
private static $instance = null;
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
// Initialize Settings
$this->settings = new TBRV_Settings();
// Initialize Generator (Frontend)
$this->generator = new TBRV_Generator();
// Initialize Block (Gutenberg)
$this->block = new TBRV_Block();
// Load Assets
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) );
}
public function enqueue_assets() {
if ( is_singular() ) {
wp_enqueue_style( 'tbrv-style', TBRV_URL . 'assets/css/style.css', array(), TBRV_VERSION );
wp_enqueue_script( 'tbrv-script', TBRV_URL . 'assets/js/script.js', array(), TBRV_VERSION, true );
}
}
}
// Initialize Plugin
function tbrv_init() {
TBRV_Plugin::get_instance();
}
add_action( 'plugins_loaded', 'tbrv_init' );
// Migration function for settings
function tbrv_migrate_settings() {
$old_options = get_option( 'toc_master_options' );
$new_options = get_option( 'tbrv_options' );
// Only migrate if old options exist and new options don't
if ( $old_options && ! $new_options ) {
update_option( 'tbrv_options', $old_options );
}
}
register_activation_hook( __FILE__, 'tbrv_migrate_settings' );