Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/includes/builder
File: functions.php
$post_id = isset( $post->ID ) ? $post->ID : (int) et_()->array_get( $_POST, 'current_page.id' ); // phpcs:ignore WordPress.Security.NonceVerification -- This function does not change any state, and is therefore not susceptible to CSRF.
[1500] Fix | Delete
$exclude_woo = wp_doing_ajax() || ! et_is_woocommerce_plugin_active() || 'latest' === ET_Builder_Module_Helper_Woocommerce_Modules::get_product_default();
[1501] Fix | Delete
[1502] Fix | Delete
$default_categories = array( get_term_by( 'name', 'Uncategorized', 'category' ) );
[1503] Fix | Delete
$categories = et_pb_get_post_categories( $post_id, $default_categories );
[1504] Fix | Delete
[1505] Fix | Delete
// phpcs:ignore
[1506] Fix | Delete
$block_id = et_()->array_get( $_GET, 'blockId', '' );
[1507] Fix | Delete
[1508] Fix | Delete
$current_page = array(
[1509] Fix | Delete
'url' => esc_url( $current_url ),
[1510] Fix | Delete
'permalink' => esc_url( remove_query_arg( 'et_fb', $current_url ) ),
[1511] Fix | Delete
'backendBuilderUrl' => esc_url( sprintf( admin_url( '/post.php?post=%d&action=edit' ), get_the_ID() ) ),
[1512] Fix | Delete
'id' => isset( $post->ID ) ? $post->ID : false,
[1513] Fix | Delete
'title' => esc_html( get_the_title() ),
[1514] Fix | Delete
'thumbnailUrl' => isset( $post->ID ) ? esc_url( get_the_post_thumbnail_url( $post->ID, $thumbnail_size ) ) : '',
[1515] Fix | Delete
'thumbnailId' => isset( $post->ID ) ? get_post_thumbnail_id( $post->ID ) : '',
[1516] Fix | Delete
'authorName' => esc_html( get_the_author() ),
[1517] Fix | Delete
'authorUrl' => isset( $authordata->ID ) && isset( $authordata->user_nicename ) ? esc_html( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ) : false,
[1518] Fix | Delete
// translators: post author name.
[1519] Fix | Delete
'authorUrlTitle' => sprintf( esc_html__( 'Posts by %s', 'et_builder' ), get_the_author() ),
[1520] Fix | Delete
'date' => intval( get_the_time( 'U' ) ),
[1521] Fix | Delete
'categories' => $categories,
[1522] Fix | Delete
'commentsPopup' => esc_html( $comment_count_text ),
[1523] Fix | Delete
'commentsCount' => esc_html( $comment_count ),
[1524] Fix | Delete
'comments_popup_tb' => esc_html__( '12 Comments', 'et_builder' ),
[1525] Fix | Delete
'paged' => is_front_page() ? $et_paged : $paged,
[1526] Fix | Delete
'post_modified' => isset( $post->ID ) ? esc_attr( $post->post_modified ) : '',
[1527] Fix | Delete
'lang' => get_locale(),
[1528] Fix | Delete
'blockId' => ET_GB_Block_Layout::is_layout_block_preview() ? sanitize_title( et_()->array_get( $_GET, 'blockId', '' ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification -- This function does not change any state, and is therefore not susceptible to CSRF.
[1529] Fix | Delete
'langCode' => get_locale(),
[1530] Fix | Delete
'page_layout' => $post_id ? get_post_meta( $post_id, '_et_pb_page_layout', true ) : '',
[1531] Fix | Delete
'woocommerceComponents' => $exclude_woo ? array() : et_fb_current_page_woocommerce_components(),
[1532] Fix | Delete
'woocommerceTabs' => et_builder_tb_enabled() && et_is_woocommerce_plugin_active() ?
[1533] Fix | Delete
ET_Builder_Module_Helper_Woocommerce_Modules::get_default_tab_options() : et_fb_woocommerce_tabs(),
[1534] Fix | Delete
'woocommerce' => array(
[1535] Fix | Delete
'inactive_module_notice' => esc_html__(
[1536] Fix | Delete
'WooCommerce must be active for this module to appear',
[1537] Fix | Delete
'et_builder'
[1538] Fix | Delete
),
[1539] Fix | Delete
),
[1540] Fix | Delete
);
[1541] Fix | Delete
[1542] Fix | Delete
return apply_filters( 'et_fb_current_page_params', $current_page );
[1543] Fix | Delete
}
[1544] Fix | Delete
[1545] Fix | Delete
/**
[1546] Fix | Delete
* Ajax Callback :: Process computed property.
[1547] Fix | Delete
*/
[1548] Fix | Delete
function et_pb_process_computed_property() {
[1549] Fix | Delete
if ( ! isset( $_POST['et_pb_process_computed_property_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['et_pb_process_computed_property_nonce'] ), 'et_pb_process_computed_property_nonce' ) ) {
[1550] Fix | Delete
die( -1 );
[1551] Fix | Delete
}
[1552] Fix | Delete
[1553] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[1554] Fix | Delete
die( -1 );
[1555] Fix | Delete
}
[1556] Fix | Delete
[1557] Fix | Delete
if ( ! isset( $_POST['depends_on'], $_POST['conditional_tags'], $_POST['current_page'] ) ) {
[1558] Fix | Delete
// Shouldn't even be a possibility, but...
[1559] Fix | Delete
// Since computing `__page` can exit here too, we need to json_encode the reponse.
[1560] Fix | Delete
// This is needed in case jQuery migrate is disabled (eg via plugin) otherwise the AJAX success callback
[1561] Fix | Delete
// won't be executed (because json is malformed).
[1562] Fix | Delete
die( wp_json_encode( null ) );
[1563] Fix | Delete
}
[1564] Fix | Delete
[1565] Fix | Delete
$utils = ET_Core_Data_Utils::instance();
[1566] Fix | Delete
[1567] Fix | Delete
// phpcs:disable ET.Sniffs.ValidatedSanitizedInput -- Sanitization of following arrays is done at the time of accessing an array values.
[1568] Fix | Delete
$depends_on = isset( $_POST['depends_on'] ) ? $_POST['depends_on'] : array();
[1569] Fix | Delete
$conditional_tags = isset( $_POST['conditional_tags'] ) ? $_POST['conditional_tags'] : array();
[1570] Fix | Delete
$current_page = isset( $_POST['current_page'] ) ? $_POST['current_page'] : array();
[1571] Fix | Delete
// phpcs:enable
[1572] Fix | Delete
[1573] Fix | Delete
// allowlist keys.
[1574] Fix | Delete
$conditional_tags = array_intersect_key( $conditional_tags, et_fb_conditional_tag_params() );
[1575] Fix | Delete
$current_page = array_intersect_key( $current_page, et_fb_current_page_params() );
[1576] Fix | Delete
[1577] Fix | Delete
// sanitize values.
[1578] Fix | Delete
$conditional_tags = $utils->sanitize_text_fields( $conditional_tags );
[1579] Fix | Delete
$current_page = $utils->sanitize_text_fields( $current_page );
[1580] Fix | Delete
[1581] Fix | Delete
if ( empty( $current_page['id'] ) || ! current_user_can( 'edit_post', $current_page['id'] ) ) {
[1582] Fix | Delete
die( -1 );
[1583] Fix | Delete
}
[1584] Fix | Delete
[1585] Fix | Delete
// $_POST['depends_on'] is a single dimensional assoc array created by jQuery.ajax data param, sanitize each key and value, they will both be strings
[1586] Fix | Delete
foreach ( $depends_on as $key => $value ) {
[1587] Fix | Delete
[1588] Fix | Delete
if ( et_()->includes( $value, '%' ) ) {
[1589] Fix | Delete
// `sanitize_text_fields` removes octets `%[a-f0-9]{2}` and would zap icon values / `%date`
[1590] Fix | Delete
// so we prefix octets with `_` to protected them and remove the prefix after sanitization.
[1591] Fix | Delete
$prepared_value = preg_replace( '/%([a-f0-9]{2})/', '%_$1', $value );
[1592] Fix | Delete
$sanitized_value = preg_replace( '/%_([a-f0-9]{2})/', '%$1', sanitize_text_field( $prepared_value ) );
[1593] Fix | Delete
} else {
[1594] Fix | Delete
$sanitized_value = sanitize_text_field( $value );
[1595] Fix | Delete
}
[1596] Fix | Delete
[1597] Fix | Delete
$depends_on[ sanitize_text_field( $key ) ] = $sanitized_value;
[1598] Fix | Delete
[1599] Fix | Delete
}
[1600] Fix | Delete
$module_slug = isset( $_POST['module_type'] ) ? sanitize_text_field( $_POST['module_type'] ) : '';
[1601] Fix | Delete
$post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : '';
[1602] Fix | Delete
[1603] Fix | Delete
// Since VB performance, it is introduced single ajax request for several property
[1604] Fix | Delete
// in that case, computed_property posted data can be as an array
[1605] Fix | Delete
// hence we get the raw post data value, then sanitize it afterward either as array or string.
[1606] Fix | Delete
// @phpcs:ignore ET.Sniffs.ValidatedSanitizedInput.InputNotSanitized -- Will be sanitized conditionally as string or array afterward.
[1607] Fix | Delete
$computed_property = isset( $_POST['computed_property'] ) ? $_POST['computed_property'] : '';
[1608] Fix | Delete
$computed_property = is_array( $computed_property ) ? array_map( 'sanitize_text_field', $computed_property ) : sanitize_text_field( $computed_property );
[1609] Fix | Delete
[1610] Fix | Delete
// get all fields for module.
[1611] Fix | Delete
$fields = ET_Builder_Element::get_module_fields( $post_type, $module_slug );
[1612] Fix | Delete
[1613] Fix | Delete
// make sure only valid fields are being passed through.
[1614] Fix | Delete
$depends_on = array_intersect_key( $depends_on, $fields );
[1615] Fix | Delete
[1616] Fix | Delete
if ( is_array( $computed_property ) ) {
[1617] Fix | Delete
$results = array();
[1618] Fix | Delete
[1619] Fix | Delete
foreach ( $computed_property as $property ) {
[1620] Fix | Delete
if ( ! isset( $fields[ $property ], $fields[ $property ]['computed_callback'] ) ) {
[1621] Fix | Delete
continue;
[1622] Fix | Delete
}
[1623] Fix | Delete
[1624] Fix | Delete
$callback = $fields[ $property ]['computed_callback'];
[1625] Fix | Delete
[1626] Fix | Delete
if ( is_callable( $callback ) ) {
[1627] Fix | Delete
// @phpcs:ignore Generic.PHP.ForbiddenFunctions.Found -- The callback is hard-coded in module fields configuration.
[1628] Fix | Delete
$results[ $property ] = call_user_func( $callback, $depends_on, $conditional_tags, $current_page );
[1629] Fix | Delete
}
[1630] Fix | Delete
}
[1631] Fix | Delete
[1632] Fix | Delete
if ( empty( $results ) ) {
[1633] Fix | Delete
die( -1 );
[1634] Fix | Delete
}
[1635] Fix | Delete
[1636] Fix | Delete
die( wp_json_encode( $results ) );
[1637] Fix | Delete
}
[1638] Fix | Delete
[1639] Fix | Delete
// computed property field.
[1640] Fix | Delete
$field = $fields[ $computed_property ];
[1641] Fix | Delete
[1642] Fix | Delete
$callback = $field['computed_callback'];
[1643] Fix | Delete
[1644] Fix | Delete
if ( is_callable( $callback ) ) {
[1645] Fix | Delete
// @phpcs:ignore Generic.PHP.ForbiddenFunctions.Found -- The callback is hard-coded in module fields configuration.
[1646] Fix | Delete
die( wp_json_encode( call_user_func( $callback, $depends_on, $conditional_tags, $current_page ) ) );
[1647] Fix | Delete
} else {
[1648] Fix | Delete
die( -1 );
[1649] Fix | Delete
}
[1650] Fix | Delete
}
[1651] Fix | Delete
add_action( 'wp_ajax_et_pb_process_computed_property', 'et_pb_process_computed_property' );
[1652] Fix | Delete
[1653] Fix | Delete
/**
[1654] Fix | Delete
* Process shortcode json.
[1655] Fix | Delete
*
[1656] Fix | Delete
* @param array $object Shortcodes object.
[1657] Fix | Delete
* @param array $options Options.
[1658] Fix | Delete
* @param string $library_item_type Library item type.
[1659] Fix | Delete
* @param bool $escape_content_slashes Whether escape content slashes.
[1660] Fix | Delete
*
[1661] Fix | Delete
* @return string
[1662] Fix | Delete
*/
[1663] Fix | Delete
function et_fb_process_to_shortcode( $object, $options = array(), $library_item_type = '', $escape_content_slashes = true ) {
[1664] Fix | Delete
$output = '';
[1665] Fix | Delete
$_object = array();
[1666] Fix | Delete
[1667] Fix | Delete
$default_options = array(
[1668] Fix | Delete
'force_valid_slugs' => false,
[1669] Fix | Delete
'post_type' => false,
[1670] Fix | Delete
'apply_global_presets' => false,
[1671] Fix | Delete
);
[1672] Fix | Delete
[1673] Fix | Delete
$options = wp_parse_args( $options, $default_options );
[1674] Fix | Delete
[1675] Fix | Delete
$global_presets_manager = ET_Builder_Global_Presets_Settings::instance();
[1676] Fix | Delete
[1677] Fix | Delete
// do not proceed if $object is empty.
[1678] Fix | Delete
if ( empty( $object ) ) {
[1679] Fix | Delete
return '';
[1680] Fix | Delete
}
[1681] Fix | Delete
[1682] Fix | Delete
$font_icon_fields = ! empty( $options['post_type'] ) ? ET_Builder_Element::get_font_icon_fields( $options['post_type'] ) : false;
[1683] Fix | Delete
$structure_types = ET_Builder_Element::get_structure_module_slugs();
[1684] Fix | Delete
[1685] Fix | Delete
if ( in_array( $library_item_type, array( 'module', 'row' ), true ) ) {
[1686] Fix | Delete
$excluded_elements = array();
[1687] Fix | Delete
[1688] Fix | Delete
switch ( $library_item_type ) {
[1689] Fix | Delete
case 'module':
[1690] Fix | Delete
$excluded_elements = array( 'et_pb_section', 'et_pb_row', 'et_pb_column' );
[1691] Fix | Delete
break;
[1692] Fix | Delete
case 'row':
[1693] Fix | Delete
$excluded_elements = array( 'et_pb_section' );
[1694] Fix | Delete
break;
[1695] Fix | Delete
}
[1696] Fix | Delete
[1697] Fix | Delete
foreach ( $object as $item ) {
[1698] Fix | Delete
// do not proceed if $item is empty.
[1699] Fix | Delete
if ( empty( $item ) ) {
[1700] Fix | Delete
continue;
[1701] Fix | Delete
}
[1702] Fix | Delete
[1703] Fix | Delete
while ( in_array( $item['type'], $excluded_elements, true ) ) {
[1704] Fix | Delete
$item = $item['content'][0];
[1705] Fix | Delete
}
[1706] Fix | Delete
[1707] Fix | Delete
$_object[] = $item;
[1708] Fix | Delete
}
[1709] Fix | Delete
} else {
[1710] Fix | Delete
$_object = $object;
[1711] Fix | Delete
}
[1712] Fix | Delete
[1713] Fix | Delete
if ( $options['force_valid_slugs'] ) {
[1714] Fix | Delete
// we need to supply a reasonable default post type to get a simple list of slugs,
[1715] Fix | Delete
// otherwise the function will return an array of arrays of slugs for every possible post_type.
[1716] Fix | Delete
$slug_post_type = ! empty( $options['post_type'] ) ? $options['post_type'] : 'page';
[1717] Fix | Delete
$valid_slugs = ET_Builder_Element::get_module_slugs_by_post_type( $slug_post_type );
[1718] Fix | Delete
}
[1719] Fix | Delete
[1720] Fix | Delete
foreach ( $_object as $item ) {
[1721] Fix | Delete
// do not proceed if $item is empty.
[1722] Fix | Delete
if ( empty( $item ) ) {
[1723] Fix | Delete
continue;
[1724] Fix | Delete
}
[1725] Fix | Delete
$attributes = '';
[1726] Fix | Delete
$content = '';
[1727] Fix | Delete
$type = sanitize_text_field( $item['type'] );
[1728] Fix | Delete
$type = esc_attr( $type );
[1729] Fix | Delete
[1730] Fix | Delete
// if option enabled, reject invalid slugs.
[1731] Fix | Delete
if ( $options['force_valid_slugs'] ) {
[1732] Fix | Delete
if ( ! in_array( $type, $valid_slugs, true ) ) {
[1733] Fix | Delete
continue;
[1734] Fix | Delete
}
[1735] Fix | Delete
}
[1736] Fix | Delete
[1737] Fix | Delete
if ( ! empty( $item['raw_child_content'] ) ) {
[1738] Fix | Delete
$content = stripslashes( $item['raw_child_content'] );
[1739] Fix | Delete
}
[1740] Fix | Delete
[1741] Fix | Delete
if ( $options['apply_global_presets'] ) {
[1742] Fix | Delete
$module_type = $global_presets_manager->maybe_convert_module_type( $type, $item['attrs'] );
[1743] Fix | Delete
$module_global_presets = $global_presets_manager->get_module_presets_settings( $module_type, $item['attrs'] );
[1744] Fix | Delete
$item['attrs'] = array_merge( $module_global_presets, $item['attrs'] );
[1745] Fix | Delete
}
[1746] Fix | Delete
[1747] Fix | Delete
foreach ( $item['attrs'] as $attribute => $value ) {
[1748] Fix | Delete
// ignore computed fields.
[1749] Fix | Delete
if ( '__' === substr( $attribute, 0, 2 ) ) {
[1750] Fix | Delete
continue;
[1751] Fix | Delete
}
[1752] Fix | Delete
[1753] Fix | Delete
// Sanitize attribute.
[1754] Fix | Delete
$attribute = sanitize_text_field( $attribute );
[1755] Fix | Delete
[1756] Fix | Delete
// Sanitize input properly.
[1757] Fix | Delete
if ( isset( $font_icon_fields[ $item['type'] ][ $attribute ] ) ) {
[1758] Fix | Delete
$value = esc_attr( $value );
[1759] Fix | Delete
}
[1760] Fix | Delete
[1761] Fix | Delete
// handle content.
[1762] Fix | Delete
if ( in_array( $attribute, array( 'content', 'raw_content' ), true ) ) {
[1763] Fix | Delete
// do not override the content if item has raw_child_content.
[1764] Fix | Delete
if ( empty( $item['raw_child_content'] ) ) {
[1765] Fix | Delete
$content = $value;
[1766] Fix | Delete
[1767] Fix | Delete
$content = trim( $content );
[1768] Fix | Delete
[1769] Fix | Delete
if ( ! empty( $content ) && 'content' === $attribute ) {
[1770] Fix | Delete
$content = "\n\n" . $content . "\n\n";
[1771] Fix | Delete
}
[1772] Fix | Delete
}
[1773] Fix | Delete
} else {
[1774] Fix | Delete
// Since WordPress version 5.1, any links in the content that
[1775] Fix | Delete
// has "target" attribute will be automatically added
[1776] Fix | Delete
// rel="noreferrer noopener" attribute. This attribute added
[1777] Fix | Delete
// after the shortcode processed in et_fb_process_to_shortcode
[1778] Fix | Delete
// function. This become an issue for the builder while parsing the shortcode attributes
[1779] Fix | Delete
// because the double quote that wrapping the "rel" attribute value is not encoded.
[1780] Fix | Delete
// So we need to manipulate "target" attribute here before storing the content by renaming
[1781] Fix | Delete
// is as "data-et-target-link". Later in "et_pb_fix_shortcodes" function
[1782] Fix | Delete
// we will turn it back as "target".
[1783] Fix | Delete
$value = str_replace( ' target=', ' data-et-target-link=', $value );
[1784] Fix | Delete
[1785] Fix | Delete
$is_include_attr = false;
[1786] Fix | Delete
[1787] Fix | Delete
if ( '' === $value
[1788] Fix | Delete
&& et_pb_hover_options()->get_field_base_name( $attribute ) !== $attribute
[1789] Fix | Delete
&& et_pb_hover_options()->is_enabled( et_pb_hover_options()->get_field_base_name( $attribute ), $item['attrs'] ) ) {
[1790] Fix | Delete
$is_include_attr = true;
[1791] Fix | Delete
}
[1792] Fix | Delete
[1793] Fix | Delete
if ( '' === $value
[1794] Fix | Delete
&& et_pb_responsive_options()->get_field_base_name( $attribute ) !== $attribute
[1795] Fix | Delete
&& et_pb_responsive_options()->is_enabled( et_pb_responsive_options()->get_field_base_name( $attribute ), $item['attrs'] ) ) {
[1796] Fix | Delete
$is_include_attr = true;
[1797] Fix | Delete
}
[1798] Fix | Delete
[1799] Fix | Delete
if ( '' !== $value ) {
[1800] Fix | Delete
$is_include_attr = true;
[1801] Fix | Delete
}
[1802] Fix | Delete
[1803] Fix | Delete
if ( $is_include_attr ) {
[1804] Fix | Delete
// TODO, should we check for and handle default here? probably done in FB alredy...
[1805] Fix | Delete
[1806] Fix | Delete
// Make sure double quotes are encoded, before adding values to shortcode.
[1807] Fix | Delete
$value = str_ireplace( '"', '%22', $value );
[1808] Fix | Delete
[1809] Fix | Delete
// Make sure single backslash is encoded, before adding values to Shortcode.
[1810] Fix | Delete
if ( 'breadcrumb_separator' === $attribute ) {
[1811] Fix | Delete
$value = str_ireplace( '\\', '%5c', $value );
[1812] Fix | Delete
}
[1813] Fix | Delete
[1814] Fix | Delete
// Encode backslash for custom CSS-related and json attributes.
[1815] Fix | Delete
$json_attributes = array( 'checkbox_options', 'radio_options', 'select_options' );
[1816] Fix | Delete
if ( 0 === strpos( $attribute, 'custom_css_' ) || in_array( $attribute, $json_attributes, true ) ) {
[1817] Fix | Delete
$value = str_ireplace( '\\', '%92', $value );
[1818] Fix | Delete
[1819] Fix | Delete
} elseif ( et_builder_parse_dynamic_content( $value )->is_dynamic() ) {
[1820] Fix | Delete
$value = str_replace( '\\', '%92', $value );
[1821] Fix | Delete
}
[1822] Fix | Delete
[1823] Fix | Delete
$attributes .= ' ' . esc_attr( $attribute ) . '="' . et_core_esc_previously( $value ) . '"';
[1824] Fix | Delete
}
[1825] Fix | Delete
}
[1826] Fix | Delete
}
[1827] Fix | Delete
[1828] Fix | Delete
$attributes = str_replace( array( '[', ']' ), array( '%91', '%93' ), $attributes );
[1829] Fix | Delete
[1830] Fix | Delete
// prefix sections with a fb_built attr flag.
[1831] Fix | Delete
if ( 'et_pb_section' === $type ) {
[1832] Fix | Delete
$attributes = ' fb_built="1"' . $attributes;
[1833] Fix | Delete
}
[1834] Fix | Delete
[1835] Fix | Delete
// build shortcode
[1836] Fix | Delete
// start the opening tag.
[1837] Fix | Delete
$output .= '[' . $type . $attributes;
[1838] Fix | Delete
[1839] Fix | Delete
// close the opening tag, depending on self closing.
[1840] Fix | Delete
if ( empty( $content ) && ! isset( $item['content'] ) && ! in_array( $type, $structure_types, true ) ) {
[1841] Fix | Delete
$open_tag_only = true;
[1842] Fix | Delete
$output .= ' /]';
[1843] Fix | Delete
} else {
[1844] Fix | Delete
$open_tag_only = false;
[1845] Fix | Delete
$output .= ']';
[1846] Fix | Delete
}
[1847] Fix | Delete
[1848] Fix | Delete
// if applicable, add inner content and close tag.
[1849] Fix | Delete
if ( ! $open_tag_only ) {
[1850] Fix | Delete
if ( 'et_pb_section' === $type && isset( $item['attrs'] ) && isset( $item['attrs']['fullwidth'] ) && 'on' !== $item['attrs']['fullwidth'] && isset( $item['attrs']['specialty'] ) && 'on' !== $item['attrs']['specialty'] && ( ! isset( $item['content'] ) || ! is_array( $item['content'] ) ) ) {
[1851] Fix | Delete
// insert empty row if saving empty Regular section to make it work correctly in BB.
[1852] Fix | Delete
$output .= '[et_pb_row admin_label="Row"][/et_pb_row]';
[1853] Fix | Delete
} elseif ( isset( $item['content'] ) && is_array( $item['content'] ) ) {
[1854] Fix | Delete
$output .= et_fb_process_to_shortcode( $item['content'], $options, '', $escape_content_slashes );
[1855] Fix | Delete
} else {
[1856] Fix | Delete
if ( ! empty( $content ) ) {
[1857] Fix | Delete
if ( et_is_builder_plugin_active() && in_array( $type, ET_Builder_Element::get_has_content_modules(), true ) ) {
[1858] Fix | Delete
// Wrap content in autop to avoid tagless content on FE due to content is edited on html editor and only
[1859] Fix | Delete
// have one-line without newline wrap which prevent `the_content`'s wpautop filter to properly wrap it.
[1860] Fix | Delete
$content = wpautop( $content );
[1861] Fix | Delete
}
[1862] Fix | Delete
[1863] Fix | Delete
$output .= $content;
[1864] Fix | Delete
} else {
[1865] Fix | Delete
if ( isset( $item['content'] ) ) {
[1866] Fix | Delete
$_content = $item['content'];
[1867] Fix | Delete
[1868] Fix | Delete
if ( $escape_content_slashes ) {
[1869] Fix | Delete
$_content = str_replace( '\\', '\\\\', $_content );
[1870] Fix | Delete
}
[1871] Fix | Delete
[1872] Fix | Delete
if ( et_is_builder_plugin_active() && in_array( $type, ET_Builder_Element::get_has_content_modules(), true ) ) {
[1873] Fix | Delete
// Wrap content in autop to avoid tagless content on FE due to content is edited on html editor and only
[1874] Fix | Delete
// have one-line without newline wrap which prevent `the_content`'s wpautop filter to properly wrap it.
[1875] Fix | Delete
$_content = wpautop( $_content );
[1876] Fix | Delete
}
[1877] Fix | Delete
[1878] Fix | Delete
$output .= $_content;
[1879] Fix | Delete
} else {
[1880] Fix | Delete
$output .= '';
[1881] Fix | Delete
}
[1882] Fix | Delete
}
[1883] Fix | Delete
}
[1884] Fix | Delete
[1885] Fix | Delete
// add the closing tag.
[1886] Fix | Delete
$output .= '[/' . $type . ']';
[1887] Fix | Delete
}
[1888] Fix | Delete
}
[1889] Fix | Delete
[1890] Fix | Delete
return $output;
[1891] Fix | Delete
}
[1892] Fix | Delete
[1893] Fix | Delete
/**
[1894] Fix | Delete
* Ajax Callback :: Render shortcode output.
[1895] Fix | Delete
*/
[1896] Fix | Delete
function et_fb_ajax_render_shortcode() {
[1897] Fix | Delete
if ( ! isset( $_POST['et_pb_render_shortcode_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['et_pb_render_shortcode_nonce'] ), 'et_pb_render_shortcode_nonce' ) ) {
[1898] Fix | Delete
wp_send_json_error();
[1899] Fix | Delete
}
[1900] Fix | Delete
[1901] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[1902] Fix | Delete
wp_send_json_error();
[1903] Fix | Delete
}
[1904] Fix | Delete
[1905] Fix | Delete
$utils = ET_Core_Data_Utils::instance();
[1906] Fix | Delete
[1907] Fix | Delete
global $et_pb_predefined_module_index;
[1908] Fix | Delete
[1909] Fix | Delete
$et_pb_predefined_module_index = isset( $_POST['et_fb_module_index'] ) && 'default' !== $_POST['et_fb_module_index'] ? sanitize_text_field( $_POST['et_fb_module_index'] ) : false;
[1910] Fix | Delete
[1911] Fix | Delete
$options = isset( $_POST['options'] ) ? $utils->sanitize_text_fields( $_POST['options'] ) : array(); // phpcs:ignore ET.Sniffs.ValidatedSanitizedInput -- sanitize_text_fields sanitize the options.
[1912] Fix | Delete
[1913] Fix | Delete
// enforce valid module slugs only
[1914] Fix | Delete
// shortcode slugs need to be allowlisted so as to prevent malicious shortcodes from being generated and run through do_shortcode().
[1915] Fix | Delete
$options['force_valid_slugs'] = true;
[1916] Fix | Delete
[1917] Fix | Delete
// phpcs:ignore ET.Sniffs.ValidatedSanitizedInput -- $_POST['object'] will not be stored in db.
[1918] Fix | Delete
$object = isset( $_POST['object'] ) ? $_POST['object'] : array();
[1919] Fix | Delete
[1920] Fix | Delete
// convert shortcode array to shortcode string.
[1921] Fix | Delete
$shortcode = et_fb_process_to_shortcode( $object, $options );
[1922] Fix | Delete
[1923] Fix | Delete
// take shortcode string and ensure it's properly sanitized for the purposes of this function.
[1924] Fix | Delete
$shortcode = et_pb_enforce_builder_shortcode( $shortcode );
[1925] Fix | Delete
[1926] Fix | Delete
$output = do_shortcode( $shortcode );
[1927] Fix | Delete
[1928] Fix | Delete
$styles = ET_Builder_Element::get_style();
[1929] Fix | Delete
[1930] Fix | Delete
if ( ! empty( $styles ) ) {
[1931] Fix | Delete
$output .= sprintf(
[1932] Fix | Delete
'<style type="text/css" class="et-builder-advanced-style">
[1933] Fix | Delete
%1$s
[1934] Fix | Delete
</style>',
[1935] Fix | Delete
$styles
[1936] Fix | Delete
);
[1937] Fix | Delete
}
[1938] Fix | Delete
[1939] Fix | Delete
wp_send_json_success( $output );
[1940] Fix | Delete
}
[1941] Fix | Delete
add_action( 'wp_ajax_et_fb_ajax_render_shortcode', 'et_fb_ajax_render_shortcode' );
[1942] Fix | Delete
[1943] Fix | Delete
/**
[1944] Fix | Delete
* Determine current user can save the post.
[1945] Fix | Delete
*
[1946] Fix | Delete
* @param int $post_id Post id.
[1947] Fix | Delete
* @param string $status Post status.
[1948] Fix | Delete
*
[1949] Fix | Delete
* @return bool
[1950] Fix | Delete
*/
[1951] Fix | Delete
function et_fb_current_user_can_save( $post_id, $status = '' ) {
[1952] Fix | Delete
if ( is_page( $post_id ) ) {
[1953] Fix | Delete
if ( ! current_user_can( 'edit_pages' ) ) {
[1954] Fix | Delete
return false;
[1955] Fix | Delete
}
[1956] Fix | Delete
[1957] Fix | Delete
if ( ! current_user_can( 'publish_pages' ) && 'publish' === $status ) {
[1958] Fix | Delete
return false;
[1959] Fix | Delete
}
[1960] Fix | Delete
[1961] Fix | Delete
if ( ! current_user_can( 'edit_published_pages' ) && 'publish' === get_post_status( $post_id ) ) {
[1962] Fix | Delete
return false;
[1963] Fix | Delete
}
[1964] Fix | Delete
[1965] Fix | Delete
if ( ! current_user_can( 'edit_others_pages' ) && ! current_user_can( 'edit_page', $post_id ) ) {
[1966] Fix | Delete
return false;
[1967] Fix | Delete
}
[1968] Fix | Delete
} else {
[1969] Fix | Delete
if ( ! current_user_can( 'edit_posts' ) ) {
[1970] Fix | Delete
return false;
[1971] Fix | Delete
}
[1972] Fix | Delete
[1973] Fix | Delete
if ( ! current_user_can( 'publish_posts' ) && 'publish' === $status ) {
[1974] Fix | Delete
return false;
[1975] Fix | Delete
}
[1976] Fix | Delete
[1977] Fix | Delete
if ( ! current_user_can( 'edit_published_posts' ) && 'publish' === get_post_status( $post_id ) ) {
[1978] Fix | Delete
return false;
[1979] Fix | Delete
}
[1980] Fix | Delete
[1981] Fix | Delete
if ( ! current_user_can( 'edit_others_posts' ) && ! current_user_can( 'edit_post', $post_id ) ) {
[1982] Fix | Delete
return false;
[1983] Fix | Delete
}
[1984] Fix | Delete
}
[1985] Fix | Delete
[1986] Fix | Delete
return true;
[1987] Fix | Delete
}
[1988] Fix | Delete
[1989] Fix | Delete
/**
[1990] Fix | Delete
* Ajax Callback :: Drop backup/autosave depending on exit type.
[1991] Fix | Delete
*/
[1992] Fix | Delete
function et_fb_ajax_drop_autosave() {
[1993] Fix | Delete
if ( ! isset( $_POST['et_fb_drop_autosave_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['et_fb_drop_autosave_nonce'] ), 'et_fb_drop_autosave_nonce' ) ) {
[1994] Fix | Delete
wp_send_json_error();
[1995] Fix | Delete
}
[1996] Fix | Delete
[1997] Fix | Delete
$post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
[1998] Fix | Delete
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function