'boolean',
'single' => true,
'default' => false,
'show_in_rest' => true,
'sanitize_callback' => 'rest_sanitize_boolean',
'auth_callback' => function ( $allowed, $meta_key, $post_id ) {
return current_user_can( 'edit_post', $post_id );
},
)
);
register_block_type( CLVRLY_DIR . 'blocks/assistant' );
add_shortcode( 'clvrly', array( __CLASS__, 'shortcode' ) );
}
/**
* The element concierge.js renders into. Printed at most once per page.
*
* @param string $wrapper_attributes Attributes for the wrapping element.
* @return string
*/
public static function host_html( $wrapper_attributes = '' ) {
if ( self::$host_printed || ! Clvrly_Frontend::should_load() ) {
return '';
}
self::$host_printed = true;
return sprintf(
'
',
$wrapper_attributes ? $wrapper_attributes : 'class="clvrly-inline"'
);
}
/**
* [clvrly] shortcode: show the assistant inside the content.
*
* @return string
*/
public static function shortcode() {
return self::host_html();
}
/**
* Block editor sidebar panel ("Clvrly assistant" → Hide on this page).
*/
public static function enqueue_panel() {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || 'post' !== $screen->base ) {
return; // Post and page editors only, not the Site Editor or widgets screen.
}
wp_enqueue_script(
'clvrly-editor',
CLVRLY_URL . 'assets/editor.js',
// The panel slot lives in wp-editor from WordPress 6.6 and in wp-edit-post before that.
array( 'wp-plugins', 'wp-element', 'wp-components', 'wp-data', 'wp-i18n', 'wp-editor', 'wp-edit-post' ),
CLVRLY_VERSION,
true
);
wp_set_script_translations( 'clvrly-editor', 'clvrly' );
wp_localize_script(
'clvrly-editor',
'clvrlyEditor',
array(
'metaKey' => Clvrly_Settings::HIDE_META,
'connected' => Clvrly_Settings::has_token(),
'enabled' => Clvrly_Settings::is_enabled(),
'settingsUrl' => current_user_can( 'manage_options' ) ? admin_url( 'options-general.php?page=clvrly' ) : '',
)
);
}
/**
* Classic editor fallback for the visibility toggle. Hidden in the block editor,
* which uses the sidebar panel instead.
*/
public static function add_meta_box() {
$types = get_post_types( array( 'public' => true ) );
unset( $types['attachment'] );
add_meta_box(
'clvrly-visibility',
__( 'Clvrly assistant', 'clvrly' ),
array( __CLASS__, 'render_meta_box' ),
array_values( $types ),
'side',
'low',
array( '__back_compat_meta_box' => true )
);
}
/**
* Render the classic editor meta box.
*
* @param WP_Post $post Current post.
*/
public static function render_meta_box( $post ) {
wp_nonce_field( 'clvrly_meta_box', 'clvrly_meta_box_nonce' );
?>