1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Add Yoast SEO scripts and styles to GravityView no-conflict list |
4
|
|
|
* |
5
|
|
|
* @file class-gravityview-plugin-hooks-yoast-seo.php |
6
|
|
|
* @package GravityView |
7
|
|
|
* @license GPL2+ |
8
|
|
|
* @author Katz Web Services, Inc. |
9
|
|
|
* @link http://gravityview.co |
10
|
|
|
* @copyright Copyright 2015, Katz Web Services, Inc. |
11
|
|
|
* |
12
|
|
|
* @since 1.15.2 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @inheritDoc |
17
|
|
|
* @since 1.15.2 |
18
|
|
|
*/ |
19
|
|
|
class GravityView_Plugin_Hooks_Yoast_SEO extends GravityView_Plugin_and_Theme_Hooks { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @inheritDoc |
23
|
|
|
* @since 1.15.2 |
24
|
|
|
*/ |
25
|
|
|
protected $constant_name = 'WPSEO_FILE'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
* @since 1.15.2 |
30
|
|
|
*/ |
31
|
|
|
protected $style_handles = array( |
32
|
|
|
'wp-seo-metabox', |
33
|
|
|
'wpseo-admin-media', |
34
|
|
|
'yoast-seo-metabox-css', |
35
|
|
|
'yoast-seo-admin-media', |
36
|
|
|
'yoast-seo-scoring', |
37
|
|
|
'yoast-seo-snippet', |
38
|
|
|
'yoast-seo-select2', |
39
|
|
|
'yoast-seo-kb-search', |
40
|
|
|
'metabox-tabs', |
41
|
|
|
'metabox-classic', |
42
|
|
|
'metabox-fresh', |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritDoc |
47
|
|
|
* @since 1.15.2 |
48
|
|
|
*/ |
49
|
|
|
protected $script_handles = array( |
50
|
|
|
'wp-seo-metabox', |
51
|
|
|
'wpseo-admin-media', |
52
|
|
|
'yoast-seo-metabox', |
53
|
|
|
'yoast-seo-admin-media', |
54
|
|
|
'yoast-seo-post-scraper', |
55
|
|
|
'yoast-seo-replacevar-plugin', |
56
|
|
|
'yoast-seo-shortcode-plugin', |
57
|
|
|
'jquery-qtip', |
58
|
|
|
'jquery-ui-autocomplete', |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @inheritDoc |
63
|
|
|
* @copydoc GravityView_Plugin_and_Theme_Hooks::add_hooks() |
64
|
|
|
* @since 1.15.2 |
65
|
|
|
*/ |
66
|
|
|
protected function add_hooks() { |
67
|
|
|
|
68
|
|
|
parent::add_hooks(); |
69
|
|
|
|
70
|
|
|
if( gravityview_is_admin_page() ) { |
71
|
|
|
|
72
|
|
|
// Make Yoast metabox go down to the bottom please. |
73
|
|
|
add_filter( 'wpseo_metabox_prio', array( $this, '__return_low' ) ); |
74
|
|
|
|
75
|
|
|
// Prevent the SEO from being checked. Eesh. |
76
|
|
|
add_filter( 'wpseo_use_page_analysis', '__return_false' ); |
77
|
|
|
|
78
|
|
|
add_filter( 'option_wpseo', array( $this, 'disable_content_analysis' ) ); |
79
|
|
|
|
80
|
|
|
// WordPress SEO Plugin |
81
|
|
|
add_filter( 'option_wpseo_titles', array( $this, 'hide_wordpress_seo_metabox' ) ); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Don't try to analyze content for Views |
87
|
|
|
* |
88
|
|
|
* @since 1.22.4 |
89
|
|
|
* @param array $options Existing WPSEO options array |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function disable_content_analysis( $options ) { |
94
|
|
|
|
95
|
|
|
$options['keyword_analysis_active'] = false; |
96
|
|
|
$options['content_analysis_active'] = false; |
97
|
|
|
|
98
|
|
|
return $options; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Modify the WordPress SEO plugin's metabox behavior |
103
|
|
|
* |
104
|
|
|
* Only show when the View has been configured. |
105
|
|
|
* |
106
|
|
|
* @since 1.15.2 Moved from class-gravityview-admin-metaboxes.php |
107
|
|
|
* |
108
|
|
|
* @param array $options WP SEO options array |
109
|
|
|
* @return array Modified array if on post-new.php |
110
|
|
|
*/ |
111
|
|
|
public function hide_wordpress_seo_metabox( $options = array() ) { |
112
|
|
|
global $pagenow; |
|
|
|
|
113
|
|
|
|
114
|
|
|
// New View page |
115
|
|
|
if( $pagenow === 'post-new.php' ) { |
|
|
|
|
116
|
|
|
$options['hideeditbox-gravityview'] = true; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $options; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Return 'low' as the status for metabox priority when on a GravityView post type admin screen |
124
|
|
|
* |
125
|
|
|
* @since 1.15.2 Moved from class-gravityview-admin-metaboxes.php |
126
|
|
|
* @since 1.15.2 Added check for GravityView post type |
127
|
|
|
* |
128
|
|
|
* @param string $existing Existing priority. Default: `high` |
129
|
|
|
* @return string Returns 'low' |
130
|
|
|
*/ |
131
|
|
|
function __return_low( $existing = 'high' ) { |
|
|
|
|
132
|
|
|
return 'low'; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
new GravityView_Plugin_Hooks_Yoast_SEO; |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.