ID, '_SnS', true ); $SnS = is_array( $SnS ) ? $SnS: array(); $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array(); if ( ! empty( $styles[ 'classes_mce' ] ) ) array_unshift( $buttons, 'styleselect' ); return $buttons; } static function tiny_mce_before_init( $initArray ) { global $post; $SnS = get_post_meta( $post->ID, '_SnS', true ); $SnS = is_array( $SnS ) ? $SnS: array(); $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array(); // Add div as a format option, should probably use a string replace thing here. // Better yet, a setting for adding these. Postpone for now. //$initArray['theme_advanced_blockformats'] = "p,address,pre,h1,h2,h3,h4,h5,h6,div"; if ( ( ! empty( $styles[ 'classes_body' ] ) || ! empty( $styles[ 'classes_post' ] ) ) && ! isset( $initArray['body_class'] ) ) $initArray['body_class'] = ''; // Add body_class (and/or maybe post_class) values... somewhat problematic. if ( ! empty( $styles[ 'classes_body' ] ) ) $initArray['body_class'] .= ' ' . $styles[ 'classes_body' ]; if ( ! empty( $styles[ 'classes_post' ] ) ) $initArray['body_class'] .= ' ' . $styles[ 'classes_post' ]; // In case Themes or plugins have added style_formats, not tested. if ( isset( $initArray['style_formats'] ) ) $style_formats = json_decode( $initArray['style_formats'], true ); else $style_formats = array(); if ( ! empty( $styles[ 'classes_mce' ] ) ) foreach ( $styles[ 'classes_mce' ] as $format ) $style_formats[] = $format; if ( ! empty( $style_formats ) ) $initArray['style_formats'] = json_encode( $style_formats ); return $initArray; } /** * Admin Action: 'mce_css' * Adds a styles sheet to TinyMCE via ajax that contains the current styles data. */ static function mce_css( $mce_css ) { $url = admin_url( 'admin-ajax.php' ); $url = wp_nonce_url( $url, 'sns_tinymce_styles' ); $url = add_query_arg( 'post_id', get_the_ID(), $url ); $url = add_query_arg( 'action', 'sns_tinymce_styles', $url ); add_theme_support( 'editor-styles' ); add_editor_style( $url ); return $mce_css; } /** * Admin Action: 'add_meta_boxes' * Main Meta Box function. Checks restriction options and display options, calls add_meta_box() and adds actions for adding admin CSS and JavaScript. */ static function add_meta_boxes() { if ( current_user_can( 'unfiltered_html' ) ) { $post_type = get_current_screen()->post_type; if ( in_array( $post_type, get_post_types( array('show_ui' => true, 'public' => true ) ) ) ) { add_meta_box( 'SnS_meta_box', __( 'Scripts n Styles', 'scripts-n-styles' ), array( __CLASS__, 'admin_meta_box' ), $post_type, 'normal', 'high' ); add_filter( 'default_hidden_meta_boxes', array( __CLASS__, 'default_hidden_meta_boxes' ) ); add_action( "admin_print_styles", array( __CLASS__, 'meta_box_styles')); add_action( "admin_print_scripts", array( __CLASS__, 'meta_box_scripts')); add_filter( 'contextual_help', array( 'SnS_Admin', 'help' ) ); add_filter( 'mce_buttons_2', array( __CLASS__, 'mce_buttons_2' ) ); add_filter( 'tiny_mce_before_init', array( __CLASS__, 'tiny_mce_before_init' ) ); add_filter( 'replace_editor', array( __CLASS__, 'mce_css' ) ); } } } static function default_hidden_meta_boxes( $hidden ) { $options = get_option( 'SnS_options' ); if ( ! ( isset( $options[ 'metabox' ] ) && 'yes' == $options[ 'metabox' ] ) ) { $hidden[] = 'SnS_meta_box'; $hidden[] = 'SnS_shortcode'; } return $hidden; } /** * Admin Action: 'add_meta_boxes' * Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action. * @param unknown_type WordPress Post object. */ static function admin_meta_box( $post ) { $registered_handles = Scripts_n_Styles::get_wp_registered(); $SnS = get_post_meta( $post->ID, '_SnS', true ); $SnS = is_array( $SnS ) ? $SnS: array(); $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array(); $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array(); $html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array(); $position = get_user_option( "current_sns_tab" ); if ( ! in_array( $position, array( 's0', 's1', 's2', 's3', 's4', 's5', 's6' ) ) ) $position = 's0'; wp_nonce_field( Scripts_n_Styles::$file, self::NONCE_NAME ); ?>

verbatim in <script> tags at the end of your page's (or post's)", 'scripts-n-styles' ) ?> ...

... </head> .

... </body> .

verbatim in <style> tags in the <head> tag of your page (or post).', 'scripts-n-styles' ) ?>

space separated class names will be added to the body_class() or post_class() function (provided your theme uses these functions).', 'scripts-n-styles' ) ?>

Include Scripts

' . esc_html( $handle ) . ' '; ?>

Shortcodes
ID, '_SnS', true ); $SnS = is_array( $SnS ) ? $SnS: array(); $shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ] : array(); ?>

Existing Codes:

$value ) { ?>

[hoops name=""]

HTML for the head element", 'scripts-n-styles' ) ?> ...

 

HTML for the bottom of the body element", 'scripts-n-styles' ) ?> ...

$cm_theme ) ); } /** * Admin Action: 'save_post' * Saves the values entered in the Meta Box when a post is saved (on the Edit Screen only, excluding autosaves) if the user has permission. * @param int $post_id ID value of the WordPress post. */ static function save_post( $post_id ) { if ( ! isset( $_POST[ self::NONCE_NAME ] ) || ! wp_verify_nonce( $_POST[ self::NONCE_NAME ], Scripts_n_Styles::$file ) || ! current_user_can( 'unfiltered_html' ) || wp_is_post_revision( $post_id ) // is needed for get_post_meta compatibility. || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) return; /* NOTE: There is no current_user_can( 'edit_post' ) check here, because as far as I can tell, in /wp-admin/post.php the calls edit_post(), write_post(), post_preview(), wp_untrash_post(), etc., the check is already done prior to the 'save_post' action, which is where this function is called. Other calls are from other pages so the NONCE covers those cases, and that leaves autosave, which is also checked here. */ $SnS = get_post_meta( $post_id, '_SnS', true ); $SnS = is_array( $SnS ) ? $SnS: array(); // automatic array conversion became an error in PHP 7.1 $scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array(); $styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array(); $html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array(); $scripts = self::maybe_set( $scripts, 'scripts_in_head' ); $scripts = self::maybe_set( $scripts, 'scripts' ); $scripts = self::maybe_set( $scripts, 'enqueue_scripts' ); $styles = self::maybe_set( $styles, 'styles' ); $styles = self::maybe_set( $styles, 'classes_body' ); $styles = self::maybe_set( $styles, 'classes_post' ); $html = self::maybe_set( $html, 'html_in_head' ); $html = self::maybe_set( $html, 'html_in_footer' ); $shortcodes = array(); $SnS_shortcodes = isset( $_REQUEST[ 'SnS_shortcodes' ] ) ? $_REQUEST[ 'SnS_shortcodes' ]: array(); $existing_shortcodes = isset( $SnS_shortcodes[ 'existing' ] ) ? $SnS_shortcodes[ 'existing' ]: array(); foreach ( $existing_shortcodes as $key => $value ) if ( ! empty( $value ) ) $shortcodes[ $key ] = $value; $new_shortcode = isset( $SnS_shortcodes[ 'new' ] ) ? $SnS_shortcodes[ 'new' ]: array(); if ( ! empty( $new_shortcode[ 'value' ] ) ) { $key = ( isset( $new_shortcode[ 'name' ] ) ) ? $new_shortcode[ 'name' ] : ''; if ( '' == $key ) { $key = count( $shortcodes ); while ( isset( $shortcodes[ $key ] ) ) $key++; } if ( isset( $shortcodes[ $key ] ) ) { $countr = 1; while ( isset( $shortcodes[ $key . '_' . $countr ] ) ) $countr++; $key .= '_' . $countr; } $shortcodes[ $key ] = $new_shortcode[ 'value' ]; } // This one isn't posted, it's ajax only. Cleanup anyway. if ( isset( $styles[ 'classes_mce' ] ) && empty( $styles[ 'classes_mce' ] ) ) unset( $styles[ 'classes_mce' ] ); if ( empty( $scripts ) ) { if ( isset( $SnS['scripts'] ) ) unset( $SnS['scripts'] ); } else { $SnS['scripts'] = $scripts; } if ( empty( $styles ) ) { if ( isset( $SnS['styles'] ) ) unset( $SnS['styles'] ); } else { $SnS['styles'] = $styles; } if ( empty( $html ) ) { if ( isset( $SnS['html'] ) ) unset( $SnS['html'] ); } else { $SnS['html'] = $html; } if ( empty( $shortcodes ) ) { if ( isset( $SnS['shortcodes'] ) ) unset( $SnS['shortcodes'] ); } else { $SnS['shortcodes'] = $shortcodes; } if ( empty( $SnS ) ) delete_post_meta( $post_id, '_SnS' ); else update_post_meta( $post_id, '_SnS', $SnS ); } /** * maybe_set() * Filters $o and Checks if the sent data $i is empty (intended to clear). If not, updates. */ static function maybe_set( $o, $i, $p = 'SnS_' ) { if ( ! is_array( $o ) ) return array(); if ( empty( $_REQUEST[ $p . $i ] ) ) { if ( isset( $o[ $i ] ) ) unset( $o[ $i ] ); } else { $o[ $i ] = $_REQUEST[ $p . $i ]; } return $o; } }