Upload file wp-business-forum.php via GUI
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: WP Business Forum
|
* Plugin Name: WP Business Forum
|
||||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Business-Forum
|
* Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Business-Forum
|
||||||
* Description: Professionelles Forum mit eigenem Login, Rollen, Signaturen, Hierarchie und Moderations-Tools.
|
* Description: Professionelles Forum mit eigenem Login, Rollen, Signaturen, Hierarchie und Moderations-Tools.
|
||||||
* Version: 1.0.1
|
* Version: 1.0.2
|
||||||
* Author: M_Viper
|
* Author: M_Viper
|
||||||
* Author URI: https://m-viper.de
|
* Author URI: https://m-viper.de
|
||||||
* Text Domain: wp-business-forum
|
* Text Domain: wp-business-forum
|
||||||
@@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
|||||||
|
|
||||||
define( 'WBF_PATH', plugin_dir_path( __FILE__ ) );
|
define( 'WBF_PATH', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'WBF_URL', plugin_dir_url( __FILE__ ) );
|
define( 'WBF_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'WBF_VERSION', '1.0.1' );
|
define( 'WBF_VERSION', '1.0.2' );
|
||||||
|
|
||||||
require_once WBF_PATH . 'includes/class-forum-db.php';
|
require_once WBF_PATH . 'includes/class-forum-db.php';
|
||||||
require_once WBF_PATH . 'includes/class-forum-roles.php';
|
require_once WBF_PATH . 'includes/class-forum-roles.php';
|
||||||
@@ -22,6 +22,7 @@ require_once WBF_PATH . 'includes/class-forum-bbcode.php';
|
|||||||
require_once WBF_PATH . 'includes/class-forum-auth.php';
|
require_once WBF_PATH . 'includes/class-forum-auth.php';
|
||||||
require_once WBF_PATH . 'includes/class-forum-shortcodes.php';
|
require_once WBF_PATH . 'includes/class-forum-shortcodes.php';
|
||||||
require_once WBF_PATH . 'includes/class-forum-ajax.php';
|
require_once WBF_PATH . 'includes/class-forum-ajax.php';
|
||||||
|
require_once WBF_PATH . 'includes/class-forum-export.php';
|
||||||
require_once WBF_PATH . 'admin/forum-admin.php';
|
require_once WBF_PATH . 'admin/forum-admin.php';
|
||||||
require_once WBF_PATH . 'admin/forum-settings.php';
|
require_once WBF_PATH . 'admin/forum-settings.php';
|
||||||
require_once WBF_PATH . 'admin/forum-setup.php';
|
require_once WBF_PATH . 'admin/forum-setup.php';
|
||||||
@@ -33,6 +34,11 @@ register_activation_hook( __FILE__, function() {
|
|||||||
set_transient( 'wbf_activation_redirect', true, 30 );
|
set_transient( 'wbf_activation_redirect', true, 30 );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ── Export / Import Hooks ─────────────────────────────────────────────────────
|
||||||
|
add_action( 'plugins_loaded', function() {
|
||||||
|
WBF_Export::hooks();
|
||||||
|
}, 5 );
|
||||||
|
|
||||||
// ── Superadmin-Sync ───────────────────────────────────────────────────────────
|
// ── Superadmin-Sync ───────────────────────────────────────────────────────────
|
||||||
add_action( 'wp_login', function() { WBF_Roles::sync_superadmin(); } );
|
add_action( 'wp_login', function() { WBF_Roles::sync_superadmin(); } );
|
||||||
add_action( 'init', function() { WBF_Roles::sync_superadmin(); } );
|
add_action( 'init', function() { WBF_Roles::sync_superadmin(); } );
|
||||||
@@ -57,6 +63,7 @@ if ( ! wp_next_scheduled( 'wbf_check_expired_bans' ) ) {
|
|||||||
|
|
||||||
register_deactivation_hook( __FILE__, function() {
|
register_deactivation_hook( __FILE__, function() {
|
||||||
wp_clear_scheduled_hook( 'wbf_check_expired_bans' );
|
wp_clear_scheduled_hook( 'wbf_check_expired_bans' );
|
||||||
|
wp_clear_scheduled_hook( 'wbf_check_for_updates' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
@@ -98,4 +105,156 @@ add_action( 'wp_enqueue_scripts', function() {
|
|||||||
'forum_url' => wbf_get_forum_url(),
|
'forum_url' => wbf_get_forum_url(),
|
||||||
'reactions' => WBF_DB::get_allowed_reactions(),
|
'reactions' => WBF_DB::get_allowed_reactions(),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// ══════════════════════════════════════════════════════════════════════════════
|
||||||
|
// ── Update-Checker ────────────────────────────────────────────────────────────
|
||||||
|
// Prüft täglich gegen die Gitea-Releases-API ob eine neue Version verfügbar ist.
|
||||||
|
// Releases-URL: https://git.viper.ipv64.net/M_Viper/WP-Business-Forum/releases
|
||||||
|
// ══════════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
define( 'WBF_UPDATE_API', 'https://git.viper.ipv64.net/api/v1/repos/M_Viper/WP-Business-Forum/releases?limit=1&page=1' );
|
||||||
|
define( 'WBF_RELEASES_PAGE', 'https://git.viper.ipv64.net/M_Viper/WP-Business-Forum/releases' );
|
||||||
|
define( 'WBF_UPDATE_TRANSIENT','wbf_update_check' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holt die neueste Release-Info von Gitea (gecacht per Transient, 12h).
|
||||||
|
* Gibt null zurück wenn kein Update verfügbar oder API nicht erreichbar.
|
||||||
|
*
|
||||||
|
* @return array|null ['version'=>string, 'url'=>string, 'name'=>string, 'published'=>string, 'body'=>string]
|
||||||
|
*/
|
||||||
|
function wbf_get_latest_release() {
|
||||||
|
$cached = get_transient( WBF_UPDATE_TRANSIENT );
|
||||||
|
if ( $cached !== false ) {
|
||||||
|
return $cached ?: null; // false = noch nie gecacht, '' = kein Update
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = wp_remote_get( WBF_UPDATE_API, [
|
||||||
|
'timeout' => 8,
|
||||||
|
'user-agent' => 'WP-Business-Forum/' . WBF_VERSION . '; ' . get_bloginfo('url'),
|
||||||
|
'sslverify' => true,
|
||||||
|
] );
|
||||||
|
|
||||||
|
if ( is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200 ) {
|
||||||
|
// Bei Fehler 1h warten bevor erneut versucht
|
||||||
|
set_transient( WBF_UPDATE_TRANSIENT, '', HOUR_IN_SECONDS );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = wp_remote_retrieve_body( $response );
|
||||||
|
$releases = json_decode( $body, true );
|
||||||
|
|
||||||
|
if ( empty($releases) || ! is_array($releases) || empty($releases[0]) ) {
|
||||||
|
set_transient( WBF_UPDATE_TRANSIENT, '', 12 * HOUR_IN_SECONDS );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$latest = $releases[0];
|
||||||
|
$version = ltrim( $latest['tag_name'] ?? '', 'v' ); // "v1.2.0" → "1.2.0"
|
||||||
|
|
||||||
|
$info = [
|
||||||
|
'version' => $version,
|
||||||
|
'url' => $latest['html_url'] ?? WBF_RELEASES_PAGE,
|
||||||
|
'name' => $latest['name'] ?? $latest['tag_name'] ?? $version,
|
||||||
|
'published' => $latest['published_at'] ?? '',
|
||||||
|
'body' => wp_strip_all_tags( $latest['body'] ?? '' ),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 12 Stunden cachen
|
||||||
|
set_transient( WBF_UPDATE_TRANSIENT, $info, 12 * HOUR_IN_SECONDS );
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft ob ein Update verfügbar ist.
|
||||||
|
* Gibt die Release-Info zurück wenn Gitea-Version > installierte Version.
|
||||||
|
*/
|
||||||
|
function wbf_update_available() {
|
||||||
|
$latest = wbf_get_latest_release();
|
||||||
|
if ( ! $latest || empty($latest['version']) ) return null;
|
||||||
|
if ( version_compare( $latest['version'], WBF_VERSION, '>' ) ) {
|
||||||
|
return $latest;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Cron: täglich Update prüfen (Cache warm halten) ──────────────────────────
|
||||||
|
add_action( 'wbf_check_for_updates', function() {
|
||||||
|
delete_transient( WBF_UPDATE_TRANSIENT );
|
||||||
|
wbf_get_latest_release();
|
||||||
|
} );
|
||||||
|
|
||||||
|
if ( ! wp_next_scheduled( 'wbf_check_for_updates' ) ) {
|
||||||
|
wp_schedule_event( time(), 'twicedaily', 'wbf_check_for_updates' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Admin-Notice wenn Update verfügbar ───────────────────────────────────────
|
||||||
|
add_action( 'admin_notices', function() {
|
||||||
|
if ( ! current_user_can('manage_options') ) return;
|
||||||
|
|
||||||
|
$update = wbf_update_available();
|
||||||
|
if ( ! $update ) return;
|
||||||
|
|
||||||
|
// Notice ausblenden wenn der User sie weggeklickt hat (per GET-Parameter)
|
||||||
|
if ( isset($_GET['wbf_dismiss_update']) && check_admin_referer('wbf_dismiss_update') ) {
|
||||||
|
set_transient( 'wbf_update_dismissed_' . WBF_VERSION, $update['version'], 7 * DAY_IN_SECONDS );
|
||||||
|
wp_safe_redirect( remove_query_arg(['wbf_dismiss_update','_wpnonce']) );
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dismissed = get_transient( 'wbf_update_dismissed_' . WBF_VERSION );
|
||||||
|
if ( $dismissed === $update['version'] ) return;
|
||||||
|
|
||||||
|
$dismiss_url = wp_nonce_url(
|
||||||
|
add_query_arg('wbf_dismiss_update', '1'),
|
||||||
|
'wbf_dismiss_update'
|
||||||
|
);
|
||||||
|
$changelog_url = esc_url( $update['url'] );
|
||||||
|
$new_ver = esc_html( $update['version'] );
|
||||||
|
$cur_ver = esc_html( WBF_VERSION );
|
||||||
|
|
||||||
|
echo "
|
||||||
|
<div class=\"notice notice-warning is-dismissible\" style=\"border-left-color:#f59e0b;padding:12px 15px\">
|
||||||
|
<div style=\"display:flex;align-items:center;gap:14px;flex-wrap:wrap\">
|
||||||
|
<span style=\"font-size:1.6rem\">🔔</span>
|
||||||
|
<div>
|
||||||
|
<strong style=\"font-size:.95rem\">WP Business Forum — Update verfügbar!</strong>
|
||||||
|
<p style=\"margin:.3rem 0 0;color:#374151\">
|
||||||
|
Version <strong>{$new_ver}</strong> ist verfügbar. Du verwendest <strong>{$cur_ver}</strong>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div style=\"display:flex;gap:8px;margin-left:auto\">
|
||||||
|
<a href=\"{$changelog_url}\" target=\"_blank\" rel=\"noopener\"
|
||||||
|
class=\"button button-primary\" style=\"background:#f59e0b;border-color:#d97706\">
|
||||||
|
📋 Changelog & Download
|
||||||
|
</a>
|
||||||
|
<a href=\"" . esc_url($dismiss_url) . "\" class=\"button\">Später erinnern</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>";
|
||||||
|
} );
|
||||||
|
|
||||||
|
// ── Update-Badge im WP-Admin-Menü ─────────────────────────────────────────────
|
||||||
|
add_action( 'admin_menu', function() {
|
||||||
|
$update = wbf_update_available();
|
||||||
|
if ( ! $update ) return;
|
||||||
|
global $menu;
|
||||||
|
if ( ! is_array($menu) ) return;
|
||||||
|
foreach ( $menu as &$item ) {
|
||||||
|
if ( isset($item[2]) && $item[2] === 'wbf-admin' ) {
|
||||||
|
$item[0] .= ' <span class="update-plugins"><span class="plugin-count">1</span></span>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 999 );
|
||||||
|
|
||||||
|
// ── Manuellen Cache-Reset erlauben (für die Admin-UI) ─────────────────────────
|
||||||
|
add_action( 'admin_init', function() {
|
||||||
|
if ( ! isset($_GET['wbf_refresh_update']) ) return;
|
||||||
|
if ( ! current_user_can('manage_options') ) return;
|
||||||
|
if ( ! check_admin_referer('wbf_refresh_update') ) return;
|
||||||
|
delete_transient( WBF_UPDATE_TRANSIENT );
|
||||||
|
wp_safe_redirect( remove_query_arg(['wbf_refresh_update','_wpnonce']) );
|
||||||
|
exit;
|
||||||
|
} );
|
||||||
Reference in New Issue
Block a user