/** * Register shortcodes */ public static function register() { // Prepare compatibility mode prefix $prefix = mom_su_cmpt(); // Loop through shortcodes foreach ((array) mom_su_Data::shortcodes() as $id => $data) { if (isset($data['function']) && is_callable($data['function'])) { $func = $data['function']; } elseif (is_callable(array('mom_su_Shortcodes', $id))) { $func = array('mom_su_Shortcodes', $id); } elseif (is_callable(array('mom_su_Shortcodes', 'mom_su_' . $id))) { $func = array('mom_su_Shortcodes', 'mom_su_' . $id); } else { continue; } // Register shortcode add_shortcode($prefix . $id, $func); } // Register [media] manually // 3.x add_shortcode($prefix . 'media', array('mom_su_Shortcodes', 'media')); }
public static function cheatsheet($field, $config) { // Prepare print button $print = '<div><a href="javascript:;" id="mom-su-cheatsheet-print" class="mom-su-cheatsheet-switch button button-primary button-large">' . __('Printable version', 'theme') . '</a><div id="mom-su-cheatsheet-print-head"><h1>' . __('Shortcodes Ultimate', 'theme') . ': ' . __('Cheatsheet', 'theme') . '</h1><a href="javascript:;" class="mom-su-cheatsheet-switch">← ' . __('Back to Dashboard', 'theme') . '</a></div></div>'; // Prepare table array $table = array(); // Table start $table[] = '<table><tr><th style="width:20%;">' . __('Shortcode', 'theme') . '</th><th style="width:50%">' . __('Attributes', 'theme') . '</th><th style="width:30%">' . __('Example code', 'theme') . '</th></tr>'; // Loop through shortcodes foreach ((array) mom_su_Data::shortcodes() as $name => $shortcode) { // Prepare vars $icon = isset($shortcode['icon']) ? $shortcode['icon'] : 'puzzle-piece'; $shortcode['name'] = isset($shortcode['name']) ? $shortcode['name'] : $name; $attributes = array(); $example = array(); $icons = 'icon: music, icon: envelope … <a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank">' . __('full list', 'theme') . '</a>'; // Loop through attributes if (is_array($shortcode['atts'])) { foreach ($shortcode['atts'] as $id => $data) { // Prepare default value $default = isset($data['default']) && $data['default'] !== '' ? '<p><em>' . __('Default value', 'theme') . ':</em> ' . $data['default'] . '</p>' : ''; // Check type is set if (empty($data['type'])) { $data['type'] = 'text'; } // Switch attribute types switch ($data['type']) { // Select case 'select': $value = implode(', ', array_keys($data['values'])); break; // Slider and number // Slider and number case 'slider': case 'number': $value = $data['min'] . '…' . $data['max']; break; // Bool // Bool case 'bool': $value = 'yes | no'; break; // Icon // Icon case 'icon': $value = $icons; break; // Color // Color case 'color': $value = __('#RGB and rgba() colors'); break; // Default value // Default value default: $value = $data['default']; break; } // Check empty value if ($value === '') { $value = __('Any text value', 'theme'); } // Extra CSS class if ($id === 'class') { $value = __('Any custom CSS classes', 'theme'); } // Add attribute $attributes[] = '<div class="mom-su-shortcode-attribute"><strong>' . $data['name'] . ' <em>– ' . $id . '</em></strong><p><em>' . __('Possible values', 'theme') . ':</em> ' . $value . '</p>' . $default . '</div>'; // Add attribute to the example code $example[] = $id . '="' . $data['default'] . '"'; } } // Prepare example code $example = '[%prefix_' . $name . ' ' . implode(' ', $example) . ']'; // Prepare content value if (empty($shortcode['content'])) { $shortcode['content'] = ''; } // Add wrapping code if ($shortcode['type'] === 'wrap') { $example .= esc_textarea($shortcode['content']) . '[/%prefix_' . $name . ']'; } // Change compatibility prefix $example = str_replace(array('%prefix_', '__'), mom_su_cmpt(), $example); // Shortcode $table[] = '<td>' . '<span class="mom-su-shortcode-icon">' . mom_su_Tools::icon($icon) . '</span>' . $shortcode['name'] . '<br/><em class="mom-su-shortcode-desc">' . $shortcode['desc'] . '</em></td>'; // Attributes $table[] = '<td>' . implode('', $attributes) . '</td>'; // Example code $table[] = '<td><code contenteditable="true">' . $example . '</code></td></tr>'; } // Table end $table[] = '</table>'; // Query assets mom_su_query_asset('css', array('font-awesome', 'mom-su-cheatsheet')); mom_su_query_asset('js', array('jquery', 'mom-su-options-page')); // Return output return '<div id="mom-su-cheatsheet-screen">' . $print . implode('', $table) . '</div>'; }
/** * Process AJAX request */ public static function settings() { self::access(); // Param check if (empty($_REQUEST['shortcode'])) { wp_die(__('Shortcode not specified', 'framework')); } // Get cache delete_transient('mom_su/generator/settings/' . sanitize_text_field($_REQUEST['shortcode'])); $output = get_transient('mom_su/generator/settings/' . sanitize_text_field($_REQUEST['shortcode'])); if ($output && mom_su_ENABLE_CACHE) { echo $output; } else { // Request queried shortcode $shortcode = mom_su_Data::shortcodes(sanitize_key($_REQUEST['shortcode'])); // Prepare skip-if-default option $skip = get_option('mom_su_option_skip') === 'on' ? ' mom-su-generator-skip' : ''; // Prepare actions $actions = apply_filters('mom_su/generator/actions', array('insert' => '<a href="javascript:void(0);" class="button button-primary button-large mom-su-generator-insert"><i class="fa fa-check"></i> ' . __('Insert shortcode', 'framework') . '</a>')); // Shortcode header $return = '<div id="mom-su-generator-breadcrumbs">'; $return .= apply_filters('mom_su/generator/breadcrumbs', '<a href="javascript:void(0);" class="mom-su-generator-home" title="' . __('Click to return to the shortcodes list', 'framework') . '">' . __('All shortcodes', 'framework') . '</a> → <span>' . $shortcode['name'] . '</span> <small class="alignright">' . $shortcode['desc'] . '</small><div class="mom-su-generator-clear"></div>'); $return .= '</div>'; // Shortcode note if (isset($shortcode['note']) || isset($shortcode['example'])) { $return .= '<div class="mom-su-generator-note"><i class="fa fa-info-circle"></i><div class="mom-su-generator-note-content">'; if (isset($shortcode['note'])) { $return .= wpautop($shortcode['note']); } if (isset($shortcode['example'])) { $return .= wpautop('<a href="' . admin_url('admin.php?page=mom-shortcodes-ultimate-examples&example=' . $shortcode['example']) . '" target="_blank">' . __('Examples of use', 'framework') . ' →</a>'); } $return .= '</div></div>'; } // Shortcode has atts if (count($shortcode['atts']) && $shortcode['atts']) { // Loop through shortcode parameters foreach ($shortcode['atts'] as $attr_name => $attr_info) { // Prepare default value $default = (string) isset($attr_info['default']) ? $attr_info['default'] : ''; $attr_info['name'] = isset($attr_info['name']) ? $attr_info['name'] : $attr_name; $required = ''; if (isset($attr_info['required'])) { $required .= 'data-required="' . $attr_info['required'][0] . '" data-operator="' . $attr_info['required'][1] . '" data-value="' . $attr_info['required'][2] . '"'; } $return .= '<div class="mom-su-generator-attr-container' . $skip . '" data-default="' . esc_attr($default) . '" ' . $required . ' >'; $return .= '<h5>' . $attr_info['name'] . '</h5>'; // Create field types if (!isset($attr_info['type']) && isset($attr_info['values']) && is_array($attr_info['values']) && count($attr_info['values'])) { $attr_info['type'] = 'select'; } elseif (!isset($attr_info['type'])) { $attr_info['type'] = 'text'; } if (is_callable(array('mom_su_Generator_Views', $attr_info['type']))) { $return .= call_user_func(array('mom_su_Generator_Views', $attr_info['type']), $attr_name, $attr_info); } elseif (isset($attr_info['callback']) && is_callable($attr_info['callback'])) { $return .= call_user_func($attr_info['callback'], $attr_name, $attr_info); } if (isset($attr_info['desc'])) { $attr_info['desc'] = str_replace('%mom_su_skins_link%', mom_su_skins_link(), $attr_info['desc']); } if (isset($attr_info['desc'])) { $return .= '<div class="mom-su-generator-attr-desc">' . str_replace(array('<b%value>', '<b_>'), '<b class="mom-su-generator-set-value" title="' . __('Click to set this value', 'framework') . '">', $attr_info['desc']) . '</div>'; } $return .= '</div>'; } } // Single shortcode (not closed) if ($shortcode['type'] == 'single') { $return .= '<input type="hidden" name="mom-su-generator-content" id="mom-su-generator-content" value="false" />'; } else { $return .= '<div class="mom-su-generator-attr-container"><h5>' . __('Content', 'framework') . '</h5><textarea name="mom-su-generator-content" id="mom-su-generator-content" rows="5">' . esc_attr(str_replace(array('%prefix_', '__'), mom_su_cmpt(), $shortcode['content'])) . '</textarea></div>'; } $return .= '<div id="mom-su-generator-preview"></div>'; $return .= '<div class="mom-su-generator-actions mom-su-generator-clearfix">' . implode(' ', array_values($actions)) . '</div>'; set_transient('mom_su/generator/settings/' . sanitize_text_field($_REQUEST['shortcode']), $return, 2 * DAY_IN_SECONDS); echo $return; } exit; }
public static function example() { // Check authentication self::access(); // Check incoming data if (!isset($_REQUEST['code']) || !isset($_REQUEST['id'])) { return; } // Check for cache $output = get_transient('mom_su/examples/render/' . sanitize_key($_REQUEST['id'])); if ($output && mom_su_ENABLE_CACHE) { echo $output; } else { ob_start(); // Prepare data $code = file_get_contents(sanitize_text_field($_REQUEST['code'])); // Check for code if (!$code) { die('<p class="mom-su-examples-error">' . __('Example code does not found, please check it later', 'theme') . '</p>'); } // Clean-up the code $code = str_replace(array("\t", '%mom_su_'), array(' ', mom_su_cmpt()), $code); // Split code $chunks = explode('-----', $code); // Show snippets do_action('mom_su/examples/preview/before'); foreach ($chunks as $chunk) { // Clean-up new lines $chunk = trim($chunk, "\n\r"); // Calc textarea rows $rows = substr_count($chunk, "\n"); $rows = $rows < 4 ? '4' : (string) ($rows + 1); $rows = $rows > 20 ? '20' : (string) ($rows + 1); echo wpautop(do_shortcode($chunk)); echo '<div style="clear:both"></div>'; echo '<div class="mom-su-examples-code"><span class="mom-su-examples-get-code button"><i class="fa fa-code"></i> ' . __('Get the code', 'theme') . '</span><textarea rows="' . $rows . '">' . esc_textarea($chunk) . '</textarea></div>'; } do_action('mom_su/examples/preview/after'); $output = ob_get_contents(); ob_end_clean(); set_transient('mom_su/examples/render/' . sanitize_key($_REQUEST['id']), $output); echo $output; } die; }