Code Snippets
DIVI (1)
View SnippetsJetpack (7)
View SnippetsREST API (1)
View SnippetsTags
#Google Analytics#Jetpack#Photon#REST API#Sharing#WordPressRecent Code Snippets
Add CSV to Rest Endpoints
PHP// Add custom query var to REST API function add_csv_query_var( $vars ) { $vars[] = 'csv'; return $vars; } add_filter(…
November 14, 2024
Load Custom Styles Conditionally Based on User Role
PHPfunction load_custom_styles_for_roles() { if ( current_user_can( 'administrator' ) ) { wp_enqueue_style( 'admin-styles', get_template_directory_uri() . '/css/admin-styles.css' ); } elseif ( current_user_can(…
November 14, 2024
Dynamically Change Styles Based on Query Parameters
PHPfunction load_styles_based_on_url() { if ( isset( $_GET['theme_mode'] ) && $_GET['theme_mode'] == 'dark' ) { wp_enqueue_style( 'dark-theme', get_template_directory_uri() . '/css/dark-theme.css' );…
November 14, 2024
Dynamically Add Inline Styles Based on Custom Fields or Post Meta
PHPfunction add_inline_styles_based_on_meta() { if ( is_single() ) { global $post; $custom_style = get_post_meta( $post->ID, '_custom_css', true ); if ( !…
November 14, 2024
Checking for ZScaler
PHPfunction check_zscaler_connection() { if ( isset( $_SERVER['HTTP_X_ZSCALER_CLIENT_ID'] ) ) { echo '<div class="notice notice-info"><p>User is connected via Zscaler.</p></div>'; } else…
November 14, 2024
Log and Monitor 404 Errors
PHPfunction my_plugin_log_404_errors() { if ( is_404() ) { $url = $_SERVER['REQUEST_URI']; $referer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'Direct…
November 14, 2024
Audit Database Table Size
PHPfunction my_plugin_check_db_table_sizes() { global $wpdb; // Query the database for table sizes $results = $wpdb->get_results( "SHOW TABLE STATUS", OBJECT );…
November 14, 2024
Audit Site Performance: Query Execution Time
PHPfunction my_plugin_query_execution_time() { global $wpdb; // Log query execution time if the site is in debug mode if ( defined(…
November 14, 2024
Check for Weak File Permissions
PHPfunction my_plugin_check_file_permissions() { $files = array( ABSPATH . 'wp-config.php', ABSPATH . 'wp-content/uploads/', ); foreach ( $files as $file ) {…
November 14, 2024
Log HTTP Request Headers for Security Audit
PHPfunction my_plugin_log_http_headers() { if ( is_admin() ) { $headers = getallheaders(); $log_file = ABSPATH . 'wp-content/plugins/my-plugin-http-headers.log'; $log_entry = date( 'Y-m-d…
November 14, 2024