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 Aug 22, 2023
2 parents 92f0349 + 818c8cb commit 8ff263b
Show file tree
Hide file tree
Showing 26 changed files with 388 additions and 80 deletions.
8 changes: 1 addition & 7 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
# DO NOT EXCLUDE /vendor

# Files
.babelrc
.distignore
.eslintignore
.eslintrc.json
.gitignore
.*
CHANGELOG.md
CODE_OF_CONDUCT.md
composer.json
Expand All @@ -28,5 +24,3 @@ phpunit.xml
README.md
webpack.config.js
webpack.gutenberg.config.js
.wp-env.json
.nvmrc
4 changes: 0 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ on:
pull_request:
branches:
- develop
paths:
- '**.js'
- '**.php'
- '**.css'

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ on:
schedule:
- cron: '0 0 * * 1'

permissions:
issues: write

jobs:
wordpress-version-checker:
runs-on: ubuntu-latest
steps:
- name: WordPress version checker
uses: skaut/wordpress-version-checker@v1.2.0
uses: skaut/wordpress-version-checker@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .wordpress-version-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"channel": "rc"
}
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased] - TBD

## [2.1.0] - 2023-07-05
## [2.1.1] - 2023-08-XX

### Changed
- Improved setup instructions and error handing (props [@johnwatkins0](https://github.com/johnwatkins0), [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul) via [#255](https://github.com/10up/autoshare-for-twitter/pull/255)).
- Bump WordPress "tested up to" version 6.3 (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul) via [#265](https://github.com/10up/autoshare-for-twitter/pull/265)).

### Fixed
- The custom tweet message does not work with scheduled posts (props [@GeoffLambert77](https://github.com/GeoffLambert77), [@iamdharmesh](https://github.com/iamdharmesh), [@Sidsector9](https://github.com/Sidsector9) via [#267](https://github.com/10up/autoshare-for-twitter/pull/267)).
- Connected Twitter accounts visibility in the classic editor (props [@iamdharmesh](https://github.com/iamdharmesh), [@Sidsector9](https://github.com/Sidsector9) via [#269](https://github.com/10up/autoshare-for-twitter/pull/269)).
- Better error handling for environments that don't match our minimum PHP version (props [@dkotter](https://github.com/dkotter), [@rahulsprajapati](https://github.com/rahulsprajapati), [@iamdharmesh](https://github.com/iamdharmesh) via [#258](https://github.com/10up/autoshare-for-twitter/pull/258)).
- Ensure our E2E tests work properly on WordPress 6.3 (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter) via [#264](https://github.com/10up/autoshare-for-twitter/pull/264)).

### Security
- Bump `tough-cookie` from 2.5.0 to 4.1.3 and `@cypress/request` from 2.88.10 to 2.88.12 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh) via [#266](https://github.com/10up/autoshare-for-twitter/pull/266)).
- Bump `word-wrap` from 1.2.3 to 1.2.4 (props [@dependabot[bot]](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh) via [#257](https://github.com/10up/autoshare-for-twitter/pull/257)).

## [2.1.0] - 2023-07-06
### 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)).
Expand Down Expand Up @@ -210,6 +226,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.1]: https://github.com/10up/autoshare-for-twitter/compare/2.1.0...2.1.1
[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
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), [Lukasz Grzegorski (@lgrzegorski)](https://github.com/lgrzegorski), [Ben Marshall (@bmarshall511)](https://github.com/bmarshall511), [Miguel Estrada (@mae829)](https://github.com/mae829).
[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), [Rahul Prajapati (@rahulsprajapati)](https://github.com/rahulsprajapati), [@GeoffLambert77](https://github.com/GeoffLambert77).

## Libraries

Expand Down
3 changes: 3 additions & 0 deletions assets/js/admin-autoshare-for-twitter-classic-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@
( ( response.success && response.data.message ) || ( false === response.success && false === response.data.is_retweeted) )
) {
$('.autoshare-for-twitter-status-logs-wrapper').html(response.data.message);
if ( response.data.is_retweeted ) {
$tweetText.val(''); // Reset the tweet text.
}
} else {
$("#autoshare-for-twitter-error-message").html(adminAutoshareForTwitter.unknownErrorText);
}
Expand Down
49 changes: 47 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.1.0
* Version: 2.1.1
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up
Expand All @@ -15,16 +15,61 @@
* @package TenUp\AutoshareForTwitter
*/

namespace TenUp\AutoshareForTwitter;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

define( 'AUTOSHARE_FOR_TWITTER', __FILE__ );
define( 'AUTOSHARE_FOR_TWITTER_VERSION', '2.1.0' );
define( 'AUTOSHARE_FOR_TWITTER_VERSION', '2.1.1' );
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/' );

/**
* Get the minimum version of PHP required by this plugin.
*
* @return string Minimum version required.
*/
function minimum_php_requirement() {
return '7.4';
}

/**
* Whether PHP installation meets the minimum requirements
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_php_requirements() {
return version_compare( phpversion(), minimum_php_requirement(), '>=' );
}

// Ensuring our PHP version requirement is met first before loading plugin.
if ( ! site_meets_php_requirements() ) {
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'Autoshare for Twitter requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'autoshare-for-twitter' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

/**
* Composer check.
*/
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": "10upAutoshareForTwitterV210",
"autoloader-suffix": "10upAutoshareForTwitterV211",
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
Expand Down
2 changes: 2 additions & 0 deletions includes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function localize_data( $handle = SCRIPT_HANDLE ) {
$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 );
$tweet_body = trim( get_autoshare_for_twitter_meta( $post_id, TWEET_BODY_KEY ) );
if ( empty( $tweet_accounts ) ) {
$tweet_accounts = get_default_autoshare_accounts();
}
Expand All @@ -217,6 +218,7 @@ function localize_data( $handle = SCRIPT_HANDLE ) {
'nonce' => wp_create_nonce( 'wp_rest' ),
'restUrl' => rest_url( post_autoshare_for_twitter_meta_rest_route( $post_id ) ),
'tweetBodyKey' => TWEET_BODY_KEY,
'customTweetBody' => $tweet_body,
'status' => $status_meta && is_array( $status_meta ) ? $status_meta : null,
'unknownErrorText' => __( 'An unknown error occurred', 'autoshare-for-twitter' ),
'siteUrl' => home_url(),
Expand Down
18 changes: 12 additions & 6 deletions includes/admin/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function save_autoshare_for_twitter_meta_data( $post_id, $data ) {
// If the enable key is not set, set it to the default setting value.
if ( ! array_key_exists( ENABLE_AUTOSHARE_FOR_TWITTER_KEY, $data ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['classic-editor'] ) ) {
if ( isset( $_POST['autoshare-classic-editor'] ) ) {
// Handle unchecked "Tweet this post" checkbox for classic editor.
$data[ ENABLE_AUTOSHARE_FOR_TWITTER_KEY ] = 0;
} else {
Expand All @@ -166,7 +166,7 @@ function save_autoshare_for_twitter_meta_data( $post_id, $data ) {

if ( ! array_key_exists( TWEET_ALLOW_IMAGE, $data ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( isset( $_POST['classic-editor'] ) ) {
if ( isset( $_POST['autoshare-classic-editor'] ) ) {
// Handle unchecked "Tweet this post" checkbox for classic editor.
$data[ TWEET_ALLOW_IMAGE ] = 0;
} else {
Expand Down Expand Up @@ -293,8 +293,9 @@ function render_twitter_accounts( $post_id ) {
if ( empty( $enabled ) ) {
$enabled = Utils\get_default_autoshare_accounts();
}
$display = ( autoshare_enabled( $post_id ) ) ? '' : 'display: none;';
?>
<div class="autoshare-for-twitter-accounts-wrapper">
<div class="autoshare-for-twitter-accounts-wrapper" style="<?php echo esc_attr( $display ); ?>">
<?php
foreach ( $accounts as $account ) {
?>
Expand Down Expand Up @@ -546,6 +547,8 @@ function markup_unknown( $status_meta ) {
* @return string
*/
function _safe_markup_default() {
$custom_tweet_body = Utils\get_autoshare_for_twitter_meta( get_the_ID(), TWEET_BODY_KEY );

$count = ( strlen( get_permalink( get_the_ID() ) ) + 5 );
$max_length = 280 - $count;
ob_start();
Expand All @@ -558,9 +561,12 @@ function _safe_markup_default() {
value="1"
<?php checked( autoshare_enabled( get_the_ID() ) ); ?>
>
<input type="hidden" name="autoshare-classic-editor" value="1" />
<span id="autoshare-for-twitter-icon" class="dashicons-before dashicons-twitter"></span>
<?php esc_html_e( 'Tweet this post', 'autoshare-for-twitter' ); ?>
<a href="#edit_tweet_text" id="autoshare-for-twitter-edit"><?php esc_html_e( 'Edit', 'autoshare-for-twitter' ); ?></a>
<a href="#edit_tweet_text" id="autoshare-for-twitter-edit" style="<?php echo ( ( ! empty( $custom_tweet_body ) ) ? 'display: none;' : '' ); ?>">
<?php esc_attr_e( 'Edit', 'autoshare-for-twitter' ); ?>
</a>
</label>

<div class="autoshare-for-twitter-tweet-allow-image-wrap" style="display: none;">
Expand All @@ -583,7 +589,7 @@ function _safe_markup_default() {
render_twitter_accounts( get_the_ID() );
?>

<div id="autoshare-for-twitter-override-body" style="display: none;">
<div id="autoshare-for-twitter-override-body" style="<?php echo ( ( empty( $custom_tweet_body ) ) ? 'display: none;' : '' ); ?>">
<label for="<?php echo esc_attr( sprintf( '%s[%s]', META_PREFIX, TWEET_BODY_KEY ) ); ?>">
<?php esc_html_e( 'Custom Message', 'autoshare-for-twitter' ); ?>:
</label>
Expand All @@ -593,7 +599,7 @@ function _safe_markup_default() {
name="<?php echo esc_attr( sprintf( '%s[%s]', META_PREFIX, TWEET_BODY_KEY ) ); ?>"
rows="3"
maxlength="<?php echo esc_attr( $max_length ); ?>"
><?php echo esc_textarea( Utils\get_autoshare_for_twitter_meta( get_the_ID(), TWEET_BODY_KEY ) ); ?></textarea>
><?php echo esc_textarea( $custom_tweet_body ); ?></textarea>
<p class="howto" id="autoshare-for-twitter-text-desc"><?php esc_html_e( 'Character count is inclusive of the post permalink which will be included in the final tweet.', 'autoshare-for-twitter' ); ?></p>

<p><a href="#" class="hide-if-no-js cancel-tweet-text"><?php esc_html_e( 'Hide', 'autoshare-for-twitter' ); ?></a></p>
Expand Down
8 changes: 8 additions & 0 deletions includes/admin/post-transition.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use function TenUp\AutoshareForTwitter\Utils\get_autoshare_for_twitter_meta;
use function TenUp\AutoshareForTwitter\Core\Post_Meta\get_tweet_status_logs;

use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWEET_BODY_KEY;

/**
* Setup function.
*
Expand Down Expand Up @@ -171,6 +173,12 @@ function publish_tweet( $post_id, $force = false ) {
}
}

if ( ! $failed ) {
// Clear the tweet body on successful publishing to Twitter.
Utils\delete_autoshare_for_twitter_meta( $post->ID, TWEET_BODY_KEY );
remove_action( 'save_post', 'TenUp\AutoshareForTwitter\Core\Post_Meta\save_tweet_meta', 10 );
}

return ( ! $failed );
}

Expand Down
4 changes: 1 addition & 3 deletions includes/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,8 @@ function cred_section_cb() {
?>
</li>
<li><?php esc_html_e( 'Switch from the "Settings" tab to the "Keys and tokens" tab.', 'autoshare-for-twitter' ); ?></li>
<li><?php echo wp_kses_data( __( 'Click on the <code>Generate</code> button in the <code>API Key and Secret</code> section.', 'autoshare-for-twitter' ) ); ?></li>
<li><?php echo wp_kses_data( __( 'Click on the <code>Generate</code>/<code>Regenerate</code> button in the <code>Consumer Keys</code> section.', 'autoshare-for-twitter' ) ); ?></li>
<li><?php echo wp_kses_data( __( 'Copy the <code>API Key</code> and <code>API Key Secret</code> values and paste them below.', 'autoshare-for-twitter' ) ); ?></li>
<li><?php echo wp_kses_data( __( 'Click on the <code>Generate</code> button in the <code>Access Token and Secret</code> section.', 'autoshare-for-twitter' ) ); ?></li>
<li><?php echo wp_kses_data( __( 'Copy the <code>Access Token</code> and <code>Access Token Secret</code> values and paste them below.', 'autoshare-for-twitter' ) ); ?></li>
</ul>

<h4><?php esc_html_e( '3. Save settings', 'autoshare-for-twitter' ); ?></h4>
Expand Down
10 changes: 3 additions & 7 deletions includes/class-twitter-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ class Twitter_API {
*/
protected $access_token_secret;

/**
* The twitter handle.
*
* @var string The twitter handle.
*/
protected $twitter_handle;

/**
* The TwitterOAuth client.
*
Expand Down Expand Up @@ -172,6 +165,9 @@ public function get_current_account() {
);

if ( ! $user || ! isset( $user->data ) || ! isset( $user->data->id ) ) {
if ( ! empty( $user->detail ) ) {
return new \WP_Error( 'error_get_twitter_user', $user->detail );
}
return new \WP_Error( 'error_get_twitter_user', __( 'Something went wrong during getting user details', 'autoshare-for-twitter' ) );
}

Expand Down
Loading

0 comments on commit 8ff263b

Please sign in to comment.