wordpress custom_header does not save any changes - php

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!!

Related

Wordpress + Divi: Custom Section Toggle

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.

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.

Woocommerce product api not accept images in some urls

I am creating products from external in woocommerce site. My code is like bellow:
if($_POST["Type"] == "CREATE"){
$data = array(
'product' => array(
'title' => $_POST["Title"],
'type' => 'simple',
'regular_price' => $_POST["Regular_price"],
'description' => $_POST["Description"],
'short_description' => $_POST["Short_description"],
'categories' => array(
$_POST['CategoryName']
),
'images' => array(
array(
'src' => $_POST["Image_url"],
'position' => 0
),
array(
'src' => $_POST["Image_url"],
'position' => 1
)
)
)
);
$res = $client->products->create($data);
}
When using $_POST["Image_url"] such like http://app.test.net:8080/test/img/company-logo.png gives the following error:
PHP Fatal error: Uncaught exception 'WC_API_Client_HTTP_Exception' with message 'Error: Error getting remote image
But if we give a normal url(url do not contain the specific port) such like http://test.com/wp-content/uploads/2016/02/test.png it's working properly.
How to resolve this?
In my case above mentioned code in the such a URL (http://app.test.net:8080/api/v1/product.php). Calling this API from .net application by (http://appname.test.net). Both are having the same domain part (test.net).
There fore difficult to find the URL to woo commerce.I have change URL the of .net application by my server configuration(I have using virtual hosts).Then it works properly.
---- (Edit 2) ----
Sorry but your question is Not clear at all. You have to update it, because it is very incomplete and fuzzy. Same thing for the title.
The medias images are located in a 2nd server on port 8080, right…
Form me the problem is here in:
'images' => array(
array(
'src' => $_POST["Image_url"],
'position' => 0
),
array(
'src' => $_POST["Image_url"],
'position' => 0
)
)
with 'src' => $_POST["Image_url"]
Have a look to this interesting related thread: Synchronize external database with woocommerce database

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