This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Output like the var_dump() in the JS console.log() | |
*/ | |
if ( ! function_exists( 'js_console_log' ) ) { | |
function js_console_log( $x, $as_text = false ) { | |
echo '<div class="php-to-js-console-log" style="display: none!important;" data-as-text="' . esc_attr( (bool) $as_text ) . '" data-variable="' . htmlspecialchars( wp_json_encode( $x ) ) . '">' . htmlspecialchars( var_export( $x, true ) ) . '</div>'; | |
} | |
if ( function_exists( 'js_console_log' ) ) { | |
add_action( 'wp_footer', function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Load Google Map only if it needs (when we load ACF field type='google_map') | |
*/ | |
add_action( 'acf/init', function () { | |
acf_update_setting( 'google_api_key', ( get_theme_mod( 'google_maps_api' ) ?: 'YoUrLiCeNsECoDePlAcEhErE' ) ); | |
} ); | |
add_action( 'wp_enqueue_scripts', function () { | |
wp_register_script( 'google-map', 'https://maps.googleapis.com/maps/api/js?key=' . acf_get_setting( 'google_api_key' ) . '&v=3.exp', null, false, true ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove any chars except numbers | |
* '+1-012-123-45-678' => (string) '101212345678' | |
* 'user_15' => (string) '15' | |
*/ | |
function sanitize_numbers( $string ) { | |
$string = is_numeric( $string ) ? (string) $string : $string; | |
return is_string( $string ) ? preg_replace( '/\D+/', '', $string ) : ''; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------ | |
/** | |
* Convert file url to path | |
* | |
* @param string $url Link to file | |
* | |
* @return bool|mixed|string | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save JSON parsing | |
function tryParseJSON(jsonString) { | |
try { | |
var o = JSON.parse(jsonString); | |
// Handle non-exception-throwing cases: | |
// Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking, | |
// but... JSON.parse(null) returns null, and typeof null === "object", | |
// so we must check for that, too. Thankfully, null is falsey, so this suffices: | |
if (o && typeof o === "object") { | |
return o; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* !!! BE CAREFULLY !!! | |
* | |
* Will be deleted all files in the current dir! | |
* Place this PHP-script file in the target folder & run like http://site.com/some-target-folder/delete.php | |
* | |
* Author: K | |
* Version: 2.0 | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Define & change the website WP_Roles | |
* Help: https://codex.wordpress.org/Roles_and_Capabilities | |
*/ | |
class UserRoles { | |
/** Array of allowed roles (keys) with data array with 'label' text & 'caps' array. | |
* Set standard name and empty array for default WP role. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------------------------------------------------------------- | |
/** | |
* Logging to debug.log in DEBUG_LOG_DIR dir (default is the root site dir) | |
* | |
* Note: In the wp-config.php: | |
* | |
* you need define: | |
* 0) define( 'DEBUG_LOG', true ) | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a Youtube video ID from URL | |
* | |
* @link https://regex101.com/ | |
* | |
* @param string $url - target URL, like 'https://www.youtube.com/watch?v=C0DPdy98e4c' and similar | |
* | |
* @return bool|string - Youtube video ID, like 'C0DPdy98e4c', or false if no matches | |
* | |
* @author K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find an maximum integer divider. Emxample: max_int_divider(18, 4) => 3; 18/3 = 6 (integer); | |
// Author - K | |
// Version 1.01 | |
function max_int_divider( $value = null, $limit = null ) { | |
// Wrong params | |
if ( $value === null || ! is_int( $value ) || empty( $limit ) || ! is_int( $limit ) ) { | |
return false; | |
} |
NewerOlder