Skip to content

Commit

Permalink
add new shortcode and instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Houke de Kwant committed Jun 7, 2017
1 parent d9a5b4f commit 54591e1
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 6 deletions.
4 changes: 4 additions & 0 deletions assets/css/cpg-frontend-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
flex-wrap: wrap;
}

.cpg__palette-holder .cpg__palette-list + .cpg__palette-list{
margin-top: 20px;
}

.cpg__palette-holder .cpg__palette-list:before,
.cpg__palette-holder .cpg__palette-list:after{
content: "";
Expand Down
4 changes: 2 additions & 2 deletions color-palette-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Color Palette Generator
Plugin URI: https://github.com/houke/color-palette-generator
Description: Generates color palettes for your media uploads (jpg, png, gif), shows them on your website and allows you to filter images per color
Version: 1.3
Version: 1.4
Author: Houke de Kwant
Author URI: https://github.com/houke/
Text Domain: cpg
Expand All @@ -16,7 +16,7 @@

//Constants
$prefix = 'CPG_';
$version = '1.3';
$version = '1.4';

//Define variables
$cpg_constants = array(
Expand Down
84 changes: 82 additions & 2 deletions inc/cpg-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function cpg_settings_page(){
</div>

<div id="cpg-stats" class="postbox cpg-postbox">
<h2 class="hndle cpg-hndle"><?php _e( 'Shortcode', 'cpg' ); ?></h2>
<h2 class="hndle cpg-hndle"><?php _e( 'Shortcodes', 'cpg' ); ?></h2>
<div class="inside cpg__inside cpg__inside--btn">
<p><?php _e('To show individual images within a post, use the following shortcode (or enter the required options while adding images)', 'cpg'); ?>: <pre><code>[colorpalette attachment="56" dominant="false" colors="3" size="thumbnail"]</code></pre></p>
<ul>
Expand All @@ -321,6 +321,13 @@ function cpg_settings_page(){
<li><?php _e('colors: the number of colors you want to show', 'cpg'); ?></li>
<li><?php _e('size: the format of the artwork you want to show (thumbnail, medium and large are WordPress defaults)', 'cpg'); ?></li>
</ul>
<br/><br/>
<p><?php _e('To show generated palettes, without the images use the following shortcode', 'cpg'); ?>: <pre><code>[colorpalettes attachments="21, 28, 32" colors="5"]</code></pre> <?php _e('To show all palettes, simply use', 'cpg'); ?> <pre><code>[colorpalettes]</code></pre></p>
<ul>
<li><?php _e('attachments: the ids of the images of which you want to show the palettes. Leave empty to show the palettes of all images', 'cpg'); ?></li>
<li><?php _e('colors: the number of colors you want to show, default to the number of colors you\'ve defined above', 'cpg'); ?></li>
<li><?php _e('total: the maximum number of palettes you want to show, by default, all palettes are shown', 'cpg'); ?></li>
</ul>
</div>
</div>

Expand Down Expand Up @@ -502,13 +509,86 @@ function cpg_colorpalette_shortcode( $atts, $content = "" ) {
}
$content .= '</div>';
}else{
$content = "<p>Attachment doesn't exist or isn't an image</p>";
$content = "<p>".__( "Attachment doesn't exist or isn't an image", "cpg"). "</p>";
}

return $content;
}
add_shortcode( 'colorpalette', 'cpg_colorpalette_shortcode' );

function cpg_colorpalettes_shortcode( $atts ) {

$options = get_option('cpg_options');
$colors = isset( $options['colors'] ) ? $options['colors'] : 10;
$content = '<div class="cpg__palette-holder">';

$atts = shortcode_atts( array(
'attachments' => '',
'colors' => $colors,
'orderby' => 'post_date',
'order' => 'DESC',
'total' => -1
), $atts, 'colorpalettes' );

$attachments = $atts['attachments'];
$colors = $atts['colors'];
$orderby = $atts['orderby'];
$order = $atts['order'];
$ppp = $atts['total'];

$terms = get_terms( array(
'taxonomy' => 'cpg_dominant_color'
) );

$args = array(
'post_type' => 'attachment',
'orderby' => $orderby,
'order' => $order,
'fields' => 'ids',
'posts_per_page' => $ppp,
'tax_query' => array(
array(
'taxonomy' => 'cpg_dominant_color',
'field' => 'slug',
'terms' => wp_list_pluck( $terms, 'slug' )
)
)
);

if( $attachments != '' ){
$args['post__in'] = explode(',', $attachments);
}

$attachments = get_posts( $args );

if( $attachments ){
wp_enqueue_style( 'cpg-frontend-styles-css' );
foreach ($attachments as $attachment) {
$content .= '<ul class="cpg__palette-list">';
$palette = get_the_terms( $attachment, 'cpg_palette' );
shuffle( $palette );
foreach ( $palette as $i => $color ) {
if ( $i == $atts['colors'] ){
break;
}

if( is_object( $color ) ){
$color = $color->name;
}
$content .= '<li class="cpg__palette-item cpg__color-item" style="background-color:'.$color.';" data-title="'.$color.'"></li>';
}
$content .= '</ul>';
}
}else{
$content .= '<p>' . __( "You don't have any palettes. Start generating them in your media library.", "cpg" ) . '</p>';
}

$content .= '</div>';

return $content;
}
add_shortcode( 'colorpalettes', 'cpg_colorpalettes_shortcode' );

//Register taxonomies on install
function cpg_install(){
cpg_register_default_settings();
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Manual Installation:
3. When inserting images into your content, new options will be available
4. Add a widget to your sidebar
5. The palette in use
6. A list of generated palettes

## Todo ##

Expand All @@ -61,6 +62,10 @@ Manual Installation:

## Changelog ##

### 1.4 ###

* Added new shortcode to show all generate palettes (without the images)

### 1.3 ###

* Validate, sanetize & escape
Expand Down
9 changes: 7 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Contributors: houkedekwant
Donate link: https://github.com/houke/
Tags: color palette, color palette generator, image, images, color, colour, colour palette, palette, attachments
Requires at least: 4.0
Tested up to: 4.7.2
Tested up to: 4.8.0
Stable tag: trunk
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: cpg
Domain Path: /languages
Version: 1.3
Version: 1.4

This plugin generates color palettes for your WordPress images and appends them to your content.

Expand Down Expand Up @@ -63,11 +63,16 @@ Manual Installation:
3. When inserting images into your content, new options will be available
4. Add a widget to your sidebar
5. The palette in use
6. A list of generated palettes

== Upgrade Notice ==

== Changelog ==

= 1.4 =

* Added new shortcode to show all generate palettes (without the images)

= 1.3 =

* Validate, sanetize & escape
Expand Down
Binary file added screenshots/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 54591e1

Please sign in to comment.