Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add custom options to plugin or theme to main options WordPress screen
<?php
if(!defined('ABSPATH')){exit;}
/**
* Add new options field
*/
function additional_settings_section_callback_function() {
_e("This options will optimize your best WordPress site!", TEXTDOMAIN);
}
add_action( 'admin_init', 'additional_settings_api_init' );
function additional_settings_api_init() {
add_settings_section(
'additional_settings_section', // секция
__("Additional settings", TEXTDOMAIN),
'additional_settings_section_callback_function',
'general' // страница
);
add_settings_field(
'delete_child_media',
__("Delete child media", TEXTDOMAIN),
'delete_child_media_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'delete_child_media' );
add_settings_field(
'hide_theme_options',
__("Hide theme options and replace to Menu page", TEXTDOMAIN),
'hide_theme_options_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'hide_theme_options' );
add_settings_field(
'disable_emoji',
__("Disable Emoji", TEXTDOMAIN),
'disable_emoji_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'disable_emoji' );
add_settings_field(
'disable_all_updates',
__("Disable all updates", TEXTDOMAIN),
'disable_all_updates_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'disable_all_updates' );
add_settings_field(
'disable_wpjsonhead',
__("Disable Json", TEXTDOMAIN),
'disable_wpjsonhead_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'disable_wpjsonhead' );
add_settings_field(
'disable_embedshead',
__("Disable Embeds", TEXTDOMAIN),
'disable_embedshead_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'disable_embedshead' );
add_settings_field(
'enable_viewport',
__("Enable viewport for responsive markup", TEXTDOMAIN),
'enable_viewport_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'enable_viewport' );
add_settings_field(
'enable_html_minification',
__("Enable HTML minification", TEXTDOMAIN),
'enable_html_minification_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'enable_html_minification' );
add_settings_field(
'enable_xuacompatible',
__("Enable X-UA-Compatible", TEXTDOMAIN),
'enable_xuacompatible_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'enable_xuacompatible' );
add_settings_field(
'hide_dnsprefetch',
__("Hide DNS-prefetch", TEXTDOMAIN),
'hide_dnsprefetch_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'hide_dnsprefetch' );
add_settings_field(
'disable_skype_parser',
__("Disable Skype phone parser", TEXTDOMAIN),
'disable_skype_parser_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'disable_skype_parser' );
add_settings_field(
'rename_media_files',
__("Rename file on upload inside post", TEXTDOMAIN),
'rename_media_files_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'rename_media_files' );
add_settings_field(
'custom_header',
__("Header custom code", TEXTDOMAIN),
'custom_header_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'custom_header' );
add_settings_field(
'custom_footer',
__("Footer custom code", TEXTDOMAIN),
'custom_footer_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'custom_footer' );
add_settings_field(
'resizeupload_width',
__("Max uploaded image width", TEXTDOMAIN),
'resizeupload_width_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'resizeupload_width' );
add_settings_field(
'resizeupload_height',
__("Max uploaded image height", TEXTDOMAIN),
'resizeupload_height_option_function',
'general',
'additional_settings_section'
);
register_setting( 'general', 'resizeupload_height' );
}
function delete_child_media_option_function() {
echo '<input
name="delete_child_media"
type="checkbox"
' . checked( 1, get_option( 'delete_child_media' ), false ) . '
value="1"
class="code"
/>';
}
function hide_theme_options_option_function() {
echo '<input
name="hide_theme_options"
type="checkbox"
' . checked( 1, get_option( 'hide_theme_options' ), false ) . '
value="1"
class="code"
/>';
}
function disable_emoji_option_function() {
echo '<input
name="disable_emoji"
type="checkbox"
' . checked( 1, get_option( 'disable_emoji' ), false ) . '
value="1"
class="code"
/>';
}
function disable_all_updates_option_function() {
echo '<input
name="disable_all_updates"
type="checkbox"
' . checked( 1, get_option( 'disable_all_updates' ), false ) . '
value="1"
class="code"
/>';
}
function disable_wpjsonhead_option_function() {
echo '<input
name="disable_wpjsonhead"
type="checkbox"
' . checked( 1, get_option( 'disable_wpjsonhead' ), false ) . '
value="1"
class="code"
/>';
}
function disable_embedshead_option_function() {
echo '<input
name="disable_embedshead"
type="checkbox"
' . checked( 1, get_option( 'disable_embedshead' ), false ) . '
value="1"
class="code"
/>';
}
function enable_viewport_option_function() {
echo '<input
name="enable_viewport"
type="checkbox"
' . checked( 1, get_option( 'enable_viewport' ), false ) . '
value="1"
class="code"
/>';
}
function enable_html_minification_option_function() {
echo '<input
name="enable_html_minification"
type="checkbox"
' . checked( 1, get_option( 'enable_html_minification' ), false ) . '
value="1"
class="code"
/>';
}
function enable_xuacompatible_option_function() {
echo '<input
name="enable_xuacompatible"
type="checkbox"
' . checked( 1, get_option( 'enable_xuacompatible' ), false ) . '
value="1"
class="code"
/>';
}
function hide_dnsprefetch_option_function() {
echo '<input
name="hide_dnsprefetch"
type="checkbox"
' . checked( 1, get_option( 'hide_dnsprefetch' ), false ) . '
value="1"
class="code"
/>';
}
function disable_skype_parser_option_function() {
echo '<input
name="disable_skype_parser"
type="checkbox"
' . checked( 1, get_option( 'disable_skype_parser' ), false ) . '
value="1"
class="code"
/>';
}
function rename_media_files_option_function() {
echo '<input
name="rename_media_files"
type="checkbox"
' . checked( 1, get_option( 'rename_media_files' ), false ) . '
value="1"
class="code"
/>';
}
function custom_header_option_function()
{
echo '<textarea name="custom_header" id="custom_header" rows="8" class="large-text">' . get_option('custom_header') . '</textarea>';
}
function custom_footer_option_function()
{
echo '<textarea name="custom_footer" id="custom_footer" rows="8" class="large-text">' . get_option('custom_footer') . '</textarea>';
}
function resizeupload_width_option_function()
{
echo '<input type="number" name="resizeupload_width" id="resizeupload_width" value="' . get_option('resizeupload_width') . '" step="1">';
}
function resizeupload_height_option_function()
{
echo '<input type="number" name="resizeupload_height" id="resizeupload_height" value="' . get_option('resizeupload_height') . '" step="1">';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.