if (!function_exists('fifteenten_setup')) {
function fifteenten_setup()
{
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded
tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support('title-tag');
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support('post-thumbnails');
register_nav_menus(
array(
'primary-menu' => __('Primary Menu'),
'secondary-menu' => __('Secondary Menu')
)
);
/** Add custom image sizes */
add_image_size('square-image', 512, 512, true);
add_image_size('gallery-image', 1000, 600);
add_image_size('masthead', 1600, 1000);
add_image_size('50-width-column-images', 600, 480);
add_theme_support('menus');
}
}
add_action('after_setup_theme', 'fifteenten_setup');
add_action('init', 'fifteenten_register_my_menus');
function fifteenten_register_my_menus()
{
register_nav_menus(
array(
'primary-menu' => __('Primary Menu'),
'secondary-menu' => __('Secondary Menu')
)
);
}
/**
* Remove all the annoying things WP spits out
*/
if (!function_exists('fifteeten_remove_actions')) {
function fifteeten_remove_actions()
{
/**
* remove .recentcomments CSS
*/
global $wp_widget_factory;
remove_action(
'wp_head',
array(
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
'recent_comments_style'
)
);
/**
* Remove header stuff
*/
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('template_redirect', 'rest_output_link_header', 11, 0);
/**
* All actions related to emojis
*/
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
/**
* Remove all new WP SVG nonsense
*/
// remove SVG and global styles
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
// remove wp_footer actions which add's global inline styles
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
// remove render_block filters which adding unnecessary stuff
remove_filter('render_block', 'wp_render_duotone_support');
remove_filter('render_block', 'wp_restore_group_inner_container');
remove_filter('render_block', 'wp_render_layout_support_flag');
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
remove_action('wp_body_open', 'wp_global_styles_render_svg_filters');
/**
* Filter to remove P tags on images
*/
add_filter('acf_the_content', 'filter_ptags_on_images');
add_filter('use_block_editor_for_post', '__return_false', 10);
/**
* Remove Default Rest Routes
*/
remove_action('rest_api_init', 'create_initial_rest_routes', 99);
}
}
add_action('init', 'fifteeten_remove_actions');
/**
* Remove native Lazyloading
*/
add_filter('wp_lazy_loading_enabled', '__return_false');
/**
* Allow for SVG & WEBP image uploads and previews
*/
if (!function_exists('dtd_upload_mimes')) {
function dtd_upload_mimes($existing_mimes)
{
// add WEBP to the list of mime types
$existing_mimes['webp'] = 'image/webp';
$existing_mimes['svg'] = 'image/svg+xml';
// return the array back to the function with our added mime type
return $existing_mimes;
}
add_filter('mime_types', 'dtd_upload_mimes');
}
if (!function_exists('webp_is_displayable')) {
function webp_is_displayable($result, $path)
{
if ($result === false) {
$displayable_image_types = array(IMAGETYPE_WEBP);
$info = @getimagesize($path);
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
$result = true;
}
}
return $result;
}
add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);
}
if (!function_exists('svg_media_library_css')) {
function svg_media_library_css()
{
$css = '';
$css = 'td.media-icon img[src$=".svg"] { width: 100% !important; height: auto !important; }';
echo '';
}
add_action('admin_head', 'svg_media_library_css');
}
if (!function_exists('add_mime_types')) {
function add_mime_types($mime_types)
{
$mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
return $mime_types;
}
add_filter('upload_mimes', 'add_mime_types', 1, 1);
}
function filter_ptags_on_images($content)
{
return preg_replace('/\s*()?\s*(
)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
function fifteenten_scripts()
{
wp_enqueue_script('fifteenten-app', get_template_directory_uri() . '/js/dist/all.min.js', array(), THEME_VERSION, true);
wp_enqueue_style('fifteenten-css', get_template_directory_uri() . '/css/style.min.css', array(), THEME_VERSION);
wp_enqueue_style('fifteenten-stylesheet', get_template_directory_uri() . '/style.css', array(), THEME_VERSION);
// wp_enqueue_script('fifteenten-webpack', get_template_directory_uri() . '/js/dist/webpack.bundle.js', array(), THEME_VERSION, true);
// enables jquery on frontend
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'fifteenten_scripts');
// Disable Gutenberg everywhere.
add_filter('use_block_editor_for_post', '__return_false');
/**
* Disable Gutemburg on Specific Post Types.
*/
function mgc_gutenberg_filter($use_block_editor, $post_type)
{
if ('post' === $post_type) {
return true;
}
if ('page' === $post_type) {
return false;
}
return $use_block_editor;
}
// add_filter('use_block_editor_for_post_type', 'mgc_gutenberg_filter', 10, 2);
// Disable Gutenberg for widgets.
add_filter('use_widgets_blog_editor', '__return_false');
add_action('wp_enqueue_scripts', function () {
// Remove CSS on the front end.
wp_dequeue_style('wp-block-library');
// Remove Gutenberg theme.
wp_dequeue_style('wp-block-library-theme');
// Remove inline global CSS on the front end.
wp_dequeue_style('global-styles');
}, 20);
/**
*
* Enqeue Block Editor assets.
*/
add_action('enqueue_block_editor_assets', 'fifteenten_enqueue_block_editor_assets');
function fifteenten_enqueue_block_editor_assets()
{
wp_enqueue_style('fifteenten-editor-styles', get_template_directory_uri() . '/css/editor.min.css', array(), THEME_VERSION);
}
$post_type = "team"; // just for a showcase
// the basic support (menu_order is included in the page-attributes)
add_post_type_support($post_type, 'page-attributes');
// add a column to the post type's admin
// basically registers the column and sets it's title
add_filter('manage_' . $post_type . '_posts_columns', function ($columns) {
$columns['menu_order'] = "Order"; //column key => title
return $columns;
});
// display the column value
add_action('manage_' . $post_type . '_posts_custom_column', function ($column_name, $post_id) {
if ($column_name == 'menu_order') {
echo get_post($post_id)->menu_order;
}
}, 10, 2); // priority, number of args - MANDATORY HERE!
// make it sortable
$menu_order_sortable_on_screen = 'edit-' . $post_type; // screen name of LIST page of posts
add_filter('manage_' . $menu_order_sortable_on_screen . '_sortable_columns', function ($columns) {
// column key => Query variable
// menu_order is in Query by default so we can just set it
$columns['menu_order'] = 'menu_order';
return $columns;
});
// Allow SVG
add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {
global $wp_version;
if ($wp_version !== '4.7.1') {
return $data;
}
$filetype = wp_check_filetype($filename, $mimes);
return [
'ext' => $filetype['ext'],
'type' => $filetype['type'],
'proper_filename' => $data['proper_filename']
];
}, 10, 4);
function cc_mime_types($mimes)
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
function fix_svg()
{
echo '';
}
add_action('admin_head', 'fix_svg');
function f10_add_custom_query_var($vars)
{
$vars[] = "";
$vars[] = "keyword";
return $vars;
}
add_filter('query_vars', 'f10_add_custom_query_var');
add_shortcode('1510_AUTHOR_EMAIL', function () {
$author = get_field('advertising_consultant');
$email = ($author && get_field('email_address', $author)) ? get_field('email_address', $author) : "charlie.walker@walkerandsloan.com";
return $email;
});
$include = [];
foreach ($include as $file) {
require_once get_template_directory() . '' . $file . '.php';
}
// Remove and
from Contact Form 7
add_filter('wpcf7_autop_or_not', '__return_false');
/**
*
* Add URL Params here to enable get_query_var('var')
*
*/
function add_query_vars_filter($vars)
{
$vars[] = "";
return $vars;
}
add_filter('query_vars', 'add_query_vars_filter');
/**
* Extend WordPress search to include custom fields
*
* https://adambalee.com
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join($join)
{
global $wpdb;
if (is_search() || get_query_var('_s')) {
$join .= ' LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'cf_search_join');
/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function cf_search_where($where)
{
global $pagenow, $wpdb;
if (is_search() || get_query_var('_s')) {
$where = preg_replace(
"/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)",
$where
);
}
return $where;
}
add_filter('posts_where', 'cf_search_where');
/**
* Prevent duplicates
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function cf_search_distinct($where)
{
global $wpdb;
if (is_search() || get_query_var('_s')) {
return "DISTINCT";
}
return $where;
}
add_filter('posts_distinct', 'cf_search_distinct');
/**
* Add page slug to the class attribute in the body tag.
*/
function add_slug_body_class($classes)
{
global $post;
if (isset($post)) {
$classes[] = " " . $post->post_type . '-' . $post->post_name . " ";
}
return $classes;
}
add_filter('body_class', 'add_slug_body_class');
/**
* Autogenerate src setss
*/
function acf_responsive_img($image, $size, $max_width, $class = "", $alt = "", $lazy = true)
{
$id = is_array($image) ? $image['id'] : $image;
if (!$id) return;
// set the default src image size
$src = wp_get_attachment_image_url($id, $size);
// set the srcset with various image sizes
$srcset = wp_get_attachment_image_srcset($id, $size);
if ($lazy) : ?>
else : ?>
endif;
}
/**
* use with the File field in ACF if elem could be video or image
*/
function outputMedia($media, $size = null, $max_width = null, $class = null, $attributes = ['autoplay', 'muted', 'loop="true"', 'playsinline'])
{
if (!$media) return;
if ($media['type'] == 'image') : ?>
acf_responsive_img($media['id'], $size, $max_width, $class); ?>
elseif ($media['type'] == 'video') : ?>