Skip to content

Instantly share code, notes, and snippets.

@linemoon
linemoon / remove-all-product-categories-tags.php
Created December 31, 2023 02:03 — forked from mikaelz/remove-all-product-categories-tags.php
Remove all WooCommerce product categories and tags
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag'");
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
@linemoon
linemoon / delete-all-woocommerce-products.php
Created December 31, 2023 10:20 — forked from mikaelz/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
@linemoon
linemoon / Fileupload.php
Created January 20, 2024 14:16 — forked from kirandash/Fileupload.php
WordPress File Upload using wp_handle_upload - change wordpress upload directory and change file name
require_once(ABSPATH.'wp-admin/includes/file.php');
$uploadedfile = $_FILES['csvtoimport'];
add_filter( 'upload_dir', 'wpse_183245_upload_dir' );
function wpse_183245_upload_dir( $dirs ) {
$dirs['subdir'] = '/upload';
$dirs['path'] = $dirs['basedir'] . '/upload';
@linemoon
linemoon / Translation.md
Created June 16, 2024 06:43 — forked from mehedidb/Translation.md
WordPress Translation

WordPress Default Translation Function For Language Support In Pot File.

__
_e
esc_html__
esc_html__e
esc_attr__
esc_attr__e
@linemoon
linemoon / functions.php
Created June 16, 2024 07:03 — forked from palicao/functions.php
Remove Wordpress admin submenu
<?php
//The menu-ID:s are found in wp-admin/menu.php.
function remove_submenus() {
global $submenu;
unset($submenu['index.php'][10]); // Removes 'Updates'.
unset($submenu['themes.php'][5]); // Removes 'Themes'.
unset($submenu['options-general.php'][15]); // Removes 'Writing'.
unset($submenu['options-general.php'][25]); // Removes 'Discussion'.
}
@linemoon
linemoon / wphack3.php
Created June 16, 2024 07:04 — forked from mspalex/wphack3.php
Wodpress - Remove Admin WP Logo and Submenu
<?php
// Code to remove the WP Logo and Submenu from the Admin
add_action( 'wp_before_admin_bar_render', 'remove_logo_and_submenu' );
function remove_logo_and_submenu() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('about');
$wp_admin_bar->remove_menu('wporg');
$wp_admin_bar->remove_menu('documentation');
@linemoon
linemoon / wp-capabilities
Created June 16, 2024 07:05 — forked from AlphaAlec/wp-capabilities
Restricting Capabilities in the WP Back End
function change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
//You can list all currently available roles like this...
//$roles = $wp_roles->get_names();
//print_r($roles);
@linemoon
linemoon / clean-wpAdmin-functions.php
Created June 16, 2024 07:06 — forked from pfortes/clean-wpAdmin-functions.php
Remove everything from a wordpress Admin, add this code to your functions.php and you will have a blank administration page to make it simple to your clients, just add some custom post types or edit the code to keep some of the menu items.
function remove_dashboard_widgets(){
global$wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_welcome']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
@linemoon
linemoon / hide_elementor_admin_menus_WP.php
Created June 16, 2024 07:06 — forked from loorlab/hide_elementor_admin_menus_WP.php
Hide Elementor Admin Menus - WordPress
<?php
function plt_hide_elementor_menus() {
//Hide "Elementor".
remove_menu_page('elementor');
//Hide "Elementor → Settings".
remove_submenu_page('elementor', 'elementor');
//Hide "Elementor → Role Manager".
remove_submenu_page('elementor', 'elementor-role-manager');
//Hide "Elementor → Tools".
remove_submenu_page('elementor', 'elementor-tools');
@linemoon
linemoon / cfcore.php
Created June 16, 2024 07:08 — forked from nathaningram/cfcore.php
Creating a Starter Site - Custom Functions - Core
<?php
/*
Plugin Name: Custom Core Functions
Plugin URI: https://nathaningram.com
Description: Customize the WP Core
Version: 2023.11
Author: Nathan Ingram
Author URI: https://nathaningram.com
License: GPL2
*/