| 1 |
<?php |
| 2 |
// Create a section. |
| 3 |
CSF::createSection( |
| 4 |
$prefix, |
| 5 |
[ |
| 6 |
'title' => __( 'Topic Replies', 'forumax' ), |
| 7 |
'icon' => 'dashicons dashicons-format-chat', |
| 8 |
'fields' => [ |
| 9 |
[ |
| 10 |
'id' => 'is_ajax_reply', |
| 11 |
'type' => 'switcher', |
| 12 |
'default' => false, |
| 13 |
'title' => __( 'AJAX Reply', 'forumax' ), |
| 14 |
'subtitle' => __( 'Enable instant reply submission without page reload. Replies appear in real-time via AJAX.', 'forumax' ), |
| 15 |
'class' => 'st-promax-notice' |
| 16 |
], |
| 17 |
[ |
| 18 |
'id' => 'replies_per_page', |
| 19 |
'type' => 'number', |
| 20 |
'title' => __( 'Replies Per Page', 'forumax' ), |
| 21 |
'subtitle' => __( 'Set how many replies are shown per topic page. Pagination links appear after this limit is exceeded.', 'forumax' ), |
| 22 |
'desc' => __( 'This setting reuses bbPress reply pagination option. Example: 15 means pagination starts from 16 replies.', 'forumax' ), |
| 23 |
'default' => (int) get_option( '_bbp_replies_per_page', 15 ), |
| 24 |
'min' => 1, |
| 25 |
'max' => 100, |
| 26 |
], |
| 27 |
[ |
| 28 |
'id' => 'is_bbpc_insert_media', |
| 29 |
'type' => 'switcher', |
| 30 |
'default' => false, |
| 31 |
'title' => __( 'Insert Media', 'forumax' ), |
| 32 |
'subtitle' => __( 'Enable/Disable the custom image insert button with upload & URL modal for editors.', 'forumax' ), |
| 33 |
'class' => 'st-pro-notice' |
| 34 |
], |
| 35 |
[ |
| 36 |
'id' => 'is_auto_approval_replies', |
| 37 |
'type' => 'switcher', |
| 38 |
'default' => false, |
| 39 |
'title' => __( 'Auto Approval', 'forumax' ), |
| 40 |
'subtitle' => __( 'Enable/ Disable Auto Approval feature.', 'forumax' ), |
| 41 |
'class' => 'st-pro-notice' |
| 42 |
], |
| 43 |
[ |
| 44 |
'id' => 'is_attachment_replies', |
| 45 |
'type' => 'button_set', |
| 46 |
'title' => __( 'Replies with Attachments', 'forumax' ), |
| 47 |
'subtitle' => __( 'Approve or Unapprove if attachment is added with the reply', 'forumax' ), |
| 48 |
'class' => 'st-pro-notice', |
| 49 |
'options' => array( |
| 50 |
'1' => 'Approve', |
| 51 |
'0' => 'Unapprove', |
| 52 |
), |
| 53 |
'default' => '1', |
| 54 |
'dependency' => [ 'is_auto_approval_replies', '==', 'true', ], |
| 55 |
], |
| 56 |
[ |
| 57 |
'id' => 'is_private_replies', |
| 58 |
'type' => 'switcher', |
| 59 |
'default' => 1, |
| 60 |
'title' => __( 'Private Replies', 'forumax' ), |
| 61 |
'subtitle' => __( 'Enable/ Disable Private Replies feature.', 'forumax' ), |
| 62 |
], |
| 63 |
[ |
| 64 |
'id' => 'anonymous_reply', |
| 65 |
'type' => 'switcher', |
| 66 |
'title' => __( 'Anonymous Reply', 'forumax' ), |
| 67 |
'subtitle' => __( 'Allow anonymous to reply a topic.', 'forumax' ), |
| 68 |
'class' => 'st-pro-notice' |
| 69 |
], |
| 70 |
[ |
| 71 |
'id' => 'anonymous_reply_label', |
| 72 |
'type' => 'text', |
| 73 |
'title' => __( 'Anonymous Label', 'forumax' ), |
| 74 |
'default' => __( 'Post Anonymously', 'forumax' ), |
| 75 |
'dependency' => [ 'anonymous_reply', '==', 'true', ], |
| 76 |
'class' => 'st-pro-notice' |
| 77 |
], |
| 78 |
[ |
| 79 |
'id' => 'replies_react_voting', |
| 80 |
'type' => 'switcher', |
| 81 |
'title' => __( 'React Reactions', 'forumax' ), |
| 82 |
'subtitle' => __( 'To enable or disable the react reactions.', 'forumax' ), |
| 83 |
'class' => 'st-promax-notice', |
| 84 |
'default' => false |
| 85 |
], |
| 86 |
[ |
| 87 |
'id' => 'replies_react_label', |
| 88 |
'type' => 'text', |
| 89 |
'title' => __( 'React Button Text', 'forumax' ), |
| 90 |
'default' => __( 'React', 'forumax' ), |
| 91 |
'class' => 'st-promax-notice', |
| 92 |
'dependency' => [ 'replies_react_voting', '==', 'true', ] |
| 93 |
], |
| 94 |
[ |
| 95 |
'id' => 'reply_timeline_enabled', |
| 96 |
'type' => 'switcher', |
| 97 |
'title' => __( 'Reply Timeline Navigation', 'forumax' ), |
| 98 |
'subtitle' => __( 'Enable/Disable Discourse-style vertical timeline navigation for replies.', 'forumax' ), |
| 99 |
'class' => 'st-promax-notice', |
| 100 |
'default' => false |
| 101 |
], |
| 102 |
[ |
| 103 |
'id' => 'frmx_nested_replies', |
| 104 |
'type' => 'switcher', |
| 105 |
'title' => __( 'Nested Replies', 'forumax' ), |
| 106 |
'subtitle' => __( 'Enable threaded / nested replies so users can reply directly to a specific reply.', 'forumax' ), |
| 107 |
'class' => 'st-promax-notice', |
| 108 |
'default' => false, |
| 109 |
], |
| 110 |
[ |
| 111 |
'id' => 'frmx_nested_replies_depth', |
| 112 |
'type' => 'select', |
| 113 |
'title' => __( 'Nesting Depth', 'forumax' ), |
| 114 |
'subtitle' => __( 'Maximum depth of nested replies.', 'forumax' ), |
| 115 |
'class' => 'st-promax-notice', |
| 116 |
'default' => '3', |
| 117 |
'options' => array( |
| 118 |
'2' => __( '2 levels', 'forumax' ), |
| 119 |
'3' => __( '3 levels', 'forumax' ), |
| 120 |
'4' => __( '4 levels', 'forumax' ), |
| 121 |
'5' => __( '5 levels', 'forumax' ), |
| 122 |
), |
| 123 |
'dependency' => array( 'frmx_nested_replies', '==', 'true' ), |
| 124 |
], |
| 125 |
] |
| 126 |
] |
| 127 |
); |
| 128 |
|
| 129 |
if ( ! function_exists( 'forumax_sync_bbp_replies_per_page_option' ) ) { |
| 130 |
/** |
| 131 |
* Sync Forumax replies-per-page setting to bbPress core option. |
| 132 |
* |
| 133 |
* @param array $data Saved Forumax settings. |
| 134 |
* @return void |
| 135 |
*/ |
| 136 |
function forumax_sync_bbp_replies_per_page_option( $data, $options = null ) { |
| 137 |
if ( ! is_array( $data ) || ! isset( $data['replies_per_page'] ) ) { |
| 138 |
return; |
| 139 |
} |
| 140 |
|
| 141 |
$replies_per_page = absint( $data['replies_per_page'] ); |
| 142 |
|
| 143 |
if ( $replies_per_page < 1 ) { |
| 144 |
$replies_per_page = 15; |
| 145 |
} |
| 146 |
|
| 147 |
update_option( '_bbp_replies_per_page', $replies_per_page ); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
add_action( 'csf_bbp_core_settings_save_after', 'forumax_sync_bbp_replies_per_page_option', 10, 2 ); |
| 152 |
|
| 153 |
if ( ! function_exists( 'forumax_sync_replies_per_page_field_from_bbp' ) ) { |
| 154 |
/** |
| 155 |
* Keep Forumax field value aligned with bbPress replies-per-page option. |
| 156 |
* |
| 157 |
* @return void |
| 158 |
*/ |
| 159 |
function forumax_sync_replies_per_page_field_from_bbp() { |
| 160 |
$bbp_replies_per_page = absint( get_option( '_bbp_replies_per_page', 15 ) ); |
| 161 |
|
| 162 |
if ( $bbp_replies_per_page < 1 ) { |
| 163 |
$bbp_replies_per_page = 15; |
| 164 |
} |
| 165 |
|
| 166 |
$forumax_settings = get_option( 'bbp_core_settings', array() ); |
| 167 |
|
| 168 |
if ( ! is_array( $forumax_settings ) ) { |
| 169 |
$forumax_settings = array(); |
| 170 |
} |
| 171 |
|
| 172 |
$current_value = isset( $forumax_settings['replies_per_page'] ) |
| 173 |
? absint( $forumax_settings['replies_per_page'] ) |
| 174 |
: 0; |
| 175 |
|
| 176 |
if ( $current_value === $bbp_replies_per_page ) { |
| 177 |
return; |
| 178 |
} |
| 179 |
|
| 180 |
$forumax_settings['replies_per_page'] = $bbp_replies_per_page; |
| 181 |
update_option( 'bbp_core_settings', $forumax_settings ); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
add_action( 'admin_init', 'forumax_sync_replies_per_page_field_from_bbp', 20 ); |