admin_hooks(); Capabilities::assign_capabilities_for_user_roles(); } /** * Admin Hooks. * * @since 1.0.0 */ public function admin_hooks() { add_action( 'admin_menu', array( $this, 'create_admin_menu_pages' ) ); // admin_footer, not admin_init: the flag is read while localizing the // client script, so clearing it earlier would hide the badge on the // very visit that is supposed to show it. add_action( 'admin_footer', array( $this, 'maybe_mark_mcp_page_seen' ) ); add_action( 'wp_ajax_quillforms_duplicate_form', array( $this, 'duplicate_form' ) ); add_action( 'wp_ajax_quillforms_install_doublescale', array( $this, 'install_doublescale' ) ); add_action( 'wp_ajax_quillforms_activate_doublescale', array( $this, 'activate_doublescale' ) ); add_action( 'pre_get_posts', array( $this, 'include_quill_forms_post_type_in_query' ), 11 ); add_filter( 'post_type_link', array( $this, 'remove_cpt_slug' ), 10, 3 ); add_filter('rewrite_rules_array', array($this, 'rewrite_quillforms_rules') ); } /** * Drop the "New" badge once the MCP page has been opened. * * Runs late in the request so the badge survives the visit that reveals it, * and is gone from the next page load onwards. * * @since 5.8.0 * * @return void */ public function maybe_mark_mcp_page_seen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check of the current screen, no state is changed on behalf of the user. if ( ! isset( $_GET['page'], $_GET['path'] ) || 'quillforms' !== $_GET['page'] || 'mcp' !== $_GET['path'] ) { return; } if ( ! current_user_can( apply_filters( 'quillforms_admin_capability_filter', 'manage_quillforms' ) ) ) { return; } if ( ! get_option( 'quillforms_mcp_page_seen' ) ) { update_option( 'quillforms_mcp_page_seen', 1 ); } } /** * Duplicate form * * @since 1.7.4 * * @return integer|WP_Error|false */ public function duplicate_form() { // check for valid nonce field. if ( ! check_ajax_referer( 'quillforms_duplicate', '_nonce', false ) ) { wp_send_json_error( esc_html__( 'Invalid nonce', 'quillforms' ), 403 ); exit; } if ( ! current_user_can( 'manage_quillforms' ) ) { wp_send_json_error( 'Unauthorized' ); return; } $form_id = (int) $_POST['form_id']; $form = get_post( $form_id ); if ( ! $form ) { return false; } $new_form_id = wp_insert_post( array( 'post_title' => $form->post_title . ' copy', 'post_status' => 'draft', 'post_type' => $form->post_type, 'post_author' => $form->post_author, ) ); if ( is_wp_error( $new_form_id ) ) { return $new_form_id; } $form_meta = get_post_meta( $form_id ); foreach ( $form_meta as $key => $values ) { foreach ( $values as $value ) { add_post_meta( $new_form_id, $key, maybe_unserialize( $value ) ); } } wp_send_json_success( $new_form_id ); } /** * Install DoubleScale plugin (our partner CRM/mailer) from WordPress.org * * @since 3.5.0 */ public function install_doublescale() { // Check nonce. if ( ! check_ajax_referer( 'quillforms_install_doublescale', '_nonce', false ) ) { wp_send_json_error( esc_html__( 'Invalid nonce', 'quillforms' ), 403 ); exit; } // Check permissions. if ( ! current_user_can( 'install_plugins' ) ) { wp_send_json_error( esc_html__( 'You do not have permission to install plugins.', 'quillforms' ), 403 ); exit; } // Include required files. require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; // Get plugin info from WordPress.org. $api = plugins_api( 'plugin_information', array( 'slug' => 'doublescale', 'fields' => array( 'short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false, ), ) ); if ( is_wp_error( $api ) ) { wp_send_json_error( $api->get_error_message() ); exit; } // Install the plugin. $skin = new \WP_Ajax_Upgrader_Skin(); $upgrader = new \Plugin_Upgrader( $skin ); $result = $upgrader->install( $api->download_link ); if ( is_wp_error( $result ) ) { wp_send_json_error( $result->get_error_message() ); exit; } if ( is_wp_error( $skin->result ) ) { wp_send_json_error( $skin->result->get_error_message() ); exit; } if ( $skin->get_errors()->has_errors() ) { wp_send_json_error( $skin->get_error_messages() ); exit; } if ( is_null( $result ) ) { wp_send_json_error( esc_html__( 'Unable to connect to the filesystem. Please confirm your credentials.', 'quillforms' ) ); exit; } wp_send_json_success( esc_html__( 'DoubleScale installed successfully.', 'quillforms' ) ); } /** * Activate DoubleScale plugin (our partner CRM/mailer) * * @since 3.5.0 */ public function activate_doublescale() { // Check nonce. if ( ! check_ajax_referer( 'quillforms_activate_doublescale', '_nonce', false ) ) { wp_send_json_error( esc_html__( 'Invalid nonce', 'quillforms' ), 403 ); exit; } // Check permissions. if ( ! current_user_can( 'activate_plugins' ) ) { wp_send_json_error( esc_html__( 'You do not have permission to activate plugins.', 'quillforms' ), 403 ); exit; } $plugin_file = 'doublescale/doublescale.php'; // Check if plugin exists. if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) { wp_send_json_error( esc_html__( 'DoubleScale plugin not found.', 'quillforms' ) ); exit; } // Activate the plugin. $result = activate_plugin( $plugin_file ); if ( is_wp_error( $result ) ) { wp_send_json_error( $result->get_error_message() ); exit; } wp_send_json_success( esc_html__( 'DoubleScale activated successfully.', 'quillforms' ) ); } /** * Create admin menu pages * * @since 1.0.0 */ public function create_admin_menu_pages() { add_menu_page( __( 'Quill Forms', 'quillforms' ), __( 'Quill Forms', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms', array( Admin_Loader::class, 'page_wrapper' ), 'data:image/svg+xml;base64,' . base64_encode( ' ' ), 30 ); // Add main page as a submenu page. add_submenu_page( 'quillforms', __( 'Quill Forms', 'quillforms' ), __( 'All Forms', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms', array( Admin_Loader::class, 'page_wrapper' ) ); // Add addons page as a submenu page. add_submenu_page( 'quillforms', __( 'Addons', 'quillforms' ), __( 'Addons', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=addons', array( Admin_Loader::class, 'page_wrapper' ) ); // Add settings page as a submenu page. add_submenu_page( 'quillforms', __( 'Settings', 'quillforms' ), __( 'Settings', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=settings', array( Admin_Loader::class, 'page_wrapper' ) ); // Add MCP server page as a submenu page. add_submenu_page( 'quillforms', __( 'MCP Server', 'quillforms' ), __( 'MCP Server', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=mcp', array( Admin_Loader::class, 'page_wrapper' ) ); // Add license page as a submenu page. add_submenu_page( 'quillforms', __( 'License', 'quillforms' ), __( 'License', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=license', array( Admin_Loader::class, 'page_wrapper' ) ); // Add system page as a submenu page. add_submenu_page( 'quillforms', __( 'System', 'quillforms' ), __( 'System', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=system', array( Admin_Loader::class, 'page_wrapper' ) ); // Add import/export page as a submenu page. add_submenu_page( 'quillforms', __( 'Import/Export', 'quillforms' ), __( 'Import/Export', 'quillforms' ), 'manage_quillforms', 'quillforms&path=import-export', array( Admin_Loader::class, 'page_wrapper' ) ); // Add support page as a submenu page. add_submenu_page( 'quillforms', __( 'Support', 'quillforms' ), __( 'Support', 'quillforms' ), apply_filters('quillforms_admin_capability_filter', 'manage_quillforms'), 'quillforms&path=support', array( Admin_Loader::class, 'page_wrapper' ) ); } /** * Include quill_forms in post type query if the slug is empty. * * @since 1.17.1 * * @param object $query Query object. * @return void */ public function include_quill_forms_post_type_in_query( $query ) { if ( Settings::get( 'override_quillforms_slug' ) && empty( Settings::get( 'quillforms_slug' ) ) ) { // Only noop the main query. if ( ! $query->is_main_query() ) { return; } // Only noop our very specific rewrite rule match. if ( 2 !== count( $query->query ) || ! isset( $query->query['page'] ) ) { return; } // Include my post type in the query. if ( ! empty( $query->query['name'] ) ) { $query->set( 'post_type', array( 'post', 'page', 'quill_forms' ) ); } } } /** * Remove CPT Slug * * @since 1.25.0 */ public function remove_cpt_slug( $post_link, $post, $leavename ) { if ( 'quill_forms' !== $post->post_type || 'publish' !== $post->post_status || ! Settings::get( 'override_quillforms_slug' ) || ! empty( Settings::get( 'quillforms_slug' ) ) ) { return $post_link; } $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } /** * Rewrite QuillForms Rules * * @since 3.4.0 */ public function rewrite_quillforms_rules( $rules ) { $override_slug= Settings::get("override_quillforms_slug"); $new_slug = Settings::get("quillforms_slug"); // if($override_slug && empty($new_slug)) { // in this case the url shouldn't contain quillforms slug $rules = array_merge( ['[^/]+/quillforms/([^/]+)/?$' => 'index.php?quill_forms=$matches[1]'], $rules ); } return $rules; } }