Completed
Push — master ( babeed...92cdcd )
by Zack
11s
created

GravityView_Theme_Hooks_Ultimate_Member   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 6
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add_hooks() 0 6 1
B parse_um_profile_post_content() 0 23 5
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 69.

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 Ultimate Member plugin compatibility to GravityView
4
 *
5
 * @file      class-gravityview-theme-hooks-ultimate-member.php
6
 * @package   GravityView
7
 * @license   GPL2+
8
 * @author    Katz Web Services, Inc.
9
 * @link      http://gravityview.co
10
 * @copyright Copyright 2016', Katz Web Services, Inc.
11
 *
12
 * @since 1.17.2
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 1.17.2
18
 */
19
class GravityView_Theme_Hooks_Ultimate_Member extends GravityView_Plugin_and_Theme_Hooks {
20
21
	/**
22
	 * @inheritDoc
23
	 * @since 1.17.2
24
	 */
25
	protected $constant_name = 'ultimatemember_version';
26
27
	function add_hooks() {
0 ignored issues
show
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...
28
		parent::add_hooks();
29
30
		// Needs to be early to be triggered before DataTables
31
		add_action( 'template_redirect', array( $this, 'parse_um_profile_post_content' ) );
32
	}
33
34
	/**
35
	 * Parse tab content in Ultimate Member profile tabs
36
	 *
37
	 * @since 1.17.2
38
	 *
39
	 * @param array $args Ultimate Member profile settings array
40
	 *
41
	 * @return void
42
	 */
43
	function parse_um_profile_post_content( $args = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
44
		global $ultimatemember;
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...
45
46
		if( ! $ultimatemember || ! is_object( $ultimatemember ) || ! class_exists( 'GravityView_View_Data' ) ) {
47
			return;
48
		}
49
50
		$active_tab_args = array(
51
			'name'        => $ultimatemember->profile->active_tab(),
52
			'post_type'   => 'um_tab',
53
			'numberposts' => 1,
54
		);
55
56
		$active_tab = get_posts( $active_tab_args );
57
58
		if ( ! $active_tab ) {
59
			return;
60
		}
61
62
		GravityView_View_Data::getInstance()->parse_post_content( $active_tab[0]->post_content );
63
64
		wp_reset_postdata();
65
	}
66
67
}
68
69
new GravityView_Theme_Hooks_Ultimate_Member;