Created
February 24, 2016 07:16
-
-
Save richardsweeney/e484c9689366c86e4431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register widget area. | |
* | |
* @link http://codex.wordpress.org/Function_Reference/register_sidebar | |
*/ | |
add_action( 'widgets_init', function() { | |
register_sidebar([ | |
'name' => __( 'Sidebar', 'shipyard' ), | |
'id' => 'sidebar-1', | |
'description' => '', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h1 class="widget-title">', | |
'after_title' => '</h1>', | |
]); | |
}); | |
/** | |
* Enqueue scripts and styles. | |
*/ | |
function shipyard_scripts() { | |
if ( true === shipyard_is_dev() ) { | |
$main_js = '/resources/js/all.js'; | |
$main_css = '/resources/css/main.css'; | |
} else { | |
$main_js = '/resources/js/all-min.js'; | |
$main_css = '/resources/css/main.min.css'; | |
} | |
$t10ns = array( | |
'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
); | |
wp_enqueue_style( 'shipyard-css', get_template_directory_uri() . $main_css, array(), filemtime( get_template_directory() . $main_css ) ); | |
wp_enqueue_script( 'shipyard-js', get_template_directory_uri() . $main_js, array( 'jquery' ), filemtime( get_template_directory() . $main_js ), true ); | |
wp_localize_script( 'shipyard-js', 'shipyard', $t10ns ); | |
} | |
add_action( 'wp_enqueue_scripts', 'shipyard_scripts' ); | |
/** | |
* Output a SVG-file via an include | |
* | |
* @param $svg_file | |
* | |
* @return void | |
*/ | |
function shipyard_render_svg( $svg_file ) { | |
$file_path = get_stylesheet_directory() . '/resources/img/' . $svg_file; | |
$compressed_file_path = get_stylesheet_directory() . '/resources/img/compressed/' . $svg_file; | |
if ( is_file( $compressed_file_path ) ) { | |
include( $compressed_file_path ); | |
} | |
elseif ( is_file( $file_path ) ) { | |
include( $file_path ); | |
} | |
} | |
/** | |
* Disable WooCommerce default stylesheet | |
*/ | |
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' ); | |
/** | |
* Change the Login Logo | |
*/ | |
add_action( 'login_enqueue_scripts', function() { | |
$shipyard_logo = get_theme_mod( 'shipyard_logo' ); | |
if ( ! empty( $shipyard_logo ) ) { ?> | |
<style type="text/css"> | |
.login h1 a { | |
background-image: url(<?php echo $shipyard_logo; ?>); | |
} | |
</style> | |
<?php } | |
}); | |
/* | |
* Change the link values so the logo links to your site ( wp-Login page ) | |
*/ | |
add_filter( 'login_headerurl', function() { | |
return home_url(); | |
}); | |
add_filter( 'login_headertitle', function() { | |
return get_bloginfo( 'name' ); | |
}); | |
/** | |
* Set the option for blog_visiblity automatically | |
* to avoid human error in this regard! | |
*/ | |
add_filter( 'pre_option_blog_public', function( $option ) { | |
$url = get_site_url(); | |
$is_visible = 0; | |
if ( false === strpos( $url, '.stage.o-lab.se' ) && false === strpos( $url, '.stage2.o-lab.se' ) && false === strpos( $url, '.dev' ) ) { | |
$is_visible = 1; | |
} | |
return $is_visible; | |
}); | |
/** | |
* Convert Yoast breadcrumbs to use Microdata | |
* May need tweaking in case your markup differs | |
* | |
* @params string $breadcrumbs Breadcrumb HTML | |
* @return string | |
**/ | |
add_filter( 'wpseo_breadcrumb_output', function( $breadcrumbs ) { | |
// Strip off enclosing XML namespace | |
$breadcrumbs = preg_replace( | |
'/<span xmlns:v="http:\/\/rdf.data-vocabulary.org\/#">(.*?)<\/span>/', | |
'$1', | |
$breadcrumbs | |
); | |
// Strip off enclosing breadcrumb span | |
$breadcrumbs = preg_replace( | |
'/<span typeof="v:Breadcrumb">(.*?)<\/span>/', | |
'$1', | |
$breadcrumbs | |
); | |
// convert each breadcrumb | |
$breadcrumbs = preg_replace( | |
'/<a href="([^"]+)" rel="v:url" property="v:title">([^<]+)<\/a>/', | |
'<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="$1" itemprop="url"><span class="breadcrumb" itemprop="title">$2</span></a></span>', | |
$breadcrumbs | |
); | |
return $breadcrumbs; | |
}); | |
/** | |
* Check if site is on stage | |
* | |
* @return bool | |
*/ | |
function shipyard_is_stage() { | |
if ( strpos( site_url(), 'stage' ) !== false ) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Check if site is on dev | |
* | |
* @return bool | |
*/ | |
function shipyard_is_dev() { | |
if ( strpos( site_url(), '.dev' ) !== false ) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Remove the VC message nag. | |
*/ | |
add_action( 'admin_init', function() { | |
setcookie( 'vchideactivationmsg', '1', strtotime( '+3 years' ), '/' ); | |
}); | |
/** | |
* Sanitize filename on upload | |
*/ | |
add_filter( 'sanitize_file_name', function( $filename ) { | |
$ext = end( explode( '.', $filename ) ); | |
// Replace all weird characters | |
$sanitized = preg_replace( '/[^a-zA-Z0-9-_.]/', '', substr( $filename, 0, - ( strlen( $ext ) + 1 ) ) ); | |
// Replace dots inside filename | |
$sanitized = str_replace( '.','-', $sanitized ); | |
return strtolower( $sanitized . '.' . $ext ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment