Completed
Push — master ( 32d0b0...d48100 )
by Zack
58:19 queued 38:20
created

disable_content_analysis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 136.

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.

Loading history...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
113
114
		// New View page
115
		if( $pagenow === 'post-new.php' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
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' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $existing is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "GravityView_Plugin_Hooks_Yoast_SEO::__return_low" is invalid; only PHP magic methods should be prefixed with a double underscore
Loading history...
132
		return 'low';
133
	}
134
}
135
136
new GravityView_Plugin_Hooks_Yoast_SEO;