How Do you Properly Add An Image Control To Wordpress Customizer? - wordpress

Wordpress admin customizer control is incomplete. How can I fix it?
My Code:
$wp_customize->add_setting('swag_header_media');
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'swag_header_media'
)));
The results are incomplete. I can select an image from the and the image show up in the frontend of the theme. However, the image selected does not show that it is being used in the control.
In other words(see screenshot), you can see the background image being used(phone), but it doesn't show that it being used in the admin customizer control. Its says "Current Image Selection", but it's empty with no buttons below it to change or remove it.

When you inspect the page, is there any errors?
It is a bit hard to figure out with so little data.
Try this 'settings' => 'themename_theme_options[swag_header_media]',

Try:
$wp_customize->add_setting('themename_theme_mods[swag_header_media]',array(
//'default' => 'image.jpg',
//'capability' => 'edit_theme_options',
//'type' => 'option'
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'swag_header_media', array(
'label' => 'Current Image Selection',
'section' => 'swag_header_media_section',
'active_callback' => 'header_show_image_selection_settings_callback',
'settings' => 'themename_theme_mods[swag_header_media]'
)));
if that doesnt work,I suggest to change swag_header_media to other keyname. I suspect that key name might be used by other control/funtion too. So, try to add any 1 letter to that keyname, and see the result. Also, if you have any caching on site, turn it off.
also, the problem could be with callback,

Related

Adding the Classic Editor to a Gutenberg Block Template

NOTE: Here is a video that helps explain my question: https://drive.google.com/file/d/1c3pS-j8yq75GAwGDrrMMh9X7fDrCKV5R/view?pli=1
I am creating a custom post type that includes a set of blocks as a template. My basic code looks like this:
function register_article_post_type(){
$post_settings = array(
'label' => 'Articles',
'public' => true,
'show_in_rest' => true,
'template_lock' => 'all',
'template' => array(
array( 'core/heading',
array(
'placeholder' => 'Add Categories Heading...',
'className' => 'tour_categories_heading'
)
),
)
);
register_post_type('article', $post_settings);
}
That will create a Custom Post Type called Articles which has a singular Heading block. The thing is, I don't want a heading block, I want the Classic Editor block.
But I can't figure out how to add it. I can easily change the Heading block to a different block (say the paragraph block) if I change array( 'core/heading', to array( 'core/paragraph',.
But when I check the code in Gutenberg for the name of the Classic editor, nothing shows up. As such, I cannot figure out how to add a Classic editor to the custom post type.
Any ideas.
Try core/freeform - should be the slug for the classic editor block

how can i add an radio image control in Elementor Page Builder

i want to create a radio image control in Elementor that when i set in as new control like this codes it show me an radio image ->"RADIO_IMAGE" in setting.
$this->add_control(
'radio_image_control',
[
'label' => esc_html__('Select one layout',TEXTDOMAIN),
'type' => Controls_Manager::RADIO_IMAGE,
'options' => [
'1' => esc_html__('Layout 1', TEXTDOMAIN),
'2' => esc_html__('Layout 2', TEXTDOMAIN),
],
'default' => '1',
]
);
if someone have experience about this or now something please help thanks a lot.
i have tried with Elementor site emoj example as emoj.php file but it didn't work because i didn't know after add sample code where finaly i should include emoj.php file.
There is no control as you used the radio_image_control in Elementor.

Using Code Snippets in Wordpress to remove a line of code from a plugin?

I want to remove a specific line of code from a plugin in WordPress. I can edit the plugin itself, but when it is updated it overwrites the changes I have done. I read that using the code snippet WordPress plugin I can have it always overwrite, regardless of updates.
If the line of code I want to be removed is the
'required'=>true
from the code below, how would I write that in the code snippet plugin? The plugin file I am editing is located at wp-store-locator/admin/class-metaboxes.php
`$meta_fields = array(
__( 'Location', 'wpsl' ) => array(
'address' => array(
'label' => __( 'Address', 'wpsl' ),
'required' => true
),`
Thanks so much

How to add a filter (like image rename) to a Theme Customization API setting

I want to add several image upload fields to my theme options by using the WP Customization API.
For each of these upload fields I want to rename the uploaded file to a fixed name.
So for example, I want to add a hero_image field, and it should always be stored as hero.jpg.
I added a setting called hero_image,
$wp_customize->add_setting( 'hero_image' , array(
'default' => '',
) );
This is the related control
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'hero_image_control',
array(
'label' => 'Site hero',
'section' => 'context_settings',
'settings' => 'hero_image',
'context' => 'your_setting_context'
)
)
);
I know I can add a sanitize callback, but this won't rename the uploaded file.
If anyone knows how to add a preupload filter for a specific field, it would make my day :D

Add menu bar above the WordPress administration bar

I wish to add our own service menu above the WordPress administration bar in the administration area. I do not wish to hack the WordPress system, but I cannot find a hook.
Is there a method?
You can add extra menu items in your administrator menu bar instead of removing/replacing the menu bar.
Below is an example which will insert one menu item with two sub menu items. Just paste the code in your functions.php and log in to your WordPress as admin. If everything goes right then you can see an extra menu in your administrator bar. To accomplish this, WordPress provided the admin_bar_menu hook:
add_action('admin_bar_menu', 'my_custom_menu', 1000);
function my_custom_menu()
{
global $wp_admin_bar;
if(!is_super_admin() || !is_admin_bar_showing()) return;
// Add Parent Menu
$argsParent=array(
'id' => 'myCustomMenu',
'title' => 'Services',
'href' => false
);
$wp_admin_bar->add_menu($argsParent);
// Add Sub Menus
$argsSub1=array(
'parent' => 'myCustomMenu',
'title' => 'Visit Heera IT',
'href' => 'http://heera.it',
'meta' => array('target' => '_blank')
);
$wp_admin_bar->add_menu($argsSub1);
$argsSub2=array(
'parent' => 'myCustomMenu',
'title' => 'Visit StackOverflow',
'href' => 'http://stackoverflow.com/',
'meta' => array('target' => '_blank')
);
$wp_admin_bar->add_menu($argsSub2);
}
For more details, you can visit Codex.
You can also accomplish this using a plugin that allows you to easily customize the content and appearance of the WordPress Admin Bar. Here are a few plugins to consider:
Plugin #1
Plugin #2
Plugin #3
$wp_admin_bar->add_menu(array
(
"parent" => "bba_booking_bank",
"id" => "bba_booking_bank_location",
"title" => $bba_location_providers_wizard_setup,
"href" => admin_url("admin.php?page=booking_bank"),
));
$wp_admin_bar->add_menu(array
(
"parent" => "bba_booking_bank",
"id" => "bba_booking_bank_calendar",
"title" => $bba_booking_bank_calendar,
"href" => admin_url("admin.php?page=bba_booking_calendar"),
)
);

Resources