Skip to content

Instantly share code, notes, and snippets.

View toleabivol's full-sized avatar
🤠
life is happening

Anatolii Bivol toleabivol

🤠
life is happening
View GitHub Profile
@byevhen2
byevhen2 / apiRequest.js
Last active October 6, 2022 15:58 — forked from phpbits/apiRequest.js
Using wp.apiRequest to access custom endpoints.
// See: wp-includes/js/api-request.js
// Returns a jqXHR object. See: https://api.jquery.com/jQuery.ajax/#jqXHR
wp.apiRequest({path: '/namespace/vendor/v1/config'})
.then(configOptions => console.log(configOptions));
// jqXHR object has method then(), but does not have methods catch() or
// finally(). Use fail() or always() instead
wp.apiRequest({path: '/namespace/vendor/v1/config'})
.done(configOptions => console.log(configOptions))
@phpbits
phpbits / apiRequest.js
Created October 3, 2018 06:42
Using wp.apiRequest to access custom endpoints.
wp.apiRequest( { path: '/phpbits/test-blocks/v1/user-roles/' } )
.then(
( obj ) => {
console.log( obj );
}
);
@tripflex
tripflex / job-filters.php
Last active February 16, 2022 10:49
Output dropdown in Job Filters/Search page for job_location (when configured as dropdown type) for WP Job Manager Field Editor
<?php
$job_locations = get_custom_field_config( 'job_location', 'options' );
if ( is_array( $job_locations ) ):
?>
<select class="" name="search_location" id="search_location">
<option value="" <?php selected( empty( $location ) || ! in_array( $location, $job_locations ) ); ?>><?php _e( 'Any Location' ); ?></option>
<?php foreach( $job_locations as $loc_val => $loc_label ): ?>
<option value="<?php echo esc_attr( $loc_val ); ?>" <?php selected( $location, $loc_val ); ?>><?php echo esc_attr( $loc_label ); ?></option>
<?php endforeach; ?>
</select>
@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active April 11, 2024 12:33
WP: Insert attachment from URL
<?php
/**
* Insert an attachment from a URL address.
*
* @param string $url The URL address.
* @param int|null $parent_post_id The parent post ID (Optional).
* @return int|false The attachment ID on success. False on failure.
*/
function wp_insert_attachment_from_url( $url, $parent_post_id = null ) {