Skip to content

Instantly share code, notes, and snippets.

View edit-profile.php
<?php
/* Recheck if user is logged in just to be sure, this should have been done already */
if( !is_user_logged_in() ) {
wp_redirect( home_url() );
exit;
}
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {
@martijn94
martijn94 / page-edit-profile.php
Last active May 29, 2019
Page template for wp profile edit page
View page-edit-profile.php
<?php
check_page_security();
require_once('includes/update-profile.php');
?>
<?php get_header(); ?>
<?php get_template_part('parts/dashboard/user'); ?>
@martijn94
martijn94 / check-page-security.php
Created Apr 13, 2016
Simple function to check if user is logged in
View check-page-security.php
<?php
//===========================================================================
// Function to check page security
//===========================================================================
function check_page_security() {
if( !is_user_logged_in() ) {
wp_redirect( home_url() );
@martijn94
martijn94 / wp-admin-remove-support.php
Created Apr 13, 2016
Snippet to remove post editor and add a notice to a wordpress page
View wp-admin-remove-support.php
<?php
//======================================================================
// Add notice to the profile edit page
//======================================================================
add_action( 'admin_notices', 'ecs_add_post_notice' );
function ecs_add_post_notice() {
@martijn94
martijn94 / wp-admin-add-posts-state.php
Last active Jun 16, 2021
Snippet to add post state to a WordPress page
View wp-admin-add-posts-state.php
<?php
//======================================================================
// Add post state to the projects page
//======================================================================
add_filter( 'display_post_states', 'ecs_add_post_state', 10, 2 );
function ecs_add_post_state( $post_states, $post ) {
View select2-ajax-wpi-api.js
function formatResult (company) {
if (company.loading) return company.text;
var markup = "<div class='select2-result-company clearfix'>" +
"<div class='select2-result-company__meta'>" +
"<div class='select2-result-company__title'>" + company.company_name + "</div>" +
"<div class='select2-result-company__number'>" + company.company_number + "</div>" +
"</div></div>";
return markup;
@martijn94
martijn94 / wp-api-callback-function.php
Last active Jan 27, 2016
WP api callback function
View wp-api-callback-function.php
<?php
function wpc_somename_search_callback( $request_data ) {
$parameters = $request_data->get_params();
if( !isset( $parameters['keyword'] ) || empty($parameters['keyword']) )
return array( 'error' => 'no_parameter_given' );
$keyword = $parameters['keyword'];
@martijn94
martijn94 / custom-endpoint-wp-json.json
Last active Jan 26, 2016
WP json custom endpoint doc
View custom-endpoint-wp-json.json
"/somename/search":
{
"namespace": "somename",
"methods": [
"GET"
],
"endpoints": [
{
"methods": [
"GET"
@martijn94
martijn94 / register_wp_rest_api_route.php
Last active Jan 26, 2016
Register WP REST API route
View register_wp_rest_api_route.php
<?php
add_action( 'rest_api_init', 'wpc_register_wp_api_endpoints' );
function wpc_register_wp_api_endpoints() {
register_rest_route( 'somename', '/search', array(
'methods' => 'GET',
'callback' => 'wpc_somename_search_callback',
));
}