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

Fix auto-posting tweets for automatically published posts. #294

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading