Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pg_override_color_picker_swatches() {
- if ( is_page( [ CREATE_BANNER_PAGE, EDIT_BANNER_PAGE ] ) ) {
- $colors = [
- '#000000',
- '#ffffff',
- '#DD3333', // red
- '#DD9933', // orange
- // '#EEEE22', // yellow
- // '#81D742', // green
- // '#1E73BE', // blue
- // '#8224E3', // purple
- ];
- $primary_color = false;
- $secondary_color = false;
- if ( isset( $_GET[ 'id' ] ) ) {
- $post_id = $_GET[ 'id' ];
- $fields = get_field_objects( $post_id );
- $primary_color = ! empty( $fields[ 'pg_primary_color' ][ 'value' ] ) ? $fields[ 'pg_primary_color' ][ 'value' ] : $primary_color;
- $secondary_color = ! empty( $fields[ 'pg_secondary_color' ][ 'value' ] ) ? $fields[ 'pg_secondary_color' ][ 'value' ] : $secondary_color;
- }
- if ( false != $secondary_color ) {
- array_unshift( $colors, $secondary_color );
- array_pop( $colors );
- }
- if ( false != $primary_color ) {
- array_unshift( $colors, $primary_color );
- array_pop( $colors );
- }
- $colors = "'" . implode("','", $colors ) . "'";
- // @TODO: maybe don't apply to primary/secondary color
- ?>
- <script type="text/javascript">
- (function($) {
- acf.add_filter('color_picker_args', function( args, $field ) {
- args.palettes = [ <?php echo $colors; ?> ];
- return args;
- });
- })(jQuery);
- </script>
- <?php
- }
- }
- add_action( 'acf/input/admin_footer', 'pg_override_color_picker_swatches' );
Add Comment
Please, Sign In to add comment