Schema & Structured Data for WP & AMP - Version 1.0

Version Description

(6 August 2018) = * Version 1.0 Released

Download this release

Release Info

Developer mohammed_kaludi
Plugin Icon 128x128 Schema & Structured Data for WP & AMP
Version 1.0
Comparing to
See all releases

Version 1.0

admin_section/ajax-selectbox.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_action('wp_ajax_create_ajax_select_sdwp','saswp_ajax_select_creator');
3
+ function saswp_ajax_select_creator($data = '', $saved_data= '', $current_number = '') {
4
+
5
+ $response = $data;
6
+ $is_ajax = false;
7
+ if( $_SERVER['REQUEST_METHOD']=='POST'){
8
+ $is_ajax = true;
9
+ if(wp_verify_nonce($_POST["saswp_call_nonce"],'saswp_select_action_nonce')){
10
+
11
+ if ( isset( $_POST["id"] ) ) {
12
+ $response = sanitize_text_field(wp_unslash($_POST["id"]));
13
+ }
14
+ if ( isset( $_POST["number"] ) ) {
15
+ $current_number = intval($_POST["number"]);
16
+ }
17
+ }else{
18
+ exit;
19
+ }
20
+
21
+ }
22
+ // send the response back to the front end
23
+ // vars
24
+ $choices = array();
25
+
26
+ $options['param'] = $response;
27
+ // some case's have the same outcome
28
+ if($options['param'] == "page_parent")
29
+ {
30
+ $options['param'] = "page";
31
+ }
32
+
33
+ switch($options['param'])
34
+ {
35
+ case "post_type":
36
+
37
+ $choices = saswp_post_type_generator();
38
+
39
+ $choices = apply_filters('saswp_modify_select_post_type', $choices );
40
+ break;
41
+
42
+ case "page":
43
+
44
+ $post_type = 'page';
45
+ $posts = get_posts(array(
46
+ 'posts_per_page' => -1,
47
+ 'post_type' => $post_type,
48
+ 'orderby' => 'menu_order title',
49
+ 'order' => 'ASC',
50
+ 'post_status' => 'any',
51
+ 'suppress_filters' => false,
52
+ 'update_post_meta_cache' => false,
53
+ ));
54
+
55
+ if( $posts )
56
+ {
57
+ // sort into hierachial order!
58
+ if( is_post_type_hierarchical( $post_type ) )
59
+ {
60
+ $posts = get_page_children( 0, $posts );
61
+ }
62
+
63
+ foreach( $posts as $page )
64
+ {
65
+ $title = '';
66
+ $ancestors = get_ancestors($page->ID, 'page');
67
+ if($ancestors)
68
+ {
69
+ foreach($ancestors as $a)
70
+ {
71
+ $title .= '- ';
72
+ }
73
+ }
74
+
75
+ $title .= apply_filters( 'the_title', $page->post_title, $page->ID );
76
+ // status
77
+ if($page->post_status != "publish")
78
+ {
79
+ $title .= " ($page->post_status)";
80
+ }
81
+
82
+ $choices[ $page->ID ] = $title;
83
+
84
+ }
85
+ // foreach($pages as $page)
86
+
87
+ }
88
+
89
+ break;
90
+
91
+ case "page_template" :
92
+
93
+ $choices = array(
94
+ 'default' => esc_html__('Default Template','schema-and-structured-data-for-wp'),
95
+ );
96
+
97
+ $templates = get_page_templates();
98
+ foreach($templates as $k => $v)
99
+ {
100
+ $choices[$v] = $k;
101
+ }
102
+
103
+ break;
104
+
105
+ case "post" :
106
+
107
+ $post_types = get_post_types();
108
+
109
+ unset( $post_types['page'], $post_types['attachment'], $post_types['revision'] , $post_types['nav_menu_item'], $post_types['acf'] , $post_types['amp_acf'] );
110
+
111
+ if( $post_types )
112
+ {
113
+ foreach( $post_types as $post_type )
114
+ {
115
+
116
+ $posts = get_posts(array(
117
+ 'numberposts' => '-1',
118
+ 'post_type' => $post_type,
119
+ 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
120
+ 'suppress_filters' => false,
121
+ ));
122
+
123
+ if( $posts)
124
+ {
125
+ $choices[$post_type] = array();
126
+
127
+ foreach($posts as $post)
128
+ {
129
+ $title = apply_filters( 'the_title', $post->post_title, $post->ID );
130
+
131
+ // status
132
+ if($post->post_status != "publish")
133
+ {
134
+ $title .= " ($post->post_status)";
135
+ }
136
+
137
+ $choices[$post_type][$post->ID] = $title;
138
+
139
+ }
140
+ // foreach($posts as $post)
141
+ }
142
+ // if( $posts )
143
+ }
144
+ // foreach( $post_types as $post_type )
145
+ }
146
+ // if( $post_types )
147
+
148
+
149
+ break;
150
+
151
+ case "post_category" :
152
+
153
+ $terms = get_terms( 'category', array( 'hide_empty' => false ) );
154
+
155
+ if( !empty($terms) ) {
156
+
157
+ foreach( $terms as $term ) {
158
+
159
+ $choices[ $term->term_id ] = $term->name;
160
+
161
+ }
162
+
163
+ }
164
+
165
+ break;
166
+
167
+ case "post_format" :
168
+
169
+ $choices = get_post_format_strings();
170
+
171
+ break;
172
+
173
+ case "user_type" :
174
+ global $wp_roles;
175
+ $choices = $wp_roles->get_names();
176
+
177
+ if( is_multisite() )
178
+ {
179
+ $choices['super_admin'] = esc_html__('Super Admin','schema-and-structured-data-for-wp');
180
+ }
181
+
182
+ break;
183
+
184
+ case "ef_taxonomy" :
185
+
186
+ $choices = array('all' => esc_html__('All','schema-and-structured-data-for-wp'));
187
+ $taxonomies = saswp_post_taxonomy_generator();
188
+ $choices = array_merge($choices, $taxonomies);
189
+ break;
190
+
191
+ }
192
+ // allow custom location rules
193
+ $choices = $choices;
194
+
195
+ // Add None if no elements found in the current selected items
196
+ if ( empty( $choices) ) {
197
+ $choices = array('none' => esc_html__('No Items', 'schema-and-structured-data-for-wp') );
198
+ }
199
+ // echo $current_number;
200
+ // echo $saved_data;
201
+
202
+ $output = '<select class="widefat ajax-output" name="data_array['. esc_attr($current_number) .'][key_3]">';
203
+
204
+ // Generate Options for Posts
205
+ if ( $options['param'] == 'post' ) {
206
+ foreach ($choices as $choice_post_type) {
207
+ foreach ($choice_post_type as $key => $value) {
208
+ if ( $saved_data == $key ) {
209
+ $selected = 'selected="selected"';
210
+ } else {
211
+ $selected = '';
212
+ }
213
+
214
+ $output .= '<option '. esc_attr($selected) .' value="' . esc_attr($key) .'"> ' . esc_html__($value, 'schema-and-structured-data-for-wp') .' </option>';
215
+ }
216
+ }
217
+ // Options for Other then posts
218
+ } else {
219
+ foreach ($choices as $key => $value) {
220
+ if ( $saved_data == $key ) {
221
+ $selected = 'selected="selected"';
222
+ } else {
223
+ $selected = '';
224
+ }
225
+
226
+ $output .= '<option '. esc_attr($selected) .' value="' . esc_attr($key) .'"> ' . esc_html__($value, 'schema-and-structured-data-for-wp') .' </option>';
227
+ }
228
+ }
229
+ $output .= ' </select> ';
230
+ $allowed_html = saswp_expanded_allowed_tags();
231
+ echo wp_kses($output, $allowed_html);
232
+
233
+ if ( $is_ajax ) {
234
+ die();
235
+ }
236
+ // endif;
237
+
238
+ }
239
+ // Generate Proper Post Taxonomy for select and to add data.
240
+ function saswp_post_taxonomy_generator(){
241
+ $taxonomies = '';
242
+ $choices = array();
243
+ $taxonomies = get_taxonomies( array('public' => true), 'objects' );
244
+
245
+
246
+ foreach($taxonomies as $taxonomy) {
247
+ $choices[ $taxonomy->name ] = $taxonomy->labels->name;
248
+ }
249
+
250
+ // unset post_format (why is this a public taxonomy?)
251
+ if( isset($choices['post_format']) ) {
252
+ unset( $choices['post_format']) ;
253
+ }
254
+
255
+ return $choices;
256
+ }
257
+ add_action('wp_ajax_create_ajax_select_sdwp_taxonomy','saswp_create_ajax_select_taxonomy');
258
+
259
+ function saswp_create_ajax_select_taxonomy($selectedParentValue = '',$selectedValue='', $current_number =''){
260
+ $is_ajax = false;
261
+ if( $_SERVER['REQUEST_METHOD']=='POST'){
262
+ $is_ajax = true;
263
+ if(wp_verify_nonce($_POST["saswp_call_nonce"],'saswp_select_action_nonce')){
264
+ if(isset($_POST['id'])){
265
+ $selectedParentValue = sanitize_text_field(wp_unslash($_POST['id']));
266
+ }
267
+ if(isset($_POST['number'])){
268
+ $current_number = intval($_POST['number']);
269
+ }
270
+ }else{
271
+ exit;
272
+ }
273
+ }
274
+ $taxonomies = array();
275
+ if($selectedParentValue == 'all'){
276
+ $taxonomies = get_terms( array(
277
+ 'hide_empty' => true,
278
+ ) );
279
+ }else{
280
+ $taxonomies = get_terms($selectedParentValue, array(
281
+ 'hide_empty' => true,
282
+ ) );
283
+ }
284
+ $choices = '<option value="all">'.esc_html__('All','schema-and-structured-data-for-wp').'</option>';
285
+ foreach($taxonomies as $taxonomy) {
286
+ $sel="";
287
+ if($selectedValue == $taxonomy->slug){
288
+ $sel = "selected";
289
+ }
290
+ $choices .= '<option value="'.esc_attr($taxonomy->slug).'" '.esc_attr($sel).'>'.esc_html__($taxonomy->name,'schema-and-structured-data-for-wp').'</option>';
291
+ }
292
+ $allowed_html = saswp_expanded_allowed_tags();
293
+ echo '<select class="widefat ajax-output-child" name="data_array['. esc_attr($current_number) .'][key_4]">'. wp_kses($choices, $allowed_html).'</select>';
294
+ if($is_ajax){
295
+ die;
296
+ }
297
+ }
admin_section/common-function.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //Function to expand html tags form allowed html tags in wordpress
3
+ function saswp_expanded_allowed_tags() {
4
+ $my_allowed = wp_kses_allowed_html( 'post' );
5
+ // form fields - input
6
+ $my_allowed['input'] = array(
7
+ 'class' => array(),
8
+ 'id' => array(),
9
+ 'name' => array(),
10
+ 'value' => array(),
11
+ 'type' => array(),
12
+ 'style' => array(),
13
+ 'placeholder' => array(),
14
+ 'maxlength' => array(),
15
+ 'checked' => array(),
16
+ 'readonly' => array(),
17
+ 'disabled' => array(),
18
+ 'width' => array(),
19
+ 'data-id' => array()
20
+ );
21
+ $my_allowed['hidden'] = array(
22
+ 'id' => array(),
23
+ 'name' => array(),
24
+ 'value' => array(),
25
+ 'type' => array(),
26
+ 'data-id' => array(),
27
+ );
28
+ //number
29
+ $my_allowed['number'] = array(
30
+ 'class' => array(),
31
+ 'id' => array(),
32
+ 'name' => array(),
33
+ 'value' => array(),
34
+ 'type' => array(),
35
+ 'style' => array(),
36
+ 'width' => array(),
37
+ );
38
+ //textarea
39
+ $my_allowed['textarea'] = array(
40
+ 'class' => array(),
41
+ 'id' => array(),
42
+ 'name' => array(),
43
+ 'value' => array(),
44
+ 'type' => array(),
45
+ 'style' => array(),
46
+ 'rows' => array(),
47
+ );
48
+ // select
49
+ $my_allowed['select'] = array(
50
+ 'class' => array(),
51
+ 'id' => array(),
52
+ 'name' => array(),
53
+ 'value' => array(),
54
+ 'type' => array(),
55
+ );
56
+ // checkbox
57
+ $my_allowed['checkbox'] = array(
58
+ 'class' => array(),
59
+ 'id' => array(),
60
+ 'name' => array(),
61
+ 'value' => array(),
62
+ 'type' => array(),
63
+ );
64
+ // options
65
+ $my_allowed['option'] = array(
66
+ 'selected' => array(),
67
+ 'value' => array(),
68
+ );
69
+ // style
70
+ $my_allowed['style'] = array(
71
+ 'types' => array(),
72
+ );
73
+ return $my_allowed;
74
+ }
75
+ function saswp_admin_link($tab = '', $args = array()){
76
+
77
+ $page = 'structured_data_options';
78
+ if ( ! is_multisite() ) {
79
+ $link = admin_url( 'admin.php?page=' . $page );
80
+ }
81
+ else {
82
+ $link = network_admin_url( 'admin.php?page=' . $page );
83
+ }
84
+
85
+ if ( $tab ) {
86
+ $link .= '&tab=' . $tab;
87
+ }
88
+
89
+ if ( $args ) {
90
+ foreach ( $args as $arg => $value ) {
91
+ $link .= '&' . $arg . '=' . urlencode( $value );
92
+ }
93
+ }
94
+
95
+ return esc_url($link);
96
+ }
97
+ function saswp_get_tab( $default = '', $available = array() ) {
98
+
99
+ $tab = isset( $_GET['tab'] ) ? sanitize_text_field(wp_unslash($_GET['tab'])) : $default;
100
+ if ( ! in_array( $tab, $available ) ) {
101
+ $tab = $default;
102
+ }
103
+
104
+ return $tab;
105
+ }
106
+
107
+ $sd_data=array();
108
+ function saswp_defaultSettings(){
109
+ global $sd_data;
110
+ $defaults = array(
111
+ 'saswp-for-wordpress' => 0,
112
+ 'saswp-for-amp' => 0,
113
+ );
114
+ $sd_data = $settings = get_option( 'sd_data', $defaults);
115
+ return $settings;
116
+ }
117
+ saswp_defaultSettings();
admin_section/css/main-style.css ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ To change this license header, choose License Headers in Project Properties.
3
+ To change this template file, choose Tools | Templates
4
+ and open the template in the editor.
5
+ */
6
+ /*
7
+ Created on : Jul 27, 2018, 5:36:26 PM
8
+ Author : Magazine3
9
+ */
10
+ .saswp-general table th{
11
+ width: auto;
12
+ font-weight: 600;
13
+ padding: 0px;
14
+ }
15
+ .saswp-knowledge table th{
16
+ width: auto;
17
+ padding: 0px;
18
+ }
19
+ .saswp-schema table th{
20
+ width: auto;
21
+ padding: 0px;
22
+ }
23
+ .saswp-help table th{
24
+ width: auto;
25
+ padding: 0px;
26
+ }
27
+ .saswp-settings-list{
28
+ display:inline-block;
29
+ width:100%
30
+ }
31
+ .saswp-settings-list li{
32
+ padding:15px;
33
+ padding-left:0px;
34
+ }
35
+ .saswp-settings-list li div label{
36
+ font-weight: 600;
37
+ }
38
+ .saswp-general h2{
39
+ margin-bottom: 0px;
40
+ }
41
+ .saswp-knowledge h2{
42
+ margin-bottom: 0px;
43
+ }
44
+ .saswp-schema h2{
45
+ margin-bottom: 0px;
46
+ }
47
+ .saswp-help h2{
48
+ margin-bottom: 0px;
49
+ }
50
+ .saswp-settings-form p.submit{
51
+ margin-top:0px;
52
+ }
53
+ .saswp_qanda_p{
54
+ font-weight: 500;
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+
admin_section/fields-generator.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Metabox to show ads type such as custom and adsense
4
+ */
5
+ class saswp_fields_generator {
6
+
7
+ public function saswp_field_generator( $meta_fields, $settings ) {
8
+ $output = '';
9
+ foreach ( $meta_fields as $meta_field ) {
10
+
11
+ $class = "";
12
+ $note = "";
13
+ $hidden = array();
14
+ if(array_key_exists('class', $meta_field)){
15
+ $class = $meta_field['class'];
16
+ }
17
+ if(array_key_exists('note', $meta_field)){
18
+ $note = $meta_field['note'];
19
+ }
20
+ if(array_key_exists('hidden', $meta_field)){
21
+ $hidden = $meta_field['hidden'];
22
+ }
23
+ $label = '<label for="' . esc_attr($meta_field['id']) . '">' . esc_html__( $meta_field['label'], 'schema-and-structured-data-for-wp' ) . '</label>';
24
+
25
+ switch ( $meta_field['type'] ) {
26
+ case 'media':
27
+ $mediavalue = $settings[$meta_field['id']];
28
+ $input = sprintf(
29
+ '<fieldset><input class="%s" style="width: 80%%" id="%s" name="%s" type="text" value="%s"> <input data-id="media" style="width: 19%%" class="button" id="%s_button" name="%s_button" type="button" value="Upload" />'
30
+ . '<input type="hidden" data-id="'.esc_attr($meta_field['id']).'_id" class="upload-id " name="sd_data['.esc_attr($meta_field['id']).'][id]" id="sd_data['.esc_attr($meta_field['id']).'][id]" value="'.esc_attr($mediavalue['id']).'">'
31
+ . '<input type="hidden" data-id="'.esc_attr($meta_field['id']).'_height" class="upload-height" name="sd_data['.esc_attr($meta_field['id']).'][height]" id="sd_data['.esc_attr($meta_field['id']).'][height]" value="'.esc_attr($mediavalue['height']).'">'
32
+ . '<input type="hidden" data-id="'.esc_attr($meta_field['id']).'_width" class="upload-width" name="sd_data['.esc_attr($meta_field['id']).'][width]" id="sd_data['.esc_attr($meta_field['id']).'][width]" value="'.esc_attr($mediavalue['width']).'">'
33
+ . '<input type="hidden" data-id="'.esc_attr($meta_field['id']).'_thumbnail" class="upload-thumbnail" name="sd_data['.esc_attr($meta_field['id']).'][thumbnail]" id="sd_data['.esc_attr($meta_field['id']).'][thumbnail]" value="'.esc_attr($mediavalue['thumbnail']).'">'
34
+ . '</fieldset>',
35
+ $class,
36
+ esc_attr($meta_field['id']),
37
+ esc_attr($meta_field['name']),
38
+ esc_url($mediavalue['url']),
39
+ esc_attr($meta_field['id']),
40
+ esc_attr($meta_field['id'])
41
+ );
42
+ break;
43
+ case 'checkbox':
44
+ $hiddenvalue ="";
45
+ if(array_key_exists('id', $hidden)){
46
+ $hiddenvalue = $settings[$hidden['id']];
47
+ }
48
+ $hiddenfield="";
49
+ if(!empty($hidden)){
50
+ $hiddenfield = sprintf(
51
+ '<input id="%s" name="%s" type="hidden" value="%s">',
52
+ esc_attr($hidden['id']),
53
+ esc_attr($hidden['name']),
54
+ esc_attr($hiddenvalue)
55
+ );
56
+ }
57
+
58
+ $input = sprintf(
59
+ '<input class="%s" id="%s" name="%s" type="checkbox" %s>',
60
+ esc_attr($class),
61
+ esc_attr($meta_field['id']),
62
+ esc_attr($meta_field['name']),
63
+ $hiddenvalue == 1 ? 'checked' : ''
64
+ );
65
+
66
+ $input .=$hiddenfield;
67
+ break;
68
+
69
+ case 'select':
70
+ $input = sprintf(
71
+ '<select class="%s" id="%s" name="%s">',
72
+ $class,
73
+ esc_attr($meta_field['id']),
74
+ esc_attr($meta_field['name'])
75
+ );
76
+ foreach ( $meta_field['options'] as $key => $value ) {
77
+ $input .= sprintf(
78
+ '<option %s value="%s">%s</option>',
79
+ $settings[$meta_field['id']] == $key ? 'selected' : '',
80
+ $key,
81
+ esc_html__( $value, 'schema-and-structured-data-for-wp' )
82
+ );
83
+ }
84
+ $input .= '</select>';
85
+ break;
86
+ default:
87
+ $input = sprintf(
88
+ '<input class="%s" %s id="%s" name="%s" type="%s" value="%s">',
89
+ $class,
90
+ $meta_field['type'] !== 'color' ? 'style="width: 100%"' : '',
91
+ esc_attr($meta_field['id']),
92
+ esc_attr($meta_field['name']),
93
+ esc_attr($meta_field['type']),
94
+ esc_attr($settings[$meta_field['id']])
95
+ );
96
+ }
97
+
98
+ $allowed_html = saswp_expanded_allowed_tags();
99
+ $output .= '<li><div style="width:200px;float:left;clear: both;">'.$label.'</div><div style="width:75%; float:right;">'.$input.'<p>'.esc_html__($note,'schema-and-structured-data-for-wp').'</p></div></li>';
100
+ }
101
+ echo '<div style="width:85%;"><div class="saswp-settings-list"><ul>' . wp_kses($output, $allowed_html) . '</ul></div></div>';
102
+ }
103
+ }
admin_section/js/main-script.js ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function getParameterByName(name, url) {
2
+ if (!url){
3
+ url = window.location.href;
4
+ }
5
+ name = name.replace(/[\[\]]/g, "\\$&");
6
+ var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
7
+ results = regex.exec(url);
8
+ if (!results) return null;
9
+ if (!results[2]) return "";
10
+ return decodeURIComponent(results[2].replace(/\+/g, " "));
11
+ }
12
+ jQuery(document).ready(function($){
13
+ $(".saswp-tabs a").click(function(e){
14
+ var href = $(this).attr('href');
15
+ var currentTab = getParameterByName('tab',href);
16
+ if(!currentTab){
17
+ currentTab = "general";
18
+ }
19
+ $(this).siblings().removeClass("nav-tab-active");
20
+ $(this).addClass("nav-tab-active");
21
+ $(".form-wrap").find(".saswp-"+currentTab).siblings().hide();
22
+ $(".form-wrap .saswp-"+currentTab).show();
23
+ window.history.pushState("", "", href);
24
+ return false;
25
+ });
26
+ //Settings page jquery starts here
27
+ $(".saswp-checkbox").change(function(){
28
+ var id = $(this).attr("id");
29
+ switch(id){
30
+ case 'saswp-for-wordpress-checkbox':
31
+
32
+ if ($(this).is(':checked')) {
33
+ $("#saswp-for-wordpress").val(1);
34
+ }else{
35
+ $("#saswp-for-wordpress").val(0);
36
+ }
37
+ break;
38
+ case 'saswp-for-amp-checkbox':
39
+
40
+ if ($(this).is(':checked')) {
41
+ $("#saswp-for-amp").val(1);
42
+ }else{
43
+ $("#saswp-for-amp").val(0);
44
+ }
45
+ break;
46
+ case 'saswp_kb_contact_1_checkbox':
47
+
48
+ if ($(this).is(':checked')) {
49
+ $("#saswp_kb_contact_1").val(1);
50
+ $("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').show();
51
+ }else{
52
+ $("#saswp_kb_contact_1").val(0);
53
+ $("#saswp_kb_telephone, #saswp_contact_type").parent().parent('li').hide();
54
+ }
55
+ break;
56
+ case 'saswp-logo-dimensions-check':
57
+
58
+ if ($(this).is(':checked')) {
59
+ $("#saswp-logo-dimensions").val(1);
60
+ $("#saswp-logo-width, #saswp-logo-height").parent().parent('li').show();
61
+ }else{
62
+ $("#saswp-logo-dimensions").val(0);
63
+ $("#saswp-logo-width, #saswp-logo-height").parent().parent('li').hide();
64
+ }
65
+ break;
66
+ case 'saswp_archive_schema_checkbox':
67
+
68
+ if ($(this).is(':checked')) {
69
+ $("#saswp_archive_schema").val(1);
70
+ }else{
71
+ $("#saswp_archive_schema").val(0);
72
+ }
73
+ break;
74
+ case 'saswp_breadcrumb_schema_checkbox':
75
+
76
+ if ($(this).is(':checked')) {
77
+ $("#saswp_breadcrumb_schema").val(1);
78
+ }else{
79
+ $("#saswp_breadcrumb_schema").val(0);
80
+ }
81
+ break;
82
+ default:
83
+ break;
84
+ }
85
+
86
+ }).change();
87
+
88
+ $("#saswp_kb_type").change(function(){
89
+ var datatype = $(this).val();
90
+ for(var i=1;i<=12;i++){
91
+ if(datatype ==="Person"){
92
+ if(i<8){
93
+ $( ".saswp-knowledge-base li:eq('"+i+"')" ).hide();
94
+ }else{
95
+ $( ".saswp-knowledge-base li:eq('"+i+"')" ).show();
96
+ }
97
+ }else{
98
+ if(i<8){
99
+ $( ".saswp-knowledge-base li:eq('"+i+"')" ).show();
100
+ }else{
101
+ $( ".saswp-knowledge-base li:eq('"+i+"')" ).hide();
102
+ }
103
+ }
104
+
105
+ }
106
+ }).change();
107
+ $("input[data-id=media]").click(function(e) { // Application Icon upload
108
+ e.preventDefault();
109
+ var button = $(this);
110
+ var id = button.attr('id').replace('_button', '');
111
+ var saswpMediaUploader = wp.media({
112
+ title: "Application Icon",
113
+ button: {
114
+ text: "Select Icon"
115
+ },
116
+ multiple: false // Set this to true to allow multiple files to be selected
117
+ })
118
+ .on("select", function() {
119
+ var attachment = saswpMediaUploader.state().get('selection').first().toJSON();
120
+
121
+ $("#"+id).val(attachment.url);
122
+ $("input[data-id='"+id+"_id']").val(attachment.id);
123
+ $("input[data-id='"+id+"_height']").val(attachment.height);
124
+ $("input[data-id='"+id+"_width']").val(attachment.width);
125
+ $("input[data-id='"+id+"_thumbnail']").val(attachment.url);
126
+ })
127
+ .open();
128
+ });
129
+ //Settings page jquery ends here
130
+ });
admin_section/js/structure_admin.js ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var clone = function(){
2
+ jQuery(".structured-clone").off("click").click(function(){
3
+ var selectrow = jQuery(document).find("#call_html_template_sdwp").html();
4
+ nextId = jQuery(this).parents("tbody").find("tr").length;
5
+ selectrow = selectrow.replace(/\[0\]/g, "["+nextId+"]");
6
+ console.log(selectrow);
7
+ jQuery(this).parents("tr").after(selectrow);removeHtml();clone();
8
+ });
9
+ }
10
+ var removeHtml = function(){
11
+ jQuery(".structured-delete").off("click").click(function(){
12
+ if(jQuery(this).parents("tbody").find("tr").length>1){
13
+ jQuery(this).parents("tr").remove();
14
+ }
15
+ });
16
+ }
17
+ jQuery(document).ready(function($){
18
+ var selectrow = $("#amp_sdwp_select").find("table.widefat tr").html();
19
+ $("body").append("<script type='template/html' id='call_html_template_sdwp'><tr class='toclone cloneya'>"+selectrow+"</tr>");
20
+ clone();
21
+ removeHtml();
22
+ $(document).on("change", ".select-post-type", function(){
23
+ var parent = $(this).parents('tr').find(".insert-ajax-select");
24
+ var selectedValue = $(this).val();
25
+ var currentFiledNumber = $(this).attr("class").split(" ")[2];
26
+ var saswp_call_nonce = $("#saswp_select_name_nonce").val();
27
+
28
+ parent.find(".ajax-output").remove();
29
+ parent.find(".ajax-output-child").remove();
30
+ parent.find(".spinner").attr("style","visibility:visible");
31
+ parent.children(".spinner").addClass("show");
32
+ var ajaxURL = amp_sdwp_field_data.ajax_url;
33
+ //ajax call
34
+ $.ajax({
35
+ url : ajaxURL,
36
+ method : "POST",
37
+ data: {
38
+ action: "create_ajax_select_sdwp",
39
+ id: selectedValue,
40
+ number : currentFiledNumber,
41
+ saswp_call_nonce : saswp_call_nonce
42
+ },
43
+ beforeSend: function(){
44
+ },
45
+ success: function(data){
46
+ // This code is added twice " withThis.find('.ajax-output').remove(); "
47
+ parent.find(".ajax-output").remove();
48
+ parent.children(".spinner").removeClass("show");
49
+ parent.find(".spinner").attr("style","visibility:hidden").hide();
50
+ parent.append(data);
51
+ taxonomyDataCall();
52
+ },
53
+ error: function(data){
54
+ console.log("Failed Ajax Request");
55
+ console.log(data);
56
+ }
57
+ });
58
+ });
59
+ taxonomyDataCall();
60
+ $("#notAccessibleForFree").click(function(){
61
+ if($(this).is(':checked')){
62
+ $("#paywall_class_name").parents("tr").show();
63
+ $("#isAccessibleForFree").parents("tr").show();
64
+ }else{
65
+ $("#paywall_class_name").parents("tr").hide();
66
+ $("#isAccessibleForFree").parents("tr").hide();
67
+ }
68
+ })
69
+
70
+ });//jQuery(document) closed
71
+ function taxonomyDataCall(){
72
+ jQuery('select.ajax-output').change(function(){
73
+ var mainSelectedValue = jQuery(".select-post-type").val();
74
+ if(mainSelectedValue=="ef_taxonomy"){
75
+ parentSelector = jQuery(this).parents("td").find(".insert-ajax-select");
76
+ var selectedValue = jQuery(this).val();
77
+ var currentFiledNumber = jQuery(this).attr("name").split("[")[1].replace("]",'');
78
+ var saswp_call_nonce = $("#saswp_select_name_nonce").val();
79
+
80
+ parentSelector.find(".ajax-output-child").remove();
81
+ parentSelector.find(".spinner").attr("style","visibility:visible");
82
+ parentSelector.children(".spinner").addClass("show");
83
+
84
+ var ajaxURL = amp_sdwp_field_data.ajax_url;
85
+ //ajax call
86
+ jQuery.ajax({
87
+ url : ajaxURL,
88
+ method : "POST",
89
+ data: {
90
+ action: "create_ajax_select_sdwp_taxonomy",
91
+ id: selectedValue,
92
+ number : currentFiledNumber,
93
+ saswp_call_nonce: saswp_call_nonce
94
+ },
95
+ beforeSend: function(){
96
+ },
97
+ success: function(data){
98
+ // This code is added twice " withThis.find('.ajax-output').remove(); "
99
+ parentSelector.find(".ajax-output-child").remove();
100
+ parentSelector.children(".spinner").removeClass("show");
101
+ parentSelector.find(".spinner").attr("style","visibility:hidden").hide();
102
+ parentSelector.append(data);
103
+ taxonomyDataCall();
104
+ },
105
+ error: function(data){
106
+ console.log("Failed Ajax Request");
107
+ console.log(data);
108
+ }
109
+ });
110
+ }
111
+ });
112
+ }
113
+
admin_section/settings.php ADDED
@@ -0,0 +1,592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin Settings
4
+ * Function saswp_add_menu_links
5
+ *
6
+ */
7
+ function saswp_add_menu_links() {
8
+ // Settings page - Same as main menu page
9
+ add_submenu_page( 'edit.php?post_type=saswp', esc_html__( 'Schema And Structured Data For Wp', 'schema-and-structured-data-for-wp' ), esc_html__( 'Settings', 'schema-and-structured-data-for-wp' ), 'manage_options', 'structured_data_options', 'saswp_admin_interface_render' );
10
+
11
+ }
12
+ add_action( 'admin_menu', 'saswp_add_menu_links' );
13
+
14
+ function saswp_admin_interface_render(){
15
+ // Authentication
16
+ if ( ! current_user_can( 'manage_options' ) ) {
17
+ return;
18
+ }
19
+ // Handing save settings
20
+ if ( isset( $_GET['settings-updated'] ) ) {
21
+ // Show Settings Saved Message
22
+ settings_errors();
23
+ }
24
+ $tab = saswp_get_tab('general', array('general','knowledge','schema', 'help'));
25
+ ?>
26
+ <div class="wrap saswp-settings-form">
27
+ <h1> <?php echo esc_html__( 'Schema And Structured Data For WP', 'schema-and-structured-data-for-wp' ); ?></h1>
28
+ <h2 class="nav-tab-wrapper saswp-tabs">
29
+ <?php
30
+
31
+ echo '<a href="' . esc_url(saswp_admin_link('general')) . '" class="nav-tab ' . esc_attr( $tab == 'general' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-admin-generic"></span> ' . esc_html__('General','schema-and-structured-data-for-wp') . '</a>';
32
+
33
+ echo '<a href="' . esc_url(saswp_admin_link('knowledge')) . '" class="nav-tab ' . esc_attr( $tab == 'knowledge' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-info"></span> ' . esc_html__('Knowledge Base','schema-and-structured-data-for-wp') . '</a>';
34
+
35
+ echo '<a href="' . esc_url(saswp_admin_link('schema')) . '" class="nav-tab ' . esc_attr( $tab == 'schema' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-welcome-view-site"></span> ' . esc_html__('Schema Type','schema-and-structured-data-for-wp') . '</a>';
36
+
37
+ echo '<a href="' . esc_url(saswp_admin_link('help')) . '" class="nav-tab ' . esc_attr( $tab == 'help' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-dashboard"></span> ' . esc_html__('Help','schema-and-structured-data-for-wp') . '</a>';
38
+ ?>
39
+ </h2>
40
+ <form action="options.php" method="post" enctype="multipart/form-data">
41
+ <div class="form-wrap">
42
+ <?php
43
+ // Output nonce, action, and option_page fields for a settings page.
44
+ settings_fields( 'sd_data_group' );
45
+ echo "<div class='saswp-general' ".( $tab != 'general' ? 'style="display:none;"' : '').">";
46
+ // general Application Settings
47
+ do_settings_sections( 'saswp_general_section' ); // Page slug
48
+ echo "</div>";
49
+
50
+ echo "<div class='saswp-knowledge' ".( $tab != 'knowledge' ? 'style="display:none;"' : '').">";
51
+ // knowledge Application Settings
52
+ do_settings_sections( 'saswp_knowledge_section' ); // Page slug
53
+ echo "</div>";
54
+ echo "<div class='saswp-schema' ".( $tab != 'schema' ? 'style="display:none;"' : '').">";
55
+ do_settings_sections( 'saswp_schema_section' ); // Page slug
56
+ echo "</div>";
57
+
58
+ echo "<div class='saswp-help' ".( $tab != 'help' ? 'style="display:none;"' : '').">";
59
+ // Status
60
+ do_settings_sections( 'saswp_help_section' ); // Page slug
61
+ echo "</div>";
62
+
63
+ ?>
64
+ </div>
65
+ <div class="button-wrapper">
66
+ <?php
67
+ // Output save settings button
68
+ submit_button( esc_html__('Save Settings', 'schema-and-structured-data-for-wp') );
69
+ ?>
70
+ </div>
71
+ </form>
72
+ </div>
73
+ <?php
74
+ }
75
+
76
+
77
+ /*
78
+ WP Settings API
79
+ */
80
+ add_action('admin_init', 'saswp_settings_init');
81
+
82
+ function saswp_settings_init(){
83
+ register_setting( 'sd_data_group', 'sd_data' );
84
+ add_settings_section('saswp_general_section', __return_false(), '__return_false', 'saswp_general_section');
85
+
86
+ add_settings_field(
87
+ 'general_settings', // ID
88
+ '', // Title
89
+ 'saswp_general_page_callback', // CB
90
+ 'saswp_general_section', // Page slug
91
+ 'saswp_general_section' // Settings Section ID
92
+ );
93
+
94
+ add_settings_section('saswp_knowledge_section', __return_false(), '__return_false', 'saswp_knowledge_section');
95
+
96
+ add_settings_field(
97
+ 'knowledge_settings', // ID
98
+ '', // Title
99
+ 'saswp_knowledge_page_callback', // CB
100
+ 'saswp_knowledge_section', // Page slug
101
+ 'saswp_knowledge_section' // Settings Section ID
102
+ );
103
+ add_settings_section('saswp_schema_section', __return_false(), '__return_false', 'saswp_schema_section');
104
+
105
+ add_settings_field(
106
+ 'saswp_schema_settings', // ID
107
+ '', // Title
108
+ 'saswp_schema_page_callback', // CB
109
+ 'saswp_schema_section', // Page slug
110
+ 'saswp_schema_section' // Settings Section ID
111
+ );
112
+ add_settings_section('saswp_help_section', __return_false(), '__return_false', 'saswp_help_section');
113
+
114
+ add_settings_field(
115
+ 'saswp_help_settings', // ID
116
+ '', // Title
117
+ 'saswp_help_page_callback', // CB
118
+ 'saswp_help_section', // Page slug
119
+ 'saswp_help_section' // Settings Section ID
120
+ );
121
+ }
122
+ function saswp_schema_page_callback(){
123
+ // Get Settings
124
+ $settings = saswp_defaultSettings();
125
+ $field_objs = new saswp_fields_generator();
126
+ $meta_fields_schema_type = array(
127
+ array(
128
+ 'label' => 'Post',
129
+ 'id' => 'sd_post_type',
130
+ 'name' => 'sd_data[sd_post_type]',
131
+ 'type' => 'select',
132
+ 'options' => array(
133
+ ''=>'Select an item',
134
+ 'Blogposting'=>'Blogposting',
135
+ 'NewsArticle'=>'NewsArticle',
136
+ 'WebPage'=>'WebPage',
137
+ 'Article'=>'Article',
138
+ 'Recipe'=>'Recipe',
139
+ 'Product'=>'Product',
140
+ 'VideoObject'=>'VideoObject',
141
+ )
142
+ ),
143
+ array(
144
+ 'label' => 'Page',
145
+ 'id' => 'sd_page_type',
146
+ 'name' => 'sd_data[sd_page_type]',
147
+ 'type' => 'select',
148
+ 'options' => array(
149
+ ''=>'Select an item',
150
+ 'Blogposting'=>'Blogposting',
151
+ 'NewsArticle'=>'NewsArticle',
152
+ 'WebPage'=>'WebPage',
153
+ 'Article'=>'Article',
154
+ 'Recipe'=>'Recipe',
155
+ 'Product'=>'Product',
156
+ 'VideoObject'=>'VideoObject',
157
+ )
158
+ ),
159
+ );
160
+ echo '<h2>'.esc_html__('Schema Type','schema-and-structured-data-for-wp').'</h2>';
161
+ $field_objs->saswp_field_generator($meta_fields_schema_type, $settings);
162
+ $meta_fields_default = array(
163
+ array(
164
+ 'label' => 'Default Structured Data Logo',
165
+ 'id' => 'sd-data-logo-ampforwp',
166
+ 'name' => 'sd_data[sd-data-logo-ampforwp][url]',
167
+ 'class' => 'saswp-logo-ampforwp regular-text',
168
+ 'type' => 'media',
169
+ ),
170
+ array(
171
+ 'label' => 'Custom Logo Size',
172
+ 'id' => 'saswp-logo-dimensions-check',
173
+ 'name' => 'sd_data[saswp-logo-dimensions]',
174
+ 'type' => 'checkbox',
175
+ 'class' => 'checkbox saswp-checkbox',
176
+ 'hidden' => array(
177
+ 'id' => 'saswp-logo-dimensions',
178
+ 'name' => 'sd_data[saswp-logo-dimensions]',
179
+ )
180
+ ),
181
+ array(
182
+ 'label' => 'Logo Width',
183
+ 'id' => 'saswp-logo-width',
184
+ 'name' => 'sd_data[saswp-logo-width]',
185
+ 'class' => 'regular-text',
186
+ 'type' => 'text',
187
+ 'note' => 'Default width is 600 pixels'
188
+ ),
189
+ array(
190
+ 'label' => 'Logo Height',
191
+ 'id' => 'saswp-logo-height',
192
+ 'name' => 'sd_data[saswp-logo-height]',
193
+ 'class' => 'regular-text',
194
+ 'type' => 'text',
195
+ 'note' => 'Default height is 60 pixels'
196
+ ),
197
+ array(
198
+ 'label' => 'Default Image',
199
+ 'id' => 'sd_default_image',
200
+ 'name' => 'sd_data[sd_default_image][url]',
201
+ 'class' => 'saswp-sd_default_image',
202
+ 'type' => 'media',
203
+ ),
204
+ array(
205
+ 'label' => 'Default Post Image Width',
206
+ 'id' => 'sd_default_image_width',
207
+ 'name' => 'sd_data[sd_default_image_width]',
208
+ 'class' => 'regular-text',
209
+ 'type' => 'text',
210
+ ),
211
+ array(
212
+ 'label' => 'Default Post Image Height',
213
+ 'id' => 'sd_default_image_height',
214
+ 'name' => 'sd_data[sd_default_image_height]',
215
+ 'class' => 'regular-text',
216
+ 'type' => 'text',
217
+ ),
218
+ array(
219
+ 'label' => 'Default Thumbnail for VideoObject',
220
+ 'id' => 'sd_default_video_thumbnail',
221
+ 'name' => 'sd_data[sd_default_video_thumbnail][url]',
222
+ 'class' => 'saswp-sd_default_video_thumbnail',
223
+ 'type' => 'media',
224
+ ),
225
+ array(
226
+ 'label' => 'Archive',
227
+ 'id' => 'saswp_archive_schema_checkbox',
228
+ 'name' => 'saswp_archive_schema_checkbox',
229
+ 'type' => 'checkbox',
230
+ 'class' => 'checkbox saswp-checkbox',
231
+ 'hidden' => array(
232
+ 'id' => 'saswp_archive_schema',
233
+ 'name' => 'sd_data[saswp_archive_schema]',
234
+ )
235
+ ),
236
+ array(
237
+ 'label' => 'BreadCrumbs',
238
+ 'id' => 'saswp_breadcrumb_schema_checkbox',
239
+ 'name' => 'saswp_breadcrumb_schema_checkbox',
240
+ 'type' => 'checkbox',
241
+ 'class' => 'checkbox saswp-checkbox',
242
+ 'hidden' => array(
243
+ 'id' => 'saswp_breadcrumb_schema',
244
+ 'name' => 'sd_data[saswp_breadcrumb_schema]',
245
+ )
246
+ ),
247
+ );
248
+ echo '<h2>'.esc_html__('Default Values','schema-and-structured-data-for-wp').'</h2>';
249
+ $field_objs->saswp_field_generator($meta_fields_default, $settings);
250
+ ?>
251
+
252
+ <?php
253
+ }
254
+ function saswp_general_page_callback(){
255
+ // Get Settings
256
+ $settings = saswp_defaultSettings();
257
+ $field_objs = new saswp_fields_generator();
258
+ $meta_fields = array(
259
+ array(
260
+ 'label' => 'Structured Data for WordPress',
261
+ 'id' => 'saswp-for-wordpress-checkbox',
262
+ 'name' => 'saswp-for-wordpress-checkbox',
263
+ 'type' => 'checkbox',
264
+ 'class' => 'checkbox saswp-checkbox',
265
+ 'note' => '',
266
+ 'hidden' => array(
267
+ 'id' => 'saswp-for-wordpress',
268
+ 'name' => 'sd_data[saswp-for-wordpress]',
269
+ )
270
+ ),
271
+ array(
272
+ 'label' => 'Structured Data for AMP',
273
+ 'id' => 'saswp-for-amp-checkbox',
274
+ 'name' => 'saswp-for-amp-checkbox',
275
+ 'type' => 'checkbox',
276
+ 'class' => 'checkbox saswp-checkbox',
277
+ 'hidden' => array(
278
+ 'id' => 'saswp-for-amp',
279
+ 'name' => 'sd_data[saswp-for-amp]',
280
+ )
281
+ ),
282
+ );
283
+ echo '<h2>'.esc_html__('Set Up','schema-and-structured-data-for-wp').'</h2>';
284
+ $field_objs->saswp_field_generator($meta_fields, $settings);
285
+
286
+ ?>
287
+ <div class="saswp-settings-list">
288
+ <h2><?php echo esc_html__('Page Schema','schema-and-structured-data-for-wp') ?></h2>
289
+ <ul><li><div style="width:200px;float:left;clear: both;"><label>
290
+ <?php echo esc_html__('About Us','schema-and-structured-data-for-wp') ?>
291
+ </label>
292
+ </div>
293
+ <div style="width:85%">
294
+ <div style="width:75%; float:right;">
295
+
296
+ <label for="sd_about_page-select">
297
+ <?php
298
+ echo wp_dropdown_pages( array(
299
+ 'name' => 'sd_data[sd_about_page]',
300
+ 'id' => 'sd_about_page',
301
+ 'echo' => 0,
302
+ 'show_option_none' => esc_attr( 'Select an item' ),
303
+ 'option_none_value' => '',
304
+ 'selected' => isset($settings['sd_about_page']) ? $settings['sd_about_page'] : '',
305
+ )); ?>
306
+ </label>
307
+ </div>
308
+ </div>
309
+ </li>
310
+ <li><div style="width:200px;float:left;clear: both;">
311
+ <label>
312
+ <?php echo esc_html__('Contact Us','schema-and-structured-data-for-wp') ?>
313
+ </label>
314
+ </div>
315
+ <div style="width:85%">
316
+ <div style="width:75%; float:right;">
317
+
318
+ <label for="sd_contact_page-select">
319
+ <?php echo wp_dropdown_pages( array(
320
+ 'name' => 'sd_data[sd_contact_page]',
321
+ 'id' => 'sd_contact_page-select',
322
+ 'echo' => 0,
323
+ 'show_option_none' => esc_attr( 'Select an item' ),
324
+ 'option_none_value' => '',
325
+ 'selected' => isset($settings['sd_contact_page']) ? $settings['sd_contact_page'] : '',
326
+ )); ?>
327
+ </label>
328
+ </div>
329
+ </div>
330
+ </li>
331
+ </ul>
332
+ </div>
333
+ <?php
334
+ }
335
+ function saswp_knowledge_page_callback(){
336
+ // Get Settings
337
+ $settings = saswp_defaultSettings();
338
+ $field_objs = new saswp_fields_generator();
339
+ $meta_fields = array(
340
+ array(
341
+ 'label' => 'Data Type',
342
+ 'id' => 'saswp_kb_type',
343
+ 'name' => 'sd_data[saswp_kb_type]',
344
+ 'type' => 'select',
345
+ 'options' => array(
346
+ 'Organization'=>'Organization',
347
+ 'Person'=>'Person',
348
+ )
349
+ ),
350
+
351
+ array(
352
+ 'label' => 'Data Name',
353
+ 'id' => 'sd_name',
354
+ 'name' => 'sd_data[sd_name]',
355
+ 'class' => 'regular-text',
356
+ 'type' => 'text',
357
+ ),
358
+ array(
359
+ 'label' => 'Alternative Name',
360
+ 'id' => 'sd_alt_name',
361
+ 'name' => 'sd_data[sd_alt_name]',
362
+ 'class' => 'regular-text',
363
+ 'type' => 'text',
364
+ ),
365
+ array(
366
+ 'label' => 'Data url',
367
+ 'id' => 'sd_url',
368
+ 'name' => 'sd_data[sd_url]',
369
+ 'class' => 'regular-text',
370
+ 'type' => 'text',
371
+ ),
372
+ array(
373
+ 'label' => 'Logo',
374
+ 'id' => 'sd_logo',
375
+ 'name' => 'sd_data[sd_logo][url]',
376
+ 'class' => 'saswp-icon upload large-text',
377
+ 'type' => 'media',
378
+ ),
379
+ array(
380
+ 'label' => 'Contact details',
381
+ 'id' => 'saswp_kb_contact_1_checkbox',
382
+ 'name' => 'saswp_kb_contact_1_checkbox',
383
+ 'type' => 'checkbox',
384
+ 'class' => 'checkbox saswp-checkbox',
385
+ 'hidden' => array(
386
+ 'id' => 'saswp_kb_contact_1',
387
+ 'name' => 'sd_data[saswp_kb_contact_1]'
388
+ )
389
+ ),
390
+ array(
391
+ 'label' => 'Telephone Number',
392
+ 'id' => 'saswp_kb_telephone',
393
+ 'name' => 'sd_data[saswp_kb_telephone]',
394
+ 'class' => 'regular-text',
395
+ 'type' => 'text',
396
+ ),
397
+ array(
398
+ 'label' => 'Contact Type',
399
+ 'id' => 'saswp_contact_type',
400
+ 'name' => 'sd_data[saswp_contact_type]',
401
+ 'class' => '',
402
+ 'type' => 'select',
403
+ 'options' => array(
404
+ ''=>'Select an item',
405
+ 'customer support'=>'Customer Support',
406
+ 'technical support'=>'Technical Support',
407
+ 'billing support'=>'Billing Support',
408
+ 'bill payment'=>'Bill payment',
409
+ 'sales'=>'Sales',
410
+ 'reservations'=>'Reservations',
411
+ 'credit card support'=>'Credit Card Support',
412
+ 'emergency'=>'Emergency',
413
+ 'baggage tracking'=>'Baggage Tracking',
414
+ 'roadside assistance'=>'Roadside Assistance',
415
+ 'package tracking'=>'Package Tracking',
416
+ )
417
+ ),
418
+ array(
419
+ 'label' => 'Name',
420
+ 'id' => 'sd-person-name',
421
+ 'name' => 'sd_data[sd-person-name]',
422
+ 'class' => 'regular-text',
423
+ 'type' => 'text',
424
+ ),
425
+ array(
426
+ 'label' => 'Job Title',
427
+ 'id' => 'sd-person-job-title',
428
+ 'name' => 'sd_data[sd-person-job-title]',
429
+ 'class' => 'regular-text',
430
+ 'type' => 'text',
431
+ ),
432
+ array(
433
+ 'label' => 'Image',
434
+ 'id' => 'sd-person-image',
435
+ 'name' => 'sd_data[sd-person-image][url]',
436
+ 'class' => 'upload large-text',
437
+ 'type' => 'media',
438
+ ),
439
+ array(
440
+ 'label' => 'Phone Number',
441
+ 'id' => 'sd-person-phone-number',
442
+ 'name' => 'sd_data[sd-person-phone-number]',
443
+ 'class' => 'regular-text',
444
+ 'type' => 'text',
445
+ ),
446
+ array(
447
+ 'label' => 'URL',
448
+ 'id' => 'sd-person-url',
449
+ 'name' => 'sd_data[sd-person-url]',
450
+ 'class' => 'regular-text',
451
+ 'type' => 'text',
452
+ ),
453
+
454
+ );
455
+ echo '<h2>'.esc_html__('Knowledge Base','schema-and-structured-data-for-wp').'</h2>';
456
+ echo '<div class="saswp-knowledge-base">';
457
+ $field_objs->saswp_field_generator($meta_fields, $settings);
458
+ echo '</div>';
459
+
460
+ //social
461
+ echo '<h2>'.esc_html__( 'Social Fields', 'schema-and-structured-data-for-wp' ).'</h2>';
462
+ $social_meta_fields = array(
463
+ array(
464
+ 'label' => 'Facebook',
465
+ 'id' => 'sd_facebook',
466
+ 'name' => 'sd_data[sd_facebook]',
467
+ 'class' => 'regular-text',
468
+ 'type' => 'text',
469
+ 'attributes' => array(
470
+ 'placeholder' => 'https://'
471
+ )
472
+ ),
473
+ array(
474
+ 'label' => 'Twitter',
475
+ 'id' => 'sd_twitter',
476
+ 'name' => 'sd_data[sd_twitter]',
477
+ 'class' => 'regular-text',
478
+ 'type' => 'text',
479
+ 'attributes' => array(
480
+ 'placeholder' => 'https://'
481
+ )
482
+ ),
483
+ array(
484
+ 'label' => 'Google+',
485
+ 'id' => 'sd_google_plus',
486
+ 'name' => 'sd_data[sd_google_plus]',
487
+ 'class' => 'regular-text',
488
+ 'type' => 'text',
489
+ 'attributes' => array(
490
+ 'placeholder' => 'https://'
491
+ )
492
+ ),
493
+ array(
494
+ 'label' => 'Instagram',
495
+ 'id' => 'sd_instagram',
496
+ 'name' => 'sd_data[sd_instagram]',
497
+ 'class' => 'regular-text',
498
+ 'type' => 'text',
499
+ 'attributes' => array(
500
+ 'placeholder' => 'https://'
501
+ )
502
+ ),
503
+ array(
504
+ 'label' => 'Youtube',
505
+ 'id' => 'sd_youtube',
506
+ 'name' => 'sd_data[sd_youtube]',
507
+ 'class' => 'regular-text',
508
+ 'type' => 'text',
509
+ 'attributes' => array(
510
+ 'placeholder' => 'https://'
511
+ )
512
+ ),
513
+ array(
514
+ 'label' => 'LinkedIn',
515
+ 'id' => 'sd_linkedin',
516
+ 'name' => 'sd_data[sd_linkedin]',
517
+ 'class' => 'regular-text',
518
+ 'type' => 'text',
519
+ 'attributes' => array(
520
+ 'placeholder' => 'https://'
521
+ )
522
+ ),
523
+ array(
524
+ 'label' => 'Pinterest',
525
+ 'id' => 'sd_pinterest',
526
+ 'name' => 'sd_data[sd_pinterest]',
527
+ 'class' => 'regular-text',
528
+ 'type' => 'text',
529
+ 'attributes' => array(
530
+ 'placeholder' => 'https://'
531
+ )
532
+ ),
533
+ array(
534
+ 'label' => 'SoundCloud',
535
+ 'id' => 'sd_soundcloud',
536
+ 'name' => 'sd_data[sd_soundcloud]',
537
+ 'class' => 'regular-text',
538
+ 'type' => 'text',
539
+ 'attributes' => array(
540
+ 'placeholder' => 'https://'
541
+ )
542
+ ),
543
+ array(
544
+ 'label' => 'Tumblr',
545
+ 'id' => 'sd_tumblr',
546
+ 'name' => 'sd_data[sd_tumblr]',
547
+ 'class' => 'regular-text',
548
+ 'type' => 'text',
549
+ 'attributes' => array(
550
+ 'placeholder' => 'https://'
551
+ )
552
+ ),
553
+
554
+ );
555
+ $field_objs->saswp_field_generator($social_meta_fields, $settings);
556
+
557
+ ?>
558
+ <?php
559
+ }
560
+ function saswp_help_page_callback(){
561
+ echo '<h1>'.esc_html__( 'Here are some Q&A which helps you to understand and setup the Schema and Structured data for wp.', 'schema-and-structured-data-for-wp' ).'</h1>
562
+ <br><br>
563
+ <h3>1Q) '.esc_html__( 'How can I setup the Schema and Structured data for individual pages and posts?', 'schema-and-structured-data-for-wp' ).'</h3>
564
+ <p class="saswp_qanda_p">A) '.esc_html__( 'Just with one click on the Structured data option, you will find an add new options window in the structured data option panel. Secondly, you need to write the name of the title where, if you would like to set the individual Page/Post then you can set the Page/Post type equal to the Page/Post(Name).', 'schema-and-structured-data-for-wp' ).'</p>
565
+
566
+ <h3>2Q) '.esc_html__( 'How can I check the code whether the structured data is working or not?', 'schema-and-structured-data-for-wp' ).'</h3>
567
+ <p class="saswp_qanda_p">A) To check the code, the first step we need to take is to copy the code of a page or post then visit the <a href="https://search.google.com/structured-data/testing-tool" target="_blank">Structured data testing tool</a> by clicking on code snippet. Once we paste the snippet we can run the test.</p>
568
+
569
+ <h3> 3Q) '.esc_html__( 'How can I check whether the pages or posts are valid or not?', 'schema-and-structured-data-for-wp' ).'</h3>
570
+ <p class="saswp_qanda_p"> A) '.esc_html__( 'To check the page and post validation, please visit the', 'schema-and-structured-data-for-wp' ).' <a href="https://search.google.com/structured-data/testing-tool" target="_blank">'.esc_html__( 'Structured data testing tool', 'schema-and-structured-data-for-wp' ).'</a> '.esc_html__( 'and paste the link of your website.', 'schema-and-structured-data-for-wp' ).' '.esc_html__( 'Once we click on run test we can see the result whether the page or post is a valid one or not.', 'schema-and-structured-data-for-wp' ).'</p>
571
+
572
+ <h3>4Q) '.esc_html__( 'Where should users contact if they faced any issues?', 'schema-and-structured-data-for-wp' ).'</h3>
573
+ <p class="saswp_qanda_p">A) '.esc_html__( 'We always welcome all our users to share their issues and get them fixed just with one click to the link', 'schema-and-structured-data-for-wp' ).' team@magazine3.com or <a href="https://ampforwp.com/support/" target="_blank">'.esc_html__( 'Support link', 'schema-and-structured-data-for-wp' ).'</a></p><br>';
574
+ }
575
+ /**
576
+ * Enqueue CSS and JS
577
+ */
578
+ function saswp_enqueue_style_js( $hook ) {
579
+ if ( strpos( $hook, 'structured_data_options' ) === false ) {
580
+ return;
581
+ }
582
+ // Color picker CSS
583
+ // @refer https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
584
+ wp_enqueue_style( 'wp-color-picker' );
585
+ // Everything needed for media upload
586
+ wp_enqueue_media();
587
+ // Main JS
588
+ wp_enqueue_script( 'saswp-main-js', SASWP_PLUGIN_URL . 'admin_section/js/main-script.js', array( 'wp-color-picker' ), SASWP_VERSION, true );
589
+ //Main Css
590
+ wp_enqueue_style( 'saswp-main-css', SASWP_PLUGIN_URL . 'admin_section/css/main-style.css', false , SASWP_VERSION );
591
+ }
592
+ add_action( 'admin_enqueue_scripts', 'saswp_enqueue_style_js' );
admin_section/structure_admin.php ADDED
@@ -0,0 +1,800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ //FrontEnd
3
+ function saswp_get_all_schema_posts(){
4
+ $post_idArray = array();
5
+ $query = new WP_Query(
6
+ array(
7
+ 'post_type' => 'saswp',
8
+ 'post_status' => 'publish',
9
+ 'posts_per_page' => -1,
10
+ ));
11
+ while ($query->have_posts()) {
12
+ $query->the_post();
13
+ $post_idArray[] = get_the_ID();
14
+ }
15
+ wp_reset_query();
16
+ wp_reset_postdata();
17
+
18
+ if(count($post_idArray)>0){
19
+ $returnData = array();
20
+ foreach ($post_idArray as $key => $post_id)
21
+ {
22
+ $data = saswp_generate_field_data( $post_id );
23
+ $data = array_filter($data);
24
+ $number_of_fields = count($data);
25
+ $unique_checker = 0;
26
+ // Check if we have more then 1 fields.
27
+ if ( $number_of_fields > 0 ) {
28
+ // Check if all the arrays have TRUE setup, then send the value 1, if all the
29
+ // values are same.
30
+ $unique_checker = count( array_unique($data) );
31
+ // Check and make sure only all TRUE values only passed on, if all values are FALSE,
32
+ // then making sure all FALSE are converting to 0, and returing false.
33
+ // Code will not run.
34
+ $array_is_false = in_array(false, $data);
35
+ if ( $array_is_false ) {
36
+ $unique_checker = 0;
37
+ }
38
+ }
39
+
40
+ if ( $unique_checker === 1 || $unique_checker === true) {
41
+ $conditions = get_post_meta( $post_id, 'data_array', true);
42
+ $conditions = $conditions[0];
43
+ $returnData[] = array(
44
+ 'schema_type' => get_post_meta( $post_id, 'schema_type', true),
45
+ 'schema_options' => get_post_meta( $post_id, 'schema_options', true),
46
+ 'conditions' => $conditions,
47
+ );
48
+ }
49
+ }//foreach closed post_idArray
50
+ //Prioritize
51
+ if(count($returnData)>0){
52
+ $priority = array(
53
+ 'post_type'=>1,
54
+ 'user_type'=>2,
55
+ 'post'=> 3 ,
56
+ 'post_category'=> 4,
57
+ 'post_format'=> 5,
58
+ 'Page'=> 6,
59
+ 'page_template'=>7,
60
+ 'ef_taxonomy'=>8
61
+ );
62
+ $actualReturnData = array();
63
+ foreach ($returnData as $key => $value) {
64
+ $actualReturnData[$priority[$value['conditions']['key_1']]] = $value;
65
+ }
66
+ $maxs = array_keys($actualReturnData, max($actualReturnData));
67
+ return $actualReturnData[$maxs[0]];
68
+ }
69
+ }//iF Closed post_idArray
70
+ return false;
71
+ }
72
+
73
+ function saswp_generate_field_data( $post_id ){
74
+ $conditions = get_post_meta( $post_id, 'data_array', true);
75
+
76
+ $output = array();
77
+ if ( $conditions ) {
78
+ $output = array_map('saswp_comparison_logic_checker', $conditions);
79
+ }
80
+ return $output;
81
+ }
82
+
83
+ function saswp_comparison_logic_checker($input){
84
+ global $post;
85
+ $type = $input['key_1'];
86
+ $comparison = $input['key_2'];
87
+ $data = $input['key_3'];
88
+ $result = '';
89
+
90
+ // Get all the users registered
91
+ $user = wp_get_current_user();
92
+
93
+ switch ($type) {
94
+ // Basic Controls ------------
95
+ // Posts Type
96
+ case 'post_type':
97
+ $current_post_type = $post->post_type;
98
+ if ( $comparison == 'equal' ) {
99
+ if ( $current_post_type == $data ) {
100
+ $result = true;
101
+ }
102
+ }
103
+ if ( $comparison == 'not_equal') {
104
+ if ( $current_post_type != $data ) {
105
+ $result = true;
106
+ }
107
+ }
108
+ break;
109
+
110
+ // Logged in User Type
111
+ case 'user_type':
112
+ if ( $comparison == 'equal') {
113
+ if ( in_array( $data, (array) $user->roles ) ) {
114
+ $result = true;
115
+ }
116
+ }
117
+ if ( $comparison == 'not_equal') {
118
+ require_once ABSPATH . 'wp-admin/includes/user.php';
119
+ // Get all the registered user roles
120
+ $roles = get_editable_roles();
121
+ $all_user_types = array();
122
+ foreach ($roles as $key => $value) {
123
+ $all_user_types[] = $key;
124
+ }
125
+ // Flip the array so we can remove the user that is selected from the dropdown
126
+ $all_user_types = array_flip( $all_user_types );
127
+
128
+ // User Removed
129
+ unset( $all_user_types[$data] );
130
+
131
+ // Check and make the result true that user is not found
132
+ if ( in_array( $data, (array) $all_user_types ) ) {
133
+ $result = true;
134
+ }
135
+ }
136
+
137
+ break;
138
+
139
+ // Post Controls ------------
140
+ // Posts
141
+ case 'post':
142
+ $current_post = $post->ID;
143
+ if ( $comparison == 'equal' ) {
144
+ if ( $current_post == $data ) {
145
+ $result = true;
146
+ }
147
+ }
148
+ if ( $comparison == 'not_equal') {
149
+ if ( $current_post != $data ) {
150
+ $result = true;
151
+ }
152
+ }
153
+
154
+ break;
155
+
156
+ // Post Category
157
+ case 'post_category':
158
+ $postcat = get_the_category( $post->ID );
159
+ $current_category = $postcat[0]->cat_ID;
160
+
161
+ if ( $comparison == 'equal') {
162
+ if ( $data == $current_category ) {
163
+ $result = true;
164
+ }
165
+ }
166
+ if ( $comparison == 'not_equal') {
167
+ if ( $data != $current_category ) {
168
+ $result = true;
169
+ }
170
+ }
171
+ break;
172
+ // Post Format
173
+ case 'post_format':
174
+ $current_post_format = get_post_format( $post->ID );
175
+ if ( $current_post_format === false ) {
176
+ $current_post_format = 'standard';
177
+ }
178
+ if ( $comparison == 'equal') {
179
+ if ( $data == $current_post_format ) {
180
+ $result = true;
181
+ }
182
+ }
183
+ if ( $comparison == 'not_equal') {
184
+ if ( $data != $current_post_format ) {
185
+ $result = true;
186
+ }
187
+ }
188
+ break;
189
+
190
+ // Page Controls ----------------
191
+ // Page
192
+ case 'page':
193
+ global $redux_builder_amp;
194
+ if(ampforwp_is_front_page()){
195
+ $current_post = $redux_builder_amp['amp-frontpage-select-option-pages'];
196
+ }else{
197
+ $current_post = $post->ID;
198
+ }
199
+ if ( $comparison == 'equal' ) {
200
+ if ( $current_post == $data ) {
201
+ $result = true;
202
+ }
203
+ }
204
+ if ( $comparison == 'not_equal') {
205
+ if ( $current_post != $data ) {
206
+ $result = true;
207
+ }
208
+ }
209
+ break;
210
+
211
+ // Page Template
212
+ case 'page_template':
213
+ $current_page_template = get_page_template_slug( $post->ID );
214
+ if ( $current_page_template == false ) {
215
+ $current_page_template = 'default';
216
+ }
217
+ if ( $comparison == 'equal' ) {
218
+ if ( $current_page_template == $data ) {
219
+ $result = true;
220
+ }
221
+ }
222
+ if ( $comparison == 'not_equal') {
223
+ if ( $current_page_template != $data ) {
224
+ $result = true;
225
+ }
226
+ }
227
+
228
+ break;
229
+
230
+ // Other Controls ---------------
231
+ // Taxonomy Term
232
+ case 'ef_taxonomy':
233
+ // Get all the post registered taxonomies
234
+ // Get the list of all the taxonomies associated with current post
235
+ $taxonomy_names = get_post_taxonomies( $post->ID );
236
+
237
+ $checker = '';
238
+ $post_terms = '';
239
+
240
+ if ( $data != 'all') {
241
+ $post_terms = wp_get_post_terms($post->ID, $data);
242
+
243
+ if ( $comparison == 'equal' ) {
244
+ if ( $post_terms ) {
245
+ $result = true;
246
+ }
247
+ }
248
+
249
+ if ( $comparison == 'not_equal') {
250
+ $checker = in_array($data, $taxonomy_names);
251
+ if ( ! $checker ) {
252
+ $result = true;
253
+ }
254
+ }
255
+ if($result==true && isset( $input['key_4'] ) && $input['key_4'] !='all'){
256
+ $term_data = $input['key_4'];
257
+ $terms = wp_get_post_terms( $post->ID ,$data);
258
+ if(count($terms)>0){
259
+ $termChoices = array();
260
+ foreach ($terms as $key => $termvalue) {
261
+ $termChoices[] = $termvalue->slug;
262
+ }
263
+ }
264
+ $result = false;
265
+ if(in_array($term_data, $termChoices)){
266
+ $result = true;
267
+ }
268
+ }//if closed for key_4
269
+
270
+ } else {
271
+
272
+ if ( $comparison == 'equal' ) {
273
+ if ( $taxonomy_names ) {
274
+ $result = true;
275
+ }
276
+ }
277
+
278
+ if ( $comparison == 'not_equal') {
279
+ if ( ! $taxonomy_names ) {
280
+ $result = true;
281
+ }
282
+ }
283
+
284
+ }
285
+ break;
286
+
287
+ default:
288
+ $result = false;
289
+ break;
290
+ }
291
+
292
+ return $result;
293
+ }
294
+
295
+
296
+ require_once( untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/ajax-selectbox.php' );
297
+ //Back End
298
+ if(is_admin()){
299
+ add_action( 'init', 'saswp_create_post_type' );
300
+ function saswp_create_post_type() {
301
+
302
+
303
+ register_post_type( 'saswp',
304
+ array(
305
+ 'labels' => array(
306
+ 'name' => esc_html__( 'Structured Data', 'schema-and-structured-data-for-wp' ),
307
+ 'singular_name' => esc_html__( 'Structured Data', 'schema-and-structured-data-for-wp' ),
308
+ 'add_new' => esc_html__( 'Add New', 'schema-and-structured-data-for-wp' ),
309
+ 'add_new_item' => esc_html__( 'Add New', 'schema-and-structured-data-for-wp' ),
310
+ 'edit_item' => esc_html__( 'Edit Structured Data','schema-and-structured-data-for-wp')
311
+ ),
312
+ 'public' => true,
313
+ 'has_archive' => false,
314
+ 'exclude_from_search' => true,
315
+ 'publicly_queryable' => false,
316
+ 'supports' => array('title'),
317
+ )
318
+ );
319
+ }
320
+ add_action( 'add_meta_boxes', 'saswp_create_meta_box_select' );
321
+ function saswp_create_meta_box_select(){
322
+ // Repeater Comparison Field
323
+ add_meta_box( 'amp_sdwp_select', esc_html__( 'Placement','schema-and-structured-data-for-wp' ), 'saswp_select_callback', 'saswp','normal', 'high' );
324
+
325
+ }
326
+
327
+
328
+
329
+ function saswp_select_callback($post) {
330
+
331
+ $data_array = esc_sql ( get_post_meta($post->ID, 'data_array', true) );
332
+ $schema_type = esc_sql ( get_post_meta($post->ID, 'schema_type', true) );
333
+ $schema_options = esc_sql ( get_post_meta($post->ID, 'schema_options', true) );
334
+ $data_array = is_array($data_array)? array_values($data_array): array();
335
+ if ( empty( $data_array ) ) {
336
+ $data_array = array(
337
+ array(
338
+ 'key_1' => 'post_type',
339
+ 'key_2' => 'not_equal',
340
+ 'key_3' => 'none',
341
+ )
342
+ );
343
+ }
344
+ //security check
345
+ wp_nonce_field( 'saswp_select_action_nonce', 'saswp_select_name_nonce' );?>
346
+
347
+ <?php
348
+ // Type Select
349
+ $choices = array(
350
+ esc_html__("Basic",'schema-and-structured-data-for-wp') => array(
351
+ 'post_type' => esc_html__("Post Type",'schema-and-structured-data-for-wp'),
352
+ 'user_type' => esc_html__("Logged in User Type",'schema-and-structured-data-for-wp'),
353
+ ),
354
+ esc_html__("Post",'schema-and-structured-data-for-wp') => array(
355
+ 'post' => esc_html__("Post",'schema-and-structured-data-for-wp'),
356
+ 'post_category' => esc_html__("Post Category",'schema-and-structured-data-for-wp'),
357
+ 'post_format' => esc_html__("Post Format",'schema-and-structured-data-for-wp'),
358
+ ),
359
+ esc_html__("Page",'schema-and-structured-data-for-wp') => array(
360
+ 'page' => esc_html__("Page",'schema-and-structured-data-for-wp'),
361
+ 'page_template' => esc_html__("Page Template",'schema-and-structured-data-for-wp'),
362
+ ),
363
+ esc_html__("Other",'schema-and-structured-data-for-wp') => array(
364
+ 'ef_taxonomy' => esc_html__("Taxonomy Term",'schema-and-structured-data-for-wp'),
365
+ )
366
+ );
367
+
368
+ $comparison = array(
369
+ 'equal' => esc_html__( 'Equal to', 'schema-and-structured-data-for-wp'),
370
+ 'not_equal' => esc_html__( 'Not Equal to', 'schema-and-structured-data-for-wp'),
371
+ );
372
+
373
+ $total_fields = count( $data_array ); ?>
374
+
375
+ <table class="widefat">
376
+ <tbody id="sdwp-repeater-tbody" class="fields-wrapper-1">
377
+ <?php for ($i=0; $i < $total_fields; $i++) {
378
+ $selected_val_key_1 = $data_array[$i]['key_1'];
379
+ $selected_val_key_2 = $data_array[$i]['key_2'];
380
+ $selected_val_key_3 = $data_array[$i]['key_3'];
381
+ $selected_val_key_4 = '';
382
+ if(isset($data_array[$i]['key_4'])){
383
+ $selected_val_key_4 = $data_array[$i]['key_4'];
384
+ }
385
+ ?>
386
+ <tr class="toclone">
387
+ <td style="width:31%" class="post_types">
388
+ <select class="widefat select-post-type <?php echo esc_attr( $i );?>" name="data_array[<?php echo esc_attr( $i) ?>][key_1]">
389
+ <?php
390
+ foreach ($choices as $choice_key => $choice_value) { ?>
391
+ <option disabled class="pt-heading" value="<?php echo esc_attr($choice_key);?>"> <?php echo esc_html__($choice_key,'schema-and-structured-data-for-wp');?> </option>
392
+ <?php
393
+ foreach ($choice_value as $sub_key => $sub_value) { ?>
394
+ <option class="pt-child" value="<?php echo esc_attr( $sub_key );?>" <?php selected( $selected_val_key_1, $sub_key );?> > <?php echo esc_html__($sub_value,'schema-and-structured-data-for-wp');?> </option>
395
+ <?php
396
+ }
397
+ } ?>
398
+ </select>
399
+ </td>
400
+ <td style="width:31%">
401
+ <select class="widefat comparison" name="data_array[<?php echo esc_attr( $i )?>][key_2]"> <?php
402
+ foreach ($comparison as $key => $value) {
403
+ $selcomp = '';
404
+ if($key == $selected_val_key_2){
405
+ $selcomp = 'selected';
406
+ }
407
+ ?>
408
+ <option class="pt-child" value="<?php echo esc_attr( $key );?>" <?php echo esc_attr($selcomp); ?> > <?php echo esc_html__($value,'schema-and-structured-data-for-wp');?> </option>
409
+ <?php
410
+ } ?>
411
+ </select>
412
+ </td>
413
+ <td style="width:31%">
414
+ <div class="insert-ajax-select">
415
+ <?php saswp_ajax_select_creator($selected_val_key_1, $selected_val_key_3, $i );
416
+ if($selected_val_key_1 == 'ef_taxonomy'){
417
+ saswp_create_ajax_select_taxonomy($selected_val_key_3, $selected_val_key_4, $i);
418
+ }
419
+ ?>
420
+ <div class="spinner"></div>
421
+ </div>
422
+ </td>
423
+
424
+ <td class="widefat structured-clone" style="width:3.5%">
425
+ <span> <button type="button"> <?php echo esc_html__('Add' ,'schema-and-structured-data-for-wp');?> </button> </span> </td>
426
+
427
+ <td class="widefat structured-delete" style="width:3.5%">
428
+ <span> <button type="button"> <?php echo esc_html__( 'Remove' ,'schema-and-structured-data-for-wp');?> </button> </span> </td>
429
+ </tr>
430
+ <?php
431
+ } ?>
432
+ </tbody>
433
+ </table>
434
+ <br/>
435
+ <style type="text/css">
436
+ .option-table-class{width:100%;}
437
+ .option-table-class tr td {padding: 10px 10px 10px 10px ;}
438
+ .option-table-class tr > td{width: 30%;}
439
+ .option-table-class tr td:last-child{width: 60%;}
440
+ .option-table-class input[type="text"], select{width:100%;}
441
+ </style>
442
+ <table class="option-table-class">
443
+ <tbody>
444
+ <tr>
445
+ <td><label for="schema_type"><?php echo esc_html__( 'Schema Type' ,'schema-and-structured-data-for-wp');?></label></td>
446
+ <td><select id="schema_type" name="schema_type">
447
+ <?php
448
+
449
+ $all_schema_array = array(
450
+ 'Blogposting' => 'Blogposting',
451
+ 'NewsArticle' => 'NewsArticle',
452
+ 'WebPage' => 'WebPage',
453
+ 'Article' => 'Article',
454
+ 'Recipe' => 'Recipe',
455
+ 'Product' => 'Product',
456
+ 'VideoObject' => 'VideoObject'
457
+ );
458
+ foreach ($all_schema_array as $key => $value) {
459
+ $sel = '';
460
+ if($schema_type==$key){
461
+ $sel = 'selected';
462
+ }
463
+ echo "<option value='".esc_attr($key)."' ".esc_attr($sel).">".esc_html__($value, 'schema-and-structured-data-for-wp' )."</option>";
464
+ }
465
+ ?>
466
+ </select></td>
467
+ </tr>
468
+
469
+ <tr>
470
+ <td><label for="notAccessibleForFree"><?php echo esc_html__( 'Paywall', 'schema-and-structured-data-for-wp' ) ?></label></td>
471
+ <td><input type="checkbox" id="notAccessibleForFree" name="notAccessibleForFree" value="1" <?php if(isset($schema_options['notAccessibleForFree']) && $schema_options['notAccessibleForFree']==1){echo 'checked'; }?>>
472
+ </td>
473
+ </tr>
474
+ <tr <?php if(!isset($schema_options['notAccessibleForFree']) || $schema_options['notAccessibleForFree']!=1){echo 'style="display:none"'; }?>>
475
+ <td><label for="isAccessibleForFree"><?php echo esc_html__( 'Is accessible for free', 'schema-and-structured-data-for-wp' ) ?></label></td>
476
+ <td>
477
+ <select name="isAccessibleForFree" id="isAccessibleForFree">
478
+ <option value="False" <?php if( isset($schema_options['isAccessibleForFree']) && $schema_options['isAccessibleForFree']=='False'){echo 'selected'; }?>><?php echo esc_html__( 'False', 'schema-and-structured-data-for-wp' ); ?></option>
479
+ <option value="True" <?php if( isset($schema_options['isAccessibleForFree']) && $schema_options['isAccessibleForFree']=='True'){echo 'selected'; }?>><?php echo esc_html__( 'True', 'schema-and-structured-data-for-wp' ); ?></option>
480
+ </select>
481
+ </td>
482
+ </tr>
483
+ <tr <?php if(!isset($schema_options['notAccessibleForFree']) || $schema_options['notAccessibleForFree']!=1){echo 'style="display:none"'; }?>>
484
+ <td>
485
+ <label for="paywall_class_name"><?php echo esc_html__( 'Enter the class name of paywall section', 'schema-and-structured-data-for-wp' ); ?></label>
486
+ </td>
487
+ <td><input type="text" id="paywall_class_name" name="paywall_class_name" value="<?php if( isset($schema_options['paywall_class_name']) ){echo esc_attr($schema_options['paywall_class_name']); }?>"></td>
488
+ </tr>
489
+ </tbody>
490
+ </table>
491
+ <?php
492
+ }
493
+ add_action( 'admin_enqueue_scripts', 'saswp_style_script_include' );
494
+ function saswp_style_script_include() {
495
+ global $pagenow, $typenow;
496
+ if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php' && $typenow=='saswp') {
497
+ wp_register_script( 'structure_admin', plugin_dir_url(__FILE__) . '/js/structure_admin.js', array( 'jquery'), SASWP_VERSION, true );
498
+ // Localize the script with new data
499
+ $data_array = array(
500
+ 'ajax_url' => admin_url( 'admin-ajax.php' )
501
+ );
502
+ wp_localize_script( 'structure_admin', 'amp_sdwp_field_data', $data_array );
503
+ wp_enqueue_script('structure_admin');
504
+ }
505
+ }
506
+
507
+ // Save PHP Editor
508
+ add_action ( 'save_post' , 'saswp_select_save_data' );
509
+ function saswp_select_save_data ( $post_id ) {
510
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
511
+
512
+ // if our nonce isn't there, or we can't verify it, bail
513
+ if( !isset( $_POST['saswp_select_name_nonce'] ) || !wp_verify_nonce( $_POST['saswp_select_name_nonce'], 'saswp_select_action_nonce' ) ) return;
514
+
515
+ // if our current user can't edit this post, bail
516
+ if( !current_user_can( 'edit_post' ) ) return;
517
+ $post_data_array = array();
518
+
519
+ foreach($_POST['data_array'] as $post){
520
+ $post_data_array[] = array_map('sanitize_text_field', $post);
521
+ }
522
+ $post_schema_type = sanitize_text_field($_POST['schema_type']);
523
+ $notAccessibleForFree = sanitize_text_field($_POST['notAccessibleForFree']);
524
+ $isAccessibleForFree = sanitize_text_field($_POST['isAccessibleForFree']);
525
+ $paywall_class_name = sanitize_text_field($_POST['paywall_class_name']);
526
+ $saswp_schema_options = array('isAccessibleForFree'=>$isAccessibleForFree,'notAccessibleForFree'=>$notAccessibleForFree,'paywall_class_name'=>$paywall_class_name);
527
+
528
+ if(isset($_POST['data_array'])){
529
+ update_post_meta(
530
+ $post_id,
531
+ 'data_array',
532
+ $post_data_array
533
+ );
534
+ update_post_meta(
535
+ $post_id,
536
+ 'schema_type',
537
+ $post_schema_type
538
+ );
539
+ update_post_meta(
540
+ $post_id,
541
+ 'schema_options',
542
+ $saswp_schema_options
543
+ );
544
+ }
545
+ }
546
+ add_action("admin_init",'saswp_migration');
547
+ function saswp_migration(){
548
+ $sdwp_migration_posts = get_option("sdwp_migration_posts");
549
+ $sd_data = get_option("sd_data");
550
+ if($sdwp_migration_posts != 'inserted'){
551
+ if(isset($sd_data['sd_page_type'])){
552
+ $postarr = array(
553
+ 'post_type'=>'saswp',
554
+ 'post_title'=>'Default page type',
555
+ 'post_status'=>'publish',
556
+
557
+ );
558
+ $insertedPageId = wp_insert_post( $postarr );
559
+ if($insertedPageId){
560
+ $post_data_array = array(
561
+ array(
562
+ 'key_1'=>'post_type',
563
+ 'key_2'=>'equal',
564
+ 'key_3'=>'page',
565
+ )
566
+ );
567
+ $schema_options_array = array('isAccessibleForFree'=>False,'notAccessibleForFree'=>0,'paywall_class_name'=>'');
568
+ update_post_meta( $insertedPageId, 'data_array', $post_data_array);
569
+ update_post_meta( $insertedPageId, 'schema_type', $sd_data['sd_page_type']);
570
+ update_post_meta( $insertedPageId, 'schema_options', $schema_options_array);
571
+ }
572
+ }
573
+ if(isset($sd_data['sd_post_type'])){
574
+ $postarr = array(
575
+ 'post_type'=>'saswp',
576
+ 'post_title'=>'Default post type',
577
+ 'post_status'=>'publish',
578
+
579
+ );
580
+ $insertedPageId = wp_insert_post( $postarr );
581
+ if($insertedPageId){
582
+ $post_data_array = array(
583
+ array(
584
+ 'key_1'=>'post_type',
585
+ 'key_2'=>'equal',
586
+ 'key_3'=>'post',
587
+ )
588
+ );
589
+ $schema_options_array = array('isAccessibleForFree'=>False,'notAccessibleForFree'=>0,'paywall_class_name'=>'');
590
+ update_post_meta( $insertedPageId, 'data_array', $post_data_array);
591
+ update_post_meta( $insertedPageId, 'schema_type', $sd_data['sd_post_type']);
592
+ update_post_meta( $insertedPageId, 'schema_options', $schema_options_array);
593
+ }
594
+ }
595
+
596
+ update_option( "sdwp_migration_posts", "inserted");
597
+
598
+ }
599
+ }
600
+
601
+ }//CLosed is_admin
602
+
603
+ // Generate Proper post types for select and to add data.
604
+ add_action('wp_loaded', 'saswp_post_type_generator');
605
+
606
+ function saswp_post_type_generator(){
607
+
608
+ $post_types = '';
609
+ $post_types = get_post_types( array( 'public' => true ), 'names' );
610
+
611
+ // Remove Unsupported Post types
612
+ unset($post_types['attachment'], $post_types['amp_acf']);
613
+
614
+ return $post_types;
615
+ }
616
+
617
+ add_action('wp_head','saswp_custom_breadcrumbs',99);
618
+
619
+ // Breadcrumbs
620
+ function saswp_custom_breadcrumbs() {
621
+ global $sd_data;
622
+ $variables1_titles = array();
623
+ $variables2_links = array();
624
+ // Settings
625
+ $separator = '&gt;';
626
+ $home_title = esc_html__('Homepage', 'schema-and-structured-data-for-wp' );
627
+
628
+ // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat)
629
+ $custom_taxonomy = 'product_cat';
630
+
631
+ // Get the query & post information
632
+ global $post;
633
+
634
+ // Do not display on the homepage
635
+ if ( !is_front_page() ) {
636
+
637
+ // Build the breadcrums
638
+ // Home page
639
+ $variables1_titles[] = $home_title;
640
+ $variables2_links[] = get_home_url();
641
+
642
+
643
+ if ( is_archive() && !is_tax() && !is_category() && !is_tag() && !is_author() ) {
644
+ $archive_title = post_type_archive_title($prefix, false);
645
+ $variables1_titles[] = $archive_title;
646
+
647
+
648
+ } else if ( is_author() ) {
649
+ global $author;
650
+
651
+ $userdata = get_userdata( $author );
652
+ $author_url= get_author_posts_url($userdata->ID);
653
+
654
+ // author name
655
+ $variables1_titles[]= $userdata->display_name;
656
+ $variables2_links[]= $author_url;
657
+
658
+ } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) {
659
+
660
+ // If post is a custom post type
661
+ $post_type = get_post_type();
662
+
663
+ // If it is a custom post type display name and link
664
+ if($post_type != 'post') {
665
+
666
+ $post_type_object = get_post_type_object($post_type);
667
+ $post_type_archive = get_post_type_archive_link($post_type);
668
+ $variables1_titles[] = $post_type_object->labels->name;
669
+ $variables2_links[] = $post_type_archive;
670
+
671
+ }
672
+
673
+ $custom_tax_name = get_queried_object()->name;
674
+ $variables1_titles[] = $custom_tax_name;
675
+
676
+ } else if ( is_single() ) {
677
+
678
+ // If post is a custom post type
679
+ $post_type = get_post_type();
680
+
681
+ // If it is a custom post type display name and link
682
+ if($post_type != 'post') {
683
+
684
+ $post_type_object = get_post_type_object($post_type);
685
+ $post_type_archive = get_post_type_archive_link($post_type);
686
+
687
+ $variables1_titles[]= $post_type_object->labels->name;
688
+ $variables2_links[]= $post_type_archive;
689
+ }
690
+
691
+ // Get post category info
692
+ $category = get_the_category();
693
+
694
+ if(!empty($category)) {
695
+ $category_values = array_values( $category );
696
+ foreach ($category_values as $category_value) {
697
+ $category_name = get_category($category_value);
698
+ $cat_name = $category_name->name;
699
+ $variables1_titles[]=$cat_name;
700
+ $variables2_links[]=get_category_link( $category_value );
701
+
702
+ }
703
+ // Get last category post is in
704
+ $last_category = end(($category));
705
+ $category_name = get_category($last_category);
706
+ // Get parent any categories and create array
707
+ $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),',');
708
+ $cat_parents = explode(',',$get_cat_parents);
709
+
710
+ // Loop through parent categories and store in variable $cat_display
711
+ $cat_display = '';
712
+ foreach($cat_parents as $parents) {
713
+ $cat_display .= '<li class="item-cat">'.esc_html__( $parents, 'schema-and-structured-data-for-wp' ).'</li>';
714
+ $cat_display .= '<li class="separator"> ' . esc_html__( $separator, 'schema-and-structured-data-for-wp' ) . ' </li>';
715
+ }
716
+ }
717
+
718
+ // If it's a custom post type within a custom taxonomy
719
+ $taxonomy_exists = taxonomy_exists($custom_taxonomy);
720
+ if(empty($last_category) && !empty($custom_taxonomy) && $taxonomy_exists) {
721
+
722
+ $taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy );
723
+ $cat_id = $taxonomy_terms[0]->term_id;
724
+ $cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy);
725
+ $cat_name = $taxonomy_terms[0]->name;
726
+
727
+ }
728
+
729
+ if(!empty($cat_id)) {
730
+ $variables1_titles[]= $cat_name;
731
+ $variables2_links[]=$cat_link;
732
+
733
+ } else {
734
+ if($post_type == 'post') {
735
+ $variables1_titles[]= get_the_title();
736
+ }
737
+ }
738
+
739
+ } else if ( is_category() ) {
740
+ $category = get_the_category();
741
+
742
+ if(!empty($category)) {
743
+ $category_values = array_values( $category );
744
+ foreach ($category_values as $category_value) {
745
+ $category_name = get_category($category_value);
746
+ $cat_name = $category_name->name;
747
+ $variables1_titles[]=$cat_name;
748
+ $variables2_links[]=get_category_link( $category_value );
749
+
750
+ }
751
+ }
752
+ } else if ( is_page() ) {
753
+
754
+ // Standard page
755
+ if( $post->post_parent ){
756
+
757
+ // If child page, get parents
758
+ $anc = get_post_ancestors( $post->ID );
759
+
760
+ // Get parents in the right order
761
+ $anc = array_reverse($anc);
762
+
763
+ // Parent page loop
764
+ if ( !isset( $parents ) ) $parents = null;
765
+ foreach ( $anc as $ancestor ) {
766
+ $parents .= '<li class="item-parent item-parent-' . esc_attr($ancestor) . '"><a class="bread-parent bread-parent-' . esc_attr($ancestor) . '" href="' . esc_url(get_permalink($ancestor)) . '" title="' . esc_attr(get_the_title($ancestor)) . '">' . esc_html__(get_the_title($ancestor), 'schema-and-structured-data-for-wp' ) . '</a></li>';
767
+ $parents .= '<li class="separator separator-' . esc_attr($ancestor) . '"> ' . esc_html__($separator, 'schema-and-structured-data-for-wp' ) . ' </li>';
768
+ $variables1_titles[]= get_the_title($ancestor);
769
+ $variables2_links[]=get_permalink($ancestor);
770
+ }
771
+
772
+ $variables1_titles[]= get_the_title();
773
+ $variables2_links[]=get_permalink();
774
+
775
+ } else {
776
+ $variables1_titles[]=get_the_title();
777
+ $variables2_links[]=get_permalink();
778
+ }
779
+
780
+ } else if ( is_tag() ) {
781
+ // Tag page
782
+ // Get tag information
783
+ $term_id = get_query_var('tag_id');
784
+ $taxonomy = 'post_tag';
785
+ $args = 'include=' . $term_id;
786
+ $terms = get_terms( $taxonomy, $args );
787
+ $get_term_id = $terms[0]->term_id;
788
+ $get_term_name = $terms[0]->name;
789
+ $term_link = get_term_link($get_term_id );
790
+
791
+ // Tag name and link
792
+
793
+ $variables1_titles[] = $get_term_name;
794
+ $variables2_links[] = $term_link;
795
+ }
796
+ $sd_data['titles']= $variables1_titles;
797
+ $sd_data['links']= $variables2_links;
798
+ }
799
+
800
+ }
metaboxes/help.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * To change this license header, choose License Headers in Project Properties.
4
+ * To change this template file, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+ add_action( 'add_meta_boxes', 'saswp_help_meta_box' );
8
+ function saswp_help_meta_box()
9
+ {
10
+ add_meta_box( 'saswp_help_meta_box_id',
11
+ esc_html__('Help', 'schema-and-structured-data-for-wp' ),
12
+ 'saswp_help_meta_box_cb',
13
+ 'saswp',
14
+ 'advanced', 'low'
15
+ );
16
+ }
17
+
18
+ function saswp_help_meta_box_cb()
19
+ {
20
+ echo '<a href="admin.php?page=structured_data_options&tab=help">'.esc_html__('Need Help', 'schema-and-structured-data-for-wp').'</a>';
21
+ }
output/function.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ add_filter( 'amp_init', 'saswp_structured_data' );
3
+ function saswp_structured_data()
4
+ {
5
+ add_action( 'amp_post_template_head' , 'saswp_data_generator' );
6
+ remove_action( 'amp_post_template_head', 'amp_post_template_add_schemaorg_metadata',10,1);
7
+ }
8
+
9
+ add_action('wp_head', 'saswp_data_generator');
10
+ function saswp_data_generator() {
11
+ global $sd_data;
12
+ $output ='';
13
+ $contact_page_output = saswp_contact_page_output();
14
+ $about_page_output = saswp_about_page_output();
15
+ $author_output = saswp_author_output();
16
+ $archive_output = saswp_archive_output();
17
+ $kb_website_output = saswp_kb_website_output();
18
+ $schema_breadcrumb_output = saswp_schema_breadcrumb_output($sd_data);
19
+ $schema_output = saswp_schema_output();
20
+ $kb_schema_output = saswp_kb_schema_output();
21
+
22
+ if( ( 1 == $sd_data['saswp-for-wordpress'] && saswp_non_amp() ) || ( 1 == $sd_data['saswp-for-amp'] && !saswp_non_amp() ) ) {
23
+
24
+ $output .= "\n\n";
25
+ if(!empty($contact_page_output)){
26
+ $output .= "//Contact page Schema\n";
27
+ $output .= $contact_page_output;
28
+ $output .= "\n\n";
29
+ }
30
+ if(!empty($about_page_output)){
31
+ $output .= "//About page Schema\n";
32
+ $output .= $about_page_output;
33
+ $output .= "\n\n";
34
+ }
35
+ if(!empty($author_output)){
36
+ $output .= "//Author Schema\n";
37
+ $output .= $author_output;
38
+ $output .= "\n\n";
39
+ }
40
+
41
+ if(!empty($archive_output)){
42
+ $output .= "//Archive Schema\n";
43
+ $output .= $archive_output;
44
+ $output .= "\n\n";
45
+ }
46
+ if(!empty($kb_website_output)){
47
+ $output .= "//Website Schema\n";
48
+ $output .= $kb_website_output;
49
+ $output .= "\n\n";
50
+ }
51
+ if(!empty($schema_breadcrumb_output)){
52
+ $output .= "//Breadcrumbs navigation Schema\n";
53
+ $output .= $schema_breadcrumb_output;
54
+ $output .= "\n\n";
55
+ }
56
+
57
+ if(!empty($schema_output)){
58
+ $output .= "// Type Schmea\n";
59
+ $output .= $schema_output;
60
+ $output .= "\n\n";
61
+ }
62
+
63
+ if(!empty($kb_schema_output)){
64
+ $output .= "//Organization Schema\n";
65
+ $output .= $kb_schema_output;
66
+ $output .= "\n\n";
67
+ }
68
+
69
+ }
70
+ echo '<!-- Schema And Structured Data For WP v'.SASWP_VERSION.' - -->';
71
+ echo "\n";
72
+ echo '<script type="application/ld+json">';
73
+ echo html_entity_decode(esc_html($output));
74
+ echo '</script>';
75
+ echo "\n\n";
76
+ }
77
+
78
+ add_filter('the_content', 'saswp_paywall_data_for_login');
79
+ function saswp_paywall_data_for_login($content){
80
+ if( saswp_non_amp() ){
81
+ return $content;
82
+ }
83
+ remove_filter('the_content', 'MeprAppCtrl::page_route', 60);
84
+
85
+ $schemaConditionals = saswp_get_all_schema_posts();
86
+ if(!$schemaConditionals){
87
+ return $content;
88
+ }else{
89
+ $schema_options = $schemaConditionals['schema_options'];
90
+ if($schema_options['paywall_class_name']!=''){
91
+ $className = $schema_options['paywall_class_name'];
92
+ }
93
+ if(strpos($content, '<!--more-->')!==false && !is_user_logged_in()){
94
+ global $wp;
95
+ $redirect = home_url( $wp->request );
96
+ $breakedContent = explode("<!--more-->", $content);
97
+ $content = $breakedContent[0].'<a href="'.wp_login_url( $redirect ) .'">'.esc_html__( 'Login', 'schema-and-structured-data-for-wp' ).'</a>';
98
+ }elseif(strpos($content, '<!--more-->')!==false && is_user_logged_in()){
99
+ global $wp;
100
+ $redirect = home_url( $wp->request );
101
+ $breakedContent = explode("<!--more-->", $content);
102
+ $content = $breakedContent[0].'<div class="'.$className.'">'.$breakedContent[1].'</div>';
103
+ }
104
+ }
105
+ return $content;
106
+ }
107
+
108
+ add_filter('memberpress_form_update', 'saswp_memberpress_form_update');
109
+
110
+ function saswp_memberpress_form_update($form){
111
+ if( !saswp_non_amp() ){
112
+ add_action('amp_post_template_css',function(){
113
+ echo '.amp-mem-login{background-color: #fef5c4;padding: 13px 30px 9px 30px;}';
114
+ },11);
115
+ global $wp;
116
+ $redirect = home_url( $wp->request );
117
+ $form = '<a class="amp-mem-login" href="'.wp_login_url( $redirect ) .'">'.esc_html__( 'Login', 'schema-and-structured-data-for-wp' ).'</a>';
118
+ }
119
+ return $form;
120
+ }
output/output.php ADDED
@@ -0,0 +1,863 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (! defined('ABSPATH') ) exit;
3
+
4
+ function saswp_kb_schema_output() {
5
+ global $sd_data;
6
+ if( (!saswp_non_amp() && $sd_data['saswp-for-amp']!=1) || (saswp_non_amp() && $sd_data['saswp-for-wordpress']!=1) ) {
7
+ return ;
8
+ }
9
+ // social profile
10
+ $sd_social_profile = array();
11
+
12
+ $sd_facebook = array();
13
+ if(isset($sd_data['sd_facebook']) && !empty($sd_data['sd_facebook'])){
14
+ $sd_facebook[] = $sd_data['sd_facebook'];
15
+ $sd_social_profile[] = $sd_facebook;
16
+ }
17
+ $sd_twitter = array();
18
+ if(isset($sd_data['sd_twitter']) && !empty($sd_data['sd_twitter'])){
19
+ $sd_twitter[] = $sd_data['sd_twitter'];
20
+ $sd_social_profile[] = $sd_twitter;
21
+ }
22
+
23
+ $sd_google_plus = array();
24
+ if(isset($sd_data['sd_google_plus']) && !empty($sd_data['sd_google_plus'])){
25
+ $sd_google_plus[] = $sd_data['sd_google_plus'];
26
+ $sd_social_profile[] = $sd_google_plus;
27
+ }
28
+
29
+ $sd_instagram = array();
30
+ if(isset($sd_data['sd_instagram']) && !empty($sd_data['sd_instagram'])){
31
+ $sd_instagram[] = $sd_data['sd_instagram'];
32
+ $sd_social_profile[] = $sd_instagram;
33
+ }
34
+
35
+ $sd_youtube = array();
36
+ if(isset($sd_data['sd_youtube']) && !empty($sd_data['sd_youtube'])){
37
+ $sd_youtube[] = $sd_data['sd_youtube'];
38
+ $sd_social_profile[] = $sd_youtube;
39
+ }
40
+
41
+ $sd_linkedin = array();
42
+ if(isset($sd_data['sd_linkedin']) && !empty($sd_data['sd_linkedin'])){
43
+ $sd_linkedin[] = $sd_data['sd_linkedin'];
44
+ $sd_social_profile[] = $sd_linkedin;
45
+ }
46
+
47
+ $sd_pinterest = array();
48
+ if(isset($sd_data['sd_pinterest']) && !empty($sd_data['sd_pinterest'])){
49
+ $sd_pinterest[] = $sd_data['sd_pinterest'];
50
+ $sd_social_profile[] = $sd_pinterest;
51
+ }
52
+
53
+ $sd_soundcloud = array();
54
+ if(isset($sd_data['sd_soundcloud']) && !empty($sd_data['sd_soundcloud'])){
55
+ $sd_soundcloud[] = $sd_data['sd_soundcloud'];
56
+ $sd_social_profile[] = $sd_soundcloud;
57
+ }
58
+
59
+ $sd_tumblr = array();
60
+ if(isset($sd_data['sd_tumblr']) && !empty($sd_data['sd_tumblr'])){
61
+ $sd_tumblr[] = $sd_data['sd_tumblr'];
62
+ $sd_social_profile[] = $sd_tumblr;
63
+ }
64
+
65
+ $platform = array();
66
+ foreach ($sd_social_profile as $key => $value) {
67
+ $platform[] = $value;
68
+ }
69
+
70
+ // Organization Schema
71
+
72
+
73
+ if ( $sd_data['saswp_kb_type'] == 'Organization' ) {
74
+ $logo = $sd_data['sd_logo']['url'];
75
+ $contact_1 = $sd_data['saswp_contact_type'];
76
+ $telephone_1 = $sd_data['saswp_kb_telephone'];
77
+ $height = $sd_data['sd_logo']['height'];
78
+ $width = $sd_data['sd_logo']['width'];
79
+
80
+ if( '' == $logo && empty($logo) && isset($sd_data['sd_default_image'])){
81
+ $logo = $sd_data['sd_default_image']['url'];
82
+ }
83
+
84
+ if( '' == $height && empty($height) && isset($sd_data['sd_default_image_height'])){
85
+ $height = $sd_data['sd_default_image_height'];
86
+ }
87
+
88
+ if( '' == $width && empty($width) && isset($sd_data['sd_default_image_width'])){
89
+ $width = $sd_data['sd_default_image_width'];
90
+ }
91
+
92
+ if( '' == $contact_1 && empty($contact_1) && isset($sd_data['saswp_contact_type'])){
93
+ $contact_1 = $sd_data['saswp_contact_type'];
94
+ }
95
+
96
+ if( '' == $telephone_1 && empty($telephone_1) && isset($sd_data['saswp_kb_telephone'])){
97
+ $telephone_1 = $sd_data['saswp_kb_telephone'];
98
+ }
99
+
100
+ // Contact Information
101
+ $contact_info = array();
102
+ $contact_info = array(
103
+ 'contactPoint' => array(
104
+ '@type' => 'ContactPoint',
105
+ 'contactType' => $contact_1,
106
+ 'telephone' => $telephone_1,
107
+ )
108
+ );
109
+
110
+ $input = array(
111
+ '@context' =>'http://schema.org',
112
+ '@type' => $sd_data['saswp_kb_type'],
113
+ 'name' => $sd_data['sd_name'],
114
+ 'url' => $sd_data['sd_url'],
115
+ 'sameAs' => $platform,
116
+ 'logo' => array(
117
+ '@type' => 'ImageObject',
118
+ 'url' => $logo,
119
+ 'width' => $width,
120
+ 'height' => $height,
121
+ ),
122
+ 'alternateName' => $sd_data['sd_alt_name']
123
+ );
124
+
125
+ if ( isset($sd_data['saswp_kb_contact_1'] ) && $sd_data['saswp_kb_contact_1'] ) {
126
+ $input = array_merge($input, $contact_info);
127
+ }
128
+ }
129
+ // Person
130
+
131
+ if ( $sd_data['saswp_kb_type'] == 'Person' ) {
132
+ $image = $sd_data['sd-person-image']['url'];
133
+ $height = $sd_data['sd-person-image']['height'];
134
+ $width = $sd_data['sd-person-image']['width'];
135
+ if( '' == $image && empty($image) && isset($sd_data['sd_default_image'])){
136
+ $image = $sd_data['sd_default_image']['url'];
137
+ }
138
+
139
+ if( '' == $height && empty($height) && isset($sd_data['sd_default_image_height'])){
140
+ $height = $sd_data['sd_default_image_height'];
141
+ }
142
+
143
+ if( '' == $width && empty($width) && isset($sd_data['sd_default_image_width'])){
144
+ $width = $sd_data['sd_default_image_width'];
145
+ }
146
+
147
+ $input = array(
148
+ '@context' =>'http://schema.org',
149
+ '@type' => $sd_data['saswp_kb_type'],
150
+ 'name' => $sd_data['sd-person-name'],
151
+ 'url' => $sd_data['sd-person-url'],
152
+ 'Image' => array(
153
+ '@type' => 'ImageObject',
154
+ 'url' => $image,
155
+ 'width' => $width,
156
+ 'height' => $height,
157
+ ),
158
+ 'telephone' => $sd_data['sd-person-phone-number'],
159
+ );
160
+ }
161
+
162
+ return json_encode($input);
163
+
164
+ }
165
+
166
+ function sd_is_blog() {
167
+ return ( is_author() || is_category() || is_tag() || is_date() || is_home() || is_single() ) && 'post' == get_post_type();
168
+ }
169
+
170
+ function saswp_schema_output() {
171
+ global $sd_data;
172
+
173
+ $schemaConditionals = saswp_get_all_schema_posts();
174
+ if(!$schemaConditionals){
175
+ return ;
176
+ }
177
+ if( (!saswp_non_amp() && $sd_data['saswp-for-amp']!=1) || (saswp_non_amp() && $sd_data['saswp-for-wordpress']!=1) ) {
178
+ return ;
179
+ }
180
+ $schema_options = $schemaConditionals['schema_options'];
181
+ $schema_type = $schemaConditionals['schema_type'];
182
+ $logo = $sd_data['sd_logo']['url'];
183
+ if( '' == $logo && empty($logo) && isset($sd_data['sd_default_image'])){
184
+ $logo = $sd_data['sd_default_image']['url'];
185
+ }
186
+ $height = $sd_data['sd_logo']['height'];
187
+ if( '' == $height && empty($height) && isset($sd_data['sd_default_image_height'])){
188
+ $height = $sd_data['sd_default_image_height'];
189
+ }
190
+ $width = $sd_data['sd_logo']['width'];
191
+ if( '' == $width && empty($width) && isset($sd_data['sd_default_image_width'])){
192
+ $width = $sd_data['sd_default_image_width'];
193
+ }
194
+ if(is_singular()){
195
+ // Generate author id
196
+ $author_id = get_the_author_meta('ID');
197
+
198
+ // Blogposting Schema
199
+ $image_id = get_post_thumbnail_id();
200
+ $image_details = wp_get_attachment_image_src($image_id, 'full');
201
+ $author_details = get_avatar_data($author_id);
202
+ $date = get_the_date();
203
+ $modified_date = get_the_modified_date();
204
+ $aurthor_name = get_the_author();
205
+
206
+ if(is_page()){
207
+ $schema_type = $schema_type; //$sd_data['sd_page_type'];
208
+ }
209
+ if(is_single()){
210
+ $schema_type = $schema_type; //$sd_data['sd_post_type'];
211
+ }
212
+ if(is_front_page()){
213
+ $schema_type = $schema_type; // $sd_data['sd_page_type'];
214
+ }
215
+ $input1 = array(
216
+ '@context' => 'http://schema.org',
217
+ '@type' => $schema_type ,
218
+
219
+ 'mainEntityOfPage' => get_permalink(),
220
+ 'headline' => get_the_title(),
221
+ 'description' => get_the_excerpt(),
222
+ 'name' => get_the_title(),
223
+ 'url' => get_permalink(),
224
+ 'datePublished' => $date,
225
+ 'dateModified' => $modified_date,
226
+ 'author' => array(
227
+ '@type' => 'Person',
228
+ 'name' => $aurthor_name, ),
229
+ 'Publisher' => array(
230
+ '@type' => 'Organization',
231
+ 'logo' => array(
232
+ '@type' => 'ImageObject',
233
+ 'url' => $logo,
234
+ 'width' => $width,
235
+ 'height' => $height,
236
+ ),
237
+ 'name' => $sd_data['sd_name'],
238
+ ),
239
+ );
240
+ // For WebPage
241
+ if( 'WebPage' === $schema_type){
242
+ if(empty($image_details[0]) || $image_details[0] === NULL ){
243
+ $image_details[0] = $logo;
244
+ }
245
+
246
+ $input1 = array(
247
+ '@context' => 'http://schema.org',
248
+ '@type' => $schema_type ,
249
+ 'name' => get_the_title(),
250
+ 'url' => get_permalink(),
251
+ 'description' => get_the_excerpt(),
252
+ 'mainEntity' => array(
253
+ '@type' => 'Article',
254
+ 'mainEntityOfPage' => get_permalink(),
255
+ 'image' => $image_details[0],
256
+ 'headline' => get_the_title(),
257
+ 'description' => get_the_excerpt(),
258
+ 'datePublished' => $date,
259
+ 'dateModified' => $modified_date,
260
+ 'author' => array(
261
+ '@type' => 'Person',
262
+ 'name' => $aurthor_name, ),
263
+ 'Publisher' => array(
264
+ '@type' => 'Organization',
265
+ 'logo' => array(
266
+ '@type' => 'ImageObject',
267
+ 'url' => $logo,
268
+ 'width' => $width,
269
+ 'height' => $height,
270
+ ),
271
+ 'name' => $sd_data['sd_name'],
272
+ ),
273
+ ),
274
+
275
+
276
+ );
277
+ }
278
+
279
+ // For Article
280
+
281
+ if( 'Article' === $schema_type ){
282
+ $input1 = array(
283
+ '@context' => 'http://schema.org',
284
+ '@type' => 'Article',
285
+ 'mainEntityOfPage' => get_permalink(),
286
+ 'image' => $image_details[0],
287
+ 'headline' => get_the_title(),
288
+ 'description' => get_the_excerpt(),
289
+ 'datePublished' => $date,
290
+ 'dateModified' => $modified_date,
291
+ 'author' => array(
292
+ '@type' => 'Person',
293
+ 'name' => $aurthor_name, ),
294
+ 'Publisher' => array(
295
+ '@type' => 'Organization',
296
+ 'logo' => array(
297
+ '@type' => 'ImageObject',
298
+ 'url' => $sd_data['sd_logo']['url'],
299
+ 'width' => $sd_data['sd_logo']['width'],
300
+ 'height' => $sd_data['sd_logo']['height'],
301
+ ),
302
+ 'name' => $sd_data['sd_name'],
303
+ ),
304
+ );
305
+ }
306
+
307
+ // Recipe
308
+ if( 'Recipe' === $schema_type){
309
+ if(empty($image_details[0]) || $image_details[0] === NULL ){
310
+ $image_details[0] = $sd_data['sd_logo']['url'];
311
+ }
312
+ $input1 = array(
313
+ '@context' => 'http://schema.org',
314
+ '@type' => $schema_type ,
315
+ 'url' => get_permalink(),
316
+ 'headline' => get_the_title(),
317
+ 'datePublished' => $date,
318
+ 'dateModified' => $modified_date,
319
+ 'description' => get_the_excerpt(),
320
+ 'mainEntity' => array(
321
+ '@type' => 'WebPage',
322
+ '@id' => get_permalink(),
323
+ 'author' => array(
324
+ '@type' => 'Person',
325
+ 'name' => $aurthor_name,
326
+ 'Image' => array(
327
+ '@type' => 'ImageObject',
328
+ 'url' => $author_details['url'],
329
+ 'height' => $author_details['height'],
330
+ 'width' => $author_details['width']
331
+ ),
332
+ ),
333
+ 'Publisher' => array(
334
+ '@type' => 'Organization',
335
+ 'logo' => array(
336
+ '@type' => 'ImageObject',
337
+ 'url' => $sd_data['sd_logo']['url'],
338
+ 'width' => $sd_data['sd_logo']['width'],
339
+ 'height' => $sd_data['sd_logo']['height'],
340
+ ),
341
+ 'name' => $sd_data['sd_name'],
342
+ ),
343
+ ),
344
+
345
+
346
+ );
347
+ }
348
+
349
+ // Product
350
+
351
+ if( 'Product' === $schema_type){
352
+ if(empty($image_details[0]) || $image_details[0] === NULL ){
353
+ $image_details[0] = $logo;
354
+ }
355
+ $input1 = array(
356
+ '@context' => 'http://schema.org',
357
+ '@type' => $schema_type ,
358
+ 'url' => get_permalink(),
359
+ 'name' => get_the_title(),
360
+ 'description' => get_the_excerpt(),
361
+ 'mainEntity' => array(
362
+ '@type' => 'WebPage',
363
+ '@id' => get_permalink(),
364
+ ),
365
+
366
+
367
+ );
368
+ }
369
+
370
+ // VideoObject
371
+ if( 'VideoObject' === $schema_type){
372
+ if(empty($image_details[0]) || $image_details[0] === NULL ){
373
+ $image_details[0] = $sd_data['sd_logo']['url'];
374
+ }
375
+
376
+ if( 'NewsArticle' === $schema_type ){
377
+ $input1 = array(
378
+ '@context' => 'http://schema.org',
379
+ '@type' => $schema_type ,
380
+ '@type' => $schema_type,
381
+ 'mainEntityOfPage' => get_permalink(),
382
+ 'url' => get_permalink(),
383
+ 'headline' => get_the_title(),
384
+ 'datePublished' => $date,
385
+ 'dateModified' => $modified_date,
386
+ 'description' => get_the_excerpt(),
387
+ 'name' => get_the_title(),
388
+ 'thumbnailUrl' => $image_details[0],
389
+ 'mainEntity' => array(
390
+ '@type' => 'WebPage',
391
+ '@id' => get_permalink(),
392
+ ),
393
+ 'author' => array(
394
+ '@type' => 'Person',
395
+ 'name' => $aurthor_name,
396
+ 'Image' => array(
397
+ '@type' => 'ImageObject',
398
+ 'url' => $author_details['url'],
399
+ 'height' => $author_details['height'],
400
+ 'width' => $author_details['width']
401
+ ),
402
+ ),
403
+ 'Publisher' => array(
404
+ '@type' => 'Organization',
405
+ 'logo' => array(
406
+ '@type' => 'ImageObject',
407
+ 'url' => $sd_data['sd_logo']['url'],
408
+ 'width' => $sd_data['sd_logo']['width'],
409
+ 'height' => $sd_data['sd_logo']['height'],
410
+ ),
411
+ 'name' => $sd_data['sd_name'],
412
+ ),
413
+ );
414
+ }
415
+ else {
416
+
417
+ $input1 = array(
418
+ '@context' => 'http://schema.org',
419
+ '@type' => $schema_type,
420
+ 'url' => get_permalink(),
421
+ 'headline' => get_the_title(),
422
+ 'datePublished' => $date,
423
+ 'dateModified' => $modified_date,
424
+ 'description' => get_the_excerpt(),
425
+ 'name' => get_the_title(),
426
+ 'uploadDate' => $date,
427
+ 'thumbnailUrl' => $image_details[0],
428
+ 'mainEntity' => array(
429
+ '@type' => 'WebPage',
430
+ '@id' => get_permalink(),
431
+ ),
432
+ 'author' => array(
433
+ '@type' => 'Person',
434
+ 'name' => $aurthor_name,
435
+ 'Image' => array(
436
+ '@type' => 'ImageObject',
437
+ 'url' => $author_details['url'],
438
+ 'height' => $author_details['height'],
439
+ 'width' => $author_details['width']
440
+ ),
441
+ ),
442
+ 'Publisher' => array(
443
+ '@type' => 'Organization',
444
+ 'logo' => array(
445
+ '@type' => 'ImageObject',
446
+ 'url' => $sd_data['sd_logo']['url'],
447
+ 'width' => $sd_data['sd_logo']['width'],
448
+ 'height' => $sd_data['sd_logo']['height'],
449
+ ),
450
+ 'name' => $sd_data['sd_name'],
451
+ ),
452
+ );
453
+ }
454
+ }
455
+
456
+ //Check for Featured Image
457
+ if( is_array($image_details) ){
458
+ if(isset($image_details[1]) ){
459
+ $width = $image_details[1];
460
+ }
461
+ if(isset($image_details[2])){
462
+ $height = $image_details[2];
463
+ }
464
+ $input2 = array(
465
+ 'image' =>array(
466
+ '@type' =>'ImageObject',
467
+ 'url' =>$image_details[0],
468
+ 'width' =>$width,
469
+ 'height' =>$height,
470
+ ),
471
+ );
472
+ $input = array_merge($input1,$input2);
473
+ }
474
+ else{
475
+ $input2 = array(
476
+ 'image' =>array(
477
+ '@type' =>'ImageObject',
478
+ 'url' => $sd_data['sd_logo']['url'],
479
+ 'width' => $sd_data['sd_logo']['width'],
480
+ 'height' => $sd_data['sd_logo']['height'],
481
+ ),
482
+ );
483
+ $input = array_merge($input1,$input2);
484
+ }
485
+ if($schema_options['notAccessibleForFree']==1){
486
+
487
+ add_filter( 'amp_post_template_data', 'saswp_structure_data_access_scripts');
488
+ $paywall_class_name = $schema_options['paywall_class_name'];
489
+ $isAccessibleForFree = isset($schema_options['isAccessibleForFree'])? $schema_options['isAccessibleForFree']: False;
490
+
491
+ if($paywall_class_name!=""){
492
+ if(strpos($paywall_class_name, ".")==-1){
493
+ $paywall_class_name = ".".$paywall_class_name;
494
+ }
495
+ $paywallData = array("isAccessibleForFree"=> $isAccessibleForFree,
496
+ "hasPart"=>array(
497
+ "@type"=> "WebPageElement",
498
+ "isAccessibleForFree"=> $isAccessibleForFree,
499
+ "cssSelector" => $paywall_class_name
500
+ )
501
+ );
502
+ $input = array_merge($input,$paywallData);
503
+ }
504
+ }
505
+ return json_encode($input);
506
+ }
507
+
508
+ }
509
+
510
+ function saswp_structure_data_access_scripts($data){
511
+ if ( empty( $data['amp_component_scripts']['amp-access'] ) ) {
512
+ $data['amp_component_scripts']['amp-access'] = 'https://cdn.ampproject.org/v0/amp-access-0.1.js';
513
+ }
514
+ if ( empty( $data['amp_component_scripts']['amp-analytics'] ) ) {
515
+ $data['amp_component_scripts']['amp-analytics'] = "https://cdn.ampproject.org/v0/amp-analytics-0.1.js";
516
+ }
517
+ if ( empty( $data['amp_component_scripts']['amp-mustache'] ) ) {
518
+ $data['amp_component_scripts']['amp-mustache'] = "https://cdn.ampproject.org/v0/amp-mustache-0.1.js";
519
+ }
520
+ return $data;
521
+ }
522
+
523
+ function saswp_list_items_generator(){
524
+ global $sd_data;
525
+ $bc_titles = array();
526
+ $bc_links = array();
527
+ if(isset($sd_data['titles'])){
528
+ $bc_titles = $sd_data['titles'];
529
+ }
530
+ if(isset($sd_data['links'])){
531
+ $bc_links = $sd_data['links'];
532
+ }
533
+ $j=1;
534
+ $i = 0;
535
+ $breadcrumbslist = array();
536
+ if(is_single()){
537
+ if(isset($bc_titles)){
538
+ for($i=0;$i<sizeof($bc_titles);$i++){
539
+ $breadcrumbslist[] = array(
540
+ '@type' => 'ListItem',
541
+ 'position' => $j,
542
+ 'item' => array(
543
+ '@id' => $bc_links[$i],
544
+ 'name' => $bc_titles[$i],
545
+ ),
546
+ );
547
+ $j++;
548
+ }}
549
+ $breadcrumbslist[] = array(
550
+ '@type' =>'ListItem',
551
+ 'position' => $j,
552
+ 'item' => array(
553
+ '@id' => get_permalink(),
554
+ 'name' => get_the_title(),
555
+
556
+ ),
557
+ );
558
+ }
559
+ if(is_page()){
560
+
561
+ for($i=0;$i<sizeof($bc_titles);$i++){
562
+ $breadcrumbslist[] = array(
563
+ '@type' => 'ListItem',
564
+ 'position' => $j,
565
+ 'item' => array(
566
+ '@id' => $bc_links[$i],
567
+ 'name' => $bc_titles[$i],
568
+ ),
569
+ );
570
+ $j++;
571
+ }
572
+
573
+ }
574
+ if(is_archive()){
575
+
576
+ for($i=0;$i<sizeof($bc_titles);$i++){
577
+ $breadcrumbslist[] = array(
578
+ '@type' => 'ListItem',
579
+ 'position' => $j,
580
+ 'item' => array(
581
+ '@id' => $bc_links[$i],
582
+ 'name' => $bc_titles[$i],
583
+ ),
584
+ );
585
+ $j++;
586
+ }
587
+ }
588
+
589
+ return $breadcrumbslist;
590
+ }
591
+
592
+ function saswp_schema_breadcrumb_output($sd_data){
593
+ global $sd_data;
594
+ if( (!saswp_non_amp() && $sd_data['saswp-for-amp']!=1) || (saswp_non_amp() && $sd_data['saswp-for-wordpress']!=1) ) {
595
+ return ;
596
+ }
597
+ if(isset($sd_data['saswp_breadcrumb_schema']) && $sd_data['saswp_breadcrumb_schema'] == 1){
598
+
599
+ $input = array(
600
+ '@context' => 'http://schema.org',
601
+ '@type' => 'BreadcrumbList' ,
602
+ 'itemListElement' =>saswp_list_items_generator(),
603
+ );
604
+ if ( !is_front_page() ) {
605
+ return json_encode($input);
606
+ }
607
+ }
608
+ }
609
+
610
+ function saswp_kb_website_output(){
611
+ global $sd_data;
612
+ if( (!saswp_non_amp() && $sd_data['saswp-for-amp']!=1) || (saswp_non_amp() && $sd_data['saswp-for-wordpress']!=1) ) {
613
+ return ;
614
+ }
615
+ $site_url = get_site_url();
616
+ $site_name = get_bloginfo();
617
+ $input = array(
618
+ '@context' =>'http://schema.org',
619
+ '@type' => 'WebSite',
620
+ 'id' => '#website',
621
+ 'url' => $site_url,
622
+ 'name' => $site_name,
623
+ 'potentialAction' => array(
624
+ '@type' => 'SearchAction',
625
+ 'target' => $site_url.'/?s={search_term_string}',
626
+ 'query-input' => 'required name=search_term_string',
627
+ )
628
+ );
629
+
630
+ return json_encode($input);
631
+ }
632
+ // For Archive
633
+ function saswp_archive_output(){
634
+ global $query_string, $sd_data;
635
+ if( (!saswp_non_amp() && $sd_data['saswp-for-amp']!=1) || (saswp_non_amp() && $sd_data['saswp-for-wordpress']!=1) ) {
636
+ return ;
637
+ }
638
+ if(isset($sd_data['saswp_archive_schema']) && $sd_data['saswp_archive_schema'] == 1){
639
+
640
+ if ( is_category() ) {
641
+ $category_posts = array();
642
+ $category_loop = new WP_Query( $query_string );
643
+ if ( $category_loop->have_posts() ):
644
+ while( $category_loop->have_posts() ): $category_loop->the_post();
645
+ $image_id = get_post_thumbnail_id();
646
+ $image_details = wp_get_attachment_image_src($image_id, 'full');
647
+ $publisher_info = array(
648
+ "type" => "Organization",
649
+ "name" => $sd_data['sd_name'],
650
+ "id" => $sd_data['sd_url'],
651
+ "logo" => $sd_data['sd_logo']['url'],
652
+ );
653
+ $publisher_info['name'] = get_bloginfo('name');
654
+ $publisher_info['id'] = get_the_permalink();
655
+ $category_posts[] = array
656
+ (
657
+ '@type' => 'BlogPosting',
658
+ 'headline' => get_the_title(),
659
+ 'url' => get_the_permalink(),
660
+ 'datePublished' => get_the_date('c'),
661
+ 'dateModified' => get_the_modified_date('c'),
662
+ 'mainEntityOfPage' => get_the_permalink(),
663
+ 'author' => get_the_author(),
664
+ 'publisher' => $publisher_info,
665
+ 'image' => $image_details[0],
666
+ );
667
+
668
+ endwhile;
669
+
670
+ wp_reset_postdata();
671
+
672
+ $category = get_the_category();
673
+ $category_id = intval($category[0]->term_id);
674
+ $category_link = get_category_link( $category_id );
675
+ $category_link = get_term_link( $category[0]->term_id , 'category' );
676
+ $category_headline = single_cat_title( '', false ) . __(' Category', 'schema-wp');
677
+ $input = array
678
+ (
679
+ '@context' => 'http://schema.org/',
680
+ '@type' => "CollectionPage",
681
+ 'headline' => $category_headline,
682
+ 'description' => strip_tags(category_description()),
683
+ 'url' => $category_link,
684
+ 'sameAs' => '',
685
+ 'hasPart' => $category_posts
686
+ );
687
+ return json_encode($input);
688
+ endif;
689
+ }
690
+ }
691
+ }
692
+
693
+ // For Author
694
+ function saswp_author_output()
695
+ {
696
+ global $post, $sd_data;
697
+ if(isset($sd_data['saswp_archive_schema']) && $sd_data['saswp_archive_schema'] == 1){
698
+ $post_id = $post->ID;
699
+ if(is_author()){
700
+ // Get author from post content
701
+ $post_content = get_post($post_id);
702
+ $post_author = get_userdata($post_content->post_author);
703
+ $input = array (
704
+ '@type' => 'Person',
705
+ 'name' => get_the_author_meta('display_name'),
706
+ 'url' => esc_url( get_author_posts_url( $post_author->ID ) ),
707
+
708
+ );
709
+
710
+ $sd_website = esc_attr( stripslashes( get_the_author_meta( 'user_url', $post_author->ID ) ) );
711
+ $sd_googleplus = esc_attr( stripslashes( get_the_author_meta( 'googleplus', $post_author->ID ) ) );
712
+ $sd_facebook = esc_attr( stripslashes( get_the_author_meta( 'facebook', $post_author->ID) ) );
713
+ $sd_twitter = esc_attr( stripslashes( get_the_author_meta( 'twitter', $post_author->ID ) ) );
714
+ $sd_instagram = esc_attr( stripslashes( get_the_author_meta( 'instagram', $post_author->ID ) ) );
715
+ $sd_youtube = esc_attr( stripslashes( get_the_author_meta( 'youtube', $post_author->ID ) ) );
716
+ $sd_linkedin = esc_attr( stripslashes( get_the_author_meta( 'linkedin', $post_author->ID ) ) );
717
+ $sd_pinterest = esc_attr( stripslashes( get_the_author_meta( 'pinterest', $post_author->ID ) ) );
718
+ $sd_soundcloud = esc_attr( stripslashes( get_the_author_meta( 'soundcloud', $post_author->ID ) ) );
719
+ $sd_tumblr = esc_attr( stripslashes( get_the_author_meta( 'tumblr', $post_author->ID ) ) );
720
+
721
+ $sd_sameAs_links = array( $sd_website, $sd_googleplus, $sd_facebook, $sd_twitter, $sd_instagram, $sd_youtube, $sd_linkedin, $sd_pinterest, $sd_soundcloud, $sd_tumblr);
722
+
723
+ $sd_social = array();
724
+
725
+ // Remove empty fields
726
+ foreach( $sd_sameAs_links as $sd_sameAs_link ) {
727
+ if ( '' != $sd_sameAs_link ) $sd_social[] = $sd_sameAs_link;
728
+ }
729
+
730
+ if ( ! empty($sd_social) ) {
731
+ $input["sameAs"] = $sd_social;
732
+ }
733
+
734
+ if ( get_the_author_meta( 'description', $post_author->ID ) ) {
735
+ $input['description'] = strip_tags( get_the_author_meta( 'description', $post_author->ID ) );
736
+ }
737
+ return json_encode($input);
738
+ }
739
+ }
740
+ }
741
+
742
+ // For About Page
743
+ function saswp_about_page_output()
744
+ {
745
+ global $sd_data;
746
+ $image_id = get_post_thumbnail_id();
747
+ $image_details = wp_get_attachment_image_src($image_id, 'full');
748
+ if(isset($image_details['url'])){
749
+ $image_url = $image_details['url'];
750
+ }
751
+ $about_page = $sd_data['sd_about_page'];
752
+
753
+ if(isset($sd_data['sd_about_page']) && $sd_data['sd_about_page'] === get_the_ID()){
754
+
755
+ $logo = $sd_data['sd_logo']['url'];
756
+ $height = $sd_data['sd_logo']['height'];
757
+ $width = $sd_data['sd_logo']['width'];
758
+
759
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image'])){
760
+ $image_url = $sd_data['sd_default_image']['url'];
761
+ }
762
+
763
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image_height'])){
764
+ $height = $sd_data['sd_default_image_height'];
765
+ }
766
+
767
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image_width'])){
768
+ $width = $sd_data['sd_default_image_width'];
769
+ }
770
+ $input = array(
771
+ "@context" => "http://schema.org",
772
+ "@type" => "AboutPage",
773
+ "mainEntityOfPage" => array(
774
+ "@type" => "WebPage",
775
+ "@id" => get_permalink(),
776
+ ),
777
+ "url" => $about_page,
778
+ "headline" => get_the_title(),
779
+ "image" => array(
780
+ "@type" => "ImageObject",
781
+ "url" => $image_url,
782
+ "width" => $width,
783
+ "height" => $height,
784
+ ),
785
+ 'Publisher' => array(
786
+ '@type' => 'Organization',
787
+ 'logo' => array(
788
+ '@type' => 'ImageObject',
789
+ 'url' => $logo,
790
+ 'width' => $width,
791
+ 'height' => $height,
792
+ ),
793
+ 'name' => $sd_data['sd_name'],
794
+ ),
795
+ 'description' => get_the_excerpt(),
796
+ );
797
+
798
+ return json_encode($input);
799
+ }
800
+
801
+ }
802
+
803
+ // For Contact Page
804
+ function saswp_contact_page_output()
805
+ {
806
+ global $sd_data;
807
+ $image_id = get_post_thumbnail_id();
808
+ $image_details = wp_get_attachment_image_src($image_id, 'full');
809
+ if(isset($image_details['url'])){
810
+ $image_url = $image_details['url'];
811
+ }
812
+ $contact_page = $sd_data['sd_contact_page'];
813
+
814
+ if(isset($sd_data['sd_contact_page']) && $sd_data['sd_contact_page'] === get_the_ID()){
815
+
816
+ $logo = $sd_data['sd_logo']['url'];
817
+ $height = $sd_data['sd_logo']['height'];
818
+ $width = $sd_data['sd_logo']['width'];
819
+
820
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image'])){
821
+ $image_url = $sd_data['sd_default_image']['url'];
822
+ }
823
+
824
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image_height'])){
825
+ $height = $sd_data['sd_default_image_height'];
826
+ }
827
+
828
+ if( '' == $image_details && empty($image_details) && isset($sd_data['sd_default_image_width'])){
829
+ $width = $sd_data['sd_default_image_width'];
830
+ }
831
+ $input = array(
832
+ "@context" => "http://schema.org",
833
+ "@type" => "ContactPage",
834
+ "mainEntityOfPage" => array(
835
+ "@type" => "WebPage",
836
+ "@id" => get_permalink(),
837
+ ),
838
+ "url" => $contact_page,
839
+ "headline" => get_the_title(),
840
+ "image" => array(
841
+ "@type" => "ImageObject",
842
+ "url" => $image_url,
843
+ "width" => $width,
844
+ "height" => $height,
845
+ ),
846
+ 'Publisher' => array(
847
+ '@type' => 'Organization',
848
+ 'logo' => array(
849
+ '@type' => 'ImageObject',
850
+ 'url' => $logo,
851
+ 'width' => $width,
852
+ 'height' => $height,
853
+ ),
854
+ 'name' => $sd_data['sd_name'],
855
+ ),
856
+ 'description' => get_the_excerpt(),
857
+ );
858
+
859
+ return json_encode($input);
860
+
861
+ }
862
+
863
+ }
readme.txt ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Schema and Structured Data for WP & AMP ===
2
+ Contributors: mohammed_kaludi, ahmedkaludi, ampforwp
3
+ Tags: Schema, Structured Data, Google Snippets, Rich Snippets, Schema.org, SEO
4
+ Requires at least: 3.0
5
+ Tested up to: 4.9.8
6
+ Stable tag: 1.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+
11
+ == Description ==
12
+ Schema & Structured Data adds Google Rich Snippets markup according to Schema.org guidelines to structure your site for SEO. (AMP Compatible)
13
+
14
+ = Features =
15
+ * <strong>Schema Types</strong>: are divided into 7 types such as Blog Posting, News article, Web page, Article, Recipe, Product, and Video Object. We are going to add all the schema types in the future. You can request the one you want and we will add it for you!
16
+ * <strong>Conditional Display Feilds</strong>: Meaning you include or exclude any posts, pages, post types, taxonomies and more!
17
+ * <strong>Knowlegde Base Support</strong>: Recognize the content based on the organization or a person via data type option.
18
+ * <strong>Full AMP Compatiblity</strong>: Supports the AMP for WP and AMP by Automattic plugins.
19
+ * <strong>Unlimited Custom Post Types</strong>: You can control to represent the Rich Snippets data in the google search console using unlimited custom post types.
20
+ * <strong>Easy to use</strong> with Minimal Settings
21
+ * <strong>Archive Page Listing</strong> Support
22
+ * <strong>JSON-LD</strong> Format
23
+ * <strong>Breadcrumbs</strong> Listing Support
24
+ * <strong>Constant Development & New Features</strong>: We’ll be releasing the constant updates along with the more handy features as soon as we get the feedback from the users.
25
+ * <strong>Constant Development & New Features</strong>: We’ll be releasing the constant updates along with the more handy features as soon as we get the feedback from the users.
26
+
27
+ = Supported Schema & Structured Data Types: =
28
+ * BlogPosting Schema
29
+ * News Article Schema
30
+ * WebPage Schema
31
+ * NewsArticle Schema
32
+ * Recipe Schema
33
+ * Product Schema
34
+ * VideoObject Schema
35
+
36
+ **We Act Fast on Feedback!**
37
+ We are actively developing this plugin and our aim is to make this plugin into the #1 solution for Schema and Google Structured Data in the world. You can [Request a Feature](https://github.com/ahmedkaludi/schema-and-structured-data-for-wp/issues) or [Report a Bug](http://magazine3.company/contact/).
38
+
39
+ **Technical Support**
40
+ Support is provided in [Forum](https://wordpress.org/support/plugin/schema-and-structured-data-for-wp). You can also [Contact us](http://magazine3.company/contact/), our turn around time on email is around 12 hours.
41
+
42
+ **Would you like to contribute?**
43
+ You may now contribute to this Schema plugin on Github: [View repository](https://github.com/ahmedkaludi/schema-and-structured-data-for-wp) on Github
44
+
45
+ == Frequently Asked Questions ==
46
+
47
+ = How to install and use this Schema plugin? =
48
+
49
+ After you Active this plugin, just go to Dashboard > Structured data > Settings, and then setup the default settings, after that, just go back to 'Structured Data' click on Add New and add any data that you like!
50
+
51
+ = How do I report bugs and suggest new features? =
52
+
53
+ You can report the bugs for this Schema plugin [here](https://github.com/ahmedkaludi/schema-and-structured-data-for-wp/issues)
54
+
55
+ = Will you include features to my request? =
56
+
57
+ Yes, Absolutely! We would suggest you send your feature request by creating an issue in [Github](https://github.com/ahmedkaludi/schema-and-structured-data-for-wp/issues/new/) . It helps us organize the feedback easily.
58
+
59
+
60
+ = How do I get in touch? =
61
+ You can contact us from [here](https://ampforwp.com/contact/)
62
+
63
+ == Changelog ==
64
+ = 1.0 (6 August 2018) =
65
+ * Version 1.0 Released
structured-data-for-wp.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Schema and Structured Data for WP
4
+ Description: Schema & Structured Data adds Google Rich Snippets markup according to Schema.org guidelines to structure your site for SEO. (AMP Compatible)
5
+ Version: 1.0
6
+ Text Domain: schema-and-structured-data-for-wp
7
+ Author: Mohammed Kaludi, Ahmed Kaludi
8
+ Author URI: http://ampforwp.com
9
+ Donate link: https://www.paypal.me/Kaludi/25
10
+ License: GPL2
11
+ */
12
+
13
+ // Exit if accessed directly.
14
+ if ( ! defined( 'ABSPATH' ) ) exit;
15
+
16
+ define('SASWP_VERSION', '1.0');
17
+ define('SASWP_DIR_NAME', dirname( __FILE__ ));
18
+
19
+ if ( ! defined( 'SASWP_VERSION' ) ) {
20
+ define( 'SASWP_VERSION', '1.0' );
21
+ }
22
+ // the name of the settings page for the license input to be displayed
23
+ if(! defined('SASWP_ITEM_FOLDER_NAME')){
24
+ $folderName = basename(__DIR__);
25
+ define( 'SASWP_ITEM_FOLDER_NAME', $folderName );
26
+ }
27
+ define('SASWP_PLUGIN_URL', plugin_dir_url( __FILE__ ));
28
+
29
+ // including the output file
30
+ require_once SASWP_DIR_NAME .'/output/function.php';
31
+ require_once SASWP_DIR_NAME .'/output/output.php';
32
+
33
+ // Non amp checker
34
+ if ( ! function_exists('saswp_non_amp') ){
35
+ function saswp_non_amp(){
36
+ $non_amp = true;
37
+ if(function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint() ) {
38
+ $non_amp = false;
39
+ }
40
+ return $non_amp;
41
+ }
42
+ }
43
+ // Schema App end here
44
+ require_once SASWP_DIR_NAME.'/admin_section/structure_admin.php';
45
+ require_once SASWP_DIR_NAME.'/admin_section/settings.php';
46
+ require_once SASWP_DIR_NAME.'/admin_section/common-function.php';
47
+ require_once SASWP_DIR_NAME.'/admin_section/fields-generator.php';
48
+ //Loading Metaboxes
49
+ require SASWP_DIR_NAME.'/metaboxes/help.php';