Skip to content

Instantly share code, notes, and snippets.

@martijn94
martijn94 / edit-profile.php
Created November 29, 2017 19:35
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 13:40
Page template for wp profile edit page
<?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 April 13, 2016 21:04
Simple function to check if user is logged in
<?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 April 13, 2016 20:43
Snippet to remove post editor and add a notice to a wordpress page
<?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 May 2, 2023 04:43
Snippet to add post state to a WordPress page
<?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 ) {
@martijn94
martijn94 / select2-ajax-wpi-api.js
Created January 26, 2016 23:23
Select2 ajax wp api
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 January 27, 2016 19:42
WP api callback function
<?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 January 26, 2016 23:32
WP json custom endpoint doc
"/somename/search":
{
"namespace": "somename",
"methods": [
"GET"
],
"endpoints": [
{
"methods": [
"GET"
@martijn94
martijn94 / register_wp_rest_api_route.php
Last active January 26, 2016 22:55
Register WP REST API route
<?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',
));
}