### Fine-Tune AI Voice with Contrast Prompt Source: https://robertdevore.com/how-to-teach-ai-to-match-your-voice/ This prompt guides AI by providing examples of generic writing and contrasting them with a desired, stronger version. It instructs the AI to analyze the differences and adapt future outputs to match the preferred style, accelerating learning through comparative feedback. ```AI Prompt “Here’s a version of this idea that feels generic. Here’s how I’d say it instead. Analyze the differences and rewrite future outputs to match my stronger version.” ``` -------------------------------- ### WordPress Plugin Initialization and AJAX Setup Source: https://robertdevore.com/introducing-the-user-login-status-plugin-for-wordpress/ This snippet demonstrates typical WordPress plugin setup, including localization and AJAX endpoint configuration. It shows how to initialize plugin data and prepare for AJAX requests. ```php admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'uls_ajax_nonce' ) ) ); } add_action( 'admin_enqueue_scripts', 'uls_enqueue_scripts' ); // Add status column to Users table function uls_add_status_column( $columns ) { $columns['user_status'] = __( 'Status', 'user-login-status' ); return $columns; } add_filter( 'manage_users_columns', 'uls_add_status_column' ); // Display status in the column function uls_display_user_status( $value, $column_name, $user_id ) { if ( 'user_status' === $column_name ) { // Logic to determine user status (e.g., check active sessions) // This would typically involve checking against stored session data or user meta. // For demonstration, let's assume a function `uls_is_user_logged_in( $user_id )` exists. $is_logged_in = uls_is_user_logged_in( $user_id ); // Placeholder function if ( $is_logged_in ) { return ''; // Green circle } else { return ''; // Red circle } } return $value; } add_filter( 'manage_users_custom_column', 'uls_display_user_status', 10, 3 ); // Add bulk action for logging out users function uls_add_bulk_logout_action( $actions ) { $actions['bulk_logout_users'] = __( 'Log Out Users', 'user-login-status' ); return $actions; } add_filter( 'bulk_actions-users', 'uls_add_bulk_logout_action' ); // Handle bulk logout action function uls_handle_bulk_logout_action( $redirect_to, $doaction, $user_ids ) { if ( 'bulk_logout_users' === $doaction ) { foreach ( $user_ids as $user_id ) { // Logic to log out the user by clearing their session tokens // Example: wp_logout_user( $user_id ); // Note: wp_logout_user is not a standard WP function, custom implementation needed. // A common approach is to delete relevant session cookies or user meta. uls_force_logout_user( $user_id ); // Placeholder function } // Redirect back with a success message $redirect_to = add_query_arg( 'users_logged_out', count( $user_ids ), $redirect_to ); } return $redirect_to; } add_filter( 'handle_bulk_actions-users', 'uls_handle_bulk_logout_action', 10, 3 ); // Placeholder function for checking login status (implementation needed) function uls_is_user_logged_in( $user_id ) { // This function should check active sessions for the user. // For example, by checking user meta for active session tokens or last login times. return false; // Default to false } // Placeholder function for forcing logout (implementation needed) function uls_force_logout_user( $user_id ) { // This function should invalidate all active sessions for the user. // This might involve deleting cookies, session tokens stored in the database, etc. // Example: delete_user_meta( $user_id, 'session_tokens' ); // If using WP's session token management } // Add message for bulk logout success function uls_admin_notice_bulk_logout( $redirect_to ) { if ( isset( $_GET['users_logged_out'] ) ) { $count = intval( $_GET['users_logged_out'] ); if ( $count > 0 ) { echo "

" . sprintf( _n( '%d user logged out.', '%d users logged out.', $count, 'user-login-status' ), $count ) . "

"; } } } add_action( 'admin_notices', 'uls_admin_notice_bulk_logout' ); ?> ``` -------------------------------- ### AI Idea Generation Prompt Source: https://robertdevore.com/how-to-build-a-content-engine-that-scales-with-you/ This prompt guides an AI to generate blog post ideas based on current trends, under-discussed topics, and timeliness. It's a starting point for content ideation. ```APIDOC Prompt: "Give me 10 blog post ideas about [topic] based on what’s trending, what’s under-discussed, and what’s timely." Purpose: Generate diverse and relevant content ideas. Input: A specific topic. Output: A list of 10 blog post ideas. Notes: Requires ruthless filtering of generated ideas. ``` -------------------------------- ### BenchPress Built-in Benchmark Examples Source: https://robertdevore.com/introducing-benchpress/ Highlights examples of built-in benchmarks provided by BenchPress, comparing performance of different PHP and WordPress operations. These include switch vs match, caching strategies, and meta retrieval methods. ```php // Example: Switch vs Match performance comparison // BenchPress includes a benchmark for this. // Example: Transient caching vs direct database querying // BenchPress tests the performance difference. // Example: Post meta retrieval with get_post_meta() vs WP_Meta_Query // BenchPress provides benchmarks for these methods. // Example: WP_Query efficiency with customizable parameters // BenchPress allows configuration of WP_Query parameters for testing. // Example: Array merge techniques // BenchPress evaluates different array merging methods. // Example: String concatenation methods // BenchPress compares performance of string building techniques. ``` -------------------------------- ### PHP Unsanitized GET Request Example Source: https://robertdevore.com/wordpress-plugin-security-is-a-joke-and-youre-the-punchline/ This PHP snippet demonstrates a basic, insecure way to handle user input directly from the $_GET superglobal. It lacks essential sanitization and escaping, making it vulnerable to cross-site scripting (XSS) and other injection attacks. This example serves to illustrate common security oversights in web development. ```php if ( isset( $_GET['user'] ) ) { $user = $_GET['user']; echo "Welcome back, $user!"; } ``` -------------------------------- ### WordPress Plugin GitHub Hosting and Packaging Guide Source: https://robertdevore.com/host-your-wordpress-plugins-on-github-and-automate-plugin-packaging/ Instructions for setting up a WordPress plugin repository on GitHub and automating the creation of distributable zip archives. ```markdown Project: /llmstxt/robertdevore-llms.txt [Robert DeVore](https://robertdevore.com) ========================================= * [Free AI Tools](https://robertdevore.com/free-ai-tools/) * [Projects](https://robertdevore.com/projects/) * [Services](#) * [MVP Website Build](https://robertdevore.com/mvp-website-build/) * [Security Audits](https://robertdevore.com/security-audits-for-wordpress/) * [Page Speed Optimization](https://robertdevore.com/page-speed-optimization/) * [Blog](https://robertdevore.com/blog/) * [Contact](https://robertdevore.com/contact/) Host Your WordPress Plugins on GitHub and Automate Plugin Packaging =================================================================== December 21, 2024 Let’s talk plugin distribution. Hosting your plugins on GitHub provides powerful benefits such as version control, collaboration, and easy sharing. But distributing your plugin as a proper `.zip` file for users can be tedious, especially when you need to exclude unnecessary files like `.git` folders, `node_modules` , and `.DS_Store` . This guide walks you through: 1. Hosting your WordPress plugins on GitHub. 2. Automating the creation of `.zip` files, saving them one level up in the main `plugins` folder. ![Let's do this - GIF](https://robertdevore.com/wp-content/uploads/2024/12/lets-do-this.webp) **Step 1: Host Your Plugin on GitHub** -------------------------------------- ### 1.1. Create a New Repository Log in to your GitHub account and create a new repository: * Go to [github.com/new](https://github.com/new). * Name your repository (e.g., `my-awesome-plugin` ). * Optionally add a description. * Set it to **Public** if you want to share the plugin or **Private** for internal use. Initialize the repository with: * A `README.md` file to describe your plugin. * A `.gitignore` file (select “WordPress” from the GitHub template list). ### 1.2. Push Your Plugin Code to GitHub If your plugin already exists locally: Open your terminal and navigate to your plugin folder: `cd /path/to/your/plugin` Initialize Git and link it to your GitHub repository: `git init git remote add origin https://github.com/your-username/my-awesome-plugin.git` Add and commit your plugin files: `git add . git commit -m "Initial commit"` Push your code to GitHub: `git branch -M main git push -u origin main` ``` -------------------------------- ### Git Commands for Plugin Distribution Source: https://robertdevore.com/host-your-wordpress-plugins-on-github-and-automate-plugin-packaging/ Essential Git commands for initializing a repository, adding files, committing changes, and pushing code to a remote origin. ```bash cd /path/to/your/plugin git init git remote add origin https://github.com/your-username/my-awesome-plugin.git git add . git commit -m "Initial commit" git branch -M main git push -u origin main ``` -------------------------------- ### Zero Cool CLI Installation Source: https://robertdevore.com/zero-cool-cli-a-hackers-terminal-from-1995/ Steps to clone the Zero Cool CLI repository, install it globally on your system, and begin using the hacker-themed terminal commands. The installer creates a symlink for global access. ```git git clone https://github.com/robertdevore/zero-cool-cli ``` ```bash cd zero-cool-cli ./install.sh ``` ```bash zero-cool zero-cool --profile ``` -------------------------------- ### Automated Deployment Pipeline with GitHub Actions Source: https://robertdevore.com/db-version-control-wordpress-plugin/ Shows how to integrate the plugin's export command into an automated deployment pipeline, such as GitHub Actions. This snippet demonstrates exporting content and committing it as part of a CI/CD process. ```bash # GitHub Actions workflow - name: Deploy Content run: | wp dbvc export git add sync/ git commit -m "Auto-export: ${{ github.sha }}" || exit 0 git push ``` -------------------------------- ### WordPress Plugin Installation Source: https://robertdevore.com/introducing-markdown-comments-for-wordpress/ Provides step-by-step instructions for installing and activating the Markdown Comments for WordPress® plugin via the WordPress admin dashboard. ```php 1. Download the plugin from the Projects page. 2. Upload it to your WordPress® site: Plugins → Add New → Upload Plugin 3. Activate it 4. Go to Settings → Discussion, and enable “Markdown Comments” ``` -------------------------------- ### Git Integration for Version Control Source: https://robertdevore.com/db-version-control-wordpress-plugin/ Illustrates the basic steps to integrate the plugin's synchronized content folder with Git for version control. This involves initializing a Git repository, adding files, committing, and pushing to a remote origin. ```git cd wp-content/plugins/db-version-control/sync/ git init git add . git commit -m "Initial content export" git remote add origin your-repo-url git push -u origin main ``` -------------------------------- ### Theme Customizer Example Code Source: https://robertdevore.com/clean-blog-free-wordpress-theme/ This entry refers to example code for WordPress theme customization, likely involving the WordPress Customizer API. Such code allows users to modify theme options like colors, layouts, and typography directly from the WordPress dashboard. The provided link points to a GitHub repository for a comprehensive example. ```APIDOC WordPress Theme Customizer API Purpose: Allows theme developers to provide a user-friendly interface for customizing theme options directly within the WordPress admin area. Key Components: - add_section(): Registers a new section in the Customizer manager. - add_setting(): Registers a setting that will be stored in the WordPress database. - add_control(): Registers a control (e.g., text input, color picker) associated with a setting. Example Usage (Conceptual): // Add a new section for 'Theme Colors' $wp_customize->add_section('colors_section', array( 'title' => __('Theme Colors', 'your-text-domain'), 'priority' => 30, )); // Add a setting for the header background color $wp_customize->add_setting('header_background_color', array( 'default' => '#ffffff', 'transport' => 'refresh', // or 'postMessage' )); // Add a color picker control for the header background color $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'header_background_color', array( 'label' => __('Header Background Color', 'your-text-domain'), 'section' => 'colors_section', 'settings' => 'header_background_color', ))); // Outputting the setting in the theme's header.php or via a callback // Example: ``` -------------------------------- ### WordPress Interactivity Setup Source: https://robertdevore.com/ JavaScript configuration for WordPress interactivity, setting the locale data and defining an AJAX URL and nonce for communication with the WordPress backend. ```javascript wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); var DocuPressRatingAjax = { "ajax_url": "https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php", "nonce": "88fcec09a5" }; var { "imports": { "@wordpress\/interactivity": "https:\/\/robertdevore.com\/wp-content\/plugins\/gutenberg\/build-module\/interactivity\/index.min.js?ver=ef3cac5f125ae4ad0adb" } } ``` -------------------------------- ### Slackedd Plugin Installation Source: https://robertdevore.com/slackedd/ Instructions for installing the Slackedd WordPress plugin. This involves uploading the plugin folder and activating it via the WordPress admin dashboard. ```WordPress 1. Upload the `slackedd` folder to the `/wp-content/plugins/` directory. 2. Activate the plugin through the `Plugins` menu in WordPress. 3. Go to `Downloads > Extensions` and customize all of the settings in Slackedd (required in order for the plugin to work). ``` -------------------------------- ### WordPress Plugin Settings and Initialization Source: https://robertdevore.com/how-i-use-textexpander-to-reuse-my-best-ai-prompts/ Configuration object for WordPress plugins, including paths for code syntax highlighting (Prism.js) and settings for Contact Form 7, AJAX requests, and Markdown help text for comments. ```JavaScript var prism_settings = {"pluginUrl":"https:\/\/robertdevore.com\/wp-content\/plugins\/code-syntax-block\/"}; var wpcf7 = { "api": { "root": "https:\/\/robertdevore.com\/wp-json\/", "namespace": "contact-form-7\/v1" }, "cached": 1 }; var fpo_ajax_object = {"ajax_url":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","nonce":"8ec8690e76"}; var markdownCommentsHelp = {"text":"You can use Markdown: **bold**, *italic*, `code`, [link](url), # headings, - lists"}; var nwAjax = {"ajaxUrl":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","security":"c6e70f5cbd"}; ``` -------------------------------- ### Check Node.js and NPM Installation Source: https://robertdevore.com/5-things-i-learned-building-my-first-gutenberg-blocks-plugin/ Verify if Node.js and NPM are installed on your system by checking their versions. This is a fundamental step before using Node.js-based development tools. ```bash node -v npm -v ``` -------------------------------- ### Prism.js Syntax Highlighting Settings Source: https://robertdevore.com/host-your-wordpress-plugins-on-github-and-automate-plugin-packaging/ Configuration object for Prism.js, a lightweight, extensible syntax highlighter. It specifies the plugin URL for loading necessary assets. ```javascript var prism_settings = {"pluginUrl":"https:\/\/robertdevore.com\/wp-content\/plugins\/code-syntax-block\/"}; ``` -------------------------------- ### WordPress Localization Setup Source: https://robertdevore.com/introducing-barcodes-for-woocommerce-free/ Initializes locale data for WordPress internationalization, specifically setting the text direction to left-to-right (ltr). This is a common setup for WordPress plugins and themes. ```javascript wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); ``` -------------------------------- ### WordPress Prefetch Configuration Source: https://robertdevore.com/articles/estimated-reading-time-example/ JSON object defining prefetching strategies for WordPress, specifying document sources and conditions for eager loading resources. ```json {"prefetch":[{"source":"document","where":{"and":[{"href_matches":"\/*"},{"not":{"href_matches":["\/wp-*.php","\/wp-admin\/*","\/wp-content\/uploads\/*","\/wp-content\/*","\/wp-content\/plugins\/*","\/wp-content\/themes\/frost\/*","\/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]} ``` -------------------------------- ### Cipher Code Example Source: https://robertdevore.com/creating-my-own-cipher-code/ An example of the generated cipher text, presented between '==== Begin Cipher ====' and '==== End Cipher ====' markers. This is the encrypted message. ```plaintext ==== Begin Cipher ==== ohiylokhbianllegheeeguonanqdkiloynobkemmwgounjunlwhcrenaiamsoeakolwulkhuhuuktiamwtolhuuakafwobizenelufakkewbuehuepzkneyauwgktuhnioakefenulldwqeeiuamoolwlhaowtmealazngaaahnngubwaown ==== End Cipher ==== ``` -------------------------------- ### WordPress JavaScript Initialization Source: https://robertdevore.com/articles/benchpress/ JavaScript code for WordPress site initialization, including skip-link functionality for accessibility and configuration objects for plugins like Contact Form 7 and AJAX handlers. ```javascript ( function() { var skipLinkTarget = document.querySelector( 'main' ), sibling, skipLinkTargetID, skipLink; // Early exit if a skip-link target can't be located. if ( ! skipLinkTarget ) { return; } /\* \* Get the site wrapper. \* The skip-link will be injected in the beginning of it. \*\/ sibling = document.querySelector( '.wp-site-blocks' ); // Early exit if the root element was not found. if ( ! sibling ) { return; } // Get the skip-link target's ID, and generate one if it doesn't exist. skipLinkTargetID = skipLinkTarget.id; if ( ! skipLinkTargetID ) { skipLinkTargetID = 'wp--skip-link--target'; skipLinkTarget.id = skipLinkTargetID; } // Create the skip link. skipLink = document.createElement( 'a' ); skipLink.classList.add( 'skip-link', 'screen-reader-text' ); skipLink.id = 'wp-skip-link'; skipLink.href = '#' + skipLinkTargetID; skipLink.innerText = 'Skip to content'; // Inject the skip link. sibling.parentElement.insertBefore( skipLink, sibling ); }() ); var wpcf7 = { "api": { "root": "https:\/\/robertdevore.com\/wp-json\/", "namespace": "contact-form-7\/v1" }, "cached": 1 }; var fpo_ajax_object = {"ajax_url":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","nonce":"01cfdf51c9"}; var nwAjax = {"ajaxUrl":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","security":"05b3bcff39"}; ``` -------------------------------- ### WordPress Localization Setup Source: https://robertdevore.com/introducing-gift-cards-for-woocommerce-free/ Initializes WordPress internationalization (i18n) with locale data, specifically setting the text direction to left-to-right (ltr). This is a common setup for WordPress plugins and themes. ```javascript wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); ``` -------------------------------- ### Install Tor and Arm Packages Source: https://robertdevore.com/run-a-tor-relay/ Installs the necessary Tor and Arm software on the Debian system using the apt package manager. This command requires user confirmation (Y/N) to proceed. ```shell apt-get install tor tor-arm ``` -------------------------------- ### WordPress Localization and AJAX Setup Source: https://robertdevore.com/devio-digital/ This JavaScript code snippet initializes WordPress localization data and sets up an AJAX object for communication with the WordPress backend. It includes the AJAX URL and a nonce for security. ```javascript var DocuPressRatingAjax = {"ajax_url":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","nonce":"06a4a516c2"}; ``` -------------------------------- ### Robots.txt Customization Example Source: https://robertdevore.com/articles/seo-for-wordpress/ Provides an example of custom rules that can be entered into the 'Custom Robots.txt' field within the plugin's advanced settings to control search engine crawling. ```text User-agent: * Disallow: /wp-admin/ Allow: /wp-admin/admin-ajax.php ``` -------------------------------- ### WordPress Interactivity and AJAX Setup Source: https://robertdevore.com/chapter/00/ JavaScript code for setting locale data, configuring AJAX requests for WordPress, and importing interactivity modules. ```javascript wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); var DocuPressRatingAjax = {"ajax_url":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","nonce":"06a4a516c2"}; {"imports":{"@wordpress\/interactivity":"https:\/\/robertdevore.com\/wp-content\/plugins\/gutenberg\/build-module\/interactivity\/index.min.js?ver=ef3cac5f125ae4ad0adb"}} ``` -------------------------------- ### WordPress Interactivity Setup Source: https://robertdevore.com/grateful-to-see-21-of-my-wordpress-plugins-live-on-at-webdevstudios/ Initializes WordPress localization data and sets the text direction for the site's interactivity features. This snippet is part of the Gutenberg editor's interactivity setup. ```javascript var DocuPressRatingAjax = {"ajax_url":"https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php","nonce":"06a4a516c2"}; wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); ``` -------------------------------- ### WordPress Interactivity and Localization Setup Source: https://robertdevore.com/host-your-wordpress-plugins-on-github-and-automate-plugin-packaging/ JavaScript code for setting WordPress locale data and initializing an AJAX object for plugin interactions. ```javascript var DocuPressRatingAjax = { "ajax_url": "https:\/\/robertdevore.com\/wp-admin\/admin-ajax.php", "nonce": "88fcec09a5" }; wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } ); ``` ```javascript {"imports":{"@wordpress\/interactivity":"https:\/\/robertdevore.com\/wp-content\/plugins\/gutenberg\/build-module\/interactivity\/index.min.js?ver=ef3cac5f125ae4ad0adb"}} ``` -------------------------------- ### Composer Installation for WPCom Check Source: https://robertdevore.com/how-to-stop-your-plugins-themes-from-being-used-on-wordpress-com-hosting/ Instructions on how to install the WPCom Check utility using Composer, a dependency manager for PHP. This command adds the package to your project, making the `WPComPluginHandler` class available for use. ```bash composer require robertdevore/wpcom-check ``` -------------------------------- ### Automate WordPress Plugin Zipping with GitHub Actions Source: https://robertdevore.com/host-your-wordpress-plugins-on-github-and-automate-plugin-packaging/ This snippet demonstrates a GitHub Actions workflow for automating the creation of a zip archive for a WordPress plugin. It typically involves checking out the code, creating the zip file, and attaching it to a GitHub release. This approach is useful for plugins without complex build steps. ```YAML # Example workflow structure for automating plugin zipping # This is a conceptual representation based on discussion # Actual code would be in a .github/workflows/*.yml file name: Release Plugin Zip on: push: # Or on release creation tags: - 'v*.*.* jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Get Plugin Name id: get_plugin_name run: echo "::set-output name=plugin_name::$(basename $(pwd))" - name: Create plugin zip run: | PLUGIN_NAME=${{ steps.get_plugin_name.outputs.plugin_name }} ZIP_FILE="${{ env.GITHUB_REF_NAME }}-${{ steps.get_plugin_name.outputs.plugin_name }}.zip" # Exclude unnecessary files/folders like .git, .github, etc. # The exact command might vary based on plugin structure and desired exclusions zip -r $ZIP_FILE . -x "*.git*" "*.github*" "*.DS_Store" "*.travis.yml" "*.travis.yml" "README.md" "LICENSE" echo "::set-output name=zip_file_path::${ZIP_FILE}" - name: Upload artifact uses: actions/upload-artifact@v3 with: name: plugin-zip path: ${{ steps.create_plugin_zip.outputs.zip_file_path }} # Further steps would typically upload this artifact to a release ```