admin.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <?php
  2. require_once WPCF7_PLUGIN_DIR . '/admin/includes/admin-functions.php';
  3. require_once WPCF7_PLUGIN_DIR . '/admin/includes/help-tabs.php';
  4. require_once WPCF7_PLUGIN_DIR . '/admin/includes/tag-generator.php';
  5. require_once WPCF7_PLUGIN_DIR . '/admin/includes/welcome-panel.php';
  6. require_once WPCF7_PLUGIN_DIR . '/admin/includes/config-validator.php';
  7. add_action( 'admin_init', 'wpcf7_admin_init', 10, 0 );
  8. function wpcf7_admin_init() {
  9. do_action( 'wpcf7_admin_init' );
  10. }
  11. add_action( 'admin_menu', 'wpcf7_admin_menu', 9, 0 );
  12. function wpcf7_admin_menu() {
  13. global $_wp_last_object_menu;
  14. $_wp_last_object_menu++;
  15. do_action( 'wpcf7_admin_menu' );
  16. add_menu_page( __( 'Contact Form 7', 'contact-form-7' ),
  17. __( 'Contact', 'contact-form-7' )
  18. . wpcf7_admin_menu_change_notice(),
  19. 'wpcf7_read_contact_forms', 'wpcf7',
  20. 'wpcf7_admin_management_page', 'dashicons-email',
  21. $_wp_last_object_menu );
  22. $edit = add_submenu_page( 'wpcf7',
  23. __( 'Edit Contact Form', 'contact-form-7' ),
  24. __( 'Contact Forms', 'contact-form-7' )
  25. . wpcf7_admin_menu_change_notice( 'wpcf7' ),
  26. 'wpcf7_read_contact_forms', 'wpcf7',
  27. 'wpcf7_admin_management_page' );
  28. add_action( 'load-' . $edit, 'wpcf7_load_contact_form_admin', 10, 0 );
  29. $addnew = add_submenu_page( 'wpcf7',
  30. __( 'Add New Contact Form', 'contact-form-7' ),
  31. __( 'Add New', 'contact-form-7' )
  32. . wpcf7_admin_menu_change_notice( 'wpcf7-new' ),
  33. 'wpcf7_edit_contact_forms', 'wpcf7-new',
  34. 'wpcf7_admin_add_new_page' );
  35. add_action( 'load-' . $addnew, 'wpcf7_load_contact_form_admin', 10, 0 );
  36. $integration = WPCF7_Integration::get_instance();
  37. if ( $integration->service_exists() ) {
  38. $integration = add_submenu_page( 'wpcf7',
  39. __( 'Integration with Other Services', 'contact-form-7' ),
  40. __( 'Integration', 'contact-form-7' )
  41. . wpcf7_admin_menu_change_notice( 'wpcf7-integration' ),
  42. 'wpcf7_manage_integration', 'wpcf7-integration',
  43. 'wpcf7_admin_integration_page' );
  44. add_action( 'load-' . $integration, 'wpcf7_load_integration_page', 10, 0 );
  45. }
  46. }
  47. function wpcf7_admin_menu_change_notice( $menu_slug = '' ) {
  48. $counts = apply_filters( 'wpcf7_admin_menu_change_notice',
  49. array(
  50. 'wpcf7' => 0,
  51. 'wpcf7-new' => 0,
  52. 'wpcf7-integration' => 0,
  53. )
  54. );
  55. if ( empty( $menu_slug ) ) {
  56. $count = absint( array_sum( $counts ) );
  57. } elseif ( isset( $counts[$menu_slug] ) ) {
  58. $count = absint( $counts[$menu_slug] );
  59. } else {
  60. $count = 0;
  61. }
  62. if ( $count ) {
  63. return sprintf(
  64. ' <span class="update-plugins %1$d"><span class="plugin-count">%2$s</span></span>',
  65. $count,
  66. esc_html( number_format_i18n( $count ) )
  67. );
  68. }
  69. return '';
  70. }
  71. add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_scripts', 10, 1 );
  72. function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
  73. if ( false === strpos( $hook_suffix, 'wpcf7' ) ) {
  74. return;
  75. }
  76. wp_enqueue_style( 'contact-form-7-admin',
  77. wpcf7_plugin_url( 'admin/css/styles.css' ),
  78. array(), WPCF7_VERSION, 'all'
  79. );
  80. if ( wpcf7_is_rtl() ) {
  81. wp_enqueue_style( 'contact-form-7-admin-rtl',
  82. wpcf7_plugin_url( 'admin/css/styles-rtl.css' ),
  83. array(), WPCF7_VERSION, 'all'
  84. );
  85. }
  86. wp_enqueue_script( 'wpcf7-admin',
  87. wpcf7_plugin_url( 'admin/js/scripts.js' ),
  88. array( 'jquery', 'jquery-ui-tabs' ),
  89. WPCF7_VERSION, true
  90. );
  91. $args = array(
  92. 'apiSettings' => array(
  93. 'root' => esc_url_raw( rest_url( 'contact-form-7/v1' ) ),
  94. 'namespace' => 'contact-form-7/v1',
  95. 'nonce' => ( wp_installing() && ! is_multisite() )
  96. ? '' : wp_create_nonce( 'wp_rest' ),
  97. ),
  98. 'pluginUrl' => wpcf7_plugin_url(),
  99. 'saveAlert' => __(
  100. "The changes you made will be lost if you navigate away from this page.",
  101. 'contact-form-7' ),
  102. 'activeTab' => isset( $_GET['active-tab'] )
  103. ? (int) $_GET['active-tab'] : 0,
  104. 'configValidator' => array(
  105. 'errors' => array(),
  106. 'howToCorrect' => __( "How to resolve?", 'contact-form-7' ),
  107. 'oneError' => __( '1 configuration error detected', 'contact-form-7' ),
  108. 'manyErrors' => __( '%d configuration errors detected', 'contact-form-7' ),
  109. 'oneErrorInTab' => __( '1 configuration error detected in this tab panel', 'contact-form-7' ),
  110. 'manyErrorsInTab' => __( '%d configuration errors detected in this tab panel', 'contact-form-7' ),
  111. 'docUrl' => WPCF7_ConfigValidator::get_doc_link(),
  112. /* translators: screen reader text */
  113. 'iconAlt' => __( '(configuration error)', 'contact-form-7' ),
  114. ),
  115. );
  116. if ( $post = wpcf7_get_current_contact_form()
  117. and current_user_can( 'wpcf7_edit_contact_form', $post->id() )
  118. and wpcf7_validate_configuration() ) {
  119. $config_validator = new WPCF7_ConfigValidator( $post );
  120. $config_validator->restore();
  121. $args['configValidator']['errors'] =
  122. $config_validator->collect_error_messages();
  123. }
  124. wp_localize_script( 'wpcf7-admin', 'wpcf7', $args );
  125. add_thickbox();
  126. wp_enqueue_script( 'wpcf7-admin-taggenerator',
  127. wpcf7_plugin_url( 'admin/js/tag-generator.js' ),
  128. array( 'jquery', 'thickbox', 'wpcf7-admin' ), WPCF7_VERSION, true );
  129. }
  130. add_action( 'doing_dark_mode', 'wpcf7_dark_mode_support', 10, 1 );
  131. function wpcf7_dark_mode_support( $user_id ) {
  132. wp_enqueue_style( 'contact-form-7-admin-dark-mode',
  133. wpcf7_plugin_url( 'admin/css/styles-dark-mode.css' ),
  134. array( 'contact-form-7-admin' ), WPCF7_VERSION, 'screen' );
  135. }
  136. add_filter( 'set-screen-option', 'wpcf7_set_screen_options', 10, 3 );
  137. function wpcf7_set_screen_options( $result, $option, $value ) {
  138. $wpcf7_screens = array(
  139. 'cfseven_contact_forms_per_page',
  140. );
  141. if ( in_array( $option, $wpcf7_screens ) ) {
  142. $result = $value;
  143. }
  144. return $result;
  145. }
  146. function wpcf7_load_contact_form_admin() {
  147. global $plugin_page;
  148. $action = wpcf7_current_action();
  149. do_action( 'wpcf7_admin_load',
  150. isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
  151. $action
  152. );
  153. if ( 'save' == $action ) {
  154. $id = isset( $_POST['post_ID'] ) ? $_POST['post_ID'] : '-1';
  155. check_admin_referer( 'wpcf7-save-contact-form_' . $id );
  156. if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) {
  157. wp_die( __( 'You are not allowed to edit this item.', 'contact-form-7' ) );
  158. }
  159. $args = $_REQUEST;
  160. $args['id'] = $id;
  161. $args['title'] = isset( $_POST['post_title'] )
  162. ? $_POST['post_title'] : null;
  163. $args['locale'] = isset( $_POST['wpcf7-locale'] )
  164. ? $_POST['wpcf7-locale'] : null;
  165. $args['form'] = isset( $_POST['wpcf7-form'] )
  166. ? $_POST['wpcf7-form'] : '';
  167. $args['mail'] = isset( $_POST['wpcf7-mail'] )
  168. ? $_POST['wpcf7-mail'] : array();
  169. $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] )
  170. ? $_POST['wpcf7-mail-2'] : array();
  171. $args['messages'] = isset( $_POST['wpcf7-messages'] )
  172. ? $_POST['wpcf7-messages'] : array();
  173. $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] )
  174. ? $_POST['wpcf7-additional-settings'] : '';
  175. $contact_form = wpcf7_save_contact_form( $args );
  176. if ( $contact_form and wpcf7_validate_configuration() ) {
  177. $config_validator = new WPCF7_ConfigValidator( $contact_form );
  178. $config_validator->validate();
  179. $config_validator->save();
  180. }
  181. $query = array(
  182. 'post' => $contact_form ? $contact_form->id() : 0,
  183. 'active-tab' => isset( $_POST['active-tab'] )
  184. ? (int) $_POST['active-tab'] : 0,
  185. );
  186. if ( ! $contact_form ) {
  187. $query['message'] = 'failed';
  188. } elseif ( -1 == $id ) {
  189. $query['message'] = 'created';
  190. } else {
  191. $query['message'] = 'saved';
  192. }
  193. $redirect_to = add_query_arg( $query, menu_page_url( 'wpcf7', false ) );
  194. wp_safe_redirect( $redirect_to );
  195. exit();
  196. }
  197. if ( 'copy' == $action ) {
  198. $id = empty( $_POST['post_ID'] )
  199. ? absint( $_REQUEST['post'] )
  200. : absint( $_POST['post_ID'] );
  201. check_admin_referer( 'wpcf7-copy-contact-form_' . $id );
  202. if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) {
  203. wp_die( __( 'You are not allowed to edit this item.', 'contact-form-7' ) );
  204. }
  205. $query = array();
  206. if ( $contact_form = wpcf7_contact_form( $id ) ) {
  207. $new_contact_form = $contact_form->copy();
  208. $new_contact_form->save();
  209. $query['post'] = $new_contact_form->id();
  210. $query['message'] = 'created';
  211. }
  212. $redirect_to = add_query_arg( $query, menu_page_url( 'wpcf7', false ) );
  213. wp_safe_redirect( $redirect_to );
  214. exit();
  215. }
  216. if ( 'delete' == $action ) {
  217. if ( ! empty( $_POST['post_ID'] ) ) {
  218. check_admin_referer( 'wpcf7-delete-contact-form_' . $_POST['post_ID'] );
  219. } elseif ( ! is_array( $_REQUEST['post'] ) ) {
  220. check_admin_referer( 'wpcf7-delete-contact-form_' . $_REQUEST['post'] );
  221. } else {
  222. check_admin_referer( 'bulk-posts' );
  223. }
  224. $posts = empty( $_POST['post_ID'] )
  225. ? (array) $_REQUEST['post']
  226. : (array) $_POST['post_ID'];
  227. $deleted = 0;
  228. foreach ( $posts as $post ) {
  229. $post = WPCF7_ContactForm::get_instance( $post );
  230. if ( empty( $post ) ) {
  231. continue;
  232. }
  233. if ( ! current_user_can( 'wpcf7_delete_contact_form', $post->id() ) ) {
  234. wp_die( __( 'You are not allowed to delete this item.', 'contact-form-7' ) );
  235. }
  236. if ( ! $post->delete() ) {
  237. wp_die( __( 'Error in deleting.', 'contact-form-7' ) );
  238. }
  239. $deleted += 1;
  240. }
  241. $query = array();
  242. if ( ! empty( $deleted ) ) {
  243. $query['message'] = 'deleted';
  244. }
  245. $redirect_to = add_query_arg( $query, menu_page_url( 'wpcf7', false ) );
  246. wp_safe_redirect( $redirect_to );
  247. exit();
  248. }
  249. $post = null;
  250. if ( 'wpcf7-new' == $plugin_page ) {
  251. $post = WPCF7_ContactForm::get_template( array(
  252. 'locale' => isset( $_GET['locale'] ) ? $_GET['locale'] : null,
  253. ) );
  254. } elseif ( ! empty( $_GET['post'] ) ) {
  255. $post = WPCF7_ContactForm::get_instance( $_GET['post'] );
  256. }
  257. $current_screen = get_current_screen();
  258. $help_tabs = new WPCF7_Help_Tabs( $current_screen );
  259. if ( $post
  260. and current_user_can( 'wpcf7_edit_contact_form', $post->id() ) ) {
  261. $help_tabs->set_help_tabs( 'edit' );
  262. } else {
  263. $help_tabs->set_help_tabs( 'list' );
  264. if ( ! class_exists( 'WPCF7_Contact_Form_List_Table' ) ) {
  265. require_once WPCF7_PLUGIN_DIR . '/admin/includes/class-contact-forms-list-table.php';
  266. }
  267. add_filter( 'manage_' . $current_screen->id . '_columns',
  268. array( 'WPCF7_Contact_Form_List_Table', 'define_columns' ), 10, 0 );
  269. add_screen_option( 'per_page', array(
  270. 'default' => 20,
  271. 'option' => 'cfseven_contact_forms_per_page',
  272. ) );
  273. }
  274. }
  275. function wpcf7_admin_management_page() {
  276. if ( $post = wpcf7_get_current_contact_form() ) {
  277. $post_id = $post->initial() ? -1 : $post->id();
  278. require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
  279. require_once WPCF7_PLUGIN_DIR . '/admin/edit-contact-form.php';
  280. return;
  281. }
  282. if ( 'validate' == wpcf7_current_action()
  283. and wpcf7_validate_configuration()
  284. and current_user_can( 'wpcf7_edit_contact_forms' ) ) {
  285. wpcf7_admin_bulk_validate_page();
  286. return;
  287. }
  288. $list_table = new WPCF7_Contact_Form_List_Table();
  289. $list_table->prepare_items();
  290. ?>
  291. <div class="wrap" id="wpcf7-contact-form-list-table">
  292. <h1 class="wp-heading-inline"><?php
  293. echo esc_html( __( 'Contact Forms', 'contact-form-7' ) );
  294. ?></h1>
  295. <?php
  296. if ( current_user_can( 'wpcf7_edit_contact_forms' ) ) {
  297. echo wpcf7_link(
  298. menu_page_url( 'wpcf7-new', false ),
  299. __( 'Add New', 'contact-form-7' ),
  300. array( 'class' => 'page-title-action' )
  301. );
  302. }
  303. if ( ! empty( $_REQUEST['s'] ) ) {
  304. echo sprintf( '<span class="subtitle">'
  305. /* translators: %s: search keywords */
  306. . __( 'Search results for &#8220;%s&#8221;', 'contact-form-7' )
  307. . '</span>', esc_html( $_REQUEST['s'] )
  308. );
  309. }
  310. ?>
  311. <hr class="wp-header-end">
  312. <?php
  313. do_action( 'wpcf7_admin_warnings',
  314. 'wpcf7', wpcf7_current_action(), null );
  315. wpcf7_welcome_panel();
  316. do_action( 'wpcf7_admin_notices',
  317. 'wpcf7', wpcf7_current_action(), null );
  318. ?>
  319. <form method="get" action="">
  320. <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
  321. <?php $list_table->search_box( __( 'Search Contact Forms', 'contact-form-7' ), 'wpcf7-contact' ); ?>
  322. <?php $list_table->display(); ?>
  323. </form>
  324. </div>
  325. <?php
  326. }
  327. function wpcf7_admin_add_new_page() {
  328. $post = wpcf7_get_current_contact_form();
  329. if ( ! $post ) {
  330. $post = WPCF7_ContactForm::get_template();
  331. }
  332. $post_id = -1;
  333. require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
  334. require_once WPCF7_PLUGIN_DIR . '/admin/edit-contact-form.php';
  335. }
  336. function wpcf7_load_integration_page() {
  337. do_action( 'wpcf7_admin_load',
  338. isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '',
  339. wpcf7_current_action()
  340. );
  341. $integration = WPCF7_Integration::get_instance();
  342. if ( isset( $_REQUEST['service'] )
  343. and $integration->service_exists( $_REQUEST['service'] ) ) {
  344. $service = $integration->get_service( $_REQUEST['service'] );
  345. $service->load( wpcf7_current_action() );
  346. }
  347. $help_tabs = new WPCF7_Help_Tabs( get_current_screen() );
  348. $help_tabs->set_help_tabs( 'integration' );
  349. }
  350. function wpcf7_admin_integration_page() {
  351. $integration = WPCF7_Integration::get_instance();
  352. $service = isset( $_REQUEST['service'] )
  353. ? $integration->get_service( $_REQUEST['service'] )
  354. : null;
  355. ?>
  356. <div class="wrap" id="wpcf7-integration">
  357. <h1><?php echo esc_html( __( 'Integration with Other Services', 'contact-form-7' ) ); ?></h1>
  358. <?php
  359. do_action( 'wpcf7_admin_warnings',
  360. 'wpcf7-integration', wpcf7_current_action(), $service );
  361. do_action( 'wpcf7_admin_notices',
  362. 'wpcf7-integration', wpcf7_current_action(), $service );
  363. if ( $service ) {
  364. $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : '';
  365. $service->admin_notice( $message );
  366. $integration->list_services( array( 'include' => $_REQUEST['service'] ) );
  367. } else {
  368. $integration->list_services();
  369. }
  370. ?>
  371. </div>
  372. <?php
  373. }
  374. /* Misc */
  375. add_action( 'wpcf7_admin_notices', 'wpcf7_admin_updated_message', 10, 3 );
  376. function wpcf7_admin_updated_message( $page, $action, $object ) {
  377. if ( ! in_array( $page, array( 'wpcf7', 'wpcf7-new' ) ) ) {
  378. return;
  379. }
  380. if ( empty( $_REQUEST['message'] ) ) {
  381. return;
  382. }
  383. if ( 'created' == $_REQUEST['message'] ) {
  384. $updated_message = __( "Contact form created.", 'contact-form-7' );
  385. } elseif ( 'saved' == $_REQUEST['message'] ) {
  386. $updated_message = __( "Contact form saved.", 'contact-form-7' );
  387. } elseif ( 'deleted' == $_REQUEST['message'] ) {
  388. $updated_message = __( "Contact form deleted.", 'contact-form-7' );
  389. }
  390. if ( ! empty( $updated_message ) ) {
  391. echo sprintf( '<div id="message" class="notice notice-success is-dismissible"><p>%s</p></div>', esc_html( $updated_message ) );
  392. return;
  393. }
  394. if ( 'failed' == $_REQUEST['message'] ) {
  395. $updated_message = __( "There was an error saving the contact form.",
  396. 'contact-form-7' );
  397. echo sprintf( '<div id="message" class="notice notice-error is-dismissible"><p>%s</p></div>', esc_html( $updated_message ) );
  398. return;
  399. }
  400. if ( 'validated' == $_REQUEST['message'] ) {
  401. $bulk_validate = WPCF7::get_option( 'bulk_validate', array() );
  402. $count_invalid = isset( $bulk_validate['count_invalid'] )
  403. ? absint( $bulk_validate['count_invalid'] ) : 0;
  404. if ( $count_invalid ) {
  405. $updated_message = sprintf(
  406. _n(
  407. /* translators: %s: number of contact forms */
  408. "Configuration validation completed. %s invalid contact form was found.",
  409. "Configuration validation completed. %s invalid contact forms were found.",
  410. $count_invalid, 'contact-form-7'
  411. ),
  412. number_format_i18n( $count_invalid )
  413. );
  414. echo sprintf( '<div id="message" class="notice notice-warning is-dismissible"><p>%s</p></div>', esc_html( $updated_message ) );
  415. } else {
  416. $updated_message = __( "Configuration validation completed. No invalid contact form was found.", 'contact-form-7' );
  417. echo sprintf( '<div id="message" class="notice notice-success is-dismissible"><p>%s</p></div>', esc_html( $updated_message ) );
  418. }
  419. return;
  420. }
  421. }
  422. add_filter( 'plugin_action_links', 'wpcf7_plugin_action_links', 10, 2 );
  423. function wpcf7_plugin_action_links( $links, $file ) {
  424. if ( $file != WPCF7_PLUGIN_BASENAME ) {
  425. return $links;
  426. }
  427. if ( ! current_user_can( 'wpcf7_read_contact_forms' ) ) {
  428. return $links;
  429. }
  430. $settings_link = wpcf7_link(
  431. menu_page_url( 'wpcf7', false ),
  432. __( 'Settings', 'contact-form-7' )
  433. );
  434. array_unshift( $links, $settings_link );
  435. return $links;
  436. }
  437. add_action( 'wpcf7_admin_warnings', 'wpcf7_old_wp_version_error', 10, 3 );
  438. function wpcf7_old_wp_version_error( $page, $action, $object ) {
  439. $wp_version = get_bloginfo( 'version' );
  440. if ( ! version_compare( $wp_version, WPCF7_REQUIRED_WP_VERSION, '<' ) ) {
  441. return;
  442. }
  443. ?>
  444. <div class="notice notice-warning">
  445. <p><?php
  446. echo sprintf(
  447. /* translators: 1: version of Contact Form 7, 2: version of WordPress, 3: URL */
  448. __( '<strong>Contact Form 7 %1$s requires WordPress %2$s or higher.</strong> Please <a href="%3$s">update WordPress</a> first.', 'contact-form-7' ),
  449. WPCF7_VERSION,
  450. WPCF7_REQUIRED_WP_VERSION,
  451. admin_url( 'update-core.php' )
  452. );
  453. ?></p>
  454. </div>
  455. <?php
  456. }
  457. add_action( 'wpcf7_admin_warnings', 'wpcf7_not_allowed_to_edit', 10, 3 );
  458. function wpcf7_not_allowed_to_edit( $page, $action, $object ) {
  459. if ( $object instanceof WPCF7_ContactForm ) {
  460. $contact_form = $object;
  461. } else {
  462. return;
  463. }
  464. if ( current_user_can( 'wpcf7_edit_contact_form', $contact_form->id() ) ) {
  465. return;
  466. }
  467. $message = __( "You are not allowed to edit this contact form.",
  468. 'contact-form-7' );
  469. echo sprintf(
  470. '<div class="notice notice-warning"><p>%s</p></div>',
  471. esc_html( $message ) );
  472. }