$value) { if (strpos($name, 'apx') === 0) $post_meta[$name] = $value[0]; else unset($post_meta[$name]); } return $post_meta; } // Render the template in /templates with passed in `$data`. function template($file, $data = null) { if (is_array($data)) // Pass `$data` to the template through $_POST. foreach($data as $key => $value) $_POST[$key] = $value; $path = dirname(__DIR__)."/templates/$file.php"; if (file_exists($path)) require_once $path; return; } // Gets the applied values of the plugin settings. function get_plugin_settings() { $settings = plugin_settings(); // Fetch the stored value, or apply the default. foreach($settings as $key => $setting) { $name = $setting['name']; $value = get_option($name, $setting['default']); unset($settings[$key]); // Swap value to be scalar instead of object $settings[$name] = $value; } return $settings; } // Get the path to a plugin asset. function asset($name) { $path = plugins_url('advanced-pins') . "/assets/$name"; return $path; $message = 'Failed to load asset ' . $name; $message .= '\n This is the path generated: " ' . $path; cease($message); return ''; } // Shorcut to deterine if the page request is an Editor. function is_edit_page() { global $pagenow; if (!is_admin()) return false; $pages = ['post.php', 'post-new.php', 'page-new.php']; if (in_array($pagenow, $pages)) return true; if (isset($_GET['action']) && $_GET['action'] == 'edit') return true; if (isset($_GET['action2']) && $_GET['action2'] == 'edit') return true; return false; } function is_settings_page() { $page = isset($_GET['page']) ? $_GET['page'] : ''; return 'apx_settings' == $page; }