| 1 |
<?php |
| 2 |
/** |
| 3 |
* List all site pages. |
| 4 |
* |
| 5 |
* @return array List of pages in an array of the form page_id => page_title |
| 6 |
* |
| 7 |
* @param string $post_type The post type to query |
| 8 |
* |
| 9 |
* @since 3.0.0 |
| 10 |
*/ |
| 11 |
$GLOBALS['wpas_pages_static_cache'] = array(); |
| 12 |
|
| 13 |
/** |
| 14 |
* Clear pages list cache on page update, create, or delete. |
| 15 |
* |
| 16 |
* @param int $post_id |
| 17 |
* @param WP_Post $post |
| 18 |
*/ |
| 19 |
function wpas_clear_pages_list_cache( $post_id = 0, $post = null ) { |
| 20 |
if ( $post && isset( $post->post_type ) && 'page' !== $post->post_type ) { |
| 21 |
return; |
| 22 |
} |
| 23 |
delete_transient( 'wpas_pages_list_page' ); |
| 24 |
$GLOBALS['wpas_pages_static_cache'] = array(); |
| 25 |
} |
| 26 |
add_action( 'save_post_page', 'wpas_clear_pages_list_cache', 10, 2 ); |
| 27 |
add_action( 'deleted_post', 'wpas_clear_pages_list_cache', 10, 2 ); |
| 28 |
add_action( 'trashed_post', 'wpas_clear_pages_list_cache', 10, 2 ); |
| 29 |
|
| 30 |
function wpas_list_pages( $post_type = 'page' ) { |
| 31 |
|
| 32 |
if ( isset( $GLOBALS['wpas_pages_static_cache'][ $post_type ] ) ) { |
| 33 |
return $GLOBALS['wpas_pages_static_cache'][ $post_type ]; |
| 34 |
} |
| 35 |
|
| 36 |
$cache_key = 'wpas_pages_list_' . $post_type; |
| 37 |
$cached_list = get_transient( $cache_key ); |
| 38 |
|
| 39 |
if ( false !== $cached_list && is_array( $cached_list ) ) { |
| 40 |
$GLOBALS['wpas_pages_static_cache'][ $post_type ] = $cached_list; |
| 41 |
return $cached_list; |
| 42 |
} |
| 43 |
|
| 44 |
$list = array( '' => __( 'None', 'awesome-support' ) ); |
| 45 |
|
| 46 |
$args = array( |
| 47 |
'post_type' => $post_type, |
| 48 |
'post_status' => 'publish', |
| 49 |
'order' => 'DESC', |
| 50 |
'orderby' => 'page_title', |
| 51 |
'posts_per_page' => - 1, |
| 52 |
'no_found_rows' => true, |
| 53 |
'cache_results' => false, |
| 54 |
'update_post_term_cache' => false, |
| 55 |
'update_post_meta_cache' => false, |
| 56 |
|
| 57 |
); |
| 58 |
|
| 59 |
$pages = new WP_Query( $args ); |
| 60 |
|
| 61 |
if ( ! empty( $pages->posts ) ) { |
| 62 |
|
| 63 |
foreach ( $pages->posts as $page ) { |
| 64 |
$list[ $page->ID ] = $page->post_title; |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
$result = apply_filters( 'wpas_pages_list', $list ); |
| 70 |
|
| 71 |
set_transient( $cache_key, $result, DAY_IN_SECONDS ); |
| 72 |
$GLOBALS['wpas_pages_static_cache'][ $post_type ] = $result; |
| 73 |
|
| 74 |
return $result; |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Get themes list. |
| 80 |
* |
| 81 |
* @return array |
| 82 |
* @since 3.0.0 |
| 83 |
*/ |
| 84 |
function wpas_list_themes() { |
| 85 |
|
| 86 |
$dir = WPAS_PATH . 'themes/'; |
| 87 |
$themes = array(); |
| 88 |
|
| 89 |
if ( is_dir( $dir ) ) { |
| 90 |
|
| 91 |
if ( $dh = opendir( $dir ) ) { |
| 92 |
|
| 93 |
while ( ( $file = readdir( $dh ) ) !== false ) { |
| 94 |
|
| 95 |
if ( '.' != $file && '..' != $file && is_dir( $dir . $file ) ) { |
| 96 |
|
| 97 |
if ( file_exists( "$dir$file/css/style.css" ) && file_exists( "$dir$file/registration.php" ) && file_exists( "$dir$file/submission.php" ) ) { |
| 98 |
$themes[$file] = ucwords( $file ); |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
closedir( $dh ); |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
return $themes; |
| 111 |
|
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Get theme overlay list. |
| 117 |
* |
| 118 |
* Returns a list of .CSS files that can be used in place of the default style.css |
| 119 |
* |
| 120 |
* @TODO: Right now this is hardcoded but really it should read the entire |
| 121 |
* theme styles folder and return the css file list. |
| 122 |
* |
| 123 |
* @return array |
| 124 |
* @since 5.8.0 |
| 125 |
*/ |
| 126 |
function wpas_list_overlays() { |
| 127 |
|
| 128 |
$overlay['style.css'] = 'Default'; |
| 129 |
$overlay['overlay-subtle.css'] = 'Subtle'; |
| 130 |
$overlay['overlay-angle.css'] = 'Angle'; |
| 131 |
$overlay['overlay-dark.css'] = 'Dark'; |
| 132 |
$overlay['overlay-orange-blend.css'] = 'Orange Blend'; |
| 133 |
$overlay['overlay-royal-blend.css'] = 'Royal Blend'; |
| 134 |
$overlay['overlay-purple-haze.css'] = 'Purple Haze'; |
| 135 |
$overlay['overlay-green-envy.css'] = 'Green Envy'; |
| 136 |
$overlay['overlay-plain-gray.css'] = 'Plain Gray'; |
| 137 |
$overlay['overlay-basic-blue.css'] = 'Basic Blue'; |
| 138 |
$overlay['overlay-basic-green.css'] = 'Basic Green'; |
| 139 |
$overlay['overlay-basic-red.css'] = 'Basic Red'; |
| 140 |
|
| 141 |
return apply_filters('wpas_list_overlays',$overlay); |
| 142 |
|
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Get plugin settings list |
| 148 |
* |
| 149 |
* Get all plugin settings filtered. |
| 150 |
* |
| 151 |
* @since 3.3 |
| 152 |
* @return array |
| 153 |
*/ |
| 154 |
function wpas_get_settings() { |
| 155 |
|
| 156 |
// Load the file uploader settings if not already done (those settings are loaded on plugins_loaded only) |
| 157 |
if ( ! function_exists( 'wpas_addon_settings_file_upload' ) ) { |
| 158 |
require_once( WPAS_PATH . 'includes/file-uploader/settings-file-upload.php' ); |
| 159 |
} |
| 160 |
|
| 161 |
return apply_filters( 'wpas_plugin_settings', array() ); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Get the list of all options |
| 167 |
* |
| 168 |
* This function filters the settings to remove all the hierarchy and only returns |
| 169 |
* an array of options. |
| 170 |
* |
| 171 |
* @since 3.3 |
| 172 |
* @return array |
| 173 |
*/ |
| 174 |
function wpas_get_raw_settings() { |
| 175 |
|
| 176 |
$settings = wpas_get_settings(); |
| 177 |
|
| 178 |
if ( empty( $settings ) ) { |
| 179 |
return array(); |
| 180 |
} |
| 181 |
|
| 182 |
$just_options = array(); |
| 183 |
|
| 184 |
foreach ( $settings as $tab => $contents ) { |
| 185 |
|
| 186 |
if ( ! isset( $contents['options'] ) ) { |
| 187 |
continue; |
| 188 |
} |
| 189 |
|
| 190 |
foreach ( $contents['options'] as $option ) { |
| 191 |
if ( isset( $option['id'] ) && ! array_key_exists( $option['id'], $just_options ) ) { |
| 192 |
$just_options[$option['id']] = $option; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
return $just_options; |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Get all default options |
| 204 |
* |
| 205 |
* @since 3.3 |
| 206 |
* |
| 207 |
* @param string $option Optional option ID to get the default value for |
| 208 |
* |
| 209 |
* @return array |
| 210 |
*/ |
| 211 |
function get_settings_defaults( $option = '' ) { |
| 212 |
|
| 213 |
$options = wpas_get_raw_settings(); |
| 214 |
|
| 215 |
if ( ! empty( $option ) && array_key_exists( $option, $options ) ) { |
| 216 |
return $options[ $option ]['default']; |
| 217 |
} |
| 218 |
|
| 219 |
$defaults = array(); |
| 220 |
|
| 221 |
foreach ( $options as $key => $option ) { |
| 222 |
if ( isset( $options[ $key ]['default'] ) ) { |
| 223 |
$defaults[ $key ] = $options[ $key ]['default']; |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
return $defaults; |
| 228 |
|
| 229 |
} |