Ejemplo n.º 1
0
function wp_css_admin()
{
    if ($_REQUEST['wp_css_clear_cache']) {
        if (wp_css_is_directory_writable(WP_CSS_CACHE_PATH)) {
            wp_css_delete();
        } else {
            $_REQUEST['wp_css_message'] = 'Unable to clear cache.';
        }
    }
    if ($_REQUEST['wp_css_edit_expiry']) {
        wp_css_modified_time(TRUE);
        update_option('wp_css_cache_time', $_REQUEST['wp_css_cache_time']);
    }
    if ($_REQUEST['wp_css_activation']) {
        wp_css_activation(true);
    }
    if ($_REQUEST['wp_css_within_posts_activation']) {
        wp_css_within_posts_activation(true);
    }
    $cache_time = wp_css_cache_time();
    ?>
	
	<style type="text/css" media="screen">
		fieldset {
			border: 1px solid #aaa;
			padding: 12px;
		}
		fieldset#activate-within-posts, fieldset#expiry-time, fieldset#clear-cache {
			margin-top: 12px;
		}
	</style>
	
	<?php 
    if ($_REQUEST['wp_css_message']) {
        ?>
		<div id="message" class="updated fade"><p><?php 
        echo $_REQUEST['wp_css_message'];
        ?>
</p></div>
	<?php 
    }
    ?>
	
	<div id="wp-css" class="wrap">
		<h2 style="margin: 8px 0; padding-top: 0">WP CSS v<?php 
    echo WP_CSS_VERSION;
    ?>
</h2>
		
		<p style="color:#1CCD00;">URLs must be relative to your current theme.<br />For example: <code>wp_css('file.css')</code> = <?php 
    echo TEMPLATEURL;
    ?>
/file.css</p>
		
		<fieldset id="activate"> 
		<legend>Activate</legend>
		<p>Turn the plugin on / off. wp_css() will still work but no caching or compressing is applied.</p>
		<?php 
    echo '<form name="wp_css_active" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    if (wp_css_activation() == 'on') {
        echo '<label for="wp_expiry_on"><input type="radio" id="wp_expiry_on" name="wp_css_activation" value="on" checked="checked" /> On</label>';
    } else {
        echo '<label for="wp_expiry_on"><input type="radio" id="wp_expiry_on" name="wp_css_activation" value="on" /> On</label>';
    }
    if (wp_css_activation() == 'off') {
        echo ' <label for="wp_expiry_off"><input type="radio" name="wp_css_activation" id="wp_expiry_off" value="off" checked="checked" /> Off</label><br />';
    } else {
        echo ' <label for="wp_expiry_off"><input type="radio" name="wp_css_activation" id="wp_expiry_off" value="off" /> Off</label><br />';
    }
    echo '<div class="submit"><input type="submit" value="Change activation &raquo;" name="wp_css_active" /></div>';
    echo '<input type="hidden" name="wp_css_message" value="Plugin activation changed.">';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    ?>
</fieldset>
		
		<fieldset id="activate-within-posts">
		<legend>Activate within posts</legend>
		<p>Allows you to add CSS files to specific posts/pages.</p>
		<?php 
    echo '<form name="wp_css_within_posts_activation" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    if (wp_css_within_posts_activation() == 'on') {
        echo '<label for="wp_css_within_posts_activation_on"><input type="radio" id="wp_css_within_posts_activation_on" name="wp_css_within_posts_activation" value="on" checked="checked" /> On</label>';
    } else {
        echo '<label for="wp_css_within_posts_activation_on"><input type="radio" id="wp_css_within_posts_activation_on" name="wp_css_within_posts_activation" value="on" /> On</label>';
    }
    if (wp_css_within_posts_activation() == 'off') {
        echo ' <label for="wp_css_within_posts_activation_off"><input type="radio" name="wp_css_within_posts_activation" id="wp_css_within_posts_activation_off" value="off" checked="checked" /> Off</label><br />';
    } else {
        echo ' <label for="wp_css_within_posts_activation_off"><input type="radio" name="wp_css_within_posts_activation" id="wp_css_within_posts_activation_off" value="off" /> Off</label><br />';
    }
    echo '<div class="submit"><input type="submit" value="Change activation &raquo;" name="wp_css_active" /></div>';
    echo '<input type="hidden" name="wp_css_message" value="Plugin within posts activation changed.">';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    ?>
</fieldset>
		
		<fieldset id="expiry-time"> 
		<legend>Expiry Time</legend>
		<p>Set the time for when the browser downloads a fresh copy of your CSS files.</p>
		<?php 
    echo '<form name="wp_css_edit_expiry" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    echo '<label for="wp_expiry">Expire time:</label> ';
    echo '<input type="text" size="6" name="wp_css_cache_time" value="' . $cache_time . '" /> seconds<br />';
    echo '<div class="submit"><input type="submit" value="Change expiration &raquo;" name="wp_css_edit_expiry" /></div>';
    echo '<input type="hidden" name="wp_css_message" value="Cache expiry changed">';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    ?>
</fieldset>
		
		<fieldset id="clear-cache"> 
		<legend>Clear cache</legend>

		<?php 
    if (!wp_css_is_directory_writable(WP_CSS_CACHE_PATH)) {
        ?>
			<p style="border: 1px solid #f00; padding: 2px; color: #f00;"><strong>Cache not available</strong><br/>The <code>wp-css</code> folder <strong>is not writable</strong>. Please change the plugin folder permissions to <code>777</code>.</p>
		<?php 
    }
    ?>

		<p>Clear your cache if you have updated your CSS files.</p>
		
		<?php 
    wp_css_cached_file_structure();
    ?>
		<?php 
    echo '<form name="wp_css_clear_cache" action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
    echo '<div class="submit"><input type="submit" value="Clear Cache" name="wp_css_clear_cache" /></div>';
    echo '<input type="hidden" name="wp_css_message" value="Cached cleared">';
    wp_nonce_field('wp-cache');
    echo "</form>\n";
    ?>
</fieldset>
	</div><?php 
}
Ejemplo n.º 2
0
			</div>
		<?php 
        }
        ?>
	
	<?php 
    }
}
function wp_css_files_for_post()
{
    global $post;
    $array = get_post_meta($post->ID, 'wp_css_file');
    if (!empty($array) && count($array) > 0) {
        $string = '';
        $string .= "<!-- WP CSS -->\n";
        foreach ($array as $value) {
            if (function_exists('wp_css')) {
                $string .= '<link rel="stylesheet" href="' . wp_css($value, false) . '" type="text/css" media="screen,projection" charset="utf-8" />' . "\n";
            } else {
                $string .= '<link rel="stylesheet" href="' . get_stylesheet_directory_uri() . '/' . $value . '" type="text/css" media="screen,projection" charset="utf-8" />' . "\n";
            }
        }
        $string .= "<!-- WP CSS closes -->\n";
        echo $string;
    }
}
if (wp_css_activation() == 'on' && wp_css_within_posts_activation() == 'on') {
    add_action('wp_head', 'wp_css_files_for_post');
}
add_action('edit_form_advanced', 'wp_css_files_display');
add_action('edit_page_form', 'wp_css_files_display');