Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ab3ef6a
Publicize: Creates REST endpoint for publish without Publicize
c-shultz Mar 21, 2018
8dada53
Publicize: Typo fix in meta key
c-shultz Mar 21, 2018
3c5311e
Publicize: Removes publish action from new endpoint
c-shultz Mar 22, 2018
ef41f5f
Publicize: Changing meta key name to lowercase
c-shultz Mar 22, 2018
07c47da
Publicize: Adds endpoint to directly publicize a post
c-shultz Mar 22, 2018
24f8fb9
Publicize: Docblock cleanup
c-shultz Mar 22, 2018
756b2bb
Publicize: Utilize experimental HTTP header to differentiate Gutenber…
c-shultz Mar 28, 2018
b52aaf9
Publicize: hooking into Gutenberg to display publicize form.
c-shultz Mar 30, 2018
38799e8
Publicize: Adding modular React UI for Gutenberg integration
c-shultz Apr 3, 2018
710ecb4
Publicize: Move Gutenberg extensiblity to pre-publish flow
c-shultz Apr 10, 2018
08b4b22
Publicize: Remove connection list from Publicize title
c-shultz Apr 12, 2018
f26d1db
Publicize: Adding connection verification
c-shultz Apr 12, 2018
5ca43c8
Publicize: Adding service links for non-connected users
c-shultz Apr 13, 2018
51bf51f
Publicize: Change publicize form data format
c-shultz Apr 14, 2018
23cfc9a
Publicize: Fixing ES6 compliance
c-shultz Apr 18, 2018
df0e83e
Publicize: Adding dynamic connection list refreshing
c-shultz Apr 19, 2018
b6920e1
Publicize: Move Publicize request processing to before publishing
c-shultz Apr 19, 2018
291c0b7
Publicize: Style cleanup
c-shultz Apr 19, 2018
21a6bcb
Publicize: Add post ID to connection list request
c-shultz Apr 20, 2018
a317e0d
Publicize: Comment cleanup
c-shultz Apr 20, 2018
8fdd1f3
Publicize: Adding PHP unit tests for 'publicize' field processing
c-shultz Apr 21, 2018
041a31a
Publicize: UI tweaks for Publicize in Gutenberg.
c-shultz Apr 23, 2018
b2c74cf
Jetpack: Adding modules directory to lint path
c-shultz Apr 23, 2018
66f747d
Publicize: Connection icon and related UI tweaks for Publicize in Gut…
c-shultz Apr 23, 2018
0624e73
Publicize: Make Publicize form values persistent
c-shultz Apr 23, 2018
19e4931
Publicize: Set maximum character limit
c-shultz Apr 23, 2018
6cc593e
Publicize: CSS tweak for character count
c-shultz Apr 24, 2018
fa91ebc
Publicize: Adding Readme about how Publicize works
c-shultz Apr 27, 2018
08c999b
Publicize: Make done_sharing_post method public
c-shultz May 1, 2018
e61595f
Publicize: Adding simple test coverage for Publicize helper methods
c-shultz May 1, 2018
57b3e3e
Publicize: Adding test coverage for get_filtered_connection_data filters
c-shultz May 1, 2018
54f51f9
Publicize: Removing ui.php changes
c-shultz May 2, 2018
4d5a3b0
Publicize: Use get_filtered_connection_data method from separate branch
c-shultz May 2, 2018
51e8471
Publicize: use REST for connection request
c-shultz May 3, 2018
8e60b5c
Publicize: Adding simple front-end unit testing
c-shultz May 4, 2018
b8557ca
Publicize: Whitespace cleanup in .jsx files
c-shultz May 4, 2018
4172f10
Publicize: Removing 'href="javascript:void(0)"'
c-shultz May 4, 2018
1e866df
Publicize: climbing out of boolean trap
c-shultz May 4, 2018
9c5bb68
Publicize: replacing three dots with ellipsis
c-shultz May 4, 2018
6763385
Publicize: Separate PublicizeForm from data handling
c-shultz May 4, 2018
3127bf8
Publicize: Unit testing for PublicizeFormUnwrapped
c-shultz May 4, 2018
1527ae7
Publicize: utilizing classnames in Publicize form
c-shultz May 4, 2018
28d85d4
Publicize: using 'some' to simplify code
c-shultz May 4, 2018
c8b5b7f
Publicize: remove 'null == ' conditions
c-shultz May 4, 2018
6b688d7
Publicize: Adding data store for Publicize data
c-shultz May 4, 2018
2ec05c7
Publicize: Getting post id from editor
c-shultz May 4, 2018
c9bd2d2
Publicize: Move ajax connection request to utility file
c-shultz May 4, 2018
d8a46b2
Publicize: Adding close link to connection page
c-shultz May 4, 2018
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
27 changes: 27 additions & 0 deletions modules/publicize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Jetpack - Publicize Module
==============
[See Publicize Description](https://jetpack.com/support/publicize/)

## How Publicize Works
1. Client submits request to publish post
2. Publicize catches incoming post and sets post meta to configure sharing options
3. Post is published
4. WP.com receives publishing post and shares to connected social media accounts based on post meta


### Meta Keys
#### Skipping connections

By default, if a post is published when Publicize is enabled, WP.com shares it to the current user's connected social media accounts.

If a post should not be shared to a connection, the appropriate post meta must be set by Publicize.

The meta key prefix to skip a connection is `_wpas_skip_`. WP.com will skip sharing a post to a connection if this meta key is set for a given connection id.

For example, for a connection ID `'123'` Publicize would flag it to be skipped by setting post meta key `_wpas_skip_123` to a value of `1`.

#### Post Message
A message string can be added to the social media posts by setting the `_wpas_mess` to any user provided string.

#### Done Sharing
Publicize will only allow a post to be shared once. When a post is published, Publicize sets the `_wpas_done_all` post meta key. After a post has been flagged by `_wpas_done_all`, Publicize will not share it again.
87 changes: 87 additions & 0 deletions modules/publicize/assets/gutenberg_client/async-publicize-lib.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Data access functions for Publicizing in Gutenberg.
*
* This file contains a set of helper functions that
* gather data and/or send requests for data to support
* the features of Publicize in Gutenberg.
*
* @file Data access functions for Gutenberg Publicize extension.
* @since 5.9.1
*/

/**
* Internal dependencies
*/
const {
gutenberg_publicize_setup,
wp,
ajaxurl,
} = window;

/**
* Get connection form set up data.
*
* Retrieves array of filtered connection UI data (labels, checked value,
* URLs, etc.) from window global. This data only updates on refresh.
*
* @see ui.php
*
* @since 5.9.1
*
* @return {object} List of filtered connection UI data.
*/
export function getStaticPublicizeConnections() {
return JSON.parse( gutenberg_publicize_setup.staticConnectionList );
}

/**
* Get up-to-date connection list data for post.
*
* Retrieves array of filtered connection UI data (labels, checked value).
* Connection list is queried based on post id because the connection
* filtering depends on current post.
*
* @see ui.php
*
* @since 5.9.1
*
* @param {integer} postId ID of post to query connection defaults for.
*
* @return {Promise} Promise for connection request.
*/
export function requestPublicizeConnections( postId ) {
return wp.apiRequest( {
path: '/publicize/posts/' + postId.toString() + '/connections',
contentType: 'application/json',
dataType: 'json',
processData: false,
method: 'GET',
} );
}

/**
* Gets list of all possible connections.
*
* Gets list of possible social sites ('twitter', 'facebook, etc..')
*
* @since 5.9.1
*
* @return {object} List of possible services that can be connected to
*/
export function getAllConnections() {
return JSON.parse( gutenberg_publicize_setup.allServices );
}

/**
* Verifies that all connections are still functioning.
*
* Ajax request handled by 'wp_ajax_test_publicize_conns' action
* in {@see publicize.php}.
*
* @since 5.9.1
*
* @return {object} List of possible services that can be connected to
*/
export function requestTestPublicizeConnections() {
return $.post( ajaxurl, { action: 'test_publicize_conns' } );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Publicize connections verification component.
*
* Component to create Ajax request to check
* all connections. If any connection tests failed,
* a refresh link may be provided to the user. If
* no connection tests fail, this component will
* not render anything.
*
* @since 5.9.1
*/

/**
* External dependencies
*/
import React, { Component } from 'react';

/**
* Internal dependencies
*/
import { requestTestPublicizeConnections } from './async-publicize-lib';
const { __ } = window.wp.i18n;

class PublicizeConnectionVerify extends Component {
constructor( props ) {
super( props );
this.state = {
failedConnections: {},
isLoading: false,
};
}

/**
* Callback for connection test request
*
* Receives results of connection request and
* updates component state to display potentially
* failed connections.
*
* @since 5.9.1
*
* @param {object} response Response from ajax action 'wp_ajax_test_publicize_conns' {@see publicize.php}
*/
connectionTestComplete = ( response ) => {
const failureList = response.data.filter( connection => ( ! connection.connectionTestPassed ) );
this.setState( {
failedConnections: failureList,
isLoading: false,
} );
}

/**
* Starts request to check connections
*
* Checks connections with ajax action 'wp_ajax_test_publicize_conns'
*
* @see publicize.php
*
* @since 5.9.1
*/
connectionTestStart = () => {
requestTestPublicizeConnections().then(
() => this.connectionTestComplete
);
};

/**
* Opens up popup so user can refresh connection
*
* Displays pop up with to specified URL where user
* can refresh a specific connection.
*
* @since 5.9.1
*
* @param {object} event Event instance for onClick.
*/
refreshConnectionClick = ( event ) => {
const { href, title } = event.target;
event.preventDefault();
// open a popup window
// when it is closed, kick off the tests again
const popupWin = window.open( href, title, '' );
window.setInterval( () => {
if ( false !== popupWin.closed ) {
this.connectionTestStart();
}
}, 500 );
}

componentDidMount() {
this.connectionTestStart();
}

render() {
const { failedConnections } = this.state;
if ( failedConnections.length > 0 ) {
return (
<div className="below-h2 error publicize-token-refresh-message">
<p key="error-title">{ __( 'Before you hit Publish, please refresh the following connection(s) to make sure we can Publicize your post:' ) }</p>
{ failedConnections.filter( c => c.userCanRefresh ).map( c =>
<a
className="pub-refresh-button button"
title={ c.refreshText }
href={ c.refreshURL }
target={ '_refresh_' + c.serviceName }
onClick={ this.refreshConnectionClick }
key={ c.connectionID }

>
{ c.refreshText }
</a>
) }

</div>
);
}
return null;
}
}

export default PublicizeConnectionVerify;

71 changes: 71 additions & 0 deletions modules/publicize/assets/gutenberg_client/publicize-connection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Publicize connection form component.
*
* Component to display connection label and a
* checkbox to enable/disable the connection for sharing.
*
* @since 5.9.1
*/

/**
* External dependencies
*/
import React, { Component } from 'react';
const {
FormToggle,
} = window.wp.components;

class PublicizeConnection extends Component {
/**
* Handler for when connection is enabled/disabled.
*
* Calls parent's change handler in this.prop so
* state change can be handled by parent.
*
* @since 5.9.1
*/
onConnectionChange = () => {
const { unique_id } = this.props.connectionData;
const { connectionChange, connectionOn } = this.props;
connectionChange( {
connectionID: unique_id,
shouldShare: ! connectionOn,
} );
}

render() {
const {
name,
label,
disabled,
display_name,
} = this.props.connectionData;
const { connectionOn } = this.props;
// Genericon names are dash separated
const socialName = name.replace( '_', '-' );

return (
<li>
<div className="publicize-jetpack-connection-container">
<label htmlFor={ label }className="jetpack-publicize-connection-label">
<span
title={ label }
className={ 'jetpack-publicize-gutenberg-social-icon social-logo social-logo__' + socialName }
>
</span>
<span>{ display_name }</span>
</label>
<FormToggle
id={ label }
className="jetpack-publicize-connection-toggle"
checked={ connectionOn }
onChange={ this.onConnectionChange }
disabled={ disabled }
/>
</div>
</li>
);
}
}

export default PublicizeConnection;
Loading