135 lines
3.9 KiB
PHP
135 lines
3.9 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* Plugin Name: Sirius Press Core
|
||
|
|
* Plugin URI: https://code.silentmode.st/silentmode/sirius-press
|
||
|
|
* Description: Wallet identity, gateway publishing and the in-app inbox that the rest of Sirius Press is built on.
|
||
|
|
* Version: 0.1.0
|
||
|
|
* Requires at least: 6.5
|
||
|
|
* Requires PHP: 7.4
|
||
|
|
* Author: Silent Mode
|
||
|
|
* Author URI: https://silentmode.st
|
||
|
|
* License: GPL-2.0-or-later
|
||
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||
|
|
* Text Domain: sirius-press
|
||
|
|
*
|
||
|
|
* @package SiriusPress
|
||
|
|
*/
|
||
|
|
|
||
|
|
defined( 'ABSPATH' ) || exit;
|
||
|
|
|
||
|
|
define( 'SIRIUS_PRESS_VERSION', '0.1.0' );
|
||
|
|
define( 'SIRIUS_PRESS_CORE_FILE', __FILE__ );
|
||
|
|
define( 'SIRIUS_PRESS_CORE_DIR', plugin_dir_path( __FILE__ ) );
|
||
|
|
define( 'SIRIUS_PRESS_CORE_URL', plugin_dir_url( __FILE__ ) );
|
||
|
|
|
||
|
|
foreach (
|
||
|
|
array(
|
||
|
|
'class-sp-bn',
|
||
|
|
'class-sp-secp256k1',
|
||
|
|
'class-sp-cashaddr',
|
||
|
|
'class-sp-hd',
|
||
|
|
'class-sp-message',
|
||
|
|
'class-sp-settings',
|
||
|
|
'class-sp-gateway',
|
||
|
|
'class-sp-identity',
|
||
|
|
'class-sp-inbox',
|
||
|
|
'class-sp-admin',
|
||
|
|
) as $sp_class
|
||
|
|
) {
|
||
|
|
require_once SIRIUS_PRESS_CORE_DIR . 'includes/' . $sp_class . '.php';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The function this whole fork turns on.
|
||
|
|
*
|
||
|
|
* Core calls `is_email()` in a dozen places to decide whether a string is a
|
||
|
|
* usable identity. Sirius Press answers the same question about a different
|
||
|
|
* kind of string, and the core patches in `patches/` swap the call rather
|
||
|
|
* than changing what `is_email()` itself means — plugins still need the real
|
||
|
|
* `is_email()` for contact forms and newsletters.
|
||
|
|
*
|
||
|
|
* @param string $value
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
function is_cashaddr( $value ) {
|
||
|
|
return SP_CashAddr::is_valid( $value );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The address that identifies a user, or '' — the `user_email` of this fork.
|
||
|
|
*
|
||
|
|
* @param int|WP_User|null $user Defaults to the current user.
|
||
|
|
*/
|
||
|
|
function sirius_press_address( $user = null ) {
|
||
|
|
if ( null === $user ) {
|
||
|
|
$user = get_current_user_id();
|
||
|
|
}
|
||
|
|
$id = $user instanceof WP_User ? $user->ID : (int) $user;
|
||
|
|
return $id ? SP_Identity::address_of( $id ) : '';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Whether this installation can do wallet cryptography at all.
|
||
|
|
*
|
||
|
|
* Checked on activation and shown as an admin notice rather than left to
|
||
|
|
* surface as a fatal during someone's first login attempt.
|
||
|
|
*
|
||
|
|
* @return string '' when fine, otherwise what is missing.
|
||
|
|
*/
|
||
|
|
function sirius_press_requirements_problem() {
|
||
|
|
if ( ! SP_BN::available() ) {
|
||
|
|
return __( 'Sirius Press needs either the GMP or the BCMath PHP extension to verify wallet signatures. Ask your host to enable one — GMP is much faster.', 'sirius-press' );
|
||
|
|
}
|
||
|
|
if ( PHP_INT_SIZE < 8 ) {
|
||
|
|
return __( 'Sirius Press needs 64-bit PHP. Address checksums cannot be computed on a 32-bit build.', 'sirius-press' );
|
||
|
|
}
|
||
|
|
if ( ! function_exists( 'openssl_encrypt' ) ) {
|
||
|
|
return __( 'Sirius Press needs the OpenSSL PHP extension to store a publishing key safely.', 'sirius-press' );
|
||
|
|
}
|
||
|
|
return '';
|
||
|
|
}
|
||
|
|
|
||
|
|
register_activation_hook(
|
||
|
|
__FILE__,
|
||
|
|
function () {
|
||
|
|
SP_Inbox::install();
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
add_action(
|
||
|
|
'plugins_loaded',
|
||
|
|
function () {
|
||
|
|
load_plugin_textdomain( 'sirius-press', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
||
|
|
|
||
|
|
if ( (int) get_option( 'sirius_press_inbox_version', 0 ) < SP_Inbox::VERSION ) {
|
||
|
|
SP_Inbox::install();
|
||
|
|
}
|
||
|
|
|
||
|
|
SP_Identity::hooks();
|
||
|
|
SP_Inbox::hooks();
|
||
|
|
SP_Admin::hooks();
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
add_action(
|
||
|
|
'admin_notices',
|
||
|
|
function () {
|
||
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
$problem = sirius_press_requirements_problem();
|
||
|
|
if ( '' !== $problem ) {
|
||
|
|
printf( '<div class="notice notice-error"><p>%s</p></div>', esc_html( $problem ) );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if ( ! SP_Settings::is_configured() ) {
|
||
|
|
printf(
|
||
|
|
'<div class="notice notice-warning"><p>%s <a href="%s">%s</a></p></div>',
|
||
|
|
esc_html__( 'Sirius Press does not know which BCNR name this site publishes under yet.', 'sirius-press' ),
|
||
|
|
esc_url( admin_url( 'admin.php?page=sirius-press' ) ),
|
||
|
|
esc_html__( 'Set it now', 'sirius-press' )
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
);
|