/** * hunch_schema_add is called to lookup schema.org or add default markup */ public function hunch_schema_add() { global $post; $DisableMarkup = is_singular() ? get_post_meta($post->ID, '_HunchSchemaDisableMarkup', true) : false; if (!$DisableMarkup) { $server = new SchemaServer(); $jsonLd = $server->getResource(); if ($jsonLd === "") { $postType = get_post_type(); $schemaObj = HunchSchema_Thing::factory($postType); if (isset($schemaObj)) { $jsonLd = $schemaObj->getResource(); } } if ($jsonLd !== "") { echo "<script type='application/ld+json'>" . $jsonLd . "</script>"; } } }
/** * Render Meta Box content. * * @param WP_Post $post The post object. */ public function render_meta_box_content($post) { $PostType = get_post_type(); $DisableMarkup = get_post_meta($post->ID, '_HunchSchemaDisableMarkup', true); $MarkupType = get_post_meta($post->ID, '_HunchSchemaType', true); // Add an nonce field so we can check for it later. wp_nonce_field('schema_inner_custom_box', 'schema_inner_custom_box_nonce'); $server = new SchemaServer(); // Use get_post_meta to retrieve an existing value from the database. $jsonLd = $server->getResource(get_permalink($post->ID), true); if (empty($jsonLd)) { $schemaObj = HunchSchema_Thing::factory($PostType); $jsonLd = $schemaObj->getResource(TRUE); $replacelink = $server->createLink(); } else { $editlink = $server->updateLink(); } $testlink = "https://developers.google.com/structured-data/testing-tool?url=" . urlencode(get_permalink($post->ID)); // Display the form, using the current value. ?> <style> #schemapostlinks { display: inline; float: right; } #schemapostlinks button { margin: 0 1em; } </style> <label for="schema_new_field"><span class="inside"><?php echo _e('Post JSON-LD', 'schema_textdomain'); ?> </span> <div id="schemapostlinks"> <?php if (empty($replacelink)) { echo '<button><a target="_blank" href="' . $editlink . '">Edit</a></button>'; } else { ?> <button><a target="_blank" href="<?php echo $replacelink; ?> ">Use Different Schema.org Type</a></button> <button id="extendSchema" value="Extend Markup"><a target="_blank" href="#">Add to <?php echo $schemaObj->schemaType; ?> Default Markup</a></button> <input type="hidden" id="resourceURI" value="<?php echo get_permalink($post->ID); ?> "/> <textarea id="resourceData" style="display:none"><?php echo esc_attr($jsonLd); ?> </textarea> <?php } ?> <button><a class="" target="_blank" href="<?php echo $testlink; ?> ">Test with Google</a></button> </div> </label> <p> <textarea disabled="" class="large-text metadesc" rows="6" id="schema_new_field" name="schema_new_field"><?php echo esc_attr($jsonLd); ?> </textarea> <?php if (isset($schemaObj)) { ?> <br/><strong>Note: </strong><span style="color: grey"><em>This is default markup. Extend this with Schema App Creator using Update linked above.</em></span> <?php } ?> </p> <h4>Markup Options</h4> <p> <label><input type="checkbox" name="HunchSchemaDisableMarkup" value="1" <?php $this->CheckSelected(1, $DisableMarkup, 'checkbox'); ?> > <?php _e('Disable Schema markup', 'schema_textdomain'); ?> </label> </p> <?php if ($PostType == 'page') { ?> <p> <label>Select Type</label> <select name="HunchSchemaType"> <option value="">Article</option> <option value="BlogPosting" <?php $this->CheckSelected('BlogPosting', $MarkupType); ?> >Blog Posting</option> <option value="LiveBlogPosting" <?php $this->CheckSelected('LiveBlogPosting', $MarkupType); ?> > Live Blog Posting</option> <option value="NewsArticle" <?php $this->CheckSelected('NewsArticle', $MarkupType); ?> >News Article</option> <option value="Report" <?php $this->CheckSelected('Report', $MarkupType); ?> >Report</option> <option value="ScholarlyArticle" <?php $this->CheckSelected('ScholarlyArticle', $MarkupType); ?> >Scholarly Article</option> <option value="MedicalScholarlyArticle" <?php $this->CheckSelected('MedicalScholarlyArticle', $MarkupType); ?> > Medical Scholarly Article</option> <option value="SocialMediaPosting" <?php $this->CheckSelected('SocialMediaPosting', $MarkupType); ?> >Social Media Posting</option> <option value="DiscussionForumPosting" <?php $this->CheckSelected('DiscussionForumPosting', $MarkupType); ?> > Discussion Forum Posting</option> <option value="TechArticle" <?php $this->CheckSelected('TechArticle', $MarkupType); ?> >Tech Article</option> <option value="APIReference" <?php $this->CheckSelected('APIReference', $MarkupType); ?> > API Reference</option> </select> </p> <?php } }