Skip to content

Instantly share code, notes, and snippets.

Mark Wilkinson wpmark

Block or report user

Report or block wpmark

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wpmark
wpmark / wp-ajax-search-functions-hooked.php
Last active Nov 16, 2019
AJAX Search Function for Post Titles
View wp-ajax-search-functions-hooked.php
<?php
function myplugin_ajax_job_search() {
/* get the search terms entered into the search box */
$search = sanitize_text_field( $_POST[ 'search' ] );
/* run a new query including the search string */
$q = new WP_Query(
array(
'post_type' => job_post_type_name,
@wpmark
wpmark / wp-enqueue-localised-script.php
Created Oct 21, 2015
Enqueuing a localised script in WordPress
View wp-enqueue-localised-script.php
<?php
function myplugin_enqueue_scripts() {
/* hand the js for deleting uploads by ajax */
wp_enqueue_script(
'myplugin-utilities-ajax',
plugins_url( '/assets/js/nameofjsfile.js', __FILE__ ),
array( 'jquery' ),
'1.0.0',
true
@wpmark
wpmark / ajax-search.js
Created Oct 21, 2015
Code for Running an AJAX Search in WordPress
View ajax-search.js
( function( $ ) {
// hooks everything into document ready
$(document).ready( function() {
// create a function to actually fire the search
function dosearch(t) {
// do the ajax request for job search
$.ajax({
@wpmark
wpmark / gist:9d5d2395cb01a2de0179
Created Oct 8, 2014
Check If WordPress Post is Older than X Days
View gist:9d5d2395cb01a2de0179
<?php
/*******************************
* this will work in the loop
*******************************/
/* check if the posts publish date is older than 60 days */
if( strtotime( $post->post_date ) < strtotime('-60 days') ) {
/* post is older than 60 days - do something with it!! */
@wpmark
wpmark / editors-widget-menus.php
Created May 3, 2014
Allow WordPress Editors Access to Widgets and Menus
View editors-widget-menus.php
<?php
/***************************************************************
* Function pxlcore_give_edit_theme_options()
* Adds widgets and menus to editors.
***************************************************************/
function pxlcore_give_edit_theme_options( $caps ) {
/* check if the user has the edit_pages capability */
if( ! empty( $caps[ 'edit_pages' ] ) ) {
@wpmark
wpmark / gist:8fb38d36484ec1e34dbc
Created Dec 6, 2014
Output WP Front End Profile
View gist:8fb38d36484ec1e34dbc
<?php wpfep_show_profile(); ?>
@wpmark
wpmark / gist:7e38e5114ecc153f400b
Created Dec 6, 2014
Adding Your Own WP Front End Profile Tabs
View gist:7e38e5114ecc153f400b
<?php
function wpmark_add_tab( $tabs ) {
/* add our tab to the tabs array */
$tabs[] = array(
'id' => 'wpmark_tab',
'label' => 'Testing',
'tab_class' => 'testing-tab',
'content_class' => 'testing-content',
);
@wpmark
wpmark / cpt-archive-show-all-posts.php
Last active Jun 8, 2018
Pre Get Posts to Show All Posts for Custom Post Type Archive
View cpt-archive-show-all-posts.php
<?php
function wpmark_alter_team_archive_template_query( $query ) {
/* only proceed on the front end */
if( is_admin() ) {
return;
}
/* only on the person post archive for the main query */
if ( $query->is_post_type_archive( 'wpmark_person' ) && $query->is_main_query() ) {
@wpmark
wpmark / wp-remove-toplevel-admin-menu.php
Created Nov 19, 2014
WordPress Remove Top Level Admin Menu
View wp-remove-toplevel-admin-menu.php
<?php
function wpmark_remove_posts_menu_item() {
/* remove the sub menu item */
remove_menu_page(
'edit.php', // parent slug
);
}
@wpmark
wpmark / gist:8160972
Last active Sep 9, 2017
Remove WordPress admin menu items for certain users.
View gist:8160972
<?php
/* add our function to the admin meny action */
add_action( 'admin_menu', 'pxjn_remove_menus', 999 );
function pxjn_remove_menus() {
/* get the current user id */
$pxjn_current_user_id = $current_user->ID; // get the user ID
You can’t perform that action at this time.