<?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 '; } } }
/** * 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 ); } }
} if ($code !== 200) { return $Resp; } // Strip all tabs, line feeds, carriage returns and spaces $html = preg_replace('/[\\t\\r\\n\\s]/', '', wp_remote_retrieve_body($response)); if (!strstr($html, '<wp_head>exists</wp_head>')) { // wp_head is missing $Resp->msg[] = __('Critical: Call to <code>wp_head();</code> is missing! It ' . 'should appear directly before <code></head></code>', PO_LANG); } if (!strstr($html, '<wp_footer>exists</wp_footer>')) { // wp_footer is missing. $Resp->msg[] = __('Critical: Call to <code>wp_footer();</code> is missing! It ' . 'should appear directly before <code></body></code>', PO_LANG); } $matches = array(); $has_shortcodes = preg_match('#<wp_shortcodes>([^\\<]*)</wp_shortcodes>#', $html, $matches); if ($has_shortcodes) { $items = $matches[1]; $Resp->shortcodes = explode(',', $items); } // Display any errors that we found. if (empty($Resp->msg)) { $Resp->okay = true; $Resp->msg[] = __('Okay: Your current theme uses <code>wp_head();</code> and ' . '<code>wp_footer();</code> correctly!', PO_LANG); } } return $Resp; } } IncPopupAddon_HeaderFooter::init();