-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-dapp.php
More file actions
203 lines (181 loc) · 6.51 KB
/
wp-dapp.php
File metadata and controls
203 lines (181 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* Plugin Name: WP-Dapp: Hive Integration
* Description: A plugin to post content from WordPress to Hive with Keychain support for beneficiaries, tags, and more.
* Version: 0.7.4
* Author: DiggnDeeper
* Author URI: https://diggndeeper.com
* Plugin URI: https://github.com/DiggnDeeper/wp-dapp
* Requires at least: 5.0
* Requires PHP: 7.4
* Text Domain: wp-dapp
* Domain Path: /languages
* License: MIT
* License URI: https://opensource.org/licenses/MIT
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Define plugin constants
define( 'WPDAPP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'WPDAPP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'WPDAPP_VERSION', '0.7.4' );
define( 'WPDAPP_REPO_URL', 'https://github.com/DiggnDeeper/wp-dapp' );
/**
* Safely include a file with error handling
*
* @param string $file File path to include
* @return bool True if successful, false otherwise
*/
function wpdapp_safe_include( $file ) {
if ( ! file_exists( $file ) ) {
return false;
}
try {
include_once $file;
return true;
} catch ( Exception $e ) {
// Log the error or handle it silently
return false;
}
}
// Include required core files
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-hive-api.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-publish-handler.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-settings-page.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-post-meta.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-ajax-handler.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-comment-sync.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-frontend.php' );
wpdapp_safe_include( WPDAPP_PLUGIN_DIR . 'includes/class-update-checker.php' );
/**
* Plugin version update handler - runs when plugin version changes
*/
function wpdapp_version_update() {
$current_version = get_option( 'wpdapp_version', '0.0.0' );
// If this is a new installation or update from an older version
if ( version_compare( $current_version, WPDAPP_VERSION, '<' ) ) {
// Get current options
$options = get_option( 'wpdapp_options', array() );
// Update stored version
update_option( 'wpdapp_version', WPDAPP_VERSION );
}
}
add_action( 'plugins_loaded', 'wpdapp_version_update', 5 ); // Priority 5 to run before other init functions
/**
* Initialize plugin classes on plugins_loaded
*/
function wpdapp_init() {
// Load plugin textdomain
load_plugin_textdomain( 'wp-dapp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
// Initialize classes
new WP_Dapp_Settings_Page();
new WP_Dapp_Post_Meta();
new WP_Dapp_Publish_Handler();
new WP_Dapp_Ajax_Handler();
// Initialize comment sync (registers cron schedule and hook)
if ( class_exists( 'WP_Dapp_Comment_Sync' ) ) {
new WP_Dapp_Comment_Sync();
}
// Initialize front-end helpers (shortcode and notice)
if ( class_exists( 'WP_Dapp_Frontend' ) ) {
new WP_Dapp_Frontend();
}
// Initialize update checker if available
if ( class_exists( 'WP_Dapp_Update_Checker' ) ) {
new WP_Dapp_Update_Checker();
}
}
add_action( 'plugins_loaded', 'wpdapp_init' );
/**
* Plugin activation hook
*/
function wpdapp_activate() {
// Set default options
$default_options = array(
'hive_account' => '',
'enable_default_beneficiary' => '1',
'default_beneficiary_account' => 'diggndeeper.com',
'default_beneficiary_weight' => '100', // 1%
'default_tags' => 'blog,wordpress',
'enable_comment_sync' => 0,
'auto_approve_comments' => 0,
'hive_frontend' => 'peakd',
'hive_max_thread_depth' => 4,
'show_reply_buttons' => 1,
);
// Only set options if they don't exist
if ( ! get_option( 'wpdapp_options' ) ) {
add_option( 'wpdapp_options', $default_options );
}
// Clear any transients
delete_transient( 'wpdapp_update_check' );
// Ensure our cron schedule exists before scheduling the event
if ( class_exists( 'WP_Dapp_Comment_Sync' ) ) {
new WP_Dapp_Comment_Sync();
}
// Schedule recurring comment sync if not already scheduled
if ( ! wp_next_scheduled( 'wpdapp_sync_hive_comments_event' ) ) {
// Default to our 15-minute schedule; if unavailable, fallback to hourly
$schedules = wp_get_schedules();
$recurrence = isset( $schedules['wpdapp_every_15_minutes'] ) ? 'wpdapp_every_15_minutes' : 'hourly';
wp_schedule_event( time() + 5 * 60, $recurrence, 'wpdapp_sync_hive_comments_event' );
}
}
register_activation_hook( __FILE__, 'wpdapp_activate' );
/**
* Plugin deactivation hook
*/
function wpdapp_deactivate() {
// Clean up transients
delete_transient( 'wpdapp_update_check' );
// Clear scheduled comment sync
wp_clear_scheduled_hook( 'wpdapp_sync_hive_comments_event' );
}
register_deactivation_hook( __FILE__, 'wpdapp_deactivate' );
/**
* Plugin uninstall hook (static method)
*/
function wpdapp_uninstall() {
// Get options
$options = get_option( 'wpdapp_options', array() );
// Delete options and data if requested
if ( ! empty( $options['delete_data_on_uninstall'] ) ) {
delete_option( 'wpdapp_options' );
// Delete post meta
global $wpdb;
$wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_wpdapp_%'" );
}
}
register_uninstall_hook( __FILE__, 'wpdapp_uninstall' );
// Add plugin action links
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wpdapp_plugin_action_links' );
function wpdapp_plugin_action_links( $links ) {
$settings_link = '<a href="' . admin_url( 'options-general.php?page=wpdapp-settings' ) . '">' . __( 'Settings', 'wp-dapp' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
/**
* WP-Dapp Tag System Documentation
*
* This plugin handles tags from multiple sources and manages them for Hive publishing.
*
* Tag Sources:
* 1. WordPress Categories: Automatically converted to Hive tags
* 2. WordPress Tags: Automatically converted to Hive tags
* 3. Default Tags: Global tags set in the plugin settings
*
* Tag Processing:
* - All tags from the different sources are combined
* - Duplicates are removed (array_unique)
* - Tags are limited to 5 (Hive's maximum) using array_slice
* - The first tag becomes the "parent_permlink" in Hive (main category)
* - If no tags are available, 'blog' is used as a default
*
* Hive Tag Requirements:
* - Tags must be lowercase letters, numbers, or hyphens
* - No spaces or special characters allowed
* - The plugin automatically converts tags to meet these requirements
* - Maximum of 5 tags per post
* - At least 1 tag is required
*/