@@ -1221,6 +1221,7 @@ public function wp_ajax_get_attachment_info()
1221
1221
throw new Exception ( __ ( "Nonce mismatch " , 'pdf-forms-for-contact-form-7 ' ) );
1222
1222
1223
1223
$ attachment_id = $ _POST [ 'file_id ' ];
1224
+ $ form = isset ( $ _POST ['wpcf7-form ' ] ) ? wp_unslash ( $ _POST ['wpcf7-form ' ] ) : null ;
1224
1225
1225
1226
$ filepath = get_attached_file ( $ attachment_id );
1226
1227
if ( !$ filepath )
@@ -1236,13 +1237,19 @@ public function wp_ajax_get_attachment_info()
1236
1237
)
1237
1238
);
1238
1239
1240
+ $ cf7_fields = $ this ->query_cf7_fields ( $ form );
1241
+
1242
+ $ unavailableNames = array ();
1243
+ foreach ( $ cf7_fields as $ cf7_field )
1244
+ $ unavailableNames [] = $ cf7_field ['name ' ];
1245
+
1246
+ $ info = $ this ->get_info ( $ attachment_id );
1247
+ $ info ['fields ' ] = $ this ->query_pdf_fields ( $ attachment_id , $ unavailableNames );
1248
+
1239
1249
$ options = array ( );
1240
1250
foreach ( self ::$ pdf_options as $ option => $ default )
1241
1251
$ options [$ option ] = $ default ;
1242
1252
1243
- $ info = $ this ->get_info ( $ attachment_id );
1244
- $ info ['fields ' ] = $ this ->query_pdf_fields ( $ attachment_id );
1245
-
1246
1253
return wp_send_json ( array (
1247
1254
'success ' => true ,
1248
1255
'attachment_id ' => $ attachment_id ,
@@ -1386,7 +1393,7 @@ private static function escape_tag_value($value)
1386
1393
* Generates CF7 field tag based on field data
1387
1394
* $tagName must already be sanitized
1388
1395
*/
1389
- private static function generate_tag ( $ field , &$ tagName )
1396
+ private static function generate_tag ( $ field , &$ tagName, $ unavailableNames = array () )
1390
1397
{
1391
1398
$ type = strval ($ field ['type ' ]);
1392
1399
@@ -1494,7 +1501,7 @@ private static function generate_tag( $field, &$tagName )
1494
1501
$ tagOptions .= 'readonly ' ;
1495
1502
}
1496
1503
1497
- $ unavailableNames = array (
1504
+ $ reservedNames = array (
1498
1505
'm ' ,'p ' ,'posts ' ,'w ' ,'cat ' ,'withcomments ' ,'withoutcomments '
1499
1506
,'s ' ,'search ' ,'exact ' ,'sentence ' ,'calendar ' ,'page ' ,'paged '
1500
1507
,'more ' ,'tb ' ,'pb ' ,'author ' ,'order ' ,'orderby ' ,'year ' ,'monthnum '
@@ -1503,6 +1510,7 @@ private static function generate_tag( $field, &$tagName )
1503
1510
,'attachment_id ' ,'subpost ' ,'subpost_id ' ,'preview ' ,'robots ' ,'taxonomy '
1504
1511
,'term ' ,'cpage ' ,'post_type ' ,'embed '
1505
1512
);
1513
+ $ unavailableNames = array_merge ( $ unavailableNames , $ reservedNames );
1506
1514
if ( array_search ( $ tagName , $ unavailableNames ) !== FALSE )
1507
1515
{
1508
1516
$ tagName .= '-0000 ' ;
@@ -1525,6 +1533,7 @@ public function wp_ajax_query_tags()
1525
1533
1526
1534
$ attachments = isset ( $ _POST ['attachments ' ] ) ? $ _POST ['attachments ' ] : null ;
1527
1535
$ all = isset ( $ _POST ['all ' ] ) ? $ _POST ['all ' ] : null ;
1536
+ $ form = isset ( $ _POST ['wpcf7-form ' ] ) ? wp_unslash ( $ _POST ['wpcf7-form ' ] ) : null ;
1528
1537
1529
1538
if ( !isset ($ attachments ) || !is_array ($ attachments ) )
1530
1539
$ attachments = array ();
@@ -1542,8 +1551,13 @@ public function wp_ajax_query_tags()
1542
1551
$ tags = __ ( "This PDF file does not appear to contain a PDF form. See https://acrobat.adobe.com/us/en/acrobat/how-to/create-fillable-pdf-forms-creator.html for more information. " , 'pdf-forms-for-contact-form-7 ' );
1543
1552
else
1544
1553
{
1545
- $ tags = "" ;
1554
+ $ cf7_fields = $ this ->query_cf7_fields ( $ form );
1555
+
1556
+ $ unavailableNames = array ();
1557
+ foreach ( $ cf7_fields as $ cf7_field )
1558
+ $ unavailableNames [] = $ cf7_field ['name ' ];
1546
1559
1560
+ $ tags = "" ;
1547
1561
foreach ( $ fields as $ attachment_id => $ fs )
1548
1562
foreach ( $ fs as $ field )
1549
1563
{
@@ -1558,13 +1572,15 @@ public function wp_ajax_query_tags()
1558
1572
$ tag_flag = "all " ;
1559
1573
1560
1574
$ tagName = self ::wpcf7_field_name_encode ( $ tag_flag , $ name );
1561
- $ generated_tag = self ::generate_tag ( $ field , $ tagName );
1575
+ $ generated_tag = self ::generate_tag ( $ field , $ tagName, $ unavailableNames );
1562
1576
1563
1577
if ( $ generated_tag === null )
1564
1578
continue ;
1565
1579
1566
1580
$ tag .= ' ' . $ generated_tag ;
1567
1581
$ tags .= $ tag . "\n\n" ;
1582
+
1583
+ $ unavailableNames [] = $ tagName ;
1568
1584
}
1569
1585
}
1570
1586
}
@@ -1587,7 +1603,7 @@ public function wp_ajax_query_tags()
1587
1603
/**
1588
1604
* Helper function used in wp-admin interface
1589
1605
*/
1590
- private function query_pdf_fields ( $ attachment_id )
1606
+ private function query_pdf_fields ( $ attachment_id, & $ unavailableNames = array () )
1591
1607
{
1592
1608
$ fields = $ this ->get_fields ( $ attachment_id );
1593
1609
foreach ( $ fields as $ id => &$ field )
@@ -1613,10 +1629,11 @@ private function query_pdf_fields( $attachment_id )
1613
1629
$ slug = sanitize_title ( $ name );
1614
1630
if ( preg_match ( '/^[a-zA-Z]$/ ' , $ slug [0 ] ) === 0 )
1615
1631
$ slug = 'f- ' .$ slug ;
1616
- $ tag_hint = self ::generate_tag ( $ field , $ slug );
1632
+ $ tag_hint = self ::generate_tag ( $ field , $ slug, $ unavailableNames );
1617
1633
$ field ['id ' ] = $ encoded_name ;
1618
1634
$ field ['tag_hint ' ] = $ tag_hint ;
1619
1635
$ field ['tag_name ' ] = $ slug ;
1636
+ $ unavailableNames [] = $ slug ;
1620
1637
}
1621
1638
1622
1639
return $ fields ;
@@ -1641,6 +1658,12 @@ public function wp_ajax_preload_data()
1641
1658
if ( ! current_user_can ( 'wpcf7_edit_contact_form ' , $ post_id ) )
1642
1659
throw new Exception ( __ ( "Permission denied " , 'pdf-forms-for-contact-form-7 ' ) );
1643
1660
1661
+ $ cf7_fields = $ this ->query_cf7_fields ( $ form );
1662
+
1663
+ $ unavailableNames = array ();
1664
+ foreach ( $ cf7_fields as $ cf7_field )
1665
+ $ unavailableNames [] = $ cf7_field ['name ' ];
1666
+
1644
1667
$ attachments = array ();
1645
1668
$ attachment_ids = array ();
1646
1669
foreach ( $ this ->post_get_all_pdfs ( $ post_id ) as $ attachment_id => $ attachment )
@@ -1650,7 +1673,7 @@ public function wp_ajax_preload_data()
1650
1673
$ options = $ attachment ['options ' ];
1651
1674
1652
1675
$ info = $ this ->get_info ( $ attachment_id );
1653
- $ info ['fields ' ] = $ this ->query_pdf_fields ( $ attachment_id );
1676
+ $ info ['fields ' ] = $ this ->query_pdf_fields ( $ attachment_id, $ unavailableNames );
1654
1677
1655
1678
$ attachments [] = array (
1656
1679
'attachment_id ' => $ attachment_id ,
@@ -1661,8 +1684,6 @@ public function wp_ajax_preload_data()
1661
1684
$ attachment_ids [] = $ attachment_id ;
1662
1685
}
1663
1686
1664
- $ cf7_fields = $ this ->query_cf7_fields ( $ form );
1665
-
1666
1687
$ mappings = self ::get_meta ( $ post_id , 'mappings ' );
1667
1688
if ( $ mappings )
1668
1689
$ mappings = json_decode ( $ mappings , true );
0 commit comments