Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpcs fixes #157

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions includes/class-syndication-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ public static function display_valid_notices() {
foreach( $message_values as $message_key => $message_data ) {
$dismiss_nonce = wp_create_nonce( esc_attr( $message_key ) );
printf( '<div class="%s"><p>', esc_attr( $message_data['class'] ) );
printf( __('%1$s : %2$s <a href="%3$s">Hide Notice</a>'), esc_html( $message_type ), wp_kses_post( $message_data['message_text'] ), add_query_arg( array( self::$dismiss_parameter => esc_attr( $message_key ), 'syn_dismiss_nonce' => esc_attr( $dismiss_nonce ) ) ) );
printf(
__('%1$s : %2$s <a href="%3$s">Hide Notice</a>'), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html( $message_type ),
wp_kses_post( $message_data['message_text'] ),
esc_url( add_query_arg(
array(
self::$dismiss_parameter => esc_attr( $message_key ),
'syn_dismiss_nonce' => esc_attr( $dismiss_nonce )
)
) )
);
printf( '</p></div>' );
}
}
Expand All @@ -112,9 +122,9 @@ public static function handle_dismiss_syndication_notice() {
if ( isset( $_GET[self::$dismiss_parameter] ) && current_user_can( $capability ) ) {

$dismiss_key = esc_attr( $_GET[self::$dismiss_parameter] );
$dismiss_nonce = esc_attr( $_GET['syn_dismiss_nonce'] );
$dismiss_nonce = esc_attr( isset( $_GET['syn_dismiss_nonce'] ) ? $_GET['syn_dismiss_nonce'] : '' );
if ( ! wp_verify_nonce( $dismiss_nonce, $dismiss_key ) ) {
wp_die( __( "Invalid security check" ) );
wp_die( esc_html__( "Invalid security check" ) );
}
$messages = get_option( self::$notice_option );
$notice_bundles = get_option( self::$notice_bundles_option );
Expand Down
3 changes: 2 additions & 1 deletion includes/class-syndication-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function log( $storage_type, $msg_type, $object_type = 'post', $object_i
}

if ( ! empty( $log_time ) ) {
$log_entry['time'] = date('Y-m-d H:i:s', strtotime( $log_time ) );
$log_entry['time'] = gmdate('Y-m-d H:i:s', strtotime( $log_time ) );
} else {
$log_entry['time'] = current_time('mysql');
}
Expand All @@ -288,6 +288,7 @@ private function log( $storage_type, $msg_type, $object_type = 'post', $object_i


if ( true === $this->use_php_error_logging ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $this->format_log_message( $msg_type, $log_entry ) );
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-syndication-site-auto-retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function handle_pull_failure_event( $site_id = 0, $failed_attempts = 0 )
// and hence order better in the log viewer
// without this, sometimes when the pull occurs quickly
// these log items appear to occur at the same time as the failure
$log_time = date( 'Y-m-d H:i:s', $time_now + 1 );
$log_time = gmdate( 'Y-m-d H:i:s', $time_now + 1 );

// Are we still below the auto retry limit?
if ( $site_auto_retry_count < $auto_retry_limit ) {
Expand Down
53 changes: 27 additions & 26 deletions includes/class-wp-push-syndication-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class WP_Push_Syndication_Server {

function __construct() {

$this->push_syndicate_default_settings = array(
'selected_pull_sitegroups' => array(),
'selected_post_types' => array( 'post' ),
'delete_pushed_posts' => 'off',
'pull_time_interval' => '3600',
'update_pulled_posts' => 'off',
'client_id' => '',
'client_secret' => ''
);

$this->push_syndicate_settings = wp_parse_args( (array) get_option( 'push_syndicate_settings' ), $this->push_syndicate_default_settings );

// initialization
add_action( 'init', array( $this, 'init' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
Expand Down Expand Up @@ -136,18 +148,6 @@ public function init() {
'capabilities' => $taxonomy_capabilities,
));

$this->push_syndicate_default_settings = array(
'selected_pull_sitegroups' => array(),
'selected_post_types' => array( 'post' ),
'delete_pushed_posts' => 'off',
'pull_time_interval' => '3600',
'update_pulled_posts' => 'off',
'client_id' => '',
'client_secret' => ''
);

$this->push_syndicate_settings = wp_parse_args( (array) get_option( 'push_syndicate_settings' ), $this->push_syndicate_default_settings );

$this->version = get_option( 'syn_version' );

do_action( 'syn_after_init_server' );
Expand Down Expand Up @@ -183,7 +183,7 @@ public function manage_columns( $column_name, $id ) {
$client_data = $client->get_client_data();
echo esc_html( sprintf( '%s (%s)', $client_data['name'], array_shift( $client_data['modes'] ) ) );
} catch ( Exception $e ) {
printf( __( 'Unknown (%s)', 'push-syndication' ), esc_html( $transport_type ) );
printf( esc_html__( 'Unknown (%s)', 'push-syndication' ), esc_html( $transport_type ) );
}
break;
case 'syn_sitegroup':
Expand Down Expand Up @@ -346,7 +346,7 @@ public function display_pull_sitegroups_selection() {

<p>
<label>
<input type="checkbox" name="push_syndicate_settings[selected_pull_sitegroups][]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $this->push_syndicate_settings['selected_pull_sitegroups'] ) ?> />
<input type="checkbox" name="push_syndicate_settings[selected_pull_sitegroups][]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $this->push_syndicate_settings['selected_pull_sitegroups'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
<?php echo esc_html( $sitegroup->name ); ?>
</label>
<?php echo esc_html( $sitegroup->description ); ?>
Expand Down Expand Up @@ -421,7 +421,7 @@ public function display_post_types_selection() {

<li>
<label>
<input type="checkbox" name="push_syndicate_settings[selected_post_types][]" value="<?php echo esc_attr( $post_type ); ?>" <?php echo $this->checked_array( $post_type, $this->push_syndicate_settings['selected_post_types'] ); ?> />
<input type="checkbox" name="push_syndicate_settings[selected_post_types][]" value="<?php echo esc_attr( $post_type ); ?>" <?php echo $this->checked_array( $post_type, $this->push_syndicate_settings['selected_post_types'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
<?php echo esc_html( $post_type ); ?>
</label>
</li>
Expand Down Expand Up @@ -560,7 +560,7 @@ public function display_sitegroups_selection() {

<p>
<label>
<input type="checkbox" name="syn_selected_sitegroups[]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $selected_sitegroups ) ?> />
<input type="checkbox" name="syn_selected_sitegroups[]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $selected_sitegroups ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
<?php echo esc_html( $sitegroup->name ); ?>
</label>
<?php echo esc_html( $sitegroup->description ); ?>
Expand Down Expand Up @@ -621,7 +621,7 @@ public function add_site_status_metabox( $site ) {
<div id="major-publishing-actions">

<div id="delete-action">
<a class="submitdelete deletion" href="<?php echo get_delete_post_link($site->ID); ?>"><?php echo __( 'Move to Trash', 'push-syndication' ); ?></a>
<a class="submitdelete deletion" href="<?php echo get_delete_post_link($site->ID); ?>"><?php echo esc_html__( 'Move to Trash', 'push-syndication' ); ?></a>
</div>

<div id="publishing-action">
Expand Down Expand Up @@ -663,7 +663,7 @@ public function add_site_settings_metabox( $post ) {
try {
Syndication_Client_Factory::display_client_settings( $post, $transport_type );
} catch( Exception $e ) {
echo $e;
echo $e; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

?>
Expand All @@ -684,7 +684,7 @@ public function display_transports( $transport_type, $mode ) {
$max_len = 0;
foreach( $this->push_syndicate_transports as $key => $value ) {
$mode = array_shift( $value['modes'] );
echo '<option value="' . esc_html( $key ) . '"' . selected( $key, $transport_type ) . '>' . sprintf( esc_html__( '%s (%s)' ), $value['name'], $mode ) . '</option>';
echo '<option value="' . esc_html( $key ) . '"' . selected( $key, $transport_type ) . '>' . sprintf( esc_html__( '%s (%s)' ), $value['name'], $mode ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo '</select>';

Expand All @@ -702,12 +702,12 @@ public function save_site_settings() {
if( !isset( $_POST['site_settings_noncename'] ) || !wp_verify_nonce( $_POST['site_settings_noncename'], plugin_basename( __FILE__ ) ) )
return;

$transport_type = sanitize_text_field( $_POST['transport_type'] ); // TODO: validate this exists
$transport_type = sanitize_text_field( isset( $_POST['transport_type'] ) ? $_POST['transport_type'] : '' );

// @TODO validate that type and mode are valid
update_post_meta( $post->ID, 'syn_transport_type', $transport_type );

$site_enabled = sanitize_text_field( $_POST['site_enabled'] );
$site_enabled = sanitize_text_field( isset( $_POST['site_enabled'] ) ? $_POST['site_enabled'] : '' );

try {
$save = Syndication_Client_Factory::save_client_settings( $post->ID, $transport_type );
Expand Down Expand Up @@ -808,7 +808,7 @@ public function add_syndicate_metabox( ) {
?>
<li>
<label>
<input type="checkbox" name="selected_sitegroups[]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $selected_sitegroups ) ?> />
<input type="checkbox" name="selected_sitegroups[]" value="<?php echo esc_html( $sitegroup->slug ); ?>" <?php $this->checked_array( $sitegroup->slug, $selected_sitegroups ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> />
<?php echo esc_html( $sitegroup->name ); ?>
</label>
<p> <?php echo esc_html( $sitegroup->description ); ?> </p>
Expand Down Expand Up @@ -1222,7 +1222,6 @@ public function current_user_can_syndicate() {
}

public function cron_add_pull_time_interval( $schedules ) {

// Adds the custom time interval to the existing schedules.
$schedules['syn_pull_time_interval'] = array(
'interval' => intval( $this->push_syndicate_settings['pull_time_interval'] ),
Expand Down Expand Up @@ -1485,9 +1484,11 @@ private function upgrade() {
foreach ( $inserted_posts_by_site as $site_id ) {
$inserted_posts = get_post_meta( $site_id, 'syn_inserted_posts', true );

foreach ( $inserted_posts as $inserted_post_id => $inserted_post_guid ) {
update_post_meta( $inserted_post_id, 'syn_post_guid', $inserted_post_guid );
update_post_meta( $inserted_post_id, 'syn_source_site_id', $site_id );
if ( is_array( $inserted_posts ) ) {
foreach ( $inserted_posts as $inserted_post_id => $inserted_post_guid ) {
update_post_meta( $inserted_post_id, 'syn_post_guid', $inserted_post_guid );
update_post_meta( $inserted_post_id, 'syn_source_site_id', $site_id );
}
}
}

Expand Down