| 1 |
<?php |
| 2 |
/** |
| 3 |
* @wordpress-plugin |
| 4 |
* Plugin Name: Pushly |
| 5 |
* Plugin URI: http://pushly.com |
| 6 |
* Description: Provide Pushly push notification capability to WordPress installations |
| 7 |
* Version: 2.2.1 |
| 8 |
* Author: Pushly |
| 9 |
* Author URI: http://pushly.com/ |
| 10 |
* License: GPLv2 |
| 11 |
* Text Domain: pushly |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
require_once dirname( __FILE__ ) . '/environment.php'; |
| 19 |
require_once PUSHLY__DIR . '/vendor/autoload.php'; |
| 20 |
|
| 21 |
add_action( 'init', function (): void { |
| 22 |
// Settings — admin UI hooks are gated internally, but register_settings |
| 23 |
// must also run on rest_api_init so it's registered unconditionally. |
| 24 |
$settings = new \Pushly\Admin\Settings(); |
| 25 |
$settings->register_hooks(); |
| 26 |
|
| 27 |
// Post — hooks into both admin (meta boxes, notices) and REST (post meta, |
| 28 |
// transition_post_status, rest_after_insert). Must be unconditional so |
| 29 |
// Gutenberg REST saves work correctly. |
| 30 |
$options = get_option( 'pushly', [] ); |
| 31 |
|
| 32 |
$log_store = new \Pushly\Admin\LogStore(); |
| 33 |
$log_writer = new \Pushly\Admin\LogWriter( $log_store, ! empty( $options['debug_logging_enabled'] ) ); |
| 34 |
$log_writer->register_hooks(); |
| 35 |
|
| 36 |
$post = new \Pushly\Admin\Post( $options, $log_writer ); |
| 37 |
$post->register_hooks(); |
| 38 |
|
| 39 |
// REST controller — runs on both admin and REST contexts |
| 40 |
$activity_log_controller = new \Pushly\Admin\ActivityLogController( $log_store ); |
| 41 |
$activity_log_controller->register_hooks(); |
| 42 |
|
| 43 |
// Frontend SDK — runs on public-facing requests only |
| 44 |
if ( ! is_admin() ) { |
| 45 |
$sdk = new \Pushly\Frontend\SDK(); |
| 46 |
$sdk->register_hooks(); |
| 47 |
} |
| 48 |
|
| 49 |
// Site Health — admin only |
| 50 |
if ( is_admin() ) { |
| 51 |
$site_health = new \Pushly\Admin\SiteHealth( $log_store ); |
| 52 |
$site_health->register_hooks(); |
| 53 |
} |
| 54 |
|
| 55 |
// WP-Cron pruning — schedule daily cleanup when debug logging is enabled. |
| 56 |
if ( ! empty( $options['debug_logging_enabled'] ) && ! wp_next_scheduled( 'pushly_prune_activity_log' ) ) { |
| 57 |
wp_schedule_event( time(), 'daily', 'pushly_prune_activity_log' ); |
| 58 |
} |
| 59 |
|
| 60 |
// Hook the cron action to the LogStore pruning method. |
| 61 |
add_action( 'pushly_prune_activity_log', [ $log_store, 'prune_old_entries' ] ); |
| 62 |
} ); |
| 63 |
|
| 64 |
// Activation hook — create the activity log table. |
| 65 |
register_activation_hook( __FILE__, function (): void { |
| 66 |
$log_store = new \Pushly\Admin\LogStore(); |
| 67 |
$log_store->create_table(); |
| 68 |
} ); |
| 69 |
|
| 70 |
// Deactivation hook — unschedule the cron event. |
| 71 |
register_deactivation_hook( __FILE__, function (): void { |
| 72 |
wp_clear_scheduled_hook( 'pushly_prune_activity_log' ); |
| 73 |
} ); |
| 74 |
|