register(); PaidContent::register(); Privacy::register(); add_action( 'clean_post_cache', [ Button::class, 'forget_post' ] ); if ( is_admin() ) { ( new Admin() )->register(); } add_filter( 'plugin_action_links_' . CRYPTOWAY_BUTTON_BASENAME, [ $this, 'add_action_links' ] ); } public function init(): void { Payment::register_post_type(); add_shortcode( 'cryptoway', [ $this, 'render_shortcode' ] ); add_shortcode( 'cryptoway_button', [ $this, 'render_shortcode' ] ); Block::register(); } /** * [cryptoway amount="50" currency="USD" pay="page" label="…" title="…" after="message" message="…" redirect="…" fields="name,email,message" coins="USDTTRC20,BTC" qr="yes" id="…" class="…"] * * @param array|string $atts */ public function render_shortcode( $atts, $content = '' ): string { $atts = is_array( $atts ) ? $atts : []; $content = is_string( $content ) ? $content : ''; // [cryptoway ...]paid content[/cryptoway]: the enclosed text is shown only after payment, and is // not even run (its shortcodes, its embeds) for anyone else: the payer gets it rendered from the post. if ( '' !== trim( $content ) ) { return Button::render( Button::shortcode_params( $atts, true ), 0, '', '', [ 'kind' => 'text', 'raw' => $content ] ); } return Button::render( Button::shortcode_params( $atts, false ) ); } /** Registered up front; the button enqueues them only on pages that show one. */ public function register_front_assets(): void { wp_register_style( 'cryptoway-button', CRYPTOWAY_BUTTON_URL . 'assets/css/front.css', [], self::asset_version( 'assets/css/front.css' ) ); wp_register_script( 'cryptoway-button-qr', CRYPTOWAY_BUTTON_URL . 'assets/js/qr.js', [], self::asset_version( 'assets/js/qr.js' ), true ); wp_register_script( 'cryptoway-button', CRYPTOWAY_BUTTON_URL . 'assets/js/front.js', [ 'cryptoway-button-qr' ], self::asset_version( 'assets/js/front.js' ), true ); } /** The plugin version, or the file's time while SCRIPT_DEBUG is on (a test site must not serve a stale copy). */ public static function asset_version( string $relative ): string { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { $mtime = filemtime( CRYPTOWAY_BUTTON_DIR . $relative ); if ( $mtime ) { return (string) $mtime; } } return CRYPTOWAY_BUTTON_VERSION; } public function add_action_links( array $links ): array { array_unshift( $links, '' . esc_html__( 'Settings', 'cryptoway-button' ) . '', '' . esc_html__( 'Payments', 'cryptoway-button' ) . '' ); return $links; } }