Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter robinheymans

    (@robinheymans)

    Hi @gripgrip

    Thanks for the reply. I’ve extended your script: this adds every WPCode snippet of type CSS with the tag “admin” to the head of the admin section.

    add_action('admin_head', 'wpcode_admin_css');
    
    function wpcode_admin_css() {
    	global $wpdb;
    	
    	$stylesheets = $wpdb->get_results("SELECT p.post_content, p.post_title FROM wp_posts p
    			JOIN wp_term_relationships tr_category ON tr_category.object_id = p.id
    			JOIN wp_term_taxonomy tt_category ON tr_category.term_taxonomy_id = tt_category.term_taxonomy_id
    			JOIN wp_terms t_category ON tt_category.term_id = t_category.term_id
    			JOIN wp_term_relationships tr_tag ON tr_tag.object_id = p.id
    			JOIN wp_term_taxonomy tt_tag ON tr_tag.term_taxonomy_id = tt_tag.term_taxonomy_id
    			JOIN wp_terms t_tag ON tt_tag.term_id = t_tag.term_id
    		 WHERE p.post_status != 'trash' AND p.post_type = 'wpcode'
    			AND tt_category.taxonomy = 'wpcode_type' AND t_category.name = 'css'
    			AND tt_tag.taxonomy = 'wpcode_tags' AND t_tag.name = 'admin'");
    	
    	$styleblock = "<style>";
    	foreach ($stylesheets as $stylesheet) {
    		$styleblock .= "/* " . $stylesheet->post_title . " */";
    		$styleblock .= $stylesheet->post_content;
    	}
    	$styleblock .= "</style>";
    	
    	echo $styleblock;
    }

Viewing 1 replies (of 1 total)