From 84f2948362519f65360e413af72c6033f9c285aa Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Fri, 20 Oct 2023 19:42:10 +0530 Subject: [PATCH 1/3] Fix auto-post for automatic published posts. --- includes/admin/assets.php | 3 --- includes/admin/post-meta.php | 4 +--- includes/utils.php | 11 +++++++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/includes/admin/assets.php b/includes/admin/assets.php index b2d1994c..569c0c83 100644 --- a/includes/admin/assets.php +++ b/includes/admin/assets.php @@ -189,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 ), diff --git a/includes/admin/post-meta.php b/includes/admin/post-meta.php index b5aa6332..d41da63a 100644 --- a/includes/admin/post-meta.php +++ b/includes/admin/post-meta.php @@ -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;'; ?>
diff --git a/includes/utils.php b/includes/utils.php index 7e465723..2ed03e89 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -124,8 +124,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 = []; } From 39d8a669e38b6bca38570f9e3420c077065a7331 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 23 Nov 2023 15:17:03 +0530 Subject: [PATCH 2/3] Removed unwanted code. --- includes/admin/assets.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/admin/assets.php b/includes/admin/assets.php index 569c0c83..efce2e87 100644 --- a/includes/admin/assets.php +++ b/includes/admin/assets.php @@ -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 const TenUp\AutoshareForTwitter\Core\Post_Meta\ENABLE_AUTOSHARE_FOR_TWITTER_KEY; use const TenUp\AutoshareForTwitter\Core\Post_Meta\TWEET_ACCOUNTS_KEY; From 6ae38bb1641821471ddf0443f09e5ef931e15bef Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Thu, 23 Nov 2023 16:00:59 +0530 Subject: [PATCH 3/3] Fix json to md issue. --- composer.json | 2 +- composer.lock | 19 +++++++++---------- package-lock.json | 22 ++++++++++++++++++++++ package.json | 1 + 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 69b512ef..8d099f0e 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index a6dc3497..0f2868a6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cc6e4242cfc2df2ee3c988aa552f8c64", + "content-hash": "8421a957f988a1a59e6c57ec9246f7a6", "packages": [ { "name": "abraham/twitteroauth", @@ -2399,21 +2399,21 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "dev-main", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "3b59adeef77fb1c03ff5381dbb9d68b0aaff3171" + "reference": "c758753e8f9dac251fed396a73c8305af3f17922" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/3b59adeef77fb1c03ff5381dbb9d68b0aaff3171", - "reference": "3b59adeef77fb1c03ff5381dbb9d68b0aaff3171", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/c758753e8f9dac251fed396a73c8305af3f17922", + "reference": "c758753e8f9dac251fed396a73c8305af3f17922", "shasum": "" }, "require": { - "php": ">=5.4", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "php": ">=5.6", + "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" }, "require-dev": { "yoast/yoastcs": "^2.3.0" @@ -2455,15 +2455,14 @@ "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2023-03-30T23:39:05+00:00" + "time": "2023-06-06T20:28:24+00:00" } ], "aliases": [], "minimum-stability": "dev", "stability-flags": { "10up/phpcs-composer": 20, - "phpunit/phpunit": 20, - "yoast/phpunit-polyfills": 20 + "phpunit/phpunit": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/package-lock.json b/package-lock.json index 883e0f07..0a5f015d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,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" } }, @@ -14536,6 +14537,18 @@ "mocha": ">=7" } }, + "node_modules/mochawesome-json-to-md": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/mochawesome-json-to-md/-/mochawesome-json-to-md-0.7.2.tgz", + "integrity": "sha512-dxh+o73bhC6nEph6fNky9wy35R+2oK3ueXwAlJ/COAanlFgu8GuvGzQ00VNO4PPYhYGDsO4vbt4QTcMA3lv25g==", + "dev": true, + "dependencies": { + "yargs": "^17.0.1" + }, + "bin": { + "mochawesome-json-to-md": "index.js" + } + }, "node_modules/mochawesome-merge": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/mochawesome-merge/-/mochawesome-merge-4.3.0.tgz", @@ -31537,6 +31550,15 @@ "uuid": "^8.3.2" } }, + "mochawesome-json-to-md": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/mochawesome-json-to-md/-/mochawesome-json-to-md-0.7.2.tgz", + "integrity": "sha512-dxh+o73bhC6nEph6fNky9wy35R+2oK3ueXwAlJ/COAanlFgu8GuvGzQ00VNO4PPYhYGDsO4vbt4QTcMA3lv25g==", + "dev": true, + "requires": { + "yargs": "^17.0.1" + } + }, "mochawesome-merge": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/mochawesome-merge/-/mochawesome-merge-4.3.0.tgz", diff --git a/package.json b/package.json index 8f3fe9dc..0f96ba82 100644 --- a/package.json +++ b/package.json @@ -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"