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

Add support for multiple Twitter Accounts #238

Merged
merged 40 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1d61c09
Added Twitter accounts list table.
iamdharmesh May 19, 2023
27125a4
Added Twitter Auth class.
iamdharmesh May 19, 2023
5fdb487
Added utils functions.
iamdharmesh May 19, 2023
d833b15
Added accounts list table in settings screen.
iamdharmesh May 19, 2023
41d3bf1
Added Twitter API class to handle API requests.
iamdharmesh May 26, 2023
1e477e5
Update settings section to add twitter accounts UI
iamdharmesh Jun 12, 2023
d062244
Added account toggle UI in gutenberg.
iamdharmesh Jun 13, 2023
570fc93
Merge branch 'develop' of github.com:10up/autoshare-for-twitter into …
iamdharmesh Jun 13, 2023
c436f0d
Fix PHP Unit tests.
iamdharmesh Jun 13, 2023
d38c678
Handled tweet to multiple account.
iamdharmesh Jun 13, 2023
49bfa8f
Created a component for status logs.
iamdharmesh Jun 14, 2023
ed4a85b
Update status log on classic editor.
iamdharmesh Jun 14, 2023
9b435c9
Added twitter accounts UI in classic editor.
iamdharmesh Jun 14, 2023
9a80486
Fix styles.
iamdharmesh Jun 14, 2023
917ba97
Added disconnect account functionality.
iamdharmesh Jun 14, 2023
15945f9
Don't load panel if we don't have any accounts connected.
iamdharmesh Jun 14, 2023
50c6e1a
Fix incorrect conditions
iamdharmesh Jun 14, 2023
5d1545b
Added aushare for default setting for each connected account.
iamdharmesh Jun 15, 2023
e469ffe
Enabled default autoshare in classic editor.
iamdharmesh Jun 15, 2023
ba267db
Added test plugin to skip twitter API calls.
iamdharmesh Jun 15, 2023
ca1698f
Updated admin tests as per new settings.
iamdharmesh Jun 15, 2023
d6ad95f
Added multi accounts e2e tests.
iamdharmesh Jun 15, 2023
235e13d
Update existing e2e editor tests.
iamdharmesh Jun 15, 2023
32dca28
Fix unit tests.
iamdharmesh Jun 15, 2023
c5af852
Update E2E worflow file.
iamdharmesh Jun 15, 2023
5b117cf
Fix plugin path in e2e workflow file.
iamdharmesh Jun 15, 2023
658b0be
Mock disconnect request.
iamdharmesh Jun 15, 2023
d228d42
Added tests for account check/uncheck.
iamdharmesh Jun 15, 2023
70dc122
Added Disconnect tests and added few commands to increase code reusab…
iamdharmesh Jun 15, 2023
d8d130f
Fix flaky tests
iamdharmesh Jun 15, 2023
6b331dd
Fixed flaky e2e tests.
iamdharmesh Jun 15, 2023
09570e5
Fixed unit tests.
iamdharmesh Jun 15, 2023
a47af3c
Revert "Fixed flaky e2e tests."
iamdharmesh Jun 15, 2023
3c0a00e
Different approach.
iamdharmesh Jun 15, 2023
6f1d182
Added retry mechanism in run mode.
iamdharmesh Jun 15, 2023
8537974
Update E2E tests.
iamdharmesh Jun 16, 2023
55ea4a7
EOF lines added and indentation changes.
iamdharmesh Jun 16, 2023
de20ace
Merge branch 'develop' of github.com:10up/autoshare-for-twitter into …
iamdharmesh Jun 26, 2023
5a24c7d
PR Feedback.
iamdharmesh Jun 28, 2023
5c8000a
Update return type to bool on publish_tweet function.
iamdharmesh Jun 29, 2023
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
9 changes: 2 additions & 7 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ jobs:
run: npm install

- name: Set the core version and plugins config
run: ./tests/bin/set-wp-config.js --core=${{ matrix.core.version }} --plugins=./${{ github.event.repository.name }},https://downloads.wordpress.org/plugin/classic-editor.1.6.1.zip
run: ./tests/bin/set-wp-config.js --core=${{ matrix.core.version }} --plugins=./${{ github.event.repository.name }},https://downloads.wordpress.org/plugin/classic-editor.1.6.1.zip,./tests/test-plugin

- name: Set up WP environment
run: npm run env:start

- name: Test
run: npm run cypress:run
env:
CYPRESS_TWITTER_API_KEY: ${{ secrets.TWITTER_API_KEY_V2 }}
CYPRESS_TWITTER_API_SECRET: ${{ secrets.TWITTER_API_SECRET_V2 }}
CYPRESS_TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN_V2 }}
CYPRESS_TWITTER_ACCESS_SECRET: ${{ secrets.TWITTER_ACCESS_SECRET_V2 }}

- name: Update summary
if: always()
Expand All @@ -81,7 +76,7 @@ jobs:
cat ./tests/cypress/reports/mochawesome.md >> $GITHUB_STEP_SUMMARY

- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-artifact-autoshare-for-twitter
Expand Down
3 changes: 2 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"plugins": [
"https://downloads.wordpress.org/plugin/classic-editor.1.6.1.zip",
"."
".",
"./tests/test-plugin"
],
"env": {
"tests": {
Expand Down
9 changes: 7 additions & 2 deletions assets/css/admin-autoshare-for-twitter-settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
display: flex;
}

.autoshare-settings form {
.autoshare-settings .settings-wrapper {
width: 70%;
margin-right: 50px;
}
Expand All @@ -96,8 +96,13 @@
}
}

.autoshare-settings table.twitter_accounts th,
.autoshare-settings table.twitter_accounts td {
padding: 8px 10px;
}

@media (min-width: 1200px) {
.autoshare-settings form {
.autoshare-settings .settings-wrapper {
width: 60%;
margin-right: 10%;
}
Expand Down
48 changes: 48 additions & 0 deletions assets/css/admin-autoshare-for-twitter.css
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,51 @@ tbody .autoshare-for-twitter-status-logo--disabled::before {
.autoshare-for-twitter-editor-panel .autoshare-for-twitter-tweet-text label {
width: 100%;
}

.autoshare-settings .twitter-account-profile-image {
float:left;
margin-right: 10px;
border-radius: 50%;
max-width: 48px;
}

.autoshare-for-twitter-accounts-wrapper {
margin-top: 24px;
}

#autoshare_for_twitter_metabox .autoshare-for-twitter-accounts-wrapper {
margin-top: 12px;
}

.autoshare-for-twitter-accounts-wrapper .twitter-account-wrapper {
display: flex;
align-items: center;
width: 100%;
margin-bottom: 8px;
}

.autoshare-for-twitter-accounts-wrapper .twitter-account-wrapper img {
max-width: 36px;
max-height: 36px;
border-radius: 50%;
}

.autoshare-for-twitter-accounts-wrapper .twitter-account-wrapper span.account-details {
padding-left: 8px;
padding-right: 8px;
}

#autoshare_for_twitter_metabox .twitter-account-wrapper input.autoshare-for-twitter-account-checkbox{
margin-left: auto;
}

.autoshare-for-twitter-accounts-wrapper .twitter-account-wrapper .autoshare-for-twitter-account-toggle {
margin-top: 10px;
margin-bottom: 10px;
margin-left: auto;
}

.autoshare-for-twitter-accounts-wrapper .twitter-account-wrapper span.connect-account-link {
margin-top: 12px;
display: block;
}
30 changes: 25 additions & 5 deletions assets/js/admin-autoshare-for-twitter-classic-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Event handlers.
$tweetPost.on('click', handleRequest);
$tweetText.change(handleRequest);
$tweetPost.change(toggleAllowImageVisibility);
$tweetPost.change(toggleVisibility);
$allowTweetImage.change(handleRequest);
$editLink.on('click', function() {
$editBody.slideToggle();
Expand All @@ -42,6 +42,7 @@
$('#autoshare-for-twitter-override-body').slideToggle();
$editLink.show();
});
$('input.autoshare-for-twitter-account-checkbox').on('change', handleRequest);

// Runs on page load to auto-enable posts to be tweeted
window.onload = function(event) {
Expand All @@ -66,19 +67,24 @@

$icon.removeClass('pending');
$tweetPost.prop('checked', false);
$('#submit').attr('disabled', true);
$('#publish').prop('disabled', false);
}

/**
* AJAX handler
* @param event
*/
function handleRequest(event, status = $tweetPost.prop('checked')) {
var data = {};
let data = {};
let enabledAccounts = [];
$('input.autoshare-for-twitter-account-checkbox:checked').each(function() {
enabledAccounts.push($(this).val());
});
data[adminAutoshareForTwitter.enableAutoshareKey] = status;
data[adminAutoshareForTwitter.tweetBodyKey] = $tweetText.val();
data[adminAutoshareForTwitter.allowTweetImageKey] = $allowTweetImage.prop('checked');
$('#submit').attr('disabled', true);
data[adminAutoshareForTwitter.tweetAccountsKey] = enabledAccounts;
$('#publish').prop('disabled', true);

wp.apiFetch({
url: adminAutoshareForTwitter.restUrl,
Expand Down Expand Up @@ -113,7 +119,7 @@
$allowTweetImage.prop('checked', false);
}

$('#submit').attr('disabled', false);
$('#publish').prop('disabled', false);
})
.catch(onRequestFail);
}
Expand Down Expand Up @@ -173,6 +179,20 @@
$('#postimagediv').on( 'click', '#remove-post-thumbnail', toggleAllowImageVisibility );
}

/**
* Show/Hide accounts and visibility options.
*/
function toggleVisibility( event ) {
toggleAllowImageVisibility( event );
const autoshareEnabled = $tweetPost.prop('checked');
const accountsWrap = $('.autoshare-for-twitter-accounts-wrapper');
if ( autoshareEnabled ) {
accountsWrap.show();
} else {
accountsWrap.hide();
}
}

/**
* Show/Hide "Use featured image in Tweet" checkbox.
*/
Expand Down
22 changes: 21 additions & 1 deletion includes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

namespace TenUp\AutoshareForTwitter\Admin\Assets;

use TenUp\AutoshareForTwitter\Core\Twitter_Accounts as Twitter_Accounts;

use function TenUp\AutoshareForTwitter\Utils\get_autoshare_for_twitter_meta;
use function TenUp\AutoshareForTwitter\Utils\opted_into_autoshare_for_twitter;
use function TenUp\AutoshareForTwitter\REST\post_autoshare_for_twitter_meta_rest_route;
use function TenUp\AutoshareForTwitter\Utils\autoshare_enabled;
use function TenUp\AutoshareForTwitter\Utils\tweet_image_allowed;
use function TenUp\AutoshareForTwitter\Utils\get_tweet_accounts;
use function TenUp\AutoshareForTwitter\Utils\get_default_autoshare_accounts;

use const TenUp\AutoshareForTwitter\Core\Post_Meta\ENABLE_AUTOSHARE_FOR_TWITTER_KEY;
use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWEET_ACCOUNTS_KEY;
use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWEET_BODY_KEY;
use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWITTER_STATUS_KEY;
use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWEET_ALLOW_IMAGE;
Expand Down Expand Up @@ -157,6 +162,12 @@ function enqueue_editor_assets() {
return;
}

// Don't load if no Twitter accounts are configured.
$accounts = ( new Twitter_Accounts() )->get_twitter_accounts( true );
if ( empty( $accounts ) ) {
return;
}

wp_enqueue_script(
SCRIPT_HANDLE,
trailingslashit( AUTOSHARE_FOR_TWITTER_URL ) . 'dist/autoshare-for-twitter.js',
Expand Down Expand Up @@ -192,7 +203,12 @@ function localize_data( $handle = SCRIPT_HANDLE ) {
);
}

$status_meta = get_autoshare_for_twitter_meta( $post_id, TWITTER_STATUS_KEY );
$status_meta = get_autoshare_for_twitter_meta( $post_id, TWITTER_STATUS_KEY );
$accounts = ( new Twitter_Accounts() )->get_twitter_accounts( true );
$tweet_accounts = get_tweet_accounts( $post_id );
if ( empty( $tweet_accounts ) ) {
$tweet_accounts = get_default_autoshare_accounts();
}

$localization = [
'enabled' => autoshare_enabled( $post_id ),
Expand All @@ -207,6 +223,10 @@ function localize_data( $handle = SCRIPT_HANDLE ) {
'allowTweetImage' => tweet_image_allowed( $post_id ),
'allowTweetImageKey' => TWEET_ALLOW_IMAGE,
'retweetAction' => 'tenup_autoshare_retweet',
'connectAccountUrl' => admin_url( 'options-general.php?page=autoshare-for-twitter' ),
'tweetAccounts' => $tweet_accounts,
'tweetAccountsKey' => TWEET_ACCOUNTS_KEY,
'connectedAccounts' => $accounts ?? [],
];

wp_localize_script( $handle, 'adminAutoshareForTwitter', $localization );
Expand Down
Loading