1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Jetpack Compatibility File |
4
|
|
|
* See: http://jetpack.com/ |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
function twentysixteen_jetpack_setup() { |
8
|
|
|
/** |
9
|
|
|
* Add theme support for Responsive Videos. |
10
|
|
|
*/ |
11
|
|
|
add_theme_support( 'jetpack-responsive-videos' ); |
12
|
|
|
} |
13
|
|
|
add_action( 'after_setup_theme', 'twentysixteen_jetpack_setup' ); |
14
|
|
|
|
15
|
|
View Code Duplication |
function twentysixteen_init_jetpack() { |
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Add our compat CSS file for custom widget stylings and such. |
18
|
|
|
* Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production |
19
|
|
|
* or skip it entirely for wpcom. |
20
|
|
|
*/ |
21
|
|
|
if ( ! is_admin() ) { |
22
|
|
|
$version = false; |
23
|
|
|
if ( method_exists( 'Jetpack', 'is_development_version' ) ) { |
24
|
|
|
$version = Jetpack::is_development_version() ? filemtime( plugin_dir_path( __FILE__ ) . 'twentysixteen.css' ) : JETPACK__VERSION; |
25
|
|
|
} |
26
|
|
|
wp_enqueue_style( 'twentysixteen-jetpack', plugins_url( 'twentysixteen.css', __FILE__ ), array(), $version ); |
27
|
|
|
wp_style_add_data( 'twentysixteen-jetpack', 'rtl', 'replace' ); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
add_action( 'init', 'twentysixteen_init_jetpack' ); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Alter gallery widget default width. |
34
|
|
|
*/ |
35
|
|
|
function twentysixteen_gallery_widget_content_width( $width ) { |
36
|
|
|
return 390; |
37
|
|
|
} |
38
|
|
|
add_filter( 'gallery_widget_content_width', 'twentysixteen_gallery_widget_content_width' ); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Remove ratings from excerpts that are used as intro on blog index, single, and archive pages. |
42
|
|
|
*/ |
43
|
|
|
function twentysixteen_remove_share() { |
44
|
|
|
if ( is_single() || is_archive() || is_home() ) { |
45
|
|
|
remove_filter( 'the_excerpt', 'sharing_display', 19 ); |
46
|
|
|
if ( class_exists( 'Jetpack_Likes' ) ) { |
47
|
|
|
remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
add_action( 'loop_start', 'twentysixteen_remove_share' ); |
52
|
|
|
|
53
|
|
|
function twentysixteen_jetpack_lazy_images_compat() { |
54
|
|
|
if ( ! function_exists( 'wp_add_inline_script' ) ) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Since TwentySixteen outdents when window is resized, let's trigger a window resize |
59
|
|
|
// every time we lazy load an image on the TwentySixteen theme. |
60
|
|
|
wp_add_inline_script( |
61
|
|
|
'jetpack-lazy-images', |
62
|
|
|
"jQuery( document.body ).on( 'jetpack-lazy-loaded-image', function () { jQuery( window ).trigger( 'resize' ); } );" |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Priority needs to be 11 here so that we have already enqueued jetpack-lazy-images. |
67
|
|
|
add_action( 'wp_enqueue_scripts', 'twentysixteen_jetpack_lazy_images_compat', 11 ); |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.