Skip to content

Instantly share code, notes, and snippets.

@code-flow
Created March 26, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code-flow/c905fe434b073322751fa5cab3bf72c7 to your computer and use it in GitHub Desktop.
Save code-flow/c905fe434b073322751fa5cab3bf72c7 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: SNIP Shortcode Example
Description: A plugin that allows to add shortcode-content to schema properties.
Author: Florian Simeth
Version: 0.1.0
Author URI: https://rich-snippets.io
Plugin URI: https://rich-snippets.io/shortcode-content-in-properties/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
/**
*
* PHP Version check.
*
*/
if ( version_compare( PHP_VERSION, '7.0', '<' ) ) {
add_action( 'admin_notices', 'snip_scc_old_php_notice' );
function snip_scc_old_php_notice() {
printf(
'<div class="notice error"><p>%s</p></div>',
sprintf(
__( 'Hey mate! Sorry for interrupting you. It seem\'s that you\'re using an old PHP version (your current version is %s). You should upgrade to at least 7.0 or higher in order to use the SNIP Shortcode plugin. Thank you!', 'snip-scc' ),
esc_html( PHP_VERSION )
)
);
}
# sorry. The plugin will not work with an old PHP version.
return;
}
add_filter( 'wpbuddy/rich_snippets/fields/internal_subselect/values', 'snip_scc_subselects' );
/**
* Adds new field to use in Global Snippets in the SNIP plugin.
*
* @param array $values
*
* @return array
* @since 0.1.0
*
*/
function snip_scc_subselects( $values ) {
$values['http://schema.org/Text'][] = [
'id' => 'textfield_snip_scc_shortcode',
'label' => esc_html_x( 'Shortcode content', 'subselect field', 'snip-scc' ),
'method' => 'snip_scc_callback',
];
return $values;
}
/**
* Returns the value.
*
* @param $val
* @param \wpbuddy\rich_snippets\Rich_Snippet $rich_snippet
* @param array $meta_info
*
* @return int|float
*/
function snip_scc_callback( $val, \wpbuddy\rich_snippets\Rich_Snippet $rich_snippet, array $meta_info ) {
$shortcode_content = do_shortcode( $val );
return strip_tags( $shortcode_content );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment