Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: theme.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Theme Administration API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Remove a theme
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.8.0
[11] Fix | Delete
*
[12] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[13] Fix | Delete
*
[14] Fix | Delete
* @param string $stylesheet Stylesheet of the theme to delete.
[15] Fix | Delete
* @param string $redirect Redirect to page when complete.
[16] Fix | Delete
* @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure.
[17] Fix | Delete
* Null if filesystem credentials are required to proceed.
[18] Fix | Delete
*/
[19] Fix | Delete
function delete_theme( $stylesheet, $redirect = '' ) {
[20] Fix | Delete
global $wp_filesystem;
[21] Fix | Delete
[22] Fix | Delete
if ( empty( $stylesheet ) ) {
[23] Fix | Delete
return false;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
if ( empty( $redirect ) ) {
[27] Fix | Delete
$redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
ob_start();
[31] Fix | Delete
$credentials = request_filesystem_credentials( $redirect );
[32] Fix | Delete
$data = ob_get_clean();
[33] Fix | Delete
[34] Fix | Delete
if ( false === $credentials ) {
[35] Fix | Delete
if ( ! empty( $data ) ) {
[36] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[37] Fix | Delete
echo $data;
[38] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[39] Fix | Delete
exit;
[40] Fix | Delete
}
[41] Fix | Delete
return;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( ! WP_Filesystem( $credentials ) ) {
[45] Fix | Delete
ob_start();
[46] Fix | Delete
// Failed to connect. Error and request again.
[47] Fix | Delete
request_filesystem_credentials( $redirect, '', true );
[48] Fix | Delete
$data = ob_get_clean();
[49] Fix | Delete
[50] Fix | Delete
if ( ! empty( $data ) ) {
[51] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[52] Fix | Delete
echo $data;
[53] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[54] Fix | Delete
exit;
[55] Fix | Delete
}
[56] Fix | Delete
return;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
if ( ! is_object( $wp_filesystem ) ) {
[60] Fix | Delete
return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
[64] Fix | Delete
return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// Get the base plugin folder.
[68] Fix | Delete
$themes_dir = $wp_filesystem->wp_themes_dir();
[69] Fix | Delete
if ( empty( $themes_dir ) ) {
[70] Fix | Delete
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
$themes_dir = trailingslashit( $themes_dir );
[74] Fix | Delete
$theme_dir = trailingslashit( $themes_dir . $stylesheet );
[75] Fix | Delete
$deleted = $wp_filesystem->delete( $theme_dir, true );
[76] Fix | Delete
[77] Fix | Delete
if ( ! $deleted ) {
[78] Fix | Delete
return new WP_Error(
[79] Fix | Delete
'could_not_remove_theme',
[80] Fix | Delete
/* translators: %s: Theme name. */
[81] Fix | Delete
sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet )
[82] Fix | Delete
);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
$theme_translations = wp_get_installed_translations( 'themes' );
[86] Fix | Delete
[87] Fix | Delete
// Remove language files, silently.
[88] Fix | Delete
if ( ! empty( $theme_translations[ $stylesheet ] ) ) {
[89] Fix | Delete
$translations = $theme_translations[ $stylesheet ];
[90] Fix | Delete
[91] Fix | Delete
foreach ( $translations as $translation => $data ) {
[92] Fix | Delete
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' );
[93] Fix | Delete
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' );
[94] Fix | Delete
[95] Fix | Delete
$json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' );
[96] Fix | Delete
if ( $json_translation_files ) {
[97] Fix | Delete
array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
// Remove the theme from allowed themes on the network.
[103] Fix | Delete
if ( is_multisite() ) {
[104] Fix | Delete
WP_Theme::network_disable_theme( $stylesheet );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
// Force refresh of theme update information.
[108] Fix | Delete
delete_site_transient( 'update_themes' );
[109] Fix | Delete
[110] Fix | Delete
return true;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Gets the page templates available in this theme.
[115] Fix | Delete
*
[116] Fix | Delete
* @since 1.5.0
[117] Fix | Delete
* @since 4.7.0 Added the `$post_type` parameter.
[118] Fix | Delete
*
[119] Fix | Delete
* @param WP_Post|null $post Optional. The post being edited, provided for context.
[120] Fix | Delete
* @param string $post_type Optional. Post type to get the templates for. Default 'page'.
[121] Fix | Delete
* @return string[] Array of template file names keyed by the template header name.
[122] Fix | Delete
*/
[123] Fix | Delete
function get_page_templates( $post = null, $post_type = 'page' ) {
[124] Fix | Delete
return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Tidies a filename for url display by the theme editor.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 2.9.0
[131] Fix | Delete
* @access private
[132] Fix | Delete
*
[133] Fix | Delete
* @param string $fullpath Full path to the theme file
[134] Fix | Delete
* @param string $containingfolder Path of the theme parent folder
[135] Fix | Delete
* @return string
[136] Fix | Delete
*/
[137] Fix | Delete
function _get_template_edit_filename( $fullpath, $containingfolder ) {
[138] Fix | Delete
return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath );
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Check if there is an update for a theme available.
[143] Fix | Delete
*
[144] Fix | Delete
* Will display link, if there is an update available.
[145] Fix | Delete
*
[146] Fix | Delete
* @since 2.7.0
[147] Fix | Delete
*
[148] Fix | Delete
* @see get_theme_update_available()
[149] Fix | Delete
*
[150] Fix | Delete
* @param WP_Theme $theme Theme data object.
[151] Fix | Delete
*/
[152] Fix | Delete
function theme_update_available( $theme ) {
[153] Fix | Delete
echo get_theme_update_available( $theme );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Retrieve the update link if there is a theme update available.
[158] Fix | Delete
*
[159] Fix | Delete
* Will return a link if there is an update available.
[160] Fix | Delete
*
[161] Fix | Delete
* @since 3.8.0
[162] Fix | Delete
*
[163] Fix | Delete
* @param WP_Theme $theme WP_Theme object.
[164] Fix | Delete
* @return string|false HTML for the update link, or false if invalid info was passed.
[165] Fix | Delete
*/
[166] Fix | Delete
function get_theme_update_available( $theme ) {
[167] Fix | Delete
static $themes_update = null;
[168] Fix | Delete
[169] Fix | Delete
if ( ! current_user_can( 'update_themes' ) ) {
[170] Fix | Delete
return false;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
if ( ! isset( $themes_update ) ) {
[174] Fix | Delete
$themes_update = get_site_transient( 'update_themes' );
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
if ( ! ( $theme instanceof WP_Theme ) ) {
[178] Fix | Delete
return false;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
$stylesheet = $theme->get_stylesheet();
[182] Fix | Delete
[183] Fix | Delete
$html = '';
[184] Fix | Delete
[185] Fix | Delete
if ( isset( $themes_update->response[ $stylesheet ] ) ) {
[186] Fix | Delete
$update = $themes_update->response[ $stylesheet ];
[187] Fix | Delete
$theme_name = $theme->display( 'Name' );
[188] Fix | Delete
$details_url = add_query_arg(
[189] Fix | Delete
array(
[190] Fix | Delete
'TB_iframe' => 'true',
[191] Fix | Delete
'width' => 1024,
[192] Fix | Delete
'height' => 800,
[193] Fix | Delete
),
[194] Fix | Delete
$update['url']
[195] Fix | Delete
); // Theme browser inside WP? Replace this. Also, theme preview JS will override this on the available list.
[196] Fix | Delete
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
[197] Fix | Delete
[198] Fix | Delete
if ( ! is_multisite() ) {
[199] Fix | Delete
if ( ! current_user_can( 'update_themes' ) ) {
[200] Fix | Delete
$html = sprintf(
[201] Fix | Delete
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
[202] Fix | Delete
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>',
[203] Fix | Delete
$theme_name,
[204] Fix | Delete
esc_url( $details_url ),
[205] Fix | Delete
sprintf(
[206] Fix | Delete
'class="thickbox open-plugin-details-modal" aria-label="%s"',
[207] Fix | Delete
/* translators: 1: Theme name, 2: Version number. */
[208] Fix | Delete
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
[209] Fix | Delete
),
[210] Fix | Delete
$update['new_version']
[211] Fix | Delete
);
[212] Fix | Delete
} elseif ( empty( $update['package'] ) ) {
[213] Fix | Delete
$html = sprintf(
[214] Fix | Delete
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */
[215] Fix | Delete
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>',
[216] Fix | Delete
$theme_name,
[217] Fix | Delete
esc_url( $details_url ),
[218] Fix | Delete
sprintf(
[219] Fix | Delete
'class="thickbox open-plugin-details-modal" aria-label="%s"',
[220] Fix | Delete
/* translators: 1: Theme name, 2: Version number. */
[221] Fix | Delete
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
[222] Fix | Delete
),
[223] Fix | Delete
$update['new_version']
[224] Fix | Delete
);
[225] Fix | Delete
} else {
[226] Fix | Delete
$html = sprintf(
[227] Fix | Delete
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
[228] Fix | Delete
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>',
[229] Fix | Delete
$theme_name,
[230] Fix | Delete
esc_url( $details_url ),
[231] Fix | Delete
sprintf(
[232] Fix | Delete
'class="thickbox open-plugin-details-modal" aria-label="%s"',
[233] Fix | Delete
/* translators: 1: Theme name, 2: Version number. */
[234] Fix | Delete
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) )
[235] Fix | Delete
),
[236] Fix | Delete
$update['new_version'],
[237] Fix | Delete
$update_url,
[238] Fix | Delete
sprintf(
[239] Fix | Delete
'aria-label="%s" id="update-theme" data-slug="%s"',
[240] Fix | Delete
/* translators: %s: Theme name. */
[241] Fix | Delete
esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ),
[242] Fix | Delete
$stylesheet
[243] Fix | Delete
)
[244] Fix | Delete
);
[245] Fix | Delete
}
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
return $html;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Retrieve list of WordPress theme features (aka theme tags).
[254] Fix | Delete
*
[255] Fix | Delete
* @since 3.1.0
[256] Fix | Delete
* @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images',
[257] Fix | Delete
* 'Full Width Template', and 'Post Formats' features.
[258] Fix | Delete
* @since 3.5.0 Added 'Flexible Header' feature.
[259] Fix | Delete
* @since 3.8.0 Renamed 'Width' filter to 'Layout'.
[260] Fix | Delete
* @since 3.8.0 Renamed 'Fixed Width' and 'Flexible Width' options
[261] Fix | Delete
* to 'Fixed Layout' and 'Fluid Layout'.
[262] Fix | Delete
* @since 3.8.0 Added 'Accessibility Ready' feature and 'Responsive Layout' option.
[263] Fix | Delete
* @since 3.9.0 Combined 'Layout' and 'Columns' filters.
[264] Fix | Delete
* @since 4.6.0 Removed 'Colors' filter.
[265] Fix | Delete
* @since 4.6.0 Added 'Grid Layout' option.
[266] Fix | Delete
* Removed 'Fixed Layout', 'Fluid Layout', and 'Responsive Layout' options.
[267] Fix | Delete
* @since 4.6.0 Added 'Custom Logo' and 'Footer Widgets' features.
[268] Fix | Delete
* Removed 'Blavatar' feature.
[269] Fix | Delete
* @since 4.6.0 Added 'Blog', 'E-Commerce', 'Education', 'Entertainment', 'Food & Drink',
[270] Fix | Delete
* 'Holiday', 'News', 'Photography', and 'Portfolio' subjects.
[271] Fix | Delete
* Removed 'Photoblogging' and 'Seasonal' subjects.
[272] Fix | Delete
* @since 4.9.0 Reordered the filters from 'Layout', 'Features', 'Subject'
[273] Fix | Delete
* to 'Subject', 'Features', 'Layout'.
[274] Fix | Delete
* @since 4.9.0 Removed 'BuddyPress', 'Custom Menu', 'Flexible Header',
[275] Fix | Delete
* 'Front Page Posting', 'Microformats', 'RTL Language Support',
[276] Fix | Delete
* 'Threaded Comments', and 'Translation Ready' features.
[277] Fix | Delete
* @since 5.5.0 Added 'Block Editor Patterns', 'Block Editor Styles',
[278] Fix | Delete
* and 'Full Site Editing' features.
[279] Fix | Delete
* @since 5.5.0 Added 'Wide Blocks' layout option.
[280] Fix | Delete
*
[281] Fix | Delete
* @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true.
[282] Fix | Delete
* @return array Array of features keyed by category with translations keyed by slug.
[283] Fix | Delete
*/
[284] Fix | Delete
function get_theme_feature_list( $api = true ) {
[285] Fix | Delete
// Hard-coded list is used if API is not accessible.
[286] Fix | Delete
$features = array(
[287] Fix | Delete
[288] Fix | Delete
__( 'Subject' ) => array(
[289] Fix | Delete
'blog' => __( 'Blog' ),
[290] Fix | Delete
'e-commerce' => __( 'E-Commerce' ),
[291] Fix | Delete
'education' => __( 'Education' ),
[292] Fix | Delete
'entertainment' => __( 'Entertainment' ),
[293] Fix | Delete
'food-and-drink' => __( 'Food & Drink' ),
[294] Fix | Delete
'holiday' => __( 'Holiday' ),
[295] Fix | Delete
'news' => __( 'News' ),
[296] Fix | Delete
'photography' => __( 'Photography' ),
[297] Fix | Delete
'portfolio' => __( 'Portfolio' ),
[298] Fix | Delete
),
[299] Fix | Delete
[300] Fix | Delete
__( 'Features' ) => array(
[301] Fix | Delete
'accessibility-ready' => __( 'Accessibility Ready' ),
[302] Fix | Delete
'block-patterns' => __( 'Block Editor Patterns' ),
[303] Fix | Delete
'block-styles' => __( 'Block Editor Styles' ),
[304] Fix | Delete
'custom-background' => __( 'Custom Background' ),
[305] Fix | Delete
'custom-colors' => __( 'Custom Colors' ),
[306] Fix | Delete
'custom-header' => __( 'Custom Header' ),
[307] Fix | Delete
'custom-logo' => __( 'Custom Logo' ),
[308] Fix | Delete
'editor-style' => __( 'Editor Style' ),
[309] Fix | Delete
'featured-image-header' => __( 'Featured Image Header' ),
[310] Fix | Delete
'featured-images' => __( 'Featured Images' ),
[311] Fix | Delete
'footer-widgets' => __( 'Footer Widgets' ),
[312] Fix | Delete
'full-site-editing' => __( 'Full Site Editing' ),
[313] Fix | Delete
'full-width-template' => __( 'Full Width Template' ),
[314] Fix | Delete
'post-formats' => __( 'Post Formats' ),
[315] Fix | Delete
'sticky-post' => __( 'Sticky Post' ),
[316] Fix | Delete
'theme-options' => __( 'Theme Options' ),
[317] Fix | Delete
),
[318] Fix | Delete
[319] Fix | Delete
__( 'Layout' ) => array(
[320] Fix | Delete
'grid-layout' => __( 'Grid Layout' ),
[321] Fix | Delete
'one-column' => __( 'One Column' ),
[322] Fix | Delete
'two-columns' => __( 'Two Columns' ),
[323] Fix | Delete
'three-columns' => __( 'Three Columns' ),
[324] Fix | Delete
'four-columns' => __( 'Four Columns' ),
[325] Fix | Delete
'left-sidebar' => __( 'Left Sidebar' ),
[326] Fix | Delete
'right-sidebar' => __( 'Right Sidebar' ),
[327] Fix | Delete
'wide-blocks' => __( 'Wide Blocks' ),
[328] Fix | Delete
),
[329] Fix | Delete
[330] Fix | Delete
);
[331] Fix | Delete
[332] Fix | Delete
if ( ! $api || ! current_user_can( 'install_themes' ) ) {
[333] Fix | Delete
return $features;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$feature_list = get_site_transient( 'wporg_theme_feature_list' );
[337] Fix | Delete
if ( ! $feature_list ) {
[338] Fix | Delete
set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
if ( ! $feature_list ) {
[342] Fix | Delete
$feature_list = themes_api( 'feature_list', array() );
[343] Fix | Delete
if ( is_wp_error( $feature_list ) ) {
[344] Fix | Delete
return $features;
[345] Fix | Delete
}
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
if ( ! $feature_list ) {
[349] Fix | Delete
return $features;
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
[353] Fix | Delete
[354] Fix | Delete
$category_translations = array(
[355] Fix | Delete
'Layout' => __( 'Layout' ),
[356] Fix | Delete
'Features' => __( 'Features' ),
[357] Fix | Delete
'Subject' => __( 'Subject' ),
[358] Fix | Delete
);
[359] Fix | Delete
[360] Fix | Delete
$wporg_features = array();
[361] Fix | Delete
[362] Fix | Delete
// Loop over the wp.org canonical list and apply translations.
[363] Fix | Delete
foreach ( (array) $feature_list as $feature_category => $feature_items ) {
[364] Fix | Delete
if ( isset( $category_translations[ $feature_category ] ) ) {
[365] Fix | Delete
$feature_category = $category_translations[ $feature_category ];
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
$wporg_features[ $feature_category ] = array();
[369] Fix | Delete
[370] Fix | Delete
foreach ( $feature_items as $feature ) {
[371] Fix | Delete
if ( isset( $features[ $feature_category ][ $feature ] ) ) {
[372] Fix | Delete
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
[373] Fix | Delete
} else {
[374] Fix | Delete
$wporg_features[ $feature_category ][ $feature ] = $feature;
[375] Fix | Delete
}
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
return $wporg_features;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Retrieves theme installer pages from the WordPress.org Themes API.
[384] Fix | Delete
*
[385] Fix | Delete
* It is possible for a theme to override the Themes API result with three
[386] Fix | Delete
* filters. Assume this is for themes, which can extend on the Theme Info to
[387] Fix | Delete
* offer more choices. This is very powerful and must be used with care, when
[388] Fix | Delete
* overriding the filters.
[389] Fix | Delete
*
[390] Fix | Delete
* The first filter, {@see 'themes_api_args'}, is for the args and gives the action
[391] Fix | Delete
* as the second parameter. The hook for {@see 'themes_api_args'} must ensure that
[392] Fix | Delete
* an object is returned.
[393] Fix | Delete
*
[394] Fix | Delete
* The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org
[395] Fix | Delete
* Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list',
[396] Fix | Delete
* an object MUST be passed. If `$action` is 'hot_tags', an array should be passed.
[397] Fix | Delete
*
[398] Fix | Delete
* Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the
[399] Fix | Delete
* response object or array, depending on the `$action` type.
[400] Fix | Delete
*
[401] Fix | Delete
* Supported arguments per action:
[402] Fix | Delete
*
[403] Fix | Delete
* | Argument Name | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list' |
[404] Fix | Delete
* | -------------------| :------------: | :-----------------: | :--------: | :--------------: |
[405] Fix | Delete
* | `$slug` | No | Yes | No | No |
[406] Fix | Delete
* | `$per_page` | Yes | No | No | No |
[407] Fix | Delete
* | `$page` | Yes | No | No | No |
[408] Fix | Delete
* | `$number` | No | No | Yes | No |
[409] Fix | Delete
* | `$search` | Yes | No | No | No |
[410] Fix | Delete
* | `$tag` | Yes | No | No | No |
[411] Fix | Delete
* | `$author` | Yes | No | No | No |
[412] Fix | Delete
* | `$user` | Yes | No | No | No |
[413] Fix | Delete
* | `$browse` | Yes | No | No | No |
[414] Fix | Delete
* | `$locale` | Yes | Yes | No | No |
[415] Fix | Delete
* | `$fields` | Yes | Yes | No | No |
[416] Fix | Delete
*
[417] Fix | Delete
* @since 2.8.0
[418] Fix | Delete
*
[419] Fix | Delete
* @param string $action API action to perform: 'query_themes', 'theme_information',
[420] Fix | Delete
* 'hot_tags' or 'feature_list'.
[421] Fix | Delete
* @param array|object $args {
[422] Fix | Delete
* Optional. Array or object of arguments to serialize for the Themes API.
[423] Fix | Delete
*
[424] Fix | Delete
* @type string $slug The theme slug. Default empty.
[425] Fix | Delete
* @type int $per_page Number of themes per page. Default 24.
[426] Fix | Delete
* @type int $page Number of current page. Default 1.
[427] Fix | Delete
* @type int $number Number of tags to be queried.
[428] Fix | Delete
* @type string $search A search term. Default empty.
[429] Fix | Delete
* @type string $tag Tag to filter themes. Default empty.
[430] Fix | Delete
* @type string $author Username of an author to filter themes. Default empty.
[431] Fix | Delete
* @type string $user Username to query for their favorites. Default empty.
[432] Fix | Delete
* @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'.
[433] Fix | Delete
* @type string $locale Locale to provide context-sensitive results. Default is the value of get_locale().
[434] Fix | Delete
* @type array $fields {
[435] Fix | Delete
* Array of fields which should or should not be returned.
[436] Fix | Delete
*
[437] Fix | Delete
* @type bool $description Whether to return the theme full description. Default false.
[438] Fix | Delete
* @type bool $sections Whether to return the theme readme sections: description, installation,
[439] Fix | Delete
* FAQ, screenshots, other notes, and changelog. Default false.
[440] Fix | Delete
* @type bool $rating Whether to return the rating in percent and total number of ratings.
[441] Fix | Delete
* Default false.
[442] Fix | Delete
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default false.
[443] Fix | Delete
* @type bool $downloaded Whether to return the download count. Default false.
[444] Fix | Delete
* @type bool $downloadlink Whether to return the download link for the package. Default false.
[445] Fix | Delete
* @type bool $last_updated Whether to return the date of the last update. Default false.
[446] Fix | Delete
* @type bool $tags Whether to return the assigned tags. Default false.
[447] Fix | Delete
* @type bool $homepage Whether to return the theme homepage link. Default false.
[448] Fix | Delete
* @type bool $screenshots Whether to return the screenshots. Default false.
[449] Fix | Delete
* @type int $screenshot_count Number of screenshots to return. Default 1.
[450] Fix | Delete
* @type bool $screenshot_url Whether to return the URL of the first screenshot. Default false.
[451] Fix | Delete
* @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false.
[452] Fix | Delete
* @type bool $template Whether to return the slug of the parent theme. Default false.
[453] Fix | Delete
* @type bool $parent Whether to return the slug, name and homepage of the parent theme. Default false.
[454] Fix | Delete
* @type bool $versions Whether to return the list of all available versions. Default false.
[455] Fix | Delete
* @type bool $theme_url Whether to return theme's URL. Default false.
[456] Fix | Delete
* @type bool $extended_author Whether to return nicename or nicename and display name. Default false.
[457] Fix | Delete
* }
[458] Fix | Delete
* }
[459] Fix | Delete
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
[460] Fix | Delete
* {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article}
[461] Fix | Delete
* for more information on the make-up of possible return objects depending on the value of `$action`.
[462] Fix | Delete
*/
[463] Fix | Delete
function themes_api( $action, $args = array() ) {
[464] Fix | Delete
// Include an unmodified $wp_version.
[465] Fix | Delete
require ABSPATH . WPINC . '/version.php';
[466] Fix | Delete
[467] Fix | Delete
if ( is_array( $args ) ) {
[468] Fix | Delete
$args = (object) $args;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if ( 'query_themes' === $action ) {
[472] Fix | Delete
if ( ! isset( $args->per_page ) ) {
[473] Fix | Delete
$args->per_page = 24;
[474] Fix | Delete
}
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
if ( ! isset( $args->locale ) ) {
[478] Fix | Delete
$args->locale = get_user_locale();
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
if ( ! isset( $args->wp_version ) ) {
[482] Fix | Delete
$args->wp_version = substr( $wp_version, 0, 3 ); // x.y
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
/**
[486] Fix | Delete
* Filters arguments used to query for installer pages from the WordPress.org Themes API.
[487] Fix | Delete
*
[488] Fix | Delete
* Important: An object MUST be returned to this filter.
[489] Fix | Delete
*
[490] Fix | Delete
* @since 2.8.0
[491] Fix | Delete
*
[492] Fix | Delete
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API.
[493] Fix | Delete
* @param string $action Requested action. Likely values are 'theme_information',
[494] Fix | Delete
* 'feature_list', or 'query_themes'.
[495] Fix | Delete
*/
[496] Fix | Delete
$args = apply_filters( 'themes_api_args', $args, $action );
[497] Fix | Delete
[498] Fix | Delete
/**
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function