function cjtheme_fetch_shortcode_options() { global $wpdb, $shortcode_tags; $select_shortcodes = null; $shortcode_options = cjtheme_do_shortcode('[' . $_POST['shortcode'] . ' return="options"]'); $shortcode_options = is_serialized($shortcode_options) ? unserialize($shortcode_options) : $shortcode_options; $shortcode_defaults = cjtheme_do_shortcode('[' . $_POST['shortcode'] . ' return="defaults"]'); $shortcode_defaults = is_serialized($shortcode_defaults) ? unserialize($shortcode_defaults) : $shortcode_defaults; $form_fields[] = array('type' => 'heading', 'id' => 'shortcode-settings-heading', 'label' => '', 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => __('Shortcode Settings', 'cjtheme'), 'options' => ''); if (!is_null($shortcode_options['description'])) { $form_fields[] = array('type' => 'info-full', 'id' => 'shortcode_info', 'label' => '', 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => $shortcode_options['description'], 'options' => ''); } if ($shortcode_options['stype'] == 'closed' && isset($shortcode_options['default_content']) && $shortcode_options['default_content'] != '') { $form_fields[] = array('type' => 'textarea', 'id' => 'shortcode_content', 'label' => __('Content', 'cjtheme'), 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => $shortcode_options['default_content'], 'options' => ''); } foreach ($shortcode_options as $key => $options) { if (is_array($options)) { $form_fields[] = array('type' => $options[1], 'id' => $key, 'label' => $options[0], 'info' => $options[3], 'suffix' => '', 'prefix' => '', 'default' => isset($shortcode_defaults[$key]) ? $shortcode_defaults[$key] : '', 'options' => is_array($options[2]) ? $options[2] : ''); } } $form_fields[] = array('type' => 'submit', 'id' => 'cj-insert-shortcode', 'label' => __('Insert Shortcode', 'cjtheme'), 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => '', 'options' => ''); echo '<div class="cj-table">'; echo '<form action="" method="post" id="cj-shortcode-settings-form" data-shortcode-stype="' . $shortcode_options['stype'] . '" data-shortcode-name="' . $_POST['shortcode'] . '">'; echo cjtheme_admin_form_raw($form_fields, 'no-search-box', true); echo '</form>'; echo '</div>'; die; }
<?php /** * @package CSSJockey WordPress Framework * @author Mohit Aneja (cssjockey.com) * @version FW-20150208 */ global $shortcode_tags; $select_shortcodes = null; $cj_products_text_domains = @array_keys(cjtheme_list_submenu_admin_pages('cj-products')); if (!empty($shortcode_tags)) { foreach ($shortcode_tags as $key => $value) { $tag = explode('_', $key); if (@in_array($tag[0], $cj_products_text_domains)) { $select_shortcodes[$tag[0]][] = $value; $shortcode_options[$value] = @unserialize(cjtheme_do_shortcode('[' . $value . ' return="options"]')); } } } ?> <div class="cj-shortcode-generator-lightbox"> <div class="cj-shortcode-generator"> <h3 class="heading"> <img src="<?php echo cjtheme_item_path('includes_url') . '/shortcode-generator/cj-icon.png'; ?> " /> <?php _e('CSSJockey Shortcode Generator', 'cjtheme'); ?>
function cjtheme_shortcode_generator_run(array $meta_boxes) { global $shortcode_tags; // Start with an underscore to hide fields from custom fields list $prefix = '_'; $default_post_types = array('post', 'page'); $custom_post_types = get_post_types(); if (!empty($custom_post_types)) { $custom_post_types = @array_keys($custom_post_types); if (is_array($custom_post_types)) { $show_metabox_on = array_merge($custom_post_types, $default_post_types); } else { $show_metabox_on = $default_post_types; } } else { $show_metabox_on = $default_post_types; } $cjtheme_shortcodes['cjtheme'][] = array('name' => __('Select shortcode', 'cjtheme'), 'value' => 'select shortcode'); if (!empty($shortcode_tags)) { $text_domain_count = strlen('cjtheme'); foreach ($shortcode_tags as $key => $value) { if (!is_array($value) && substr($value, 0, $text_domain_count) == 'cjtheme') { $name = str_replace('cjtheme' . '_', '', $value); $name = str_replace('_', ' ', $name); $cjtheme_shortcodes['cjtheme'][] = array('name' => ucwords($name), 'value' => $value); $shortcode_options[$key] = unserialize(cjtheme_do_shortcode('[' . $key . ' return="defaults"]')); //$shortcode_options[$key] = unserialize(get_option( sha1($key) )); } } } $shortcode_options_display[] = '<span id="cjtheme-shortcode-content" onclick="selectText(\'cjtheme-shortcode-content\')" class="cjtheme-shortcode-content">' . __('Select shortcode', 'cjtheme') . '</span>'; if (isset($shortcode_options) && is_array($shortcode_options)) { foreach ($shortcode_options as $key => $value) { $shortcode_options_display[] = '<span style="clear:both;"></span><div id="' . $key . '" style="clear:both; overflow:hidden; height:0px;" class="cjtheme-shortcode-panel clearfix" data-stype="' . $value['stype'] . '">'; $shortcode_options_display[] = '<b style="border-bottom:1px solid #ddd; display:block; margin-bottom:5px; padding-bottom:5px;">' . ucwords(str_replace('cjtheme', '', str_replace('_', ' ', $key)) . ' ' . __('Options', 'cjtheme')) . '</b>'; if (is_array($value)) { foreach ($value as $skey => $sval) { if ($skey != 'stype' && $sval[1] == 'text') { $shortcode_options_display[] = '<p>'; $shortcode_options_display[] = '<label><b>' . $sval[0] . '</b><br />'; $shortcode_options_display[] = '<input class="' . $key . '-cjtheme-options" data-attr="' . $skey . '" name="cjtheme-' . $skey . '" type="' . $sval[1] . '" value="' . $sval[2] . '" />'; $shortcode_options_display[] = '</label>'; $shortcode_options_display[] = '</p>'; } if ($skey != 'stype' && $sval[1] == 'textarea') { $shortcode_options_display[] = '<p>'; $shortcode_options_display[] = '<label><b>' . $sval[0] . '</b><br />'; $shortcode_options_display[] = '<textarea class="' . $key . '-cjtheme-options" rows="3" cols="40" data-attr="' . $skey . '" name="cjtheme-' . $skey . '">' . $sval[2] . '</textarea>'; $shortcode_options_display[] = '</label>'; $shortcode_options_display[] = '</p>'; } if ($skey != 'stype' && $sval[1] == 'heading') { $shortcode_options_display[] = '<b style="clear:both; border-bottom:1px solid #ddd; display:block; margin-top:15px; margin-bottom:15px; padding-bottom:5px;">'; $shortcode_options_display[] = $sval[0]; $shortcode_options_display[] = '</b>'; } if ($skey != 'stype' && $sval[1] == 'info') { $shortcode_options_display[] = '<div style="clear:both; display:block; margin-top:15px; margin-bottom:15px;">'; $shortcode_options_display[] = $sval[0]; $shortcode_options_display[] = '</div>'; } if ($skey != 'stype' && $sval[1] == 'select' || $sval[1] == 'dropdown') { $shortcode_options_display[] = '<p>'; $shortcode_options_display[] = '<label><b>' . $sval[0] . '</b><br />'; $shortcode_options_display[] = '<select class="' . $key . '-cjtheme-options chzn-select-no-results" data-attr="' . $skey . '" name="cjtheme-' . $skey . '" style="width:250px !important;">'; $opts = ''; $opts = '<option value="">' . __('Please Select ', 'cjtheme') . '</option>'; if (is_array($sval[2])) { $shortcode_options_display[] = $opts; foreach ($sval[2] as $okey => $oval) { $ovalue = str_replace('_', ' ', $oval); $ovalue = str_replace('-', ' ', $ovalue); $shortcode_options_display[] = '<option value="' . $okey . '">' . $ovalue . '</option>'; } } $shortcode_options_display[] = '</select>'; $shortcode_options_display[] = '</label>'; $shortcode_options_display[] = '</p>'; } if ($skey != 'stype' && $sval[1] == 'multiselect' || $sval[1] == 'multidropdown') { $shortcode_options_display[] = '<p>'; $shortcode_options_display[] = '<label><b>' . $sval[0] . '</b><br />'; $shortcode_options_display[] = '<select multiple class="' . $key . '-cjtheme-options chzn-select-no-results" data-attr="' . $skey . '" name="cjtheme-' . $skey . '" style="width:250px !important;">'; $opts = ''; $opts = '<option value="">' . __('Please Select ', 'cjtheme') . '</option>'; if (is_array($sval[2])) { $shortcode_options_display[] = $opts; foreach ($sval[2] as $okey => $oval) { $ovalue = str_replace('_', ' ', $oval); $ovalue = str_replace('-', ' ', $ovalue); $shortcode_options_display[] = '<option value="' . $okey . '">' . $ovalue . '</option>'; } } $shortcode_options_display[] = '</select>'; $shortcode_options_display[] = '</label>'; $shortcode_options_display[] = '</p>'; } } $shortcode_options_display[] = '<br style="clear:both; height:1px;"><br />'; } $shortcode_options_display[] = '</div>'; } } $shortcode_options_panel = implode('', $shortcode_options_display); if (isset($_GET['post'])) { update_post_meta(@$_GET['post'], '_shortcodes', ''); } if (count($cjtheme_shortcodes['cjtheme']) > 1) { $meta_boxes['cjtheme'] = array('id' => 'cjtheme_shortcode_generator', 'title' => sprintf(__('Shortcode Generator (%s)', 'cjtheme'), cjtheme_item_info('item_name')), 'pages' => $show_metabox_on, 'context' => 'advanced', 'priority' => 'high', 'show_names' => false, 'fields' => array(array('name' => __('Choose a shortcode', 'cjtheme'), 'desc' => $shortcode_options_panel, 'id' => $prefix . 'cjtheme_shortcodes', 'type' => 'select', 'options' => $cjtheme_shortcodes['cjtheme'], 'std' => ''))); } return $meta_boxes; }