$settings ) { foreach ( $settings as $option ) { if ( ! isset( $option['id'] ) ) { continue; } $setting_id = $option['id']; $setting_type = $option['type'] ?? ''; $default_value = ''; // When checkbox is set to true, set this to 1. if ( 'checkbox' === $setting_type ) { $default_value = isset( $option['default'] ) ? (int) (bool) $option['default'] : 0; } elseif ( isset( $option['default'] ) && in_array( $setting_type, $default_types, true ) ) { $default_value = $option['default']; } $options[ $setting_id ] = $default_value; } } /** * Filters the default settings array. * * @since 2.5.0 * * @param array $options Default settings. */ $options = apply_filters( 'tptn_settings_defaults', $options ); return $options; } /** * Get the saved settings merged with the default settings, so newly-registered settings * that are not yet present in the saved `tptn_settings` option still resolve to a value. * * @since 4.4.0 * * @return array Settings merged with defaults. */ function tptn_get_settings_with_defaults() { return array_merge( tptn_settings_defaults(), tptn_get_settings() ); } /** * Get the default option for a specific key * * @since 1.3.0 * * @param string $key Key of the option to fetch. * @return mixed */ function tptn_get_default_option( $key = '' ) { /** This filter is documented in includes/options-api.php */ $default_settings = apply_filters( 'tptn_settings_defaults', \WebberZone\Top_Ten\Admin\Settings::get_defaults() ); if ( array_key_exists( $key, $default_settings ) ) { return $default_settings[ $key ]; } else { return false; } } /** * Reset settings. * * @since 2.5.0 * * @return void */ function tptn_settings_reset() { delete_option( 'tptn_settings' ); } /** * Get registered settings types for cache key generation. * * @since 4.2.0 * * @return array Array of setting types keyed by setting ID. */ function tptn_get_registered_settings_types() { $options = array(); // Populate some default values. foreach ( \WebberZone\Top_Ten\Admin\Settings::get_registered_settings() as $tab => $settings ) { foreach ( $settings as $option ) { $options[ $option['id'] ] = $option['type']; } } /** * Filter the settings types array for cache key generation. * * @since 4.2.0 * * @param array $options Array of setting types keyed by setting ID. */ return apply_filters( 'tptn_registered_settings_types', $options ); } /** * Handles the AJAX request to search for tags in the Top 10 settings. * * @since 1.7.0 * * @return void */ function tptn_tags_search() { if ( ! isset( $_REQUEST['tax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended wp_die(); } $taxonomy = sanitize_key( $_REQUEST['tax'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tax = get_taxonomy( $taxonomy ); if ( ! empty( $taxonomy ) ) { $tax = get_taxonomy( $taxonomy ); if ( ! $tax ) { wp_die(); } if ( ! current_user_can( $tax->cap->assign_terms ) ) { wp_die(); } } $s = isset( $_REQUEST['q'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['q'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) { $s = str_replace( $comma, ',', $s ); } if ( false !== strpos( $s, ',' ) ) { $s = explode( ',', $s ); $s = $s[ count( $s ) - 1 ]; } $s = trim( $s, " \t\n\r\0\x0B" ); /** * This filter has been defined in /wp-admin/includes/ajax-actions.php */ $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s ); /* * Require $term_search_min_chars chars for matching (default: 2) * ensure it's a non-negative, non-zero integer. */ if ( ( 0 === $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) { wp_die(); } $results = get_terms( array( 'taxonomy' => $taxonomy, 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false, ) ); echo wp_json_encode( $results ); wp_die(); } add_action( 'wp_ajax_tptn_tags_search', 'tptn_tags_search' );