Plugin Directory

Changeset 2536605


Ignore:
Timestamp:
05/24/2021 05:51:18 PM (5 years ago)
Author:
angelcosta
Message:

New and improved 1.0

Location:
wp-seo-search/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-seo-search/trunk/readme.txt

    r2097596 r2536605  
    22=== WP SEO Search ===
    33Contributors: angelcosta
    4 Donate link: https://netmundo.com.br/
     4Donate link: https://angelcosta.com.br/apoie
    55Tags: search, seo, permalink, pretty urls, friendly urls
    6 Requires at least: 3.0.1
    7 Tested up to: 5.2
    8 Requires PHP: 5.2.4
    9 Stable tag: 0.3
     6Requires at least: 5.4
     7Tested up to: 5.7.2
     8Requires PHP: 7.0
     9Stable tag: 1.0
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1414
    1515== Description ==
    16 This plugin makes the url for the search results page look like http://site.com/search/keyword
     16This plugin makes the url for the search results page look like https://site.com/search/keyword
    1717
    18 Credit: https://wordpress.org/plugins/nice-search/
     18Credit/Inspired by: [Nice Search](https://wordpress.org/)
    1919
    2020== Installation ==
     
    2222
    2323== Frequently Asked Questions ==
    24 = I want to change the word "search" in the permalink. How? =
    25 Go to Permalinks and change your search base
     24= I want to change the word "search" in the permalinks. How do I do that? =
     25Go to your Wordpress's Admin Dashboard and click on *Permalinks* under *Configuration*. In the *Optional* section you can change your search base to whatever you want.
    2626
    2727== Screenshots ==
    28  
    29 1. How it looks on the panel
     28
     291. This is how your URL will look
     302. This is how you change your search base
    3031
    3132== Changelog ==
     33= 1.0 =
     34* Cleaner code
     35* Compatibility with WP 5.7.2
     36* Added link to configuration in plugin list
     37* Fixed correct URL for my website
    3238= 0.2.1 =
    3339* Added i18n code. Plugin is now translation-ready.
  • wp-seo-search/trunk/wp-seo-search.php

    r1351031 r2536605  
    11<?php
    2 /*
     2/**
    33* Plugin Name: WP SEO Search
     4* Plugin URI: https://angelcosta.com.br/wp-seo-search/
    45* Description: Get a better permalink for your search results page.
    5 * Version: 0.2.1
    6 * Author: Angelica Costa
    7 * Author URI: http://webangie.com/
     6* Version: 1.0
     7* Requires at least: 5.4
     8* Requires PHP: 7.0
     9* Author: Angel Costa
     10* Author URI: https://angelcosta.com.br/
     11* License: GPL v2 or later
     12* License URI: https://www.gnu.org/licenses/gpl-2.0.html
    813* Text Domain: wpseosearch
    9 * Domain Path: /languages/
     14* Domain Path: /languages
    1015*/
    1116
     17//Let's make this plugin available in all languages
    1218load_plugin_textdomain( 'wpseosearch', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    1319
     20//Creates the form in the permalinks page
    1421add_action( 'load-options-permalink.php', 'wpseosearch_settings' );
    15 function wpseosearch_settings(){
    16     if( isset( $_POST['wpseosearch_base'] ) ){
    17         update_option( 'wpseosearch_base', sanitize_title_with_dashes( $_POST['wpseosearch_base'] ) );
     22
     23if ( !function_exists( 'wpseosearch_settings' ) ) {
     24   
     25    function wpseosearch_settings(){
     26        if( isset( $_POST[ 'wpseosearch_base' ] ) ){
     27            update_option( 'wpseosearch_base', sanitize_key( $_POST[ 'wpseosearch_base' ] ) );
     28        }
     29        add_settings_field( 'wpseosearch_base', __( 'Search Base', 'wpseosearch' ), 'wpseosearch_input', 'permalink', 'optional' );
    1830    }
    19     add_settings_field( 'wpseosearch_base', __( 'Search Base', 'wpseosearch' ), 'wpseosearch_input', 'permalink', 'optional' );
    20 }
    21 function wpseosearch_input(){
    22     $value = get_option( 'wpseosearch_base', 'search');
    23     echo '<input type="text" value="' . esc_attr( $value ) . '" name="wpseosearch_base" id="wpseosearch_base" class="regular-text" />';
     31
    2432}
    2533
    26 function wpseosearch_base() {
    27     global $wp_rewrite;
    28     $wp_rewrite->search_base = get_option( 'wpseosearch_base', 'search' );
    29     $wp_rewrite->flush_rules();
     34if ( !function_exists( 'wpseosearch_input' ) ){
     35   
     36    function wpseosearch_input(){
     37        $value = get_option( 'wpseosearch_base', 'search');
     38        echo '<input type="text" value="' . esc_attr( $value ) . '" name="wpseosearch_base" id="wpseosearch_base" class="regular-text" />';
     39    }
     40
    3041}
    3142
    32 add_action('init', 'wpseosearch_base');
     43//Let's do some rewriting as soon as WP loads
     44add_action( 'init', 'wpseosearch_base' );
    3345
    34 function wpseosearch_rewrite() {
    35     global $wp_rewrite;
    36     if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
    37         return;
    38     $search_base = $wp_rewrite->search_base;
    39     if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
    40         wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
    41         exit();
     46if ( !function_exists( 'wpseosearch_base' ) ){
     47   
     48    function wpseosearch_base() {
     49        global $wp_rewrite;
     50        $wp_rewrite->search_base = get_option( 'wpseosearch_base', 'search' );
     51        $wp_rewrite->flush_rules();
     52    }
     53
     54}
     55
     56//And also some redirecting...
     57add_action( 'template_redirect', 'wpseosearch_rewrite' );
     58
     59if ( !function_exists( 'wpseosearch_rewrite' ) ){
     60   
     61    function wpseosearch_rewrite() {
     62        global $wp_rewrite;
     63
     64        if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() ){
     65            return;
     66        }
     67
     68        $search_base = $wp_rewrite->search_base;
     69
     70        if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
     71            wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
     72            exit();
     73        }
     74    }
     75
     76}
     77
     78//Easy shortcut for the configuration
     79add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'wpseosearch_settings_link');
     80
     81if ( !function_exists('wpseosearch_settings_link')) {
     82
     83    function wpseosearch_settings_link( $links ) {
     84        $links[] = '<a href="' .
     85            admin_url( 'options-permalink.php' ) .
     86            '">' . __('Settings') . '</a>';
     87        return $links;
     88    }
     89
     90}
     91
     92// Let's add some useful links
     93add_filter( 'plugin_row_meta', 'wpseosearch_row_meta', 10, 4 );
     94if ( !function_exists( 'wpseosearch_row_meta' )) {
     95    function wpseosearch_row_meta( $links, $file ) {
     96        if ( $file == plugin_basename( __FILE__ ) ){
     97            $links[] = '<a href="https://angelcosta.com.br/wp-seo-search">'. __( 'Documentation' ). '</a>';
     98            $links[] = '<a href="https://angelcosta.com.br/apoie">'. __( 'Donations' ). '</a>';
     99            $links[] = '<a href="options-permalink.php">'. __( 'Settings' ). '</a>';
     100            $links[] = '<a href="https://wordpress.org/support/plugin/wp-seo-search/">'. __( 'Support' ). '</a>';
     101         }
     102        return $links;
    42103    }
    43104}
    44 add_action( 'template_redirect', 'wpseosearch_rewrite' );
     105//In the next episode...
    45106
    46 if ( version_compare( $wp_version, '3.5', '<=' ) ) {
    47     function rewrite_seo_bug( $q ) {
    48         if ( $q->get( 's' ) && empty( $_GET['s'] ) && is_main_query() )
    49             $q->set( 's', urldecode( $q->get( 's' ) ) );
    50     }
    51     add_action( 'pre_get_posts', 'rewrite_seo_bug' );
    52 }
    53 ?>
     107//Run after plugin is activated
     108//register_activation_hook( __FILE__, 'pluginprefix_function_to_run' );
     109//Run after plugin is deactivated
     110//register_deactivation_hook( __FILE__, 'pluginprefix_function_to_run' );
Note: See TracChangeset for help on using the changeset viewer.