-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
123 lines (98 loc) · 4.57 KB
/
functions.php
File metadata and controls
123 lines (98 loc) · 4.57 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
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
<?php
// add scripts and styles for user
function arc_theme_scripts(){
wp_enqueue_style( 'arc-style', get_template_directory_uri() . '/assets/css/style.css', array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri(). '/assets/lib/bootstrap/css/bootstrap.min.css' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_style( 'fontawesome-css', get_template_directory_uri(). '/assets/lib/font-awesome/css/font-awesome.min.css' , array(), wp_get_theme()->get( 'Version' ) );
// wp_enqueue_style( 'animate-css', get_template_directory_uri(). '/assets/lib/animate/animate.min.css' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'jquery-script', get_template_directory_uri(). '/assets/lib/jquery/jquery.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'jquery-migrate-script', get_template_directory_uri(). '/assets/lib/jquery/jquery-migrate.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'bootstrap-script', get_template_directory_uri(). '/assets/lib/bootstrap/js/bootstrap.bundle.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'wow-script', get_template_directory_uri(). '/assets/lib/wow/wow.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'arc-script', get_template_directory_uri(). '/assets/js/main.js' , array(), wp_get_theme()->get( 'Version' ) );
}
add_action( 'wp_enqueue_scripts', 'arc_theme_scripts' );
// add scripts and styles for admin
function arc_admin_scripts(){
wp_enqueue_style( 'arc-datatables-style', get_template_directory_uri() . '/admin_pages/css/jquery.dataTables.min.css', array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'jquery-script', get_template_directory_uri(). '/assets/lib/jquery/jquery.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'jquery-migrate-script', get_template_directory_uri(). '/assets/lib/jquery/jquery-migrate.min.js' , array(), wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'arc-datatables-script', get_template_directory_uri(). '/admin_pages/js/jquery.dataTables.min.js' , array(), wp_get_theme()->get( 'Version' ) );
}
add_action( 'admin_enqueue_scripts', 'arc_admin_scripts' );
// this function run when theme is installed for the first time
function run_once_code() {
if ( get_option( 'page_function_run' ) != 'completed' ) {
$form_page = array(
'post_type' => 'page',
'post_title' => 'Form',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1
);
$invoice = array(
'post_type' => 'page',
'post_title' => 'Invoice',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1
);
$form_page_id = wp_insert_post( $form_page );
$form_render_id = wp_insert_post( $invoice );
update_post_meta($form_page_id, '_wp_page_template', 'form.php');
update_post_meta($form_render_id, '_wp_page_template', 'admin_invoice.php');
update_option( 'page_function_run', 'completed' );
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%postname%/' );
global $wpdb;
$sql = "CREATE TABLE `{$wpdb->base_prefix}invoices` (
`id` INT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(100),
`middle_name` VARCHAR(100),
`last_name` VARCHAR(100),
`gender` VARCHAR(10),
`email` VARCHAR(100),
`phone_personal` INT,
`phone_parent` INT,
`address` TEXT,
`department` VARCHAR(50),
`batch` VARCHAR(10),
`uni_number` INT,
`company` VARCHAR(100),
`higher_studies` varchar(255),
PRIMARY KEY (`id`)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
/*
* if you want to reset the settings and rerun the run_once_code() function
* replace reset_settings() function with run_once_code() in admin_init()
* and switch the theme and activate this theme again
* then replace reset_settings with run_once_code and switch this theme and active this theme again
*/
function reset_settings(){
update_option( 'page_function_run', 'not completed' );
}
add_action( 'admin_init', 'run_once_code' );
// get asset function
function get_asset($url){
return get_template_directory_uri() . '/assets/' . $url;
}
// add admin page for managing invoices
function add_invoice_page() {
add_menu_page(
__( 'Invoice', 'invoice' ),
__( 'Invoice', 'invoice' ),
'manage_options',
'invoice-page',
'invoice_page',
'dashicons-text-page',
4
);
}
add_action( 'admin_menu', 'add_invoice_page' );
function invoice_page() {
include_once 'admin_pages/admin_invoice.php';
}