Preloader Switcher Redux Wordpress Framework - php

I need to make a switch for the preloader. I created the corresponding item in the config.php:
array(
'id' => 'page_load_transition',
'type' => 'switch',
'title' => __( 'Page Load Transition', 'redux-framework-demo' ),
'desc' => __( 'Page load transition animation.', 'redux-framework-demo' ),
'default' => 1,
'on' => 'Enable',
'off' => 'Disable'
),
Also I have a div with a preloader html code:
<div id="preloader"><span id="spinner"></span></div>
and jQuery code:
var $preloader = $('#preloader').delay(700).fadeOut('slow').find('#spinner').fadeOut('slow'),
Now I need to make a switch, but all my attempts did not work.
I need to learn how to implement this correctly.
Thank you

Solved:
if(esc_html($varuna_option['page_load_transition'] == '1')) {
echo '<div id="preloader"><span id="spinner"></span></div>';
}
Everything turned out to be easier.

Related

Check value from Gravity Forms API

I am creating a custom Gravity Forms add-on and it appears to work so far. The settings are showing and saving as expected.
Here's what I have:
public function plugin_settings_fields() {
return array(
array(
'title' => esc_html__( 'Animal Types', 'animaltypes' ),
'fields' => array(
array(
'name' => 'gravity_forms_animal_types',
'type' => 'checkbox',
'label' => esc_html__( 'Animal Types', 'animaltypes' ),
'choices' => array(
array(
'label' => esc_html__( 'Cat', 'animaltypes' ),
'name' => 'option_cat',
'default_value' => 0,
),
array(
'label' => esc_html__( 'Dogs', 'animaltypes' ),
'name' => 'option_dog',
'default_value' => 0,
)
)
),
)
)
);
}
But what I can't figure out is how to check, for example, if option_cat has been set so that I can then run a custom function if it is.
So essentially (and I know the below code is not correct) something like this:
if(option_cat == true) {
my_cat_function();
}
In gravity forms when you create a new addon you provide a slug for that addon. Gravity forms save that settings with the help of that slug.
So if you want to get that settings you can use below code.
$settings = get_option('gravityformsaddon_slugname__settings');
$option = rgar( $settings, 'gravity_forms_animal_types' );
In options you can get selection of your settings, and if you want to one selection at a time you must use radio button instead of checkbox.
It was quite simple after all.
$options = get_option('gravityformsaddon_animaltypes_settings');
$cat = $options['option_cat'];
if($cat) {
my_cat_function();
}

CMB2 option-page parameter

CMB2 has an option to use as an option page.
I'm looking in the example files, and on the wiki page but even copying and pasting the example on the files it not work.
I'm probably missing something, but I can't find what it is, I already spent two days trying to make this work.
Following the wiki and the example I modified to this code
add_action( 'cmb2_admin_init', 'yourprefix_register_theme_options_metabox' );
function yourprefix_register_theme_options_metabox() {
$option_key = 'wherever';
$cmb = new_cmb2_box( array(
'id'=> $option_key . '_theme_options-page',
'object_types' => array( 'options-page' ),
'hookup' => false,
'menu_title' => 'Site Options',
'parent_slug' => 'tools.php',
'capability' => 'manage_options'
) );
$cmb->add_field( array(
'name' => 'Site Background Color',
'desc' => 'field description',
'id' => 'bg_color',
'type' => 'colorpicker',
'default' => '#ffffff'
) );
}
Any leads on why it's not working?
Currently the documentation for CMB2's options page capabilities just takes you to their Snippet Library which isn't 100% straightforward, so hopefully I can help clarify how to use these functions properly.
First, the metaboxes you register in cmb2_admin_init can generate an entire admin page. Take this code example straight from the snippet library for instance:
add_action('cmb2_admin_init', 'register_my_admin_page');
function register_my_admin_page() {
/**
* Registers options page menu item and form.
*/
$cmb_options = new_cmb2_box( array(
'id' => 'myprefix_option_metabox',
'title' => esc_html__( 'Site Options', 'myprefix' ),
'object_types' => array( 'options-page' ),
/*
* The following parameters are specific to the options-page box
* Several of these parameters are passed along to add_menu_page()/add_submenu_page().
*/
'option_key' => 'myprefix_options', // The option key and admin menu page slug.
// 'icon_url' => 'dashicons-palmtree', // Menu icon. Only applicable if 'parent_slug' is left empty.
// 'menu_title' => esc_html__( 'Options', 'myprefix' ), // Falls back to 'title' (above).
// 'parent_slug' => 'themes.php', // Make options page a submenu item of the themes menu.
// 'capability' => 'manage_options', // Cap required to view options-page.
// 'position' => 1, // Menu position. Only applicable if 'parent_slug' is left empty.
// 'admin_menu_hook' => 'network_admin_menu', // 'network_admin_menu' to add network-level options page.
// 'display_cb' => false, // Override the options-page form output (CMB2_Hookup::options_page_output()).
// 'save_button' => esc_html__( 'Save Theme Options', 'myprefix' ), // The text for the options-page save button. Defaults to 'Save'.
) );
/*
* Options fields ids only need
* to be unique within this box.
* Prefix is not needed.
*/
$cmb_options->add_field( array(
'name' => __( 'Test Text', 'myprefix' ),
'desc' => __( 'field description (optional)', 'myprefix' ),
'id' => 'test_text',
'type' => 'text',
'default' => 'Default Text',
) );
$cmb_options->add_field( array(
'name' => __( 'Test Color Picker', 'myprefix' ),
'desc' => __( 'field description (optional)', 'myprefix' ),
'id' => 'test_colorpicker',
'type' => 'colorpicker',
'default' => '#bada55',
) );
}
This code snippet will generate a top-level admin page named "Site Options" with two fields: a text field and a color-picker field, complete with a title, form fields, submit button, etc. You can configure how the page is displayed to the user using the commented out settings on the new_cmb2_box function.
When the form is saved, it will save the meta box and its fields to the site option myprefix_options. So if you call the function get_option('myprefix_options'), it will return the following array:
array(
'myprefix_option_metabox' => array(
'test_text' => '' // value of the Test Text field,
'test_colorpicker' => '' // value of the Test Color Picker field
)
)
I hope that helps clarify things a bit.

Wordpress select setting in customizer not outputing proper code

I have a customizer section inside my wordpress theme. I made a setting and a control for an icon. I want my user to be able to choose what icon he wants. I implemented the icomoon icon font with classes like icon-home.
I made a setting and a control for that icon like this:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
'type' => 'option',
)
);
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'icon1' => 'mobile',
'icon2' => 'home',
),
)
);
and in html/php:
<span class="service-icon icon-<?php echo get_theme_mod('service1_icon', 'icon1'); ?>"></span>
But when in my browser I see the output like this:
<span class="service-icon icon-icon1"></span>
instead of:
<span class="service-icon icon-mobile"></span>
I was trying to fix it and did some stuff that were illogical to me and I fixed it.
First, I removed the type from the setting:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
)
);
Then I renamed icon1, icon2... to the actual name of the icon:
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'mobile' => 'mobile',
'home' => 'home',
),
)
);

Yii Booster popover over text rather than button

Yii booster documentation shows how to make a popover over a button. I want to create one over an anchor element rather than a button. Essentially I want to combine the popover with Yii's tooltip. Does anyone know how to do this?
This is the code for the pop-over:
$this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Top popover',
'type' => 'primary',
'htmlOptions' => array(
'data-title' => 'A Title',
'data-placement' => 'top',
'data-content' => "And here's some amazing content. It's very engaging. right?",
'data-toggle' => 'popover'
),
));
If there was a way of altering this to not render a button, but just an anchor the problem would be solved, but I can't find anything in the code that I can use to do this.
Update
Following Sergey's answer, here's what I've put:
echo CHtml::Link("$detail->text", null,
array(
'rel' => 'popover',
'data-trigger' => "hover",
'data-title' => "$header",
'data-content' => "$body"
));
This is close to what I need, but for some reason the hove doesn't work, only the click and also only the content get's displayed not the title.
You can use CHtml:
<?php echo CHtml::Link('<i class="icon-info-sign"></i>', null, [
'rel' => 'popover',
'data-trigger' => 'hover',
'data-title' => 'Your title',
'data-content' => 'Your content',
])?>
Update:
For Bootstrap 2.3.2 :
<?php Yii::app()->clientScript->registerScript("", "$('.ipopover').popover();", CClientScript::POS_READY) ?>
<?php echo CHtml::Link('<i class="icon-info-sign"></i>', null, array(
'class' => 'ipopover',
'data-trigger' => 'hover',
'data-title' => 'Your title',
'data-content' => 'Your content',
))?>

How can I change an image using WordPress customize ($wp_customize)?

I have the following code below, but I can't figure out why it's not working. All I get from my template is a blank screen. Any ideas? I'm using the latest version of WordPress.
function twentyone_customizer_register($wp_customize)
{
$wp_customize->add_section('logo_changer', array(
'title' => __('Images', 'twentyone'),
'description' => 'Change index page background image.'
));
$wp_customize->add_setting('logo_image', array(
'default' => 'http://localhost/twentyone/wp-content/themes/twentyone/assets/img/showcase.jpg'
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'logo_image', array(
'label' => __('Edit Showcase Image', 'twentyone'),
'section' => 'logo_changer',
'settings' => 'logo_image'
)));
}
add_action('customize_register', 'twentyone_customizer_register');
I've solved my problem and I have edited the code to reflect the changes. I named the function starting with a number and that caused the theme customizer not to work.

Categories