Skip to content
Merged
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
7 changes: 4 additions & 3 deletions projects/packages/publicize/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
// # Issue statistics:
// PhanPluginDuplicateConditionalNullCoalescing : 6 occurrences
// PhanTypeMismatchArgument : 6 occurrences
// PhanNoopNew : 3 occurrences
// PhanPluginUnreachableCode : 4 occurrences
// PhanPluginMixedKeyNoKey : 3 occurrences
// PhanTypeMismatchArgumentNullable : 3 occurrences
// PhanUndeclaredClassMethod : 3 occurrences
// PhanDeprecatedFunction : 2 occurrences
// PhanNoopNew : 2 occurrences
// PhanPossiblyUndeclaredVariable : 2 occurrences
// PhanTypeMismatchArgumentNullable : 2 occurrences
// PhanTypeMismatchReturnProbablyReal : 2 occurrences
// PhanTypeMissingReturn : 2 occurrences
// PhanImpossibleCondition : 1 occurrence
Expand Down Expand Up @@ -47,7 +48,7 @@
'src/social-image-generator/class-rest-settings-controller.php' => ['PhanPluginMixedKeyNoKey'],
'src/social-image-generator/class-settings.php' => ['PhanPluginDuplicateConditionalNullCoalescing'],
'src/social-image-generator/class-setup.php' => ['PhanTypeMismatchArgumentNullable'],
'tests/php/test-connections-post-field.php' => ['PhanTypeMismatchArgument'],
'tests/php/test-connections-post-field.php' => ['PhanPluginUnreachableCode', 'PhanTypeMismatchArgument'],
'tests/php/test-publicize-og-optimization.php' => ['PhanDeprecatedFunction'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Updated the connections schema for classic editor
13 changes: 12 additions & 1 deletion projects/packages/publicize/src/class-connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,25 @@ public static function get_all_for_user( $args = array() ) {

foreach ( $connections as $connection ) {

if ( $connection['shared'] || self::user_owns_connection( $connection ) ) {
if ( self::is_shared( $connection ) || self::user_owns_connection( $connection ) ) {
$connections_for_user[] = $connection;
}
}

return $connections_for_user;
}

/**
* Check whether a connection is shared.
*
* @param array $connection The connection.
*
* @return boolean
*/
public static function is_shared( $connection ) {
return ! empty( $connection['shared'] );
}

/**
* Whether the current user owns a connection.
*
Expand Down
81 changes: 19 additions & 62 deletions projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ public function __construct() {
// Alter the "Post Publish" admin notice to mention the Connections we Publicized to.
add_filter( 'post_updated_messages', array( $this, 'update_published_message' ), 20, 1 );

// Connection test callback.
add_action( 'wp_ajax_test_publicize_conns', array( $this, 'test_publicize_conns' ) );

// Custom priority to ensure post type support is added prior to thumbnail support being added to the theme.
add_action( 'init', array( $this, 'add_post_type_support' ), 8 );
add_action( 'init', array( $this, 'register_post_meta' ), 20 );
Expand Down Expand Up @@ -722,15 +719,6 @@ public function is_connecting_connection( $connection ) {
return isset( $connection_data['meta']['options_responses'] );
}

/**
* AJAX Handler to run connection tests on all Connections
*
* @return void
*/
public function test_publicize_conns() {
wp_send_json_success( $this->get_publicize_conns_test_results() );
}

/**
* Parse the error code returned by the XML-RPC API call.
*
Expand Down Expand Up @@ -885,19 +873,17 @@ public function get_filtered_connection_data( $selected_post_id = null ) {
$post_id = null;
}

// TODO Get these services->connections from the cache populated from the REST API.
$services = $this->get_services( 'connected' );
$all_done = $this->post_is_done_sharing( $post_id );

// We don't allow Publicizing to the same external id twice, to prevent spam.
$service_id_done = (array) get_post_meta( $post_id, $this->POST_SERVICE_DONE, true );

foreach ( $services as $service_name => $connections ) {
$connections = Connections::get_all_for_user();

if ( ! empty( $connections ) ) {

foreach ( $connections as $connection ) {
$connection_meta = $this->get_connection_meta( $connection );
$connection_data = $connection_meta['connection_data'];
$unique_id = $this->get_connection_unique_id( $connection );
$connection_id = $this->get_connection_id( $connection );
$service_name = $connection['service_name'];
$unique_id = $connection['id'];
$connection_id = $connection['connection_id'];
// Was this connection (OR, old-format service) already Publicized to?
$done = ! empty( $post ) && (
// Flags based on token_id.
Expand All @@ -916,10 +902,10 @@ public function get_filtered_connection_data( $selected_post_id = null ) {
* @param bool true Should the post be publicized to a given service? Default to true.
* @param int $post_id Post ID.
* @param string $service_name Service name.
* @param array $connection_data Array of information about all Publicize details for the site.
* @param array $connection The connection data.
*/
/* phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores */
if ( ! apply_filters( 'wpas_submit_post?', true, $post_id, $service_name, $connection_data ) ) {
if ( ! apply_filters( 'wpas_submit_post?', true, $post_id, $service_name, $connection ) ) {
continue;
}

Expand All @@ -943,15 +929,10 @@ public function get_filtered_connection_data( $selected_post_id = null ) {
)
||
(
is_array( $connection )
&&
isset( $connection_meta['external_id'] ) && ! empty( $service_id_done[ $service_name ][ $connection_meta['external_id'] ] )
isset( $connection['external_id'] ) && ! empty( $service_id_done[ $service_name ][ $connection['external_id'] ] )
)
);

// If this one has already been publicized to, don't let it happen again.
$toggleable = ! $done && ! $all_done;

// Determine the state of the checkbox (on/off) and allow filtering.
$enabled = $done || ! $skip;
/**
Expand All @@ -968,12 +949,9 @@ public function get_filtered_connection_data( $selected_post_id = null ) {
$enabled = apply_filters( 'publicize_checkbox_default', $enabled, $post_id, $service_name, $connection );

/**
* If this is a global connection and this user doesn't have enough permissions to modify
* those connections, don't let them change it.
* If this is a shared connection and this user doesn't have enough permissions to modify.
*/
if ( ! $done && $this->is_global_connection( $connection_meta ) && ! current_user_can( $this->GLOBAL_CAP ) ) {
$toggleable = false;

if ( ! $done && Connections::is_shared( $connection ) && ! current_user_can( $this->GLOBAL_CAP ) ) {
/**
* Filters the checkboxes for global connections with non-prilvedged users.
*
Expand All @@ -993,28 +971,11 @@ public function get_filtered_connection_data( $selected_post_id = null ) {
$enabled = true;
}

$connection_list[] = array(
// REST Meta fields.
'connection_id' => $connection_id,
'display_name' => $this->get_display_name( $service_name, $connection ),
'enabled' => $enabled,
'external_handle' => $this->get_external_handle( $service_name, $connection ),
'external_id' => $connection_meta['external_id'] ?? '',
'profile_link' => (string) $this->get_profile_link( $service_name, $connection ),
'profile_picture' => (string) $this->get_profile_picture( $connection ),
'service_label' => static::get_service_label( $service_name ),
'service_name' => $service_name,
'shared' => ! $connection_data['user_id'],
'status' => null,

// Deprecated fields.
'id' => $connection_id,
'unique_id' => $unique_id,
'username' => $this->get_username( $service_name, $connection ),
'done' => $done,
'toggleable' => $toggleable,
'global' => 0 == $connection_data['user_id'], // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual,WordPress.PHP.StrictComparisons.LooseComparison -- Other types can be used at times.
'user_id' => (int) $connection_data['user_id'],
$connection_list[] = array_merge(
$connection,
array(
'enabled' => $enabled,
)
);
}
}
Expand Down Expand Up @@ -1303,13 +1264,9 @@ public function should_submit_post_pre_checks( $post ) {
// - API/XML-RPC Test Posts
if (
(
defined( 'XMLRPC_REQUEST' )
&&
XMLRPC_REQUEST
( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
||
defined( 'APP_REQUEST' )
&&
APP_REQUEST
( defined( 'APP_REQUEST' ) && constant( 'APP_REQUEST' ) )
)
&&
str_starts_with( $post->post_title, 'Temporary Post Used For Theme Detection' )
Expand Down
Loading
Loading