Plugin Directory

Changeset 1755493


Ignore:
Timestamp:
10/30/2017 08:26:46 PM (8 years ago)
Author:
richartkeil
Message:

use second page to change detail pages

Location:
exposify/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • exposify/trunk/README.txt

    r1731187 r1755493  
    44Requires at least: 4.5.0
    55Tested up to: 4.6.1
    6 Stable tag: 1.5.0
     6Stable tag: 1.6
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1515content and personalized styling make it a must have for all Exposify users!
    1616
    17 Visit us at [www.exposify.de ](https://www.exposify.de) or [send us a mail](mailto:info@exposify.de) 📬
     17Visit us at [www.exposify.de ](https://www.exposify.de) or [send us a mail](mailto:team@exposify.de) 📬
    1818
    1919== Installation ==
     
    4848== Changelog ==
    4949
     50= 1.6 =
     51* Update plugin to insert page titles correctly
    5052= 1.5 =
    5153* Change page titles where possible
  • exposify/trunk/admin.php

    r1572347 r1755493  
    33/**
    44 * Add an options page.
     5 *
     6 * @return void
    57 */
    68function exposify_add_options_page()
     
    1113/**
    1214 * Initialize all settings.
     15 *
     16 * @return void
    1317 */
    1418function exposify_init_settings()
     
    6771/**
    6872 * Sanitize settings which aren't used as template.
    69  * @param  Array $option
    70  * @return Array
     73 *
     74 * @param  array  $option
     75 * @return array
    7176 */
    7277function exposify_sanitize_settings($option)
     
    8287/**
    8388 * Display the field.
     89 *
     90 * @return void
    8491 */
    8592function exposify_api_key_render()
     
    93100/**
    94101 * Display the field.
     102 *
     103 * @return void
    95104 */
    96105function exposify_site_title_render()
     
    104113/**
    105114 * Display the field.
     115 *
     116 * @return void
    106117 */
    107118function exposify_site_slug_render()
     
    115126/**
    116127 * Display the field.
     128 *
     129 * @return void
    117130 */
    118131function exposify_theme_template_render()
     
    133146/**
    134147 * Display the options page.
     148 *
     149 * @return void
    135150 */
    136151function exposify_settings_page()
     
    150165/**
    151166 * Hook for updated settings. Update the page and rules when necessary.
    152  * @param $old_settings Array The old settings
    153  * @param $new_settings Array The new settings
     167 *
     168 * @param  array  $old_settings
     169 * @param  array  $new_settings
     170 * @return void
    154171 */
    155172function exposify_settings_updated($old_settings, $new_settings)
     
    161178  ) {
    162179    wp_update_post([
    163       'ID'         => get_option('exposify_properties_page_id'),
     180      'ID'         => get_option('exposify_overview_page_id'),
    164181      'post_title' => $new_settings['exposify_site_title'] ? $new_settings['exposify_site_title'] : 'Immobilien',
    165       'post_name'  => $new_settings['exposify_site_slug'] ? $new_settings['exposify_site_slug'] : 'immobilien'
     182      'post_name'  => $new_settings['exposify_site_slug']  ? $new_settings['exposify_site_slug'] : 'immobilien'
    166183    ]);
    167184  }
     
    175192/**
    176193 * Remove the properties page from the overview.
     194 *
    177195 * @param  WP_Query $query
    178  */
    179 function exposify_remove_page_from_overview($query)
     196 * @return void
     197 */
     198function exposify_remove_pages_from_admin_interfaces($query)
    180199{
    181200  global $pagenow, $post_type;
    182201
     202  // remove detail page from every possible place
     203  $query->query_vars['post__not_in'] = [
     204    get_option('exposify_property_page_id')
     205  ];
     206
     207  // remove overview page only from wordpress page overview
    183208  if ($pagenow == 'edit.php' && $post_type == 'page') {
    184     $query->query_vars['post__not_in'] = [get_option('exposify_properties_page_id')];
     209    $query->query_vars['post__not_in'][] = get_option('exposify_overview_page_id');
    185210  }
    186211}
    187212
    188 add_action('parse_query', 'exposify_remove_page_from_overview');
     213add_action('parse_query', 'exposify_remove_pages_from_admin_interfaces');
    189214add_action('admin_menu', 'exposify_add_options_page');
    190215add_action('admin_init', 'exposify_init_settings');
  • exposify/trunk/exposify.php

    r1731187 r1755493  
    55Plugin URI: https://exposify.de
    66Description: Zeigt alle eigenen Immobilienangebote von Exposify.
    7 Version: 1.5.0
     7Version: 1.6
    88Author: Exposify
    99Author URI: https://exposify.de
     
    1313/**
    1414 * Add the page and the rewrite rules.
     15 *
     16 * @return void
    1517 */
    1618function exposify_activate_plugin()
    1719{
    18   exposify_add_properties_page();
     20  exposify_add_all_pages();
    1921  exposify_rewrite();
    2022  flush_rewrite_rules();
     
    2224
    2325/**
    24  * Remove the page.
     26 * Remove the pages. Remove the old option from the previous plugin version.
     27 *
     28 * @return void
    2529 */
    2630function exposify_deactivate_plugin()
    2731{
    28   $pageID = get_option('exposify_properties_page_id');
    29   if ($pageID) {
    30     wp_delete_post($pageID, true);
    31   }
     32  exposify_delete_page('exposify_overview_page_id');
     33  exposify_delete_page('exposify_property_page_id');
     34
     35  delete_option('exposify_properties_page_id');
     36
    3237  flush_rewrite_rules();
    3338}
    3439
    3540/**
    36  * Rewrite the URLs for single properties
     41 * Rewrite the URLs for single properties. Add 404 redirect for detail page.
     42 *
     43 * @return void
    3744 */
    3845function exposify_rewrite()
     
    4047  $options = get_option('exposify_settings');
    4148  $slug = $options['exposify_site_slug'] ? $options['exposify_site_slug'] : 'immobilien';
    42   add_rewrite_rule('^' . $slug . '/(.+)/?$', 'index.php?page_id=' . get_option('exposify_properties_page_id') . '&slug=$matches[1]', 'top');
     49  add_rewrite_rule('^' . $slug . '/(.+)/?$', 'index.php?page_id=' . get_option('exposify_property_page_id') . '&slug=$matches[1]', 'top');
    4350  add_rewrite_tag('%slug%', '([^&]+)');
     51  add_rewrite_rule('^exposify-detail$', 'index.php?error=404', 'top');
    4452}
    4553
    4654/**
    4755 * Add a properties page and store its id. If there is already a saved id, delete it and add a new one.
     56 *
     57 * @return void
    4858 */
    49 function exposify_add_properties_page()
     59function exposify_add_all_pages()
    5060{
    5161  $options = get_option('exposify_settings');
    52   $pageTitle = ($options['exposify_site_title']) ? $options['exposify_site_title'] : 'Immobilien';
    53   $pageName  = ($options['exposify_site_slug'])  ? $options['exposify_site_slug']  : 'immobilien';
     62  $overviewTitle = ($options['exposify_site_title']) ? $options['exposify_site_title'] : 'Immobilien';
     63  $overviewSlug  = ($options['exposify_site_slug'])  ? $options['exposify_site_slug']  : 'immobilien';
    5464
     65  exposify_add_page($overviewTitle, $overviewSlug, 'exposify_overview_page_id');
     66  exposify_add_page('Exposify Detail', 'exposify-detail', 'exposify_property_page_id');
     67}
     68
     69/**
     70 * Add an Exposify page with title, slug and an option to store its id in the database.
     71 *
     72 * @param  string  $pageTitle
     73 * @param  string  $pageSlug
     74 * @param  string  $pageDatabaseOptionName
     75 * @return void
     76 */
     77function exposify_add_page($pageTitle, $pageSlug, $pageDatabaseOptionName)
     78{
    5579  $page = [
    5680    'post_content' => '',
    5781    'post_title'   => $pageTitle,
    58     'post_name'    => $pageName,
     82    'post_name'    => $pageSlug,
    5983    'post_status'  => 'publish',
    6084    'post_type'    => 'page'
    6185  ];
    6286
    63   $pageID = get_option('exposify_properties_page_id');
    64   if ($pageID) {
    65     wp_delete_post($pageID, true);
     87  $pageId = get_option($pageDatabaseOptionName);
     88  if ($pageId) {
     89    wp_delete_post($pageId, true);
    6690  }
    6791
    68   $pageID = wp_insert_post($page);
    69   update_option('exposify_properties_page_id', $pageID);
     92  $pageId = wp_insert_post($page);
     93  update_option($pageDatabaseOptionName, $pageId);
     94}
     95
     96/**
     97 * Delete an Exposify page with the option where its id is stored in the database.
     98 *
     99 * @param  string  $pageDatabaseOptionName
     100 * @return void
     101 */
     102function exposify_delete_page($pageDatabaseOptionName)
     103{
     104  $pageId = get_option($pageDatabaseOptionName);
     105  if ($pageId) {
     106    wp_delete_post($pageId, true);
     107  }
    70108}
    71109
  • exposify/trunk/public.php

    r1731185 r1755493  
    2424    add_filter('page_template',          [$this, 'changePageTemplate']);
    2525    add_action('wp_enqueue_scripts',     [$this, 'insertLinks']);
    26     add_filter('the_title',              [$this, 'changePageTitle']);
     26    add_filter('the_title',              [$this, 'changePageTitle'], 10, 2);
    2727    add_filter('pre_get_document_title', [$this, 'changeSiteTitle']);
    2828  }
     
    5252  public function changePageTemplate($oldTemplate)
    5353  {
    54     if (get_the_ID() != get_option('exposify_properties_page_id')) {
     54    if (
     55      get_the_ID() != get_option('exposify_overview_page_id') &&
     56      get_the_ID() != get_option('exposify_property_page_id')
     57    ) {
    5558      return $oldTemplate;
    5659    }
     
    7275  public function changePageContent($oldContent)
    7376  {
    74     if (get_the_ID() != get_option('exposify_properties_page_id')) {
     77    if (
     78      get_the_ID() != get_option('exposify_overview_page_id') &&
     79      get_the_ID() != get_option('exposify_property_page_id')
     80    ) {
    7581      return $oldContent;
    7682    }
     
    8187
    8288  /**
    83   * Change the page title to the property name.
     89  * Change the page title to the property name. We need to use the passed $pageId
     90  * here instead of the get_the_ID() method because it would return the same ID
     91  * for all titles. But we only want to change the main title of the detail page,
     92  * not of the other menu items.
    8493  *
    8594  * @param  string  $oldTitle
    8695  * @return string
    8796  */
    88   public function changePageTitle($oldTitle)
     97  public function changePageTitle($oldTitle, $pageId)
    8998  {
    9099    if (
    91100      !get_query_var('slug') ||
    92       get_the_ID() != get_option('exposify_properties_page_id') ||
    93       !in_the_loop()
     101      $pageId != get_option('exposify_property_page_id')
    94102    ) {
    95103      return $oldTitle;
     
    124132  public function insertLinks()
    125133  {
    126     if (get_the_ID() != get_option('exposify_properties_page_id')) {
     134    if (
     135      get_the_ID() != get_option('exposify_overview_page_id') &&
     136      get_the_ID() != get_option('exposify_property_page_id')
     137    ) {
    127138      return;
    128139    }
Note: See TracChangeset for help on using the changeset viewer.