Skip to content

Commit

Permalink
Merge pull request #294 from 10up/fix/287
Browse files Browse the repository at this point in the history
Fix auto-posting tweets for automatically published posts.
  • Loading branch information
iamdharmesh authored Nov 29, 2023
2 parents bdbdd2d + 6ae38bb commit 2bcd494
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"10up/phpcs-composer": "dev-master",
"phpunit/phpunit": "9.6.x-dev",
"yoast/phpunit-polyfills": "2.x-dev"
"yoast/phpunit-polyfills": "2.0.0"
},
"scripts": {
"test": "phpunit",
Expand Down
19 changes: 9 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions includes/admin/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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 function TenUp\AutoshareForTwitter\Utils\is_local;

use const TenUp\AutoshareForTwitter\Core\Post_Meta\ENABLE_AUTOSHARE_FOR_TWITTER_KEY;
Expand Down Expand Up @@ -190,9 +189,6 @@ function localize_data( $handle = SCRIPT_HANDLE ) {
$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();
}

$localization = [
'enabled' => autoshare_enabled( $post_id ),
Expand Down
4 changes: 1 addition & 3 deletions includes/admin/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ function render_twitter_accounts( $post_id ) {
}

$enabled = Utils\get_tweet_accounts( $post_id );
if ( empty( $enabled ) ) {
$enabled = Utils\get_default_autoshare_accounts();
}

$display = ( autoshare_enabled( $post_id ) || 'publish' === $post_status ) ? '' : 'display: none;';
?>
<div class="autoshare-for-twitter-accounts-wrapper" style="<?php echo esc_attr( $display ); ?>">
Expand Down
11 changes: 9 additions & 2 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ function tweet_image_allowed( $post_id ) {
* @return array
*/
function get_tweet_accounts( $post_id ) {
$tweet_accounts = get_autoshare_for_twitter_meta( $post_id, TWEET_ACCOUNTS_KEY );
if ( empty( $tweet_accounts ) ) {
$tweet_accounts = [];
if ( has_autoshare_for_twitter_meta( $post_id, TWEET_ACCOUNTS_KEY ) ) {
$tweet_accounts = get_autoshare_for_twitter_meta( $post_id, TWEET_ACCOUNTS_KEY );
} else {
// If post don't have meta value set for tweet accounts, use default enabled accounts to handle auto-tweet for automated posts.
$tweet_accounts = get_default_autoshare_accounts();
}

if ( ! is_array( $tweet_accounts ) ) {
$tweet_accounts = [];
}

Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"cypress-mochawesome-reporter": "^3.5.1",
"husky": "^3.0.5",
"lint-staged": "^9.2.5",
"mochawesome-json-to-md": "^0.7.2",
"node-wp-i18n": "^1.2.3"
},
"prettier": "@wordpress/prettier-config"
Expand Down

0 comments on commit 2bcd494

Please sign in to comment.