Patrick Wilson Official Website

Link Exchange WP Documentation

Plugin's Main File free-link-exchange.php

Key Features and Functionalities

1. Link Exchange Forms

  • Paid Premium Links: Enables the exchange of paid premium links via PayPal.
  • Reciprocal Links: Facilitates the exchange of reciprocal links, stored in the database.

2. Admin Dashboard Operations

  • Link Management: Allows the admin to approve, reject, or delete submitted links.
  • Payment Integration: Admin inserts PayPal payment HTML forms, stored in the database for frontend transactions.

3. File Structure

  • Main Directory: Houses core plugin files (free-link-exchange.php).
  • Admin Directory: Contains files for admin-related functionalities (admin.php).
  • Includes Directory: Stores essential logic files and form handlers (form-data-processor.php, links-submission-form.php, payment-ajax-handler.php, thankyou-template.php).
  • Style and Scripts Directories: Holds CSS and JavaScript files (form.css, form-script.js).
  1. Database Table Creation: This plugin creates tables to manage premium and reciprocal links.
  2. Shortcodes: These are used to generate dropdowns and anchor code for links.
  3. PayPal Integration: There are hooks for PayPal payment settings and retrieval of PayPal credentials.
  4. Admin Dashboard: Files for managing link submissions, approvals, rejections, and deletions.
  5. File Inclusions: Necessary files and configurations are being included in the plugin.

Constants- Constant.php

The LINK_EXCHANGE_DIR constant stores the directory path of your plugin. Meanwhile, LINK_EXCHANGE_CSS and LINK_EXCHANGE_SCRIPTS define the URLs for CSS and scripts within your plugin’s directory.

Display Link Submission Form - display-link-submission-form.php

  • add_link_and_form_to_content Function:

    • Determines whether to display a link and a form based on the settings in the WordPress admin panel (link_exchange_display_field option).
    • Adds a link at the beginning of the content that scrolls to the link submission form.
    • Appends a form below the content based on defined conditions.
  • link_submission_form Function:

    • Utilizes output buffering (ob_start and ob_get_clean) to capture the HTML output generated from the includes/links-submission-form.php file.
  • add_filter('the_content', 'add_link_and_form_to_content'):

    • Hooks the add_link_and_form_to_content function to the WordPress the_content filter, enabling it to modify the content displayed on pages.

Failure Template - File - failure-page-template.php

This code snippet processes a token provided via a URL parameter ($_GET['token']). It performs a simple check to verify the token’s existence and displays different HTML content based on whether the token is present or not.

Here’s what it does:

  • Retrieves Token: Fetches the token from the URL parameter token using $_GET['token'].
  • Token Validation: Checks if a token exists.
  • Display Messages: Renders HTML content:
    • If the token exists: Displays a failure message indicating a transaction issue.
    • If the token is absent: Displays an error message for an invalid token.

Function's File - Functions.php

This script is part of a WordPress plugin and contains several functions:

  1. display_links_on_page: Checks if the current page is a single post or page and retrieves approved reciprocal and premium links related to that page from the database. It then generates HTML to display these links at the end of the content.

  2. get_approved_reciprocal_links and get_approved_premium_links: Retrieve approved reciprocal and premium links respectively for a specific page title from the WordPress database.

  3. generate_return_url: Generates a return URL based on the current site’s domain and a unique identifier.

  4. handle_custom_plugin_endpoint: Handles a custom plugin endpoint by including a requested file from the ‘includes’ directory if it exists and is valid.

  5. link_exchange_handle_return_endpoint: Handles success and failure endpoints based on tokens and redirection to respective pages (success-page-template.php or failure-page-template.php) based on the return type.

This script manages various aspects of displaying links, generating return URLs, handling custom plugin endpoints, and redirecting based on success or failure.

 

Payments Success Template - Success-page-template.php

This code snippet processes a token provided via a URL parameter ($_GET['token']). It checks for the existence of the token and displays different HTML content based on whether the token is present or not.

Here’s a breakdown:

  • Retrieves Token: Fetches the token from the URL parameter token using $_GET['token'].
  • Token Validation: Checks if a token exists.
  • Display Messages: Renders HTML content:
    • If the token exists: Displays a success message indicating a successful transaction.
    • If the token is absent: Displays an error message for an invalid token.

This code snippet handle token verification and present users with specific messages based on token validity.

Uninstall - Uninstall.php

This code is part of the uninstallation process for a WordPress plugin. When the plugin is uninstalled from the WordPress admin panel, this script gets executed.

Here’s what it does:

  1. Checks for WordPress Uninstallation: It first checks if the constant WP_UNINSTALL_PLUGIN is defined. This ensures that the file is being executed during the uninstallation of the plugin and not accessed directly. If it’s not defined, the script exits.

  2. Drops Database Tables: It uses the WordPress database object $wpdb to construct and execute SQL queries that drop tables associated with the plugin. Specifically, it removes two tables: link_exchange_reciprocal_links and link_exchange_premium_links.

These queries use the $wpdb->query method to execute SQL commands and drop the respective tables from the WordPress database.

This code ensures that when the plugin is uninstalled, its associated database tables are removed to clean up the database and delete plugin-related data.

In The Admin Folder

Admin Main File - Admin.php
  1. WordPress Core Loading: It checks if ABSPATH is defined to prevent direct access to the file. Then, it includes WordPress core files such as wp-config.php and wp-load.php to initialize WordPress functionalities.

  2. Display Functions and Admin Menu Setup:

    • link_exchange_display: Function to display submitted links.
    • Admin Menu Setup (link_exchange_menu): Defines the main menu page and several sub-menu pages for the Link Exchange Plugin within the WordPress admin area. Each sub-menu page is associated with a callback function to display content.
  3. Submenu Page Setup Functions:

    • Functions (link_exchange_submenu_pages) to add various sub-menu pages like ‘Link Exchange Settings’, ‘Manage PayPal HTML’, ‘Edit PayPal Codes’, and ‘Payment Settings’. Each submenu page is linked to a specific callback function to render its content.
  4. Custom Icon Styles: (link_exchange_custom_icon): Dynamically adds custom icon styles for your plugin’s pages by modifying the CSS for specific page slugs.

  5. Include Files: It includes several PHP files (submitted-links.php, approved-links.php, rejected-links.php, settings.php) containing code for displaying submitted, approved, and rejected links, as well as settings functionality.

There’s a commented line (//require_once plugin_dir_path(dirname(__FILE__)) . 'includes/reciprocal-check.php';) that seems to be a directive to include the reciprocal-check.php file, which might be related to reciprocal link functionalities but is currently commented out.

This file manages the setup of various admin menu pages and their associated functionalities within your WordPress plugin.

Admin Select Which Page To Display The Links Submission Form admin-select-page.php

This script generate a form in the WordPress admin area to allow the admin to choose a display page for the plugin. Here’s a breakdown of what it does:

  1. Fetching Pages: It retrieves all published pages from your WordPress installation using get_pages() and displays them in a dropdown list within a form.

  2. Form Submission: When the form is submitted, it checks for a POST request and the presence of save_page_choice. If these conditions are met, it retrieves the selected page’s title from the submitted form data.

  3. Database Update: Using the WordPress database global instance ($wpdb), it updates a table (link_exchange_reciprocal_links) in the database. The update operation sets the page_choice column to the selected page’s title for entries where the status is ‘pending’ (you might adjust these conditions based on your needs).

  4. Feedback Message: After attempting the database update, it provides feedback to the admin, indicating whether the update was successful or not.

This functionality allows the admin to dynamically set a chosen display page for certain entries in the link_exchange_reciprocal_links table based on the selected page from the form.

Admin Navigation Tabs - Admin-tabs.php

This HTML snippet generates a management dashboard header for the Link Exchange plugin within the WordPress admin area. Here’s a breakdown of what it does:

  1. Wrap Element: It uses a <div> element with the class wrap to contain the dashboard elements. Styling attributes like padding, margin, width, background color, box shadow, and border radius are applied to style the container.

  2. Heading: It contains an <h1> element displaying the text “Link Exchange Management Dashboard” as the main title.

  3. Navigation Tabs: It creates a set of navigation tabs using <a> elements styled as tabs (nav-tab class). Each tab links to a different admin page related to the Link Exchange plugin using admin_url('admin.php?page=...').

    • Link Exchange Settings Tab: Points to link-exchange-settings.
    • Submitted Links Tab: Points to link-exchange.
    • Approved Links Tab: Points to approved-links.
    • Rejected Links Tab: Points to rejected-links.

Each tab has conditional styling based on the current URL parameters ($_GET['page']) to determine which tab corresponds to the currently active page. If a tab corresponds to the current page, it’s styled as active by adding the nav-tab-active class.

This structure provides an organized and visually appealing navigation header for managing different aspects of the Link Exchange plugin in the WordPress admin dashboard.

Display And Manage Approved Links - Approved-links.php

This chunk of code handles the functionality to display and manage approved reciprocal and premium links in the WordPress admin panel. Here’s what each part does:

Reciprocal Links:

  • Data Retrieval: Fetches approved reciprocal links from the database.
  • Display: Generates a form to display these links in a tabular format with details like link URL, name, page choice, email, and admin approval status.
  • Action Controls: Provides options to change the page choice and select actions like rejecting, deleting, or keeping the link unchanged.
  • Form Submission Handling: Manages the form submission for changes made to the approved reciprocal links.

Premium Links:

  • Data Retrieval: Retrieves approved premium links from the database.
  • Display: Creates a form to display these links in a tabular format, showcasing link URL, name, page choice, email, and action controls to modify page choices or reject/delete the links.
  • Action Controls: Similar to reciprocal links, allows changing the page choice and selecting actions for each link.
  • Form Submission Handling: Manages the form submission for changes made to the approved premium links.

Both sections operate similarly but handle different types of approved links (reciprocal and premium), providing administrators the ability to modify page choices or take actions (reject/delete) for each link individually.

Constants - constants.php

This code snippet defines constants that specify the directory paths for CSS and JavaScript files within the plugin. These constants can be used throughout the plugin to refer to these specific directories. Here’s what each part does:

  • LINK_EXCHANGE_DIR Constant: Specifies the absolute server path to the main directory of your plugin.
  • LINK_EXCHANGE_CSS Constant: Indicates the URL to the directory containing CSS files for your plugin’s admin section.
  • LINK_EXCHANGE_SCRIPTS Constant: Indicates the URL to the directory containing JavaScript files for your plugin’s admin section.

These constants help maintain consistency and ease of access when referencing the plugin’s resources across various files and functionalities within the admin section of WordPress.

Database Options - Database-options.php

Plugin Deletion Settings

This section outlines the settings and functionality related to data deletion upon uninstallation of the Link Exchange WordPress plugin.

Delete Data on Uninstall

The plugin provides an option to delete all associated data from the database when the plugin is uninstalled. This feature can be found in the plugin settings.

Functionality

The plugin settings include a checkbox labeled “Delete data from database on plugin uninstallation.” By checking this box, all plugin-related data will be permanently deleted upon uninstallation. This action cannot be undone, so proceed with caution.

Code Implementation

Checkbox Display Function

The `link_exchange_delete_on_uninstall_callback()` function is responsible for displaying the checkbox in the plugin settings. It fetches the current option value and displays the checkbox accordingly.

Uninstallation Hook

The `register_uninstall_hook()` function is used to hook into the plugin uninstallation process. It triggers the `link_exchange_plugin_uninstall()` function when the plugin is uninstalled.

Uninstallation Logic

The `link_exchange_plugin_uninstall()` function checks if the “Delete data from database on plugin uninstallation” checkbox is selected. If checked, it proceeds to delete specific tables from the database associated with the plugin.

 Tables Deleted

– `link_exchange_reciprocal_links`: Contains data for reciprocal links.
– `link_exchange_premium_links`: Contains data for premium links.

Important Note

Ensure to replace the table names (`link_exchange_reciprocal_links` and `link_exchange_premium_links`) with your actual table names if they differ.

**Caution**: Always take a backup of your database before enabling the deletion on uninstallation setting.

Additional Actions

You can add further cleanup or deletion actions within the provided hooks based on your plugin’s requirements.

 

PayPal Payments Settings - Paypal-settings.php

This file handles the configuration and settings management for the “Link Exchange WP” plugin. It integrates with WordPress core functionalities and provides an interface for administrators to set up PayPal-related settings and manage pricing information for link placements within the plugin.

Purpose:

The primary purpose of this file is to establish settings sections, fields, and callbacks necessary for the plugin’s configuration in the WordPress dashboard.

Code Overview:

  • File Inclusion: The file starts by loading essential WordPress core files required for proper functioning.
  • Plugin Settings Registration: It registers various settings sections related to PayPal configuration and pricing information for link placements.
  • Callback Functions: Several callback functions are defined to render specific fields within the settings sections. These functions facilitate the display and update of settings such as PayPal email, API credentials, link placement price, and currency selection.
  • Saving Settings: It includes a function to save entered settings securely using WordPress nonce verification and data sanitization for each field.

Functions Overview:

  • add_plugin_settings(): Registers settings sections and fields for PayPal and pricing configuration.
  • paypal_settings_section_callback(): Callback function to display the PayPal settings section.
  • paypal_email_field_callback(): Callback function to render the PayPal email input field.
  • paypal_api_username_field_callback(): Callback function to render the PayPal API username input field.
  • paypal_api_password_field_callback(): Callback function to render the PayPal API password input field securely.
  • pricing_settings_section_callback(): Callback function to display the pricing settings section.
  • link_placement_price_field_callback(): Callback function to render the link placement price input field.
  • currency_selection_field_callback(): Callback function to render the currency selection dropdown field.
  • save_plugin_settings(): Saves entered settings securely when updated, using nonce verification and data sanitization.

Management Of Reciprocal And Premium Rejected Links - Rejected-links.php

Purpose: This file handles the management of rejected reciprocal and premium links, allowing users to modify page choices, approve, or delete rejected links.

WordPress Dependencies:

  • Ensures that the file is accessed through WordPress.
  • Loads essential WordPress core files (wp-config.php and wp-load.php).

Functions:

  1. Link Management for Rejected Reciprocal Links:

    • Handles form submission to change page choices for rejected reciprocal links.
    • Manages actions like approving or deleting rejected reciprocal links.
    • Displays a table of rejected reciprocal links for management.
  2. Link Management for Rejected Premium Links:

    • Handles form submission to change page choices for rejected premium links.
    • Manages actions like approving or deleting rejected premium links.
    • Displays a table of rejected premium links for management.

Important Notes:

  • The file is designed to interact with WordPress database tables (link_exchange_reciprocal_links and link_exchange_premium_links).
  • It includes functions to update page choices, approve, or delete rejected links based on user actions.
  • The interface provides radio buttons for approving or deleting links, with the option to change page choices for each rejected link.

Usage:

  • Accessing this file through WordPress admin allows the administrator to manage rejected links, change page choices, and take actions like approval or deletion.

Management Of Both Submitted Reciprocal And Premium Links - Submitted-links.php

Functions and Operations:

  1. Load WordPress Core Files:

    • Loads the necessary WordPress core files (wp-config.php and wp-load.php) to ensure proper access to WordPress functionalities.
  2. Handle Form Submissions:

    • Checks if form data has been submitted and the ‘save_changes’ button is clicked.
    • Processes changes related to page choices for reciprocal links, updating page titles in the database based on selected page IDs.
    • Handles approval, rejection, and deletion actions for submitted reciprocal links based on user selections.
  3. Handle Premium Links Submission:

    • Registers an action hook to process form submissions related to premium links upon initialization.
    • Manages changes in page choices for premium links and handles actions like approval, rejection, or deletion for each premium link.
  4. Display Submitted Links:

    • Fetches and displays submitted reciprocal links and premium links separately.
    • Allows administrators to view, manage page choices, and perform actions (approve, reject, delete) on these links through styled tables.
  5. Display Admin-Approved Links with ‘Link Not Found’ Status:

    • Retrieves and displays links that have been admin approved despite having a ‘link not found’ status.
    • Shows relevant link details like URL, anchor text, name, email, and status in a formatted table for admin review.

File To Manage Plugin's Settings - Settings.php

This PHP file manages the settings related to the “Link Exchange” WordPress plugin. It handles various functionalities, including registering plugin options, rendering the settings page, displaying PayPal return and IPN URLs, and managing form display settings.

Functions and Actions:

  1. link_exchange_plugin_settings()

    • Registers settings for enabling/disabling features and setting the link check frequency.
    • Adds a unified settings section for feature and uninstall settings.
    • Adds fields for enabling features, deleting data on uninstall, and setting the link check frequency.
  2. link_exchange_settings_section_callback()

    • Callback function to display information about configuring Link Exchange settings.
  3. link_exchange_settings_page()

    • Renders the settings page for Link Exchange.
    • Uses WordPress settings API to display and handle settings.
  4. display_paypal_return_and_ipn_urls_section()

    • Generates PayPal return and IPN URLs for successful and failed transactions.
    • Saves these URLs in WordPress options for future use.
    • Displays these URLs in a formatted section on the settings page.
  5. link_exchange_form_display_settings()

    • Adds settings section and fields for determining where to display the link submission form (all pages, specific pages, or none).
  6. link_exchange_display_options_callback()

    • Callback function to display information about selecting where to display the link submission form.
  7. link_exchange_display_field_callback()

    • Renders radio buttons to select where the link submission form should be displayed (all pages, specific pages, or none).
    • Provides checkboxes to select specific pages, posts, and categories if the specific pages option is chosen.
  8. link_exchange_check_frequency_callback()

    • Callback function to display and set the frequency for link status checks in hours.

Includes:

  • paypal-settings.php: Required file for PayPal settings.
  • database-options.php: Required file for managing database-related options.
  • admin-tabs.php: Required file for displaying admin tabs.

The Includes Folder

Link Exchange Submission Form - Links-submission-form.php

Purpose: This PHP file serves as the interface for users to submit reciprocal or premium links to the WordPress plugin.

Functionality:

  1. WordPress Core Loading:

    • Checks for the existence of WordPress core files (wp-config.php and wp-load.php) within the directory structure.
    • Includes these files to initiate WordPress functionality.
  2. HTML Structure:

    • Constructs the HTML structure for the link submission form.
    • Includes jQuery library for JavaScript functionality.
    • Embeds CSS and JavaScript files for styling and dynamic form behavior.
  3. Guidelines Display:

    • Displays guidelines for users interested in link exchange.
    • Lists detailed instructions and requirements for link submission, distinguishing between reciprocal and premium links.
  4. Form Selection:

    • Presents a dropdown menu for users to select the type of link submission (reciprocal or premium).
    • Utilizes JavaScript to toggle the display of the corresponding submission form based on the user’s selection.
  5. Reciprocal Links Submission Form:

    • Constructs a form for submitting reciprocal links.
    • Fields include:
      • Link URL
      • Anchor Text
      • Name
      • Email
      • Partner’s Reciprocal URL
      • Display code for initiating link exchange on the user’s website
      • Captcha form for security
  6. Premium Links Submission Form:

    • Builds a form for submitting premium links.
    • Fields include:
      • Link URL
      • Anchor Text
      • Name
      • Email
      • Payment Choice (PayPal or Other Payment Method)
      • Captcha form for security
  7. JavaScript Functionality:

    • Uses JavaScript to control the display of the appropriate form based on the user’s link type selection.

Important Notes:

  • All fields marked with an asterisk (*) are required for submission.
  • Users must adhere to the provided guidelines for successful link placement.
  • The form includes Captcha for security verification.
  • Payment for premium links is specified via PayPal or another payment method.

Send Notifications To Both Admin For Link Submission And To User For Link Approval - Notification.php

Purpose: This PHP file is part of a WordPress plugin designed for managing premium and reciprocal links exchange within a WordPress website. The file primarily focuses on monitoring and notifying admins and users about newly approved links.

File Structure:

  • File Name: link-exchange-notification.php
  • Location: Within the plugin’s directory structure.

Features:

  1. Initial Setup and WordPress Core Inclusion:

    • Checks and includes essential WordPress core files required for database connectivity and functionality.
    • Accesses WordPress core functionalities via included files.
  2. Database Connectivity:

    • Establishes connectivity with the WordPress database using global $wpdb.
  3. Functionality:

    • Defines two table names ($reciprocal_table and $premium_table) used for managing reciprocal and premium links, respectively.
    • Implements checkLinks() function to handle the notification process for newly approved links of both types.
      • Queries the database for newly approved premium and reciprocal links that are yet to be notified.
      • Sends email notifications to the admin and users for approved links.
      • Updates the database to mark links as notified after sending emails.
  4. Hooks and Scheduling:

    • Registers activation and deactivation hooks for scheduling the checkLinks() function.
    • Ensures the checkLinks() function is triggered hourly after plugin activation.
    • Clears scheduled events upon plugin deactivation.

Note:

  • Ensure this file is placed within the plugin’s directory and properly integrated into the plugin’s structure.
  • Customize email templates and notifications as per specific requirements.

Caution:

  • Carefully configure email notifications to avoid spamming users or overloading the server with unnecessary emails.

Usage:

  • This file should be included as part of the WordPress plugin for managing link exchanges.
  • Customize table names and queries based on the actual database structure and requirements.

Payment Tracking - Payment-track.php

Purpose: This PHP script is designed to facilitate tracking user actions and updating premium link statuses in a WordPress database based on payment events.

Description:

  • Loading WordPress Core Files: This script locates and loads essential WordPress core files (wp-config.php and wp-load.php) to enable WordPress functionalities within the script.

  • Security Check: It checks if the file is accessed directly and exits if the WordPress environment constant ABSPATH is not defined, preventing unauthorized access.

  • Tracking Event Logging: Contains a function logTrackingEvent($event) to log tracking events. The function logs events with timestamps either in a file named tracking.log or by storing events in the session for tracking across requests.

  • Session Handling: Initiates or resumes a session to store tracking data.

  • Payment Status Tracking: Processes GET parameters (token and payment_status) to update premium link statuses in the database based on payment events received from the URL. It identifies the source of the request, checking if it originated from PayPal.

  • Updating Premium Link Status: Provides updatePremiumLinkStatus($token, $status) function to update the status of premium links in the database. It retrieves the link associated with the provided token and updates its payment status.

Functions:

  • logTrackingEvent($event): Logs tracking events with timestamps either in tracking.log file or in the session.

  • updatePremiumLinkStatus($token, $status): Updates the payment status of premium links in the database based on the provided token and status.

Premium Captcha Validation - Premium-captcha-logic.php

Purpose:

This PHP file handles the validation of a CAPTCHA code submitted via a form. It ensures that the submitted CAPTCHA code matches the one stored in the session for verification purposes.

Usage:

This file should be included or called from a script that processes a form submission requiring CAPTCHA validation.

Functions/Logic:

  1. Setting Session Save Path:

    • Sets the session save path to the ‘sessions’ folder relative to the current file’s directory for storing session data.
  2. Starting the Session:

    • Initiates the PHP session to enable session-based storage and retrieval of data.
  3. Captcha Validation Logic:

    • Checks if the form has been submitted with the ‘pay_now’ action.
    • Stores the submitted CAPTCHA code in the session.
    • Retrieves the stored CAPTCHA code from the session.
    • Outputs debug information (submitted and stored CAPTCHA) to the error log for comparison (for debugging purposes only).
    • Compares the submitted and stored CAPTCHA codes:
      • If the codes do not match or are empty:
        • Outputs an error message indicating the validation code mismatch.
        • Logs the validation failure in the error log.
        • Stops further execution of the script.
      • If the codes match:
        • Sets a success message indicating the validation code match.
        • Allows further processing such as data insertion or other operations.
Premium Link Processor - Premium-link-processor.php

Purpose:

This PHP file handles the submission of premium links within the WordPress plugin “Link Exchange WP.” It processes form data, validates input, and inserts the information into the database for premium link submissions.

Error Handling and Logging:

  • Error reporting is enabled for all types of errors but not displayed on the screen (display_errors is set to 0).
  • Errors are logged to a file named error_log.txt located in the same directory as this script (__DIR__).

Dependencies:

  • Requires WordPress core files for functionality.
  • Includes files for premium captcha logic (premium-captcha-logic.php) and updating payment status (update-payment-status.php).

Input Processing:

  • Retrieves and sanitizes POST data for premium link submission.
  • Validates and sanitizes form fields such as link URL, anchor text, page choice, name, and email.
  • Additional data validation can be added as needed, populating the $errors array for any validation failures.

Database Interaction:

  • Inserts validated data into the link_exchange_premium_links table within the WordPress database.
  • Logs the page title instead of the ID (page_choice_premium) for debugging purposes.
  • Logs the result of the database insert operation ($insert_result) for debugging.
  • If the insertion is successful, the script requires the PayPal payments file (payments.php) and redirects to the payment page.

Important Note:

  • Caution is advised when modifying this file, especially regarding data validation and database operations. Incorrect modifications could affect plugin functionality or compromise data integrity.
Reciprocal Captcha Logic - Reciprocal-captcha-logic.php

This PHP file is responsible for validating captcha input for the submission of reciprocal links. It verifies the captcha code submitted via a form against the stored captcha in the session to ensure validation before processing further operations.

Functionality:

  1. Setting Session Save Path:

    • Sets the session save path to the ‘sessions’ folder, which is located relative to the current file’s directory. The sessions folder is used to store and retrieve captcha-related session data.
  2. Starting Session:

    • Initiates the PHP session to manage and store captcha-related information securely.
  3. Captcha Validation Logic:

    • Checks if the form to submit reciprocal links (submit_reciprocal_link) has been submitted.
    • Stores the submitted captcha code in the session for comparison.
    • Deserializes the stored captcha code from the session.
    • Compares the submitted captcha code with the stored captcha code.
      • Outputs error messages if the validation code doesn’t match.
      • Logs debugging information (captchas for comparison) for development purposes.
      • Stops further execution if there’s a validation mismatch.
    • If the validation code matches, it displays a success message ($msg) and allows further processing (such as data insertion).

Usage:

  • Ensure this file is included in the reciprocal link submission process to validate the captcha input.
  • The HTML form should submit the captcha code as captcha_code along with the submit_reciprocal_link value set to 'submit_reciprocal_link'.
  • Debugging outputs (such as error_log and echo statements) are present and should be commented out or removed in production for security and user experience reasons.
Reciprocal Links Check - Reciprocal-check.php

Plugin Name: Link Exchange Status Checker
Description: Checks and updates link statuses based on partner reciprocal URLs.

This file includes functionality to manage link status checks and updates for reciprocal links associated with the Link Exchange plugin.

Dependencies:
– This file is a WordPress plugin and requires a WordPress installation to function.
– It depends on WordPress core files and uses various WordPress functions and hooks.

Functionality:
– The plugin schedules regular checks of link statuses based on partner reciprocal URLs.
– It hooks into WordPress activation and deactivation events to schedule and unschedule link status checks respectively.
– It allows for the customization of the link check frequency via the WordPress admin interface.
– The file contains functions to check if a reciprocal link is present on a partner’s webpage, utilizing cURL for fetching the partner’s URL content and verifying the link presence.
– It includes functionality to send email notifications to the admin regarding changes in link statuses (e.g., pending to approved or vice versa).
– The main processing function ‘process_links’ retrieves data from the database, checks the link statuses, updates them accordingly, and sends notifications to the admin when statuses change.

Usage:
– This plugin operates in the background to manage and update link statuses associated with reciprocal URLs.
– It can be extended or integrated further to suit additional functionalities or customizations.

Note:
– Care should be taken while modifying this plugin to ensure the safety of data and the smooth functioning of the Link Exchange system.
– The plugin heavily interacts with database tables related to reciprocal links and email functionalities; any modifications should be tested thoroughly.

Reciprocal Links Submission Processor - Reciprocal-links-processor.php

This PHP file manages the submission of reciprocal links in the WordPress plugin “Link Exchange WP”. Below is an overview of its functionalities and structure:

Functions:

  1. custom_esc_url_raw($url): This function provides an alternative method to esc_url_raw() by utilizing PHP’s filter_var() with the FILTER_SANITIZE_URL filter. It sanitizes and filters the provided URL.

WordPress Core Loading: The file loads essential WordPress core files using a method that traverses the directory structure until it finds the wp-load.php file. If the file is not found, an error message is displayed, indicating a failure to locate the core WordPress files.

Error Logging: The script sets the error log file location using ini_set() to log errors encountered during script execution. Errors are logged in the error_log.txt file located in the same directory as this script.

Included Files:

  • reciprocal-captcha-logic.php: This file is required using require_once(). It presumably contains logic related to reciprocal captcha functionality.

  • includes/reciprocal-check.php: Another file is included using require_once(). It likely contains additional reciprocal link checking or processing logic.

Form Handling: Upon form submission (identified by $_POST['submit_reciprocal_link']), the script handles the data:

  • Sanitizes input data (link URL, anchor text, name, email, partner reciprocal URL) using WordPress sanitization functions (sanitize_text_field() and sanitize_email()).
  • Performs error checking and logs potential errors in an error array.

Database Interaction:

  • The script interacts with the WordPress database via the global $wpdb object to insert data into the ‘link_exchange_reciprocal_links’ table.
  • It constructs an INSERT query to add the submitted reciprocal link data to the database.
  • Logs the result of the insert operation for debugging purposes.
  • If the insertion is successful, it redirects to the ‘thank you’ page by requiring thankyou-template.php.

Important Note: Ensure the error_log.txt file is accessible and that error logging is appropriately managed in a production environment. Additionally, verify the completeness and correctness of the included files’ paths and functionalities for seamless plugin operation.

Update Payments Status - Update-payment-status.php

Purpose: This file is responsible for handling PayPal transaction status change callbacks within the WordPress environment.

Usage:

  1. Loads WordPress core files to enable WordPress-specific functionalities.
  2. Handles PayPal transaction status changes passed through URL parameters (token and payment_status).
  3. Updates the link status based on the PayPal transaction status.
  4. Updates the payment status in the database when the payment is completed.

Requirements:

  • Access to WordPress core files (wp-config.php, wp-load.php).
  • Proper setup and integration of PayPal transactions within the plugin or WordPress environment.

Code Structure:

  • Loading WordPress Core Files: Checks for the existence of WordPress core files (wp-config.php and wp-load.php) in the directory hierarchy and includes them to enable WordPress functionality.
  • Direct Access Check: Ensures the file is accessed within the WordPress context by checking the definition of ABSPATH. Exits if accessed directly from outside WordPress.
  • PayPal Transaction Callback Handling: Processes URL parameters (token and payment_status) if present, sanitizes the input, and updates link status based on the PayPal transaction status.
  • Updating Payment Status: Contains a function (updatePaymentStatus()) that updates the payment status in the database table link_exchange_premium_links for a specific token.

Functions:

  • updatePaymentStatus($token, $status): Updates the payment_status field in the link_exchange_premium_links table based on the provided token.
Payments - Payment.php

Purpose: This PHP file handles the submission of links for placement via PayPal integration. It allows users to submit their links for placement by paying an annual fee using PayPal.

Functionality Overview:

  1. Error Handling and Configuration:

    • Enables error reporting and sets the error log file.
    • Checks for the existence of WordPress core files (wp-config.php and wp-load.php) to ensure proper WordPress initialization.
    • Validates and fetches PayPal credentials and link placement price from plugin settings.
    • Displays an admin notice if PayPal credentials are missing.
  2. PayPal Integration:

    • Provides a message to users indicating that their link submission has been received and prompts them to complete the link insertion by paying an annual fee of $10.
    • Renders a PayPal payment form with hidden fields containing seller’s email, item details, price, and currency code for link placement.
    • Allows users to make payments through the PayPal “Pay Now” button.
    • Displays contact information for users to reach out with questions or concerns.

File Structure:

  1. Configuration and Initialization:

    • Enables error reporting, sets error log file.
    • Checks for WordPress core files existence and includes them.
    • Retrieves and validates PayPal credentials and link placement price.
  2. Frontend Display:

    • Contains CSS styles for layout adjustments.
    • Displays a message confirming link submission receipt.
    • Provides a PayPal payment form for users to complete link placement by making a payment.
    • Offers contact information for users to reach out for inquiries.

Usage:

  • Ensure WordPress core files (wp-config.php and wp-load.php) are properly placed.
  • Configure PayPal credentials and link placement price in the plugin settings.
  • Include this file in the plugin directory.
  • Customize CSS styles and PayPal image/button as needed.
PayPal Response - Paypal-response.php

PayPal Integration and Response Handling Logic

This PHP file serves the purpose of handling PayPal responses and integrating them into a WordPress plugin for managing premium link placements.

Purpose:

The file facilitates the integration of PayPal payment responses into the plugin’s functionality. It retrieves PayPal settings from WordPress options and handles the simulation of PayPal response processing.

Instructions:

  1. Loading WordPress Core Files:

    • This script first attempts to load WordPress core files by traversing directories. It includes wp-load.php to access WordPress functionalities.
  2. Retrieving PayPal Settings:

    • Retrieves PayPal settings such as email, API credentials, link placement price, and currency selection from WordPress options using get_option().
  3. PayPal Response Handling Logic:

    • Simulates PayPal response handling logic.
    • Checks for a POST request and simulates a successful payment response.
    • Upon receiving a response, it retrieves the transaction ID (txn_id) and payment status.
    • Updates the link status in the database based on the PayPal transaction status.
    • Logs the PayPal transaction status updates in paypal_tracking.log.

Functions:

  1. updateLinkStatusFromPayPal($token, $payment_status):
    • Parameters:
      • $token: PayPal transaction ID.
      • $payment_status: Status of the payment received (e.g., ‘Completed’).
    • Functionality:
      • Updates the link status in the ‘link_exchange_premium_links’ table based on PayPal transaction status.
      • Retrieves the link associated with the provided transaction ID and updates its payment status.
      • Logs the transaction status update events in paypal_tracking.log.
PayPal Return URLs - Return.php

Purpose: This PHP file is responsible for generating and displaying PayPal return and IPN (Instant Payment Notification) URLs within a WordPress plugin.

Usage:

  1. Load WordPress Core Files: The code first attempts to locate the wp-config.php file within the WordPress installation directory to include necessary core files. If not found, it terminates with an error message.

  2. Function generate_paypal_urls(): This function constructs unique URLs for success, failure, and IPN handling.

    • Success and Failure URLs: URLs to success and failure pages are constructed within the plugin directory and then generated with unique tokens appended as query parameters. These URLs are updated in the WordPress options for potential usage elsewhere.

    • IPN URL: An IPN URL is generated with a unique token for PayPal’s Instant Payment Notification handling. This URL is also updated in the WordPress options.

    • Output: The generated URLs for success, failure, and IPN are echoed for reference.

Functions:

  1. generate_paypal_urls(): Generates PayPal return and IPN URLs with unique tokens and updates them in WordPress options. Outputs these URLs for reference.

Notes:

  • Modify the placeholders (success-page-template.php, failure-page-template.php, paypal-response.php) with the appropriate file names or endpoints.
  • Ensure proper security measures are in place for IPN handling, as it involves sensitive payment-related operations.

Usage Example:

include_once('paypal-url-generator.php');generate_paypal_urls();
Plugin Installation Guide

Installation Guide

1. Download and Upload

  • Download the plugin ZIP file.
  • Log in to your WordPress admin panel.
  • Navigate to Plugins > Add New > Upload Plugin.
  • Choose the ZIP file and click “Install Now.”

2. Activate the Plugin

  • After successful upload, activate the “Link Exchange WP” plugin.

3. Configuration

  • Go to the plugin settings in the WordPress dashboard.
  • Input PayPal credentials (email, API username, and password).
  • Set the link placement price and select the preferred currency.

Usage Steps

1. Managing Links

  • Access the admin dashboard.
  • Navigate to the Link Exchange section.
  • Approve, reject, or delete submitted links.

2. Premium Link Placement

  • Insert PayPal Payment Forms.
  • Customize payment amount, currency, and item name.

3. Captcha Integration

  • Ensure the Captcha Validation is activated.
  • Verify the functionality with sample submissions.

4. Automated Link Status Checks

  • Verify the automatic status checking mechanism.
  • Ensure the scheduled checks are functioning correctly.

5. Customization Options

  • Customize CSS, JavaScript, and HTML templates for visual and behavioral adjustments.
  • Implement custom messages or additional functionalities.

Troubleshooting

1. Missing Configurations

  • Verify PayPal credentials in the plugin settings.
  • Ensure the correct setup of link placement prices.

2. Debugging

  • Access plugin-related logs (/error_log.txt).
  • Check for error messages for debugging purposes.
Scroll to Top