GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WP_SYNDICATE   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 134
rs 10
c 0
b 0
f 0
wmc 24
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B init() 0 38 2
A add_meta_box() 0 8 2
A meta_box_wp_syndicate() 0 49 3
A meta_box_wp_syndicate_import_test() 0 3 1
F save_meta_box() 0 24 15
1
<?php
2
class WP_SYNDICATE {
3
4
	public function __construct() {
5
		add_action( 'init', array( $this, 'init' ) );
6
		add_action( 'save_post', array( $this, 'save_meta_box' ) );
7
	}
8
9
	public function init() {
10
		$capabilities = array(
11
		    'read_wp_syndicate',
12
			'edit_wp_syndicate',
13
			'delete_wp_syndicate',
14
			'edit_wp_syndicates',
15
			'edit_others_wp_syndicates',
16
			'publish_wp_syndicates',
17
			'read_private_wp_syndicates',
18
			'delete_wp_syndicates',
19
			'delete_private_wp_syndicates',
20
			'delete_published_wp_syndicates',
21
			'delete_others_wp_syndicates',
22
			'edit_private_wp_syndicates',
23
			'edit_published_wp_syndicates',
24
		);
25
26
		$role = get_role( 'administrator' );
27
		foreach ( $capabilities as $cap ) {
28
			$role->add_cap( $cap );
29
		}
30
		register_post_type( 'wp-syndicate',
31
			array(
32
	    								'labels' => array( 'name' => __( 'Syndication', WPSYND_DOMAIN ) ),
33
	    								'public' => true,
34
	    								'publicly_queryable' => false,
35
										'has_archive' => false,
36
	    								'hierarchical' => false,
37
	    								'supports' => array( 'title' ),
38
	    								'rewrite' => false,
39
	    								'can_export' => true,
40
	    								'menu_position' => 28,
41
	    								'capability_type' => 'wp_syndicate',
42
										'capabilities'    => $capabilities,
43
										'map_meta_cap' => true,
44
										'register_meta_box_cb' => array( $this, 'add_meta_box' ),
45
	    							));
46
	}
47
48
	public function add_meta_box() {
49
		global $hook_suffix;
50
51
		add_meta_box( 'wp_syndicate_meta_box', __( 'configuration', WPSYND_DOMAIN ), array( $this, 'meta_box_wp_syndicate' ),'wp-syndicate' );
52
		if ( 'post.php' === $hook_suffix ) {
53
			add_meta_box( 'wp_syndicate_meta_box_import_test', __( 'Import Test', WPSYND_DOMAIN ), array( $this, 'meta_box_wp_syndicate_import_test' ),'wp-syndicate' );
54
		}
55
	}
56
57
	public function meta_box_wp_syndicate() {
58
		wp_nonce_field( 'wp_syndicate_meta_box', 'wp_syndicate_meta_box_nonce' );
59
60
		$feed_url = get_post_meta( get_the_ID(), 'wp_syndicate-feed-url', true );
61
		$feed_retrieve_term = get_post_meta( get_the_ID(), 'wp_syndicate-feed-retrieve-term', true );
62
		$author_id = get_post_meta( get_the_ID(), 'wp_syndicate-author-id', true );
63
		$statuses = get_post_statuses();
64
		unset( $statuses['pending'] );
65
		$status = get_post_meta( get_the_ID(), 'wp_syndicate-default-post-status', true );
66
		$post_types = get_post_types( array( 'public' => true ) );
67
		$post_type = get_post_meta( get_the_ID(), 'wp_syndicate-default-post-type', true );
68
		$registration_method = get_post_meta( get_the_ID(), 'wp_syndicate-registration-method', true );
69
		$user_id = get_post_meta( get_the_ID(), 'wp_syndicate-basic-auth-user', true );
70
		$password = get_post_meta( get_the_ID(), 'wp_syndicate-basic-auth-pass', true );
71
72
?>
73
<table class="form-table">
74
<tr><th><?php esc_html_e( 'feed URL', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-feed-url" size="40" value="<?php echo esc_attr( $feed_url ); ?>" /></td></tr>
75
<tr><th><?php esc_html_e( 'feed retrieve term', WPSYND_DOMAIN ) ?></th><td><input type="number" step="1" min="1" max="999" name="wp_syndicate-feed-retrieve-term" size="20" value="<?php echo esc_attr( $feed_retrieve_term ); ?>" /> <?php esc_html_e( 'min', WPSYND_DOMAIN ) ?></td></tr>
76
<tr><th><?php esc_html_e( 'Author ID', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-author-id" size="7" value="<?php echo esc_attr( $author_id ); ?>" /></td></tr>
77
<tr><th><?php esc_html_e( 'Default Post Type', WPSYND_DOMAIN ) ?></th>
78
<td>
79
<select name="wp_syndicate-default-post-type">
80
<?php foreach ( $post_types as $key => $val ) : ?>
81
	<option <?php selected( $post_type, $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $val ); ?></option>
82
<?php endforeach; ?>
83
</select>
84
</td></tr>
85
<tr><th><?php esc_html_e( 'Default Post Status', WPSYND_DOMAIN ) ?></th>
86
<td>
87
<select name="wp_syndicate-default-post-status">
88
<?php foreach ( $statuses as $key => $val ) : ?>
89
	<option <?php selected( $status, $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $val ); ?></option>
90
<?php endforeach; ?>
91
</select>
92
</td></tr>
93
<tr><th><?php esc_html_e( 'Registration method', WPSYND_DOMAIN ) ?></th>
94
<td>
95
<select name="wp_syndicate-registration-method">
96
	<option <?php selected( $registration_method, 'insert' ); ?> value="insert">insert only</option>
97
	<option <?php selected( $registration_method, 'insert-or-update' ); ?> value="insert-or-update">insert or update</option>
98
</select>
99
</td></tr>
100
<tr><th><?php esc_html_e( 'Basic Auth User ID', WPSYND_DOMAIN ) ?></th><td><input type="text" name="wp_syndicate-basic-auth-user" size="40" value="<?php echo esc_attr( $user_id ); ?>" /></td></tr>
101
<tr><th><?php esc_html_e( 'Basic Auth Password', WPSYND_DOMAIN ) ?></th><td><input type="password" name="wp_syndicate-basic-auth-pass" size="40" value="<?php echo esc_attr( $password ); ?>" /></td></tr>
102
<?php do_action( 'wp_syndicate_add_metabox' ); ?>
103
</table>
104
<?php
105
	}
106
107
	public function meta_box_wp_syndicate_import_test($post) {
0 ignored issues
show
Unused Code introduced by
The parameter $post 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...
108
		submit_button( 'Save and Test Excute', 'primary', 'wp_syndicate_import_test_excute' );
109
	}
110
111
	public function save_meta_box( $post_id ) {
112
		if ( wp_is_post_revision( $post_id ) || get_post_type() !== 'wp-syndicate' || ! current_user_can( 'edit_wp_syndicate', $post_id )
113
				|| ! isset( $_POST['wp_syndicate_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wp_syndicate_meta_box_nonce'], 'wp_syndicate_meta_box' ) ) {
114
			return;
115
		}
116
117
		isset( $_POST['wp_syndicate-feed-url'] ) && update_post_meta( $post_id, 'wp_syndicate-feed-url', esc_url( $_POST['wp_syndicate-feed-url'] ) );
118
		isset( $_POST['wp_syndicate-feed-retrieve-term'] ) && update_post_meta( $post_id, 'wp_syndicate-feed-retrieve-term', absint( $_POST['wp_syndicate-feed-retrieve-term'] ) );
119
		isset( $_POST['wp_syndicate-author-id'] ) && update_post_meta( $post_id, 'wp_syndicate-author-id', absint( $_POST['wp_syndicate-author-id'] ) );
120
		isset( $_POST['wp_syndicate-default-post-status'] ) && update_post_meta( $post_id, 'wp_syndicate-default-post-status', trim( $_POST['wp_syndicate-default-post-status'] ) );
121
		isset( $_POST['wp_syndicate-default-post-type'] ) && update_post_meta( $post_id, 'wp_syndicate-default-post-type', trim( $_POST['wp_syndicate-default-post-type'] ) );
122
		isset( $_POST['wp_syndicate-registration-method'] ) && update_post_meta( $post_id, 'wp_syndicate-registration-method', trim( $_POST['wp_syndicate-registration-method'] ) );
123
		isset( $_POST['wp_syndicate-basic-auth-user'] ) && update_post_meta( $post_id, 'wp_syndicate-basic-auth-user', trim( $_POST['wp_syndicate-basic-auth-user'] ) );
124
		isset( $_POST['wp_syndicate-basic-auth-pass'] ) && update_post_meta( $post_id, 'wp_syndicate-basic-auth-pass', trim( $_POST['wp_syndicate-basic-auth-pass'] ) );
125
126
		if ( isset( $_POST['wp_syndicate_import_test_excute'] ) ) {
127
			remove_action( 'save_post', array( $this, 'save_meta_box' ) );
128
			$action = new WP_SYND_Action();
129
			$action->import( $post_id );
130
			add_action( 'save_post', array( $this, 'save_meta_box' ) );
131
		}
132
		
133
		do_action( 'wp_syndicate_save_meta_box', $post_id );
134
	}
135
}
136
new WP_SYNDICATE();
137