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.
Completed
Pull Request — master (#293)
by Chris
16:36 queued 14:25
created

pinterest-functions.php ➔ ppp_pt_add_meta_tab()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 2
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
// Exit if accessed directly
4
if ( ! defined( 'ABSPATH' ) ) {
5
	exit;
6
}
7
8
/**
9
 * Register the Pinterest metabox tab
10
 * @param  array $tabs The tabs
11
 * @return array       The tabs with Pinterest added
12
 */
13
function ppp_pt_add_meta_tab( $tabs ) {
14
	$tabs['pt'] = array( 'name' => __( 'Pinterest', 'ppp-txt' ), 'class' => 'icon-ppp-pt' );
15
16
	return $tabs;
17
}
18
add_filter( 'ppp_metabox_tabs', 'ppp_pt_add_meta_tab', 10, 1 );
19
20
/**
21
 * Register the metabox content for Pinterest
22
 * @param  array $content The existing metabox tokens
23
 * @return array          The metabox tokens with Pinterest added
24
 */
25
function ppp_pt_register_metabox_content( $content ) {
26
	$content[] = 'pt';
27
28
	return $content;
29
}
30
add_filter( 'ppp_metabox_content', 'ppp_pt_register_metabox_content', 10, 1 );
31
32
/**
33
 * The callback that adds Pinterest metabox content
34
 * @param  object $post The post object
35
 * @return void         Displays the metabox content
36
 */
37
function ppp_pt_add_metabox_content( $post ) {
38
	$pinterest_data = get_post_meta( $post->ID, '_ppp_pt_media', true );
39
	$defaults = array(
40
		'attachment_id' => '',
41
		'image'         => '',
42
	);
43
44
	$pinterest_data = wp_parse_args( $pinterest_data, $defaults );
45
	?>
46
	<p>
47
	<div class="ppp-post-override-wrap">
48
	<p><h3><?php _e( 'Pinterest Data', 'ppp-txt' ); ?></h3></p>
49
	<div id="ppp-pinterest-fields" class="ppp-pinterest-fields">
50
		<div id="ppp-pinterest-fields" class="ppp-meta-table-wrap">
51
			<table class="widefat ppp-repeatable-table" width="100%" cellpadding="0" cellspacing="0">
52
				<thead>
53
				<tr>
54
					<th style="width: 80%"><?php _e( 'Pinterest Image', 'ppp-txt' ); ?></th>
55
				</tr>
56
				</thead>
57
				<tbody>
58
					<tr class="ppp-pinterest-wrapper ppp-repeatable-row on-publish-row">
59
						<td class="ppp-repeatable-upload-wrapper" style="width: 200px">
60
							<div class="ppp-repeatable-upload-field-container">
61
								<input type="hidden" name="_ppp_pinterest_data[attachment_id]" class="ppp-repeatable-attachment-id-field" value="<?php echo esc_attr( absint( $pinterest_data['attachment_id'] ) ); ?>"/>
62
								<input type="text" class="ppp-repeatable-upload-field ppp-upload-field" name="_ppp_pinterest_data[image]" placeholder="<?php _e( 'Upload or Enter URL', 'ppp-txt' ); ?>" value="<?php echo esc_attr( $pinterest_data['image'] ); ?>" />
63
64
								<span class="ppp-upload-file">
65
							<a href="#" title="<?php _e( 'Insert File', 'ppp-txt' ) ?>" data-uploader-title="<?php _e( 'Insert File', 'ppp-txt' ); ?>" data-uploader-button-text="<?php _e( 'Insert', 'ppp-txt' ); ?>" class="ppp-upload-file-button" onclick="return false;">
66
								<span class="dashicons dashicons-upload"></span>
67
							</a>
68
						</span>
69
							</div>
70
						</td>
71
					</tr>
72
				</tbody>
73
			</table>
74
		</div>
75
	</div><!--end #edd_variable_price_fields-->
76
	<?php
77
}
78
add_action( 'ppp_generate_metabox_content-pt', 'ppp_pt_add_metabox_content', 10, 1 );
79
80
/**
81
 * Save the items in our meta boxes
82
 * @param  int $post_id The Post ID being saved
83
 * @param  object $post    The Post Object being saved
84
 */
85
function ppp_pt_save_post_meta_boxes( $post_id, $post ) {
86
87
	if ( ! ppp_should_save( $post_id, $post ) ) {
88
		return;
89
	}
90
91
	$pinterest_data = $_POST['_ppp_pinterest_data'];
92
93
	update_post_meta( $post_id, '_ppp_pt_media', $pinterest_data );
94
95
}
96
add_action( 'save_post', 'ppp_pt_save_post_meta_boxes', 10, 2 ); // save the custom fields
97
98
/**
99
 * Output the Pinterest OG Data
100
 *
101
 * @since  2.2
102
 * @return void
103
 */
104
function ppp_pt_open_graph_meta() {
105
106
	if ( ! is_single() ) {
107
		return;
108
	}
109
110
	global $post, $ppp_options;
111
112
	if ( ! array_key_exists( $post->post_type, $ppp_options['post_types'] ) ) {
113
		return;
114
	}
115
116
	echo ppp_pt_get_open_graph_meta();
117
}
118
add_action( 'wp_head', 'ppp_pt_open_graph_meta', 10 );
119
120
/**
121
 * Generates the Pinterest OG Content
122
 *
123
 * @since  2.2
124
 * @return string The Pinterest OG tags
125
 */
126
function ppp_pt_get_open_graph_meta() {
127
128
	$return = '';
129
130
	if ( ! is_single() ) {
131
		return $return;
132
	}
133
134
	global $post;
135
136
137
	if ( empty( $post ) ) {
138
		return;
139
	}
140
141
	$elements = ppp_pt_default_meta_elements();
142
	foreach ( $elements as $name => $content ) {
143
		$return .= '<meta name="' . $name . '" content="' . $content . '" />' . "\n";
144
	}
145
146
	return apply_filters( 'ppp_pt_og_data', $return );
147
148
}
149
150
/**
151
 * Sets an array of names and content for Pinterest OG Meta
152
 * for easy filtering by devs
153
 *
154
 * @since  2.2
155
 * @return array The array of keys and values for the Pinterest Meta
156
 */
157
function ppp_pt_default_meta_elements() {
158
	global $post;
159
160
	$elements       = array();
161
	$pinterest_data = get_post_meta( $post->ID, '_ppp_pt_media', true );
162
163
	if ( ! empty( $pinterest_data['image'] ) ) {
164
		$elements['og:image'] = $pinterest_data['image'];
165
166
		$thumb_id = ! empty( $pinterest_data['attachment_id'] ) ? (int) $pinterest_data['attachment_id'] : ppp_get_attachment_id_from_image_url( $pinterest_data['image'] ) ;
167
168
		if ( ! empty( $thumb_id ) ) {
169
			$alt_text = ppp_get_attachment_alt_text( $thumb_id );
170
			// When adding media via the WP Uploader, any 'alt text' supplied will be used as the accessible alt text.
171
			if ( ! empty( $alt_text ) ) {
172
				$elements['og:image:alt'] = esc_attr( $alt_text );
173
			}
174
		}
175
	}
176
177
	$elements['og:referenced'] = get_the_permalink( $post );
178
179
	return apply_filters( 'ppp_pt_og_elements', $elements );
180
}