appsero
1 year ago
classes
2 months ago
elementor
2 months ago
gutenberg
3 years ago
settings
2 weeks ago
templates
3 years ago
helper.php
2 years ago
notice.php
3 years ago
support.php
3 years ago
helper.php
126 lines
| 1 | <?php |
| 2 | if ( ! function_exists('pgcu_get_paged_num') ) { |
| 3 | /** |
| 4 | * Get current page number for the pagination. |
| 5 | * |
| 6 | * @since 1.0.0 |
| 7 | * |
| 8 | * @return int $paged The current page number for the pagination. |
| 9 | */ |
| 10 | function pgcu_get_paged_num() { |
| 11 | |
| 12 | global $paged; |
| 13 | |
| 14 | if (get_query_var('paged')) { |
| 15 | $paged = get_query_var('paged'); |
| 16 | } else if (get_query_var('page')) { |
| 17 | $paged = get_query_var('page'); |
| 18 | } else { |
| 19 | $paged = 1; |
| 20 | } |
| 21 | |
| 22 | return absint($paged); |
| 23 | |
| 24 | } |
| 25 | |
| 26 | } |
| 27 | |
| 28 | if ( ! function_exists('pgcu_load_dependencies') ) { |
| 29 | function pgcu_load_dependencies( $files = 'all', $directory = PGCU_INC_DIR, $ext = '.php' ) |
| 30 | { |
| 31 | if ( ! file_exists( $directory ) ) return; // vail if the directory does not exist |
| 32 | |
| 33 | switch( $files ) { |
| 34 | case is_array( $files ) && 'all' !== strtolower( $files[0] ): |
| 35 | // include one or more file looping through the $files array |
| 36 | load_some_file( $files, $directory ); |
| 37 | break; |
| 38 | case ! is_array( $files ) && 'all' !== $files: |
| 39 | //load a single file here |
| 40 | ( file_exists( $directory . $files . $ext ) ) ? require_once $directory . $files . $ext : null; |
| 41 | break; |
| 42 | case 'all' == $files || 'all' == strtolower( $files[0] ): |
| 43 | // load all php file here |
| 44 | load_all_files( $directory ); |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | return false; |
| 49 | |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( ! function_exists('load_all_files') ) { |
| 54 | function load_all_files( $dir = '', $ext = '.php' ) |
| 55 | { |
| 56 | if ( ! file_exists( $dir ) ) return; |
| 57 | foreach ( scandir( $dir ) as $file ) { |
| 58 | // require once all the files with the given ext. eg. .php |
| 59 | if ( preg_match( "/{$ext}$/i", $file ) ) { |
| 60 | require_once( $dir . $file ); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if( ! function_exists('pgcu_pagination') ) { |
| 67 | /** |
| 68 | * Prints pagination for custom post |
| 69 | * @param object|WP_Query $custom_post_query |
| 70 | * @param int $paged |
| 71 | * |
| 72 | * @return string |
| 73 | */ |
| 74 | function pgcu_pagination( $custom_post_query, $paged = 1 ) |
| 75 | { |
| 76 | $navigation = ''; |
| 77 | $largeNumber = 999999999; // we need a large number here |
| 78 | $links = paginate_links( array( |
| 79 | 'base' => str_replace( $largeNumber, '%#%', esc_url( get_pagenum_link( $largeNumber ) ) ), |
| 80 | 'format' => '?paged=%#%', |
| 81 | 'current' => max( 1, $paged ), |
| 82 | 'total' => $custom_post_query->max_num_pages, |
| 83 | 'prev_text' => apply_filters('pgcu_pagination_prev_text', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M257.5 445.1l-22.2 22.2c-9.4 9.4-24.6 9.4-33.9 0L7 273c-9.4-9.4-9.4-24.6 0-33.9L201.4 44.7c9.4-9.4 24.6-9.4 33.9 0l22.2 22.2c9.5 9.5 9.3 25-.4 34.3L136.6 216H424c13.3 0 24 10.7 24 24v32c0 13.3-10.7 24-24 24H136.6l120.5 114.8c9.8 9.3 10 24.8.4 34.3z"/></svg>'), |
| 84 | 'next_text' => apply_filters('pgcu_pagination_next_text', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z"/></svg>'), |
| 85 | ) ); |
| 86 | if( $links ) { |
| 87 | $navigation = _navigation_markup($links, 'pagination', ' '); |
| 88 | } |
| 89 | return apply_filters('pgcu_pagination', $navigation, $links, $custom_post_query, $paged); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if ( ! function_exists( 'pgcu_sanitize_array' ) ) { |
| 94 | /** |
| 95 | * It sanitize a multi-dimensional array |
| 96 | * @param array &$array The array of the data to sanitize |
| 97 | * @return mixed |
| 98 | */ |
| 99 | function pgcu_sanitize_array( &$array ) { |
| 100 | foreach ( $array as &$value ) { |
| 101 | if ( ! is_array( $value ) ) { |
| 102 | // sanitize if value is not an array |
| 103 | $value = sanitize_text_field( $value ); |
| 104 | } else { |
| 105 | // go inside this function again |
| 106 | pgcu_sanitize_array( $value ); |
| 107 | } |
| 108 | } |
| 109 | return $array; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Checks if a string is a valid JSON-encoded string. |
| 115 | * |
| 116 | * @param string $data The string to be checked for JSON encoding. |
| 117 | * |
| 118 | * @return bool Returns true if the string is a valid JSON-encoded string, false otherwise. |
| 119 | */ |
| 120 | if ( ! function_exists( 'is_json_encoded' ) ) { |
| 121 | function is_json_encoded( $data ) { |
| 122 | json_decode( $data ); |
| 123 | return (json_last_error() == JSON_ERROR_NONE); |
| 124 | } |
| 125 | } |
| 126 |