PHP code example of jtsternberg / shortcode-button

1. Go to this page and download the library: Download jtsternberg/shortcode-button library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jtsternberg / shortcode-button example snippets



// Include the library
button() {

	// the button slug should be your shortcodes name.
	// The same value you would use in `add_shortcode`
	// Only numbers, letters and underscores are allowed.
	$button_slug = 'shortcode_name';

	// Set up the button data that will be passed to the javascript files
	$js_button_data = array(
		// Actual quicktag button text (on the text edit tab)
		'qt_button_text' => __( 'Shortcode Button', 'shortcode-button' ),
		// Tinymce button hover tooltip (on the html edit tab)
		'button_tooltip' => __( 'Shortcode Button', 'shortcode-button' ),
		// Tinymce button icon. Use a dashicon class or a 20x20 image url
		'icon'           => 'dashicons-admin-appearance',

		// Optional parameters
		'author'         => 'Justin Sternberg',
		'authorurl'      => 'http://dsgnwrks.pro',
		'infourl'        => 'https://github.com/jtsternberg/Shortcode_Button',
		'version'        => '1.0.0',
		'tion( 'shortcode_button_load', 'init_my_shortcode_button', ( SHORTCODE_BUTTONS_LOADED + 1 ) );

/**
 * Return CMB2 config array
 *
 * @param  array  $button_data Array of button data
 *
 * @return array               CMB2 config array
 */
function shortcode_button_cmb_config( $button_data ) {

	return array(
		'id'     => 'shortcode_'. $button_data['slug'],
		'fields' => array(
			array(
				'name'    => __( 'Test Text Small', 'shortcode-button' ),
				'desc'    => __( 'field description (optional)', 'shortcode-button' ),
				'default' => __( 'default shortcode param value', 'shortcode-button' ),
				'id'      => 'shortcode_param',
				'type'    => 'text_small',
			),
		),
		// keep this w/ a key of 'options-page' and use the button slug as the value
		'show_on' => array( 'key' => 'options-page', 'value' => $button_data['slug'] ),
	);

}

/**
 * Callback dictates that shortcode button will only display if we're on a 'page' edit screen
 *
 * @return bool Expects a boolean value
 */
function shortcode_button_only_pages() {
	if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
		return false;
	}

	$current_screen = get_current_screen();

	if ( ! isset( $current_screen->parent_base ) || $current_screen->parent_base != 'edit' ) {
		return false;
	}

	if ( ! isset( $current_screen->post_type ) || $current_screen->post_type != 'page' ) {
		return false;
	}

	// Ok, guess we're on a 'page' edit screen
	return true;
}