This repository was archived by the owner on Nov 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.php
More file actions
136 lines (127 loc) · 5.98 KB
/
schema.php
File metadata and controls
136 lines (127 loc) · 5.98 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
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
Plugin Name: JSON Schema
Plugin URI: https://github.com/Sanj718
Description: Plugin for displaying schema in the head as JSON format.
Author: Sanjar Sobirjonov
Version: 2.0
Author URI: https://github.com/Sanj718
*/
class Schema{
public function __construct(){
require_once(ABSPATH . 'wp-config.php');
mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
}
public function create_menu(){
function schema_admin_actions() {
add_menu_page("Json Schema", "Json Schema", 1, "jsonschema", 'schema_admin');
add_submenu_page( 'jsonschema', 'Page title', 'Schema Config', 'manage_options', 'schema-config', 'schema_config_page');
}
add_action('admin_menu', 'schema_admin_actions');
function schema_admin(){
include('schema_admin.php');
}
function schema_config_page() {
include('schema_config.php');
}
}
public function schematohead(){
function schema_to_head(){
$ind = get_option('schema_individual');$i = 0;
if (is_array($ind) || is_object($ind)){foreach ($ind as $in){if ($in == get_the_ID()){$i = get_the_ID();}}}
if ($i == 0 && empty($i)){
?>
<script type="application/ld+json">
{
"@context": {
"@vocab": "http://schema.org/"
},
"@graph": [
{
"@id": "<?php echo get_option('schema_url'); ?>",
"@type": "Organization",
"name": "<?php echo get_option('schema_name'); ?>",
"url" : "<?php echo get_option('schema_url'); ?>",
"logo" : "<?php echo get_option('schema_logo'); ?>",
"sameAs" : <?php $t = explode(',', get_option('schema_socials'));
$result = "";foreach ($t as $r) {$result .= '"' . trim($r) . '", ';}
$re = rtrim($result, ", ");echo "[ " . $re . " ]";; ?>,
"address": {
"@type": "PostalAddress",
"addressLocality": "<?php echo get_option('schema_city'); ?>",
"addressRegion": "<?php echo ucwords(get_option('schema_state')); ?>",
"postalCode": "<?php echo get_option('schema_zip'); ?>",
"streetAddress": "<?php echo get_option('schema_street'); ?>",
"telephone": "<?php echo get_option('schema_phone'); ?>"
},
"hasmap" : "<?php echo get_option('schema_map'); ?>",
"image" : "<?php echo get_option('schema_logo'); ?>"
}<?php if (get_option('schema_location') == "multi") { ?>,
<?php $loop = get_option('schema_locnumber');
$i = 1;
while ($loop > 0) {
?>
{
"@type": "LocalBusiness",
"parentOrganization": {
"name" : "<?php echo get_option('schema_name'); ?>"
},
"name" : "<?php echo get_option('schema_sub_name' . $i); ?>",
"address": {
"@type" : "PostalAddress",
"streetAddress": "<?php echo get_option('schema_sub_street' . $i); ?>",
"addressLocality": "<?php echo get_option('schema_sub_city' . $i); ?>",
"addressRegion": "<?php echo ucwords(get_option('schema_sub_state' . $i)); ?>",
"postalCode": "<?php echo get_option('schema_sub_zip' . $i); ?>",
"telephone" : "<?php echo get_option('schema_sub_phone' . $i); ?>"
},
"hasmap" : "<?php echo get_option('schema_sub_map' . $i); ?>",
"image" : "<?php echo get_option('schema_logo'); ?>"
}<?php $i++;
$loop--;
if ($loop != 0) { ?>,
<?php }
}
} ?>
]
}
</script> <?php
}else{
?>
<script type="application/ld+json">
{
"@context": {
"@vocab": "http://schema.org/"
},
"@graph": [
{
"@id": "<?php echo get_option('schema_ind_url'.$i); ?>",
"@type": "LocalBusiness",
"name": "<?php echo get_option('schema_ind_name'.$i); ?>",
"url" : "<?php echo get_option('schema_ind_url'.$i); ?>",
"logo" : "<?php echo get_option('schema_ind_logo'.$i); ?>",
"image" : "<?php echo get_option('schema_ind_logo'.$i); ?>",
"sameAs" : <?php $t = explode(',', get_option('schema_ind_socials'.$i));
$result = "";foreach ($t as $r) {$result .= '"' . trim($r) . '", ';}
$re = rtrim($result, ", ");echo "[ " . $re . " ]"; ?>,
"address": {
"@type": "PostalAddress",
"addressLocality": "<?php echo get_option('schema_ind_city'.$i);?>",
"addressRegion": "<?php echo ucwords(get_option('schema_ind_state'.$i));?>",
"postalCode": "<?php echo get_option('schema_ind_zip'.$i);?>",
"streetAddress": "<?php echo get_option('schema_ind_street'.$i);?>",
"telephone": "<?php echo get_option('schema_ind_phone'.$i);?>"
}
}
]
}
</script>
<?php
}
}
add_action( 'wp_head', 'schema_to_head' );
}
}
$schema = new Schema;
$schema->create_menu();
$schema->schematohead();