permalink-manager-actions.php
4 years ago
permalink-manager-admin-functions.php
4 years ago
permalink-manager-core-functions.php
4 years ago
permalink-manager-debug.php
4 years ago
permalink-manager-gutenberg.php
4 years ago
permalink-manager-helper-functions.php
4 years ago
permalink-manager-language-plugins.php
4 years ago
permalink-manager-third-parties.php
4 years ago
permalink-manager-uri-functions-post.php
4 years ago
permalink-manager-uri-functions.php
4 years ago
permalink-manager-uri-functions.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Functions used to create, edit and remove custom permalinks |
| 5 | */ |
| 6 | class Permalink_Manager_URI_Functions extends Permalink_Manager_Class { |
| 7 | |
| 8 | public function __construct() { |
| 9 | |
| 10 | } |
| 11 | |
| 12 | public static function get_single_uri_key($element_id, $is_tax = false) { |
| 13 | // Check if the element ID is numeric |
| 14 | if(empty($element_id) || !is_numeric($element_id)) { return; } |
| 15 | |
| 16 | if($is_tax) { |
| 17 | $element_id = "tax-{$element_id}"; |
| 18 | } |
| 19 | |
| 20 | return $element_id; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Save URI to the custom permalinks array |
| 25 | */ |
| 26 | public static function save_single_uri($element, $element_uri = null, $is_tax = false, $db_save = false) { |
| 27 | global $permalink_manager_uris; |
| 28 | |
| 29 | // Get the element key |
| 30 | $element_key = self::get_single_uri_key($element, $is_tax); |
| 31 | |
| 32 | // Save the custom permalink if the URI is not empty |
| 33 | if(!empty($element_key) && !empty($element_uri)) { |
| 34 | $permalink_manager_uris[$element_key] = Permalink_Manager_Helper_Functions::sanitize_title($element_uri, true); |
| 35 | |
| 36 | if($db_save) { |
| 37 | self::save_all_uris($permalink_manager_uris); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Remove URI to the custom permalinks array |
| 44 | */ |
| 45 | public static function remove_single_uri($element, $is_tax = false, $db_save = false) { |
| 46 | global $permalink_manager_uris; |
| 47 | |
| 48 | // Get the element key |
| 49 | $element_key = self::get_single_uri_key($element, $is_tax); |
| 50 | |
| 51 | // Check if the custom permalink is assigned to this post |
| 52 | if(!empty($element_key) && isset($permalink_manager_uris[$element_key])) { |
| 53 | unset($permalink_manager_uris[$element_key]); |
| 54 | } |
| 55 | |
| 56 | if($db_save) { |
| 57 | self::save_all_uris($permalink_manager_uris); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Save the array with custom permalinks |
| 63 | */ |
| 64 | public static function save_all_uris($updated_uris = null) { |
| 65 | if(is_null($updated_uris)) { |
| 66 | global $permalink_manager_uris; |
| 67 | $updated_uris = $permalink_manager_uris; |
| 68 | } |
| 69 | |
| 70 | if(is_array($updated_uris) && !empty($updated_uris)) { |
| 71 | update_option('permalink-manager-uris', $updated_uris); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | |
| 77 | ?> |
| 78 |