formProcessName, array(&$this, 'hesh_options_form_process'));
// Load only on certain pages
if (
!strstr($_SERVER['SCRIPT_NAME'], 'post.php') &&
!strstr($_SERVER['SCRIPT_NAME'], 'post-new.php') &&
!strstr($_SERVER['SCRIPT_NAME'], 'editor.php')
) return;
add_action( 'admin_enqueue_scripts', array(&$this, 'hesh_admin_enqueue_scripts' ) );
add_action( 'admin_footer', array(&$this, 'hesh_output_form') );
// add_action( 'admin_notices', array(&$this, 'display_survey_notice' ));
}
// Enqueued scripts and styles for hesh.js
public function hesh_admin_enqueue_scripts () {
// get the plugin version number for cache busting purposes
$plugData = get_plugin_data( __FILE__ ); // need this temporary var to support versions of php < 5.4
$ver = $plugData['Version'];
// load minified version if not a localhost dev account
// $min = strpos(home_url(), 'localhost') ? '' : '.min' ; // no more...
wp_enqueue_script( 'jquery');
// dequeue the native WP code-editor and codemirror
if (wp_script_is( 'code-editor', 'enqueued' )) wp_dequeue_script( 'code-editor' );
if (wp_style_is( 'code-editor', 'enqueued' )) wp_dequeue_style( 'code-editor' );
// if (wp_script_is( 'wp-codemirror', 'enqueued' )) wp_dequeue_script( 'wp-codemirror' );
// if (wp_style_is( 'wp-codemirror', 'enqueued' )) wp_dequeue_style( 'wp-codemirror' );
// enqueue hesh scripts
wp_enqueue_script( 'heshJs', HESH_LIBS.'hesh.js', array('jquery', 'editor'), $ver, true );
wp_enqueue_style( 'heshCss', HESH_LIBS.'hesh.css', false, $ver );
// this shows up in js as window.heshOptions
$heshOptions = array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
// 'nonce' => wp_create_nonce( $this->formProcessName ) // TODO: use this instead of the hidden field?
);
// place all the userPreferences into the heshOptions object
foreach ($this->userPreferences as $id => $value) {
$heshOptions[$id] = $value['current'];
// error_log( $id . ': ' . $heshOptions[$id] . ' type: ' . gettype($heshOptions[$id]) ); // for debug
}
wp_localize_script(
'heshJs', // for hesh.js
'heshOptions', // the object name, shows up in js as window.heshOptions
$heshOptions // the php object to translate to js
);
}
private $surveyLink = 'https://goo.gl/forms/xvaHgd7sZEbBbFAL2';
private $formProcessName = 'hesh_options_form';
private $nonceSecretCode = 'secret-code';
private $prefix = 'hesh_';
private $userPreferences = array(); // added to the primary bar
public function hesh_set_options() {
$this->userPreferences = array(
// HIDDEN OPTIONS // added in the primary settings bar
'surveyNoticeDismissedB' => array(
'title' => 'UX Survey Notice Dismissed',
'type' => 'hidden',
// 'current' => false, // reset for debug
'current' => get_user_meta( get_current_user_id(), $this->prefix.'surveyNoticeDismissedB' , true),
'default' => false,
'set' => 'hidden',
),
// PRIMARY OPTIONS // added in the primary settings bar
'theme' => array(
'title' => 'Theme',
'type' => 'select',
'options' => $this->cssThemes,
'current' => get_user_meta( get_current_user_id(), $this->prefix.'theme' , true),
'default' => 'wordpress',
'set' => 'primary',
),
'tabSize' => array(
'title' => 'Indent',
'type' => 'select',
'options' => range(1,6),
'current' => get_user_meta( get_current_user_id(), $this->prefix.'tabSize' , true),
'default' => 4,
'set' => 'primary',
),
'lineWrapping'=> array(
'title' => 'Line Wrap',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'lineWrapping' , true),
'default' => true,
'set' => 'primary',
),
'lineNumbers'=> array(
'title' => 'Numbering',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'lineNumbers' , true),
'default' => true,
'set' => 'primary',
),
'fontSize'=> array(
'title' => 'Font Size',
'type' => 'select',
'options' => range(8,20),
'current' => get_user_meta( get_current_user_id(), $this->prefix.'fontSize' , true),
'default' => 13,
'set' => 'primary',
),
'lineHeight'=> array(
'title' => 'Line Height',
'type' => 'select',
'options' => range(1,2,0.25),
'current' => get_user_meta( get_current_user_id(), $this->prefix.'lineHeight' , true),
'default' => 1.5,
'set' => 'primary',
),
// ADVANCED OPTIONS // added to the advanced dropdown
'matchBrackets'=> array(
'title' => 'Match Brackets',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'matchBrackets' , true),
'default' => false,
'set' => 'advanced',
'description' => 'highlight matching bracket pairs next to cursor',
),
'matchTags'=> array(
'title' => 'Match Tags',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'matchTags' , true),
'default' => false,
'set' => 'advanced',
'description' => 'highlight matching html tag pairs (not shortcodes)',
),
'highlightSelectionMatches'=> array(
'title' => 'Highlight Selection Matches',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'highlightSelectionMatches' , true),
'default' => false,
'set' => 'advanced',
'description' => 'highlight all instances of a currently selected word',
),
'autoCloseTags'=> array(
'title' => 'Auto Close Tags',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'autoCloseTags' , true),
'default' => false,
'set' => 'advanced',
'description' => 'auto-close HTML tags when > or / is typed',
),
'autoCloseBrackets'=> array(
'title' => 'Auto Close Brackets',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'autoCloseBrackets' , true),
'default' => false,
'set' => 'advanced',
'description' => 'auto-close brackets and quotes when typed',
),
'foldGutter'=> array(
'title' => 'Code Folding',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'foldGutter' , true),
'default' => false,
'set' => 'advanced',
// 'description' => 'fold HTML code (not shortcodes)',
),
'scrollbarStyle'=> array(
'title' => 'Show Scrollbars',
'type' => 'checkbox',
'current' => get_user_meta( get_current_user_id(), $this->prefix.'scrollbarStyle' , true),
'default' => false,
'set' => 'advanced',
),
'keyMap'=> array(
'title' => 'Key Mapping',
'type' => 'radio',
'options' => array('default', 'sublime', 'vim', 'emacs'),
'current' => get_user_meta( get_current_user_id(), $this->prefix.'keyMap' , true),
'default' => 'default',
'set' => 'advanced',
),
);
// Initialize all the hesh option fields as default if they don't exist yet
foreach ($this->userPreferences as $id => $value) {
if (!isset($value['current']) || trim($value['current'])==='')
update_user_meta( get_current_user_id(), $this->prefix.$id, $value['default']);
// error_log( $id . ': ' . $value['current'] . ': ' . isset($value['current']) ); // for debug
}
}
public function hesh_options_form_process() {
if (empty($_POST) || !wp_verify_nonce($_POST[$this->nonceSecretCode], $this->formProcessName)) {
error_log('The nonce did not verify.');
wp_die();
} else {
foreach ($this->userPreferences as $id => $value) {
$setting = $_POST[$id];
if ($setting === 'true') $setting = true;
if ($setting === 'false') $setting = false;
if (is_numeric($setting)) $setting = floatval($setting);
// error_log( $id . ': ' . $setting . ' type: ' . gettype($setting) ); // for debug
update_user_meta( get_current_user_id(), $this->prefix.$id, $setting);
}
}
}
private function hesh_output_option($id, $config) {
switch ($config['type']){
case 'select':
$this->hesh_output_primary_select($id, $config);
break;
case 'checkbox':
$this->hesh_output_primary_toggle($id, $config);
break;
}
}
private function hesh_output_primary_toggle($id, $config) {
extract($config);
?>
Please Take A Short Syntax Highlighter UX Survey
A new version of the HTML Editor Syntax Highlighter Is Coming!
Please take this 5 minute user experience survey, and share your opinion to help shape new features in the v3.0 update.
A survey link is also available in the Advanced Options.
Take the UX Survey