-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
62 lines (55 loc) · 1.88 KB
/
init.php
File metadata and controls
62 lines (55 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Plugin Name: Custom Query Shortcode
* Plugin URI: https://peterhebert.com/en/code/custom-query-shortcode
* Description: A powerful shortcode that enables you to query anything you want
* and display it however you like, on both pages and posts, and in widgets.
* Version: 0.6.0
* Author: Peter Hebert
* Author URI: https://peterhebert.com/
* Text Domain: custom-query-shortcode
* Domain Path: /languages
*
* @package custom-query-shortcode
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
// Load class for shortcode.
require_once __DIR__ . '/src/class-queryshortcode.php';
// Instantiate the main class.
$query_shortcode = new QueryShortcode();
// Allow shortcodes in widget areas.
add_filter( 'widget_text', 'do_shortcode' );
/**
* Return HTML attributes from an array.
*
* @param array $attributes An associative array of attribute name-value pairs.
* Example: array('class' => 'my-class', 'data-id' => '123').
* @return string HTML for attributes.
*/
function cqs_print_html_attributes( array $attributes ) {
if ( ! is_array( $attributes ) || empty( $attributes ) ) {
return '';
}
$items_output = array();
foreach ( $attributes as $name => $value ) {
// Ensure the attribute name is a string and not empty.
if ( is_string( $name ) && ! empty( $name ) ) {
// Escape the attribute value for safe output in HTML.
$items_output[] = sprintf( '%s="%s"', esc_attr( $name ), esc_attr( $value ) );
}
}
return implode( ' ', $items_output );
}
/**
* Generate a random alphanumeric string of a specified length
*
* @param integer $length The desired length of the string.
* @return string The random string.
*/
function cqs_random_string( $length = 10 ) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$shuffled = str_shuffle( $characters );
return substr( $shuffled, 0, $length );
}