Add file to media library programmatically

$file = ‘/path/to/file.png’; $filename = basename($file); $upload_file = wp_upload_bits($filename, null, file_get_contents($file)); if (!$upload_file[‘error’]) { $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_parent’ => $parent_post_id, ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, $filename), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ );…Continue reading

Net Price Display 27/03/2024

function display_custom_prices_table_inside_additional_information_tab() { global $product; if (current_user_can(‘shop_manager’) || current_user_can(‘administrator’)) { if (is_product()) { $table_content = ”; $total_profit = 0; $total_net_price = 0; $total_current_price = 0; $table_content .= “ Profit / Loss Sheet Product SKU Net Price Current Price RRP Price…Continue reading

Net Price Display 27/03/2024

function display_custom_prices_table_inside_additional_information_tab() { global $product; if (current_user_can(‘shop_manager’) || current_user_can(‘administrator’)) { if (is_product()) { $table_content = ”; $total_profit = 0; $total_net_price = 0; $total_current_price = 0; $table_content .= “ Profit / Loss Sheet Product SKU Net Price Current Price RRP Price…Continue reading

Next Day Delivery Timer 27/03/2024

function custom_countdown_timer() { date_default_timezone_set(‘Europe/London’); // Ensure the correct timezone is set // Get current day and time $current_day = date(‘w’); // 0 (for Sunday) through 6 (for Saturday) $current_hour = date(‘G’); $start_countdown = false; // Default state is to not…Continue reading

Change POSTS to NEWS in WP dashboard

// Change POSTS to News in WP dashboard add_action( ‘admin_menu’, ‘rd_change_post_menu_label’ ); add_action( ‘init’, ‘rd_change_post_object_label’ ); function rd_change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = ‘News’; $submenu[‘edit.php’][5][0] = ‘News’; $submenu[‘edit.php’][10][0] = ‘Add News’; $submenu[‘edit.php’][16][0] = ‘News Tags’; echo ”; }…Continue reading

Remove plugin deactivation

// Remove plugin deactivation function rubberduckers_disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) { if ( array_key_exists( ‘deactivate’, $actions ) && in_array( $plugin_file, array( ‘advanced-custom-fields-pro/acf.php’, ‘perfmatters/perfmatters.php’, ‘termageddon-usercentrics/termageddon-usercentrics.php’, ‘patchstack/patchstack.php’, ‘admin-menu-editor-pro/menu-editor.php’, ‘flying-press/flying-press.php’, ‘wpcode-premium/wpcode.php’ ))) unset( $actions[‘deactivate’] ); return $actions; } add_filter( ‘plugin_action_links’, ‘rubberduckers_disable_plugin_deactivation’, 10,…Continue reading

custom_realtime_find_replace

function custom_realtime_find_replace($content) { // Define your replacement rules $rules = [ // Example “SOME_KEY_001” => “SOME_VALUE”, “SOME_KEY_002” => “SOME_VALUE2”, ]; // Loop through the rules and replace content foreach ($rules as $find => $replace) { $content = str_replace($find, $replace, $content);…Continue reading

performance

add_action(‘init’, function () { remove_action(‘wp_head’, ‘wp_resource_hints’, 2, 99); }); /** * Disable emojis */ add_action(‘init’, function () { remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7); remove_action(‘admin_print_scripts’, ‘print_emoji_detection_script’); remove_action(‘wp_print_styles’, ‘print_emoji_styles’); remove_action(‘admin_print_styles’, ‘print_emoji_styles’); remove_filter(‘the_content_feed’, ‘wp_staticize_emoji’); remove_filter(‘comment_text_rss’, ‘wp_staticize_emoji’); remove_filter(‘wp_mail’, ‘wp_staticize_emoji_for_email’); add_filter(‘tiny_mce_plugins’, function ($plugins) { if (is_array($plugins)) {…Continue reading

add_custom_javascript_review_sites

function add_custom_javascript() { // Check if we’re on a single post or page if(is_singular()) { // Get the post ID of the current post or page $post_id = get_the_ID(); // Check if the custom field ‘funnel’ exists and get its…Continue reading