Completed
Pull Request — master (#1348)
by
unknown
05:47
created

Sensei_Main::get_settings_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4
/**
5
 * Responsible for loading Sensei and setting up the Main WordPress hooks.
6
 *
7
 * @package Core
8
 * @author Automattic
9
 * @since 1.0.0
10
 */
11
class Sensei_Main {
12
13
    /**
14
     * @var string
15
     * Reference to the main plugin file
16
     */
17
    private $file;
18
19
    /**
20
     * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
21
     * @since 1.8.0
22
     */
23
    protected static $_instance = null;
24
25
    /**
26
     * Main reference to the plugins current version
27
     */
28
    public $version;
29
30
    /**
31
     * Public token, referencing for the text domain.
32
     */
33
    public $token = 'woothemes-sensei';
34
35
    /**
36
     * Plugin url and path for use when access resources.
37
     */
38
    public $plugin_url;
39
    public $plugin_path;
40
    public $template_url;
41
42
    /**
43
     * @var Sensei_PostTypes
44
     * All Sensei sub classes. Currently used to access functionality contained within
45
     * within Sensei sub classes e.g. Sensei()->course->all_courses()
46
     */
47
    public $post_types;
48
49
    /**
50
     * @var WooThemes_Sensei_Settings
51
     */
52
    public $settings;
53
54
    /**
55
     * @var WooThemes_Sensei_Course_Results
56
     */
57
    public $course_results;
58
59
    /**
60
     * @var Sensei_Updates
61
     */
62
    public $updates;
63
    /**
64
     * @var WooThemes_Sensei_Course
65
     */
66
    public $course;
67
68
    /**
69
     * @var WooThemes_Sensei_Lesson
70
     */
71
    public $lesson;
72
73
    /**
74
     * @var WooThemes_Sensei_Quiz
75
     */
76
    public $quiz;
77
78
    /**
79
     * @var WooThemes_Sensei_Question
80
     */
81
    public $question;
82
83
    /**
84
     * @var WooThemes_Sensei_Admin
85
     */
86
    public $admin;
87
88
    /**
89
     * @var WooThemes_Sensei_Frontend
90
     */
91
    public $frontend;
92
93
    /**
94
     * @var Sensei_Notices
95
     */
96
    public $notices;
97
98
    /**
99
     * @var WooThemes_Sensei_Grading
100
     */
101
    public $grading;
102
103
    /**
104
     * @var WooThemes_Sensei_Emails
105
     */
106
    public $emails;
107
108
    /**
109
     * @var WooThemes_Sensei_Learner_Profiles
110
     */
111
    public $learner_profiles;
112
113
    /**
114
     * @var Sensei_Teacher
115
     */
116
    public $teacher;
117
118
    /**
119
     * @var WooThemes_Sensei_Learners
120
     */
121
    public $learners;
122
123
    /**
124
     * @var array
125
     * Global instance for access to the permissions message shown
126
     * when users do not have the right privileges to access resources.
127
     */
128
    public $permissions_message;
129
130
    /**
131
     * @var Sensei_Core_Modules Sensei Modules functionality
132
     */
133
    public $modules;
134
135
    /**
136
     * @var Sensei_Analysis
137
     */
138
    public $analysis;
139
140
    /**
141
     * @var $id
142
     */
143
    private $id;
144
145
    /**
146
     * Constructor method.
147
     * @param  string $file The base file of the plugin.
148
     * @since  1.0.0
149
     */
150
    public function __construct ( $file ) {
151
152
        // Setup object data
153
        $this->file = $file;
154
        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
155
        $this->plugin_path = trailingslashit( dirname( $file ) );
156
        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
157
158
        // Initialize the core Sensei functionality
159
        $this->init();
160
161
        // Installation
162
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
163
164
        // Run this on activation.
165
        register_activation_hook( $this->file, array( $this, 'activation' ) );
166
167
        // Image Sizes
168
        $this->init_image_sizes();
169
170
        // load all hooks
171
        $this->load_hooks();
172
173
    } // End __construct()
174
175
    /**
176
     * Load the foundations of Sensei.
177
     * @since 1.9.0
178
     */
179
    protected function init(){
180
181
        // Localisation
182
        $this->load_plugin_textdomain();
183
        add_action( 'init', array( $this, 'load_localisation' ), 0 );
184
185
        // Setup settings
186
        $this->settings = new Sensei_Settings();
187
188
        // load the shortcode loader into memory, so as to listen to all for
189
        // all shortcodes on the front end
190
        new Sensei_Shortcode_Loader();
191
192
    }
193
194
    /**
195
     * Global Sensei Instance
196
     *
197
     * Ensure that only one instance of the main Sensei class can be loaded.
198
     *
199
     * @since 1.8.0
200
     * @static
201
     * @see WC()
202
     * @return WooThemes_Sensei Instance.
203
     */
204
    public static function instance() {
205
206
        if ( is_null( self::$_instance ) ) {
207
208
            //Sensei requires a reference to the main Sensei plugin file
209
            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
210
211
            self::$_instance = new self( $sensei_main_plugin_file  );
212
213
            // load the global class objects needed throughout Sensei
214
            self::$_instance->initialize_global_objects();
215
216
        }
217
218
        return self::$_instance;
219
220
    } // end instance()
221
222
    /**
223
     * This function is linked into the activation
224
     * hook to reset flush the urls to ensure Sensei post types show up.
225
     *
226
     * @since 1.9.0
227
     *
228
     * @param $plugin
229
     */
230
    public static function activation_flush_rules( $plugin ){
231
232
        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
233
234
            flush_rewrite_rules(true);
235
236
        }
237
238
    }
239
240
    /**
241
     * Cloning is forbidden.
242
     * @since 1.8.0
243
     */
244
    public function __clone() {
245
        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
246
    }
247
248
    /**
249
     * Unserializing instances of this class is forbidden.
250
     * @since 1.8.0
251
     */
252
    public function __wakeup() {
253
        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '1.8' );
254
    }
255
256
    /**
257
     * Load the properties for the main Sensei object
258
     *
259
     * @since 1.9.0
260
     */
261
    public function initialize_global_objects(){
262
263
        // Setup post types.
264
        $this->post_types = new Sensei_PostTypes();
265
266
        // Lad the updates class
267
        $this->updates = new Sensei_Updates( $this );
0 ignored issues
show
Documentation introduced by
$this is of type this<Sensei_Main>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
269
        // Load Course Results Class
270
        $this->course_results = new Sensei_Course_Results();
271
272
        // Load the teacher role
273
        $this->teacher = new Sensei_Teacher();
274
275
        // Add the Course class
276
        $this->course = $this->post_types->course;
0 ignored issues
show
Documentation Bug introduced by
$this->post_types->course is of type object<Sensei_Course>, but the property $course was declared to be of type object<WooThemes_Sensei_Course>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
277
278
        // Add the lesson class
279
        $this->lesson = $this->post_types->lesson;
0 ignored issues
show
Documentation Bug introduced by
$this->post_types->lesson is of type object<Sensei_Lesson>, but the property $lesson was declared to be of type object<WooThemes_Sensei_Lesson>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
280
281
        // Add the question class
282
        $this->question = $this->post_types->question;
0 ignored issues
show
Documentation Bug introduced by
$this->post_types->question is of type object<Sensei_Question>, but the property $question was declared to be of type object<WooThemes_Sensei_Question>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
283
284
        //Add the quiz class
285
        $this->quiz = $this->post_types->quiz;
0 ignored issues
show
Documentation Bug introduced by
$this->post_types->quiz is of type object<Sensei_Quiz>, but the property $quiz was declared to be of type object<WooThemes_Sensei_Quiz>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
286
287
        // load the modules class after all plugsin are loaded
288
	    $this->load_modules_class();
289
290
        // Load Learner Management Functionality
291
        $this->learners = new Sensei_Learner_Management( $this->file );
292
293
        // Differentiate between administration and frontend logic.
294
        if ( is_admin() ) {
295
296
            // Load Admin Welcome class
297
            new Sensei_Welcome();
298
299
            // Load Admin Class
300
            $this->admin = new Sensei_Admin( $this->file );
0 ignored issues
show
Unused Code introduced by
The call to Sensei_Admin::__construct() has too many arguments starting with $this->file.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
301
302
            // Load Analysis Reports
303
            $this->analysis = new Sensei_Analysis( $this->file );
304
305
        } else {
306
307
            // Load Frontend Class
308
            $this->frontend = new Sensei_Frontend();
309
310
            // Load notice Class
311
            $this->notices = new Sensei_Notices();
312
313
            // Load built in themes support integration
314
            new Sensei_Theme_Integration_Loader();
315
316
317
        }
318
319
        // Load Grading Functionality
320
        $this->grading = new Sensei_Grading( $this->file );
321
322
        // Load Email Class
323
        $this->emails = new Sensei_Emails( $this->file );
324
325
        // Load Learner Profiles Class
326
        $this->learner_profiles = new Sensei_Learner_Profiles();
327
328
    }
329
330
    /**
331
     * Initialize all Sensei hooks
332
     *
333
     * @since 1.9.0
334
     */
335
    public function load_hooks(){
336
337
        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
338
        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
339
340
        // Filter comment counts
341
        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
342
343
        add_action( 'body_class', array( $this, 'body_class' ) );
344
345
        // Check for and activate JetPack LaTeX support
346
        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
347
348
        // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
349
        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
350
351
        // Add plugin action links filter
352
        add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'plugin_action_links' ) );
353
354
    }
355
356
    /**
357
     * Run Sensei updates.
358
     * @access  public
359
     * @since   1.1.0
360
     * @return  void
361
     */
362
    public function run_updates() {
363
        // Run updates if administrator
364
        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
365
366
            $this->updates->update();
367
368
        } // End If Statement
369
    } // End run_updates()
370
371
    /**
372
     * Register the widgets.
373
     * @access public
374
     * @since  1.0.0
375
     * @return void
376
     */
377
    public function register_widgets () {
378
        // Widget List (key => value is filename => widget class).
379
        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
380
                'lesson-component' 	=> 'Lesson_Component',
381
                'course-categories' => 'Course_Categories',
382
                'category-courses' 	=> 'Category_Courses' )
383
        );
384
        foreach ( $widget_list as $key => $value ) {
385
            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
386
                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
387
                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
388
            }
389
        } // End For Loop
390
391
        do_action( 'sensei_register_widgets' );
392
393
    } // End register_widgets()
394
395
    /**
396
     * Load the plugin's localisation file.
397
     * @access public
398
     * @since  1.0.0
399
     * @return void
400
     */
401
    public function load_localisation () {
402
403
        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
404
405
    } // End load_localisation()
406
407
    /**
408
     * Load the plugin textdomain from the main WordPress "languages" folder.
409
     * @access  public
410
     * @since   1.0.0
411
     * @return  void
412
     */
413
    public function load_plugin_textdomain () {
414
415
        $domain = 'woothemes-sensei';
416
        // The "plugin_locale" filter is also used in load_plugin_textdomain()
417
        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
418
        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
419
        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
420
421
    } // End load_plugin_textdomain()
422
423
    /**
424
     * Run on activation.
425
     * @access public
426
     * @since  1.0.0
427
     * @return void
428
     */
429
    public function activation () {
430
431
        $this->register_plugin_version();
432
433
    } // End activation()
434
435
436
    /**
437
     * Register activation hooks.
438
     * @access public
439
     * @since  1.0.0
440
     * @return void
441
     */
442
    public function install () {
443
444
        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
445
        register_activation_hook( $this->file, 'flush_rewrite_rules' );
446
447
    } // End install()
448
449
450
    /**
451
     * Run on activation of the plugin.
452
     * @access public
453
     * @since  1.0.0
454
     * @return void
455
     */
456
    public function activate_sensei () {
457
458
        update_option( 'skip_install_sensei_pages', 0 );
459
        update_option( 'sensei_installed', 1 );
460
461
    } // End activate_sensei()
462
463
    /**
464
     * Register the plugin's version.
465
     * @access public
466
     * @since  1.0.0
467
     * @return void
468
     */
469
    private function register_plugin_version () {
470
        if ( $this->version != '' ) {
471
472
            update_option( 'woothemes-sensei-version', $this->version );
473
474
        }
475
    } // End register_plugin_version()
476
477
    /**
478
     * Ensure that "post-thumbnails" support is available for those themes that don't register it.
479
     * @access  public
480
     * @since   1.0.1
481
     * @return  void
482
     */
483
    public function ensure_post_thumbnails_support () {
484
485
        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
486
487
    } // End ensure_post_thumbnails_support()
488
489
    /**
490
     * template_loader function.
491
     *
492
     * @access public
493
     * @param mixed $template
494
     * @return void
495
     * @deprecated
496
     */
497
    public function template_loader ( $template = '' ) {
498
499
        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
500
        Sensei_Templates::template_loader( $template );
501
502
    } // End template_loader()
503
504
    /**
505
     * Determine the relative path to the plugin's directory.
506
     * @access public
507
     * @since  1.0.0
508
     * @return string $sensei_plugin_path
509
     */
510
    public function plugin_path () {
511
512
        if ( $this->plugin_path ) {
513
514
            $sensei_plugin_path =  $this->plugin_path;
515
516
        }else{
517
518
            $sensei_plugin_path = plugin_dir_path( __FILE__ );
519
520
        }
521
522
        return $sensei_plugin_path;
523
524
    } // End plugin_path()
525
526
    /**
527
     * Retrieve the ID of a specified page setting.
528
     * @access public
529
     * @since  1.0.0
530
     * @param  string $page
531
     * @return int
532
     */
533
    public function get_page_id ( $page ) {
534
        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
535
        return ( $page ) ? $page : -1;
536
    } // End get_page_id()
537
538
    /**
539
     * check_user_permissions function.
540
     *
541
     * @access public
542
     * @param string $page (default: '')
543
     *
544
     * @return bool
545
     */
546
    public function check_user_permissions ( $page = '' ) {
547
548
        global $current_user, $post;
549
550
        $user_allowed = false;
551
552
        switch ( $page ) {
553
	        case 'course-single':
554
		        // check for prerequisite course or lesson,
555
		        $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true );
556
		        $update_course          = Sensei_WC::course_update( $post->ID );
0 ignored issues
show
Unused Code introduced by
$update_course is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
557
558
		        // Count completed lessons
559
		        if ( 0 < absint( $course_prerequisite_id ) ) {
560
561
			        $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
562
563
		        } else {
564
			        $prerequisite_complete = true;
565
		        } // End If Statement
566
567
		        // Handles restrictions on the course
568
		        if ( ( ! $prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) ) {
569
570
			        $user_allowed = false;
571
			        $course_link  = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
572
			        $this->notices->add_notice( sprintf( __( 'Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ), 'info' );
573
574
		        } elseif( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) && ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID )  ) {
575
576
			        $message = sprintf( __( 'Or %1$s login %2$s to access your purchased courses', 'woothemes-sensei' ), '<a href="'.sensei_user_login_url().'">', '</a>' );
577
			        $this->notices->add_notice( $message, 'info' );
578
579
580
		        } elseif ( ! Sensei_Utils::user_started_course( $post->ID, $current_user->ID )  ) {
581
582
					// users who haven't started the course are allowed to view it
583
			        $user_allowed                         = true;
584
585
586
587
		        } else  {
588
589
                    $user_allowed = true;
590
591
                } // End If Statement
592
                break;
593
            case 'lesson-single':
594
                // Check for WC purchase
595
                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
596
597
                $update_course = Sensei_WC::course_update( $lesson_course_id );
0 ignored issues
show
Unused Code introduced by
$update_course is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
598
                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
599
600
                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
601
                    $user_allowed = true;
602
                } elseif( $this->access_settings() && false == $is_preview ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
603
604
                    $user_allowed = true;
605
606
                } else {
607
                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
608
                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
609
                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
610
                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
611 View Code Duplication
                        if ( $is_preview ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
612
                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
613
                        } else {
614
                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
615
                        }
616 View Code Duplication
                    } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
617
                        if ( $is_preview ) {
618
                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
619
                        } else {
620
                            /** This filter is documented in class-woothemes-sensei-frontend.php */
621
                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
622
                        }
623
                    } // End If Statement
624
                } // End If Statement
625
                break;
626
            case 'quiz-single':
627
                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
628
                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
629
630
                $update_course = Sensei_WC::course_update( $lesson_course_id );
0 ignored issues
show
Unused Code introduced by
$update_course is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
631
                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
632
633
                    // Check for prerequisite lesson for this quiz
634
                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
635
                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
636
637
                    // Handle restrictions
638
                    if( sensei_all_access() ) {
639
640
                        $user_allowed = true;
641
642
                    } else {
643
644
                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
645
646
                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
647
                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
648
                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
649
650
                        } else {
651
652
                            $user_allowed = true;
653
654
                        } // End If Statement
655
                    } // End If Statement
656
                } elseif( $this->access_settings() ) {
657
                    // Check if the user has started the course
658
659
                    if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
660
661
                        $user_allowed = false;
662
                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
663
                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
664
                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
665 View Code Duplication
                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
666
                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
667
                        } else {
668
                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
669
                        } // End If Statement
670
                    } else {
671
                        $user_allowed = true;
672
                    } // End If Statement
673
                } else {
674
                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
675
                    $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
676
                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
677
                } // End If Statement
678
                break;
679
            default:
680
                $user_allowed = true;
681
                break;
682
683
        } // End Switch Statement
684
685
        /**
686
         * filter the permissions message shown on sensei post types.
687
         *
688
         * @since 1.8.7
689
         *
690
         * @param array $permissions_message{
691
         *
692
         *   @type string $title
693
         *   @type string $message
694
         *
695
         * }
696
         * @param string $post_id
697
         */
698
        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
699
700
		// add the permissions message to the stack
701
702
        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
703
            $user_allowed = true;
704
        }
705
706
        /**
707
         * Filter the permissions check final result. Which determines if the user has
708
         * access to the given page.
709
         *
710
         * @since 1.0
711
         *
712
         * @param boolean $user_allowed
713
         * @param integer $user_id
714
         *
715
         */
716
        return apply_filters( 'sensei_access_permissions', $user_allowed, $current_user->ID );
717
718
    } // End get_placeholder_image()
719
720
721
    /**
722
     * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
723
     * @since  1.0.0
724
     * @access public
725
     * @return bool
726
     */
727
    public function access_settings () {
728
729
        if( sensei_all_access() ) return true;
730
731
        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
732
            if ( is_user_logged_in() ) {
733
                return true;
734
            } else {
735
                return false;
736
            } // End If Statement
737
        } else {
738
            return true;
739
        } // End If Statement
740
    } // End access_settings()
741
742
    /**
743
     * load_class loads in class files
744
     * @since   1.2.0
745
     * @access  public
746
     * @return  void
747
     */
748
    public function load_class ( $class_name = '' ) {
749
        if ( '' != $class_name && '' != $this->token ) {
750
            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
751
        } // End If Statement
752
    } // End load_class()
753
754
    /**
755
     * Filtering wp_count_comments to ensure that Sensei comments are ignored
756
     * @since   1.4.0
757
     * @access  public
758
     * @param  array   $comments
759
     * @param  integer $post_id
760
     * @return array
761
     */
762
    public function sensei_count_comments( $comments, $post_id ) {
763
        global $wpdb;
764
765
        $post_id = (int) $post_id;
766
767
        $count = wp_cache_get("comments-{$post_id}", 'counts');
768
769
        if ( false !== $count ) {
770
            return $count;
771
        }
772
773
        $statuses = array( '' ); // Default to the WP normal comments
774
        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
775
        foreach ( (array) $stati AS $status ) {
776
            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
777
                $statuses[] = $status['comment_type'];
778
            }
779
        }
780
        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
781
782
        if ( $post_id > 0 )
783
            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
784
785
        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
786
787
        $total = 0;
788
        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
789
        foreach ( (array) $count as $row ) {
790
            // Don't count post-trashed toward totals
791
            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
792
                $total += $row['num_comments'];
793
            if ( isset( $approved[$row['comment_approved']] ) )
794
                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
795
        }
796
797
        $stats['total_comments'] = $total;
798
        foreach ( $approved as $key ) {
799
            if ( empty($stats[$key]) )
800
                $stats[$key] = 0;
801
        }
802
803
        $stats = (object) $stats;
804
        wp_cache_set("comments-{$post_id}", $stats, 'counts');
805
806
        return $stats;
807
    }
808
809
    /**
810
     * Init images.
811
     *
812
     * @since 1.4.5
813
     * @access public
814
     * @return void
815
     */
816
    public function init_image_sizes() {
817
        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
818
        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
819
        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
820
        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
821
822
        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
823
        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
824
        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
825
        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
826
    }
827
828
    /**
829
     * Get an image size.
830
     *
831
     * Variable is filtered by sensei_get_image_size_{image_size}
832
     *
833
     * @since 1.4.5
834
     * @access public
835
     * @param mixed $image_size
836
     * @return string
837
     */
838
    public function get_image_size( $image_size ) {
839
840
        // Only return sizes we define in settings
841
        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
842
            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
843
844
        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
845
            $this->settings->settings[ $image_size . '_width' ] = false;
846
        }
847
        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
848
            $this->settings->settings[ $image_size . '_height' ] = false;
849
        }
850
        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
851
            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
852
        }
853
854
        $size = array_filter( array(
855
            'width' => $this->settings->settings[ $image_size . '_width' ],
856
            'height' => $this->settings->settings[ $image_size . '_height' ],
857
            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
858
        ) );
859
860
        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
861
        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
862
        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
863
864
        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
865
    }
866
867
    public function body_class( $classes ) {
868
        if( is_sensei() ) {
869
            $classes[] = 'sensei';
870
        }
871
        return $classes;
872
    }
873
874
    /**
875
     * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
876
     *
877
     * @return null
878
     * @since 1.7.0
879
     */
880
    public function jetpack_latex_support() {
881
        if ( function_exists( 'latex_markup') ) {
882
            add_filter( 'sensei_question_title', 'latex_markup' );
883
            add_filter( 'sensei_answer_text', 'latex_markup' );
884
        }
885
    }
886
887
    /**
888
     * Load the module functionality.
889
     *
890
     * This function is hooked into plugins_loaded to avoid conflicts with
891
     * the retired modules extension.
892
     *
893
     * @since 1.8.0
894
     */
895
    public function load_modules_class(){
896
        global $sensei_modules;
897
898
        if( !class_exists( 'Sensei_Modules' )
899
            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
900
901
            //Load the modules class
902
            require_once( 'class-sensei-modules.php');
903
            Sensei()->modules = new Sensei_Core_Modules( $this->file );
904
905
        }else{
906
            // fallback for people still using the modules extension.
907
            global $sensei_modules;
908
            Sensei()->modules = $sensei_modules;
909
            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
910
        }
911
    }
912
913
    /**
914
     * Tell the user to that the modules extension is no longer needed.
915
     *
916
     * @since 1.8.0
917
     */
918
    public function disable_sensei_modules_extension(){ ?>
919
        <div class="notice updated fade">
920
            <p>
921
                <?php
922
                $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
923
                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
924
                ?>
925
                <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
926
                Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
927
            </p>
928
        </div>
929
930
    <?php }// end function
931
932
    /**
933
     * Sensei wide rewrite flush call.
934
     *
935
     * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
936
     *
937
     * After the option is one the Rules will be flushed.
938
     *
939
     * @since 1.9.0
940
     */
941
    public function flush_rewrite_rules(){
942
943
        // ensures that the rewrite rules are flushed on the second
944
        // attempt. This ensure that the settings for any other process
945
        // have been completed and saved to the database before we refresh the
946
        // rewrite rules.
947
        $option =  get_option('sensei_flush_rewrite_rules');
948
        if( '1' == $option ) {
949
950
            update_option('sensei_flush_rewrite_rules', '2');
951
952
        }elseif( '2' == $option ) {
953
954
            flush_rewrite_rules();
955
            update_option('sensei_flush_rewrite_rules', '0');
956
957
        }
958
959
    } // end flush_rewrite_rules
960
961
    /**
962
     * Calling this function will tell Sensei to flush rewrite
963
     * rules on the next load.
964
     *
965
     * @since 1.9.0
966
     */
967
    public function initiate_rewrite_rules_flush(){
968
969
        update_option('sensei_flush_rewrite_rules', '1');
970
971
    }
972
973
    /**
974
     * sensei_woocommerce_email_course_details adds detail to email
975
     *
976
     * @deprecated since 1.9.0 use Sensei_WC::email_course_details
977
     *
978
     * @since   1.4.5
979
     * @access  public
980
     * @param   WC_Order $order
981
     *
982
     * @return  void
983
     */
984
    public function sensei_woocommerce_email_course_details( $order ) {
985
986
        Sensei_WC::email_course_details( $order );
987
988
    } // end func email course details
989
990
    /**
991
     * @deprecated since 1.9.0, movde to the Sensei_WC class
992
     * @param $user_id
993
     * @param $subscription_key
994
     */
995
    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ){
996
997
        Sensei_WC::reactivate_subscription( $user_id, $subscription_key );
0 ignored issues
show
Bug introduced by
The method reactivate_subscription() does not exist on Sensei_WC. Did you maybe mean activate_subscription()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
998
    }
999
1000
    /**
1001
     * @deprecated since 1.9.0, movde to the Sensei_WC class
1002
     * @param $user_id
1003
     * @param $subscription_key
1004
     */
1005
    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ){
1006
1007
        Sensei_WC::end_subscription( $user_id, $subscription_key );
0 ignored issues
show
Bug introduced by
The method end_subscription() does not seem to exist on object<Sensei_WC>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1008
    }
1009
1010
    /**
1011
     * sensei_woocommerce_complete_order description
1012
     *
1013
     * @deprecated since 1.9.0 use Sensei_WC::complete_order( $order_id );
1014
     * @since   1.0.3
1015
     * @access  public
1016
     * @param   int $order_id WC order ID
1017
     *
1018
     * @return  void
1019
     */
1020
    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
1021
1022
        Sensei_WC::complete_order( $order_id );
1023
1024
    } // End sensei_woocommerce_complete_order()
1025
1026
    /**
1027
     * Runs when an order is cancelled.
1028
     *
1029
     * @deprecated since 1.9.0
1030
     *
1031
     * @since   1.2.0
1032
     * @param   integer $order_id order ID
1033
     * @return  void
1034
     */
1035
    public function sensei_woocommerce_cancel_order ( $order_id ) {
1036
1037
        Sensei_WC::cancel_order( $order_id );
1038
1039
    } // End sensei_woocommerce_cancel_order()
1040
1041
    /**
1042
     * sensei_activate_subscription runs when a subscription product is purchased
1043
     * @deprecated since 1.9.0
1044
     * @since   1.2.0
1045
     * @access  public
1046
     * @param   integer $order_id order ID
1047
     * @return  void
1048
     */
1049
    public function sensei_activate_subscription(  $order_id = 0 ) {
1050
1051
        Sensei_WC::activate_subscription( $order_id );
0 ignored issues
show
Documentation introduced by
$order_id is of type integer, but the function expects a object<WC_Order>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1052
1053
    } // End sensei_activate_subscription()
1054
1055
    /**
1056
     * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
1057
     * @deprecated since 1.9.0
1058
     * @since  1.0.0
1059
     * @param  int 			$course_id  (default: 0)
1060
     * @param  array/Object $order_user (default: array()) Specific user's data.
0 ignored issues
show
Documentation introduced by
The doc-type array/Object could not be parsed: Unknown type name "array/Object" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1061
     * @return bool|int
1062
     */
1063
    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
1064
1065
        return Sensei_WC::course_update( $course_id, $order_user );
1066
1067
    } // End woocommerce_course_update()
1068
1069
    /**
1070
     * Returns the WooCommerce Product Object
1071
     *
1072
     * The code caters for pre and post WooCommerce 2.2 installations.
1073
     *
1074
     * @deprecated since 1.9.0
1075
     * @since   1.1.1
1076
     *
1077
     * @param   integer $wc_product_id Product ID or Variation ID
1078
     * @param   string  $product_type  '' or 'variation'
1079
     *
1080
     * @return   WC_Product $wc_product_object
1081
     */
1082
    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1083
1084
        return Sensei_WC::get_product_object( $wc_product_id, $product_type );
1085
1086
    } // End sensei_get_woocommerce_product_object()
1087
1088
    /**
1089
     * Setup required WooCommerce settings.
1090
     * @access  public
1091
     * @since   1.1.0
1092
     * @return  void
1093
     */
1094
    public function set_woocommerce_functionality() {
1095
1096
        _deprecated_function('Sensei()->set_woocommerce_functionality', 'Sensei 1.9.0');
1097
1098
    } // End set_woocommerce_functionality()
1099
1100
    /**
1101
     * Disable guest checkout if a course product is in the cart
1102
     * @deprecated since 1.9.0
1103
     * @param  boolean $guest_checkout Current guest checkout setting
1104
     * @return boolean                 Modified guest checkout setting
1105
     */
1106
    public function disable_guest_checkout( $guest_checkout ) {
1107
1108
        return Sensei_WC::disable_guest_checkout( $guest_checkout );
1109
1110
    }// end disable_guest_checkout
1111
1112
    /**
1113
     * Change order status with virtual products to completed
1114
     *
1115
     * @deprecated since 1.9.0 use Sensei_WC::virtual_order_payment_complete( $order_status, $order_id )
1116
     *
1117
     * @since  1.1.0
1118
     * @param string $order_status
1119
     * @param int $order_id
1120
     * @return string
1121
     **/
1122
    public function virtual_order_payment_complete( $order_status, $order_id ) {
1123
1124
        return  Sensei_WC::virtual_order_payment_complete( $order_status, $order_id );
1125
    }
1126
1127
    /**
1128
         * Add custom action links on the plugin screen.
1129
         *
1130
         * @param   mixed $actions Plugin Actions Links
1131
         * @return  array
1132
         */
1133
        public function plugin_action_links( $actions ) {
1134
1135
            $custom_actions = array();
1136
1137
            // settings url(s)
1138
            if ( $this->get_settings_link( $this->get_id() ) ) {
1139
                $custom_actions['configure'] = $this->get_settings_link( $this->get_id() );
1140
            }
1141
1142
            // documentation url if any
1143
            if ( $this->get_documentation_url() ) {
1144
                /* translators: Docs as in Documentation */
1145
                $custom_actions['docs'] = sprintf( '<a href="%s" target="_blank">%s</a>', $this->get_documentation_url(), esc_html__( 'Docs', 'woocommerce-account-funds' ) );
1146
            }
1147
1148
            // support url if any
1149
            if ( $this->get_support_url() ) {
1150
                $custom_actions['support'] = sprintf( '<a href="%s" target="_blank">%s</a>', $this->get_support_url(), esc_html_x( 'Support', 'noun', 'woocommerce-account-funds' ) );
1151
            }
1152
1153
            // add the links to the front of the actions list   
1154
            return array_merge( $custom_actions, $actions );
1155
        }
1156
1157
        /**
1158
         * Returns the "Configure" plugin action link to go directly to the plugin
1159
         * settings page (if any)
1160
         *
1161
         * @return string plugin configure link
1162
         */
1163
        public function get_settings_link( $plugin_id = null ) {
1164
            $settings_url = $this->get_settings_url( $plugin_id );
1165
            if ( $settings_url ) {
1166
                return sprintf( '<a href="%s">%s</a>', $settings_url, esc_html_x( 'Configure', 'plugin action link', 'woocommerce-account-funds' ) );
1167
            }
1168
1169
            // no settings
1170
            return '';
1171
        }
1172
1173
        /**
1174
         * Gets the plugin configuration URL
1175
         *
1176
         * @return string plugin settings URL
1177
         */
1178
        public function get_settings_url( $plugin_id = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $plugin_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1179
            return admin_url( 'admin.php?page=wc-settings&tab=account_funds' );
1180
        }
1181
1182
        /**
1183
         * Gets the plugin documentation url, used for the 'Docs' plugin action
1184
         *
1185
         * @return string documentation URL
1186
         */
1187
        public function get_documentation_url() {
1188
            return sprintf( 'https://docs.woothemes.com/documentation/plugins/sensei/' );
1189
        }
1190
1191
        /**
1192
         * Gets the support URL, used for the 'Support' plugin action link
1193
         *
1194
         * @return string support url
1195
         */
1196
        public function get_support_url() {
1197
            return 'https://www.woothemes.com/my-account/tickets/';
1198
        }
1199
1200
        /**
1201
         * Returns the plugin id
1202
         *
1203
         * @return string plugin id
1204
         */
1205
        public function get_id() {
1206
            return $this->id;
1207
        }
1208
1209
        /**
1210
         * Returns true if the current page is the admin general configuration page
1211
         *
1212
         * @return boolean true if the current page is the admin general configuration page
1213
         */
1214
        public function is_general_configuration_page() {
1215
            return isset( $_GET['page'] ) && 'woothemes-sensei-settings' == $_GET['page'] && ( ! isset( $_GET['tab'] ) || 'general' == $_GET['tab'] );
1216
        }
1217
1218
1219
        /**
1220
         * Returns the admin configuration url for the admin general configuration page
1221
         * 
1222
         * @return string admin configuration url for the admin general configuration page
1223
         */
1224
        public function get_general_configuration_url() {
1225
            return admin_url( 'admin.php?page=woothemes-sensei-settings&tab=general' );
1226
        }
1227
1228
} // End Class
1229
1230
/**
1231
 * Class Woothemes_Sensei
1232
 * @ignore only for backward compatibility
1233
 * @since 1.9.0
1234
 */
1235
class Woothemes_Sensei extends Sensei_Main{ }
1236