Wordpress add Shortcut link to Enable/Disable plugin in admin bar - wordpress

I would like to add a link to enable and disable a plugin in the admin bar.
Below the code, I wanted to know if it is the correct method.
thank you
function custom_admin_bar_link( $admin_bar ) {
$admin_bar->add_menu( array(
'id' => 'wp-custom-link',
'title' => 'Custom Item',
'href' => '',
'meta' => array(
'title' => __('Custom'),
),
));
$admin_bar->add_menu( array(
'id' => 'disable-link',
'parent'=> 'wp-custom-link',
'title' => 'Disable Amazon',
'href' => 'https://mydisablelink.com/',
'meta' => array(
'title' => __('Disable Amazon'),
),
));
$admin_bar->add_menu( array(
'id' => 'unable-link',
'parent'=> 'wp-custom-link',
'title' => 'Enable Amazon',
'href' => 'https://mydisablelink.com/',
'meta' => array(
'title' => __('Enable Amazon'),
),
));
}
add_action( 'admin_bar_menu', 'custom_admin_bar_link', 100 );

Related

Meta box tabs - in a custom post type

Is it possible to insert meta box tabs in a specific custom post type.
I've been looking at the example :
add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
// 1st Meta Box
$meta_boxes[] = array(
'title' => 'Meta Box Tabs Demo',
// List of tabs, in one of the following formats:
// 1) key => label
// 2) key => array( 'label' => Tab label, 'icon' => Tab icon )
'tabs' => array(
'contact' => array(
'label' => 'Contact',
'icon' => 'dashicons-email', // Dashicon
),
'social' => array(
'label' => 'Social Media',
'icon' => 'dashicons-share', // Dashicon
),
'note' => array(
'label' => 'Note',
'icon' => 'https://i.imgur.com/nJtag1q.png', // Custom icon, using image
),
),
// Tab style: 'default', 'box' or 'left'. Optional
'tab_style' => 'default',
// Show meta box wrapper around tabs? true (default) or false. Optional
'tab_wrapper' => true,
'fields' => array(
array(
'name' => 'Name',
'id' => 'name',
'type' => 'text',
// Which tab this field belongs to? Put tab key here
'tab' => 'contact',
),
array(
'name' => 'Email',
'id' => 'email',
'type' => 'email',
'tab' => 'contact',
),
array(
'name' => 'Facebook',
'id' => 'facebook',
'type' => 'text',
'tab' => 'social',
),
array(
'name' => 'Note',
'id' => 'note',
'type' => 'textarea',
'tab' => 'note',
),
),
);
This will work in post if added to functions.php ... but if we try to use it in a custom post type the metabox will appear but the fields will not.
Any help would be appreciated.

SSL breaks a users ability to upload an image

I have a problem that is driving me crazy. I'm working on a business listing website in WordPress which allows business users to upload their businesses, along with a description and an image.
All was working fine in development but as soon as a SSL is installed on the site, image uploads produce an error:
An error occurred in the upload. Please try again later.
The inspector console shows:
400 error: Failed to load resource: the server responded with a status of 400 (Bad Request)
and the file cannot be uploaded.
I'm out of my depth here - any ideas please?
I think this is the relevant part of the theme library - not sure it it helps?
<?php
if ( ! search_and_go_elated_listing_plugin_installed() ) {
//exit if listing plugin is not installed
return;
}
if(!function_exists('search_and_go_elated_map_listing_type_settings')) {
function search_and_go_elated_map_listing_type_settings() {
$meta_box_listing_type = search_and_go_elated_create_meta_box(array(
'scope' => 'listing-type-item',
'title' => 'Listing Type Settings',
'name' => 'listing_type_settings_meta_box'
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_phone',
'type' => 'yesno',
'label' => esc_html__( 'Show Phone Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_website',
'type' => 'yesno',
'label' => esc_html__( 'Show Website Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_email',
'type' => 'yesno',
'label' => esc_html__( 'Show Email Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Gallery Images', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_video',
'type' => 'yesno',
'label' => esc_html__( 'Show Video', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_audio',
'type' => 'yesno',
'label' => esc_html__( 'Show Audio', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_work_hours',
'type' => 'yesno',
'label' => esc_html__( 'Show Working Hours', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_social_icons',
'type' => 'yesno',
'label' => esc_html__( 'Show Social Icons', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_price',
'type' => 'yesno',
'label' => esc_html__( 'Show Price', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_sidebar_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Sidebar Gallery', 'search-and-go' ),
'description' => '',
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_booking_form',
'type' => 'yesno',
'label' => esc_html__( 'Show Booking Form', 'search-and-go' ),
'description' => esc_html__( 'Requires Elated Booking Plugin to be installed', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
//init icon pack hide and show array. It will be populated dinamically from collections array
$listing_type_icon_pack_hide_array = array();
$listing_type_icon_pack_show_array = array();
//do we have some collection added in collections array?
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//get collections params array. It will contain values of 'param' property for each collection
$listing_type_icon_collections_params = search_and_go_elated_icon_collections()->getIconCollectionsParams();
//foreach collection generate hide and show array
foreach (search_and_go_elated_icon_collections()->iconCollections as $dep_collection_key => $dep_collection_object) {
$listing_type_icon_pack_hide_array[$dep_collection_key] = '';
//we need to include only current collection in show string as it is the only one that needs to show
$listing_type_icon_pack_show_array[$dep_collection_key] = '#eltd_listing_type_icon_' . $dep_collection_object->param . '_container';
//for all collections param generate hide string
foreach ($listing_type_icon_collections_params as $listing_icon_collections_param) {
//we don't need to include current one, because it needs to be shown, not hidden
if ($listing_icon_collections_param !== $dep_collection_object->param) {
$listing_type_icon_pack_hide_array[$dep_collection_key] .= '#eltd_listing_type_icon_' . $listing_icon_collections_param . '_container,';
}
}
//remove remaining ',' character
$listing_type_icon_pack_hide_array[$dep_collection_key] = rtrim($listing_type_icon_pack_hide_array[$dep_collection_key], ',');
}
}
search_and_go_elated_create_meta_box_field(
array(
'parent' => $meta_box_listing_type,
'type' => 'select',
'name' => 'listing_type_icon_pack',
'default_value' => 'font_awesome',
'label' => esc_html__( 'Listing Type Icon Pack', 'search-and-go' ),
'description' => esc_html__( 'Choose icon pack for listing', 'search-and-go' ),
'options' => search_and_go_elated_icon_collections()->getIconCollections(),
'args' => array(
'dependence' => true,
'hide' => $listing_type_icon_pack_hide_array,
'show' => $listing_type_icon_pack_show_array
)
)
);
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//foreach icon collection we need to generate separate container that will have dependency set
//it will have one field inside with icons dropdown
foreach (search_and_go_elated_icon_collections()->iconCollections as $collection_key => $collection_object) {
$icons_array = $collection_object->getIconsArray();
//get icon collection keys (keys from collections array, e.g 'font_awesome', 'font_elegant' etc.)
$icon_collections_keys = search_and_go_elated_icon_collections()->getIconCollectionsKeys();
//unset current one, because it doesn't have to be included in dependency that hides icon container
unset($icon_collections_keys[array_search($collection_key, $icon_collections_keys)]);
$listing_icon_hide_values = $icon_collections_keys;
$listing_icon_container = search_and_go_elated_add_admin_container(
array(
'parent' => $meta_box_listing_type,
'name' => 'listing_type_icon_' . $collection_object->param . '_container',
'hidden_property' => 'listing_type_icon_pack',
'hidden_value' => '',
'hidden_values' => $listing_icon_hide_values
)
);
search_and_go_elated_create_meta_box_field(
array(
'parent' => $listing_icon_container,
'type' => 'select',
'name' => 'listing_type_icon_' . $collection_object->param,
'default_value' => '',
'label' => esc_html__( 'Listing Type Icon', 'search-and-go' ),
'description' => esc_html__( 'Choose Listing Type Icon', 'search-and-go' ),
'options' => $icons_array,
)
);
}
}
search_and_go_elated_add_custom_fields_creator(array(
'name' => 'listing_custom_fields' ,
'label' => esc_html__( 'Custom Fields Creator', 'search-and-go' ),
'desciption' => esc_html__( 'Create listing type custom fields', 'search-and-go' ),
'parent' => $meta_box_listing_type
));
$feature_list_title = search_and_go_elated_add_admin_section_title(
array(
'parent' => $meta_box_listing_type,
'title' => esc_html__( 'Listing Type Feature List', 'search-and-go' ),
'name' => 'listing_type_feature_list_title'
)
);
search_and_go_elated_add_repeater_field(array(
'name' => 'eltd_listing_type_repeater',
'parent' => $meta_box_listing_type,
'fields' => array(
array(
'type' => 'textsimple',
'name' => 'eltd_listing_type_feature_list',
'label' => '',
'description' => '',
),
)
)
);
}
add_action('search_and_go_elated_meta_boxes_map', 'search_and_go_elated_map_listing_type_settings');
}

getting error 500 after trying to add a tab to wordpress customizer

i'm trying to add a tab to my wordpress customizer.
i use the next code:
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_settings('facebook',
array(
'default' => 'http://facebook.com/ahiad'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize,'txtFacebookAddress',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
)));
}
the problem is every time i run this piece of code in my website, i get an error 500, could not spot the problem here...
You are using $wp_customize->settings which is not not exists, Please use $wp_customize->setting.
Please try below code :
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_setting('facebook',
array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
'default' => 'http://facebook.com/ahiad',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '',
));
$wp_customize->add_control('facebook',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
));
}
I hope it will helps you. Thanks

Wordpress How Can I Display skill1_logo in View

Hi Im practically a newbie and would like to kindly ask how can I display skill1_logo,skill1_title,skill1_description on a page that I want. I was trying to do a 1 page website using wordpress to practice my wordpress.
function theme_skills_customizer($wp_customize){
//adding section in wordpress customizer
$wp_customize->add_section('skills_settings_section', array(
'title' => 'Skills Section'
));
$wp_customize->add_setting('skill1_logo');
$wp_customize->add_setting('skill1_title');
$wp_customize->add_setting('skill1_description');
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'skill1_logo', array(
'label' => __( 'Skill 1 Logo', 'themeslug' ),
'width' => 400,
'height' => 400,
'flex-width' => true,
'flex-height' => true,
'section' => 'skills_settings_section',
'settings' => 'skill1_logo',
)));
$wp_customize->add_control( 'skill1_title', array(
'label' => __( 'Skill 1 Title' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'text',
));
$wp_customize->add_control( 'skill1_description', array(
'label' => __( 'Skill 1 Description' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'textarea',
));
}
add_action( 'customize_register', 'theme_skills_customizer' );
You can use get_theme_mod function to echo those settings.
e.g.
$s_title = get_theme_mod('skill1_title');

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'];

Resources