Sync plugins from current page

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-09-11 19:08:46 +02:00
parent 85d41e4216
commit 8515ff9587
1847 changed files with 505469 additions and 0 deletions

View File

@@ -0,0 +1,202 @@
<?php
/**
* Scripts n Styles Admin Class
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
require_once( 'class-sns-meta-box.php' );
// require_once( 'class-sns-code-editor.php' );
require_once( 'class-sns-settings-page.php' );
require_once( 'class-sns-usage-page.php' );
require_once( 'class-sns-global-page.php' );
require_once( 'class-sns-hoops-page.php' );
require_once( 'class-sns-theme-page.php' );
require_once( 'class-sns-ajax.php' );
require_once( 'class-sns-form.php' );
class SnS_Admin
{
/**#@+
* Constants
*/
const OPTION_GROUP = 'scripts_n_styles';
const MENU_SLUG = 'sns';
static $parent_slug = '';
/**#@-*/
/**
* Initializing method.
* @static
*/
static function init() {
add_action( 'admin_menu', array( 'SnS_Admin_Meta_Box', 'init' ) );
// add_action( 'admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
// add_action( 'network_admin_menu', array( 'SnS_Admin_Code_Editor', 'init' ) );
add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
add_action( 'admin_init', array( 'SnS_AJAX', 'init' ) );
add_action( 'admin_init', array( __CLASS__, 'load_plugin_textdomain' ) );
$plugin_file = plugin_basename( Scripts_n_Styles::$file );
add_filter( "plugin_action_links_$plugin_file", array( __CLASS__, 'plugin_action_links') );
register_activation_hook( Scripts_n_Styles::$file, array( __CLASS__, 'upgrade' ) );
}
static function load_plugin_textdomain() {
load_plugin_textdomain( 'scripts-n-styles', false, dirname( plugin_basename( Scripts_n_Styles::$file ) ) . '/languages/' );
}
static function menu() {
if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) ) return;
$options = get_option( 'SnS_options' );
$menu_spot = isset( $options[ 'menu_position' ] ) ? $options[ 'menu_position' ]: '';
$top_spots = array( 'menu', 'object', 'utility' );
$sub_spots = array( 'tools.php', 'options-general.php', 'themes.php' );
if ( in_array( $menu_spot, $top_spots ) ) $parent_slug = SnS_Admin::MENU_SLUG;
else if ( in_array( $menu_spot, $sub_spots ) ) $parent_slug = $menu_spot;
else $parent_slug = 'tools.php';
self::$parent_slug = $parent_slug;
switch( $menu_spot ) {
case 'menu':
add_menu_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
case 'object':
add_object_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
case 'utility':
add_utility_page( __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Scripts n Styles', 'scripts-n-styles' ), 'unfiltered_html', $parent_slug, array( 'SnS_Form', 'page' ), plugins_url( 'images/menu.png', Scripts_n_Styles::$file ) );
break;
}
SnS_Global_Page::init();
SnS_Hoops_Page::init();
if ( current_theme_supports( 'scripts-n-styles' ) )
SnS_Theme_Page::init();
SnS_Settings_Page::init();
SnS_Usage_Page::init();
}
/**
* Nav Tabs
*/
static function nav() {
$options = get_option( 'SnS_options' );
$page = $_REQUEST[ 'page' ];
?>
<h2>Scripts n Styles</h2>
<?php if ( ! isset( $options[ 'menu_position' ] ) || 'options-general.php' != $options[ 'menu_position' ] ) settings_errors(); ?>
<h3 class="nav-tab-wrapper">
<a class="nav-tab<?php echo ( self::MENU_SLUG == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG ); ?>"><?php _e( 'Global', 'scripts-n-styles' ); ?></a>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_hoops' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_hoops' ); ?>"><?php _e( 'Hoops', 'scripts-n-styles' ); ?></a>
<?php if ( current_theme_supports( 'scripts-n-styles' ) ) { ?>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_theme' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_theme' ); ?>"><?php _e( 'Theme', 'scripts-n-styles' ); ?></a>
<?php } ?>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_settings' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_settings' ); ?>"><?php _e( 'Settings', 'scripts-n-styles' ); ?></a>
<a class="nav-tab<?php echo ( self::MENU_SLUG . '_usage' == $page ) ? ' nav-tab-active': ''; ?>" href="<?php menu_page_url( self::MENU_SLUG . '_usage' ); ?>"><?php _e( 'Usage', 'scripts-n-styles' ); ?></a>
</h3>
<?php
}
/**
* Settings Page help
*/
static function help() {
$help = '<p>' . __( 'In default (non MultiSite) WordPress installs, both <em>Administrators</em> and <em>Editors</em> can access <em>Scripts-n-Styles</em> on individual edit screens. Only <em>Administrators</em> can access this Options Page. In MultiSite WordPress installs, only <em>"Super Admin"</em> users can access either <em>Scripts-n-Styles</em> on individual edit screens or this Options Page. If other plugins change capabilities (specifically "unfiltered_html"), other users can be granted access.', 'scripts-n-styles' ) . '</p>';
$help .= '<p><strong>' . __( 'Reference: jQuery Wrappers', 'scripts-n-styles' ) . '</strong></p>' .
'<pre><code>jQuery(document).ready(function($) {
// $() will work as an alias for jQuery() inside of this function
});</code></pre>';
$help .= '<pre><code>(function($) {
// $() will work as an alias for jQuery() inside of this function
})(jQuery);</code></pre>';
$sidebar = '<p><strong>' . __( 'For more information:', 'scripts-n-styles' ) . '</strong></p>' .
'<p>' . __( '<a href="http://wordpress.org/extend/plugins/scripts-n-styles/faq/" target="_blank">Frequently Asked Questions</a>', 'scripts-n-styles' ) . '</p>' .
'<p>' . __( '<a href="https://github.com/unFocus/Scripts-n-Styles" target="_blank">Source on github</a>', 'scripts-n-styles' ) . '</p>' .
'<p>' . __( '<a href="http://wordpress.org/tags/scripts-n-styles" target="_blank">Support Forums</a>', 'scripts-n-styles' ) . '</p>';
$screen = get_current_screen();
if ( method_exists( $screen, 'add_help_tab' ) ) {
$screen->add_help_tab( array(
'title' => __( 'Scripts n Styles', 'scripts-n-styles' ),
'id' => 'scripts-n-styles',
'content' => $help
)
);
if ( 'post' != $screen->id )
$screen->set_help_sidebar( $sidebar );
} else {
add_contextual_help( $screen, $help . $sidebar );
}
}
/**
* Utility Method: Sets defaults if not previously set. Sets stored 'version' to VERSION.
*/
static function upgrade() {
$options = get_option( 'SnS_options' );
if ( ! $options ) $options = array();
$options[ 'version' ] = Scripts_n_Styles::VERSION;
update_option( 'SnS_options', $options );
/*
* upgrade proceedure
*/
$posts = get_posts(
array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'any',
'meta_query' => array(
'relation' => 'OR',
array( 'key' => '_SnS_scripts' ),
array( 'key' => '_SnS_styles' ),
array( 'key' => 'uFp_scripts' ),
array( 'key' => 'uFp_styles' )
)
)
);
foreach( $posts as $post) {
$styles = get_post_meta( $post->ID, '_SnS_styles', true );
if ( empty( $styles ) )
$styles = get_post_meta( $post->ID, 'uFp_styles', true );
$scripts = get_post_meta( $post->ID, '_SnS_scripts', true );
if ( empty( $scripts ) )
$scripts = get_post_meta( $post->ID, 'uFp_scripts', true );
$SnS = array();
if ( ! empty( $styles ) )
$SnS[ 'styles' ] = $styles;
if ( ! empty( $scripts ) )
$SnS[ 'scripts' ] = $scripts;
if ( ! empty( $SnS ) )
update_post_meta( $post->ID, '_SnS', $SnS );
delete_post_meta( $post->ID, 'uFp_styles' );
delete_post_meta( $post->ID, 'uFp_scripts' );
delete_post_meta( $post->ID, '_SnS_styles' );
delete_post_meta( $post->ID, '_SnS_scripts' );
}
}
/**
* Adds link to the Settings Page in the WordPress "Plugin Action Links" array.
* @param array $actions
* @return array
*/
static function plugin_action_links( $actions ) {
$actions[ 'settings' ] = '<a href="' . menu_page_url( SnS_Settings_Page::MENU_SLUG, false ) . '"/>' . __( 'Settings' ) . '</a>';
return $actions;
}
}

View File

@@ -0,0 +1,452 @@
<?php
class SnS_AJAX
{
static function init() {
// Keep track of current tab.
add_action( 'wp_ajax_sns_update_tab', array( __CLASS__, 'update_tab' ) );
// TinyMCE requests a css file.
add_action( 'wp_ajax_sns_tinymce_styles', array( __CLASS__, 'tinymce_styles' ) );
add_action( 'wp_ajax_nopriv_sns_tinymce_styles', array( __CLASS__, 'tinymce_styles' ) );
// Ajax Saves.
add_action( 'wp_ajax_sns_classes', array( __CLASS__, 'classes' ) );
add_action( 'wp_ajax_sns_scripts', array( __CLASS__, 'scripts' ) );
add_action( 'wp_ajax_sns_styles', array( __CLASS__, 'styles' ) );
add_action( 'wp_ajax_sns_html', array( __CLASS__, 'html' ) );
add_action( 'wp_ajax_sns_dropdown', array( __CLASS__, 'dropdown' ) );
add_action( 'wp_ajax_sns_delete_class', array( __CLASS__, 'delete_class' ) );
add_action( 'wp_ajax_sns_shortcodes', array( __CLASS__, 'shortcodes' ) );
add_action( 'wp_ajax_sns_open_theme_panels', array( __CLASS__, 'open_theme_panels' ) );
add_action( 'wp_ajax_sns_plugin_editor', array( __CLASS__, 'plugin_editor' ) );
}
static function plugin_editor() {
check_ajax_referer( 'sns_plugin_editor' );
if ( ! current_user_can( 'edit_plugins' ) ) exit( 'Insufficient Privileges.' );
$active = false;
$plugin = '';
$debug = array();
$need_update = false;
$plugins = array_keys( get_plugins() );
$file = $_REQUEST[ 'file' ];
$short = substr( $file, 0, strpos( $file, '/' ) );
if ( ! in_array( $file, $plugins ) ) {
$need_update = true;
if ( in_array( $_REQUEST[ 'plugin' ], $plugins ) ) {
$plugin = $_REQUEST[ 'plugin' ];
} else {
foreach ( $plugins as $maybe ) {
if ( false !== strpos( $maybe, $short ) ) {
$plugin = $maybe;
break;
}
}
}
} else {
$plugin = $file;
while ( 1 < substr_count( $plugin, "/" ) ) {
$plugin = dirname( $plugin );
}
}
$active = is_plugin_active( $plugin ) || is_plugin_active_for_network( $plugin );
$files = get_plugin_files( $plugin );
add_filter( 'editable_extensions', array( 'SnS_Admin_Code_Editor', 'extend' ) );
$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
$editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
$ul = '';
foreach ( $files as $plugin_file ) {
// Get the extension of the file
if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) ) {
$ext = strtolower( $matches[1] );
// If extension is not in the acceptable list, skip it
if ( ! in_array( $ext, $editable_extensions ) )
continue;
} else {
// No extension found
continue;
}
$ul .= '<li';
$ul .= $file == $plugin_file ? ' class="highlight">' : '>';
$ul .= '<a href="plugin-editor.php?file=' . urlencode( $plugin_file ) . '&amp;plugin=' . urlencode( $plugin ) . '">';
$ul .= str_replace( $short . '/', '', $plugin_file );
$ul .= '</a>';
$ul .= '</li>';
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"plugin" => $plugin,
"active" => $active,
"files" => $files,
"need_update" => $need_update,
"ul" => $ul,
) );
exit();
}
static function open_theme_panels() {
check_ajax_referer( SnS_Admin::OPTION_GROUP . "-options" );
$name = isset( $_POST[ 'file-name' ] ) ? $_POST[ 'file-name' ] : '';
if ( empty( $name ) ) exit( 'empty name');
$collapsed = isset( $_POST[ 'collapsed' ] ) ? $_POST[ 'collapsed' ] : '';
if ( empty( $collapsed ) ) exit( 'empty value');
if ( ! $user = get_current_user_id() ) exit( 'Bad User' );
$open_theme_panels = json_decode( get_user_option( 'sns_open_theme_panels', $user ), true );
$open_theme_panels = is_array( $open_theme_panels ) ? $open_theme_panels : array();
$open_theme_panels[ $name ] = $collapsed;
$open_theme_panels = json_encode( $open_theme_panels );
update_user_option( $user, 'sns_open_theme_panels', $open_theme_panels );
exit();
}
static function update_tab() {
check_ajax_referer( Scripts_n_Styles::$file );
$active_tab = isset( $_POST[ 'active_tab' ] ) ? 's'.$_POST[ 'active_tab' ] : 's0';
if ( ! $user = wp_get_current_user() ) exit( 'Bad User' );
$success = update_user_option( $user->ID, 'current_sns_tab', $active_tab, true);
exit();
}
static function tinymce_styles() {
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$options = get_option( 'SnS_options' );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
header('Content-Type: text/css; charset=UTF-8');
if ( ! empty( $options[ 'styles' ] ) ) echo $options[ 'styles' ];
if ( ! empty( $styles[ 'styles' ] ) ) echo $styles[ 'styles' ];
exit();
}
// AJAX handlers
static function classes() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'classes_body' ], $_REQUEST[ 'classes_post' ] ) ) exit( 'Data missing.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$styles = self::maybe_set( $styles, 'classes_body' );
$styles = self::maybe_set( $styles, 'classes_post' );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_post" => $_REQUEST[ 'classes_post' ]
, "classes_body" => $_REQUEST[ 'classes_body' ]
) );
exit();
}
static function scripts() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'scripts' ], $_REQUEST[ 'scripts_in_head' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$scripts = isset( $SnS['scripts'] ) ? $SnS[ 'scripts' ]: array();
$scripts = self::maybe_set( $scripts, 'scripts_in_head' );
$scripts = self::maybe_set( $scripts, 'scripts' );
if ( empty( $scripts ) ) {
if ( isset( $SnS['scripts'] ) )
unset( $SnS['scripts'] );
} else {
$SnS[ 'scripts' ] = $scripts;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"scripts" => $_REQUEST[ 'scripts' ]
, "scripts_in_head" => $_REQUEST[ 'scripts_in_head' ]
) );
exit();
}
static function html() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'html_in_footer' ], $_REQUEST[ 'html_in_head' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$html = isset( $SnS['html'] ) ? $SnS[ 'html' ]: array();
$html = self::maybe_set( $html, 'html_in_head' );
$html = self::maybe_set( $html, 'html_in_footer' );
if ( empty( $html ) ) {
if ( isset( $SnS['html'] ) )
unset( $SnS['html'] );
} else {
$SnS[ 'html' ] = $html;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"html_in_footer" => $_REQUEST[ 'html_in_footer' ]
, "html_in_head" => $_REQUEST[ 'html_in_head' ]
) );
exit();
}
static function styles() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( ! isset( $_REQUEST[ 'styles' ] ) ) exit( 'Data incorrectly sent.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$styles = self::maybe_set( $styles, 'styles' );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"styles" => $_REQUEST[ 'styles' ],
) );
exit();
}
static function dropdown() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'format' ] ) ) exit( 'Missing Format.' );
if ( empty( $_REQUEST[ 'format' ][ 'title' ] ) ) exit( 'Title is required.' );
if ( empty( $_REQUEST[ 'format' ][ 'classes' ] ) ) exit( 'Classes is required.' );
if (
empty( $_REQUEST[ 'format' ][ 'inline' ] ) &&
empty( $_REQUEST[ 'format' ][ 'block' ] ) &&
empty( $_REQUEST[ 'format' ][ 'selector' ] )
) exit( 'A type is required.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array();
// pass title as key to be able to delete.
$styles[ 'classes_mce' ][ $_REQUEST[ 'format' ][ 'title' ] ] = $_REQUEST[ 'format' ];
$SnS[ 'styles' ] = $styles;
update_post_meta( $post_id, '_SnS', $SnS );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_mce" => array_values( $styles[ 'classes_mce' ] )
) );
exit();
}
static function delete_class() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$styles = isset( $SnS['styles'] ) ? $SnS[ 'styles' ]: array();
$title = $_REQUEST[ 'delete' ];
if ( isset( $styles[ 'classes_mce' ][ $title ] ) ) unset( $styles[ 'classes_mce' ][ $title ] );
else exit ( 'No Format of that name.' );
if ( empty( $styles[ 'classes_mce' ] ) ) unset( $styles[ 'classes_mce' ] );
if ( empty( $styles ) ) {
if ( isset( $SnS['styles'] ) )
unset( $SnS['styles'] );
} else {
$SnS[ 'styles' ] = $styles;
}
self::maybe_update( $post_id, '_SnS', $SnS );
if ( ! isset( $styles[ 'classes_mce' ] ) ) $styles[ 'classes_mce' ] = array( 'Empty' );
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"classes_mce" => array_values( $styles[ 'classes_mce' ] )
) );
exit();
}
static function shortcodes() {
check_ajax_referer( Scripts_n_Styles::$file );
if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'edit_posts' ) ) exit( 'Insufficient Privileges.' );
if ( empty( $_REQUEST[ 'post_id' ] ) ) exit( 'Bad post ID.' );
if ( empty( $_REQUEST[ 'subaction' ] ) ) exit( 'missing directive' );
if ( in_array( $_REQUEST[ 'subaction' ], array( 'add', 'update', 'delete' ) ) )
$subaction = $_REQUEST[ 'subaction' ];
else
exit( 'unknown directive' );
$post_id = absint( $_REQUEST[ 'post_id' ] );
$SnS = get_post_meta( $post_id, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$shortcodes = isset( $SnS[ 'shortcodes' ] ) ? $SnS[ 'shortcodes' ]: array();
$message = '';
$code = 0;
$key = '';
$value = '';
if ( isset( $_REQUEST[ 'name' ] ) )
$key = $_REQUEST[ 'name' ];
else
exit( 'bad directive.' );
if ( '' == $key ) {
$key = count( $shortcodes );
while ( isset( $shortcodes[ $key ] ) )
$key++;
}
switch ( $subaction ) {
case 'add':
if ( empty( $_REQUEST[ 'shortcode' ] ) )
exit( 'empty value.' );
else
$value = $_REQUEST[ 'shortcode' ];
if ( isset( $shortcodes[ $key ] ) ) {
$countr = 1;
while ( isset( $shortcodes[ $key . '_' . $countr ] ) )
$countr++;
$key .= '_' . $countr;
}
$code = 1;
$shortcodes[ $key ] = $value;
break;
case 'update':
if ( empty( $_REQUEST[ 'shortcode' ] ) ) {
if ( isset( $shortcodes[ $key ] ) )
unset( $shortcodes[ $key ] );
$code = 3;
$message = $key;
} else {
$value = $_REQUEST[ 'shortcode' ];
if ( isset( $shortcodes[ $key ] ) )
$shortcodes[ $key ] = $value;
else
exit( 'wrong key.' );
$code = 2;
$message = 'updated ' . $key;
}
break;
case 'delete':
if ( isset( $shortcodes[ $key ] ) )
unset( $shortcodes[ $key ] );
else
exit( 'bad key.' );
$code = 3;
$message = $key;
break;
}
if ( empty( $shortcodes ) ) {
if ( isset( $SnS[ 'shortcodes' ] ) )
unset( $SnS[ 'shortcodes' ] );
} else {
$SnS[ 'shortcodes' ] = $shortcodes;
}
self::maybe_update( $post_id, '_SnS', $SnS );
if ( 1 < $code ) {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode( array(
"message" => $message
, "code" => $code
) );
} else {
header('Content-Type: text/html; charset=' . get_option('blog_charset'));
?><div class="sns-shortcode widget">
<div class="inside">
<p>[hoops name="<?php echo esc_attr( $key ) ?>"]</p>
<textarea style="width: 98%;" cols="40" rows="5" name="SnS_shortcodes[existing][<?php echo esc_attr( $key ) ?>]"
data-sns-shortcode-key="<?php echo esc_attr( $key ) ?>" class="codemirror-new htmlmixed"><?php echo esc_textarea( stripslashes( $value ) ) ?></textarea>
<div class="sns-ajax-wrap"><a href="#" class="sns-ajax-delete-shortcode button">Delete</a> &nbsp; <a href="#" class="sns-ajax-update-shortcode button">Update</a> <span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span></div>
</div>
</div><?php
}
exit();
}
// Differs from SnS_Admin_Meta_Box::maybe_set() in that this needs no prefix.
static function maybe_set( $o, $i ) {
if ( ! is_array( $o ) ) return array();
if ( empty( $_REQUEST[ $i ] ) ) {
if ( isset( $o[ $i ] ) ) unset( $o[ $i ] );
} else $o[ $i ] = $_REQUEST[ $i ];
return $o;
}
static function maybe_update( $id, $name, $meta ) {
if ( empty( $meta ) ) {
delete_post_meta( $id, $name );
} else {
update_post_meta( $id, $name, $meta );
}
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* SnS_Global_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Form
{
/**
* Settings Page
* Outputs a textarea for setting 'scripts_in_head'.
*/
static function textarea( $args ) {
extract( $args );
$options = get_option( $setting );
$value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : '';
$output = '';
if ( isset( $wrap_class ) ) $output .= '<div class="'. $wrap_class . '">';
$output .= '<textarea';
$output .= ( $style ) ? ' style="' . $style . '"': '';
$output .= ( $class ) ? ' class="' . $class . '"': '';
$output .= ( $rows ) ? ' rows="' . $rows . '"': '';
$output .= ( $cols ) ? ' cols="' . $cols . '"': '';
$output .= ' name="' . $setting . '[' . $label_for . ']"';
$output .= ' id="' . $label_for . '">';
$output .= esc_textarea( $value ) . '</textarea>';
if ( isset( $wrap_class ) ) $output .= '</div>';
if ( $description ) {
$output .= $description;
}
echo $output;
}
static function radio( $args ) {
extract( $args );
$options = get_option( $setting );
$default = isset( $default ) ? $default : '';
$value = isset( $options[ $label_for ] ) ? $options[ $label_for ] : $default;
$output = '<fieldset>';
if ( $legend ) {
$output .= '<legend class="screen-reader-text"><span>';
$output .= $legend;
$output .= '</span></legend>';
}
$output .= '<p>';
foreach ( $choices as $choice ) {
$output .= '<label style="white-space: pre;">';
$output .= '<input type="radio"';
$output .= checked( $value, $choice, false );
$output .= ' value="' . $choice . '" name="' . $setting . '[' . $label_for . ']"> ' . $choice;
$output .= '</label>';
$output .= ( ! isset( $layout ) || 'horizontal' != $layout ) ? '<br>' : ' &nbsp; ';
}
$output .= '</p></fieldset>';
if ( $description ) {
$output .= $description;
}
echo $output;
}
/**
* Settings Page
* Outputs a select element for selecting options to set scripts for including.
*/
static function select( $args ) {
extract( $args );
$options = get_option( $setting );
$selected = isset( $options[ $label_for ] ) ? $options[ $label_for ] : array();
$output = '<select';
$output .= ' id="' . $label_for . '"';
$output .= ' name="' . $setting . '[' . $label_for . ']';
if ( isset( $multiple ) && $multiple )
$output .= '[]" multiple="multiple"';
else
$output .= '"';
$output .= ( $size ) ? ' size="' . $size . '"': '';
$output .= ( $style ) ? ' style="' . $style . '"': '';
$output .= '>';
foreach ( $choices as $choice ) {
$output .= '<option value="' . $choice . '"';
if ( isset( $multiple ) && $multiple )
foreach ( $selected as $handle ) $output .= selected( $handle, $choice, false );
else
$output .= selected( $selected, $choice, false );
$output .= '>' . $choice . '</option> ';
}
$output .= '</select>';
if ( ! empty( $show_current ) && ! empty( $selected ) ) {
$output .= '<p>' . $show_current;
foreach ( $selected as $handle ) $output .= '<code>' . $handle . '</code> ';
$output .= '</p>';
}
echo $output;
}
/**
* Settings Page
* Outputs the Admin Page and calls the Settings registered with the Settings API.
*/
static function take_action() {
global $action, $option_page, $page, $new_whitelist_options;
if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'unfiltered_html' ) || ( is_multisite() && ! is_super_admin() ) )
wp_die( __( 'Cheatin&#8217; uh?' ) );
// Handle menu-redirected update message.
if ( isset( $_REQUEST[ 'message' ] ) && $_REQUEST[ 'message' ] )
add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
if ( ! isset( $_REQUEST[ 'action' ], $_REQUEST[ 'option_page' ], $_REQUEST[ 'page' ] ) )
return;
wp_reset_vars( array( 'action', 'option_page', 'page' ) );
check_admin_referer( $option_page . '-options' );
if ( ! isset( $new_whitelist_options[ $option_page ] ) )
return;
$options = $new_whitelist_options[ $option_page ];
foreach ( (array) $options as $option ) {
$old = get_option( $option );
$option = trim( $option );
$new = null;
if ( isset($_POST[ $option ]) )
$new = $_POST[ $option ];
if ( !is_array( $new ) )
$new = trim( $new );
$new = stripslashes_deep( $new );
$value = array_merge( $old, $new );
// Allow modification of $value
$value = apply_filters( 'sns_options_pre_update_option', $value, $page, $action, $new, $old );
update_option( $option, $value );
}
if ( ! count( get_settings_errors() ) )
add_settings_error( $page, 'settings_updated', __( 'Settings saved.' ), 'updated' );
if ( isset( $_REQUEST[ 'ajaxsubmit' ] ) && $_REQUEST[ 'ajaxsubmit' ] ) {
ob_start();
settings_errors( $page );
$output = ob_get_contents();
ob_end_clean();
exit( $output );
}
// Redirect to new page if changed.
if ( isset( $_POST[ $option ][ 'menu_position' ] ) && ( $value[ 'menu_position' ] != SnS_Admin::$parent_slug ) ) {
switch( $value[ 'menu_position' ] ) {
case 'menu':
case 'object':
case 'utility':
wp_redirect( add_query_arg( array( 'message' => 1, 'page' => 'sns_settings' ), admin_url( 'admin.php' ) ) );
break;
default:
wp_redirect( add_query_arg( array( 'message' => 1, 'page' => 'sns_settings' ), admin_url( $value[ 'menu_position' ] ) ) );
break;
}
}
return;
}
/**
* Settings Page
* Outputs the Admin Page and calls the Settings registered with the Settings API in init_options_page().
*/
static function page() {
?>
<div class="wrap">
<?php SnS_Admin::nav(); ?>
<form action="" method="post" autocomplete="off">
<?php settings_fields( SnS_Admin::OPTION_GROUP ); ?>
<?php do_settings_sections( SnS_Admin::MENU_SLUG ); ?>
<?php if ( apply_filters( 'sns_show_submit_button', true ) ) submit_button(); ?>
</form>
</div>
<?php
}
}

View File

@@ -0,0 +1,252 @@
<?php
/**
* SnS_Global_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Global_Page
{
/**
* Initializing method.
* @static
*/
static function init() {
if ( SnS_Admin::$parent_slug == SnS_Admin::MENU_SLUG ) $menu_title = __( 'Global', 'scripts-n-styles' );
else $menu_title = __( 'Scripts n Styles', 'scripts-n-styles' );
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), $menu_title, 'unfiltered_html', SnS_Admin::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'chosen' );
wp_enqueue_style( 'sns-options' );
wp_enqueue_script( 'sns-global-page' );
wp_localize_script( 'sns-global-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'global_html',
__( 'Blog Wide HTML', 'scripts-n-styles' ),
array( __CLASS__, 'global_html_section' ),
SnS_Admin::MENU_SLUG );
add_settings_section(
'global_styles',
__( 'Blog Wide CSS Styles', 'scripts-n-styles' ),
array( __CLASS__, 'global_styles_section' ),
SnS_Admin::MENU_SLUG );
add_settings_section(
'global_scripts',
__( 'Blog Wide JavaScript', 'scripts-n-styles' ),
array( __CLASS__, 'global_scripts_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'less',
__( '<strong>LESS:</strong> ', 'scripts-n-styles' ),
array( __CLASS__, 'less_fields' ),
SnS_Admin::MENU_SLUG,
'global_styles',
array( 'label_for' => 'less' ) );
add_settings_field(
'coffee',
__( '<strong>CoffeeScript:</strong> ', 'scripts-n-styles' ),
array( __CLASS__, 'coffee_fields' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array( 'label_for' => 'coffee' ) );
add_settings_field(
'html_in_head',
__( '<strong>HTML<br>(<code>head</code> tag):</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_html',
array(
'label_for' => 'html_in_head',
'setting' => 'SnS_options',
'class' => 'code html',
'wrap_class' => 'html',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The HTML will be included in <code>&lt;head></code> element of your pages.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'html_in_footer',
__( '<strong>HTML<br>(end of the <code>body</code> tag):</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_html',
array(
'label_for' => 'html_in_footer',
'setting' => 'SnS_options',
'class' => 'code html',
'wrap_class' => 'html',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The HTML will be included at the bottom of the <code>&lt;body></code> element of your pages.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'styles',
__( '<strong>CSS Styles:</strong> ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_styles',
array(
'label_for' => 'styles',
'setting' => 'SnS_options',
'class' => 'code css',
'wrap_class' => 'style',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'scripts_in_head',
__( '<strong>Scripts</strong><br />(for the <code>head</code> element): ', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'scripts_in_head',
'setting' => 'SnS_options',
'class' => 'code js',
'wrap_class' => 'script',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'scripts',
__( '<strong>Scripts</strong><br />(end of the <code>body</code> tag):', 'scripts-n-styles' ),
array( 'SnS_Form', 'textarea' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'scripts',
'setting' => 'SnS_options',
'class' => 'code js',
'wrap_class' => 'script',
'rows' => 5,
'cols' => 40,
'style' => 'min-width: 500px; width:97%;',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the bottom of the <code>&lt;body></code> element of your html.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'enqueue_scripts',
__( '<strong>Enqueue Scripts</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'select' ),
SnS_Admin::MENU_SLUG,
'global_scripts',
array(
'label_for' => 'enqueue_scripts',
'setting' => 'SnS_options',
'choices' => Scripts_n_Styles::get_wp_registered(),
'size' => 5,
'style' => 'height: auto;',
'multiple' => true,
'show_current' => __( 'Currently Enqueued Scripts: ', 'scripts-n-styles' )
) );
add_filter( 'sns_options_pre_update_option', array( __CLASS__, 'enqueue_scripts'), 10, 5 );
}
static function enqueue_scripts( $value, $page, $action, $new, $old ) {
if ( empty( $new['enqueue_scripts'] ) && ! empty( $old['enqueue_scripts'] ) )
unset( $value['enqueue_scripts'] );
return $value;
}
static function less_fields() {
$options = get_option( 'SnS_options' );
$less = isset( $options[ 'less' ] ) ? $options[ 'less' ] : '';
$compiled = isset( $options[ 'compiled' ] ) ? $options[ 'compiled' ] : '';
?>
<div style="overflow: hidden;">
<div style="width: 49%; float: left; overflow: hidden; margin-right: 2%;" class="less">
<textarea id="less" name="SnS_options[less]" style="min-width: 250px; width:47%; float: left" class="code less" rows="5" cols="40"><?php echo esc_textarea( $less ) ?></textarea>
</div>
<div style="width: 49%; float: left; overflow: hidden;" class="style">
<textarea id="compiled" name="SnS_options[compiled]" style="min-width: 250px; width:47%;" class="code css" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
<div id="compiled_error" style="display: none" class="error settings-error below-h2"></div>
</div>
</div>
<?php
}
static function coffee_fields() {
$options = get_option( 'SnS_options' );
$coffee = isset( $options[ 'coffee' ] ) ? $options[ 'coffee' ] : '';
$compiled = isset( $options[ 'coffee_compiled' ] ) ? $options[ 'coffee_compiled' ] : '';
?>
<div style="overflow: hidden;">
<div style="width: 49%; float: left; overflow: hidden; margin-right: 2%;" class="coffee">
<textarea id="coffee" name="SnS_options[coffee]" style="min-width: 250px; width:47%; float: left" class="code coffee" rows="5" cols="40"><?php echo esc_textarea( $coffee ) ?></textarea>
</div>
<div style="width: 49%; float: left; overflow: hidden;" class="script">
<textarea id="coffee_compiled" name="SnS_options[coffee_compiled]" style="min-width: 250px; width:47%;" class="code js" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
<div id="coffee_compiled_error" style="display: none" class="error settings-error below-h2"></div>
</div>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_scripts_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts that were registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_styles_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Styles that were registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_html_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'HTML entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> HTML added to individual posts and pages.', 'scripts-n-styles' )?></p>
<p><?php _e( 'You can place <strong>any</strong> HTML here. In the <code>head</code> tag, please stick to appropriate elements, like <code>script</code>, <code>style</code>, <code>link</code>, and <code>meta</code> html tags.' ); ?></p>
</div>
<?php
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* SnS_Hoops_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Hoops_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_hoops';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Hoops' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'sns-options' );
wp_enqueue_style( 'codemirror-theme' );
wp_enqueue_script( 'sns-hoops-page' );
wp_localize_script( 'sns-hoops-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
// added here to not effect other pages.
add_filter( 'sns_options_pre_update_option', array( __CLASS__, 'new_hoops') );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'hoops_section',
__( 'The Hoops Shortcodes', 'scripts-n-styles' ),
array( __CLASS__, 'hoops_section' ),
SnS_Admin::MENU_SLUG );
}
static function new_hoops( $options ) {
// Get Hoops. (Shouldn't be empty.)
$hoops = $options[ 'hoops' ];
/*
add_settings_error( 'sns_hoops', 'settings_updated', '<pre>'
. '$hoops '
. print_r(
$hoops, true ) . '</pre>', 'updated' );
*/
// take out new. (Also shouldn't be empty.)
$new = $hoops[ 'new' ];
unset( $hoops[ 'new' ] );
// Get Shortcodes. (Could be empty.)
$shortcodes = empty( $hoops[ 'shortcodes' ] ) ? array() : $hoops[ 'shortcodes' ];
// prune shortcodes with blank values.
foreach( $shortcodes as $key => $value ){
if ( empty( $value ) )
unset( $shortcodes[ $key ] );
}
// Add new (if not empty).
if ( ! empty( $new[ 'code' ] ) ) {
$name = empty( $new[ 'name' ] ) ? '' : $new[ 'name' ];
if ( '' == $name ) {
// If blank, find next index..
$name = 0;
while ( isset( $shortcodes[ $name ] ) )
$name++;
} else if ( isset( $shortcodes[ $name ] ) ) {
// To make sure not to overwrite.
$countr = 1;
while ( isset( $shortcodes[ $name . '_' . $countr ] ) )
$countr++;
$name .= '_' . $countr;
}
// Add new to shortcodes.
$shortcodes[ $name ] = $new[ 'code' ];
}
// Put in Shortcodes... if not empty.
if ( empty( $shortcodes ) ) {
if ( isset( $hoops[ 'shortcodes' ] ) )
unset( $hoops[ 'shortcodes' ] );
} else {
$hoops[ 'shortcodes' ] = $shortcodes;
}
// Put in Hoops... if not empty.
if ( empty( $hoops ) ) {
if ( isset( $options[ 'hoops' ] ) )
unset( $options[ 'hoops' ] );
} else {
$options[ 'hoops' ] = $hoops;
}
return $options; // Finish Filter.
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function hoops_section() {
echo '<div style="max-width: 55em;">';
_e( '<p>"Hoops" are shortcodes invented to get around some limitations of vanilla WordPress.</p>'
. '<p> Normally, certain HTML is very problematic to use in the Post Editor, because it either gets '
. 'jumbled during Switching between HTML and Visual Tabs, stripped out by WPAutoP (rare) or stripped '
. 'out because the User doesn&#8217;t have the proper Permissions.</p>'
. '<p>With Hoops, an Admin user (who has `unfiltered_html` and `manage_options` capablilities) can '
. 'write and approve snippets of HTML for other users to use via Shortcodes.</p>', 'scripts-n-styles' );
echo '</div>';
$options = get_option( 'SnS_options' );
$meta_name = 'SnS_options[hoops]';
$hoops = isset( $options[ 'hoops' ] ) ? $options[ 'hoops' ] : array();
$shortcodes = isset( $hoops[ 'shortcodes' ] ) ? $hoops[ 'shortcodes' ] : array();
?>
<div id="sns-shortcodes">
<h4>Add New: </h4>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget sns-shortcodes"><div class="inside">
<label style="display:inline" for="<?php echo $meta_name; ?>">Name: </label>
<input id="<?php echo $meta_name; ?>" name="<?php echo $meta_name . '[new][name]'; ?>" type="text" />
<?php /** / ?>
<a class="button" href="#" id="sns-ajax-add-shortcode">Add New</a>
<?php /**/ ?>
<textarea id="<?php echo $meta_name; ?>_new" class="code htmlmixed" name="<?php echo $meta_name . '[new][code]'; ?>" rows="5" cols="40" style="width: 98%;"></textarea>
</div></div>
</div>
<?php if ( ! empty( $shortcodes ) ) { ?>
<h4>Existing Codes: </h4>
<div id="sns-shortcodes-wrap">
<?php if ( ! empty( $shortcodes ) ) { ?>
<?php foreach ( $shortcodes as $key => $value ) { ?>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget sns-shortcodes"><div class="sns-collapsed inside">
<span class="sns-collapsed-btn"></span>
<p style="margin-bottom: 0;">[hoops name="<?php echo $key ?>"]</p>
<textarea class="code htmlmixed" data-sns-shortcode-key="<?php echo $key ?>" name="<?php echo $meta_name . '[shortcodes][' . $key . ']'; ?>" rows="5" cols="40" style="width: 98%;"><?php echo esc_textarea( $value ); ?></textarea>
<?php /** / ?>
<div class="sns-ajax-wrap">
<a class="sns-ajax-delete-shortcode button" href="#">Delete</a> &nbsp;
<a class="sns-ajax-update-shortcode button" href="#">Update</a>
<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
</div>
<?php /**/ ?>
</div></div>
</div>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,176 @@
<?php
if ( ! class_exists( 'WP_List_Table' ) ) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class SnS_List_Usage extends WP_List_Table {
function ajax_user_can() {
return current_user_can( 'unfiltered_html' ) && current_user_can( 'manage_options' );
}
function column_default( $post, $column_name ) {
$return = '';
switch( $column_name ){
case 'status':
return $post->post_status;
case 'ID':
case 'post_type':
return $post->$column_name;
case 'script_data':
if ( isset( $post->sns_scripts[ 'scripts_in_head' ] ) ) {
$return .= '<div>' . __( 'Scripts (head)', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_scripts[ 'scripts' ] ) ) {
$return .= '<div>' . __( 'Scripts', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_scripts[ 'enqueue_scripts' ] ) ) {
$return .= '<div>' . __( 'Enqueued Scripts', 'scripts-n-styles' ) . '</div>';
}
return $return;
case 'style_data':
if ( isset( $post->sns_styles[ 'classes_mce' ] ) ) {
$return .= '<div>' . __( 'TinyMCE Formats', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'styles' ] ) ) {
$return .= '<div>' . __( 'Styles', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'classes_post' ] ) ) {
$return .= '<div>' . __( 'Post Classes', 'scripts-n-styles' ) . '</div>';
}
if ( isset( $post->sns_styles[ 'classes_body' ] ) ) {
$return .= '<div>' . __( 'Body Classes', 'scripts-n-styles' ) . '</div>';
}
return $return;
default:
return print_r( $post, true );
}
}
function column_title( $post ) {
$edit_link = esc_url( get_edit_post_link( $post->ID ) );
$edit_title = esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $post->post_title ) );
$actions = array(
'edit' => sprintf( '<a title="%s" href="%s">%s</a>', $edit_title, $edit_link, __( 'Edit' ) ),
);
$return = '<strong>';
if ( $this->ajax_user_can() && $post->post_status != 'trash' ) {
$return .= '<a class="row-title"';
$return .= ' href="'. $edit_link .'"';
$return .= ' title="'. $edit_title .'">';
$return .= $post->post_title;
$return .= '</a>';
} else {
$return .= $post->post_title;
}
$this->_post_states( $post );
$return .= '</strong>';
$return .= $this->row_actions( $actions );
return $return;
}
function get_columns() {
$columns = array(
'title' => __( 'Title' ),
'ID' => __( 'ID' ),
'status' => __( 'Status' ),
'post_type' => __( 'Post Type', 'scripts-n-styles' ),
'script_data' => __( 'Script Data', 'scripts-n-styles' ),
'style_data' => __( 'Style Data', 'scripts-n-styles' )
);
return $columns;
}
function prepare_items() {
$screen_id = get_current_screen()->id;
$per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen_id}_per_page" ) );
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
/**
* Get Relavent Posts.
*/
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => 'any',
'post_status' => 'any',
'orderby' => 'ID',
'order' => 'ASC',
'meta_key' => '_SnS'
) );
$items = $this->_add_meta_data( $posts );
$total_items = count( $items );
/**
* Reduce items to current page's posts.
*/
$this->items = array_slice(
$items,
( ( $this->get_pagenum() - 1 ) * $per_page ),
$per_page
);
$this->set_pagination_args( compact( 'total_items', 'per_page' ) );
}
function _post_states( $post ) {
$post_states = array();
$return = '';
if ( isset($_GET[ 'post_status' ]) )
$post_status = $_GET[ 'post_status' ];
else
$post_status = '';
if ( ! empty( $post->post_password ) )
$post_states[ 'protected' ] = __( 'Password protected' );
if ( 'private' == $post->post_status && 'private' != $post_status )
$post_states[ 'private' ] = __( 'Private' );
if ( 'draft' == $post->post_status && 'draft' != $post_status )
$post_states[ 'draft' ] = __( 'Draft' );
if ( 'pending' == $post->post_status && 'pending' != $post_status )
/* translators: post state */
$post_states[ 'pending' ] = _x( 'Pending', 'post state' );
if ( is_sticky($post->ID) )
$post_states[ 'sticky' ] = __( 'Sticky' );
$post_states = apply_filters( 'display_post_states', $post_states );
if ( ! empty( $post_states ) ) {
$state_count = count( $post_states );
$i = 0;
$return .= ' - ';
foreach ( $post_states as $state ) {
++$i;
( $i == $state_count ) ? $sep = '' : $sep = ', ';
$return .= "<span class='post-state'>$state$sep</span>";
}
}
if ( get_post_format( $post->ID ) )
$return .= ' - <span class="post-state-format">' . get_post_format_string( get_post_format( $post->ID ) ) . '</span>';
return $return;
}
function _add_meta_data( $posts ) {
foreach( $posts as $post) {
$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();
if ( ! empty( $styles ) )
$post->sns_styles = $styles;
if ( ! empty( $scripts ) )
$post->sns_scripts = $scripts;
}
return $posts;
}
}

View File

@@ -0,0 +1,451 @@
<?php
/**
* SnS_Admin_Meta_Box
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Admin_Meta_Box
{
/*
* Constants
*/
const NONCE_NAME = 'scripts_n_styles_noncename';
static $post_types;
/**
* Initializing method.
*/
static function init() {
add_action( 'current_screen', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'save_post', array( __CLASS__, 'save_post' ) );
}
static function mce_buttons_2( $buttons ) {
global $post;
$SnS = get_post_meta( $post->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 );
?>
<ul class="wp-tab-bar">
<li<?php echo ( 's0' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_scripts-tab"><?php _e( 'Scripts', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's1' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_styles-tab"><?php _e( 'Styles', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's2' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_classes_body-tab"><?php _e( 'Classes', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's3' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_enqueue_scripts-tab"><?php _e( 'Include Scripts', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's4' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_shortcodes-tab"><?php _e( 'Shortcodes', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's5' == $position ) ? ' class="wp-tab-active"': ''; ?> style="display:none"><a href="#SnS_post_styles-tab"><?php _e( 'Dropdown', 'scripts-n-styles' ) ?></a></li>
<li<?php echo ( 's6' == $position ) ? ' class="wp-tab-active"': ''; ?>><a href="#SnS_html-tab"><?php _e( 'HTML', 'scripts-n-styles' ) ?></a></li>
</ul>
<div class="wp-tab-panel" id="SnS_scripts-tab">
<p><em><?php _e( "This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's)", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_scripts_in_head" class="title"><?php _e( '<strong>Scripts</strong> (for the <code>head</code> element):', 'scripts-n-styles' ) ?> </label>
<div class="script">
<textarea class="codemirror js" name="SnS_scripts_in_head" id="SnS_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts_in_head' ] ) ? esc_textarea( $scripts[ 'scripts_in_head' ] ) : ''; ?></textarea>
</div>
<p><em>... <code>&lt;/head></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
<label for="SnS_scripts" class="title"><strong>Scripts</strong>: </label>
<div class="script">
<textarea class="codemirror js" name="SnS_scripts" id="SnS_scripts" rows="5" cols="40" style="width: 98%;"><?php echo isset( $scripts[ 'scripts' ] ) ? esc_textarea( $scripts[ 'scripts' ] ) : ''; ?></textarea>
</div>
<p><em>... <code>&lt;/body></code> <?php _e( 'tag', 'scripts-n-styles' ) ?>.</em></p>
</div>
<div class="wp-tab-panel" id="SnS_styles-tab">
<label for="SnS_styles" class="title"><?php _e( '<strong>Styles</strong>:', 'scripts-n-styles' ) ?> </label>
<div class="style">
<textarea class="codemirror css" name="SnS_styles" id="SnS_styles" rows="5" cols="40" style="width: 98%;"><?php echo isset( $styles[ 'styles' ] ) ? esc_textarea( $styles[ 'styles' ] ) : ''; ?></textarea>
</div>
<p><em><?php _e( 'This code will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> tag of your page (or post).', 'scripts-n-styles' ) ?></em></p>
</div>
<div class="wp-tab-panel" id="SnS_classes_body-tab">
<strong class="title"><?php _e( 'Classes', 'scripts-n-styles' ) ?></strong>
<div id="sns-classes">
<p>
<label for="SnS_classes_body"><?php _e( '<strong>Body Classes</strong>:', 'scripts-n-styles' ) ?> </label>
<input name="SnS_classes_body" id="SnS_classes_body" type="text" class="code" style="width: 99%;"
value="<?php echo isset( $styles[ 'classes_body' ] ) ? esc_attr( $styles[ 'classes_body' ] ) : ''; ?>" />
</p>
<p>
<label for="SnS_classes_post"><strong>Post Classes</strong>: </label>
<input name="SnS_classes_post" id="SnS_classes_post" type="text" class="code" style="width: 99%;"
value="<?php echo isset( $styles[ 'classes_post' ] ) ? esc_attr( $styles[ 'classes_post' ] ) : ''; ?>" />
</p>
<p><em><?php _e( 'These <strong>space separated</strong> class names will be added to the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).', 'scripts-n-styles' ) ?></em></p>
</div>
</div>
<?php
/*
* Note: Styles Dropdown section only makes sense when Javascript is enabled. (Otherwise, no TinyMCE.)
*/
?>
<div class="wp-tab-panel" id="SnS_post_styles-tab" style="display: none;">
<strong class="title"><?php _e( 'Post Styles', 'scripts-n-styles' ) ?></strong>
<div id="mce-dropdown-names">
<h4><?php _e( 'The Styles Dropdown', 'scripts-n-styles' ) ?></h4>
<div id="add-mce-dropdown-names">
<p><?php _e( 'Add (or update) a class for the "Styles" drop-down:', 'scripts-n-styles' ) ?></p>
<p class="sns-mce-title">
<label for="SnS_classes_mce_title"><?php _e( 'Title:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_title" id="SnS_classes_mce_title"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-type">
<label for="SnS_classes_mce_type"><?php _e( 'Type:', 'scripts-n-styles' ) ?></label>
<select name="SnS_classes_mce_type" id="SnS_classes_mce_type" style="width: 80px;">
<option value="inline"><?php _ex( 'Inline', 'css type', 'scripts-n-styles' ) ?></option>
<option value="block"><?php _ex( 'Block', 'css type', 'scripts-n-styles' ) ?></option>
<option value="selector"><?php _ex( 'Selector:', 'css type', 'scripts-n-styles' ) ?></option>
</select>
</p>
<p class="sns-mce-element">
<label for="SnS_classes_mce_element"><?php _e( 'Element:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_element" id="SnS_classes_mce_element"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-classes">
<label for="SnS_classes_mce_classes"><?php _e( 'Classes:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_classes" id="SnS_classes_mce_classes"
value="" type="text" class="code" style="width: 80px;" />
</p>
<p class="sns-mce-wrapper" style="display: none;">
<label for="SnS_classes_mce_wrapper"><?php _e( 'Wrapper:', 'scripts-n-styles' ) ?></label>
<input name="SnS_classes_mce_wrapper" id="SnS_classes_mce_wrapper" type="checkbox" value="true" />
</p>
</div>
<div id="delete-mce-dropdown-names" style="display: none;">
<p id="instructions-mce-dropdown-names"><?php _e( 'Classes currently in the dropdown:', 'scripts-n-styles' ) ?></p>
</div>
</div>
</div>
<div class="wp-tab-panel" id="SnS_enqueue_scripts-tab">
<strong class="title">Include Scripts</strong>
<select name="SnS_enqueue_scripts[]" id="SnS_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
<?php
if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) {
foreach ( $registered_handles as $value ) { ?>
<option value="<?php echo esc_attr( $value ) ?>"<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) selected( $handle, $value ); ?>><?php echo esc_html( $value ) ?></option>
<?php }
} else {
foreach ( $registered_handles as $value ) { ?>
<option value="<?php echo esc_attr( $value ) ?>"><?php echo esc_html( $value ) ?></option>
<?php }
} ?>
</select>
<?php if ( ! empty( $scripts[ 'enqueue_scripts' ] ) && is_array( $scripts[ 'enqueue_scripts' ] ) ) { ?>
<p><?php _e( 'Currently Enqueued Scripts:', 'scripts-n-styles' ) ?>
<?php foreach ( $scripts[ 'enqueue_scripts' ] as $handle ) echo '<code>' . esc_html( $handle ) . '</code> '; ?>
</p>
<?php } ?>
<p><em><?php _e( 'The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).', 'scripts-n-styles' ) ?></em></p>
</div>
<div class="wp-tab-panel" id="SnS_shortcodes-tab">
<strong class="title">Shortcodes</strong>
<div id="sns-add-shortcode">
<?php
$meta_name = 'SnS_shortcodes';
$SnS = get_post_meta( $post->ID, '_SnS', true );
$SnS = is_array( $SnS ) ? $SnS: array();
$shortcodes = isset( $SnS['shortcodes'] ) ? $SnS[ 'shortcodes' ] : array();
?>
<label for="<?php echo $meta_name; ?>">Name: </label>
<input id="<?php echo $meta_name; ?>" name="<?php echo $meta_name . '[new][name]'; ?>" type="text" />
<textarea id="<?php echo $meta_name; ?>_new" class="codemirror htmlmixed" name="<?php echo $meta_name . '[new][value]'; ?>" rows="5" cols="40" style="width: 98%;"></textarea>
</div>
<div id="sns-shortcodes">
<h4>Existing Codes: </h4>
<div id="sns-shortcodes-wrap">
<?php if ( ! empty( $shortcodes ) ) { ?>
<?php foreach ( $shortcodes as $key => $value ) { ?>
<div class="sns-shortcode widget"><div class="inside">
<p>[hoops name="<?php echo $key ?>"]</p>
<textarea class="codemirror htmlmixed" data-sns-shortcode-key="<?php echo $key ?>" name="<?php echo $meta_name . '[existing][' . $key . ']'; ?>" rows="5" cols="40" style="width: 98%;"><?php echo esc_textarea( $value ); ?></textarea>
</div></div>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
<div class="wp-tab-panel" id="SnS_html-tab">
<p><em><?php _e( "<strong>HTML</strong> for the <code>head</code> element", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_html_in_head" class="title"><?php _e( '<strong>HTML</strong> (for the <code>head</code> element):', 'scripts-n-styles' ) ?> </label>
<div class="html">
<textarea class="codemirror html" name="SnS_html_in_head" id="SnS_html_in_head" rows="5" cols="40" style="width: 98%;"><?php echo isset( $html[ 'html_in_head' ] ) ? esc_textarea( $html[ 'html_in_head' ] ) : ''; ?></textarea>
</div>
<p>&nbsp;</p>
<p><em><?php _e( "<strong>HTML</strong> for the <code>bottom of the body</code> element", 'scripts-n-styles' ) ?> ...</em></p>
<label for="SnS_html_in_footer" class="title"><strong><?php _e( '<strong>HTML</strong> (for the <code>bottom of the body</code>):', 'scripts-n-styles' ) ?></strong>: </label>
<div class="html">
<textarea class="codemirror html" name="SnS_html_in_footer" id="SnS_html_in_footer" rows="5" cols="40" style="width: 98%;"><?php echo isset( $html[ 'html_in_footer' ] ) ? esc_textarea( $html[ 'html_in_footer' ] ) : ''; ?></textarea>
</div>
</div>
<?php
}
static function current_classes( $type, $post_id ) {
if ( 'body' == $type ) {
global $wp_query, $pagenow;
if ( 'post-new.php' == $pagenow ) {
echo join( ' ', get_body_class( '', $post_id ) );
echo ' ' . __( '(plus others once saved.)', 'scripts-n-styles' );
return;
}
// This returns more of what actually get used on the theme side.
$save = $wp_query;
$param = ( 'page' == get_post_type( $post_id ) ) ? 'page_id': 'p';
$wp_query = new WP_Query( "$param=$post_id" );
echo join( ' ', get_body_class( '', $post_id ) );
$wp_query = $save;
} else {
echo join( ' ', get_post_class( '', $post_id ) );
}
}
/**
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
* Enqueues the CSS for admin styling of the Meta Box.
*/
static function meta_box_styles() {
wp_enqueue_style( 'chosen' );
wp_enqueue_style( 'sns-meta-box' );
}
/**
* Admin Action: 'admin_print_styles' Action added during 'add_meta_boxes' (which restricts output to Edit Screens).
* Enqueues the JavaScript for the admin Meta Box.
*/
static function meta_box_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_script( 'sns-meta-box' );
wp_localize_script( 'sns-meta-box', 'codemirror_options', array( 'theme' => $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;
}
}

View File

@@ -0,0 +1,186 @@
<?php
/**
* SnS_Settings_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Settings_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_settings';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Settings' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : '';
wp_enqueue_style( 'sns-options' );
wp_enqueue_script( 'sns-settings-page' );
wp_localize_script( 'sns-settings-page', 'codemirror_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
wp_enqueue_style( 'sns-options' );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'settings',
__( 'Scripts n Styles Settings', 'scripts-n-styles' ),
array( __CLASS__, 'settings_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'metabox',
__( '<strong>Hide Metabox by default</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'metabox',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'yes',
'legend' => __( 'Hide Metabox by default', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This is overridable via Screen Options on each edit screen.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'menu_position',
__( '<strong>Menu Position</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'menu_position',
'setting' => 'SnS_options',
'choices' => array( 'menu', 'object', 'utility', 'tools.php', 'options-general.php', 'themes.php' ),
'default' => 'tools.php',
'legend' => __( 'Theme', 'scripts-n-styles' ),
'layout' => 'vertical',
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">Some people are fussy about where the menu goes, so I made an option.</span>', 'scripts-n-styles' ),
) );
add_settings_section(
'demo',
__( 'Code Mirror Demo', 'scripts-n-styles' ),
array( __CLASS__, 'demo_section' ),
SnS_Admin::MENU_SLUG );
add_settings_field(
'cm_theme',
__( '<strong>Theme</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'demo',
array(
'label_for' => 'cm_theme',
'setting' => 'SnS_options',
'choices' => Scripts_n_Styles::$cm_themes,
'default' => 'default',
'legend' => __( 'Theme', 'scripts-n-styles' ),
'layout' => 'horizontal',
'description' => '',
) );
add_settings_field(
'hoops_widget',
__( '<strong>Hoops Widgets</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'hoops_widget',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'no',
'legend' => __( 'Shortcode Widgets', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">This enables Hoops shortcodes to be used via a "Hoops" Text Widget.</span>', 'scripts-n-styles' )
) );
add_settings_field(
'delete_data_uninstall',
__( '<strong>Delete Data When Uninstalling</strong>: ', 'scripts-n-styles' ),
array( 'SnS_Form', 'radio' ),
SnS_Admin::MENU_SLUG,
'settings',
array(
'label_for' => 'delete_data_uninstall',
'setting' => 'SnS_options',
'choices' => array( 'yes', 'no' ),
'layout' => 'horizontal',
'default' => 'no',
'legend' => __( 'Delete Data When Uninstalling', 'scripts-n-styles' ),
'description' => __( '<span class="description" style="max-width: 500px; display: inline-block;">Should the plugin clean up after itself and delete all of its saved data.</span>', 'scripts-n-styles' )
) );
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function settings_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Control how and where Scripts n Styles menus and metaboxes appear. These options are here because sometimes users really care about this stuff. Feel free to adjust to your liking. :-)', 'scripts-n-styles' ) ?></p>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function demo_section() {
?>
<div style="max-width: 55em;">
<textarea id="codemirror_demo" name="code" style="min-width: 500px; width:97%;" rows="5" cols="40">
<?php echo esc_textarea( '<?php
function hello($who) {
return "Hello " . $who;
}
?>
<p>The program says <?= hello("World") ?>.</p>
<script>
alert("And here is some JS code"); // also colored
</script>' ); ?>
</textarea>
</div>
<?php
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* SnS_Theme_Page
*
* Allows WordPress admin users the ability to edit theme CSS
* and LESS directly in the admin via CodeMirror.
*
* On the `wp_enqueue_scripts` action, use `wp_enqueue_style( 'theme_style', get_stylesheet_uri() );` to add your style.css instead of inline.
* On the `after_setup_theme` action, use `add_theme_support( 'scripts-n-styles', array( '/less/variables.less', '/less/mixins.less' ) );` but use the appropriate file locations.
*
*/
class SnS_Theme_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_theme';
static $files = array();
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Theme' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "load-$hook_suffix", array( 'SnS_Form', 'take_action' ), 49 );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
$options = get_option( 'SnS_options' );
$cm_theme = isset( $options[ 'cm_theme' ] ) ? $options[ 'cm_theme' ] : 'default';
wp_enqueue_style( 'sns-options' );
wp_enqueue_style( 'codemirror-theme' );
wp_enqueue_script( 'sns-theme-page' );
wp_localize_script( 'sns-theme-page', '_SnS_options', array( 'theme' => $cm_theme ) );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
// added here to not effect other pages. Theme page requires JavaScript (less.js) or it doesn't make sense to save.
add_filter( 'sns_show_submit_button', '__return_false' );
register_setting(
SnS_Admin::OPTION_GROUP,
'SnS_options' );
add_settings_section(
'theme',
__( 'Scripts n Styles Theme Files', 'scripts-n-styles' ),
array( __CLASS__, 'less_fields' ),
SnS_Admin::MENU_SLUG );
}
static function less_fields() {
$files = array();
$support_files = get_theme_support( 'scripts-n-styles' );
if ( is_child_theme() )
$root = get_stylesheet_directory();
else
$root = get_template_directory();
foreach( $support_files[0] as $file ) {
if ( is_file( $root . $file ) )
$files[] = $root . $file;
}
$slug = get_stylesheet();
$options = get_option( 'SnS_options' );
// Stores data on a theme by theme basis.
$theme = isset( $options[ 'themes' ][ $slug ] ) ? $options[ 'themes' ][ $slug ] : array();
$stored = isset( $theme[ 'less' ] ) ? $theme[ 'less' ] : array(); // is an array of stored imported less file data
$compiled = isset( $theme[ 'compiled' ] ) ? $theme[ 'compiled' ] : ''; // the complete compiled down css
$slug = esc_attr( $slug );
$open_theme_panels = json_decode( get_user_option( 'sns_open_theme_panels', get_current_user_id() ), true );
?>
<div style="overflow: hidden">
<div id="less_area" style="width: 49%; float: left; overflow: hidden; margin-right: 2%;">
<?php
foreach ( $files as $file ) {
$name = basename( $file );
$raw = file_get_contents( $file );
if ( isset( $stored[ $name ] ) ) {
$source = $stored[ $name ];
$less = isset( $source ) ? $source : '';
$compiled = isset( $compiled ) ? $compiled : '';
} else {
$less = $raw;
$compiled = '';
}
$name = esc_attr( $name );
$lead_break = 0 == strpos( $less, PHP_EOL ) ? PHP_EOL : '';
if ( isset( $open_theme_panels[ $name ] ) )
$collapse = $open_theme_panels[ $name ] == 'yes' ? 'sns-collapsed ' : '';
else
$collapse = $less == $raw ? 'sns-collapsed ': '';
?>
<div class="sns-less-ide" style="overflow: hidden">
<div class="widget"><div class="<?php echo $collapse; ?>inside">
<span class="sns-collapsed-btn"></span>
<label style="margin-bottom: 0;"><?php echo $name ?></label>
<textarea data-file-name="<?php echo $name ?>" data-raw="<?php echo esc_attr( $raw ) ?>"
name="SnS_options[themes][<?php echo $slug ?>][less][<?php echo $name ?>]"
style="min-width: 250px; width:47%;"
class="code less" rows="5" cols="40"><?php echo $lead_break . esc_textarea( $less ) ?></textarea>
<div class="sns-ajax-wrap">
<a class="sns-ajax-load button" href="#">Load Source File</a>
<a class="sns-ajax-save button" href="#">Save All Changes</a>
<span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
<div class="single-status"><div class="updated settings-error below-h2"></div></div>
</div>
</div></div>
</div>
<?php
}
?>
</div>
<div id="css_area" class="sns-less-ide" style="width: 49%; float: left; overflow: hidden;">
<div id="compile_status" style="display: none" class="updated settings-error below-h2">
<p><span class="sns-ajax-loading"><span class="spinner" style="display: inline-block;"></span></span>
<span class="status-text">Keystokes detected. 1 second delay, then compiling...</span></p>
</div>
<div class="widget"><div class="sns-collapsed inside">
<span class="sns-collapsed-btn"></span>
<label style="margin-bottom: 0;">Preview Window</label>
<textarea
name="SnS_options[themes][<?php echo $slug ?>][compiled]"
style="min-width: 250px; width:47%;"
class="code css" rows="5" cols="40"><?php echo esc_textarea( $compiled ) ?></textarea>
</div></div>
<div id="compiled_error" class="error settings-error below-h2"></div>
</div>
<?php
}
/**
* Settings Page
* Outputs Description text for the Global Section.
*/
static function global_section() {
?>
<div style="max-width: 55em;">
<p><?php _e( 'Code entered here will be included in <em>every page (and post) of your site</em>, including the homepage and archives. The code will appear <strong>before</strong> Scripts and Styles registered individually.', 'scripts-n-styles' )?></p>
</div>
<?php
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* SnS_Settings_Page
*
* Allows WordPress admin users the ability to add custom CSS
* and JavaScript directly to individual Post, Pages or custom
* post types.
*/
class SnS_Usage_Page
{
/**
* Constants
*/
const MENU_SLUG = 'sns_usage';
/**
* Initializing method.
* @static
*/
static function init() {
$hook_suffix = add_submenu_page( SnS_Admin::$parent_slug, __( 'Scripts n Styles', 'scripts-n-styles' ), __( 'Usage', 'scripts-n-styles' ), 'unfiltered_html', self::MENU_SLUG, array( 'SnS_Form', 'page' ) );
add_action( "load-$hook_suffix", array( __CLASS__, 'admin_load' ) );
add_action( "load-$hook_suffix", array( 'SnS_Admin', 'help' ) );
add_action( "admin_print_styles-$hook_suffix", array( __CLASS__, 'admin_enqueue_scripts' ) );
// Make the page into a tab.
if ( SnS_Admin::MENU_SLUG != SnS_Admin::$parent_slug ) {
remove_submenu_page( SnS_Admin::$parent_slug, self::MENU_SLUG );
add_filter( 'parent_file', array( __CLASS__, 'parent_file') );
}
}
static function parent_file( $parent_file ) {
global $plugin_page, $submenu_file;
if ( self::MENU_SLUG == $plugin_page ) $submenu_file = SnS_Admin::MENU_SLUG;
return $parent_file;
}
static function admin_enqueue_scripts() {
wp_enqueue_style( 'sns-options' );
}
/**
* Settings Page
* Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
*/
static function admin_load() {
add_screen_option( 'per_page', array( 'label' => __( 'Per Page' ), 'default' => 20 ) );
add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 );
// hack for core limitation: see http://core.trac.wordpress.org/ticket/18954
set_screen_options();
add_settings_section(
'usage',
__( 'Scripts n Styles Usage', 'scripts-n-styles' ),
array( __CLASS__, 'usage_section' ),
SnS_Admin::MENU_SLUG );
}
static function set_screen_option( $false, $option, $value ) {
$screen_id = get_current_screen()->id;
$this_option = str_replace( '-', '_', "{$screen_id}_per_page" );
if ( $this_option != $option )
return false;
$value = (int) $value;
if ( $value < 1 || $value > 999 )
return false;
return $value;
}
/**
* Settings Page
* Outputs the Usage Section.
*/
static function usage_section() { ?>
<div style="max-width: 55em;">
<p><?php _e( 'The following table shows content that utilizes Scripts n Styles.', 'scripts-n-styles' ) ?></p>
</div>
<?php
require_once( 'class-sns-list-usage.php' );
$usageTable = new SnS_List_Usage();
$usageTable->prepare_items();
$usageTable->display();
}
}