/** * Parses the specified content and looks for shortcodes that are not * compatible with the current PopUp loading method. * * The function does not return a value, but if incompatible shortcodes are * detected a new Admin Notification will be generated which is displayed to * the user after the page has finished loading. * * @since 4.7.0 * @param string $content */ public static function validate_shortcodes($content) { $settings = IncPopupDatabase::get_settings(); $method = isset($settings['loadingmethod']) ? $settings['loadingmethod'] : 'ajax'; // Check for specific/frequently used shortcodes. if ('footer' !== $method && preg_match('#\\[gravityforms?(\\s.*?\\]|\\])#', $content)) { lib2()->ui->admin_message(sprintf(__('You are using Gravity Forms inside this PopUp. It is best to switch to the <a href="%s">loading method</a> "Page Footer" to ensure the form works as expected.', PO_LANG), 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err'); } // General check for shortcode incompatibility switch ($method) { case 'ajax': case 'anonymous': // Check if the content contains any of the Front-Shortcodes: $check = IncPopupAddon_HeaderFooter::check(); $content = do_shortcode($content); foreach ($check->shortcodes as $code) { $match = array(); if (preg_match('#\\[' . $code . '(\\s.*?\\]|\\])#', $content, $match)) { lib2()->ui->admin_message(sprintf(__('Shortcode <code>%s</code> requires a different <a href="%s">loading method</a> to work.<br />Try "Page Footer", though sometimes the method "Custom AJAX" also works (please test the result)', PO_LANG), $match[0], 'edit.php?post_type=' . IncPopupItem::POST_TYPE . '&page=settings'), 'err'); } } break; case 'footer': case 'front': // Nothing needs to be validated here... break; default: //lib2()->ui->admin_message( 'Shortcode-Check not defined for: ' . $method ); } }
<?php global $shortcode_tags; // Theme compatibility. $theme_compat = IncPopupAddon_HeaderFooter::check(); $settings = IncPopupDatabase::get_settings(); $cur_method = $settings['loadingmethod']; // Shortcodes with restrictions. $limited = array('app_.*', '.*-form.*', '.*_form.*'); $shortcodes = array(); // Add Admin-Shortcodes to the list. foreach ($shortcode_tags as $code => $handler) { if (!isset($shortcodes[$code])) { $shortcodes[$code] = ''; } $shortcodes[$code] .= 'sc-admin '; } // Add Front-End Shortcodes to the list. foreach ($theme_compat->shortcodes as $code) { if (!isset($shortcodes[$code])) { $shortcodes[$code] = ''; } $shortcodes[$code] .= 'sc-front '; } foreach ($shortcodes as $code => $compat) { foreach ($limited as $pattern) { if (preg_match('/^' . $pattern . '$/i', $code)) { $shortcodes[$code] = $compat . 'sc-limited '; } } }