'; echo code_profiler_display_tabs( 1 ); $error = 0; if (! function_exists('register_tick_function') ) { $error = 'register_tick_function'; } elseif (! function_exists('stream_wrapper_unregister') ) { $error = 'stream_wrapper_unregister'; } elseif (! function_exists('stream_wrapper_register') ) { $error = 'stream_wrapper_register'; } elseif (! function_exists('stream_wrapper_restore') ) { $error = 'stream_wrapper_restore'; } if (! empty( $error ) ) { printf( CODE_PROFILER_ERROR_NOTICE, sprintf( esc_html__('Your PHP configuration is missing the "%s" function. Code Profiler cannot run without it. Please contact your server administrator about this error.', 'code-profiler'), $error ) ); } if (! is_writable( CODE_PROFILER_UPLOAD_DIR ) ) { printf( CODE_PROFILER_ERROR_NOTICE, sprintf( esc_html__('The following folder is not writable: %s. Please change its permissions or ownership so that Code Profiler can write to it.', 'code-profiler'), CODE_PROFILER_UPLOAD_DIR ) ); } /** * Check and warn if the Xdebug extension is loaded. */ if ( extension_loaded('xdebug') ) { printf( CODE_PROFILER_WARNING_NOTICE, esc_html__('Warning: the PHP Xdebug extension is loaded. Consider disabling it as it can drastically impact the performance and results of Code Profiler.', 'code-profiler') ); } // Clear the log if it's too big code_profiler_clearlog(); // Clean-up temp files left in the profiles folder code_profiler_cleantmpfiles(); /** * Create temporary folder and file used to profile cron events. */ $error = code_profiler_create_tmpfile(); if ( $error ) { printf( CODE_PROFILER_ERROR_NOTICE, esc_html( $error ) ); } $home = home_url('/'); // Frontend $site = site_url('/'); // Backend // Get user login name $current_user = wp_get_current_user(); $cp_options = get_option('code-profiler'); /** * Check if we've been asked to re-run a profile. */ if (! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'rerun' && ! empty( $_REQUEST['profiles'][0] ) ) { /** * Make sure the profile exists and get its full path. */ $profile_path = code_profiler_get_profile_path( $_REQUEST['profiles'][0] ); if ( $profile_path !== false ) { $cp_data = json_decode( file_get_contents("$profile_path.summary.profile"), true ); if (! empty( $cp_data['rerun'] ) ) { $cp_options['mem'] = $cp_data['rerun']; $rerun = true; } }else { // Display why we don't want to run. wp_die( esc_html__('Missing profile ID.', 'code-profiler') ); } } // Profile's name if (! empty( $cp_options['mem']['profile'] ) ) { $profile = $cp_options['mem']['profile']; } else { $profile = code_profiler_profile_name(); } /** * Memorized options from last run. */ if ( empty( $cp_options['mem']['x_end'] ) ) { $cp_options['mem']['x_end'] = 'frontend'; } if ( empty( $cp_options['mem']['post'] ) ) { $cp_options['mem']['post'] = ''; } if ( empty( $cp_options['mem']['x_auth'] ) ) { $cp_options['mem']['x_auth'] = 'unauthenticated'; } if ( $cp_options['mem']['x_end'] == 'backend') { $cp_options['mem']['x_auth'] = 'authenticated'; } if ( empty( $cp_options['mem']['method'] ) ) { $cp_options['mem']['method'] = 'get'; } $default_theme = get_option('stylesheet'); if ( empty( $cp_options['mem']['theme'] ) ) { $cp_options['mem']['theme'] = $default_theme; } if ( empty( $cp_options['mem']['user_agent'] ) ) { $cp_options['mem']['user_agent'] = 'Firefox'; } if ( isset( $cp_options['mem']['cookies'] ) ) { // stripslashes is only needed for cookies $cookies = trim( stripslashes( json_decode( $cp_options['mem']['cookies'] ) ) ); } else { $cookies = ''; } if ( empty( $cp_options['mem']['content_type'] ) || ! in_array( $cp_options['mem']['content_type'], [ 1, 2, 3 ] ) ) { $cp_options['mem']['content_type'] = 1; } if ( isset( $cp_options['mem']['payload'] ) ) { $payload = trim( json_decode( $cp_options['mem']['payload'] ) ); } else { $payload = ''; } if ( isset( $cp_options['mem']['custom_headers'] ) ) { $custom_headers = trim( json_decode( $cp_options['mem']['custom_headers'] ) ); } else { $custom_headers = ''; } if ( isset( $cp_options['mem']['exclusions'] ) ) { $exclusions = json_decode( $cp_options['mem']['exclusions'] ); } else { $exclusions = []; } ?>
">

              


'; } else { echo ' '; } else { $value = ''; echo ' '; } else { echo ' '; } else { echo '

">

'; $disabled_button = ' disabled'; } else { echo '
/>    
window.addEventListener("load", cpjs_start_profiler);'; } // ===================================================================== // Fetch pages and posts. function code_profiler_fetch_pages( $home, $cp_options ) { $posts = ''; if ( empty( $cp_options['mem']['post'] ) ) { $cp_options['mem']['post'] = $home; } if ( $cp_options['mem']['post'] == $home ) { $pages = sprintf( '', esc_attr( $home ), esc_html__('Homepage', 'code-profiler') ); } else { $pages = sprintf( '', esc_attr( $home ), esc_html__('Homepage', 'code-profiler') ); } $args = [ 'posts_per_page' => -1, 'post_type' => ['page'], 'post_status' => 'publish', 'orderby' => 'post_name', 'order' => 'ASC' ]; $query = new WP_Query( $args ); if ( $query ) { $items = $query->posts; foreach( $items as $item ) { if ( empty( $item->post_title ) ) { $item->post_title = __('Untitled'); } $permalink = get_permalink( $item->ID ); if ( $cp_options['mem']['post'] == $permalink ) { $pages .= sprintf( '', esc_attr( $permalink ), esc_html( $item->post_title ) ); } else { $pages .= sprintf( '', esc_attr( $permalink ), esc_html( $item->post_title ) ); } } } return sprintf('%s', esc_attr__('Pages', 'code-profiler'), $pages ); } // ===================================================================== // Fetch admin pages (backend) function code_profiler_fetch_admin_pages( $home, $cp_options ) { $backend = ''; if ( empty( $cp_options['mem']['post'] ) ) { $cp_options['mem']['post'] = $home; } if (! empty( $GLOBALS[ 'menu' ] ) ) { foreach( $GLOBALS[ 'menu' ] as $menu => $value ) { if (! empty( $value[0] ) && substr( $value[2], -4 ) == '.php') { // E.g., "Comments", "Plugins" etc $value[0] = trim( preg_replace('/\s*<.+$/', '', $value[0] ) ); if ( $cp_options['mem']['post'] == "{$home}wp-admin/{$value[2]}" ) { $backend .= sprintf( '', esc_attr("{$home}wp-admin/{$value[2]}"), esc_html( $value[0] ) ); } else { $backend .= sprintf( '', esc_attr("{$home}wp-admin/{$value[2]}"), esc_html( $value[0] ) ); } } } } if ( empty( $backend ) ) { $backend = sprintf( '', esc_attr( $home ), esc_html__('Dashboard', 'code-profiler') ); } return $backend; } // ===================================================================== // Fetch scheduled tasks. function code_profiler_fetch_crontasks( $mem ) { $cron_list = ''; $wp_crons = code_profiler_get_crons(); if ( empty( $wp_crons ) ) { $cron_list = sprintf( '', esc_html__('No cron tasks found.', 'code-profiler') ); return $cron_list; } foreach( $wp_crons as $cron ) { if ( $mem == $cron ) { $selected = ' selected'; } else { $selected = ''; } $cron_list .= sprintf( "", esc_attr( $cron ), $selected, esc_html( $cron ) ); } return $cron_list; } // ===================================================================== // EOF