$functions) {
if ($tag !== 'advset_group' && !empty($functions)) {
return true;
}
}
return false;
default:
return false;
}
}
// from https://stevegrunwell.com/blog/quick-tip-is_login_page-function-for-wordpress/
if ( ! function_exists( 'is_admin_area' ) ) {
function is_admin_area() {
return is_admin() || in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) );
}
}
/**
* Updates verison information in database and checks if a version migration is required
*
* (optimized for high performance)
*/
function advset_check_for_version_migrations() {
$current_filemtime = filemtime(__FILE__);
$cache = get_option('advset_version_cache', []);
if ( isset($cache['version'], $cache['filemtime']) && $cache['filemtime'] === $current_filemtime ) {
$new_version = $cache['version'];
} else {
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data(__FILE__);
$new_version = $plugin_data['Version'];
update_option('advset_version_cache', ['version' => $new_version, 'filemtime' => $current_filemtime], true);
if (get_option('advset_version__first_install', false) === false) {
update_option('advset_version__first_install', $new_version);
}
}
$old_version = get_option('advset_version', '1.0.0');
if (version_compare($old_version, $new_version, '<')) {
require_once __DIR__ . '/updates/init.php';
update_option('advset_version', $new_version, true);
}
}
add_action('init', 'advset_check_for_version_migrations', 1);
if( is_admin() ) {
define('ADVSET_URL', 'https://wordpress.org/plugins/advanced-settings/');
# Admin menu
add_action('admin_menu', 'advset_menu');
# Add plugin option in Plugins page
add_filter( 'plugin_action_links', 'advset_plugin_action_links', 10, 2 );
// Settings tracking
require_once __DIR__ . '/class.tracksettings.php';
Advanced_Settings_Track_Settings::get_instance();
// update settings
if( isset($_POST['option_page']) && $_POST['option_page']=='advanced-settings' ) {
function advset_update() {
// security
if( !current_user_can('manage_options') )
return;
// define option name
$setup_name = 'advset_'.$_POST['advset_group'];
// prepare option group
$_POST[$setup_name] = $_POST;
unset(
$_POST[$setup_name]['option_page'],
$_POST[$setup_name]['action'],
$_POST[$setup_name]['_wpnonce'],
$_POST[$setup_name]['_wp_http_referer'],
$_POST[$setup_name]['submit']
);
if( !empty($_POST[$setup_name]['auto_thumbs']) )
$_POST[$setup_name]['add_thumbs'] = '1';
if( !empty($_POST[$setup_name]['remove_widget_system']) )
$_POST[$setup_name]['remove_default_wp_widgets'] = '1';
if( isset($_POST[$setup_name]['advset_tracksettings_choice']) && $_POST[$setup_name]['advset_tracksettings_choice'] === '' )
unset($_POST[$setup_name]['advset_tracksettings_choice']);
// save settings
register_setting( 'advanced-settings', $setup_name );
}
add_action( 'admin_init', 'advset_update' );
}
}
// get a advanced-settings option
function advset_option( $option_name, $default='' ) {
global $advset_options;
if( !isset($advset_options) )
$advset_options = get_option('advset_advset', array()) + get_option('advset_code', array()) + get_option('advset_system', array()) + get_option('advset_scripts', array()) + get_option('advset_styles', array());
if( isset($advset_options[$option_name]) )
return $advset_options[$option_name];
else
return $default;
}
function advset_check_if( $option_name, $echo=true ) {
if ( advset_option( $option_name, 0 ) ) {
if ($echo) {
echo ' checked="checked"';
}
else {
return ' checked="checked"';
}
}
}
# ADMIN MENU
function advset_menu() {
$title = __('Advanced') . ' …';
add_options_page($title, $title, 'manage_options', 'advanced-settings', 'advset_page');
}
# ADMIN PAGE TABS
function advset_page_header() {
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
?>
💚This plugin is currently being extensively revised.
If you have any questions or wishes, just get in touch.
' . __('DEPRECATED') . ' ' . __('This option will be removed in an upcoming version.') . '';
}
function advset_page_experimental() {
return ' ' . __('EXPERIMENTAL') . '';
}
# Add plugin option in Plugins page
function advset_plugin_action_links( $links, $file ) {
if ( $file == plugin_basename( basename(dirname(__FILE__)).'/index.php' ) ) {
$links[] = ''.__('Settings').'';
}
return $links;
}
# Disable The "Please Update Now" Message On WordPress Dashboard
if ( advset_option('hide_update_message') ) {
add_action( 'admin_menu', '__advsettings_hide_update_message', 2 );
function __advsettings_hide_update_message() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
}
# Email Protection
if ( !is_admin() && advset_option('protect_emails') ) {
function advset_protect_emails_in_output($content) {
return preg_replace_callback('/((?:mailto\:)?[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/', function($matches) {
static $cache = [];
$email = $matches[1];
// Use cached version if available
if (isset($cache[$email])) {
return $cache[$email];
}
// Convert to entities and cache
$output = implode('', array_map(function($char) {
return '' . ord($char) . ';';
}, str_split($email)));
$cache[$email] = $output;
return $output;
}, $content);
}
function advset_protect_emails_in_output_with_javascript($content)
{
$content = preg_split('/(\<[^\>]+\>)/', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($a = 0; $a < count($content); $a++)
{
if ($a % 2)
{
if (substr($content[$a], 0, 2) === '')
{
continue;
}
$line = preg_split('/((([a-z0-9\_\-]+)\s*\=\s*\")([^\"]*(?:@|\%40|\&\#64\;|\&\#x40\;)[^\"]*)(\"))/', $content[$a], -1, PREG_SPLIT_DELIM_CAPTURE);
$b64arr = array();
if (count($line) > 1)
{
for ($b = 3; $b < count($line); $b+=6)
{
$b64arr[$line[$b]] = $line[$b + 1];
$line[$b + 1] = $line[$b] === 'href' ? 'javascript:;' : '';
$line[$b - 2] = '';
$line[$b] = '';
}
$content[$a] = implode('', $line) . '';
}
}
else
{
$line = preg_split('/(?<=^|[^a-z0-9\.+&\_-])([a-z0-9\.+&\_-]+(?:@|\%40|\&\#64\;|\&\#x40\;)[a-z0-9\.\_-]{2,}\.[a-z0-9]+)(?=[^a-z0-9]|$)/i', $content[$a], -1, PREG_SPLIT_DELIM_CAPTURE);
if (count($line) > 1)
{
for ($b = 1; $b < count($line); $b+=2)
{
$line[$b] = '';
}
$content[$a] = implode('', $line);
}
}
}
return implode('', $content);
}
// Buffer the entire output to protect all email addresses
function advset_start_email_protection() {
if (advset_option('protect_emails_method') === 'javascript') {
ob_start('advset_protect_emails_in_output_with_javascript');
} else {
ob_start('advset_protect_emails_in_output');
}
}
add_action('init', 'advset_start_email_protection');
}
# Add a Custom Dashboard Logo
# from https://www.codementor.io/wordpress/tutorial/wordpress-functions-php-cheatsheet
if ( advset_option('dashboard_logo') ) {
add_action('wp_before_admin_bar_render', '__advsettings_dashboard_logo');
function __advsettings_dashboard_logo() {
if(is_admin())
echo '
';
}
}
# Remove Trackbacks and Pingbacks from Comment Count
# from https://www.codementor.io/wordpress/tutorial/wordpress-functions-php-cheatsheet
if ( advset_option('remove_pingbacks_trackbacks_count') ) {
add_filter('get_comments_number', '__advsettings_comment_count', 0);
function __advsettings_comment_count( $count ) {
if ( ! is_admin_area() ) {
global $id;
$comments = get_comments('status=approve&post_id=' . $id);
$comments_by_type = separate_comments($comments);
return count($comments_by_type['comment']);
}
else {
return $count;
}
}
}
# Remove admin menu
if( advset_option('remove_menu') )
add_filter('show_admin_bar' , '__return_false'); // Remove admin menu
# Configure FeedBurner
if( advset_option('feedburner') ) {
function appthemes_custom_rss_feed( $output, $feed ) {
if ( strpos( $output, 'comments' ) )
return $output;
if( strpos(advset_option('feedburner'), '/')===FALSE )
return esc_url( 'https://feeds.feedburner.com/'.advset_option('feedburner') );
else
return esc_url( advset_option('feedburner') );
}
add_action( 'feed_link', 'appthemes_custom_rss_feed', 10, 2 );
}
# Remove wp default favicon
if ( advset_option('remove_default_wp_favicon') ) {
add_action('init', function() {
if ($_SERVER['REQUEST_URI'] === '/favicon.ico') {
header("Content-Type: image/x-icon");
http_response_code(404);
exit;
}
}, 5);
}
# Favicon
if( advset_option('favicon') ) {
function __advsettings_favicon() {
foreach ([
'ico' => '',
'png' => 'image/png',
'svg' => 'image/svg+xml',
] as $suffix => $mime) {
if ( file_exists(TEMPLATEPATH.'/favicon.' . $suffix) ){
echo ''."\r\n";
break;
}
}
}
add_action( 'wp_head', '__advsettings_favicon' );
}
# Add blog description meta tag
if( advset_option('description') ) {
function __advsettings_blog_description() {
if(is_home() || !advset_option('single_metas'))
echo ''."\r\n";
}
add_action( 'wp_head', '__advsettings_blog_description' );
}
# Add description and keyword meta tag in posts
if( advset_option('single_metas') ) {
function __advsettings_single_metas() {
global $post;
if( is_single() || is_page() ) {
$tag_list = get_the_terms( $post->ID, 'post_tag' );
if( $tag_list ) {
foreach( $tag_list as $tag )
$tag_array[] = $tag->name;
echo ''."\r\n";
}
$excerpt = strip_tags($post->post_content);
$excerpt = strip_shortcodes($excerpt);
$excerpt = str_replace(array('\n', '\r', '\t'), ' ', $excerpt);
$excerpt = substr($excerpt, 0, 125);
if( !empty($excerpt) )
echo ''."\r\n";
}
}
add_action( 'wp_head', '__advsettings_single_metas' );
}
# Remove header generator
if( advset_option('remove_generator') )
remove_action('wp_head', 'wp_generator');
# Remove WLW
if( advset_option('remove_wlw') )
remove_action('wp_head', 'wlwmanifest_link');
# Thumbnails support
if( advset_option('add_thumbs') ) {
function __advsettings_add_thumbs(){
add_theme_support( 'post-thumbnails' );
}
add_action('after_setup_theme', '__advsettings_add_thumbs');
if( !current_theme_supports('post-thumbnails') )
define( 'ADVSET_THUMBS', '1' );
}
# JPEG Quality
if( advset_option('jpeg_quality', 0)>0 && $_SERVER['HTTP_HOST']!='localhost' ) {
add_filter('jpeg_quality', '__advsettings_jpeg_quality');
function __advsettings_jpeg_quality(){
return (int) advset_option('jpeg_quality');
}
}
# REL External
if( advset_option('rel_external') ) {
function ____replace_targets( $content ) {
$content = str_replace('target="_self"', '', $content);
return str_replace('target="_blank"', 'rel="external"', $content);
}
add_filter( 'the_content', '____replace_targets' );
}
# Fix post type pagination
if( advset_option('post_type_pag') ) {
# following are code adapted from Custom Post Type Category Pagination Fix by jdantzer
function fix_category_pagination($qs){
if(isset($qs['category_name']) && isset($qs['paged'])){
$qs['post_type'] = get_post_types($args = array(
'public' => true,
'_builtin' => false
));
array_push($qs['post_type'],'post');
}
return $qs;
}
add_filter('request', 'fix_category_pagination');
}
# Disable auto save
if( advset_option('disable_auto_save') ) {
define('AUTOSAVE_INTERVAL', 60 * 60 * 24 * 365 * 100); // save interval => 100 years
}
# Remove wptexturize
if( advset_option('remove_wptexturize') ) {
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
}
# Filtering the code
if( advset_option('compress') || advset_option('remove_comments') ) {
add_action('template_redirect','____template');
function ____template() { ob_start('____template2'); }
function ____template2($code) {
# dont remove conditional IE comments "/', '', $code);
/* exemples:
*
* [html code] ...
* old code replaced: $code = preg_replace('//', '', $code);
* */
if( advset_option('compress') )
$code = trim( preg_replace( '/\s+(?![^<>]*<\/pre>)/', ' ', $code ) );
return $code;
}
}
# Remove comments system
if( advset_option('remove_comments_system') ) {
function __av_comments_close( $open, $post_id ) {
#$post = get_post( $post_id );
#if ( 'page' == $post->post_type )
#$open = false;
return false;
}
add_filter( 'comments_open', '__av_comments_close', 10, 2 );
function __av_empty_comments_array( $open, $post_id ) {
return array();
}
add_filter( 'comments_array', '__av_empty_comments_array', 10, 2 );
// Removes from admin menu
function __av_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
}
add_action( 'admin_menu', '__av_remove_admin_menus' );
// Removes from admin bar
function __av_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('comments');
}
add_action( 'wp_before_admin_bar_render', '__av_admin_bar_render' );
}
# Disable author pages
if ( advset_option('disable_author_pages') ) {
function advset_disable_author_pages__template_redirect() {
global $wp_query;
if ( is_author() ) {
$wp_query->set_404();
status_header(404);
}
}
add_action( 'template_redirect', 'advset_disable_author_pages__template_redirect' );
function advset_disable_author_pages__wp_sitemaps_add_provider( $provider, $name ) {
if ( 'users' === $name ) {
return false;
}
return $provider;
}
add_filter( 'wp_sitemaps_add_provider', 'advset_disable_author_pages__wp_sitemaps_add_provider', 10, 2 );
}
# Google Analytics
if( advset_option('analytics') ) {
add_action('wp_footer', '____analytics'); // Load custom styles
function ____analytics(){
$ga_code = advset_option('analytics');
echo "