Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.91% covered (danger)
40.91%
9 / 22
75.00% covered (warning)
75.00%
9 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Forms
40.91% covered (danger)
40.91%
9 / 22
75.00% covered (warning)
75.00%
9 / 12
61.42
0.00% covered (danger)
0.00%
0 / 1
 load_contact_form
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 plugin_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 assets_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_feedback_dashboard_enabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_legacy_menu_item_retired
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_mailpoet_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_hostinger_reach_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_integrations_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_webhooks_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 show_dashboard_integrations
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 show_block_integrations
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 show_integration_icons
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Package description here
4 *
5 * @package automattic/jetpack-forms
6 */
7
8namespace Automattic\Jetpack\Forms;
9
10use Automattic\Jetpack\Forms\ContactForm\Util;
11use Automattic\Jetpack\Forms\Dashboard\Dashboard;
12/**
13 * Understands the Jetpack Forms package.
14 */
15class Jetpack_Forms {
16
17    const PACKAGE_VERSION = '7.20.0';
18
19    /**
20     * Load the contact form module.
21     */
22    public static function load_contact_form() {
23        Util::init();
24
25        if ( self::is_feedback_dashboard_enabled() ) {
26            $dashboard = new Dashboard();
27            $dashboard->init();
28        }
29
30        if ( is_admin() && apply_filters_deprecated( 'tmp_grunion_allow_editor_view', array( true ), '0.30.5', '', 'This functionality will be removed in an upcoming version.' ) ) {
31            add_action( 'current_screen', '\Automattic\Jetpack\Forms\ContactForm\Editor_View::add_hooks' );
32        }
33
34        add_action( 'init', '\Automattic\Jetpack\Forms\ContactForm\Util::register_pattern' );
35
36        // Add hook to delete file attachments when a feedback post is deleted
37        add_action( 'before_delete_post', array( '\Automattic\Jetpack\Forms\ContactForm\Contact_Form', 'delete_feedback_files' ) );
38
39        // Invalidate the source post IDs cache when a feedback post is permanently deleted.
40        add_action( 'deleted_post', array( '\Automattic\Jetpack\Forms\ContactForm\Feedback', 'invalidate_source_ids_cache_on_delete' ), 10, 2 );
41
42        // Enforces the availability of block support controls in the UI for classic themes.
43        add_filter( 'wp_theme_json_data_default', array( '\Automattic\Jetpack\Forms\ContactForm\Contact_Form', 'add_theme_json_data_for_classic_themes' ) );
44
45        // Initialize abilities registration for WordPress Abilities API (WP 6.9+)
46        \Automattic\Jetpack\Forms\Abilities\Forms_Abilities::init();
47    }
48
49    /**
50     * Get the plugin URL.
51     */
52    public static function plugin_url() {
53        return plugin_dir_url( __FILE__ );
54    }
55
56    /**
57     * Get the assets URL.
58     */
59    public static function assets_url() {
60        return plugin_dir_url( __DIR__ ) . 'assets';
61    }
62
63    /**
64     * Returns true if the feedback dashboard is enabled.
65     *
66     * @return boolean
67     */
68    public static function is_feedback_dashboard_enabled() {
69        /**
70         * Enable the new Jetpack Forms dashboard.
71         *
72         * @module contact-form
73         * @since 0.3.0
74         *
75         * @param bool false Should the new Jetpack Forms dashboard be enabled? Default to false.
76         */
77        return apply_filters( 'jetpack_forms_dashboard_enable', true );
78    }
79
80    /**
81     * Returns true if the legacy menu item is retired.
82     *
83     * @return boolean
84     */
85    public static function is_legacy_menu_item_retired() {
86        return apply_filters( 'jetpack_forms_retire_legacy_menu_item', true );
87    }
88
89    /**
90     * Returns true if MailPoet integration is enabled.
91     *
92     * @return boolean
93     */
94    public static function is_mailpoet_enabled() {
95        /**
96         * Enable MailPoet integration.
97         *
98         * @param bool false Whether MailPoet integration be enabled. Default is false.
99         */
100        return apply_filters( 'jetpack_forms_mailpoet_enable', true );
101    }
102
103    /**
104     * Returns true if Hostinger Reach integration is enabled.
105     *
106     * @return boolean
107     */
108    public static function is_hostinger_reach_enabled() {
109        /**
110         * Enable Hostinger Reach integration.
111         *
112         * @param bool false Whether Hostinger Reach integration be enabled. Default is false.
113         */
114        return apply_filters( 'jetpack_forms_hostinger_reach_enable', false );
115    }
116
117    /**
118     * Returns true if the Integrations UI should be enabled.
119     *
120     * @return boolean
121     */
122    public static function is_integrations_enabled() {
123        /**
124         * Whether to enable the Integrations UI.
125         *
126         * @param bool true Whether to enable the Integrations UI. Default true.
127         */
128        return apply_filters( 'jetpack_forms_is_integrations_enabled', true );
129    }
130
131    /**
132     * Returns true if webhooks are enabled.
133     *
134     * @return boolean
135     */
136    public static function is_webhooks_enabled() {
137        /**
138         * Whether to enable webhooks for Jetpack Forms.
139         *
140         * @param bool true Whether webhooks should be enabled. Default true.
141         */
142        return apply_filters( 'jetpack_forms_webhooks_enabled', true );
143    }
144
145    /**
146     * Returns true if the Integrations UI should be shown in the Forms dashboard.
147     *
148     * @since 6.22.0
149     *
150     * @return boolean
151     */
152    public static function show_dashboard_integrations() {
153        /**
154         * Whether to show Integrations UI in the Forms dashboard.
155         *
156         * @since 6.22.0
157         *
158         * @param bool true Whether to show the Integrations UI in the dashboard. Default true.
159         */
160        return apply_filters( 'jetpack_forms_show_dashboard_integrations', true );
161    }
162
163    /**
164     * Returns true if the Integrations UI should be shown in the Form block editor.
165     *
166     * @since 6.22.0
167     *
168     * @return boolean
169     */
170    public static function show_block_integrations() {
171        /**
172         * Whether to show Integrations UI in the Form block editor.
173         *
174         * @since 6.22.0
175         *
176         * @param bool true Whether to show the Integrations UI in the editor. Default true.
177         */
178        return apply_filters( 'jetpack_forms_show_block_integrations', true );
179    }
180
181    /**
182     * Returns true if integration icons should be shown (editor sidebar and integrations modal).
183     *
184     * @since 6.22.0
185     *
186     * @return boolean
187     */
188    public static function show_integration_icons() {
189        /**
190         * Whether to show integration icons in the UI.
191         *
192         * If set to false, the ActiveIntegrations component (editor sidebar) will be hidden
193         * and integration icons in the integrations modal will not be rendered.
194         *
195         * @since 6.22.0
196         *
197         * @param bool true Whether to show integration icons. Default true.
198         */
199        return apply_filters( 'jetpack_forms_show_integration_icons', true );
200    }
201}