Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Jul 6, 2023
2 parents 44092c7 + 1ed9f61 commit 92f0349
Show file tree
Hide file tree
Showing 50 changed files with 7,388 additions and 4,284 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@ 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()
run: |
npx mochawesome-merge ./tests/cypress/reports/*.json -o tests/cypress/reports/mochawesome.json
rm -rf ./tests/cypress/reports/mochawesome-*.json
npx mochawesome-json-to-md -p ./tests/cypress/reports/mochawesome.json -o ./tests/cypress/reports/mochawesome.md
npx mochawesome-report-generator tests/cypress/reports/mochawesome.json -o tests/cypress/reports/
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
8 changes: 6 additions & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ jobs:
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v1
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
license-check: true
vulnerability-check: false
config-file: 10up/.github/.github/dependency-review-config.yml@trunk
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ vendor

tests/cypress/downloads
tests/cypress/screenshots
tests/cypress/videos
tests/cypress/videos
tests/cypress/reports
Binary file modified .wordpress-org/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] - TBD

## [2.1.0] - 2023-07-05
### Added
- Support for tweeting via multiple Twitter accounts (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@Sidsector9](https://github.com/Sidsector9) via [#238](https://github.com/10up/autoshare-for-twitter/pull/238)).
- Obfuscation of saved Twitter keys in the UI (props [@lgrzegorski](https://github.com/lgrzegorski), [@bmarshall511](https://github.com/bmarshall511), [@iamdharmesh](https://github.com/iamdharmesh) via [#245](https://github.com/10up/autoshare-for-twitter/pull/245)).
- GitHub Action summary for end-to-end tests (props [@iamdharmesh](https://github.com/iamdharmesh), [@ravinderk](https://github.com/ravinderk) via [#247](https://github.com/10up/autoshare-for-twitter/pull/247)).

### Changed
- Readme updates for FAQs and formatting (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul) via [#235](https://github.com/10up/autoshare-for-twitter/pull/235), [#241](https://github.com/10up/autoshare-for-twitter/pull/241), [#242](https://github.com/10up/autoshare-for-twitter/pull/242)).
- Enhanced end-to-end tests by implementing mocking of Twitter API and bypassing actual Twitter API calls (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@Sidsector9](https://github.com/Sidsector9) via [#238](https://github.com/10up/autoshare-for-twitter/pull/238)).
- Updated the Dependency Review GitHub Action (props [@jeffpaul](https://github.com/jeffpaul), [@iamdharmesh](https://github.com/iamdharmesh) via [#239](https://github.com/10up/autoshare-for-twitter/pull/239)).
- Fixed inconsistent tweet status for scheduled posts (props [@mae829](https://github.com/mae829), [@iamdharmesh](https://github.com/iamdharmesh), [@ravinderk](https://github.com/ravinderk) via [#246](https://github.com/10up/autoshare-for-twitter/pull/246)).
- Improved error handing (props [@iamdharmesh](https://github.com/iamdharmesh), [@Sidsector9](https://github.com/Sidsector9) via [#249](https://github.com/10up/autoshare-for-twitter/pull/249)).

## [2.0.0] - 2023-05-16
**Autoshare for Twitter 2.0.0 utilizes [Twitter's v2 API](https://developer.twitter.com/en/products/twitter-api). If you have not already done so, please [migrate your app](https://developer.twitter.com/en/portal/projects-and-apps) to Twitter's v2 API to continue using Autoshare for Twitter. [Learn more about migrating here](https://developer.twitter.com/en/docs/twitter-api/migrate/ready-to-migrate).**

Expand Down Expand Up @@ -197,6 +210,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Initial closed source release (props [@scottlee](https://github.com/scottlee/)).

[Unreleased]: https://github.com/10up/autoshare-for-twitter/compare/trunk...develop
[2.1.0]: https://github.com/10up/autoshare-for-twitter/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/10up/autoshare-for-twitter/compare/1.3.0...2.0.0
[1.3.0]: https://github.com/10up/autoshare-for-twitter/compare/1.2.1...1.3.0
[1.2.1]: https://github.com/10up/autoshare-for-twitter/compare/1.2.0...1.2.1
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Adam Silverstein (@adamsilverstein)](https://github.com/adamsilverstein), [John Watkins (@johnwatkins0)](https://github.com/johnwatkins0), [Scott Lee (@scottlee)](https://github.com/scottlee), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Stephanie Campbell (@sncampbell)](https://github.com/sncampbell), [Ryan Welcher (@ryanwelcher)](https://github.com/ryanwelcher), [Ricky Lee Whittemore (@rickalee)](https://github.com/rickalee), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Lina Wiezkowiak (@linawiezkowiak)](https://github.com/linawiezkowiak), [Oszkar Nagy (@oszkarnagy)](https://github.com/oszkarnagy), [Helen Hou-Sandi (@helen)](https://github.com/helen), [Thrijith Thankachan (@thrijith)](https://github.com/thrijith), [Barney Jeffries (@barneyjeffries)](https://github.com/barneyjeffries), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Sudip Dadhaniya (@sudip-10up)](https://github.com/sudip-10up), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Max Lyuchin (@cadic)](https://github.com/cadic), [Vikram Moparthy (@vikrampm1)](https://github.com/vikrampm1), [GitHub Dependabot (@dependabot)](https://github.com/apps/dependabot), [Ravinder Kumar (@ravinderk)](https://github.com/ravinderk).
[Adam Silverstein (@adamsilverstein)](https://github.com/adamsilverstein), [John Watkins (@johnwatkins0)](https://github.com/johnwatkins0), [Scott Lee (@scottlee)](https://github.com/scottlee), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Stephanie Campbell (@sncampbell)](https://github.com/sncampbell), [Ryan Welcher (@ryanwelcher)](https://github.com/ryanwelcher), [Ricky Lee Whittemore (@rickalee)](https://github.com/rickalee), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Lina Wiezkowiak (@linawiezkowiak)](https://github.com/linawiezkowiak), [Oszkar Nagy (@oszkarnagy)](https://github.com/oszkarnagy), [Helen Hou-Sandi (@helen)](https://github.com/helen), [Thrijith Thankachan (@thrijith)](https://github.com/thrijith), [Barney Jeffries (@barneyjeffries)](https://github.com/barneyjeffries), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Sudip Dadhaniya (@sudip-10up)](https://github.com/sudip-10up), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Max Lyuchin (@cadic)](https://github.com/cadic), [Vikram Moparthy (@vikrampm1)](https://github.com/vikrampm1), [GitHub Dependabot (@dependabot)](https://github.com/apps/dependabot), [Ravinder Kumar (@ravinderk)](https://github.com/ravinderk), [Lukasz Grzegorski (@lgrzegorski)](https://github.com/lgrzegorski), [Ben Marshall (@bmarshall511)](https://github.com/bmarshall511), [Miguel Estrada (@mae829)](https://github.com/mae829).

## Libraries

Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ add_filter( 'autoshare_for_twitter_enabled_default', 'enable_autoshare_by_defaul

Yes, yes it does! For more details on this, see [#44](https://github.com/10up/autoshare-for-twitter/pull/44).

### Does the plugin work with Twitter API V2?

Yes, the plugin is compatible with Twitter API v2.

### I'm encountering the error message "401: Unauthorized." What could be the possible reason for this error?

There are a few potential reasons for this error:

1. **Incorrect Twitter API credentials**: Please ensure that you have entered the correct Twitter API credentials.
2. **Deprecated access levels**: If you are still using the old Twitter access levels (Standard (v1.1), Essential (v2), Elevated (v2), etc...), you must migrate to the new access levels (Free, Basic, Pro, etc.). Please make sure to migrate to the new access levels to ensure uninterrupted functionality. Here's how you can do it:

1. Go to the following URL: https://developer.twitter.com/en/portal/products
2. Look for the "Downgrade" button.
3. Click on it to migrate to the free access level.

### I'm encountering the error message "429: Too Many Requests." What could be the possible reason for this error?

If you're seeing the error message "429: Too Many Requests" it indicates that you have exceeded the usage limits of Twitter's Free API access. With the Free API, you are allowed **1,500 Tweets per month** and **50 requests within a 24-hour period**. Since you have surpassed the daily limit, we kindly advise waiting for 24 hours before attempting to tweet again.

To avoid encountering this error in the future and to have higher usage limits, we recommend considering a subscription to either the Basic or Pro access level. These access levels provide increased quotas and additional benefits to accommodate your needs. For more information on Twitter API access levels, you can visit this link: https://developer.twitter.com/en/products/twitter-api.

## Support Level

**Stable:** 10up is not planning to develop any new features for this, but will still respond to bug reports and security concerns. We welcome PRs, but any that include new features should be small and easy to integrate and should not include breaking changes. We otherwise intend to keep this tested up to the most recent version of WordPress.
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
4 changes: 2 additions & 2 deletions autoshare-for-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Autoshare for Twitter
* Description: Automatically tweets the post title or custom message and a link to the post.
* Disclaimer: TWITTER, TWEET, RETWEET and the Twitter logo are trademarks of Twitter, Inc. or its affiliates.
* Version: 2.0.0
* Version: 2.1.0
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up
Expand All @@ -20,7 +20,7 @@
}

define( 'AUTOSHARE_FOR_TWITTER', __FILE__ );
define( 'AUTOSHARE_FOR_TWITTER_VERSION', '2.0.0' );
define( 'AUTOSHARE_FOR_TWITTER_VERSION', '2.1.0' );
define( 'AUTOSHARE_FOR_TWITTER_URL', plugin_dir_url( __FILE__ ) );
define( 'AUTOSHARE_FOR_TWITTER_PATH', plugin_dir_path( __FILE__ ) );
define( 'AUTOSHARE_FOR_TWITTER_INC', AUTOSHARE_FOR_TWITTER_PATH . 'includes/' );
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"platform": {
"php": "7.4"
},
"autoloader-suffix": "10upAutoshareForTwitterV200",
"autoloader-suffix": "10upAutoshareForTwitterV210",
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
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

0 comments on commit 92f0349

Please sign in to comment.