diff --git a/.babelrc b/.babelrc index aa2d5439..59331afa 100644 --- a/.babelrc +++ b/.babelrc @@ -4,8 +4,8 @@ [ "@wordpress/babel-plugin-makepot", { - "output": "languages/autotweet.pot", + "output": "languages/autoshare-for-twitter.pot" } - ], + ] ] } diff --git a/.eslintrc.json b/.eslintrc.json index 924c66ab..d8ee40e3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,6 @@ { "globals": { - "adminAutotweet": "readonly", + "adminAutoshareForTwitter": "readonly", "jQuery": "readonly", "wp": "readonly" }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 37621a57..72a95118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [0.1.0] - 2018-05-11 - Initial closed source release -[Unreleased]: https://github.com/10up/autotweet/compare/master...develop -[1.0.0]: https://github.com/10up/autotweet/compare/1020035...1.0.0 -[0.1.0]: https://github.com/10up/autotweet/commit/1020035f2d4843221d996bd5f8fe39d9ee850b5d +[Unreleased]: https://github.com/10up/autoshare-for-twitter/compare/master...develop +[1.0.0]: https://github.com/10up/autoshare-for-twitter/compare/1020035...1.0.0 +[0.1.0]: https://github.com/10up/autoshare-for-twitter/commit/1020035f2d4843221d996bd5f8fe39d9ee850b5d diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cf3385e2..cb48b382 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,15 +6,15 @@ The following is a set of guidelines for contributors as well as information and ## Ways to contribute -Contributing isn't just writing code - it's anything that improves the project. All contributions for AutoTweet are managed right here on GitHub. Here are some ways you can help: +Contributing isn't just writing code - it's anything that improves the project. All contributions for AutoShare for Twitter are managed right here on GitHub. Here are some ways you can help: ### Reporting bugs -If you're running into an issue with the plugin, please take a look through [existing issues](https://github.com/10up/autotweet/issues) and [open a new one](https://github.com/10up/autotweet/issues/new) if needed. If you're able, include steps to reproduce, environment information, and screenshots/screencasts as relevant. +If you're running into an issue with the plugin, please take a look through [existing issues](https://github.com/10up/autoshare-for-twitter/issues) and [open a new one](https://github.com/10up/autoshare-for-twitter/issues/new) if needed. If you're able, include steps to reproduce, environment information, and screenshots/screencasts as relevant. ### Suggesting enhancements -New features and enhancements are also managed via [issues](https://github.com/10up/autotweet/issues). +New features and enhancements are also managed via [issues](https://github.com/10up/autoshare-for-twitter/issues). ### Pull requests @@ -29,14 +29,14 @@ The `develop` branch is the development branch which means it contains the next ## Release instructions 1. Starting from `develop`, cut a release branch named `release/X.Y.Z` for your changes. -2. Version bump: Bump the version number in `autotweet.php` if it does not already reflect the version being released. +2. Version bump: Bump the version number in `autoshare-for-twitter.php` if it does not already reflect the version being released. 3. Changelog: Add/update the changelog in `CHANGELOG.md` and `readme.txt` 4. Update the `.pot` file by running `npm run makepot`. 5. Check to be sure any new files/paths that are unnecessary in the production version are included in `.github/action-release/rsync-filter.txt`. 6. Merge: Make a non-fast-forward merge from your release branch to `develop`, then do the same for `develop` into `master`. `master` contains the stable development version. 7. Push: Push your `master` branch to GitHub, e.g. `git push origin master`. -8. [Wait for build](https://xkcd.com/303/): Head to the [Actions](https://github.com/10up/autotweet/actions) tab in the repo and wait for it to finish if it hasn't already. If it doesn't succeed, figure out why and start over. +8. [Wait for build](https://xkcd.com/303/): Head to the [Actions](https://github.com/10up/autoshare-for-twitter/actions) tab in the repo and wait for it to finish if it hasn't already. If it doesn't succeed, figure out why and start over. 9. Check the build: Check out the `stable` branch and test for functionality locally. -10. Git tag: Create the release as `X.Y.Z` on the `stable` branch in GitHub. It should now appear under [releases](https://github.com/10up/autotweet/releases) and in the WordPress admin as an update as well. -11. Edit the [X.Y.Z milestone](https://github.com/10up/autotweet/milestone/#) with release date (in the `Due date (optional)` field) and link to GitHub release (in the `Description` field), then close `X.Y.Z` milestone. +10. Git tag: Create the release as `X.Y.Z` on the `stable` branch in GitHub. It should now appear under [releases](https://github.com/10up/autoshare-for-twitter/releases) and in the WordPress admin as an update as well. +11. Edit the [X.Y.Z milestone](https://github.com/10up/autoshare-for-twitter/milestone/#) with release date (in the `Due date (optional)` field) and link to GitHub release (in the `Description` field), then close `X.Y.Z` milestone. 12. If any open issues or PRs which were milestoned for `X.Y.Z` do not make it into the release, update their milestone to `X+1.0.0`, `X.Y+1.0`, `X.Y.Z+1`, or `Future Release` diff --git a/README.md b/README.md index 0c710f47..72cf2479 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,67 @@ -# Auto Tweet +# Autoshare for Twitter > Automatically tweets the post title or custom message and a link to the post. -[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Release Version](https://img.shields.io/github/release/10up/autotweet.svg)](https://github.com/10up/autotweet/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v4.9.8%20tested-success.svg) [![MIT License](https://img.shields.io/github/license/10up/autotweet.svg)](https://github.com/10up/autotweet/blob/develop/LICENSE.md) +[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Release Version](https://img.shields.io/github/release/10up/autoshare-for-twitter.svg)](https://github.com/10up/autoshare-for-twitter/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v5.3%20tested-success.svg) [![GPLv2 License](https://img.shields.io/github/license/10up/autoshare-for-twitter.svg)](https://github.com/10up/autoshare-for-twitter/blob/develop/LICENSE.md) ## Overview -**Disclaimer:** *TWITTER, TWEET, RETWEET and the Twitter logo are trademarks of Twitter, Inc. or its affiliates.* +**Disclaimer:** _TWITTER, TWEET, RETWEET and the Twitter logo are trademarks of Twitter, Inc. or its affiliates._ -**Note:** Posts and pages are supported by default. Developers can use the `tenup_autotweet_default_post_types` filter to change the default supported post types (for more, see #25). The plugin namespace changed to just 'autotweet' as of version 1.0.0. +**Note:** Posts and pages are supported by default. Developers can use the `autoshare_for_twitter_default_post_types` filter to change the default supported post types (for more, see #25). The plugin namespace changed to just 'autoshare' as of version 1.0.0. -Custom post types can now be opted into autotweet features like so: +Custom post types can now be opted into autoshare features like so: ```php -function opt_my_cpt_into_autotweet() { - add_post_type_support( 'my-cpt', 'autotweet' ); +function opt_my_cpt_into_autoshare() { + add_post_type_support( 'my-cpt', 'autoshare-for-twitter' ); } -add_action( 'init', 'opt_my_cpt_into_autotweet' ); +add_action( 'init', 'opt_my_cpt_into_autoshare' ); ``` -In addition, adding support while registering custom post types also works. Post types are automatically set to auto-tweet. Future versions of this plugin could allow this to be set manually. +In addition, adding support while registering custom post types also works. Post types are automatically set to autoshare. Future versions of this plugin could allow this to be set manually. -## Plugin Compatibility ## +## Plugin Compatibility -### Distributor ### -When using with 10up's [Distributor plugin](https://github.com/10up/distributor), posts that are distributed will not auto-tweet if they are already tweeted from the origin site. Autotweet tracks posts that have been tweeted in post meta to avoid "double tweeting". To avoid this behavior, use the `dt_blacklisted_meta` filter to exclude the 'autotweet_twitter-status' meta value from being distrivuted : +### Distributor + +When using with 10up's [Distributor plugin](https://github.com/10up/distributor), posts that are distributed will not be autoshared if they are already tweeted from the origin site. Autoshare for Twitter tracks posts that have been tweeted in post meta to avoid "double tweeting". To avoid this behavior, use the `dt_blacklisted_meta` filter to exclude the 'autoshare_for_twitter_status' meta value from being distrivuted : ```php add_filter( 'dt_blacklisted_meta', function( $blacklisted_metas ) { - $blacklisted_metas[] = 'autotweet_twitter-status'; + $blacklisted_metas[] = 'autoshare_for_twitter_status'; return $blacklisted_metas; } ) ``` ## Requirements -* PHP 7.0+ -* [WordPress](http://wordpress.org) 4.7+ +- PHP 7.0+ +- [WordPress](http://wordpress.org) 4.7+ ## Installation -1. Upload the entire `/tenup-auto-tweet` directory to the `/wp-content/plugins/` directory. + +1. Upload the entire `/autoshare-for-twitter` directory to the `/wp-content/plugins/` directory. 2. Activate the plugin -3. Register post type support for types that should be allowed to auto tweet. `add_post_type_support( 'post', 'autotweet' );` +3. Register post type support for types that should be allowed to autoshare. `add_post_type_support( 'post', 'autoshare-for-twitter' );` ## FAQs + ### Does this plugin work with Gutenberg? -Yes, yes it does! For more details on this, see #44. + +Yes, yes it does! For more details on this, see #44. ## Support Level -**Active:** 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome. +**Active:** 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome. ## Changelog -A complete listing of all notable changes to Eight Day Week are documented in [CHANGELOG.md](https://github.com/10up/autotweet/blob/develop/CHANGELOG.md). +A complete listing of all notable changes to Autoshare for Twitter are documented in [CHANGELOG.md](https://github.com/10up/autoshare-for-twitter/blob/develop/CHANGELOG.md). ## Contributing -Please read [CODE_OF_CONDUCT.md](https://github.com/10up/autotweet/blob/develop/CODE_OF_CONDUCT.md) for details on our code of conduct, [CONTRIBUTING.md](https://github.com/10up/autotweet/blob/develop/CONTRIBUTING.md) for details on the process for submitting pull requests to us, and [CREDITS.md](https://github.com/10up/autotweet/blob/develop/CREDITS.md) for a listing of maintainers, contributors, and libraries for Auto Tweet. +Please read [CODE_OF_CONDUCT.md](https://github.com/10up/autoshare-for-twitter/blob/develop/CODE_OF_CONDUCT.md) for details on our code of conduct, [CONTRIBUTING.md](https://github.com/10up/autoshare-for-twitter/blob/develop/CONTRIBUTING.md) for details on the process for submitting pull requests to us, and [CREDITS.md](https://github.com/10up/autoshare-for-twitter/blob/develop/CREDITS.md) for a listing of maintainers, contributors, and libraries for Autoshare for Twitter. ## Like what you see? diff --git a/assets/css/admin-autoshare-for-twitter.css b/assets/css/admin-autoshare-for-twitter.css new file mode 100644 index 00000000..d68c4034 --- /dev/null +++ b/assets/css/admin-autoshare-for-twitter.css @@ -0,0 +1,104 @@ +#autoshare_for_twitter_metabox p::before { + display: inline-block; + margin-left: -1px; + padding-right: 3px; + vertical-align: top; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +#autoshare_for_twitter_metabox pre { + font-size: 11px; + white-space: normal; +} + +.autoshare-for-twitter-prepublish__checkbox .components-base-control__field, .autoshare-for-twitter-prepublish__checkbox-label { + display: flex; + align-items: center; +} + +.autoshare-for-twitter-prepublish__checkbox .components-base-control__field { + margin-top: 0.5rem; +} + +.autoshare-for-twitter-prepublish__checkbox-label svg { + margin-right: 0.5rem; +} + +.autoshare-for-twitter-prepublish__message-label { + display: flex; + justify-content: space-between; +} + +.autoshare-for-twitter-prepublish__checkbox-row input[type=checkbox].components-checkbox-control__input { + margin-right: 0.5rem; +} + +.autoshare-for-twitter-prepublish__override-row { + padding: 0.5rem 0; +} + +.autoshare-for-twitter-prepublish__override-row .components-button { + margin-bottom: 1rem; +} + +.autoshare-for-twitter-post-status { + font-style: italic; +} + +.autoshare-for-twitter-post-status svg { + transform: translate3d(0, 3px, 0); + margin-right: 5px; +} + +#autoshare-for-twitter-icon.pending, +.autoshare-for-twitter-prepublish__checkbox-row .dashicons-twitter.pending { + animation: fadeIn 1s infinite alternate; + color: #00aced; +} + +#autoshare-for-twitter-icon.enabled, +.autoshare-for-twitter-prepublish__checkbox-row .dashicons-twitter.enabled { + color: #00aced; +} + +#autoshare-for-twitter-icon.disabled, +.autoshare-for-twitter-prepublish__checkbox-row .dashicons-twitter.disabled { + color: #72777c; +} + +@keyframes fadeIn { + from { + opacity: 0; + color: #72777c; + } +} + +a#autoshare-for-twitter-edit { + color: #0073aa; + text-decoration: underline; + transition-property: border, background, color; + transition-duration: .05s; + transition-timing-function: ease-in-out +} + +#autoshare-for-twitter-override-body { + margin: 4px 0; +} + +textarea#autoshare-for-twitter-text { + margin: 4px 0 0; + width: 100% +} +span#autoshare-for-twitter-counter-wrap { + background: rgba(0, 0, 0, 0.07); + font-family: Consolas, Monaco, monospace; +} + +span.near-limit { + color: darkorange; +} + +span.over-limit { + color: red; +} diff --git a/assets/css/admin-autotweet.css b/assets/css/admin-autotweet.css deleted file mode 100644 index 28062363..00000000 --- a/assets/css/admin-autotweet.css +++ /dev/null @@ -1,104 +0,0 @@ -#autotweet_metabox p::before { - display: inline-block; - margin-left: -1px; - padding-right: 3px; - vertical-align: top; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -#autotweet_metabox pre { - font-size: 11px; - white-space: normal; -} - -.autotweet-prepublish__checkbox .components-base-control__field, .autotweet-prepublish__checkbox-label { - display: flex; - align-items: center; -} - -.autotweet-prepublish__checkbox .components-base-control__field { - margin-top: 0.5rem; -} - -.autotweet-prepublish__checkbox-label svg { - margin-right: 0.5rem; -} - -.autotweet-prepublish__message-label { - display: flex; - justify-content: space-between; -} - -.autotweet-prepublish__checkbox-row input[type=checkbox].components-checkbox-control__input { - margin-right: 0.5rem; -} - -.autotweet-prepublish__override-row { - padding: 0.5rem 0; -} - -.autotweet-prepublish__override-row .components-button { - margin-bottom: 1rem; -} - -.autotweet-post-status { - font-style: italic; -} - -.autotweet-post-status svg { - transform: translate3d(0, 3px, 0); - margin-right: 5px; -} - -#autotweet-icon.pending, -.autotweet-prepublish__checkbox-row .dashicons-twitter.pending { - animation: fadeIn 1s infinite alternate; - color: #00aced; -} - -#autotweet-icon.enabled, -.autotweet-prepublish__checkbox-row .dashicons-twitter.enabled { - color: #00aced; -} - -#autotweet-icon.disabled, -.autotweet-prepublish__checkbox-row .dashicons-twitter.disabled { - color: #72777c; -} - -@keyframes fadeIn { - from { - opacity: 0; - color: #72777c; - } -} - -a#autotweet-edit { - color: #0073aa; - text-decoration: underline; - transition-property: border, background, color; - transition-duration: .05s; - transition-timing-function: ease-in-out -} - -#autotweet-override-body { - margin: 4px 0; -} - -textarea#autotweet-text { - margin: 4px 0 0; - width: 100% -} -span#autotweet-counter-wrap { - background: rgba(0, 0, 0, 0.07); - font-family: Consolas, Monaco, monospace; -} - -span.near-limit { - color: darkorange; -} - -span.over-limit { - color: red; -} diff --git a/assets/js/admin-autoshare-for-twitter.js b/assets/js/admin-autoshare-for-twitter.js new file mode 100644 index 00000000..65a01197 --- /dev/null +++ b/assets/js/admin-autoshare-for-twitter.js @@ -0,0 +1,126 @@ +/** + * Handles the Autoshare JS. + * + * @todo soooo much dependency :facepalm: + */ +(function($) { + 'use strict'; + + var $tweetPost = $('#autoshare-for-twitter-enable'), + $icon = $('#autoshare-for-twitter-icon'), + $tweetText = $('#autoshare-for-twitter-text'), + $editLink = $('#autoshare-for-twitter-edit'), + $editBody = $('#autoshare-for-twitter-override-body'), + $hideLink = $('.cancel-tweet-text'), + errorMessageContainer = document.getElementById('autoshare-for-twitter-error-message'), + counterWrap = document.getElementById('autoshare-for-twitter-counter-wrap'), + limit = 280; + + // Add enabled class if checked + if ($tweetPost.prop('checked')) { + $icon.addClass('enabled'); + } + + // Event handlers. + $tweetPost.on('click', handleRequest); + $tweetText.change(handleRequest); + $editLink.on('click', function() { + $editBody.slideToggle(); + updateRemainingField(); + $(this).hide(); + }); + $tweetText.on('keyup', function() { + updateRemainingField(); + }); + $hideLink.on('click', function(e) { + e.preventDefault(); + $('#autoshare-for-twitter-override-body').slideToggle(); + $editLink.show(); + }); + + // Runs on page load to auto-enable posts to be tweeted + window.onload = function(event) { + if ('' === adminAutoshareForTwitter.currentStatus) { + handleRequest(event, true); + } + }; + + /** + * Callback for failed requests. + */ + function onRequestFail(error) { + var errorText = ''; + if ('statusText' in error && 'status' in error) { + errorText = `${adminAutoshareForTwitter.errorText} ${error.status}: ${error.statusText}`; + } else { + errorText = adminAutoshareForTwitter.unkonwnErrorText; + } + + errorMessageContainer.innerText = errorText; + + $icon.removeClass('pending'); + $tweetPost.prop('checked', false); + } + + /** + * AJAX handler + * @param event + */ + function handleRequest(event, status = $tweetPost.prop('checked')) { + var data = {}; + data[adminAutoshareForTwitter.enableAutoshareKey] = status; + data[adminAutoshareForTwitter.tweetBodyKey] = $tweetText.val(); + + wp.apiFetch({ + url: adminAutoshareForTwitter.restUrl, + data: data, + method: 'POST', + parse: false, // We'll check the response for errors. + }) + .then(function(response) { + if (!response.ok) { + throw response; + } + + return response.json(); + }) + .then(function(data) { + errorMessageContainer.innerText = ''; + + $icon.removeClass('pending'); + if (data.enabled) { + $icon.toggleClass('enabled'); + $tweetPost.prop('checked', true); + } else { + $icon.toggleClass('disabled'); + $tweetPost.prop('checked', false); + } + }) + .catch(onRequestFail); + } + + /** + * Updates the counter + */ + function updateRemainingField() { + var count = $tweetText.val().length; + + $(counterWrap).text(count); + + // Toggle the .over-limit class. + if (limit < count) { + counterWrap.classList.add('over-limit'); + } else if (counterWrap.classList.contains('over-limit')) { + counterWrap.classList.remove('over-limit'); + } + } + + /** + * Helper for toggling classes to indicate something is happening. + */ + function pendingStatus() { + $icon.toggleClass('pending'); + $icon.removeClass('enabled'); + $icon.removeClass('disabled'); + } +})(jQuery); diff --git a/assets/js/admin-autotweet.js b/assets/js/admin-autotweet.js deleted file mode 100644 index 41baa4f8..00000000 --- a/assets/js/admin-autotweet.js +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Handles the Autotweet JS. - * - * @todo soooo much dependency :facepalm: - */ -( function( $ ) { - 'use strict'; - - var $tweetPost = $( '#autotweet-enable' ), - $icon = $( '#autotweet-icon' ), - $tweetText = $( '#autotweet-text' ), - $editLink = $( '#autotweet-edit' ), - $editBody = $( '#autotweet-override-body' ), - $hideLink = $( '.cancel-tweet-text' ), - errorMessageContainer = document.getElementById( 'autotweet-error-message' ), - counterWrap = document.getElementById( 'autotweet-counter-wrap' ), - limit = 280; - - // Add enabled class if checked - if ( $tweetPost.prop( 'checked' ) ) { - $icon.addClass( 'enabled' ); - } - - // Event handlers. - $tweetPost.on( 'click', handleRequest ); - $tweetText.change( handleRequest ); - $editLink.on( 'click', function() { - $editBody.slideToggle(); - updateRemainingField(); - $( this ).hide(); - } ); - $tweetText.on( 'keyup', function() { - updateRemainingField(); - } ); - $hideLink.on( 'click', function( e ) { - e.preventDefault(); - $( '#autotweet-override-body' ).slideToggle(); - $editLink.show(); - } ); - - // Runs on page load to auto-enable posts to be tweeted - window.onload = function( event ) { - if ( '' === adminAutotweet.currentStatus ) { - handleRequest( event, true ); - } - }; - - /** - * Callback for failed requests. - */ - function onRequestFail( error ) { - var errorText = ''; - if ( 'statusText' in error && 'status' in error ) { - errorText = `${adminAutotweet.errorText} ${error.status}: ${error.statusText}`; - } else { - errorText = adminAutotweet.unkonwnErrorText; - } - - errorMessageContainer.innerText = errorText; - - $icon.removeClass( 'pending' ); - $tweetPost.prop( 'checked', false ); - } - - /** - * AJAX handler - * @param event - */ - function handleRequest( event, status = $tweetPost.prop( 'checked' ) ) { - var data = {}; - data[adminAutotweet.enableAutotweetKey] = status; - data[adminAutotweet.tweetBodyKey] = $tweetText.val(); - - wp.apiFetch( - { - url: adminAutotweet.restUrl, - data: data, - method: 'POST', - parse: false // We'll check the response for errors. - } - ).then( - function( response ) { - if ( ! response.ok ) { - throw response; - } - - return response.json(); - } - ) - .then( - function( data ) { - errorMessageContainer.innerText = ''; - - $icon.removeClass( 'pending' ); - if ( data.enabled ) { - $icon.toggleClass( 'enabled' ); - $tweetPost.prop( 'checked', true ); - } else { - $icon.toggleClass( 'disabled' ); - $tweetPost.prop( 'checked', false ); - } - } - ).catch( onRequestFail ); - } - - /** - * Updates the counter - */ - function updateRemainingField() { - var count = $tweetText.val().length; - - $( counterWrap ).text( count ); - - // Toggle the .over-limit class. - if ( limit < count ) { - counterWrap.classList.add( 'over-limit' ); - } else if ( counterWrap.classList.contains( 'over-limit' ) ) { - counterWrap.classList.remove( 'over-limit' ); - } - } - - /** - * Helper for toggling classes to indicate something is happening. - */ - function pendingStatus() { - $icon.toggleClass( 'pending' ); - $icon.removeClass( 'enabled' ); - $icon.removeClass( 'disabled' ); - } -} )( jQuery ); diff --git a/autotweet.php b/autoshare-for-twitter.php similarity index 67% rename from autotweet.php rename to autoshare-for-twitter.php index 378266cb..cffc67ce 100644 --- a/autotweet.php +++ b/autoshare-for-twitter.php @@ -1,6 +1,6 @@ get_autotweet_meta( $post_id, ENABLE_AUTOTWEET_KEY ), - 'enableAutotweetKey' => ENABLE_AUTOTWEET_KEY, - 'errorText' => __( 'Error', 'autotweet' ), + 'enabled' => get_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY ), + 'enableAutoshareKey' => ENABLE_AUTOSHARE_FOR_TWITTER_KEY, + 'errorText' => __( 'Error', 'autoshare-for-twitter' ), 'nonce' => wp_create_nonce( 'wp_rest' ), - 'restUrl' => rest_url( post_autotweet_meta_rest_route( $post_id ) ), + 'restUrl' => rest_url( post_autoshare_for_twitter_meta_rest_route( $post_id ) ), 'tweetBodyKey' => TWEET_BODY_KEY, 'status' => $status_meta && is_array( $status_meta ) ? $status_meta : null, - 'unknownErrorText' => __( 'An unknown error occurred', 'autotweet' ), + 'unknownErrorText' => __( 'An unknown error occurred', 'autoshare-for-twitter' ), 'siteUrl' => home_url(), ]; - wp_localize_script( $handle, 'adminAutotweet', $localization ); + wp_localize_script( $handle, 'adminAutoshareForTwitter', $localization ); } diff --git a/includes/admin/post-meta.php b/includes/admin/post-meta.php index b3ed9440..1f675c02 100644 --- a/includes/admin/post-meta.php +++ b/includes/admin/post-meta.php @@ -2,30 +2,30 @@ /** * Responsible for the registration and display of the metabox. * - * @package TenUp\AutoTweet\Core + * @package TenUp\AutoshareForTwitter\Core */ -namespace TenUp\AutoTweet\Core\Post_Meta; +namespace TenUp\AutoshareForTwitter\Core\Post_Meta; /** * Aliases */ -use TenUp\AutoTweet\Utils as Utils; -use function TenUp\AutoTweet\Utils\update_autotweet_meta; -use function TenUp\AutoTweet\Utils\delete_autotweet_meta; +use TenUp\AutoshareForTwitter\Utils as Utils; +use function TenUp\AutoshareForTwitter\Utils\update_autoshare_for_twitter_meta; +use function TenUp\AutoshareForTwitter\Utils\delete_autoshare_for_twitter_meta; /** * The meta prefix that all meta related keys should have */ -const META_PREFIX = 'autotweet'; +const META_PREFIX = 'autoshare'; /** - * Enable autotweet checkbox + * Enable autoshare checkbox */ -const ENABLE_AUTOTWEET_KEY = 'autotweet'; +const ENABLE_AUTOSHARE_FOR_TWITTER_KEY = 'autoshare_for_twitter'; /** - * Holds the autotweet boddy + * Holds the autoshare body */ const TWEET_BODY_KEY = 'tweet-body'; @@ -34,7 +34,7 @@ * * @see post-transition.php */ -const TWITTER_STATUS_KEY = 'twitter-status'; +const TWITTER_STATUS_KEY = 'status'; /** * The setup function @@ -43,7 +43,7 @@ */ function setup() { add_action( 'post_submitbox_misc_actions', __NAMESPACE__ . '\tweet_submitbox_callback', 15 ); - add_action( 'tenup_autotweet_metabox', __NAMESPACE__ . '\render_tweet_submitbox', 10, 1 ); + add_action( 'autoshare_for_twitter_metabox', __NAMESPACE__ . '\render_tweet_submitbox', 10, 1 ); add_action( 'save_post', __NAMESPACE__ . '\save_tweet_meta', 10, 1 ); } @@ -60,22 +60,22 @@ function save_tweet_meta( $post_id ) { return; } - $form_data = sanitize_autotweet_meta_data( + $form_data = sanitize_autoshare_for_twitter_meta_data( // Using FILTER_DEFAULT here as data is being passed to sanitize function. filter_input( INPUT_POST, META_PREFIX, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ); - save_autotweet_meta_data( $post_id, $form_data ); + save_autoshare_for_twitter_meta_data( $post_id, $form_data ); } /** - * Sanitizes autotweet-related fields passed while saving a post. + * Sanitizes autoshare-related fields passed while saving a post. * * @since 1.0.0 * @param array $data Form data. * @return array Filtered form data. */ -function sanitize_autotweet_meta_data( $data ) { +function sanitize_autoshare_for_twitter_meta_data( $data ) { if ( empty( $data ) || ! is_array( $data ) ) { return []; } @@ -83,7 +83,7 @@ function sanitize_autotweet_meta_data( $data ) { $filtered_data = []; foreach ( $data as $key => $value ) { switch ( $key ) { - case ENABLE_AUTOTWEET_KEY: + case ENABLE_AUTOSHARE_FOR_TWITTER_KEY: $filtered_data[ $key ] = boolval( $value ); break; @@ -96,28 +96,28 @@ function sanitize_autotweet_meta_data( $data ) { } /** - * Saves fields in an array of autotweet meta. + * Saves fields in an array of autoshare meta. * * @since 1.0.0 * @param int $post_id WP_Post ID. * @param array $data Associative array of data to save. */ -function save_autotweet_meta_data( $post_id, $data ) { +function save_autoshare_for_twitter_meta_data( $post_id, $data ) { if ( empty( $data ) || ! is_array( $data ) ) { return; } foreach ( $data as $key => $value ) { switch ( $key ) { - case ENABLE_AUTOTWEET_KEY: - update_autotweet_meta( $post_id, ENABLE_AUTOTWEET_KEY, $value ); + case ENABLE_AUTOSHARE_FOR_TWITTER_KEY: + update_autoshare_for_twitter_meta( $post_id, ENABLE_AUTOSHARE_FOR_TWITTER_KEY, $value ); break; case TWEET_BODY_KEY: if ( ! empty( $value ) ) { - update_autotweet_meta( $post_id, TWEET_BODY_KEY, $value ); + update_autoshare_for_twitter_meta( $post_id, TWEET_BODY_KEY, $value ); } else { - delete_autotweet_meta( $post_id, TWEET_BODY_KEY ); + delete_autoshare_for_twitter_meta( $post_id, TWEET_BODY_KEY ); } } } @@ -133,15 +133,15 @@ function save_autotweet_meta_data( $post_id, $data ) { function tweet_submitbox_callback( $post ) { /** - * Don't bother enqueuing assets if the post type hasn't opted into autotweeting. + * Don't bother enqueuing assets if the post type hasn't opted into autosharing. */ - if ( ! Utils\opted_into_autotweet( $post->ID ) ) { + if ( ! Utils\opted_into_autoshare_for_twitter( $post->ID ) ) { return; } ?> -
%s', - esc_html__( 'Failed to tweet', 'tenup_autotweet' ), + esc_html__( 'Failed to tweet', 'autoshare-for-twitter' ), esc_html( $status_meta['message'] ) ); } @@ -291,7 +292,7 @@ function markup_unknown( $status_meta ) { } /** - * Outputs the markup required to set a post to autotweet. + * Outputs the markup required to set a post to autoshare. * * @return string */ @@ -299,34 +300,34 @@ function _safe_markup_default() { ob_start(); ?> -