WP Theme Customizer - options order - wordpress

i've got a problem with theme customizer. My code is:
function candyfloss_theme_customizer( $wp_customize ) {
class Heading extends WP_Customize_Control {
public $type = 'heading';
public function render_content() {
?>
<label>
<span class="customize-control-title" style="border-bottom: 1px dashed #666;"><strong><?php echo esc_html( $this->label ); ?></strong></span>
</label>
<?php
}
}
$wp_customize->add_setting('products_heading', array(
'default',
) );
$wp_customize->add_control(new Heading ($wp_customize, 'products_heading', array(
'label' => __('Home - products section'),
'type' => 'heading',
'section' => 'home',
) ) );
$wp_customize->add_setting('candyfloss_product_first', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_first', array(
'label' => __('First product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
$wp_customize->add_setting('candyfloss_product_second', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_second', array(
'label' => __('Second product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
$wp_customize->add_setting('candyfloss_product_third', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_third', array(
'label' => __('Third product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
};
add_action( 'customize_register', 'candyfloss_theme_customizer', 11 );
And the problem is in order of this. At admin panel view is
second option,
first option,
heading,
third option,
Can anyone know, what I'm doing wrong? Could You help me? I'll be thankful

I found the answer. Wordpress gives a random priority to controls. To solve it we just need to add priority number to each control.
eg.:
$wp_customize->add_control(new Heading ($wp_customize, 'products_heading', array(
'label' => __('Home - products section'),
'type' => 'heading',
'section' => 'home',
'priority' => 2,
) ) );

Related

how can i add post-categories list in elementor custom widget

My control code is
i want to create control in elementor which shows all post categories. please help me how can i achieve this...
enter image description here
$this->add_control(
'show_elements',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => [
$category,
],
]
); ```
You can use WP get_categories() to get all categories. check below code.
$options = array();
$args = array(
'hide_empty' => false,
);
$categories = get_categories($args);
foreach ( $categories as $key => $category ) {
$options[$category->term_id] = $category->name;
}
$this->add_control(
'show_elements',
[
'label' => __( 'Post Categoris', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT2,
'multiple' => true,
'options' => $options,
]
);

How can I render Nested elements on Visual Composer (WPBakery) for wordpress?

I'm trying to do some custom elements for Visual Composer plugin (WP-Bakery) for wordpress.
I have no problem with simple custom elements, but I'm trying to do some nested elements (a parent containing some child elements). I have no problems creating child elements, and if I create them alome, they are shown on wordpress, but when I try to create parent element, I can see setting elements without problem, but it's no rendered.
I think the problem is the render function (html) on parent class, but I can't get solve it.
PARENT CLASS
<?php
class vcInfoCardContainer extends WPBakeryShortCodesContainer {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'vc_infocardcontainer_mapping' ) );
add_shortcode( 'vc_infocard', array( $this, 'vc_infocardcontainer_html' ) );
}
// Element Mapping
public function vc_infocardcontainer_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
// Map the block with vc_map()
vc_map(
array(
'name' => __('VC Info Card Container', 'ex5_vc_elements'),
'base' => 'vc_infocardcontainer',
'description' => __('Info Card Container for VC', 'ex5_vc_elements'),
'category' => __('Ex5 Elements', 'ex5_vc_elements'),
'icon' => get_template_directory_uri().'/assets/img/vc-icon.png',
'as_parent' => array('only' => 'vc_infocard'),
'is_container' => true,
'js_view' => 'VcColumnView',
'params' => array(
array(
'type' => 'textfield',
'heading' => __('Button text','ex5_vc_elements'),
'param_name' => 'button_text',
'description' => __('Default is \'Más info\'', 'ex5_vc_elements'),
'group' => 'Button',
)
),
));
}
//render
public function vc_infocard_html( $atts, $content = null ) {
// Params extraction
extract(
shortcode_atts(
array(
),
$atts
)
);
$html = '<div class="ex5-vc-info-card-container">' . do_shortcode($content) . '</div>';
return $html;
}
}
new vcInfoCardContainer();
CHILD CLASS
<?php
class vcInfoCard extends WPBakeryShortCode {
// Element Init
function __construct() {
add_action( 'init', array( $this, 'vc_infocard_mapping' ) );
add_shortcode( 'vc_infocard', array( $this, 'vc_infocard_html' ) );
}
// Element Mapping
public function vc_infocard_mapping() {
// Stop all if VC is not enabled
if ( !defined( 'WPB_VC_VERSION' ) ) {
return;
}
// Map the block with vc_map()
vc_map(
array(
'name' => __('VC Info Card', 'ex5_vc_elements'),
'base' => 'vc_infocard',
'description' => __('Info Card for VC', 'ex5_vc_elements'),
'category' => __('Ex5 Elements', 'ex5_vc_elements'),
'icon' => get_template_directory_uri().'/assets/img/vc-icon.png',
'as_child' => array('only' => 'vc_infocardcontainer'),
'params' => array(
array(
'type' => 'attach_image',
'heading' => __( 'Main image', 'ex5_vc_elements' ),
'param_name' => 'image',
'group' => 'Images',
),
array(
'type' => 'attach_image',
'heading' => __( 'Icon', 'ex5_vc_elements' ),
'param_name' => 'icon',
'group' => 'Images',
),
array(
'type' => 'colorpicker',
'heading' => __( 'Icon background color', 'ex5_vc_elements' ),
'param_name' => 'icon_background_color',
'value' => __( '#000000', 'ex5_vc_elements' ),
'group' => 'Images',
),
array(
'type' => 'textfield',
'heading' => __('Title','ex5_vc_elements'),
'param_name' => 'Title',
'group' => 'Texts',
),
array(
'type' => 'textfield',
'heading' => __( 'Text', 'ex5_vc_elements' ),
'param_name' => 'text',
'group' => 'Texts',
),
array(
'type' => 'checkbox',
'class' => 'one-third',
'heading' => __( 'Show link button', 'ex5_vc_elements' ),
'param_name' => 'show_button',
'value' => 'show',
'description' => __( 'Indicates if link button is shown)', 'ex5_vc_elements' ),
'group' => 'Button',
),
array(
'type' => 'textfield',
'heading' => __('Button text','ex5_vc_elements'),
'param_name' => 'button_text',
'description' => __('Default is \'Más info\'', 'ex5_vc_elements'),
'group' => 'Button',
),
array(
'type' => 'vc_link',
'heading' => __( 'Button link', 'ex5_vc_elements' ),
'param_name' => 'button_link',
'group' => 'Button',
),
),
));
}
//render
public function vc_infocard_html( $atts ) {
// Params extraction
extract(
shortcode_atts(
array(
'image' => '',
'icon' => '',
'icon_background_color' => '#000000',
'title' => '',
'text' => '',
'show_button' => '',
'button_text' => 'Más info',
'button_link' => '',
),
$atts
)
);
if (empty($button_text)) $button_text = __( 'Más info', 'ex5_vc_elements' );
if ($show_button === 'true') {
if (!empty($button_link)) {
$button = '<div class="ex5-vcic-button">
<a href="'. $button_link .'" target="_self" class="ex5-vcic-link" title="' . $button_text . '">
<span class="ex5-vcic-button-text">' . $button_text . '</span>
</a>
</div>';
} else {
$button = '<div class="ex5-vcic-button">
<span class="ex5-vcic-button-text">' . $button_text . '</span>
</div>';
}
} else {
$button = '';
}
$image = wp_get_attachment_image_src($image);
$icon = wp_get_attachment_image_src($icon);
//vc_build_link(
$html = '
<div class="ex5-vc-infocard">
<div class="ex5-vcic-content">
<div class="ex5-vcic-image">
<span>
<img src="' . $image[0] . '" title="history_inner_14" alt="http://oxigeno.">
</span>
</div>
<div class="ex5-vcic-icon" style="background-color: ' . $icon_background_color . '">
<img src="' . $icon[0] . '" />
</div>
<header class="ex5-vcic-headline">
<h3>' . $title . '</h3>
</header>
<div class="ex5-vcic-text">
<p>' . $text . '</p>
</div>' .
$button
. '</div>
</div>';
return $html;
}
}
new vcInfoCard();
There was a problem with the name of container shortcode. It had to be
add_shortcode( 'vc_infocardcontainer', array( $this, 'vc_infocardcontainer_html' ) );
But there's still a problem. I have a problem with do_shortcode_tag function
Attempting to parse a shortcode without a valid callback
Anybody knows how can I solve it?
I had solved it. The shortcode call was wrong because it had the wrong function name too.
public function vc_infocard_html( $atts, $content = null ) {
must be
public function vc_infocardcontainer_html( $atts, $content = null ) {

How to add a custom field in woocommerce product category using meta box plugin

I just want to add a custom field in the product category page in admin using the metabox plugin https://metabox.io/
This is in woocommerce and this is what I have
add_filter( 'rwmb_meta_boxes', 'product_register_meta_boxes' );
function product_register_meta_boxes( $meta_boxes )
{
$prefix = 'product_';
$meta_boxes[] = array(
'id' => 'product_cat_keywords_search',
'title' => __( 'Searchable keywords', 'your-prefix' ),
'post_types' => array( 'product'),
'taxonomy' => array( 'product_cat'),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'name' => __( 'Product Category Keywords', 'your-prefix' ),
'id' => "{$prefix}pcat_keywords",
'desc' => __( 'Category Keywords', 'your-prefix' ),
'type' => 'text',
'std' => __( '', 'your-prefix' ),
'clone' => true,
'clone-group' => 'my-clone-group2',
),
)
);
return $meta_boxes;
}
This code only appears in product page and not in product category page.
I need to use metabox since I will be using the clone feature, thanks

Retrieving data from additional OptionTree pages

Adding OptionTree pages is simple with the code below, but does anyone know how to retrieve the stored data?
/**
* Hook to register admin pages
*/
add_action( 'init', 'register_options_pages' );
/**
* Registers all the required admin pages.
*/
function register_options_pages() {
// Only execute in admin & if OT is installed
if ( is_admin() && function_exists( 'ot_register_settings' ) ) {
// Register the pages
ot_register_settings(
array(
array(
'id' => 'custom_options',
'pages' => array(
array(
'id' => 'test_page',
'parent_slug' => 'options-general.php',
'page_title' => 'Test Page',
'menu_title' => 'Test Page',
'capability' => 'edit_theme_options',
'menu_slug' => 'test-page',
'icon_url' => null,
'position' => null,
'updated_message' => 'Test Page updated.',
'reset_message' => 'Test Page reset.',
'button_text' => 'Save Changes',
'show_buttons' => true,
'screen_icon' => 'options-general',
'contextual_help' => null,
'sections' => array(
array(
'id' => 'test_section',
'title' => __( 'Test Section', 'motif-core' )
)
),
'settings' => array(
array(
'id' => 'test_section_input',
'label' => 'Test Input',
'desc' => 'Pretty freaking awesome!',
'std' => '',
'type' => 'text',
'section' => 'test_section',
'class' => ''
)
)
)
)
)
)
);
I tried this $my_plugin_options = get_option('custom_options'); but it only shows the word 'array' on the front end?
This is how to retrieve the stored data:
$my_plugin_options = get_option('custom_options');
echo $my_plugin_options['test_section_input'];

Fatal error when adding setting to customizer in wordpress

I am trying to add an extra setting in the Wordpress customizer. Can you add extra settings in the site title & tagline section or do you have to create your own section? This is the code I have so far in my functions.php file:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );
If I try to go to the customize theme page in the admin area though I get the following error:
Fatal error: Call to a member function check_capabilities() on a non-object in C:\xampp\htdocs\one-gas\wp-includes\class-wp-customize-control.php on line 161
Yes, you can add to the title and tagline section. Try using this code:
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
)
);
Read more about the Theme Customization API at the WordPress Codex.
I fixed it in the end it's because I had to define a setting first so this is the working code:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_setting('subtagline', array(
'default' => 0,
'type' => 'option'
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'subtagline',
array(
'label' => __( 'Sub Tagline', 'One Gas' ),
'section' => 'title_tagline',
'settings' => 'subtagline',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );

Resources