Skip to content
Merged

Release #1069

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ vue
webpack.config.js
docker-compose.yml
phpstan.neon
phpstan-baseline.neon
phpstan-baseline.neon
AGENTS.md
106 changes: 106 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Agent Workflow

## Project Overview

**Revive Old Posts (Revive Social)** — a WordPress plugin that automatically shares WordPress posts to social networks (Facebook, X/Twitter, LinkedIn, Instagram, Telegram, Mastodon, BlueSky, VK, Pinterest, TikTok, etc.) with scheduling and automation.

- **Text Domain:** `tweet-old-post`
- **Main Plugin File:** `tweet-old-post.php`
- **Pro Companion Plugin:** `tweet-old-post-pro` (separate repo)

## Build & Development Commands

```bash
# Install dependencies
npm ci
composer install

# Build assets (Vue dashboard + React sharing panel)
npm run build # Production webpack build (Vue)
npm run sharing # Production wp-scripts build (React)

# Development with watch
npm run dev # Webpack watch mode (Vue)
npm run sharing-dev # wp-scripts dev mode (React)

# Linting
composer run lint # PHPCS (WordPress-Core standard)
composer run format # Auto-fix PHP code style
npm run lint # ESLint for Vue + React files
npm run format # ESLint auto-fix

# Testing
composer run test # PHPUnit (all suites)
./vendor/bin/phpunit tests/test-content.php # Single test file
composer run phpstan # Static analysis (level 6)

# E2E Testing (requires wp-env)
npm run wp-env start # Start WordPress environment
npm run test:e2e:playwright # Run Playwright E2E tests
npm run test:e2e:playwright:ui # E2E with Playwright UI mode

# Distribution
npm run dist # Create distribution ZIP archive
```

## Architecture

### Entry Point & Autoloading

`tweet-old-post.php` defines constants (prefixed `ROP_`), registers activation/deactivation hooks, sets up a custom autoloader (`class-rop-autoloader.php`), and calls `run_rop()` which instantiates the `Rop` core class.

The autoloader scans `includes/` recursively, matching classes by the `Rop` namespace prefix. Class files follow the convention `class-{slug-case-name}.php`.

### Core Class Hierarchy

- **`Rop`** (`includes/class-rop.php`) — Core plugin class. Loads dependencies, sets up i18n, defines admin hooks.
- **`Rop_Loader`** (`includes/class-rop-loader.php`) — Central hook registration system. Actions/filters are queued then bulk-registered.
- **`Rop_Admin`** (`includes/admin/class-rop-admin.php`) — Admin UI, script/style enqueuing, menu registration. ~2,000 lines.
- **`Rop_Rest_Api`** (`includes/admin/class-rop-rest-api.php`) — REST endpoints at `tweet-old-post/v8/api` and `tweet-old-post/v8/share/{id}`. Requires `manage_options` capability. ~1,700 lines.

### Service Layer (Social Networks)

`includes/admin/services/` — Each social network has a service class extending `Rop_Services_Abstract` (Strategy pattern):
- Key methods: `get_service_credentials()`, `login()`, `publish()`, `get_account()`
- Services: Twitter, Facebook, LinkedIn, Mastodon, BlueSky, Telegram, VK, Pinterest, Tumblr, GMB, Webhook

### Models (Data Layer)

`includes/admin/models/` — Settings, services, queue, scheduler, post format, post selector, URL shorteners. Models store data in WordPress options.

### Helpers

`includes/admin/helpers/` — Content manipulation, post formatting, cron scheduling, DB migrations, logging, custom API clients (Telegram, BlueSky).

### URL Shorteners

`includes/admin/shortners/` — Each shortener extends `Rop_Url_Shortner_Abstract` (Bitly, Firebase, Rebrandly, is.gd, ow.ly, rviv.ly).

### Frontend (Two Systems)

1. **Vue 2 Dashboard** (legacy) — Built via `webpack.config.js`. Entry points in `vue/src/` → output to `assets/js/build/`. Uses Vuex for state, vue-resource for HTTP.
2. **React Components** (new) — Built via `webpack.sharing.config.js` using `@wordpress/scripts`. Source in `src/` → output to `assets/js/react/build/`. Used for instant/manual sharing in the block editor.

### Cron System

`cron-system/` — Alternative remote cron implementation (`RopCronSystem\Rop_Cron_Core`). Activated when `ROP_CRON_ALTERNATIVE` is true (controlled by `rop_use_remote_cron` option).

### External Auth

Social network authentication goes through `ROP_AUTH_APP_URL` (`https://app.revive.social`) with per-service paths (`/fb_auth`, `/tw_auth`, `/li_auth`, etc.).

## Coding Standards

- **PHP:** WordPress-Core via PHPCS (`phpcs.xml`) with many naming convention rules relaxed — camelCase variables/methods are allowed throughout the codebase
- **JS (Vue):** `plugin:vue/recommended` with babel-eslint parser
- **JS (React):** `@wordpress/eslint-plugin/recommended` with text domain enforced as `tweet-old-post`
- **Static Analysis:** PHPStan level 6 with WordPress extension and baseline (`phpstan-baseline.neon`)

## Testing Structure

PHPUnit test suites are defined in `phpunit.xml` with individual files in `tests/`:
- `test-plugin.php`, `test-accounts.php`, `test-content.php`, `test-logger.php`, `test-post-format.php`, `test-queue.php`, `test-scheduler.php`, `test-selector.php`

E2E tests use Playwright with `@wordpress/e2e-test-utils-playwright`. Specs live in `tests/e2e/specs/`. Config at `tests/e2e/playwright.config.js`.

PHPUnit bootstrap (`tests/bootstrap.php`) requires WordPress test suite via `WP_TESTS_DIR` env var.
16 changes: 8 additions & 8 deletions composer.lock

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

2 changes: 1 addition & 1 deletion includes/admin/abstract/class-rop-model-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function set( $key, $value = '', $refresh = false ) {

$this->data[ $key ] = apply_filters( 'rop_set_key_' . $key, $value );

return update_option( $this->namespace, $this->data );
return update_option( $this->namespace, $this->data, false );
}


Expand Down
52 changes: 40 additions & 12 deletions includes/admin/class-rop-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,12 @@ public function get_survey_metadata() {
* @return array
*/
public function rop_upgrade_to_pro_plugin_action( $actions, $plugin_file ) {

$is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false );
if ( $is_black_friday ) {
return $actions;
}

$global_settings = new \Rop_Global_Settings();
$actions['settings'] = '<a href="' . admin_url( 'admin.php?page=TweetOldPost' ) . '">' . __( 'Settings', 'tweet-old-post' ) . '</a>';
if ( $global_settings->license_type() < 1 ) {
Expand Down Expand Up @@ -1908,32 +1914,54 @@ public function get_languages() {
public static function add_black_friday_data( $configs ) {
$config = $configs['default'];

// translators: %1$s - HTML tag, %2$s - discount, %3$s - HTML tag, %4$s - product name.
$message_template = __( 'Our biggest sale of the year: %1$sup to %2$s OFF%3$s on %4$s. Don\'t miss this limited-time offer.', 'tweet-old-post' );
$product_label = __( 'Revive Social', 'tweet-old-post' );
$discount = '50%';
$message = __( 'Custom schedules, multiple accounts, analytics. Automate your social sharing properly. Exclusively for existing Revive Social users.', 'tweet-old-post' );
$cta_label = __( 'Get Revive Social Pro', 'tweet-old-post' );

$plan = apply_filters( 'product_rop_license_plan', 0 );
$license = apply_filters( 'product_rop_license_key', false );
$is_pro = 0 < $plan;
$status = apply_filters( 'product_rop_license_status', false );
$is_pro = 'valid' === $status;
$is_expired = 'expired' === $status || 'active-expired' === $status;

$pro_product_slug = defined( 'ROP_PRO_BASEFILE' ) ? basename( dirname( ROP_PRO_BASEFILE ) ) : '';

if ( $is_pro || $is_expired ) {
$config['plugin_meta_targets'] = array( $pro_product_slug );
}

if ( $is_pro ) {
// translators: %1$s - HTML tag, %2$s - discount, %3$s - HTML tag, %4$s - product name.
$message_template = __( 'Get %1$sup to %2$s off%3$s when you upgrade your %4$s plan or renew early.', 'tweet-old-post' );
$product_label = __( 'Revive Social Pro', 'tweet-old-post' );
$discount = '20%';
// translators: %s is the discount percentage.
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - up to %s off', 'tweet-old-post' ), '30%' );
// translators: %1$s - discount, %2$s - discount.
$message = sprintf( __( 'Upgrade your Revive Social Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'tweet-old-post' ), '30%', '20%' );
$cta_label = __( 'See your options', 'tweet-old-post' );
} elseif ( $is_expired ) {
// translators: %s is the discount percentage.
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'tweet-old-post' ), '50%' );
// translators: %s - discount.
$config['upgrade_menu_text'] = sprintf( __( 'BF Sale - %s off', 'tweet-old-post' ), '50%' );
$message = __( 'Your Revive Social Pro features are still here, just locked. Renew at a reduced rate this week.', 'tweet-old-post' );
$cta_label = __( 'Reactivate now', 'tweet-old-post' );
} else {
// translators: %s is the discount percentage.
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'tweet-old-post' ), '50%' );
// translators: %s - discount.
$config['title'] = sprintf( __( 'Revive Social Pro: %s off this week', 'tweet-old-post' ), '60%' );
// translators: %s - discount.
$config['upgrade_menu_text'] = sprintf( __( 'BF Sale - %s off', 'tweet-old-post' ), '60%' );
}

$product_label = sprintf( '<strong>%s</strong>', $product_label );
$url_params = array(
'utm_term' => $is_pro ? 'plan-' . $plan : 'free',
'lkey' => ! empty( $license ) ? $license : false,
'expired' => $is_expired ? '1' : false,
);

$config['message'] = sprintf( $message_template, '<strong>', $discount, '</strong>', $product_label );
$config['message'] = $message;
$config['cta_label'] = $cta_label;
$config['sale_url'] = add_query_arg(
$url_params,
tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/rs-bf', 'bfcm', 'revive' ) )
tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/rs-bf', 'bfcm', 'revive' ) )
);

$configs[ ROP_PRODUCT_SLUG ] = $config;
Expand Down
29 changes: 28 additions & 1 deletion includes/admin/class-rop-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class Rop_Logger {
*/
private $stream;

/**
* Holds the log namespace.
*
* @access private
* @var string $log_namespace Defaults 'rop_logs'.
*/
private $log_namespace = 'rop_logs';

/**
* Rop_Logger constructor.
* Instantiate the Logger with specified formatter and stream.
Expand All @@ -38,7 +46,7 @@ class Rop_Logger {
*/
public function __construct() {

$this->stream = new Rop_Log_Handler( 'rop_logs' );
$this->stream = new Rop_Log_Handler( $this->log_namespace );

}

Expand Down Expand Up @@ -230,4 +238,23 @@ public function is_status_error_necessary( $logs = array() ) {

}

/**
* Utility method to cleanup authenticated services.
*
* @access public
*
* @param int $cleanup_log_count Cleanup the log count.
* @return array<string, mixed>
*/
public function cleanup_logs( $cleanup_log_count = 1000 ) {
$logs = $this->stream->get_logs();

if ( count( $logs ) > $cleanup_log_count ) {
$logs = array_slice( $logs, 0, $cleanup_log_count );

update_option( $this->log_namespace, array_reverse( $logs ), false );
}

return $logs;
}
}
14 changes: 14 additions & 0 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,20 @@ private function add_account_bluesky( $data ) {
return $this->response->to_array();
}

/**
* API method called to cleanup logs.
*
* @access private
* @return array<string, mixed>
*/
private function cleanup_logs() {
$model = new Rop_Logger();
$this->response->set_code( '200' )
->set_data( $model->cleanup_logs() );

return $this->response->to_array();
}

/**
* Share API method.
*
Expand Down
44 changes: 43 additions & 1 deletion includes/admin/helpers/class-rop-bluesky-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,19 @@ public function create_post( $did, $post, $post_type, $hashtags, $access_token =

$now = gmdate( 'Y-m-d\TH:i:s\Z' );

$text = $post['content'] . $hashtags;

$record = array(
'$type' => 'app.bsky.feed.post',
'text' => $post['content'] . $hashtags,
'text' => $text,
'createdAt' => $now,
);

$facets = $this->generate_facets( $text );
if ( ! empty( $facets ) ) {
$record['facets'] = $facets;
}

if ( $post_type === 'link' && isset( $post['post_url'] ) && ! empty( $post['post_url'] ) ) {
$record['embed'] = array(
'$type' => 'app.bsky.embed.external',
Expand Down Expand Up @@ -369,6 +376,41 @@ public function create_post( $did, $post, $post_type, $hashtags, $access_token =
}
}

/**
* Generate facets for hashtags.
*
* @param string $text The text to parse.
*
* @return mixed|array
*/
private function generate_facets( $text ) {
$facets = array();
preg_match_all( '/#\S+/', $text, $matches, PREG_OFFSET_CAPTURE );

if ( ! empty( $matches[0] ) ) {
foreach ( $matches[0] as $match ) {
$hashtag = $match[0];
$start = $match[1];
$end = $start + strlen( $hashtag );

$facets[] = array(
'index' => array(
'byteStart' => $start,
'byteEnd' => $end,
),
'features' => array(
array(
'$type' => 'app.bsky.richtext.facet#tag',
'tag' => ltrim( $hashtag, '#' ),
),
),
);
}
}

return $facets;
}

/**
* Fetch Website Card embeds.
*
Expand Down
2 changes: 0 additions & 2 deletions includes/admin/models/class-rop-services-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Rop_Services_Model extends Rop_Model_Abstract {
*/
private $accounts_namespace = 'active_accounts';


/**
* Utility method to clear authenticated services.
*
Expand Down Expand Up @@ -519,5 +518,4 @@ public function find_account( $account_id ) {

return false;
}

}
Loading
Loading