Wordpress + Divi: Custom Section Toggle - php

I have a child theme editing the main-structure-elements.php file from the Divi parent theme. I have tried to override this file by moving it into the child theme and making the changes there, as well as modifying the functions.php file to require that file, still no luck.
I just need to add a toggle to the Divi sections that adds a css filter. This is the code I have written in the main-structure-elements.php file which works great in the main divi file but is unrecognized if added just in the child theme file.
public function get_fields() {
$fields = array(
'fullpage_height' => array(
'label' => esc_html__( 'Enable Fullpage', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'options' => array(
'off' => et_builder_i18n( 'No' ),
'on' => et_builder_i18n( 'Yes' ),
),
'default' => 'off',
'description' => esc_html__( 'Here you can select whether or not your page should have Full Height enabled. This must be enabled on all sections to function', 'et_builder' ),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'default_on_front' => 'off',
),
this code then is triggering this code later in that same file.
if ( 'on' === $fullpage_height ) {
$this->add_classname( 'fullpage-vertical' );
}
I have been working on this for days, any insight would be a life saver

Did you try run this code as snippet using plugin "Code Snippets"? Maybe at this way the code will work fine.

Related

Editing a function in a Wordpress Plugin (or is there a way to create a 'Child plugin')?

I am using a plugin called Lightweight Social Icons, and I want to add my own custom icons without having to edit the parent plugin.
Here's a snippet of the parent plugin:
class lsi_Widget extends WP_Widget {
... (class functions are in here)
}
function lsi_icons( $options = '' ) {
$options = array (
'email' => array(
'id' => 'email',
'name' => __( 'Contact', 'lightweight-social-icons' )
),
'delicious' => array(
'id' => 'delicious',
'name' => __( 'Delicious', 'lightweight-social-icons' )
),
'deviantart' => array(
'id' => 'deviantart',
'name' => __( 'DeviantArt', 'lightweight-social-icons' )
),
'digg' => array(
'id' => 'digg',
'name' => __( 'Digg', 'lightweight-social-icons' )
),
'facebook' => array(
'id' => 'facebook',
'name' => __( 'Facebook', 'lightweight-social-icons' )
),
);
return apply_filters( 'lsi_icons_defaults', $options );
}
I want to edit the lsi_icons() function so that I can add my own icons, but it is outside of the lsi_Widget class. I have a child theme with a functions.php file, which I am using to make changes to other plugins using actions and hooks, however, I'm not sure how to do the same for this plugin since the function I want to modify is outside of the class. I've been looking for a way to create 'Child plugins' the same way you do Child Themes, but I can't seem to find a clear answer on how to do it. So is there some other way to do what I'm trying to do?
Link to the LSI Plugin Github page: https://github.com/tomusborne/lightweight-social-icons
It's don't matter, where is filter located. You can access it from functions.php file of your theme/child theme.
Here is code:
function ww_change_lsi_icons($options){
//here you can see all icons added. Add, delete, change them through $options variable
return $options;
}
add_filter( 'lsi_icons_defaults', 'ww_change_lsi_icons' );

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 custom_header does not save any changes

i'm building a wp theme from scratch, im using xampp as a local server and wordpress 4.3, the problem comes when i click on "customize" and change the header image, then i click "save and publish" but i still have the last image i had and the changes i made from the customize menu dont take effect some times. here is the current code i have:
functions.php
register_default_headers( array(
'logo1' => array(
'url' => '%s/images/logo1.jpg',
'thumbnail_url' => '%s/images/logo1.jpg',
'description' => __( 'Wheel', 'twentyeleven' )
),
'logo2' => array(
'url' => '%s/images/logo2.jpg',
'thumbnail_url' => '%s/images/logo2.jpg',
'description' => __( 'Shore', 'twentyeleven' )
),
'logo3' => array(
'url' => '%s/images/logo3.jpg',
'thumbnail_url' => '%s/images/logo3.jpg',
'description' => __( 'Trolley', 'twentyeleven' )
)
) );
add_theme_support("custom-header");
it works fine until i click on save and publish, sometimes it dont take effect and dont save and sometimes it works, but other options like changing the background image or color of the page works well. thank you!!

Genesis Start Theme remove services post type

I'm trying to remove the services post type in the Start Genesis child theme. The Start theme comes bundled with a services post type. I have a page with the URL -- http://domain.com/services -- but when I try to the view the page on this url, I am greeted with a 404 not found yet I know this page exists and has content.
Now for SEO reasons this is the best URL for this page so changing it is not an option.
To my question, is there a way to remove the services post type in the Start theme?
Thanks
Try this..
function custom_unregister_theme_post_types() {
global $wp_post_types;
if ( isset( $wp_post_types[ 'services' ] ) ) {
unset( $wp_post_types[ 'services' ] );
}
}
add_action( 'init', 'custom_unregister_theme_post_types', 20 );
Note : Please make a back up of your database before trying.
For anyone having the same issue, response from the theme author regarding the "services" post type
There's a custom post type "Services" and /services/ url will load the archive page of services post type which conflicts with your page.
If you don't use services post type, you can remove that in zp_cpt.php file ( the file is in /include/cpt/ folder ).
In the file, remove or comment out this code
$services_custom_default = array('supports' => array( 'title', 'editor','thumbnail', 'revisions' ),'menu_icon' => get_stylesheet_directory_uri().'/include/cpt/images/portfolio.png',);
$services = new Super_Custom_Post_Type( 'services', 'Service', 'Services', $services_custom_default );
$services->add_meta_box( array('id' => 'services_settings','context' => 'normal','fields' => array('icon_type' => array( 'type' => 'select', 'options' => array('font-awesome' => 'Font-Awesome','glyphicons' => 'Glyphicons', 'image' => 'Image' ), 'data-zp_desc' => __( 'Select icons to use. Font-Awesome, Glyphicons or an Image.','start') ),'icon_class' => array( 'type' => 'text','data-zp_desc' => __( 'Add icon classes. For font-awesome classes, please refer to this link page. For Glyphicons, refer to this page ','start') ),'icon_link' => array( 'type' => 'text', 'data-zp_desc' => __( 'Service item link','start') ),'icon_target' => array( 'type' => 'select', 'options' => array('_blank' => '_blank','_self' => '_self', '_parent' => '_parent' ), 'data-zp_desc' => __( 'Target','start') ),)
) );

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