Changes to blocks

This commit is contained in:
Jeremy Rangel
2024-12-22 15:20:12 -08:00
parent cfbb860bf9
commit f3fbe0fa32
25 changed files with 612 additions and 1035 deletions

View File

@ -1,12 +1,76 @@
<?php /**
* Function to generate random class and add dynamic padding styles
*/
function render_lcp_container( $attributes, $content ) {
if (!function_exists('lcp_random_string')) {
function lcp_random_string($length = 8, $css_compliant = false, $include_character_types = '') {
// Define character sets
$lowercase = 'abcdefghijklmnopqrstuvwxyz';
$uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$numbers = '0123456789';
$special_chars = '!@#$%^&*()_+-=[]{}|;:,.<>?';
$all_chars = $lowercase . $uppercase . $numbers . $special_chars;
// Default to using all characters if no specific types are provided
if (empty($include_character_types)) {
$include_character_types = 'all';
}
// Build the allowed character set
$char_set = '';
if ($include_character_types === 'all') {
// Include everything
$char_set = $all_chars;
} else {
// Add specific types requested
if (strpos($include_character_types, 'lowercase') !== false) {
$char_set .= $lowercase;
}
if (strpos($include_character_types, 'uppercase') !== false) {
$char_set .= $uppercase;
}
if (strpos($include_character_types, 'numbers') !== false) {
$char_set .= $numbers;
}
if (strpos($include_character_types, 'special') !== false) {
$char_set .= $special_chars;
}
}
// Ensure that the string is valid for CSS (starts with a letter and can only include letters, digits, hyphens, or underscores)
$css_char_set = $lowercase . $uppercase . $numbers . '-_';
// Random string generation logic
$random_string = '';
$first_char = '';
// If CSS compliant, start with a letter (either lowercase or uppercase)
if ($css_compliant) {
// Ensure the first character is a letter (CSS compliant start)
$first_char = $lowercase[rand(0, strlen($lowercase) - 1)];
$random_string .= $first_char;
$length--; // Decrease length by 1 as we already added the first char
}
// Fill the rest of the string with random characters from the valid set (CSS compliant)
for ($i = 0; $i < $length; $i++) {
// Use only characters that are CSS compliant (letters, digits, hyphens, or underscores)
$random_string .= $css_char_set[rand(0, strlen($css_char_set) - 1)];
}
// Return the string
return $random_string;
}
}
function render_lcp_container( $attributes, $content ) {
// Debugging: Check the passed attributes
//var_dump($attributes);
// Generate a random class name (optional, could be customized)
$random_class = 'lcp-container-' . wp_generate_password( 12, false, false );
$random_class = lcp_random_string(12,true);
// Get the padding and backgroundColor attributes
$padding = isset( $attributes['padding'] ) ? $attributes['padding'] : array();