Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191

This commit is contained in:
southseact-3d
2026-02-07 20:32:41 +00:00
commit ed67b7741b
252 changed files with 99814 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
<?php
/**
* FAQ Manager Helper Class
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
class PC_FAQ_Manager_Helper {
/**
* Get all FAQs ordered by order meta
*/
public static function get_faqs($posts_per_page = -1) {
$args = array(
'post_type' => 'pc_faq',
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'orderby' => 'meta_value_num',
'meta_key' => '_pc_faq_order',
'order' => 'ASC',
);
return get_posts($args);
}
/**
* Get FAQ count
*/
public static function get_faq_count() {
$args = array(
'post_type' => 'pc_faq',
'post_status' => 'publish',
'posts_per_page' => 1,
);
$query = new WP_Query($args);
return $query->found_posts;
}
/**
* Reorder FAQs
*/
public static function reorder_faqs($faq_ids) {
if (!is_array($faq_ids) || empty($faq_ids)) {
return false;
}
foreach ($faq_ids as $order => $faq_id) {
$faq_id = intval($faq_id);
$order = intval($order);
if ($faq_id > 0) {
update_post_meta($faq_id, '_pc_faq_order', $order);
}
}
return true;
}
/**
* Get max order value
*/
public static function get_max_order() {
global $wpdb;
$max_order = $wpdb->get_var($wpdb->prepare(
"SELECT MAX(CAST(meta_value AS SIGNED))
FROM {$wpdb->postmeta}
WHERE meta_key = %s",
'_pc_faq_order'
));
return $max_order ? intval($max_order) : 0;
}
/**
* Sanitize and validate FAQ data
*/
public static function sanitize_faq_data($data) {
$sanitized = array();
if (isset($data['title'])) {
$sanitized['title'] = sanitize_text_field($data['title']);
}
if (isset($data['content'])) {
$sanitized['content'] = wp_kses_post($data['content']);
}
if (isset($data['order'])) {
$sanitized['order'] = intval($data['order']);
}
return $sanitized;
}
/**
* Check user capabilities
*/
public static function can_manage_faqs() {
return current_user_can('manage_options') || current_user_can('edit_posts');
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* FAQ Post Type Handler
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
class PC_FAQ_Manager_Post_Type {
/**
* Constructor
*/
public function __construct() {
add_action('init', array($this, 'register_post_type'));
add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
add_action('save_post_pc_faq', array($this, 'save_faq_meta'));
add_action('manage_pc_faq_posts_custom_column', array($this, 'custom_columns'), 10, 2);
add_filter('manage_pc_faq_posts_columns', array($this, 'set_custom_columns'));
}
/**
* Register FAQ post type
*/
public function register_post_type() {
$labels = array(
'name' => __('FAQs', PC_FAQ_MANAGER_SLUG),
'singular_name' => __('FAQ', PC_FAQ_MANAGER_SLUG),
'menu_name' => __('FAQ Manager', PC_FAQ_MANAGER_SLUG),
'add_new' => __('Add New FAQ', PC_FAQ_MANAGER_SLUG),
'add_new_item' => __('Add New FAQ', PC_FAQ_MANAGER_SLUG),
'edit_item' => __('Edit FAQ', PC_FAQ_MANAGER_SLUG),
'new_item' => __('New FAQ', PC_FAQ_MANAGER_SLUG),
'view_item' => __('View FAQ', PC_FAQ_MANAGER_SLUG),
'search_items' => __('Search FAQs', PC_FAQ_MANAGER_SLUG),
'not_found' => __('No FAQs found', PC_FAQ_MANAGER_SLUG),
'not_found_in_trash' => __('No FAQs found in Trash', PC_FAQ_MANAGER_SLUG),
'all_items' => __('All FAQs', PC_FAQ_MANAGER_SLUG),
);
$args = array(
'labels' => $labels,
'public' => false,
'has_archive' => false,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => false,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 25,
'menu_icon' => 'dashicons-editor-help',
'supports' => array('title', 'editor'),
'show_in_rest' => false,
'show_ui' => true,
'show_in_menu' => false,
'exclude_from_search' => true,
);
register_post_type('pc_faq', $args);
}
/**
* Add meta boxes
*/
public function add_meta_boxes() {
add_meta_box(
'pc_faq_order_meta',
__('FAQ Order', PC_FAQ_MANAGER_SLUG),
array($this, 'order_meta_box'),
'pc_faq',
'side',
'default'
);
}
/**
* Order meta box callback
*/
public function order_meta_box($post) {
wp_nonce_field('pc_faq_save_meta', 'pc_faq_nonce');
$order = get_post_meta($post->ID, '_pc_faq_order', true) ?: 0;
echo '<label for="pc_faq_order">' . __('Display Order:', PC_FAQ_MANAGER_SLUG) . '</label>';
echo '<input type="number" id="pc_faq_order" name="pc_faq_order" value="' . esc_attr($order) . '" min="0" style="width: 100%; margin-top: 5px;" />';
echo '<p class="description">' . __('Lower numbers appear first. Leave at 0 for automatic ordering.', PC_FAQ_MANAGER_SLUG) . '</p>';
}
/**
* Save FAQ meta
*/
public function save_faq_meta($post_id) {
if (!isset($_POST['pc_faq_nonce']) || !wp_verify_nonce($_POST['pc_faq_nonce'], 'pc_faq_save_meta')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if (isset($_POST['pc_faq_order'])) {
$order = sanitize_text_field($_POST['pc_faq_order']);
update_post_meta($post_id, '_pc_faq_order', $order);
}
}
/**
* Set custom columns
*/
public function set_custom_columns($columns) {
$new_columns = array();
$new_columns['cb'] = $columns['cb'];
$new_columns['title'] = $columns['title'];
$new_columns['order'] = __('Order', PC_FAQ_MANAGER_SLUG);
$new_columns['date'] = $columns['date'];
return $new_columns;
}
/**
* Display custom columns
*/
public function custom_columns($column, $post_id) {
switch ($column) {
case 'order':
$order = get_post_meta($post_id, '_pc_faq_order', true) ?: 0;
echo esc_html($order);
break;
}
}
}