__( 'Permission denied.', '6arshid-social-community' ) ) ); } if ( empty( $_FILES['arshid6social_video_file'] ) ) { wp_send_json_error( array( 'message' => __( 'No file received.', '6arshid-social-community' ) ) ); } require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $attachment_id = media_handle_upload( 'arshid6social_video_file', 0 ); if ( is_wp_error( $attachment_id ) ) { wp_send_json_error( array( 'message' => $attachment_id->get_error_message() ) ); } $url = wp_get_attachment_url( $attachment_id ); wp_send_json_success( array( 'url' => $url ) ); } /** * Outputs the video-uploader JS in the footer. */ public function print_video_uploader_script(): void { // phpcs:ignore WordPress.Security.NonceVerification -- read-only page detection, no state change. if ( sanitize_key( wp_unslash( $_GET['page'] ?? '' ) ) !== 'arshid6social-settings' ) { return; } $bundled_video = plugins_url( 'assets/videos/home-bg.mp4', ARSHID6SOCIAL_PLUGIN_FILE ); $nonce = wp_create_nonce( 'arshid6social_upload_video' ); $ajax_url = admin_url( 'admin-ajax.php' ); $js_vid = 'jQuery(function($){'; $js_vid .= 'var bundled=' . wp_json_encode( $bundled_video ) . ';'; $js_vid .= 'var ajaxUrl=' . wp_json_encode( $ajax_url ) . ';'; $js_vid .= 'var nonce=' . wp_json_encode( $nonce ) . ';'; $js_vid .= 'var txtUploading=' . wp_json_encode( __( 'Uploading…', '6arshid-social-community' ) ) . ';'; $js_vid .= 'var txtUploadFailed=' . wp_json_encode( __( 'Upload failed.', '6arshid-social-community' ) ) . ';'; $js_vid .= 'var txtUploadError=' . wp_json_encode( __( 'Upload error. Please try again.', '6arshid-social-community' ) ) . ';'; $js_vid .= 'var txtChoose=' . wp_json_encode( __( 'Choose / Upload Video or Image', '6arshid-social-community' ) ) . ';'; $js_vid .= 'var txtDefaultVideo=' . wp_json_encode( __( 'Using default video.', '6arshid-social-community' ) ) . ';'; $js_vid .= 'var txtCustomActive=' . wp_json_encode( __( 'Custom background is active.', '6arshid-social-community' ) ) . ';'; $js_vid .= <<<'ENDJS' var $btn=$('#arshid6social-video-upload-btn'); var $rmBtn=$('#arshid6social-video-remove-btn'); var $fileInput=$('#arshid6social-video-file-input'); var $urlText=$('#arshid6social-video-url-text'); var $hidden=$('#arshid6social-video-url'); var $bgType=$('#arshid6social-bg-type'); var $previewImg=$('#arshid6social-video-preview'); var $previewVid=$('#arshid6social-video-preview-video'); var $desc=$('#arshid6social-video-desc'); var $progress=$('#arshid6social-video-progress'); if(!$btn.length)return; var pendingType=null; $btn.on('click',function(e){e.preventDefault();$fileInput.trigger('click');}); $fileInput.on('change',function(){ var file=this.files[0];if(!file)return; pendingType=file.type.startsWith('image/')?'image':'video'; var fd=new FormData();fd.append('action','arshid6social_upload_video');fd.append('nonce',nonce);fd.append('arshid6social_video_file',file,file.name); $btn.prop('disabled',true).text(txtUploading);$progress.show(); $.ajax({url:ajaxUrl,type:'POST',data:fd,processData:false,contentType:false, xhr:function(){var xhr=new window.XMLHttpRequest();xhr.upload.addEventListener('progress',function(ev){if(ev.lengthComputable){var pct=Math.round(ev.loaded/ev.total*100);$progress.find('.arshid6social-progress-bar').css('width',pct+'%');$progress.find('.arshid6social-progress-label').text(pct+'%');}},false);return xhr;}, success:function(res){if(res.success){setMedia(res.data.url,pendingType||'video');}else{alert(res.data.message||txtUploadFailed);}}, error:function(){alert(txtUploadError);}, complete:function(){$btn.prop('disabled',false).text(txtChoose);$progress.hide();$fileInput.val('');pendingType=null;} }); }); $rmBtn.on('click',function(e){e.preventDefault();$hidden.val('');$bgType.val('video');$urlText.val('');$previewImg.hide();$previewVid.attr('src',bundled).show()[0].load();$desc.text(txtDefaultVideo);$(this).hide();}); $urlText.on('input change',function(){var url=$(this).val().trim();if(url){var type=/\.(jpe?g|png|gif|webp|avif|svg)(\?.*)?$/i.test(url)?'image':'video';setMedia(url,type);}}); function setMedia(url,type){$hidden.val(url);$bgType.val(type);$urlText.val(url);if(type==='image'){$previewVid.hide();$previewImg.attr('src',url).show();}else{$previewImg.hide();$previewVid.attr('src',url).show()[0].load();}$desc.text(txtCustomActive);$rmBtn.show();} }); ENDJS; wp_add_inline_script( 'arshid6social-admin', $js_vid ); } /** @return array Tab key → label. */ private function tabs(): array { return apply_filters( 'arshid6social_settings_tabs', array( 'general' => __( 'General', '6arshid-social-community' ), 'components' => __( 'Components', '6arshid-social-community' ), 'members' => __( 'Members', '6arshid-social-community' ), 'activity' => __( 'Activity', '6arshid-social-community' ), 'groups' => __( 'Groups', '6arshid-social-community' ), 'messages' => __( 'Messages', '6arshid-social-community' ), 'notifications' => __( 'Notifications', '6arshid-social-community' ), 'security' => __( 'Security', '6arshid-social-community' ), 'emails' => __( 'Emails', '6arshid-social-community' ), 'appearance' => __( 'Appearance', '6arshid-social-community' ), 'search' => __( 'Search', '6arshid-social-community' ), 'tools' => __( 'Tools', '6arshid-social-community' ), 'permalinks' => __( 'Permalinks', '6arshid-social-community' ), ) ); } /** * Registers all plugin options with the WP Settings API. * * Every option gets its own type and sanitize_callback matched to the * data it stores (bool, int, enum, slug, textarea, URL, array, …). */ public function register(): void { foreach ( $this->option_schemas() as $group => $options ) { foreach ( $options as $option_name => $schema ) { register_setting( $group, $option_name, $schema ); } } } /** * Returns option-specific registration schemas, grouped by settings group. * * @return array> */ private function option_schemas(): array { $bool = array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', ); $int = array( 'type' => 'integer', 'sanitize_callback' => 'absint', ); $text = array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ); $textarea = array( 'type' => 'string', 'sanitize_callback' => 'sanitize_textarea_field', ); $url = array( 'type' => 'string', 'sanitize_callback' => 'esc_url_raw', ); $pagination_default_scroll = $this->enum_schema( array( 'infinite_scroll', 'pagination' ), 'infinite_scroll' ); $pagination_default_pages = $this->enum_schema( array( 'infinite_scroll', 'pagination' ), 'pagination' ); return array( 'arshid6social_general' => array( 'arshid6social_date_format' => $this->enum_schema( array( 'relative', 'absolute', 'jalali' ), 'relative' ), 'arshid6social_invitation_limit' => $int, ), 'arshid6social_components' => array( 'arshid6social_enabled_components' => $this->choices_schema( array( 'activity', 'groups', 'friends', 'messages', 'notifications', 'moderation' ) ), 'arshid6social_stories_enabled' => $bool, 'arshid6social_verification_enabled' => $bool, 'arshid6social_blocking_enabled' => $bool, 'arshid6social_activity_stats_bar' => $bool, ), 'arshid6social_members' => array( 'arshid6social_members_per_page' => $int, 'arshid6social_members_pagination_type' => $pagination_default_pages, 'arshid6social_who_to_follow_per_page' => $int, 'arshid6social_members_show_friend_count' => $bool, 'arshid6social_profile_photo_size' => $int, 'arshid6social_cover_photo_width' => $int, 'arshid6social_cover_photo_height' => $int, 'arshid6social_max_upload_size_mb' => $int, 'arshid6social_allowed_upload_types' => $this->choices_schema( array( 'image/jpeg', 'image/png', 'image/gif', 'image/webp' ), false ), 'arshid6social_verification_enabled' => $bool, 'arshid6social_verification_types' => $this->verification_types_schema(), 'arshid6social_verification_badge_image' => $int, 'arshid6social_verification_require_doc' => $bool, 'arshid6social_verification_expiry_months' => $int, 'arshid6social_verification_doc_purge' => $bool, 'arshid6social_verification_rate_limit' => $int, ), 'arshid6social_activity' => array( 'arshid6social_activity_per_page' => $int, 'arshid6social_activity_allow_comments' => $bool, 'arshid6social_activity_allow_media' => $bool, 'arshid6social_activity_allowed_media_types' => $this->choices_schema( array( 'image', 'video', 'audio', 'document' ) ), 'arshid6social_activity_pagination_type' => $pagination_default_scroll, 'arshid6social_stories_enabled' => $bool, 'arshid6social_stories_expiry_hours' => $int, 'arshid6social_stories_max_video_secs' => $int, 'arshid6social_stories_allow_video' => $bool, 'arshid6social_stories_highlights' => $bool, 'arshid6social_stories_rate_limit' => $int, 'arshid6social_stories_bottom_bar' => $bool, 'arshid6social_stories_bottom_bar_marketplace' => $bool, 'arshid6social_stories_bottom_bar_messages' => $bool, ), 'arshid6social_groups' => array( 'arshid6social_groups_per_page' => $int ), 'arshid6social_messages' => array( 'arshid6social_messages_per_page' => $int, 'arshid6social_messages_story_enabled' => $bool, ), 'arshid6social_notifications' => array( 'arshid6social_email_notifications' => $bool, 'arshid6social_email_digest' => $this->enum_schema( array( 'none', 'daily', 'weekly' ), 'daily' ), ), 'arshid6social_security' => array( 'arshid6social_enable_akismet' => $bool, 'arshid6social_enable_recaptcha' => $bool, 'arshid6social_recaptcha_site_key' => $text, 'arshid6social_recaptcha_secret_key' => $text, 'arshid6social_new_member_moderation' => $bool, 'arshid6social_auto_suspend_threshold' => $int, 'arshid6social_banned_words' => $textarea, 'arshid6social_rate_limit_posts' => $int, 'arshid6social_rate_limit_messages' => $int, 'arshid6social_rate_limit_friends' => $int, 'arshid6social_blocking_enabled' => $bool, 'arshid6social_blocking_show_reason' => $bool, 'arshid6social_report_reasons' => $textarea, 'arshid6social_suspend_reasons' => $textarea, 'arshid6social_report_allow_attachments' => $bool, 'arshid6social_reserved_usernames' => $textarea, 'arshid6social_username_min_length' => array( 'type' => 'integer', 'sanitize_callback' => static function ( $value ): int { return max( 1, min( 60, absint( $value ) ) ); }, ), ), 'arshid6social_appearance' => array( 'arshid6social_primary_color' => array( 'type' => 'string', 'sanitize_callback' => static function ( $value ): string { return sanitize_hex_color( (string) $value ) ?: '#2563eb'; }, ), 'arshid6social_dark_mode' => $this->enum_schema( array( 'off', 'auto', 'on' ), 'off' ), 'arshid6social_home_video_url' => $url, 'arshid6social_home_bg_type' => $this->enum_schema( array( 'video', 'image' ), 'video' ), 'arshid6social_logo_mobile' => $int, ), 'arshid6social_permalinks' => array( 'arshid6social_permalink_tag_base' => $this->slug_schema( 'hashtags' ), 'arshid6social_permalink_activity_base' => $this->slug_schema( 'activity' ), 'arshid6social_activity_uid_enabled' => $bool, 'arshid6social_marketplace_slug' => $this->slug_schema( 'marketplace' ), ), 'arshid6social_search' => array( 'arshid6social_search_pagination_type' => $pagination_default_pages, 'arshid6social_search_results_per_section' => $int, 'arshid6social_search_per_page' => $int, ), ); } /** * Schema for a string option restricted to a fixed set of values. * * @param string[] $allowed Allowed values. * @param string $default Fallback when the submitted value is not allowed. */ private function enum_schema( array $allowed, string $default ): array { return array( 'type' => 'string', 'sanitize_callback' => static function ( $value ) use ( $allowed, $default ): string { return in_array( $value, $allowed, true ) ? $value : $default; }, ); } /** * Schema for an array option whose items must belong to a whitelist. * * @param string[] $allowed Allowed item values. * @param bool $sanitize_keys Whether to run items through sanitize_key() first. */ private function choices_schema( array $allowed, bool $sanitize_keys = true ): array { return array( 'type' => 'array', 'sanitize_callback' => static function ( $value ) use ( $allowed, $sanitize_keys ): array { if ( ! is_array( $value ) ) { return array(); } $value = array_map( $sanitize_keys ? 'sanitize_key' : 'sanitize_text_field', array_map( 'strval', $value ) ); return array_values( array_intersect( $value, $allowed ) ); }, ); } /** * Schema for a URL/permalink slug option with a fallback default. * * @param string $default Default slug when the submitted value sanitizes to ''. */ private function slug_schema( string $default ): array { return array( 'type' => 'string', 'sanitize_callback' => static function ( $value ) use ( $default ): string { return sanitize_title( (string) $value ) ?: $default; }, ); } /** * Schema for the verification types array (list of key/label/badge/color rows). */ private function verification_types_schema(): array { return array( 'type' => 'array', 'sanitize_callback' => static function ( $value ): array { if ( ! is_array( $value ) ) { return array(); } $clean = array(); foreach ( $value as $item ) { if ( ! is_array( $item ) || empty( $item['key'] ) ) { continue; } $clean[] = array( 'key' => sanitize_key( $item['key'] ), 'label' => sanitize_text_field( (string) ( $item['label'] ?? '' ) ), 'badge' => sanitize_text_field( (string) ( $item['badge'] ?? '' ) ), 'color' => sanitize_hex_color( (string) ( $item['color'] ?? '' ) ) ?: '#2563eb', ); } return $clean; }, ); } /** * Renders the full settings page. */ public function render(): void { if ( ! current_user_can( 'arshid6social_manage_settings' ) ) { wp_die( esc_html__( 'Permission denied.', '6arshid-social-community' ) ); } $current_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'general'; // phpcs:ignore WordPress.Security.NonceVerification $tabs = $this->tabs(); if ( ! array_key_exists( $current_tab, $tabs ) ) { $current_tab = 'general'; } $option_group = 'arshid6social_' . $current_tab; ?>

render_tools_tab(); ?>
render_tab( $current_tab ); submit_button( __( 'Save Settings', '6arshid-social-community' ) ); ?>
render_general_tab(); break; case 'components': $this->render_components_tab(); break; case 'members': $this->render_members_tab(); break; case 'activity': $this->render_activity_tab(); break; case 'groups': $this->render_groups_tab(); break; case 'messages': $this->render_messages_tab(); break; case 'notifications': $this->render_notifications_tab(); break; case 'security': $this->render_security_tab(); break; case 'emails': $this->render_emails_tab(); break; case 'appearance': $this->render_appearance_tab(); break; case 'permalinks': $this->render_permalinks_tab(); break; case 'search': $this->render_search_tab(); break; default: do_action( 'arshid6social_settings_tab_' . $tab ); } } private function render_search_tab(): void { ?>

array( 'label' => __( 'Activity Streams', '6arshid-social-community' ), 'desc' => __( 'News feed, posts, reactions, comments', '6arshid-social-community' ), ), 'groups' => array( 'label' => __( 'Groups', '6arshid-social-community' ), 'desc' => __( 'Public, private, and hidden groups', '6arshid-social-community' ), ), 'friends' => array( 'label' => __( 'Friends & Follow', '6arshid-social-community' ), 'desc' => __( 'Friend requests, follow, block', '6arshid-social-community' ), ), 'messages' => array( 'label' => __( 'Private Messages', '6arshid-social-community' ), 'desc' => __( 'One-to-one and group messaging', '6arshid-social-community' ), ), 'notifications' => array( 'label' => __( 'Notifications', '6arshid-social-community' ), 'desc' => __( 'On-site and email notifications', '6arshid-social-community' ), ), 'moderation' => array( 'label' => __( 'Moderation', '6arshid-social-community' ), 'desc' => __( 'Reports, bans, audit log', '6arshid-social-community' ), ), ); // Engagement Pack options (stored in their own flags, not arshid6social_enabled_components). $pack = array( 'arshid6social_stories_enabled' => array( 'label' => __( 'Stories', '6arshid-social-community' ), 'desc' => __( '24-hour ephemeral photo, video, and text stories', '6arshid-social-community' ), ), 'arshid6social_verification_enabled' => array( 'label' => __( 'Verification Badges', '6arshid-social-community' ), 'desc' => __( 'Verified badge + user request flow and admin queue', '6arshid-social-community' ), ), 'arshid6social_blocking_enabled' => array( 'label' => __( 'Block System', '6arshid-social-community' ), 'desc' => __( 'Block / unblock users with optional reason', '6arshid-social-community' ), ), 'arshid6social_activity_stats_bar' => array( 'label' => __( 'Activity Stats Bar', '6arshid-social-community' ), 'desc' => __( 'Show engagement counts (comments, reposts, likes, views) below each post', '6arshid-social-community' ), ), ); ?> render_verification_settings(); } private function render_verification_settings(): void { $types = (array) get_option( 'arshid6social_verification_types', array() ); $badge_img_id = (int) get_option( 'arshid6social_verification_badge_image', 0 ); $badge_img_url = $badge_img_id ? wp_get_attachment_image_url( $badge_img_id, array( 32, 32 ) ) : ''; ?>

render_stories_settings(); } private function render_groups_tab(): void { ?>

render_stories_bar_preview(); ?> component( 'stories' ); if ( $stories_obj instanceof \Arshid6Social\Components\Stories\Stories ) { $tray = $stories_obj->get_tray( $viewer_id ); } ?>

+
$color ) : ?>
user_id; $has_unseen = (int) $story->unseen_count > 0; $ring_color = $has_unseen ? 'linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888)' : '#555'; ?>
display_name ); ?>
render_username_restrictions(); $this->render_blocking_settings(); $this->render_reporting_settings(); } private function render_username_restrictions(): void { ?>