Skip to content

Commit

Permalink
Rename autotweet to autoshare
Browse files Browse the repository at this point in the history
  • Loading branch information
John Watkins committed Oct 29, 2019
1 parent bade005 commit 905204e
Show file tree
Hide file tree
Showing 40 changed files with 623 additions and 716 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[
"@wordpress/babel-plugin-makepot",
{
"output": "languages/autotweet.pot",
"output": "languages/autoshare.pot"
}
],
]
]
}
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"globals": {
"adminAutotweet": "readonly",
"adminAutoshare": "readonly",
"jQuery": "readonly",
"wp": "readonly"
},
Expand Down
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
# Auto Tweet
# Auto Share 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)

## Overview

<<<<<<< HEAD
**NOTE:** Posts and pages are supported by default. Developers can use the `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.
=======
**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.
>>>>>>> develop
**Note:** Posts and pages are supported by default. Developers can use the `tenup_autoshare_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' );
}
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 auto-share. 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 auto-shared if they are already tweeted from the origin site. Auto Share 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_twitter-status' meta value from being distrivuted :

```php
add_filter( 'dt_blacklisted_meta', function( $blacklisted_metas ) {
$blacklisted_metas[] = 'autotweet_twitter-status';
$blacklisted_metas[] = 'autoshare_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.
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 auto-share. `add_post_type_support( 'post', 'autoshare' );`

## 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).

## 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/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 Share for Twitter.

## Like what you see?

Expand Down
42 changes: 21 additions & 21 deletions assets/css/admin-autotweet.css → assets/css/admin-autoshare.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#autotweet_metabox p::before {
#autoshare_metabox p::before {
display: inline-block;
margin-left: -1px;
padding-right: 3px;
Expand All @@ -7,63 +7,63 @@
-moz-osx-font-smoothing: grayscale;
}

#autotweet_metabox pre {
#autoshare_metabox pre {
font-size: 11px;
white-space: normal;
}

.autotweet-prepublish__checkbox .components-base-control__field, .autotweet-prepublish__checkbox-label {
.autoshare-prepublish__checkbox .components-base-control__field, .autoshare-prepublish__checkbox-label {
display: flex;
align-items: center;
}

.autotweet-prepublish__checkbox .components-base-control__field {
.autoshare-prepublish__checkbox .components-base-control__field {
margin-top: 0.5rem;
}

.autotweet-prepublish__checkbox-label svg {
.autoshare-prepublish__checkbox-label svg {
margin-right: 0.5rem;
}

.autotweet-prepublish__message-label {
.autoshare-prepublish__message-label {
display: flex;
justify-content: space-between;
}

.autotweet-prepublish__checkbox-row input[type=checkbox].components-checkbox-control__input {
.autoshare-prepublish__checkbox-row input[type=checkbox].components-checkbox-control__input {
margin-right: 0.5rem;
}

.autotweet-prepublish__override-row {
.autoshare-prepublish__override-row {
padding: 0.5rem 0;
}

.autotweet-prepublish__override-row .components-button {
.autoshare-prepublish__override-row .components-button {
margin-bottom: 1rem;
}

.autotweet-post-status {
.autoshare-post-status {
font-style: italic;
}

.autotweet-post-status svg {
.autoshare-post-status svg {
transform: translate3d(0, 3px, 0);
margin-right: 5px;
}

#autotweet-icon.pending,
.autotweet-prepublish__checkbox-row .dashicons-twitter.pending {
#autoshare-icon.pending,
.autoshare-prepublish__checkbox-row .dashicons-twitter.pending {
animation: fadeIn 1s infinite alternate;
color: #00aced;
}

#autotweet-icon.enabled,
.autotweet-prepublish__checkbox-row .dashicons-twitter.enabled {
#autoshare-icon.enabled,
.autoshare-prepublish__checkbox-row .dashicons-twitter.enabled {
color: #00aced;
}

#autotweet-icon.disabled,
.autotweet-prepublish__checkbox-row .dashicons-twitter.disabled {
#autoshare-icon.disabled,
.autoshare-prepublish__checkbox-row .dashicons-twitter.disabled {
color: #72777c;
}

Expand All @@ -74,23 +74,23 @@
}
}

a#autotweet-edit {
a#autoshare-edit {
color: #0073aa;
text-decoration: underline;
transition-property: border, background, color;
transition-duration: .05s;
transition-timing-function: ease-in-out
}

#autotweet-override-body {
#autoshare-override-body {
margin: 4px 0;
}

textarea#autotweet-text {
textarea#autoshare-text {
margin: 4px 0 0;
width: 100%
}
span#autotweet-counter-wrap {
span#autoshare-counter-wrap {
background: rgba(0, 0, 0, 0.07);
font-family: Consolas, Monaco, monospace;
}
Expand Down
126 changes: 126 additions & 0 deletions assets/js/admin-autoshare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Handles the Autoshare JS.
*
* @todo soooo much dependency :facepalm:
*/
(function($) {
'use strict';

var $tweetPost = $('#autoshare-enable'),
$icon = $('#autoshare-icon'),
$tweetText = $('#autoshare-text'),
$editLink = $('#autoshare-edit'),
$editBody = $('#autoshare-override-body'),
$hideLink = $('.cancel-tweet-text'),
errorMessageContainer = document.getElementById('autoshare-error-message'),
counterWrap = document.getElementById('autoshare-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-override-body').slideToggle();
$editLink.show();
});

// Runs on page load to auto-enable posts to be tweeted
window.onload = function(event) {
if ('' === adminAutoshare.currentStatus) {
handleRequest(event, true);
}
};

/**
* Callback for failed requests.
*/
function onRequestFail(error) {
var errorText = '';
if ('statusText' in error && 'status' in error) {
errorText = `${adminAutoshare.errorText} ${error.status}: ${error.statusText}`;
} else {
errorText = adminAutoshare.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[adminAutoshare.enableAutoshareKey] = status;
data[adminAutoshare.tweetBodyKey] = $tweetText.val();

wp.apiFetch({
url: adminAutoshare.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);
Loading

0 comments on commit 905204e

Please sign in to comment.