Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lionhurt
Copy link

@lionhurt lionhurt commented Oct 13, 2016

Hi,

i follow this tutorial for awesome Justin Tadlock so many thanks to him : http://justintadlock.com/archives/2015/05/26/multiple-checkbox-customizer-control

Intro:
i work on new wordpress theme and i moved from redux framework to kirki. the problem is redux has a lot of useful fields i miss it in kirki like background, link color (color, :hover, :active), border and spacing field that support postMesage.

Technically to build all of this fields you need to build control with multiple inputs and save all of this inputs in a associative array so from this concept i start build the background control.

My prefix: mom_

Files:
background-control.php - gist
background-control.js - gist
background-control-preview.js - gist

Add field:

my_custom_options::add_field( 'mom_option', array(
  'type'        => 'mom_background',
  'sanitize_callback' => 'mom_background_field_sanitize',
  'settings'    => 'header_background',
  'label'       => __('Header background', MOM_TEXTDOMAIN),
  'section'     => 'main_header',
  'transport'   => 'postMessage',
));

Get field value:

print_r(get_theme_mod('header_backgroun'))
array('color' => '#fff', 'image' => 'http://image_url.png', 'repeat' => 'no-repeat'...)

Results:
background control in action

How it works:

i create inputs with simple HTML code. collect the information of each input with name attribute to build a valid json string to save it in value-holder input (hidden input).

then sanitize the json string with this function to build the associative array to save in wordpress database as theme mod.

What i miss:

  • don't test this field with defaults and reset button
  • I am sure there is a better way to doing this
  • not tested with repeater

Conclusion:

This is my first pull request and i don't know what i do so i explain everything in this comment, i hope that be helped

@Rayken
Copy link

Rayken commented Oct 13, 2016

Maybe we can hide the dropdowns unless an image has been selected/uploaded?

@lionhurt
Copy link
Author

@Quaked good suggestion 👍

@aristath
Copy link
Contributor

@lionhurt I just checked and there are no commits in your pull-request other than some old commits that I made 5-6 months ago.

@lionhurt
Copy link
Author

lionhurt commented Oct 13, 2016

@aristath

i explain everything in my comment and i leave this note

This is my first pull request and i don't know what i do so i explain everything in this comment, i hope that be helped

@Anydog
Copy link

Anydog commented Nov 7, 2016

@aristath , @lionhurt : any chance to include "background" type ( image, color, background-repeat, background-position, background-size, attachment ... ) into Kirki ?
That would be really awesome ...

@robbisy
Copy link

robbisy commented Dec 3, 2016

@lionhurt Hi I have one question, in the background-control.php you enqueue the mom-backgrodund.js on line 10. What is this file ?
Thanks

@lionhurt
Copy link
Author

lionhurt commented Mar 5, 2017

@Anydog sorry for late, i already use it in my new project i don't know how to make it as kirki control so i made it as custom control and share my idea here.

@robbisy sorry for late, i use this file to convert all input values to json and save it on php array

@aristath
Copy link
Contributor

We now have a background control.
There are still a few issues to resolve but they are minor, nothing serious.
Merged in #1283 so closing this one.

@aristath aristath closed this Mar 28, 2017
@aristath aristath deleted the feature/background-rebuild branch March 28, 2017 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants