function testDebug2() { $expected = <<<EOD <pre class='sf_box_debug'> <b>With headline:</b> Var is string with length 36: this is simple fields debug function </pre> EOD; $this->expectOutputString($expected); sf_d("this is simple fields debug function", "With headline"); }
function testDebug() { $this->expectOutputString("<pre class='sf_box_debug'>this is simple fields debug function</pre>"); sf_d("this is simple fields debug function"); }
/** * Outputs the names of the post connectors attached to the post you view + outputs the values */ function simple_fields_content_debug_output($the_content) { // we only want to appen the debug code when being used from get_the_content or the_content // but for example get_the_excerpt is also using filter the_content which leads to problems // so check that we are somewhere inside the right functions $is_inside_righ_function = FALSE; $arr_trace = debug_backtrace(); $arr_trace_count = count($arr_trace); for ($i = 0; $i < $arr_trace_count; $i++) { if (isset($arr_trace[$i]["function"]) && in_array($arr_trace[$i]["function"], array("the_content", "get_the_content"))) { $is_inside_righ_function = TRUE; break; } } if (!$is_inside_righ_function) { // Don't do the debug, since we're not in the_content return $the_content; } $output = ""; $output_all = ""; $field_count = 0; $post_connector_with_values = simple_fields_get_all_fields_and_values_for_post(get_the_ID(), "include_deleted=0"); if ($post_connector_with_values) { foreach ($post_connector_with_values["field_groups"] as $one_field_group) { if ($one_field_group["deleted"]) { continue; } $output_all .= "<div style='font-weight:bold;margin:1em 0 0 0;'>"; $str_is_repeatable = $one_field_group["repeatable"] ? __(" (Repeatable)", "simple-fields") : ""; $output_all .= sprintf(__('Fieldgroup %1$s %2$s', "simple-fields"), $one_field_group["name"], $str_is_repeatable); $output_all .= "</div>"; $str_all_group_fields = ""; foreach ($one_field_group["fields"] as $one_field) { if ($one_field["deleted"]) { continue; } $field_count++; $content = ""; $content .= "<ul style='background:#eee;padding:.5em;margin:0;display:block;'>"; $content .= "<li>Field <b>" . $one_field["name"] . "</b>"; $content .= ", type <b>" . $one_field["type"] . "</b>"; if (isset($one_field["slug"])) { $content .= ", slug <b>" . $one_field["slug"] . "</b>"; $str_all_group_fields .= $one_field["slug"] . ","; if ($one_field_group["repeatable"]) { $content .= "<br>Use <code><b>simple_fields_values('" . $one_field["slug"] . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_values($one_field["slug"])); $content .= ob_get_clean(); } else { $content .= "<br>Use <code><b>simple_fields_value('" . $one_field["slug"] . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_value($one_field["slug"])); $content .= ob_get_clean(); } } else { $content .= "<br>No slug for this field found (probably old field that has not been edited and saved)."; } $content .= "</ul>"; $output_all .= $content; } // Show example how to get all fields in one shot // But only show if field has more than one field, otherwise it's kinda not useful if (sizeof($one_field_group["fields"]) > 1) { $str_all_group_fields = preg_replace('!,$!', '', $str_all_group_fields); $output_all .= "<ul style='background:#eee;padding:.5em;margin:0;display:block;'>"; if ($one_field_group["repeatable"]) { $content = "<li>Get all fields at once: use <code><b>simple_fields_values('" . $str_all_group_fields . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_values($str_all_group_fields)); $content .= ob_get_clean(); } else { $content = "<li>Get all fields at once: use <code><b>simple_fields_value('" . $str_all_group_fields . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_value($str_all_group_fields)); $content .= ob_get_clean(); } $output_all .= $content; $output_all .= "</ul>"; } } // for each field group } if ($output_all) { $str_show_fields = __("Show fields.", "simple-fields"); $str_hide_fields = __("Hide fields.", "simple-fields"); ?> <script> window.simple_fields_post_debug_show_hide = window.simple_fields_post_debug_show_hide || function(t) { var $t = jQuery(t); var $div_wrap = $t.closest("div.simple-fields-post-debug-wrap"); var debug_content = $div_wrap.find("div.simple-fields-post-debug-content"); debug_content.toggle(); if (debug_content.is(":visible")) { $t.text("<?php echo $str_hide_fields; ?> "); } else { $t.text("<?php echo $str_show_fields; ?> "); } return false; } </script> <?php $output_all = ' <div class="simple-fields-post-debug-wrap" style="display:block;margin:0;padding:0;"> <p style="margin:0;padding:0;display:block;">This post has ' . $field_count . ' Simple Fields-fields attached. <a href="#" onclick="return simple_fields_post_debug_show_hide(this);">' . $str_show_fields . '</a></p> <div class="simple-fields-post-debug-content" style="display:none;">' . $output_all . '</div> </div> '; } // if a field has the slug caption the output will be [caption] and then it will crash with some shortcodes, so we try to fix that here $output_all = str_replace("[", "[", $output_all); $output_all = str_replace("]", "]", $output_all); return $the_content . $output_all; }
/** * Output contents for this options page */ function output_page() { do_action("simple_fields_options_print_nav_tabs", $this->slug); ?> <div class="simple-fields-debug"> <h3><?php echo __('Debug', 'simple-fields'); ?> </h3> <?php // Dropdown with debug options // Debug type. 0 = no debug, 1 = debug for admins only, 2 = debug for all $options = $this->sf->get_options(); $debug_type = isset($options["debug_type"]) ? (int) $options["debug_type"] : "0"; // capability edit_themes ?> <form action="<?php echo SIMPLE_FIELDS_FILE; ?> &action=edit-options-save&sf-options-subpage=debug" method="post"> <?php printf(' <p> <select name=debug_type> <option value=0 %1$s>%4$s</option> <option value=1 %2$s>%5$s</option> <option value=2 %3$s>%6$s</option> </select> </p> ', $debug_type === 0 ? "selected" : "", $debug_type === 1 ? "selected" : "", $debug_type === 2 ? "selected" : "", __("Don't enable debug output", "simple-fields"), __("Enable debug output for administrators", "simple-fields"), __("Enable debug output for all users", "simple-fields")); ?> <p class=description> <?php _e("Automatically append information about attached fields on posts (using filter 'the_content').", "simple-fields"); ?> </p> <p> <input class="button" type=submit value="<?php _e("Save changes", "simple-fields"); ?> "> </p> <?php wp_nonce_field("save-debug-options"); ?> </form><!-- // enable debug --> <ul> <li><a href='<?php echo SIMPLE_FIELDS_FILE; ?> &action=simple-fields-view-debug-info&sf-options-subpage=debug'><?php echo __('View debug information', 'simple-fields'); ?> </a></li> </ul> <?php // view debug information $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : ""; if ("simple-fields-view-debug-info" == $action) { echo "<h3>Post Connectors</h3>\n"; echo "<p>Called with function <code>get_post_connectors()</code>"; sf_d($this->sf->get_post_connectors()); echo "<hr>"; echo "<h3>Field Groups</h3>\n"; echo "<p>Called with function <code>get_field_groups()</code>"; sf_d($this->sf->get_field_groups()); echo "<hr>"; echo "<h3>simple_fields_post_type_defaults</h3>"; echo '<p>Called with: get_option("simple_fields_post_type_defaults")'; sf_d($this->sf->get_post_type_defaults()); } ?> </div> <?php }