options = $options; $this->pluginVersion = $pluginVersion; $this->form = new Form($this->options); $this->initAdminPhrases(); $this->formContentTypeRel = $options->formContentTypeRel; $this->formPostRel = $options->formPostRel; SocialLogin::getInstance($this->options); add_action("wpdiscuz_init", [&$this, "registerPostType"], 1); add_action("admin_init", [&$this, "custoFormRoleCaps"], 999); add_action("admin_menu", [&$this, "addFormToAdminMenu"], 874); add_action("admin_enqueue_scripts", [&$this, "customFormAdminScripts"], 245); add_action("manage_wpdiscuz_form_posts_custom_column", [&$this, "displayContentTypesOnList"], 10, 2); add_filter("manage_wpdiscuz_form_posts_columns", [&$this, "addContentTypeColumn"]); add_action("edit_form_after_title", [&$this, "renderFormGeneralSettings"]); add_action("wp_ajax_wpdiscuzCustomFields", [&$this, "wpdiscuzFieldsDialogContent"]); add_action("wp_ajax_adminFieldForm", [&$this, "adminFieldForm"]); add_action("transition_comment_status", [&$this, "changeCommentStatus"], 10, 3); add_action("delete_comment", [&$this, "deleteCommentRating"], 269); add_filter("wpdiscuz_before_subscription_added", [&$this->form, "validateSubscribtionCaptcha"]); add_filter("wpdiscuz_js_options", [$this, "transferJSData"], 10); add_action("save_post", [&$this, "saveFormData"], 10, 3); add_action("wp_trash_post", [&$this, "deleteOrTrashForm"]); add_action("add_meta_boxes", [$this, "formCustomCssMetabox"]); add_action("add_meta_boxes_comment", [&$this, "renderEditCommentForm"], 10); add_filter("comment_save_pre", [&$this, "validateMetaCommentSavePre"], 10); add_action("comment_post", [&$this, "addCommentMeta"], 5); add_action("edit_comment", [&$this, "updateCommentMeta"], 10); add_filter("comment_text", [&$this, "renderCommentMetaHtml"], 10, 2); add_filter("wpdiscuz_after_read_more", [&$this, "afterReadMore"], 10, 2); add_filter("post_row_actions", [&$this, "addCloneFormAction"], 10, 2); add_filter("admin_post_cloneWpdiscuzForm", [&$this, "cloneForm"]); add_filter("the_content", [&$this->form, "displayRatingMeta"], 10); add_shortcode("wpdrating", [&$this->form, "getRatingMetaHtml"]); add_filter("wpdiscuz_comment_form_before", [&$this->form, "displayRatingMetaBeforeCommentForm"], 10); add_action("admin_notices", [&$this, "formExists"]); add_action("wp_loaded", [&$this, "initPersonalDataExporter"]); } public function initPersonalDataExporter() { if (class_exists('PersonalDataExporter')) { PersonalDataExporter::getInstance($this->options); } } public function validateMetaCommentSavePre($commentContent) { if (Sanitizer::sanitize(INPUT_POST, "action", "FILTER_SANITIZE_STRING") === "editedcomment") { $postID = Sanitizer::sanitize(INPUT_POST, "comment_post_ID", FILTER_SANITIZE_NUMBER_INT); $this->getForm($postID); if ($this->form) { $currentUser = WpdiscuzHelper::getCurrentUser(); $this->form->initFormFields(); $this->form->validateFields($currentUser); } } return $commentContent; } public function addCommentMeta($commentID) { if (Sanitizer::sanitize(INPUT_POST, "action", "FILTER_SANITIZE_STRING") === "wpdAddComment") { $postID = Sanitizer::sanitize(INPUT_POST, "postId", FILTER_SANITIZE_NUMBER_INT); $this->getForm($postID); if ($this->form) { $this->form->saveCommentMeta($commentID); } } } public function updateCommentMeta($commentID) { if (Sanitizer::sanitize(INPUT_POST, "action", "FILTER_SANITIZE_STRING") === "editedcomment") { $postID = Sanitizer::sanitize(INPUT_POST, "comment_post_ID", FILTER_SANITIZE_NUMBER_INT); $this->getForm($postID); if ($this->form) { $this->form->saveCommentMeta($commentID); } } } public function adminFieldForm() { $this->canManageOptions(); $field = Sanitizer::sanitize(INPUT_POST, "fieldType", "FILTER_SANITIZE_STRING"); $isDefault = Sanitizer::sanitize(INPUT_POST, "defaultField", FILTER_SANITIZE_NUMBER_INT); $row = Sanitizer::sanitize(INPUT_POST, "row", "FILTER_SANITIZE_STRING"); $col = Sanitizer::sanitize(INPUT_POST, "col", "FILTER_SANITIZE_STRING"); if ($field && $row && $col) { if ($isDefault) { $field = "wpdFormAttr\Field\\$field"; } $allowedFieldsType = $this->form->getAllowedFieldsType(); if (!in_array($field, $allowedFieldsType, true)) { esc_html_e("Not whitelisted value detected"); } $fieldClass = call_user_func($field . '::getInstance'); $fieldClass->dashboardFormDialogHtml($row, $col); } else { esc_html_e("Invalid Data !!!"); } wp_die(); } public function registerPostType() { register_post_type(self::WPDISCUZ_FORMS_CONTENT_TYPE, [ "labels" => [ "name" => esc_html__("Forms", "wpdiscuz"), "singular_name" => esc_html__("Form", "wpdiscuz"), "add_new" => esc_html__("Add New", "wpdiscuz"), "add_new_item" => esc_html__("Add New Form", "wpdiscuz"), "edit_item" => esc_html__("Edit Form", "wpdiscuz"), "not_found" => esc_html__("You did not create any forms yet", "wpdiscuz"), "not_found_in_trash" => esc_html__("Nothing found in Trash", "wpdiscuz"), "search_items" => esc_html__("Search Forms", "wpdiscuz") ], "show_ui" => true, "show_in_menu" => false, "public" => false, "supports" => ["title"], "capability_type" => self::WPDISCUZ_FORMS_CONTENT_TYPE, "map_meta_cap" => true, ] ); } public function custoFormRoleCaps() { $role = get_role("administrator"); if ($role) { $role->add_cap("read"); $role->add_cap("read_" . self::WPDISCUZ_FORMS_CONTENT_TYPE); $role->add_cap("read_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("edit_" . self::WPDISCUZ_FORMS_CONTENT_TYPE); $role->add_cap("edit_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("edit_others_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("edit_published_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("publish_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("delete_" . self::WPDISCUZ_FORMS_CONTENT_TYPE); $role->add_cap("delete_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("delete_others_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("delete_private_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); $role->add_cap("delete_published_" . self::WPDISCUZ_FORMS_CONTENT_TYPE . "s"); } } public function saveFormData($postId, $post, $update) { if ($post->post_type !== self::WPDISCUZ_FORMS_CONTENT_TYPE || (isset($_REQUEST["action"]) && $_REQUEST["action"] === "inline-save")) { return; } $this->canManageOptions(); $this->form->saveFormData($postId); $css = sanitize_textarea_field(Sanitizer::sanitize(INPUT_POST, self::WPDISCUZ_META_FORMS_CSS, FILTER_DEFAULT)); update_post_meta($postId, self::WPDISCUZ_META_FORMS_CSS, $css); } public function addFormToAdminMenu() { global $submenu; if (!empty($submenu["wpdiscuz"])) { $submenu["wpdiscuz"][] = [ "
» " . esc_html__("Forms", "wpdiscuz"), "manage_options", "edit.php?post_type=" . self::WPDISCUZ_FORMS_CONTENT_TYPE ]; } } /* Display custom column */ public function displayContentTypesOnList($column, $post_id) { $this->form->theFormListData($column, $post_id); } /* Add custom column to post list */ public function addContentTypeColumn($columns) { return [ "cb" => "", "title" => esc_html__("Title", "default"), "form_post_types" => esc_html__("Post Types", "wpdiscuz"), "form_post_ids" => esc_html__("Post IDs", "wpdiscuz"), "form_lang" => esc_html__("Language", "wpdiscuz"), "date" => esc_html__("Date", "default"), ]; } public function customFormAdminScripts() { global $current_screen; if ($current_screen->id === self::WPDISCUZ_FORMS_CONTENT_TYPE) { wp_register_style("fontawesome-iconpicker-css", plugins_url(WPDISCUZ_DIR_NAME . "/assets/third-party/fontawesome-iconpicker/css/fontawesome-iconpicker.min.css"), [], "1.12.1"); wp_enqueue_style("fontawesome-iconpicker-css"); wp_register_script("fontawesome-iconpicker-js", plugins_url(WPDISCUZ_DIR_NAME . "/assets/third-party/fontawesome-iconpicker/js/fontawesome-iconpicker.js"), ["jquery"], "1.12.1", true); wp_enqueue_script("fontawesome-iconpicker-js"); wp_register_style("wpdiscuz-custom-form-css", plugins_url(WPDISCUZ_DIR_NAME . "/assets/css/wpdiscuz-custom-form.css"), [], $this->pluginVersion); wp_enqueue_style("wpdiscuz-custom-form-css"); wp_register_script("wpdiscuz-custom-form", plugins_url(WPDISCUZ_DIR_NAME . "/assets/js/wpdiscuz-custom-form.js"), ["jquery"], $this->pluginVersion, true); wp_enqueue_script("wpdiscuz-custom-form"); wp_localize_script("wpdiscuz-custom-form", "wpdFormAdminOptions", $this->wpdFormAdminOptions); wp_register_script("wpdiscuz-form-menu-item", plugins_url(WPDISCUZ_DIR_NAME . "/assets/js/wpdiscuz-admin-menu-item.js"), ["jquery"], $this->pluginVersion, true); wp_enqueue_script("wpdiscuz-form-menu-item"); wp_enqueue_style("thickbox"); wp_enqueue_script("thickbox"); wp_enqueue_script("jquery-ui-sortable"); } if ($current_screen->id === "edit-" . self::WPDISCUZ_FORMS_CONTENT_TYPE) { wp_register_script("wpdiscuz-form-menu-item", plugins_url(WPDISCUZ_DIR_NAME . "/assets/js/wpdiscuz-admin-menu-item.js"), ["jquery"], $this->pluginVersion, true); wp_enqueue_script("wpdiscuz-form-menu-item"); } } public function renderFormGeneralSettings($post) { global $current_screen; if ($current_screen->id === self::WPDISCUZ_FORMS_CONTENT_TYPE) { $this->form->setFormID($post->ID); $this->form->renderFormStructure(); } } public function wpdiscuzFieldsDialogContent() { $this->canManageOptions(); include_once WPDISCUZ_DIR_PATH . "/forms/wpdFormAttr/html/admin-form-fields-list.php"; wp_die(); } private function initAdminPhrases() { $this->wpdFormAdminOptions = [ "wpdiscuz_form_structure" => wpdFormConst::WPDISCUZ_META_FORMS_STRUCTURE, "wpd_form_fields" => esc_html__("Field Types", "wpdiscuz"), "two_column" => esc_html__("Two column", "wpdiscuz"), "delete" => esc_html__("Delete", "wpdiscuz"), "move" => esc_html__("Move", "wpdiscuz"), "add_field" => esc_html__("Add Field", "wpdiscuz"), "edit_field" => esc_html__("Edit", "wpdiscuz"), "can_not_delete_field" => esc_html__("You can not delete default field.", "wpdiscuz"), "confirm_delete_message" => esc_html__("You really want to delete this item ?", "wpdiscuz"), "loaderImg" => plugins_url(WPDISCUZ_DIR_NAME . "/assets/img/form-loading.gif"), ]; } private function canManageOptions() { if (is_admin() && !current_user_can("manage_options")) { wp_die(esc_html__("Permission Denied !!!", "wpdiscuz")); } } public function renderFrontForm($commentsCount, $currentUser) { global $post; $this->getForm($post->ID); $this->form->initFormMeta(); $this->form->renderFrontForm("main", "0_0", $commentsCount, $currentUser, $post->ID); ?> form->resetData(); $this->getForm($comment->comment_post_ID); if ($this->form && $this->form->customFieldsExists()) { $html = " query_vars["post_type"]) && $q->query_vars["post_type"] === self::WPDISCUZ_FORMS_CONTENT_TYPE) { if (isset($q->query_vars["elementor_library_category"])) { unset($q->query_vars["elementor_library_category"]); } $q->query_vars["meta_key"] = ""; $q->query_vars["meta_value"] = ""; } return $q; } public function deleteCommentRating($commentId) { $rating = get_comment_meta($commentId, "rating", true); $comment = get_comment($commentId); if ($rating && $comment->comment_approved === "1") { $this->updatePostRating($comment, -1); } } public function changeCommentStatus($new_status, $old_status, $comment) { $rating = get_comment_meta($comment->comment_ID, "rating", true); if ($old_status === "approved" && $rating) { $this->updatePostRating($comment, -1); } else if ($new_status === "approved" && $rating) { $this->updatePostRating($comment, 1); } } private function updatePostRating($comment, $difference) { $postRatings = get_post_meta($comment->comment_post_ID, self::WPDISCUZ_RATING_COUNT, true); $form = $this->getForm($comment->comment_post_ID); $form->initFormFields(); $formFields = $form->getFormFields(); foreach ($formFields as $key => $value) { if ($value["type"] === "wpdFormAttr\Field\RatingField") { $postRatings = $this->chagePostSingleRating($key, $comment->comment_ID, $difference, $postRatings); } } update_post_meta($comment->comment_post_ID, self::WPDISCUZ_RATING_COUNT, $postRatings); $form->updateSeparateRatingMeta($postRatings, $comment->comment_post_ID); } private function chagePostSingleRating($metaKey, $commentID, $difference, $postRatings) { $commentFieldRating = get_comment_meta($commentID, $metaKey, true); if (!$postRatings) { $postRatings = [$metaKey => []]; } if ($commentFieldRating) { if (isset($postRatings[$metaKey][$commentFieldRating])) { $postRatings[$metaKey][$commentFieldRating] = $postRatings[$metaKey][$commentFieldRating] + $difference; } else { $postRatings[$metaKey][$commentFieldRating] = $difference; } } return $postRatings; } }
" . esc_html__("Custom Fields", "wpdiscuz") . "
"; $html .= "