Esempio n. 1
0
 private function addMenu()
 {
     if (User::isUserLoggedIn() && User::currentUserCan('edit_themes')) {
         \add_action('admin_menu', [$this, 'addPage'], 2);
         \add_filter('plugin_action_links', [$this, 'filterActionLink'], 10, 2);
     }
 }
Esempio n. 2
0
 public static function createPage(array $pages)
 {
     if (!User::currentUserCan('manage_options')) {
         return false;
     }
     foreach ($pages as $pagePath => $v) {
         static::getPageByPath($pagePath) || \wp_insert_post(array_merge(['post_content' => '', 'post_name' => null, 'post_title' => null, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed'], $v));
     }
 }
Esempio n. 3
0
 public function ajaxProcessLogged()
 {
     Security::checkNonce();
     Security::checkReferer();
     if (!User::currentUserCan('manage_options')) {
         die;
     }
     $mainApi = new MainApi();
     if ($mainApi->deleteCacheFile()) {
         die('Done!');
     }
     die(sprintf(L10n::__('Can not delete file %s.'), $mainApi->getCacheFilePath()));
 }
Esempio n. 4
0
 public function initUpdate()
 {
     if (!User::currentUserCan('manage_options')) {
         return;
     }
     $this->setRelativeFile();
     \add_filter('site_transient_update_plugins', [$this, 'checkForUpdate'], 1);
     \add_filter('plugins_api', [$this, 'filterPluginsApi'], 10, 3);
     \add_filter('upgrader_source_selection', [$this, 'filterUpgraderSourceSelection'], 10, 3);
     \add_filter('upgrader_pre_install', [$this, 'filterUpgraderPreInstall'], 10, 2);
     //\add_filter('upgrader_post_install', [$this, 'filterFlushOpcache']);
     \add_filter('upgrader_post_install', [$this, 'filterUpgraderPostInstall'], 10, 3);
 }
Esempio n. 5
0
 protected function setAjaxLogged($actionName = null, $method = 'ajaxProcessLogged')
 {
     if (!Condition::isAjax() || !User::isUserLoggedIn()) {
         return;
     }
     if (!$actionName) {
         $actionName = static::getOptID();
     }
     $actionName = Functions::buildActionName($actionName);
     \add_action("wp_ajax_{$actionName}", [$this, $method]);
 }
Esempio n. 6
0
 public static function getPermalink($postID, $leavename = false)
 {
     static $cache = [];
     if (isset($cache[$postID])) {
         return $cache[$postID];
     }
     global $post;
     if (!isset($post->ID) || $post->ID != $postID) {
         $p = static::getPost($postID);
     } else {
         $p = $post;
     }
     $rewritecode = ['%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%'];
     if ($p->post_type == 'page') {
         return Url::esc(\get_page_link($p, $leavename));
     } elseif ($p->post_type == 'attachment') {
         return Url::esc(\get_attachment_link($p, $leavename));
     } elseif (in_array($p->post_type, \get_post_types(['_builtin' => false]))) {
         return Url::esc(\get_post_permalink($p, $leavename));
     }
     $permalink = Other::getOption('permalink_structure');
     $permalink = \apply_filters('pre_post_link', $permalink, $p, $leavename);
     if ('' != $permalink && !in_array($p->post_status, ['draft', 'pending', 'auto-draft', 'future'])) {
         $unixtime = strtotime($p->post_date);
         $category = '';
         if (strpos($permalink, '%category%') !== false) {
             $cats = Category::getTheCategory($p->ID);
             if ($cats) {
                 usort($cats, '_usort_terms_by_ID');
                 // order by ID
                 /**
                  * Filter the category that gets used in the %category% permalink token.
                  *
                  * @since 3.5.0
                  *
                  * @param stdClass $cat  The category to use InnStudio\Poil10n\in the permalink.
                  * @param array    $cats Array of all categories associated with the post.
                  * @param WP_Post  $post The post in question.
                  */
                 $category_object = \apply_filters('post_link_category', $cats[0], $cats, $p);
                 $category_object = \get_term($category_object, 'category');
                 $category = $category_object->slug;
                 if ($parent = $category_object->parent) {
                     $category = \get_category_parents($parent, false, '/', true) . $category;
                 }
             }
             // show default category in permalinks, without
             // having to assign it explicitly
             if (empty($category)) {
                 $default_category = \get_term(Other::getOption('default_category'), 'category');
                 $category = \is_wp_error($default_category) ? '' : $default_category->slug;
             }
         }
         $author = '';
         if (strpos($permalink, '%author%') !== false) {
             $authordata = User::getUserdata($p->post_author);
             $author = $authordata->user_nicename;
         }
         $date = explode(" ", date('Y m d H i s', $unixtime));
         $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $p->post_name, $p->ID, $category, $author, $p->post_name);
         $permalink = Url::getHome(str_replace($rewritecode, $rewritereplace, $permalink));
         $permalink = \user_trailingslashit($permalink, 'single');
     } else {
         // if they're not using the fancy permalink option
         $permalink = Url::getHome() . '?p=' . $p->ID;
     }
     /**
      * Filter the permalink for a post.
      *
      * Only applies to posts with post_type of 'post'.
      *
      * @since 1.5.0
      *
      * @param string  $permalink The post's permalink.
      * @param WP_Post $post      The post in question.
      * @param bool    $leavename Whether to keep the post name.
      */
     $cache[$postID] = Url::esc(\apply_filters('post_link', $permalink, $p, $leavename));
     unset($p);
     return $cache[$postID];
 }
Esempio n. 7
0
 public static function isUserLoggedIn()
 {
     return User::isUserLoggedIn();
 }