Skip to content

Commit

Permalink
Merge pull request #1121 from alleyinteractive/fix/issue-1002/path-tr…
Browse files Browse the repository at this point in the history
…aversal-plugin-activation-error

Convert all require/include statements to use __DIR__ and dirname()
  • Loading branch information
kevinfodness authored May 10, 2024
2 parents 100f022 + 07db972 commit a99bcf7
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 74 deletions.
6 changes: 3 additions & 3 deletions admin/apple-actions/class-api-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Apple_Actions;

require_once plugin_dir_path( __FILE__ ) . 'class-action.php';
require_once plugin_dir_path( __FILE__ ) . 'class-action-exception.php';
require_once plugin_dir_path( __FILE__ ) . '../../includes/apple-push-api/autoload.php';
require_once __DIR__ . '/class-action.php';
require_once __DIR__ . '/class-action-exception.php';
require_once dirname( __DIR__, 2 ) . '/includes/apple-push-api/autoload.php';

use Apple_Actions\Action;
use Apple_Push_API\API;
Expand Down
2 changes: 1 addition & 1 deletion admin/apple-actions/index/class-channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php';
require_once dirname( __DIR__ ) . '/class-api-action.php';

use Apple_Actions\API_Action;

Expand Down
2 changes: 1 addition & 1 deletion admin/apple-actions/index/class-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php';
require_once dirname( __DIR__ ) . '/class-api-action.php';

use Apple_Actions\API_Action;

Expand Down
6 changes: 3 additions & 3 deletions admin/apple-actions/index/class-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-action.php';
require_once plugin_dir_path( __FILE__ ) . '../class-action-exception.php';
require_once plugin_dir_path( __FILE__ ) . '../../../includes/apple-exporter/autoload.php';
require_once dirname( __DIR__ ) . '/class-action.php';
require_once dirname( __DIR__ ) . '/class-action-exception.php';
require_once dirname( __DIR__, 3 ) . '/includes/apple-exporter/autoload.php';

use Apple_Actions\Action;
use Apple_Exporter\Exporter;
Expand Down
2 changes: 1 addition & 1 deletion admin/apple-actions/index/class-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php';
require_once dirname( __DIR__ ) . '/class-api-action.php';

use Apple_Actions\API_Action;

Expand Down
4 changes: 2 additions & 2 deletions admin/apple-actions/index/class-push.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php';
require_once plugin_dir_path( __FILE__ ) . 'class-export.php';
require_once dirname( __DIR__ ) . '/class-api-action.php';
require_once __DIR__ . '/class-export.php';

use Admin_Apple_Async;
use Admin_Apple_Notice;
Expand Down
2 changes: 1 addition & 1 deletion admin/apple-actions/index/class-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Apple_Actions\Index;

require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php';
require_once dirname( __DIR__ ) . '/class-api-action.php';

use Apple_Actions\API_Action;
use Apple_Exporter\Settings;
Expand Down
4 changes: 2 additions & 2 deletions admin/class-admin-apple-bulk-export-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Include dependencies.
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-push.php';
require_once __DIR__ . '/apple-actions/index/class-push.php';

/**
* Bulk export page. Display progress on multiple articles export process.
Expand Down Expand Up @@ -105,7 +105,7 @@ public function build_page() {
}
}

require_once plugin_dir_path( __FILE__ ) . 'partials/page-bulk-export.php';
require_once __DIR__ . '/partials/page-bulk-export.php';
}

/**
Expand Down
14 changes: 7 additions & 7 deletions admin/class-admin-apple-index-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/

// Include dependencies.
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-get.php';
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-push.php';
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-delete.php';
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-export.php';
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-section.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-news-list-table.php';
require_once __DIR__ . '/apple-actions/index/class-get.php';
require_once __DIR__ . '/apple-actions/index/class-push.php';
require_once __DIR__ . '/apple-actions/index/class-delete.php';
require_once __DIR__ . '/apple-actions/index/class-export.php';
require_once __DIR__ . '/apple-actions/index/class-section.php';
require_once __DIR__ . '/class-admin-apple-news-list-table.php';

use Apple_Exporter\Workspace;

Expand Down Expand Up @@ -98,7 +98,7 @@ public function setup_admin_page() {
public function admin_page() {
$table = new Admin_Apple_News_List_Table( $this->settings );
$table->prepare_items();
include plugin_dir_path( __FILE__ ) . 'partials/page-index.php';
include __DIR__ . '/partials/page-index.php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/class-admin-apple-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function page_json_render() {
/* phpcs:enable */

// Load the template.
include plugin_dir_path( __FILE__ ) . 'partials/page-json.php';
include __DIR__ . '/partials/page-json.php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/class-admin-apple-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function publish_meta_box( $post ) {

/* phpcs:enable */

include plugin_dir_path( __FILE__ ) . 'partials/metabox-publish.php';
include __DIR__ . '/partials/metabox-publish.php';
}

/**
Expand Down
40 changes: 20 additions & 20 deletions admin/class-admin-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
*/

// Include dependencies.
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-settings.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-post-sync.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-index-page.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-bulk-export-page.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-notice.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-meta-boxes.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-async.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-sections.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-themes.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-preview.php';
require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-json.php';
require_once plugin_dir_path( __FILE__ ) . 'class-automation.php';
require_once __DIR__ . '/class-admin-apple-settings.php';
require_once __DIR__ . '/class-admin-apple-post-sync.php';
require_once __DIR__ . '/class-admin-apple-index-page.php';
require_once __DIR__ . '/class-admin-apple-bulk-export-page.php';
require_once __DIR__ . '/class-admin-apple-notice.php';
require_once __DIR__ . '/class-admin-apple-meta-boxes.php';
require_once __DIR__ . '/class-admin-apple-async.php';
require_once __DIR__ . '/class-admin-apple-sections.php';
require_once __DIR__ . '/class-admin-apple-themes.php';
require_once __DIR__ . '/class-admin-apple-preview.php';
require_once __DIR__ . '/class-admin-apple-json.php';
require_once __DIR__ . '/class-automation.php';

// REST Includes.
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-delete.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-get-published-state.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-get-settings.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-modify-post.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-publish.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-sections.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-update.php';
require_once plugin_dir_path( __FILE__ ) . '../includes/REST/apple-news-user-can-publish.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-delete.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-get-published-state.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-get-settings.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-modify-post.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-publish.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-sections.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-update.php';
require_once dirname( __DIR__ ) . '/includes/REST/apple-news-user-can-publish.php';

/**
* Entry-point class for the plugin.
Expand Down
2 changes: 1 addition & 1 deletion admin/class-admin-apple-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private static function show_notice( $message, $type ) {
$message = apply_filters( 'apple_news_notice_message', $message, $type );

// Load the partial for the notice.
include plugin_dir_path( __FILE__ ) . 'partials/notice.php';
include __DIR__ . '/partials/notice.php';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions admin/class-admin-apple-post-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

// Include dependencies.
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-push.php';
require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-delete.php';
require_once __DIR__ . '/apple-actions/index/class-push.php';
require_once __DIR__ . '/apple-actions/index/class-delete.php';

/**
* This class is in charge of syncing posts creation, updates and deletions
Expand Down
14 changes: 7 additions & 7 deletions admin/class-admin-apple-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

// Include dependencies.
require_once plugin_dir_path( __FILE__ ) . '../includes/apple-exporter/class-settings.php';
require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section.php';
require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-api.php';
require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-advanced.php';
require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-post-types.php';
require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-developer-tools.php';
require_once dirname( __DIR__ ) . '/includes/apple-exporter/class-settings.php';
require_once __DIR__ . '/settings/class-admin-apple-settings-section.php';
require_once __DIR__ . '/settings/class-admin-apple-settings-section-api.php';
require_once __DIR__ . '/settings/class-admin-apple-settings-section-advanced.php';
require_once __DIR__ . '/settings/class-admin-apple-settings-section-post-types.php';
require_once __DIR__ . '/settings/class-admin-apple-settings-section-developer-tools.php';

use Apple_Exporter\Settings;

Expand Down Expand Up @@ -168,7 +168,7 @@ public function page_options_render() {

/* phpcs:enable */

include plugin_dir_path( __FILE__ ) . 'partials/page-options.php';
include __DIR__ . '/partials/page-options.php';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions admin/class-admin-apple-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function page_theme_edit_render() {
/* phpcs:enable */

// Load the edit page.
include plugin_dir_path( __FILE__ ) . 'partials/page-theme-edit.php';
include __DIR__ . '/partials/page-theme-edit.php';
}

/**
Expand All @@ -332,7 +332,7 @@ public function page_themes_render() {
wp_die( esc_html__( 'You do not have permissions to access this page.', 'apple-news' ) );
}

include plugin_dir_path( __FILE__ ) . 'partials/page-themes.php';
include __DIR__ . '/partials/page-themes.php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion admin/partials/metabox-publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
</div>
<div id="apple-news-metabox-coverimage" class="apple-news-metabox-section apple-news-metabox-section-collapsable">
<h3><?php esc_html_e( 'Cover Image', 'apple-news' ); ?></h3>
<?php require plugin_dir_path( __FILE__ ) . 'cover-image.php'; ?>
<?php require __DIR__ . '/cover-image.php'; ?>
</div>
<?php
if ( 'yes' !== $this->settings->get( 'api_autosync' )
Expand Down
4 changes: 2 additions & 2 deletions admin/partials/page-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<?php $apple_section->before_section(); ?>
<?php
if ( $apple_section->is_hidden() ) {
include plugin_dir_path( __FILE__ ) . 'page-options-section-hidden.php';
include __DIR__ . '/page-options-section-hidden.php';
} else {
include plugin_dir_path( __FILE__ ) . 'page-options-section.php';
include __DIR__ . '/page-options-section.php';
}
$apple_section->after_section();
?>
Expand Down
12 changes: 6 additions & 6 deletions apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function apple_news_date( $format, $timestamp = null, $timezone = null ) {
return date( $format, $timestamp ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
}

require_once plugin_dir_path( __FILE__ ) . './includes/meta.php';
require_once __DIR__ . '/includes/meta.php';

if ( ! defined( 'WPINC' ) ) {
die;
Expand All @@ -57,7 +57,7 @@ function apple_news_activate_wp_plugin() {
}
}

require plugin_dir_path( __FILE__ ) . 'includes/apple-exporter/class-settings.php';
require __DIR__ . '/includes/apple-exporter/class-settings.php';

/**
* Deactivate the plugin.
Expand All @@ -76,16 +76,16 @@ function apple_news_uninstall_wp_plugin() {
}

// Initialize plugin class.
require plugin_dir_path( __FILE__ ) . 'includes/class-apple-news.php';
require plugin_dir_path( __FILE__ ) . 'admin/class-admin-apple-news.php';
require __DIR__ . '/includes/class-apple-news.php';
require __DIR__ . '/admin/class-admin-apple-news.php';

/**
* Load plugin textdomain.
*
* @since 0.9.0
*/
function apple_news_load_textdomain() {
load_plugin_textdomain( 'apple-news', false, plugin_dir_path( __FILE__ ) . '/lang' );
load_plugin_textdomain( 'apple-news', false, __DIR__ . '/lang' );
}
add_action( 'plugins_loaded', 'apple_news_load_textdomain' );

Expand All @@ -101,7 +101,7 @@ function apple_news_get_plugin_data() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return get_plugin_data( plugin_dir_path( __FILE__ ) . '/apple-news.php' );
return get_plugin_data( __DIR__ . '/apple-news.php' );
}

new Admin_Apple_News();
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-exporter/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function ( $class ) {
$path = explode( '\\', $path );
$file = array_pop( $path );
$path = implode( '/', $path ) . '/class-' . $file . '.php';
$path = realpath( __DIR__ . '/../' . $path );
$path = realpath( dirname( __DIR__ ) . '/' . $path );

if ( file_exists( $path ) ) {
require_once $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-exporter/builders/class-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Apple_Exporter\Builders;

require_once plugin_dir_path( __FILE__ ) . '../../../admin/class-admin-apple-news.php';
require_once dirname( __DIR__, 3 ) . '/admin/class-admin-apple-news.php';

use Admin_Apple_News;
use Apple_Exporter\Exporter_Content;
Expand Down
5 changes: 2 additions & 3 deletions includes/apple-exporter/class-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public static function get_active_theme_name() {
*/
public static function get_fonts() {
// Get custom fonts from this channel.
require_once plugin_dir_path( __DIR__ ) . '../admin/apple-actions/index/class-channel.php';
require_once dirname( __DIR__, 2 ) . '/admin/apple-actions/index/class-channel.php';
$admin_settings = new \Admin_Apple_Settings();
$channel_api = new \Apple_Actions\Index\Channel( $admin_settings->fetch_settings() );
$channel = $channel_api->perform();
Expand Down Expand Up @@ -499,8 +499,7 @@ public static function render_meta_component_order( $theme ) {
/* phpcs:enable */

// Load the template.
include dirname( dirname( plugin_dir_path( __FILE__ ) ) )
. '/admin/partials/field-meta-component-order.php';
include dirname( __DIR__, 2 ) . '/admin/partials/field-meta-component-order.php';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-exporter/components/class-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Apple_Exporter\Components;

require_once __DIR__ . '/../class-markdown.php';
require_once dirname( __DIR__ ) . '/class-markdown.php';

use Apple_Exporter\Builders\Component_Layouts;
use Apple_Exporter\Builders\Component_Styles;
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-push-api/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function ( $class ) {
$path = explode( '\\', $path );
$file = array_pop( $path );
$path = implode( '/', $path ) . '/class-' . $file . '.php';
$path = realpath( __DIR__ . '/../' . $path );
$path = realpath( dirname( __DIR__ ) . '/' . $path );

if ( file_exists( $path ) ) {
require_once $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
Expand Down
2 changes: 1 addition & 1 deletion includes/apple-push-api/request/class-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Apple_Push_API\MIME_Builder;
use WP_Error;

require_once __DIR__ . '/../class-mime-builder.php';
require_once dirname( __DIR__ ) . '/class-mime-builder.php';

/**
* An object capable of sending signed HTTP requests to the Push API.
Expand Down
Loading

0 comments on commit a99bcf7

Please sign in to comment.